Skip to content

Commit

Permalink
remove cli.js file
Browse files Browse the repository at this point in the history
  • Loading branch information
thebedigupta committed Oct 10, 2024
1 parent 56f83c1 commit 3a53813
Showing 1 changed file with 23 additions and 35 deletions.
58 changes: 23 additions & 35 deletions apps/generator/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,41 +141,29 @@ xfs.mkdirp(program.output, async err => {
* @param {*} targetDir The path to the target directory.
*/
function generate(targetDir) {
return new Promise((resolve, reject) => {
(async () => {
try {
const generator = new Generator(
template,
targetDir || path.resolve(os.tmpdir(), "asyncapi-generator"),
{
templateParams: params,
noOverwriteGlobs,
disabledHooks,
forceWrite: program.forceWrite,
install: program.install,
debug: program.debug,
mapBaseUrlToFolder,
}
);

if (isAsyncapiDocLocal) {
await generator.generateFromFile(path.resolve(asyncapiDocPath));
} else {
await generator.generateFromURL(asyncapiDocPath);
}
console.log(green("\n\nDone! ✨"));
console.log(
`${
yellow("Check out your shiny new generated files at ") +
magenta(program.output) +
yellow(".")
}\n`
);
resolve();
} catch (e) {
reject(e);
return new Promise(async (resolve, reject) => {
try {
const generator = new Generator(template, targetDir || path.resolve(os.tmpdir(), 'asyncapi-generator'), {
templateParams: params,
noOverwriteGlobs,
disabledHooks,
forceWrite: program.forceWrite,
install: program.install,
debug: program.debug,
mapBaseUrlToFolder
});

if (isAsyncapiDocLocal) {
await generator.generateFromFile(path.resolve(asyncapiDocPath));
} else {
await generator.generateFromURL(asyncapiDocPath);
}
})(); //Immediately invoke the async function
console.log(green('\n\nDone! ✨'));
console.log(`${yellow('Check out your shiny new generated files at ') + magenta(program.output) + yellow('.')}\n`);
resolve();
} catch (e) {
reject(e);
}
});
}

Expand Down Expand Up @@ -207,4 +195,4 @@ async function watcherHandler(changedFiles) {
}
}

process.on('unhandledRejection', showErrorAndExit);
process.on('unhandledRejection', showErrorAndExit);

0 comments on commit 3a53813

Please sign in to comment.