mirror of
https://github.com/facebook/docusaurus.git
synced 2025-06-02 02:42:41 +02:00
fix(create): load entry file after node version checking (#6860)
* refactor(create): add exception handling if external command is fails
refers #4870
85e87b560e
* fix(create): load entry file after node version checking
This commit is contained in:
parent
5e2168ea22
commit
a6e72192fa
1 changed files with 13 additions and 14 deletions
|
@ -13,7 +13,6 @@ import semver from 'semver';
|
|||
import path from 'path';
|
||||
import {program} from 'commander';
|
||||
import {createRequire} from 'module';
|
||||
import init from '../lib/index.js';
|
||||
|
||||
const packageJson = createRequire(import.meta.url)('../package.json');
|
||||
const requiredVersion = packageJson.engines.node;
|
||||
|
@ -24,14 +23,6 @@ if (!semver.satisfies(process.version, requiredVersion)) {
|
|||
process.exit(1);
|
||||
}
|
||||
|
||||
function wrapCommand(fn) {
|
||||
return (...args) =>
|
||||
fn(...args).catch((err) => {
|
||||
logger.error(err.stack);
|
||||
process.exitCode = 1;
|
||||
});
|
||||
}
|
||||
|
||||
program.version(packageJson.version);
|
||||
|
||||
program
|
||||
|
@ -61,11 +52,14 @@ program
|
|||
rootDir = '.',
|
||||
{packageManager, skipInstall, typescript, gitStrategy} = {},
|
||||
) => {
|
||||
wrapCommand(init)(path.resolve(rootDir), siteName, template, {
|
||||
packageManager,
|
||||
skipInstall,
|
||||
typescript,
|
||||
gitStrategy,
|
||||
// See https://github.com/facebook/docusaurus/pull/6860
|
||||
import('../lib/index.js').then(({default: init}) => {
|
||||
init(path.resolve(rootDir), siteName, template, {
|
||||
packageManager,
|
||||
skipInstall,
|
||||
typescript,
|
||||
gitStrategy,
|
||||
});
|
||||
});
|
||||
},
|
||||
);
|
||||
|
@ -75,3 +69,8 @@ program.parse(process.argv);
|
|||
if (!process.argv.slice(1).length) {
|
||||
program.outputHelp();
|
||||
}
|
||||
|
||||
process.on('unhandledRejection', (err) => {
|
||||
logger.error(err);
|
||||
process.exit(1);
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue