Skip to content

Commit

Permalink
fix: Resolve CLI issues on Mac (#10)
Browse files Browse the repository at this point in the history
Co-authored-by: Lars Johansson <lars.johansson@ftrack.com>
  • Loading branch information
ffMathy and gismya authored Apr 6, 2023
1 parent 6774616 commit b2f57ae
Show file tree
Hide file tree
Showing 3 changed files with 158 additions and 148 deletions.
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

0 comments on commit b2f57ae

Please sign in to comment.