Skip to content

Commit

Permalink
fix: correct order of generator cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ms14981 authored and ColinEberhardt committed Feb 2, 2023
1 parent 4fa5e8c commit fbd3a8a
Showing 1 changed file with 23 additions and 26 deletions.
49 changes: 23 additions & 26 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,37 +46,34 @@ const forgeCommand = program
)
.allowUnknownOption()
.action(async (schema, generatorPathOrUrl) => {
try {
const generatorPath = generatorResolver.getGenerator(generatorPathOrUrl);
const configFile = path.join(generatorPath, "config.json");
const generatorPath = generatorResolver.getGenerator(generatorPathOrUrl);
const configFile = path.join(generatorPath, "config.json");

// re-configure the command to generate the API
forgeCommand.allowUnknownOption(false).action(async (_, __, options) => {
// set the additional options as environment variables
const generatorOptions = Object.keys(options).filter((key) =>
key.startsWith(generatorOptionsPrefix)
);
generatorOptions.forEach((option) => {
const optionName = option.substring(generatorOptionsPrefix.length);
process.env[optionName] = options[option];
});

generate(schema, generatorPath, options);
// re-configure the command to generate the API
forgeCommand.allowUnknownOption(false).action(async (_, __, options) => {
// set the additional options as environment variables
const generatorOptions = Object.keys(options).filter((key) =>
key.startsWith(generatorOptionsPrefix)
);
generatorOptions.forEach((option) => {
const optionName = option.substring(generatorOptionsPrefix.length);
process.env[optionName] = options[option];
});

// add the additional options from the generator's config.json file
if (fs.existsSync(configFile)) {
const config = JSON.parse(fs.readFileSync(configFile, "utf8"));
configToCommanderOptions(config).forEach((option) => {
forgeCommand.addOption(option);
});
}

// parse the command line arguments, and perform generation (on success)
forgeCommand.parse(process.argv);
} finally {
await generate(schema, generatorPath, options);
generatorResolver.cleanup();
});

// add the additional options from the generator's config.json file
if (fs.existsSync(configFile)) {
const config = JSON.parse(fs.readFileSync(configFile, "utf8"));
configToCommanderOptions(config).forEach((option) => {
forgeCommand.addOption(option);
});
}

// parse the command line arguments, and perform generation (on success)
forgeCommand.parse(process.argv);
});

program
Expand Down

0 comments on commit fbd3a8a

Please sign in to comment.