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:
Frank Li 2017-09-06 16:00:45 -04:00 committed by Joel Marcey
parent f803dcbc8e
commit b88d4ac014
4 changed files with 94 additions and 0 deletions

View file

@ -5,3 +5,4 @@ lib/core/MetadataBlog.js
yarn.lock yarn.lock
website website
docs docs
docusaurus-init

View 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");
}

View 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"
}
}

View file

@ -176,6 +176,7 @@ if (feature === "translations") {
} }
const containingFolder = path.basename(path.dirname(file)); const containingFolder = path.basename(path.dirname(file));
if ( if (
path.basename(file) === "gitignore" ||
containingFolder === "blog-examples-from-docusaurus" || containingFolder === "blog-examples-from-docusaurus" ||
containingFolder === "docs-examples-from-docusaurus" containingFolder === "docs-examples-from-docusaurus"
) { ) {
@ -205,3 +206,28 @@ if (feature === "translations") {
} }
}); });
} }
// add scripts to package.json file
if (fs.existsSync(CWD + "/package.json")) {
const packageContent = JSON.parse(
fs.readFileSync(CWD + "/package.json", "utf8")
);
if (!packageContent.scripts) {
packageContent.scripts = {};
}
packageContent.scripts["start"] = "docusaurus-start";
packageContent.scripts["build"] = "docusaurus-build";
packageContent.scripts["publish-gh-pages"] = "docusaurus-publish";
packageContent.scripts["examples"] = "docusaurus-examples";
packageContent.scripts["write-translations"] =
"docusaurus-write-translations";
packageContent.scripts["version"] = "docusaurus-version";
packageContent.scripts["rename-version"] = "docusaurus-rename-version";
fs.writeFileSync(
CWD + "/package.json",
JSON.stringify(packageContent, null, 2)
);
console.log(
`${chalk.green("Wrote docusaurus scripts to package.json file.")}\n`
);
}