docusaurus/packages/docusaurus-init/bin/index.js
Sébastien Lorber aff848e875
chore: lockfile cleanup (#4944)
* lockfile cleanup

* temp fix eslint header/header issue in CLI: https://github.com/Stuk/eslint-plugin-header/issues/39
2021-06-10 16:12:19 +02:00

63 lines
1.7 KiB
JavaScript
Executable file

#!/usr/bin/env node
// TODO remove when fixed: https://github.com/Stuk/eslint-plugin-header/issues/39
/* eslint-disable header/header */
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
const chalk = require('chalk');
const semver = require('semver');
const path = require('path');
const program = require('commander');
const {default: init} = require('../lib');
const requiredVersion = require('../package.json').engines.node;
if (!semver.satisfies(process.version, requiredVersion)) {
console.log(
chalk.red(`\nMinimum node version not met :)`) +
chalk.yellow(
`\nYou are using Node ${process.version}, Requirement: Node ${requiredVersion}.\n`,
),
);
process.exit(1);
}
function wrapCommand(fn) {
return (...args) =>
fn(...args).catch((err) => {
console.error(chalk.red(err.stack));
process.exitCode = 1;
});
}
program
.version(require('../package.json').version)
.usage('<command> [options]');
program
.command('init [siteName] [template] [rootDir]')
.option('--use-npm')
.option('--skip-install')
.description('Initialize website')
.action((siteName, template, rootDir = '.', {useNpm, skipInstall}) => {
wrapCommand(init)(path.resolve(rootDir), siteName, template, {
useNpm,
skipInstall,
});
});
program.arguments('<command>').action((cmd) => {
program.outputHelp();
console.log(` ${chalk.red(`\n Unknown command ${chalk.yellow(cmd)}.`)}`);
console.log();
});
program.parse(process.argv);
if (!process.argv.slice(2).length) {
program.outputHelp();
}