diff --git a/.npmignore b/.npmignore index f4ae33b209..32f5543c28 100644 --- a/.npmignore +++ b/.npmignore @@ -5,3 +5,4 @@ lib/core/MetadataBlog.js yarn.lock website docs +docusaurus-init diff --git a/docusaurus-init/initialize.js b/docusaurus-init/initialize.js new file mode 100644 index 0000000000..3a5d22c206 --- /dev/null +++ b/docusaurus-init/initialize.js @@ -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"); +} diff --git a/docusaurus-init/package.json b/docusaurus-init/package.json new file mode 100644 index 0000000000..0de87ae3c6 --- /dev/null +++ b/docusaurus-init/package.json @@ -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" + } +} diff --git a/lib/copy-examples.js b/lib/copy-examples.js index 3c8198ce03..abf64cbd29 100755 --- a/lib/copy-examples.js +++ b/lib/copy-examples.js @@ -176,6 +176,7 @@ if (feature === "translations") { } const containingFolder = path.basename(path.dirname(file)); if ( + path.basename(file) === "gitignore" || containingFolder === "blog-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` + ); +}