mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-27 16:06:59 +02:00
Add docusaurus-init package and update copy-examples.js (#70)
* Add docusaurus-init package and update copy-examples.js * Use yarn by default
This commit is contained in:
parent
f803dcbc8e
commit
b88d4ac014
4 changed files with 94 additions and 0 deletions
55
docusaurus-init/initialize.js
Normal file
55
docusaurus-init/initialize.js
Normal file
|
@ -0,0 +1,55 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
/**
|
||||
* Copyright (c) 2017-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
const shell = require("shelljs");
|
||||
const chalk = require("chalk");
|
||||
const fs = require("fs");
|
||||
|
||||
const CWD = process.cwd();
|
||||
|
||||
let useYarn = false;
|
||||
if (shell.which("yarn")) {
|
||||
useYarn = true;
|
||||
}
|
||||
|
||||
if (fs.existsSync(CWD + "/website")) {
|
||||
console.error(chalk.yellow("Website folder already exists.\n"));
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
shell.cd(CWD);
|
||||
|
||||
shell.mkdir("website");
|
||||
|
||||
console.log(chalk.green("Website folder created!\n"));
|
||||
|
||||
shell.cd("website");
|
||||
|
||||
console.log(
|
||||
chalk.yellow("Installing latest version of Docusaurus in website.\n")
|
||||
);
|
||||
|
||||
const packageContent = { scripts: { examples: "docusaurus-examples" } };
|
||||
fs.writeFileSync(CWD + "/website/package.json", JSON.stringify(packageContent));
|
||||
|
||||
if (useYarn) {
|
||||
shell.exec("yarn add docusaurus --dev");
|
||||
} else {
|
||||
shell.exec("npm install docusaurus --save-dev");
|
||||
}
|
||||
|
||||
console.log(chalk.green("Docusaurus installed in website folder!\n"));
|
||||
|
||||
if (useYarn) {
|
||||
shell.exec("yarn run examples");
|
||||
} else {
|
||||
shell.exec("npm run examples");
|
||||
}
|
12
docusaurus-init/package.json
Normal file
12
docusaurus-init/package.json
Normal file
|
@ -0,0 +1,12 @@
|
|||
{
|
||||
"name": "docusaurus-init",
|
||||
"version": "1.0.0-alpha.0",
|
||||
"preferGlobal": true,
|
||||
"bin": {
|
||||
"docusaurus-init": "initialize.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"chalk": "^2.1.0",
|
||||
"shelljs": "^0.7.8"
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue