Skip to content

Commit

Permalink
convert blueprint cli to cjs
Browse files Browse the repository at this point in the history
  • Loading branch information
mshima committed Sep 7, 2023
1 parent 5c5859b commit 0e30399
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ exports[`generator - generate-blueprint with all option should match snapshot 1`
"README.md": {
"stateCleared": "modified",
},
"cli/cli.mjs": {
"cli/cli.cjs": {
"stateCleared": "modified",
},
"generators/angular/command.mjs": {
Expand Down Expand Up @@ -898,7 +898,7 @@ exports[`generator - generate-blueprint with default config should write files a
"README.md": {
"stateCleared": "modified",
},
"cli/cli.mjs": {
"cli/cli.cjs": {
"stateCleared": "modified",
},
"package.json": {
Expand Down
2 changes: 1 addition & 1 deletion generators/generate-blueprint/files.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const files = {
},
{
condition: ctx => ctx.cli,
templates: [{ file: 'cli/cli.mjs', renameTo: ctx => (ctx.js ? 'cli/cli.cjs' : 'cli/cli.mjs') }],
templates: ['cli/cli.cjs'],
},
{
condition: ctx => ctx.commands.length > 0,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
#!/usr/bin/env node

import { runJHipster, done, logger } from 'generator-jhipster/cli';
import { readFile } from 'fs/promises';
import { fileURLToPath } from 'url';
import { dirname, basename } from 'path';
const { dirname, basename, join } = require('path');
const { version, bin } = require('../package.json');

// Get package name to use as namespace.
// Allows blueprints to be aliased.
const packagePath = dirname(dirname(fileURLToPath(import.meta.url)));
const packagePath = dirname(__dirname);
const packageFolderName = basename(packagePath);

(async () => {
const { version, bin } = JSON.parse(await readFile(new URL('../package.json', import.meta.url)));
const { runJHipster, done, logger } = await import('generator-jhipster/cli');
const executableName = Object.keys(bin)[0];

runJHipster({
Expand All @@ -27,9 +25,9 @@ const packageFolderName = basename(packagePath);
},
lookups: [{ packagePaths: [packagePath], lookups: ['generators'] }],
}).catch(done);
})();

process.on('unhandledRejection', up => {
logger.error('Unhandled promise rejection at:');
logger.fatal(up);
});
process.on('unhandledRejection', up => {
logger.error('Unhandled promise rejection at:');
logger.fatal(up);
});
})();

0 comments on commit 0e30399

Please sign in to comment.