-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
76997f0
commit 34520dd
Showing
9 changed files
with
1,318 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { Spinner } from '@favware/colorette-spinner'; | ||
import { findFilesRecursivelyStringEndsWith } from '@sapphire/node-utilities'; | ||
import { readFile, writeFile } from 'node:fs/promises'; | ||
import { resolve } from 'node:path'; | ||
import { migrateProject } from '../lib/migrations'; | ||
import type { Options } from '../lib/types/Options'; | ||
import type { RequiredExcept } from '../lib/types/RequiredExcept'; | ||
|
||
export async function migrateDocs(options: RequiredExcept<Options, 'json'>) { | ||
const spinner = new Spinner().start({ text: 'Migrating TypeDoc JSON Parser output files' }); | ||
|
||
try { | ||
const directory = resolve(process.cwd(), options.migrate); | ||
let migratedFiles = 0; | ||
|
||
for await (const path of findFilesRecursivelyStringEndsWith(directory, '.json')) { | ||
const data = JSON.parse(await readFile(path, 'utf-8')); | ||
|
||
if ('typeDocJsonParserVersion' in data) { | ||
const migrated = migrateProject(data); | ||
|
||
if (migrated) { | ||
await writeFile(path, JSON.stringify(migrated, null, 2), 'utf-8'); | ||
|
||
migratedFiles++; | ||
} | ||
} | ||
} | ||
|
||
spinner.success({ text: `Migrated ${migratedFiles} TypeDoc JSON Parser output files` }); | ||
} catch (error) { | ||
const cause = error as Error; | ||
|
||
spinner.error({ text: 'Failed to migrate TypeDoc JSON Parser output' }); | ||
|
||
if (options.verbose) console.log(cause.stack ?? cause.message); | ||
|
||
process.exit(1); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,41 @@ | ||
#!/usr/bin/env node | ||
|
||
import { bold, red } from 'colorette'; | ||
import { Command } from 'commander'; | ||
import { buildDocs } from './commands/build-docs'; | ||
import { checkRepository } from './commands/check-repository'; | ||
import { migrateDocs } from './commands/migrate-docs'; | ||
import { parseDocs } from './commands/parse-docs'; | ||
import { parseOptions } from './lib/parseOptions'; | ||
import type { Options } from './lib/types/Options'; | ||
import type { RequiredExcept } from './lib/types/RequiredExcept'; | ||
|
||
async function run() { | ||
const command = new Command() | ||
.option('-j, --json <path>', 'Path to the TypeDoc JSON output file.') | ||
.option('--json [path]', 'Path to the TypeDoc JSON output file to parse') | ||
.option('--migrate [path]', 'Path to the directory containing TypeDoc JSON Parser output files to migrate') | ||
.option('-v, --verbose', 'Print verbose information', false); | ||
|
||
const program = command.parse(process.argv); | ||
const options = await parseOptions(program.opts<Partial<Options>>()); | ||
|
||
if (options.verbose) console.log(`Resolved Options:`, options); | ||
if (!Reflect.has(options, 'json')) throw new Error('Missing required option: --json'); | ||
if (!Reflect.has(options, 'json') && !Reflect.has(options, 'migrate')) { | ||
console.error(red(`${bold('[ERROR]')} You must specify either the --json or --migrate option`)); | ||
} | ||
|
||
// Check if the current working directory is a Node.js repository. | ||
await checkRepository(options); | ||
|
||
// Build the TypeDoc documentation. | ||
await buildDocs(options); | ||
if (options.migrate) { | ||
await migrateDocs(options as RequiredExcept<Options, 'json'>); | ||
} else if (options.json) { | ||
// Build the TypeDoc documentation. | ||
await buildDocs(options); | ||
|
||
// Parse the TypeDoc JSON output. | ||
await parseDocs(options); | ||
// Parse the TypeDoc JSON output. | ||
await parseDocs(options as RequiredExcept<Options, 'migrate'>); | ||
} | ||
} | ||
|
||
void run(); |
Oops, something went wrong.