create-docusaurus 2.0.0-beta.9 → 2.0.0-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/index.js +43 -41
- package/lib/index.d.ts +16 -5
- package/lib/index.js +348 -156
- package/package.json +18 -18
- package/templates/classic/docusaurus.config.js +17 -3
- package/templates/classic/package.json +14 -11
- package/templates/classic/src/components/{HomepageFeatures.js → HomepageFeatures/index.js} +5 -5
- package/templates/classic/src/components/{HomepageFeatures.module.css → HomepageFeatures/styles.module.css} +0 -0
- package/templates/classic/src/css/custom.css +18 -16
- package/templates/classic/src/pages/index.js +3 -2
- package/templates/classic/src/pages/index.module.css +1 -1
- package/templates/classic-typescript/package.json +14 -14
- package/templates/classic-typescript/src/components/{HomepageFeatures.tsx → HomepageFeatures/index.tsx} +7 -13
- package/templates/classic-typescript/src/pages/index.tsx +3 -2
- package/templates/facebook/.eslintrc.js +10 -4
- package/templates/facebook/.prettierrc +1 -1
- package/templates/facebook/.stylelintrc.js +1 -1
- package/templates/facebook/README.md +9 -1
- package/templates/facebook/babel.config.js +1 -1
- package/templates/facebook/docusaurus.config.js +22 -14
- package/templates/facebook/package.json +24 -24
- package/templates/facebook/sidebars.js +1 -1
- package/templates/facebook/src/css/custom.css +17 -13
- package/templates/facebook/src/pages/index.js +1 -1
- package/templates/facebook/src/pages/styles.module.css +2 -2
- package/templates/facebook/static/img/meta_opensource_logo.svg +1 -0
- package/templates/facebook/static/img/meta_opensource_logo_negative.svg +1 -0
- package/templates/shared/README.md +9 -1
- package/templates/shared/docs/intro.md +19 -7
- package/templates/shared/docs/tutorial-basics/_category_.json +5 -1
- package/templates/shared/docs/tutorial-basics/create-a-blog-post.md +1 -1
- package/templates/shared/docs/tutorial-basics/create-a-document.md +6 -6
- package/templates/shared/docs/tutorial-basics/create-a-page.md +5 -5
- package/templates/shared/docs/tutorial-basics/deploy-your-site.md +1 -1
- package/templates/shared/docs/tutorial-basics/markdown-features.mdx +3 -1
- package/templates/shared/docs/tutorial-extras/_category_.json +4 -1
- package/templates/shared/docs/tutorial-extras/img/docsVersionDropdown.png +0 -0
- package/templates/shared/docs/tutorial-extras/img/localeDropdown.png +0 -0
- package/templates/shared/docs/tutorial-extras/manage-docs-versions.md +1 -1
- package/templates/shared/docs/tutorial-extras/translate-your-site.md +2 -2
- package/templates/shared/static/img/undraw_docusaurus_mountain.svg +1 -0
- package/templates/shared/static/img/undraw_docusaurus_react.svg +1 -0
- package/templates/shared/static/img/undraw_docusaurus_tree.svg +40 -1
- package/lib/.tsbuildinfo +0 -1
- package/src/index.ts +0 -289
- package/templates/facebook/static/img/oss_logo.png +0 -0
- package/templates/shared/static/img/tutorial/docsVersionDropdown.png +0 -0
- package/templates/shared/static/img/tutorial/localeDropdown.png +0 -0
- package/tsconfig.json +0 -11
package/src/index.ts
DELETED
|
@@ -1,289 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the MIT license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import chalk from 'chalk';
|
|
9
|
-
import fs from 'fs-extra';
|
|
10
|
-
import {execSync} from 'child_process';
|
|
11
|
-
import prompts, {Choice} from 'prompts';
|
|
12
|
-
import path from 'path';
|
|
13
|
-
import shell from 'shelljs';
|
|
14
|
-
import {kebabCase, sortBy} from 'lodash';
|
|
15
|
-
import supportsColor from 'supports-color';
|
|
16
|
-
|
|
17
|
-
const RecommendedTemplate = 'classic';
|
|
18
|
-
const TypeScriptTemplateSuffix = '-typescript';
|
|
19
|
-
|
|
20
|
-
function hasYarn() {
|
|
21
|
-
try {
|
|
22
|
-
execSync('yarnpkg --version', {stdio: 'ignore'});
|
|
23
|
-
return true;
|
|
24
|
-
} catch (e) {
|
|
25
|
-
return false;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function isValidGitRepoUrl(gitRepoUrl: string) {
|
|
30
|
-
return ['https://', 'git@'].some((item) => gitRepoUrl.startsWith(item));
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
async function updatePkg(pkgPath: string, obj: Record<string, unknown>) {
|
|
34
|
-
const content = await fs.readFile(pkgPath, 'utf-8');
|
|
35
|
-
const pkg = JSON.parse(content);
|
|
36
|
-
const newPkg = Object.assign(pkg, obj);
|
|
37
|
-
|
|
38
|
-
await fs.outputFile(pkgPath, JSON.stringify(newPkg, null, 2));
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function readTemplates(templatesDir: string) {
|
|
42
|
-
const templates = fs
|
|
43
|
-
.readdirSync(templatesDir)
|
|
44
|
-
.filter(
|
|
45
|
-
(d) =>
|
|
46
|
-
!d.startsWith('.') &&
|
|
47
|
-
!d.startsWith('README') &&
|
|
48
|
-
!d.endsWith(TypeScriptTemplateSuffix) &&
|
|
49
|
-
d !== 'shared',
|
|
50
|
-
);
|
|
51
|
-
|
|
52
|
-
// Classic should be first in list!
|
|
53
|
-
return sortBy(templates, (t) => t !== RecommendedTemplate);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
function createTemplateChoices(templates: string[]) {
|
|
57
|
-
function makeNameAndValueChoice(value: string): Choice {
|
|
58
|
-
const title =
|
|
59
|
-
value === RecommendedTemplate ? `${value} (recommended)` : value;
|
|
60
|
-
return {title, value};
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
return [
|
|
64
|
-
...templates.map((template) => makeNameAndValueChoice(template)),
|
|
65
|
-
makeNameAndValueChoice('Git repository'),
|
|
66
|
-
];
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
function getTypeScriptBaseTemplate(template: string): string | undefined {
|
|
70
|
-
if (template.endsWith(TypeScriptTemplateSuffix)) {
|
|
71
|
-
return template.replace(TypeScriptTemplateSuffix, '');
|
|
72
|
-
}
|
|
73
|
-
return undefined;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
async function copyTemplate(
|
|
77
|
-
templatesDir: string,
|
|
78
|
-
template: string,
|
|
79
|
-
dest: string,
|
|
80
|
-
) {
|
|
81
|
-
await fs.copy(path.resolve(templatesDir, 'shared'), dest);
|
|
82
|
-
|
|
83
|
-
// TypeScript variants will copy duplicate resources like CSS & config from base template
|
|
84
|
-
const tsBaseTemplate = getTypeScriptBaseTemplate(template);
|
|
85
|
-
if (tsBaseTemplate) {
|
|
86
|
-
const tsBaseTemplatePath = path.resolve(templatesDir, tsBaseTemplate);
|
|
87
|
-
await fs.copy(tsBaseTemplatePath, dest, {
|
|
88
|
-
filter: (filePath) =>
|
|
89
|
-
fs.statSync(filePath).isDirectory() ||
|
|
90
|
-
path.extname(filePath) === '.css' ||
|
|
91
|
-
path.basename(filePath) === 'docusaurus.config.js',
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
await fs.copy(path.resolve(templatesDir, template), dest, {
|
|
96
|
-
// Symlinks don't exist in published NPM packages anymore, so this is only to prevent errors during local testing
|
|
97
|
-
filter: (filePath) => !fs.lstatSync(filePath).isSymbolicLink(),
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
export default async function init(
|
|
102
|
-
rootDir: string,
|
|
103
|
-
siteName?: string,
|
|
104
|
-
reqTemplate?: string,
|
|
105
|
-
cliOptions: Partial<{
|
|
106
|
-
useNpm: boolean;
|
|
107
|
-
skipInstall: boolean;
|
|
108
|
-
typescript: boolean;
|
|
109
|
-
}> = {},
|
|
110
|
-
): Promise<void> {
|
|
111
|
-
const useYarn = cliOptions.useNpm ? false : hasYarn();
|
|
112
|
-
const templatesDir = path.resolve(__dirname, '../templates');
|
|
113
|
-
const templates = readTemplates(templatesDir);
|
|
114
|
-
const hasTS = (templateName: string) =>
|
|
115
|
-
fs.pathExistsSync(
|
|
116
|
-
path.resolve(templatesDir, `${templateName}${TypeScriptTemplateSuffix}`),
|
|
117
|
-
);
|
|
118
|
-
|
|
119
|
-
let name = siteName;
|
|
120
|
-
|
|
121
|
-
// Prompt if siteName is not passed from CLI.
|
|
122
|
-
if (!name) {
|
|
123
|
-
const prompt = await prompts({
|
|
124
|
-
type: 'text',
|
|
125
|
-
name: 'name',
|
|
126
|
-
message: 'What should we name this site?',
|
|
127
|
-
initial: 'website',
|
|
128
|
-
});
|
|
129
|
-
name = prompt.name;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
if (!name) {
|
|
133
|
-
throw new Error(chalk.red('A website name is required.'));
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
const dest = path.resolve(rootDir, name);
|
|
137
|
-
if (fs.existsSync(dest)) {
|
|
138
|
-
throw new Error(`Directory already exists at "${dest}"!`);
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
let template = reqTemplate;
|
|
142
|
-
let useTS = cliOptions.typescript;
|
|
143
|
-
// Prompt if template is not provided from CLI.
|
|
144
|
-
if (!template) {
|
|
145
|
-
const templatePrompt = await prompts({
|
|
146
|
-
type: 'select',
|
|
147
|
-
name: 'template',
|
|
148
|
-
message: 'Select a template below...',
|
|
149
|
-
choices: createTemplateChoices(templates),
|
|
150
|
-
});
|
|
151
|
-
template = templatePrompt.template;
|
|
152
|
-
if (template && !useTS && hasTS(template)) {
|
|
153
|
-
const tsPrompt = await prompts({
|
|
154
|
-
type: 'confirm',
|
|
155
|
-
name: 'useTS',
|
|
156
|
-
message:
|
|
157
|
-
'This template is available in TypeScript. Do you want to use the TS variant?',
|
|
158
|
-
initial: false,
|
|
159
|
-
});
|
|
160
|
-
useTS = tsPrompt.useTS;
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
// If user choose Git repository, we'll prompt for the url.
|
|
165
|
-
if (template === 'Git repository') {
|
|
166
|
-
const repoPrompt = await prompts({
|
|
167
|
-
type: 'text',
|
|
168
|
-
name: 'gitRepoUrl',
|
|
169
|
-
validate: (url?: string) => {
|
|
170
|
-
if (url && isValidGitRepoUrl(url)) {
|
|
171
|
-
return true;
|
|
172
|
-
}
|
|
173
|
-
return chalk.red(`Invalid repository URL`);
|
|
174
|
-
},
|
|
175
|
-
message:
|
|
176
|
-
'Enter a repository URL from GitHub, Bitbucket, GitLab, or any other public repo.\n(e.g: https://github.com/ownerName/repoName.git)',
|
|
177
|
-
});
|
|
178
|
-
template = repoPrompt.gitRepoUrl;
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
console.log(`
|
|
182
|
-
${chalk.cyan('Creating new Docusaurus project...')}
|
|
183
|
-
`);
|
|
184
|
-
|
|
185
|
-
if (template && isValidGitRepoUrl(template)) {
|
|
186
|
-
console.log(`Cloning Git template ${chalk.cyan(template)}...`);
|
|
187
|
-
if (
|
|
188
|
-
shell.exec(`git clone --recursive ${template} ${dest}`, {silent: true})
|
|
189
|
-
.code !== 0
|
|
190
|
-
) {
|
|
191
|
-
throw new Error(chalk.red(`Cloning Git template ${template} failed!`));
|
|
192
|
-
}
|
|
193
|
-
} else if (template && templates.includes(template)) {
|
|
194
|
-
// Docusaurus templates.
|
|
195
|
-
if (useTS) {
|
|
196
|
-
if (!hasTS(template)) {
|
|
197
|
-
throw new Error(
|
|
198
|
-
`Template ${template} doesn't provide the Typescript variant.`,
|
|
199
|
-
);
|
|
200
|
-
}
|
|
201
|
-
template = `${template}${TypeScriptTemplateSuffix}`;
|
|
202
|
-
}
|
|
203
|
-
try {
|
|
204
|
-
await copyTemplate(templatesDir, template, dest);
|
|
205
|
-
} catch (err) {
|
|
206
|
-
console.log(
|
|
207
|
-
`Copying Docusaurus template ${chalk.cyan(template)} failed!`,
|
|
208
|
-
);
|
|
209
|
-
throw err;
|
|
210
|
-
}
|
|
211
|
-
} else {
|
|
212
|
-
throw new Error('Invalid template.');
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
// Update package.json info.
|
|
216
|
-
try {
|
|
217
|
-
await updatePkg(path.join(dest, 'package.json'), {
|
|
218
|
-
name: kebabCase(name),
|
|
219
|
-
version: '0.0.0',
|
|
220
|
-
private: true,
|
|
221
|
-
});
|
|
222
|
-
} catch (err) {
|
|
223
|
-
console.log(chalk.red('Failed to update package.json.'));
|
|
224
|
-
throw err;
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
// We need to rename the gitignore file to .gitignore
|
|
228
|
-
if (
|
|
229
|
-
!fs.pathExistsSync(path.join(dest, '.gitignore')) &&
|
|
230
|
-
fs.pathExistsSync(path.join(dest, 'gitignore'))
|
|
231
|
-
) {
|
|
232
|
-
await fs.move(path.join(dest, 'gitignore'), path.join(dest, '.gitignore'));
|
|
233
|
-
}
|
|
234
|
-
if (fs.pathExistsSync(path.join(dest, 'gitignore'))) {
|
|
235
|
-
fs.removeSync(path.join(dest, 'gitignore'));
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
const pkgManager = useYarn ? 'yarn' : 'npm';
|
|
239
|
-
if (!cliOptions.skipInstall) {
|
|
240
|
-
console.log(`Installing dependencies with ${chalk.cyan(pkgManager)}...`);
|
|
241
|
-
|
|
242
|
-
try {
|
|
243
|
-
// Use force coloring the output, since the command is invoked by shelljs, which is not the interactive shell
|
|
244
|
-
shell.exec(
|
|
245
|
-
`cd "${name}" && ${useYarn ? 'yarn' : 'npm install --color always'}`,
|
|
246
|
-
{
|
|
247
|
-
env: {
|
|
248
|
-
...process.env,
|
|
249
|
-
...(supportsColor.stdout ? {FORCE_COLOR: '1'} : {}),
|
|
250
|
-
},
|
|
251
|
-
},
|
|
252
|
-
);
|
|
253
|
-
} catch (err) {
|
|
254
|
-
console.log(chalk.red('Installation failed.'));
|
|
255
|
-
throw err;
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
console.log();
|
|
259
|
-
|
|
260
|
-
// Display the most elegant way to cd.
|
|
261
|
-
const cdpath =
|
|
262
|
-
path.join(process.cwd(), name) === dest
|
|
263
|
-
? name
|
|
264
|
-
: path.relative(process.cwd(), name);
|
|
265
|
-
|
|
266
|
-
console.log(`
|
|
267
|
-
Successfully created "${chalk.cyan(cdpath)}".
|
|
268
|
-
Inside that directory, you can run several commands:
|
|
269
|
-
|
|
270
|
-
${chalk.cyan(`${pkgManager} start`)}
|
|
271
|
-
Starts the development server.
|
|
272
|
-
|
|
273
|
-
${chalk.cyan(`${pkgManager} ${useYarn ? '' : 'run '}build`)}
|
|
274
|
-
Bundles your website into static files for production.
|
|
275
|
-
|
|
276
|
-
${chalk.cyan(`${pkgManager} ${useYarn ? '' : 'run '}serve`)}
|
|
277
|
-
Serves the built website locally.
|
|
278
|
-
|
|
279
|
-
${chalk.cyan(`${pkgManager} deploy`)}
|
|
280
|
-
Publishes the website to GitHub pages.
|
|
281
|
-
|
|
282
|
-
We recommend that you begin by typing:
|
|
283
|
-
|
|
284
|
-
${chalk.cyan('cd')} ${cdpath}
|
|
285
|
-
${chalk.cyan(`${pkgManager} start`)}
|
|
286
|
-
|
|
287
|
-
Happy building awesome websites!
|
|
288
|
-
`);
|
|
289
|
-
}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|