Skip to content

Commit

Permalink
refactor(msar): More consistent Module TitleCase
Browse files Browse the repository at this point in the history
  • Loading branch information
battis committed Jan 3, 2025
1 parent 5a0a17a commit caf1554
Show file tree
Hide file tree
Showing 11 changed files with 55 additions and 55 deletions.
12 changes: 6 additions & 6 deletions packages/msar/src/bin/commands/download.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
);
}
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions packages/msar/src/common.ts
Original file line number Diff line number Diff line change
@@ -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';
24 changes: 12 additions & 12 deletions packages/msar/src/common/args.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
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;
output?: boolean;
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({
Expand All @@ -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 : {})
};
}
Expand All @@ -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 : {})
};
}
Expand All @@ -42,14 +42,14 @@ export const options = pickOptions();

export function parse(values: Record<string, string>) {
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
};
16 changes: 8 additions & 8 deletions packages/msar/src/common/output.ts
Original file line number Diff line number Diff line change
@@ -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';
2 changes: 1 addition & 1 deletion packages/msar/src/common/workflow.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * as args from './workflow/args.js';
export * as args from './Workflow/args.js';
6 changes: 3 additions & 3 deletions packages/msar/src/workflows/Download/Downloader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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'
);
}
Expand Down Expand Up @@ -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)) {
Expand Down
4 changes: 2 additions & 2 deletions packages/msar/src/workflows/Download/Downloader/HTTPFetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions packages/msar/src/workflows/Download/Spider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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
Expand Down
18 changes: 9 additions & 9 deletions packages/msar/src/workflows/Snapshot/Manager/All.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
});
}
Expand All @@ -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`
);
Expand Down Expand Up @@ -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,
Expand All @@ -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 });
Expand Down
12 changes: 6 additions & 6 deletions packages/msar/src/workflows/Snapshot/Manager/Single.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ export type Context = {

export type Options = SnapshotOptions &
Context &
Partial<common.output.args.Parsed> &
common.workflow.args.Parsed;
Partial<common.Output.args.Parsed> &
common.Workflow.args.Parsed;

export async function snapshot({
session,
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit caf1554

Please sign in to comment.