Skip to content

Commit

Permalink
refactor: use new log functions
Browse files Browse the repository at this point in the history
  • Loading branch information
ad-world committed Aug 8, 2024
1 parent 5e8371f commit deba7c4
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
8 changes: 4 additions & 4 deletions packages/openapi-generator/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,17 +171,17 @@ const app = command({

const initE = findSymbolInitializer(project.right, sourceFile, ref.name);
if (E.isLeft(initE)) {
console.error(
`[ERROR] Could not find symbol '${ref.name}' in '${ref.location}': ${initE.left}`,
logError(
`Could not find symbol '${ref.name}' in '${ref.location}': ${initE.left}`,
);
process.exit(1);
}
const [newSourceFile, init, comment] = initE.right;

const codecE = parseCodecInitializer(project.right, newSourceFile, init);
if (E.isLeft(codecE)) {
console.error(
`[ERROR] Could not parse codec '${ref.name}' in '${ref.location}': ${codecE.left}`,
logError(
`Could not parse codec '${ref.name}' in '${ref.location}': ${codecE.left}`,
);
process.exit(1);
}
Expand Down
6 changes: 3 additions & 3 deletions packages/openapi-generator/src/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import resolve from 'resolve';

import { KNOWN_IMPORTS, type KnownCodec } from './knownImports';
import { parseSource, type SourceFile } from './sourceFile';
import { errorLeft } from './error';
import { errorLeft, logError, logInfo } from './error';

const readFile = promisify(fs.readFile);

Expand Down Expand Up @@ -177,7 +177,7 @@ export class Project {
);
const module = await import(customCodecPath);
if (module.default === undefined) {
console.error(`Could not find default export in ${customCodecPath}`);
logError(`Could not find default export in ${customCodecPath}`);
return;
}

Expand All @@ -187,7 +187,7 @@ export class Project {
...customCodecs,
};

console.error(`Loaded custom codecs for ${packageName}`);
logInfo(`Loaded custom codecs for ${packageName}`);
}
} catch (e) {
return;
Expand Down
3 changes: 2 additions & 1 deletion packages/openapi-generator/src/sourceFile.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as swc from '@swc/core';

import { parseTopLevelSymbols, type SymbolTable } from './symbol';
import { logError } from './error';

export type SourceFile = {
path: string;
Expand Down Expand Up @@ -41,7 +42,7 @@ export async function parseSource(
span: module.span,
};
} catch (e: unknown) {
console.error(`Error parsing source file: ${path}`, e);
logError(`Error parsing source file: ${path}, ${e}`);
return undefined;
}
}

0 comments on commit deba7c4

Please sign in to comment.