Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Resolve CLI issues on Mac #10

Merged
merged 4 commits into from
Apr 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"scripts": {
"generate": "node dist/ftrack-ts-schema-generator.js",
"build": "esbuild source/index.ts --target=esnext --outfile=dist/ftrack-ts-schema-generator.js --platform=node --format=esm --bundle --packages=external",
"watch": "esbuild source/index.ts --target=esnext --outfile=dist/ftrack-ts-schema-generator.js --platform=node --format=esm --bundle --packages=external --watch",
"prepack": "yarn build",
"test": "tsc && eslint --cache --fix --max-warnings=0 ./source && prettier -c ./source",
"prepublish": "yarn test"
Expand Down
23 changes: 16 additions & 7 deletions source/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const session = new Session(
);
const legacySchemas = ["Conversation", "Message", "Participant"];

export async function generate(
async function generate(
outputPath = "__generated__",
outputFilename = "schema.ts"
) {
Expand All @@ -35,7 +35,7 @@ export async function generate(
schema,
schemas
);
errors.push(conversionErrors);
errors.push(...conversionErrors);
interfaces += TSInterface;
}

Expand Down Expand Up @@ -78,6 +78,8 @@ export async function generate(
});
fs.mkdirSync(path.resolve(outputPath), { recursive: true });
fs.writeFileSync(path.join(outputPath, outputFilename), prettifiedContent);

return { errors, schemas };
}

async function getSchemas() {
Expand Down Expand Up @@ -123,9 +125,16 @@ function getTypedContextTypes(schemas: QuerySchemasResponse[]) {
const TypedContextSubtype = `export type TypedContextSubtype = keyof TypedContextSubtypeMap;`;
return { TypedContextSubtypeMap, TypedContextSubtype };
}
// Call the generate function with command line arguments if this module is being run directly
if (import.meta.url === `file://${process.argv[1]}`) {
const outputPath = process.argv[2] || "__generated__";
const outputFilename = process.argv[3] || "schema.ts";
generate(outputPath, outputFilename);

const outputPath = process.argv[2] || "__generated__";
const outputFilename = process.argv[3] || "schema.ts";
const { errors, schemas } = await generate(outputPath, outputFilename);

console.info(`${schemas.length} schema(s) found`);

if (errors.length > 0) {
console.warn("One or more errors occured:");
for (const error of errors) {
console.warn(error);
}
}
Loading