Skip to content

Commit

Permalink
fix(bin): warn instead of error on unsupported versions
Browse files Browse the repository at this point in the history
  • Loading branch information
RealShadowNova committed Oct 22, 2022
1 parent 488c127 commit bb0b075
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 16 deletions.
7 changes: 4 additions & 3 deletions src/bin/commands/build-docs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ export async function buildDocs(options: Options) {
} catch (error) {
const cause = error as Error;

spinner.error({ text: 'Failed to build TypeDoc documentation' });

if (options.verbose) console.log(cause.stack ?? cause.message);
if (options.verbose) {
spinner.error({ text: 'Failed to build TypeDoc documentation' });
console.log(cause.stack ?? cause.message);
} else spinner.error({ text: 'Failed to build TypeDoc documentation. Add the --verbose flag to view these errors.' });

process.exit(1);
}
Expand Down
7 changes: 6 additions & 1 deletion src/bin/commands/migrate-docs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,17 @@ export async function migrateDocs(options: RequiredExcept<Options, 'json'>) {
try {
const directory = resolve(process.cwd(), options.migrate);
let migratedFiles = 0;
const warnings = [];

for await (const path of findFilesRecursivelyStringEndsWith(directory, '.json')) {
const data = JSON.parse(await readFile(path, 'utf-8'));

if ('typeDocJsonParserVersion' in data) {
const migrated = migrateProjectJson(data);

if (migrated) {
if (typeof migrated === 'string') {
warnings.push(migrated);
} else {
await writeFile(path, JSON.stringify(migrated, null, 2), 'utf-8');

migratedFiles++;
Expand All @@ -28,6 +31,8 @@ export async function migrateDocs(options: RequiredExcept<Options, 'json'>) {
}

spinner.success({ text: `Migrated ${migratedFiles} TypeDoc JSON Parser output files` });

for (const warning of warnings) console.warn(warning);
} catch (error) {
const cause = error as Error;

Expand Down
7 changes: 4 additions & 3 deletions src/bin/commands/parse-docs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ export async function parseDocs(options: RequiredExcept<Options, 'migrate'>) {
} catch (error) {
const cause = error as Error;

spinner.error({ text: 'Failed to parse TypeDoc JSON output file' });

if (options.verbose) console.log(cause.stack ?? cause.message);
if (options.verbose) {
spinner.error({ text: 'Failed to parse TypeDoc JSON output file.' });
console.log(cause.stack ?? cause.message);
} else spinner.error({ text: 'Failed to parse TypeDoc JSON output file. Add the --verbose flag to view these errors.' });

process.exit(1);
}
Expand Down
67 changes: 58 additions & 9 deletions src/bin/lib/migrateProjectJson.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { bold, yellow } from 'colorette';
import type { ClassParser } from '../../lib/structures/class-parser';
import type { EnumParser } from '../../lib/structures/enum-parser';
import type { FunctionParser } from '../../lib/structures/FunctionParser';
Expand Down Expand Up @@ -25,7 +26,7 @@ export function migrateProjectJson(
| Migration.MajorThree.MinorTwo.ProjectJSON
| Migration.MajorFour.MinorZero.ProjectJSON
| Migration.MajorSix.MinorZero.ProjectJSON
): ProjectParser.JSON | null {
): ProjectParser.JSON | string {
const { typeDocJsonParserVersion, id, name, classes, enums, functions, interfaces, namespaces, typeAliases } = projectJson;

switch (typeDocJsonParserVersion) {
Expand Down Expand Up @@ -80,7 +81,11 @@ export function migrateProjectJson(
};
}

case '6.0.0': {
case '6.0.0':

case '6.0.1':

case '6.0.2': {
const { variables } = projectJson as Migration.MajorSix.MinorZero.ProjectJSON;

return {
Expand All @@ -101,7 +106,11 @@ export function migrateProjectJson(
}
}

throw new Error(`Unsupported typeDocJsonParserVersion: ${typeDocJsonParserVersion}`);
return yellow(
`${bold(`[WARN]`)} Unsupported typeDocJsonParserVersion(${typeDocJsonParserVersion}) encountered while migrating project ${projectJson.name}${
'version' in projectJson ? `@${projectJson.version}` : ''
}`
);
}

function migrateClassJson(
Expand Down Expand Up @@ -192,7 +201,11 @@ function migrateClassJson(
})
};

case '6.0.0': {
case '6.0.0':

case '6.0.1':

case '6.0.2': {
const { typeParameters } = classJson as Migration.MajorSix.MinorZero.ClassJSON;

return {
Expand Down Expand Up @@ -313,7 +326,11 @@ function migrateEnum(
};
}

case '6.0.0': {
case '6.0.0':

case '6.0.1':

case '6.0.2': {
const { members } = enumJson as Migration.MajorSix.MinorZero.EnumJSON;

return {
Expand Down Expand Up @@ -375,6 +392,10 @@ function migrateFunction(
case '5.2.0':

case '6.0.0':

case '6.0.1':

case '6.0.2':
return {
id,
name,
Expand Down Expand Up @@ -446,7 +467,11 @@ function migrateInterface(

case '5.2.0':

case '6.0.0': {
case '6.0.0':

case '6.0.1':

case '6.0.2': {
const { methods } = interfaceJson as Migration.MajorThree.MinorOne.InterfaceJSON;

return {
Expand Down Expand Up @@ -539,7 +564,11 @@ function migrateNamespace(
};
}

case '6.0.0': {
case '6.0.0':

case '6.0.1':

case '6.0.2': {
const { variables } = namespaceJson as Migration.MajorSix.MinorZero.NamespaceJSON;

return {
Expand Down Expand Up @@ -596,6 +625,10 @@ function migrateTypeAlias(
case '5.2.0':

case '6.0.0':

case '6.0.1':

case '6.0.2':
return {
id,
name,
Expand Down Expand Up @@ -644,6 +677,10 @@ function migrateVariable(
case '5.2.0':

case '6.0.0':

case '6.0.1':

case '6.0.2':
return {
id,
name,
Expand Down Expand Up @@ -697,7 +734,11 @@ function migrateSourceJson(

case '5.2.0':

case '6.0.0': {
case '6.0.0':

case '6.0.1':

case '6.0.2': {
const { url } = sourceJson as Migration.MajorThree.MinorZero.Misc.SourceJSON;

return {
Expand Down Expand Up @@ -743,6 +784,10 @@ function migrateParameterJson(parameterJson: Migration.MajorTwo.MinorOne.Misc.Pa
case '5.2.0':

case '6.0.0':

case '6.0.1':

case '6.0.2':
return {
id,
name,
Expand Down Expand Up @@ -801,7 +846,11 @@ function migrateSignatureJson(

case '5.2.0':

case '6.0.0': {
case '6.0.0':

case '6.0.1':

case '6.0.2': {
const { comment } = signatureJson as Migration.MajorTwo.MinorThree.Misc.SignatureJSON;

return {
Expand Down

0 comments on commit bb0b075

Please sign in to comment.