mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-09 15:17:23 +02:00
feat: npm init docusaurus, yarn create docusaurus (#5635)
* initial create-docusaurus impl * cleanup * @docusaurus/init renamed to create-docusaurus * 0.0.6 * update lockfile * fix lint * remove npm2yarn for "npm init" because npm2yarn doesn't convert it and yarn result fails to execute * prettier * add correct version * prettier * prettier * prettier * prettier * fix annoying --config .prettierrc issue
This commit is contained in:
parent
e1b4da04fe
commit
f6ec757aa0
102 changed files with 80 additions and 93 deletions
64
packages/create-docusaurus/bin/index.js
Executable file
64
packages/create-docusaurus/bin/index.js
Executable file
|
@ -0,0 +1,64 @@
|
|||
#!/usr/bin/env node
|
||||
/**
|
||||
* 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.js version not met :)`) +
|
||||
chalk.yellow(
|
||||
`\nYou are using Node.js ${process.version}, Requirement: Node.js ${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]', {isDefault: true})
|
||||
.option('--use-npm')
|
||||
.option('--skip-install')
|
||||
.option('--typescript')
|
||||
.description('Initialize website.')
|
||||
.action(
|
||||
(siteName, template, rootDir = '.', {useNpm, skipInstall, typescript}) => {
|
||||
wrapCommand(init)(path.resolve(rootDir), siteName, template, {
|
||||
useNpm,
|
||||
skipInstall,
|
||||
typescript,
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
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(1).length) {
|
||||
program.outputHelp();
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue