mirror of
https://github.com/facebook/docusaurus.git
synced 2025-04-29 18:27:56 +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
|
@ -5,3 +5,4 @@ lib/core/MetadataBlog.js
|
||||||
yarn.lock
|
yarn.lock
|
||||||
website
|
website
|
||||||
docs
|
docs
|
||||||
|
docusaurus-init
|
||||||
|
|
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"
|
||||||
|
}
|
||||||
|
}
|
|
@ -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`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue