Skip to content

Commit b88d4ac

Browse files
Frank LiJoelMarcey
Frank Li
authored andcommitted
Add docusaurus-init package and update copy-examples.js (facebook#70)
* Add docusaurus-init package and update copy-examples.js * Use yarn by default
1 parent f803dcb commit b88d4ac

File tree

4 files changed

+94
-0
lines changed

4 files changed

+94
-0
lines changed

.npmignore

+1
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ lib/core/MetadataBlog.js
55
yarn.lock
66
website
77
docs
8+
docusaurus-init

docusaurus-init/initialize.js

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#!/usr/bin/env node
2+
3+
/**
4+
* Copyright (c) 2017-present, Facebook, Inc.
5+
* All rights reserved.
6+
*
7+
* This source code is licensed under the BSD-style license found in the
8+
* LICENSE file in the root directory of this source tree. An additional grant
9+
* of patent rights can be found in the PATENTS file in the same directory.
10+
*/
11+
12+
const shell = require("shelljs");
13+
const chalk = require("chalk");
14+
const fs = require("fs");
15+
16+
const CWD = process.cwd();
17+
18+
let useYarn = false;
19+
if (shell.which("yarn")) {
20+
useYarn = true;
21+
}
22+
23+
if (fs.existsSync(CWD + "/website")) {
24+
console.error(chalk.yellow("Website folder already exists.\n"));
25+
process.exit(1);
26+
}
27+
28+
shell.cd(CWD);
29+
30+
shell.mkdir("website");
31+
32+
console.log(chalk.green("Website folder created!\n"));
33+
34+
shell.cd("website");
35+
36+
console.log(
37+
chalk.yellow("Installing latest version of Docusaurus in website.\n")
38+
);
39+
40+
const packageContent = { scripts: { examples: "docusaurus-examples" } };
41+
fs.writeFileSync(CWD + "/website/package.json", JSON.stringify(packageContent));
42+
43+
if (useYarn) {
44+
shell.exec("yarn add docusaurus --dev");
45+
} else {
46+
shell.exec("npm install docusaurus --save-dev");
47+
}
48+
49+
console.log(chalk.green("Docusaurus installed in website folder!\n"));
50+
51+
if (useYarn) {
52+
shell.exec("yarn run examples");
53+
} else {
54+
shell.exec("npm run examples");
55+
}

docusaurus-init/package.json

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"name": "docusaurus-init",
3+
"version": "1.0.0-alpha.0",
4+
"preferGlobal": true,
5+
"bin": {
6+
"docusaurus-init": "initialize.js"
7+
},
8+
"dependencies": {
9+
"chalk": "^2.1.0",
10+
"shelljs": "^0.7.8"
11+
}
12+
}

lib/copy-examples.js

+26
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ if (feature === "translations") {
176176
}
177177
const containingFolder = path.basename(path.dirname(file));
178178
if (
179+
path.basename(file) === "gitignore" ||
179180
containingFolder === "blog-examples-from-docusaurus" ||
180181
containingFolder === "docs-examples-from-docusaurus"
181182
) {
@@ -205,3 +206,28 @@ if (feature === "translations") {
205206
}
206207
});
207208
}
209+
210+
// add scripts to package.json file
211+
if (fs.existsSync(CWD + "/package.json")) {
212+
const packageContent = JSON.parse(
213+
fs.readFileSync(CWD + "/package.json", "utf8")
214+
);
215+
if (!packageContent.scripts) {
216+
packageContent.scripts = {};
217+
}
218+
packageContent.scripts["start"] = "docusaurus-start";
219+
packageContent.scripts["build"] = "docusaurus-build";
220+
packageContent.scripts["publish-gh-pages"] = "docusaurus-publish";
221+
packageContent.scripts["examples"] = "docusaurus-examples";
222+
packageContent.scripts["write-translations"] =
223+
"docusaurus-write-translations";
224+
packageContent.scripts["version"] = "docusaurus-version";
225+
packageContent.scripts["rename-version"] = "docusaurus-rename-version";
226+
fs.writeFileSync(
227+
CWD + "/package.json",
228+
JSON.stringify(packageContent, null, 2)
229+
);
230+
console.log(
231+
`${chalk.green("Wrote docusaurus scripts to package.json file.")}\n`
232+
);
233+
}

0 commit comments

Comments
 (0)