From caf15547a8a0d8806ed4524ff0115cc8f8cc5892 Mon Sep 17 00:00:00 2001 From: Seth Battis Date: Fri, 3 Jan 2025 15:43:41 -0500 Subject: [PATCH] refactor(msar): More consistent Module TitleCase --- packages/msar/src/bin/commands/download.ts | 12 +++++----- packages/msar/src/common.ts | 4 ++-- packages/msar/src/common/args.ts | 24 +++++++++---------- packages/msar/src/common/output.ts | 16 ++++++------- packages/msar/src/common/workflow.ts | 2 +- .../msar/src/workflows/Download/Downloader.ts | 6 ++--- .../Download/Downloader/AuthenticatedFetch.ts | 6 ++--- .../Download/Downloader/HTTPFetch.ts | 4 ++-- .../msar/src/workflows/Download/Spider.ts | 6 ++--- .../src/workflows/Snapshot/Manager/All.ts | 18 +++++++------- .../src/workflows/Snapshot/Manager/Single.ts | 12 +++++----- 11 files changed, 55 insertions(+), 55 deletions(-) diff --git a/packages/msar/src/bin/commands/download.ts b/packages/msar/src/bin/commands/download.ts index 3d3a5c3..cc61a48 100644 --- a/packages/msar/src/bin/commands/download.ts +++ b/packages/msar/src/bin/commands/download.ts @@ -44,7 +44,7 @@ import * as Snapshot from '../../workflows/Snapshot.js'; ); } else { if (fs.existsSync(outputPath)) { - outputPath = await common.output.avoidOverwrite( + outputPath = await common.Output.avoidOverwrite( path.join(outputPath, path.basename(snapshotPath!, '.json')) ); } @@ -105,22 +105,22 @@ import * as Snapshot from '../../workflows/Snapshot.js'; JSON.parse( fs .readFileSync( - common.output.filePathFromOutputPath(outputPath, fileName)! + common.Output.filePathFromOutputPath(outputPath, fileName)! ) .toString() ) ); fs.unlinkSync( - common.output.filePathFromOutputPath(outputPath, fileName)! + common.Output.filePathFromOutputPath(outputPath, fileName)! ); } } - const indexPath = common.output.filePathFromOutputPath( + const indexPath = common.Output.filePathFromOutputPath( outputPath, 'index.json' ); - await common.output.writeJSON(indexPath, index, { pretty }); - await common.output.writeJSON( + await common.Output.writeJSON(indexPath, index, { pretty }); + await common.Output.writeJSON( path.resolve(indexPath, '../metadata.json'), { snapshotPath, diff --git a/packages/msar/src/common.ts b/packages/msar/src/common.ts index 62ac529..d3ffc31 100644 --- a/packages/msar/src/common.ts +++ b/packages/msar/src/common.ts @@ -1,7 +1,7 @@ export * as args from './common/args.js'; export * from './common/CustomError.js'; export * as Debug from './common/Debug.js'; -export * as output from './common/output.js'; +export * as Output from './common/Output.js'; export { oxfordComma } from './common/oxfordComma.js'; export * as PuppeteerSession from './common/PuppeteerSession.js'; -export * as workflow from './common/workflow.js'; +export * as Workflow from './common/Workflow.js'; diff --git a/packages/msar/src/common/args.ts b/packages/msar/src/common/args.ts index 00abc1f..b7cc9d9 100644 --- a/packages/msar/src/common/args.ts +++ b/packages/msar/src/common/args.ts @@ -1,6 +1,6 @@ -import * as _output from './output.js'; +import * as Output from './Output.js'; import * as PuppeteerSession from './PuppeteerSession.js'; -import * as _workflow from './workflow.js'; +import * as Workflow from './Workflow.js'; export type Options = { workflow?: boolean; @@ -8,8 +8,8 @@ export type Options = { puppeteerSession?: boolean; }; -export type Parsed = _workflow.args.Parsed & - _output.args.Parsed & +export type Parsed = Workflow.args.Parsed & + Output.args.Parsed & PuppeteerSession.args.Parsed; export function pickFlags({ @@ -18,8 +18,8 @@ export function pickFlags({ puppeteerSession = true }: Options = {}) { return { - ...(workflow ? _workflow.args.flags : {}), - ...(output ? _output.args.flags : {}), + ...(workflow ? Workflow.args.flags : {}), + ...(output ? Output.args.flags : {}), ...(puppeteerSession ? PuppeteerSession.args.flags : {}) }; } @@ -32,8 +32,8 @@ export function pickOptions({ puppeteerSession = true }: Options = {}) { return { - ...(workflow ? _workflow.args.options : {}), - ...(output ? _output.args.options : {}), + ...(workflow ? Workflow.args.options : {}), + ...(output ? Output.args.options : {}), ...(puppeteerSession ? PuppeteerSession.args.options : {}) }; } @@ -42,14 +42,14 @@ export const options = pickOptions(); export function parse(values: Record) { return { - ..._workflow.args.parse(values), - ..._output.args.parse(values), + ...Workflow.args.parse(values), + ...Output.args.parse(values), ...PuppeteerSession.args.parse(values) }; } export const defaults = { - ..._workflow.args.defaults, - ..._output.args.defaults, + ...Workflow.args.defaults, + ...Output.args.defaults, ...PuppeteerSession.args.defaults }; diff --git a/packages/msar/src/common/output.ts b/packages/msar/src/common/output.ts index ac14f0f..54d7d60 100644 --- a/packages/msar/src/common/output.ts +++ b/packages/msar/src/common/output.ts @@ -1,8 +1,8 @@ -export * as args from './output/args.js'; -export * from './output/avoidOverwrite.js'; -export { filePathFromOutputPath } from './output/filePathFromOutputPath.js'; -export * from './output/OutputError.js'; -export { pathsafeTimestamp } from './output/pathsafeTimestamp.js'; -export { writeFetchedFile } from './output/writeFetchedFile.js'; -export { writeJSON } from './output/writeJSON.js'; -export { writeRecursive } from './output/writeRecursive.js'; +export * as args from './Output/args.js'; +export * from './Output/avoidOverwrite.js'; +export { filePathFromOutputPath } from './Output/filePathFromOutputPath.js'; +export * from './Output/OutputError.js'; +export { pathsafeTimestamp } from './Output/pathsafeTimestamp.js'; +export { writeFetchedFile } from './Output/writeFetchedFile.js'; +export { writeJSON } from './Output/writeJSON.js'; +export { writeRecursive } from './Output/writeRecursive.js'; diff --git a/packages/msar/src/common/workflow.ts b/packages/msar/src/common/workflow.ts index ba1d69e..4e4c227 100644 --- a/packages/msar/src/common/workflow.ts +++ b/packages/msar/src/common/workflow.ts @@ -1 +1 @@ -export * as args from './workflow/args.js'; +export * as args from './Workflow/args.js'; diff --git a/packages/msar/src/workflows/Download/Downloader.ts b/packages/msar/src/workflows/Download/Downloader.ts index b4e0078..d18f5ed 100644 --- a/packages/msar/src/workflows/Download/Downloader.ts +++ b/packages/msar/src/workflows/Download/Downloader.ts @@ -6,9 +6,9 @@ import { Strategy } from './Downloader/Strategy.js'; export type Options = { host: string; -} & common.output.args.Parsed & +} & common.Output.args.Parsed & common.PuppeteerSession.args.Parsed & - common.workflow.args.Parsed; + common.Workflow.args.Parsed; // TODO Downloader needs to honor --concurrentThreads export class Downloader implements Strategy { @@ -19,7 +19,7 @@ export class Downloader implements Strategy { public constructor({ host, outputOptions, ...options }: Options) { const { outputPath } = outputOptions; if (!outputPath) { - throw new common.output.OutputError('Downloader requires outputPath'); + throw new common.Output.OutputError('Downloader requires outputPath'); } this.host = host; this.auth = new AuthenticatedFetch.Downloader({ diff --git a/packages/msar/src/workflows/Download/Downloader/AuthenticatedFetch.ts b/packages/msar/src/workflows/Download/Downloader/AuthenticatedFetch.ts index 679adfb..e3652a1 100644 --- a/packages/msar/src/workflows/Download/Downloader/AuthenticatedFetch.ts +++ b/packages/msar/src/workflows/Download/Downloader/AuthenticatedFetch.ts @@ -21,7 +21,7 @@ type FilepathVariantsOptions = { export type Options = { host: URL | string; -} & common.output.args.Parsed & +} & common.Output.args.Parsed & common.PuppeteerSession.args.Parsed; const TEMP = path.join('/tmp/msar/download', crypto.randomUUID()); @@ -42,7 +42,7 @@ export class Downloader }: Options) { super(`https://${host}`, { ...options, ...puppeteerOptions }); if (!outputPath) { - throw new common.output.OutputError( + throw new common.Output.OutputError( 'AuthenticatedFetch requires outputPath' ); } @@ -103,7 +103,7 @@ export class Downloader const localPath = new URL(url).pathname; const destFilepath = path.resolve( process.cwd(), - common.output.filePathFromOutputPath(this.outputPath, localPath)! + common.Output.filePathFromOutputPath(this.outputPath, localPath)! ); const dir = path.dirname(destFilepath); if (!fs.existsSync(dir)) { diff --git a/packages/msar/src/workflows/Download/Downloader/HTTPFetch.ts b/packages/msar/src/workflows/Download/Downloader/HTTPFetch.ts index 3cd8cbe..b0071fb 100644 --- a/packages/msar/src/workflows/Download/Downloader/HTTPFetch.ts +++ b/packages/msar/src/workflows/Download/Downloader/HTTPFetch.ts @@ -7,7 +7,7 @@ import { } from '../filenameFromDisposition.js'; import { Strategy } from './Strategy.js'; -export type Options = { outputPath: string } & common.workflow.args.Parsed; +export type Options = { outputPath: string } & common.Workflow.args.Parsed; export class Downloader implements Strategy { private outputPath: string; @@ -37,7 +37,7 @@ export class Downloader implements Strategy { } if (response.ok && response.body) { return { - localPath: await common.output.writeFetchedFile({ + localPath: await common.Output.writeFetchedFile({ url, stream: response.body as ReadableStream, outputPath: this.outputPath diff --git a/packages/msar/src/workflows/Download/Spider.ts b/packages/msar/src/workflows/Download/Spider.ts index 2987388..a8d1f9b 100644 --- a/packages/msar/src/workflows/Download/Spider.ts +++ b/packages/msar/src/workflows/Download/Spider.ts @@ -28,7 +28,7 @@ export class Spider { ) { const { outputPath, pretty } = outputOptions; if (!outputPath) { - throw new common.output.OutputError('Spider requires outputPath'); + throw new common.Output.OutputError('Spider requires outputPath'); } if (snapshot) { common.Debug.withGroupId( @@ -42,8 +42,8 @@ export class Spider { pathToComponent: path.basename(outputPath) }); const indexName = `${snapshot.SectionInfo?.Id || 'index'}.json`; - await common.output.writeJSON( - await common.output.avoidOverwrite(path.join(outputPath, indexName)), + await common.Output.writeJSON( + await common.Output.avoidOverwrite(path.join(outputPath, indexName)), snapshot, { pretty diff --git a/packages/msar/src/workflows/Snapshot/Manager/All.ts b/packages/msar/src/workflows/Snapshot/Manager/All.ts index 04fecb0..519a01d 100644 --- a/packages/msar/src/workflows/Snapshot/Manager/All.ts +++ b/packages/msar/src/workflows/Snapshot/Manager/All.ts @@ -76,11 +76,11 @@ export async function snapshot({ const progressBars = new cliProgress.MultiBar({}); const progress = progressBars.create(groups.length, 0); if (groupsPath) { - groupsPath = common.output.filePathFromOutputPath( + groupsPath = common.Output.filePathFromOutputPath( groupsPath, 'groups.json' ); - common.output.writeJSON(groupsPath, groups, { + common.Output.writeJSON(groupsPath, groups, { pretty }); } @@ -105,7 +105,7 @@ export async function snapshot({ data[i] = snapshot; // TODO Configurable snapshot --all temp directory // TODO Optional snapshot --all temp files - common.output.writeJSON(tempPath, snapshot); + common.Output.writeJSON(tempPath, snapshot); progressBars.log( `Wrote snapshot ${snapshot?.SectionInfo?.Teacher}'s ${snapshot?.SectionInfo?.SchoolYear} ${snapshot?.SectionInfo?.GroupName} ${snapshot?.SectionInfo?.Block} to ${cli.colors.url(outputPath)}\n` ); @@ -142,13 +142,13 @@ export async function snapshot({ first = snapshot.Metadata; } } - const filepath = await common.output.avoidOverwrite( - common.output.filePathFromOutputPath(outputPath, 'snapshot.json'), - common.output.AddTimestamp + const filepath = await common.Output.avoidOverwrite( + common.Output.filePathFromOutputPath(outputPath, 'snapshot.json'), + common.Output.AddTimestamp ); const { bulletinBoard, topics, assignments, gradebook } = options; - common.output.writeJSON(filepath, data, { pretty }); - common.output.writeJSON(filepath.replace(/\.json$/, '.metadata.json'), { + common.Output.writeJSON(filepath, data, { pretty }); + common.Output.writeJSON(filepath.replace(/\.json$/, '.metadata.json'), { ...first, Start, Finish, @@ -163,7 +163,7 @@ export async function snapshot({ }); if (errors.length) { const errorsPath = filepath.replace(/\.json$/, '.errors.json'); - common.output.writeJSON(errorsPath, errors); + common.Output.writeJSON(errorsPath, errors); cli.log.error(`Errors output to ${cli.colors.url(errorsPath)}`); } await fs.rm(TEMP, { recursive: true }); diff --git a/packages/msar/src/workflows/Snapshot/Manager/Single.ts b/packages/msar/src/workflows/Snapshot/Manager/Single.ts index 343c69a..da27d99 100644 --- a/packages/msar/src/workflows/Snapshot/Manager/Single.ts +++ b/packages/msar/src/workflows/Snapshot/Manager/Single.ts @@ -46,8 +46,8 @@ export type Context = { export type Options = SnapshotOptions & Context & - Partial & - common.workflow.args.Parsed; + Partial & + common.Workflow.args.Parsed; export async function snapshot({ session, @@ -142,11 +142,11 @@ export async function snapshot({ if (snapshot.SectionInfo) { basename = `${snapshot.SectionInfo.SchoolYear} - ${snapshot.SectionInfo.Teacher} - ${snapshot.SectionInfo.GroupName} - ${snapshot.SectionInfo.Id}`; } - const filepath = await common.output.avoidOverwrite( - common.output.filePathFromOutputPath(outputPath, `${basename}.json`) + const filepath = await common.Output.avoidOverwrite( + common.Output.filePathFromOutputPath(outputPath, `${basename}.json`) ); - common.output.writeJSON(filepath, snapshot, { pretty }); - common.output.writeJSON( + common.Output.writeJSON(filepath, snapshot, { pretty }); + common.Output.writeJSON( filepath.replace(/\.json$/, '.metadata.json'), { ...snapshot.Metadata,