create-docusaurus 2.0.0-beta.13 → 2.0.0-beta.16
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 +36 -28
- package/lib/index.d.ts +10 -1
- package/lib/index.js +190 -110
- package/package.json +14 -15
- package/templates/classic/docusaurus.config.js +2 -2
- package/templates/classic/package.json +4 -4
- package/templates/classic/src/components/{HomepageFeatures.js → HomepageFeatures/index.js} +4 -4
- package/templates/classic/src/components/{HomepageFeatures.module.css → HomepageFeatures/styles.module.css} +0 -0
- package/templates/classic/src/css/custom.css +19 -8
- package/templates/classic/src/pages/index.js +1 -1
- package/templates/classic-typescript/package.json +5 -5
- package/templates/classic-typescript/src/components/{HomepageFeatures.tsx → HomepageFeatures/index.tsx} +4 -4
- package/templates/classic-typescript/src/pages/index.tsx +1 -1
- package/templates/facebook/.eslintrc.js +0 -1
- package/templates/facebook/.prettierrc +1 -1
- package/templates/facebook/docusaurus.config.js +3 -2
- package/templates/facebook/package.json +8 -8
- package/templates/facebook/src/css/custom.css +18 -7
- package/templates/shared/docs/intro.md +19 -7
- package/lib/.tsbuildinfo +0 -1
- package/src/index.ts +0 -322
- package/tsconfig.json +0 -11
package/bin/index.js
CHANGED
|
@@ -6,62 +6,70 @@
|
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
// @ts-check
|
|
10
|
+
|
|
11
|
+
import logger from '@docusaurus/logger';
|
|
12
|
+
import semver from 'semver';
|
|
13
|
+
import path from 'path';
|
|
14
|
+
import {program} from 'commander';
|
|
15
|
+
import {createRequire} from 'module';
|
|
16
|
+
import init from '../lib/index.js';
|
|
17
|
+
|
|
18
|
+
const packageJson = createRequire(import.meta.url)('../package.json');
|
|
19
|
+
const requiredVersion = packageJson.engines.node;
|
|
15
20
|
|
|
16
21
|
if (!semver.satisfies(process.version, requiredVersion)) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
chalk.yellow(
|
|
20
|
-
`\nYou are using Node.js ${process.version}, Requirement: Node.js ${requiredVersion}.\n`,
|
|
21
|
-
),
|
|
22
|
-
);
|
|
22
|
+
logger.error('Minimum Node.js version not met :(');
|
|
23
|
+
logger.info`You are using Node.js number=${process.version}, Requirement: Node.js number=${requiredVersion}.`;
|
|
23
24
|
process.exit(1);
|
|
24
25
|
}
|
|
25
26
|
|
|
26
27
|
function wrapCommand(fn) {
|
|
27
28
|
return (...args) =>
|
|
28
29
|
fn(...args).catch((err) => {
|
|
29
|
-
|
|
30
|
+
logger.error(err.stack);
|
|
30
31
|
process.exitCode = 1;
|
|
31
32
|
});
|
|
32
33
|
}
|
|
33
34
|
|
|
34
|
-
program
|
|
35
|
-
.version(require('../package.json').version)
|
|
36
|
-
.usage('<command> [options]');
|
|
35
|
+
program.version(packageJson.version);
|
|
37
36
|
|
|
38
37
|
program
|
|
39
|
-
.
|
|
40
|
-
.option(
|
|
41
|
-
|
|
42
|
-
|
|
38
|
+
.arguments('[siteName] [template] [rootDir]')
|
|
39
|
+
.option(
|
|
40
|
+
'-p, --package-manager <manager>',
|
|
41
|
+
'The package manager used to install dependencies. One of yarn, npm, and pnpm.',
|
|
42
|
+
)
|
|
43
|
+
.option(
|
|
44
|
+
'-s, --skip-install',
|
|
45
|
+
'Do not run package manager immediately after scaffolding',
|
|
46
|
+
)
|
|
47
|
+
.option('-t, --typescript', 'Use the TypeScript template variant')
|
|
48
|
+
.option(
|
|
49
|
+
'-g, --git-strategy <strategy>',
|
|
50
|
+
`Only used if the template is a git repository.
|
|
51
|
+
\`deep\`: preserve full history
|
|
52
|
+
\`shallow\`: clone with --depth=1
|
|
53
|
+
\`copy\`: do a shallow clone, but do not create a git repo
|
|
54
|
+
\`custom\`: enter your custom git clone command. We will prompt you for it.`,
|
|
55
|
+
)
|
|
43
56
|
.description('Initialize website.')
|
|
44
57
|
.action(
|
|
45
58
|
(
|
|
46
59
|
siteName,
|
|
47
60
|
template,
|
|
48
61
|
rootDir = '.',
|
|
49
|
-
{
|
|
62
|
+
{packageManager, skipInstall, typescript, gitStrategy} = {},
|
|
50
63
|
) => {
|
|
51
64
|
wrapCommand(init)(path.resolve(rootDir), siteName, template, {
|
|
52
|
-
|
|
65
|
+
packageManager,
|
|
53
66
|
skipInstall,
|
|
54
67
|
typescript,
|
|
68
|
+
gitStrategy,
|
|
55
69
|
});
|
|
56
70
|
},
|
|
57
71
|
);
|
|
58
72
|
|
|
59
|
-
program.arguments('<command>').action((cmd) => {
|
|
60
|
-
program.outputHelp();
|
|
61
|
-
console.log(` ${chalk.red(`\n Unknown command ${chalk.yellow(cmd)}.`)}`);
|
|
62
|
-
console.log();
|
|
63
|
-
});
|
|
64
|
-
|
|
65
73
|
program.parse(process.argv);
|
|
66
74
|
|
|
67
75
|
if (!process.argv.slice(1).length) {
|
package/lib/index.d.ts
CHANGED
|
@@ -4,8 +4,17 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
+
declare const SupportedPackageManagers: {
|
|
8
|
+
npm: string;
|
|
9
|
+
yarn: string;
|
|
10
|
+
pnpm: string;
|
|
11
|
+
};
|
|
12
|
+
declare type SupportedPackageManager = keyof typeof SupportedPackageManagers;
|
|
13
|
+
declare const gitStrategies: readonly ["deep", "shallow", "copy", "custom"];
|
|
7
14
|
export default function init(rootDir: string, siteName?: string, reqTemplate?: string, cliOptions?: Partial<{
|
|
8
|
-
|
|
15
|
+
packageManager: SupportedPackageManager;
|
|
9
16
|
skipInstall: boolean;
|
|
10
17
|
typescript: boolean;
|
|
18
|
+
gitStrategy: typeof gitStrategies[number];
|
|
11
19
|
}>): Promise<void>;
|
|
20
|
+
export {};
|
package/lib/index.js
CHANGED
|
@@ -1,49 +1,82 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/**
|
|
3
2
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
4
3
|
*
|
|
5
4
|
* This source code is licensed under the MIT license found in the
|
|
6
5
|
* LICENSE file in the root directory of this source tree.
|
|
7
6
|
*/
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const lodash_1 = require("lodash");
|
|
17
|
-
const supports_color_1 = (0, tslib_1.__importDefault)(require("supports-color"));
|
|
7
|
+
import logger from '@docusaurus/logger';
|
|
8
|
+
import fs from 'fs-extra';
|
|
9
|
+
import prompts from 'prompts';
|
|
10
|
+
import path from 'path';
|
|
11
|
+
import shell from 'shelljs';
|
|
12
|
+
import _ from 'lodash';
|
|
13
|
+
import supportsColor from 'supports-color';
|
|
14
|
+
import { fileURLToPath } from 'url';
|
|
18
15
|
const RecommendedTemplate = 'classic';
|
|
19
16
|
const TypeScriptTemplateSuffix = '-typescript';
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
17
|
+
// Only used in the rare, rare case of running globally installed create +
|
|
18
|
+
// using --skip-install. We need a default name to show the tip text
|
|
19
|
+
const DefaultPackageManager = 'npm';
|
|
20
|
+
const SupportedPackageManagers = {
|
|
21
|
+
npm: 'package-lock.json',
|
|
22
|
+
yarn: 'yarn.lock',
|
|
23
|
+
pnpm: 'pnpm-lock.yaml',
|
|
24
|
+
};
|
|
25
|
+
const PackageManagersList = Object.keys(SupportedPackageManagers);
|
|
26
|
+
async function findPackageManagerFromLockFile() {
|
|
27
|
+
for (const packageManager of PackageManagersList) {
|
|
28
|
+
const lockFilePath = path.resolve(process.cwd(), SupportedPackageManagers[packageManager]);
|
|
29
|
+
if (await fs.pathExists(lockFilePath)) {
|
|
30
|
+
return packageManager;
|
|
31
|
+
}
|
|
24
32
|
}
|
|
25
|
-
|
|
26
|
-
|
|
33
|
+
return undefined;
|
|
34
|
+
}
|
|
35
|
+
function findPackageManagerFromUserAgent() {
|
|
36
|
+
return PackageManagersList.find((packageManager) => { var _a; return (_a = process.env.npm_config_user_agent) === null || _a === void 0 ? void 0 : _a.startsWith(packageManager); });
|
|
37
|
+
}
|
|
38
|
+
async function askForPackageManagerChoice() {
|
|
39
|
+
const hasYarn = shell.exec('yarn --version', { silent: true }).code === 0;
|
|
40
|
+
const hasPNPM = shell.exec('pnpm --version', { silent: true }).code === 0;
|
|
41
|
+
if (!hasYarn && !hasPNPM) {
|
|
42
|
+
return 'npm';
|
|
43
|
+
}
|
|
44
|
+
const choices = ['npm', hasYarn && 'yarn', hasPNPM && 'pnpm']
|
|
45
|
+
.filter((p) => Boolean(p))
|
|
46
|
+
.map((p) => ({ title: p, value: p }));
|
|
47
|
+
return (await prompts({
|
|
48
|
+
type: 'select',
|
|
49
|
+
name: 'packageManager',
|
|
50
|
+
message: 'Select a package manager...',
|
|
51
|
+
choices,
|
|
52
|
+
})).packageManager;
|
|
53
|
+
}
|
|
54
|
+
async function getPackageManager(packageManagerChoice, skipInstall = false) {
|
|
55
|
+
var _a, _b;
|
|
56
|
+
if (packageManagerChoice &&
|
|
57
|
+
!PackageManagersList.includes(packageManagerChoice)) {
|
|
58
|
+
throw new Error(`Invalid package manager choice ${packageManagerChoice}. Must be one of ${PackageManagersList.join(', ')}`);
|
|
27
59
|
}
|
|
60
|
+
return ((_b = (_a = packageManagerChoice !== null && packageManagerChoice !== void 0 ? packageManagerChoice : (await findPackageManagerFromLockFile())) !== null && _a !== void 0 ? _a : findPackageManagerFromUserAgent()) !== null && _b !== void 0 ? _b :
|
|
61
|
+
// This only happens if the user has a global installation in PATH
|
|
62
|
+
(skipInstall ? DefaultPackageManager : askForPackageManagerChoice()));
|
|
28
63
|
}
|
|
29
64
|
function isValidGitRepoUrl(gitRepoUrl) {
|
|
30
65
|
return ['https://', 'git@'].some((item) => gitRepoUrl.startsWith(item));
|
|
31
66
|
}
|
|
32
67
|
async function updatePkg(pkgPath, obj) {
|
|
33
|
-
const content = await
|
|
68
|
+
const content = await fs.readFile(pkgPath, 'utf-8');
|
|
34
69
|
const pkg = JSON.parse(content);
|
|
35
70
|
const newPkg = Object.assign(pkg, obj);
|
|
36
|
-
await
|
|
71
|
+
await fs.outputFile(pkgPath, `${JSON.stringify(newPkg, null, 2)}\n`);
|
|
37
72
|
}
|
|
38
|
-
function readTemplates(templatesDir) {
|
|
39
|
-
const templates =
|
|
40
|
-
.readdirSync(templatesDir)
|
|
41
|
-
.filter((d) => !d.startsWith('.') &&
|
|
73
|
+
async function readTemplates(templatesDir) {
|
|
74
|
+
const templates = (await fs.readdir(templatesDir)).filter((d) => !d.startsWith('.') &&
|
|
42
75
|
!d.startsWith('README') &&
|
|
43
76
|
!d.endsWith(TypeScriptTemplateSuffix) &&
|
|
44
77
|
d !== 'shared');
|
|
45
78
|
// Classic should be first in list!
|
|
46
|
-
return
|
|
79
|
+
return _.sortBy(templates, (t) => t !== RecommendedTemplate);
|
|
47
80
|
}
|
|
48
81
|
function createTemplateChoices(templates) {
|
|
49
82
|
function makeNameAndValueChoice(value) {
|
|
@@ -63,31 +96,52 @@ function getTypeScriptBaseTemplate(template) {
|
|
|
63
96
|
return undefined;
|
|
64
97
|
}
|
|
65
98
|
async function copyTemplate(templatesDir, template, dest) {
|
|
66
|
-
await
|
|
67
|
-
// TypeScript variants will copy duplicate resources like CSS & config from
|
|
99
|
+
await fs.copy(path.resolve(templatesDir, 'shared'), dest);
|
|
100
|
+
// TypeScript variants will copy duplicate resources like CSS & config from
|
|
101
|
+
// base template
|
|
68
102
|
const tsBaseTemplate = getTypeScriptBaseTemplate(template);
|
|
69
103
|
if (tsBaseTemplate) {
|
|
70
|
-
const tsBaseTemplatePath =
|
|
71
|
-
await
|
|
72
|
-
filter: (filePath) =>
|
|
73
|
-
|
|
74
|
-
|
|
104
|
+
const tsBaseTemplatePath = path.resolve(templatesDir, tsBaseTemplate);
|
|
105
|
+
await fs.copy(tsBaseTemplatePath, dest, {
|
|
106
|
+
filter: async (filePath) => (await fs.stat(filePath)).isDirectory() ||
|
|
107
|
+
path.extname(filePath) === '.css' ||
|
|
108
|
+
path.basename(filePath) === 'docusaurus.config.js',
|
|
75
109
|
});
|
|
76
110
|
}
|
|
77
|
-
await
|
|
78
|
-
// Symlinks don't exist in published NPM packages anymore, so this is only
|
|
79
|
-
|
|
111
|
+
await fs.copy(path.resolve(templatesDir, template), dest, {
|
|
112
|
+
// Symlinks don't exist in published NPM packages anymore, so this is only
|
|
113
|
+
// to prevent errors during local testing
|
|
114
|
+
filter: async (filePath) => !(await fs.lstat(filePath)).isSymbolicLink(),
|
|
80
115
|
});
|
|
81
116
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
117
|
+
const gitStrategies = ['deep', 'shallow', 'copy', 'custom'];
|
|
118
|
+
async function getGitCommand(gitStrategy) {
|
|
119
|
+
switch (gitStrategy) {
|
|
120
|
+
case 'shallow':
|
|
121
|
+
case 'copy':
|
|
122
|
+
return 'git clone --recursive --depth 1';
|
|
123
|
+
case 'custom': {
|
|
124
|
+
const { command } = await prompts({
|
|
125
|
+
type: 'text',
|
|
126
|
+
name: 'command',
|
|
127
|
+
message: 'Write your own git clone command. The repository URL and destination directory will be supplied. E.g. "git clone --depth 10"',
|
|
128
|
+
});
|
|
129
|
+
return command;
|
|
130
|
+
}
|
|
131
|
+
case 'deep':
|
|
132
|
+
default:
|
|
133
|
+
return 'git clone';
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
export default async function init(rootDir, siteName, reqTemplate, cliOptions = {}) {
|
|
137
|
+
var _a;
|
|
138
|
+
const templatesDir = fileURLToPath(new URL('../templates', import.meta.url));
|
|
139
|
+
const templates = await readTemplates(templatesDir);
|
|
140
|
+
const hasTS = (templateName) => fs.pathExists(path.resolve(templatesDir, `${templateName}${TypeScriptTemplateSuffix}`));
|
|
87
141
|
let name = siteName;
|
|
88
142
|
// Prompt if siteName is not passed from CLI.
|
|
89
143
|
if (!name) {
|
|
90
|
-
const prompt = await (
|
|
144
|
+
const prompt = await prompts({
|
|
91
145
|
type: 'text',
|
|
92
146
|
name: 'name',
|
|
93
147
|
message: 'What should we name this site?',
|
|
@@ -96,25 +150,27 @@ async function init(rootDir, siteName, reqTemplate, cliOptions = {}) {
|
|
|
96
150
|
name = prompt.name;
|
|
97
151
|
}
|
|
98
152
|
if (!name) {
|
|
99
|
-
|
|
153
|
+
logger.error('A website name is required.');
|
|
154
|
+
process.exit(1);
|
|
100
155
|
}
|
|
101
|
-
const dest =
|
|
102
|
-
if (
|
|
103
|
-
|
|
156
|
+
const dest = path.resolve(rootDir, name);
|
|
157
|
+
if (await fs.pathExists(dest)) {
|
|
158
|
+
logger.error `Directory already exists at path=${dest}!`;
|
|
159
|
+
process.exit(1);
|
|
104
160
|
}
|
|
105
161
|
let template = reqTemplate;
|
|
106
162
|
let useTS = cliOptions.typescript;
|
|
107
163
|
// Prompt if template is not provided from CLI.
|
|
108
164
|
if (!template) {
|
|
109
|
-
const templatePrompt = await (
|
|
165
|
+
const templatePrompt = await prompts({
|
|
110
166
|
type: 'select',
|
|
111
167
|
name: 'template',
|
|
112
168
|
message: 'Select a template below...',
|
|
113
169
|
choices: createTemplateChoices(templates),
|
|
114
170
|
});
|
|
115
171
|
template = templatePrompt.template;
|
|
116
|
-
if (template && !useTS && hasTS(template)) {
|
|
117
|
-
const tsPrompt = await (
|
|
172
|
+
if (template && !useTS && (await hasTS(template))) {
|
|
173
|
+
const tsPrompt = await prompts({
|
|
118
174
|
type: 'confirm',
|
|
119
175
|
name: 'useTS',
|
|
120
176
|
message: 'This template is available in TypeScript. Do you want to use the TS variant?',
|
|
@@ -123,57 +179,81 @@ async function init(rootDir, siteName, reqTemplate, cliOptions = {}) {
|
|
|
123
179
|
useTS = tsPrompt.useTS;
|
|
124
180
|
}
|
|
125
181
|
}
|
|
182
|
+
let gitStrategy = (_a = cliOptions.gitStrategy) !== null && _a !== void 0 ? _a : 'deep';
|
|
126
183
|
// If user choose Git repository, we'll prompt for the url.
|
|
127
184
|
if (template === 'Git repository') {
|
|
128
|
-
const repoPrompt = await (
|
|
185
|
+
const repoPrompt = await prompts({
|
|
129
186
|
type: 'text',
|
|
130
187
|
name: 'gitRepoUrl',
|
|
131
188
|
validate: (url) => {
|
|
132
189
|
if (url && isValidGitRepoUrl(url)) {
|
|
133
190
|
return true;
|
|
134
191
|
}
|
|
135
|
-
return
|
|
192
|
+
return logger.red('Invalid repository URL');
|
|
136
193
|
},
|
|
137
|
-
message:
|
|
194
|
+
message: logger.interpolate `Enter a repository URL from GitHub, Bitbucket, GitLab, or any other public repo.
|
|
195
|
+
(e.g: path=${'https://github.com/ownerName/repoName.git'})`,
|
|
138
196
|
});
|
|
197
|
+
({ gitStrategy } = await prompts({
|
|
198
|
+
type: 'select',
|
|
199
|
+
name: 'gitStrategy',
|
|
200
|
+
message: 'How should we clone this repo?',
|
|
201
|
+
choices: [
|
|
202
|
+
{ title: 'Deep clone: preserve full history', value: 'deep' },
|
|
203
|
+
{ title: 'Shallow clone: clone with --depth=1', value: 'shallow' },
|
|
204
|
+
{
|
|
205
|
+
title: 'Copy: do a shallow clone, but do not create a git repo',
|
|
206
|
+
value: 'copy',
|
|
207
|
+
},
|
|
208
|
+
{ title: 'Custom: enter your custom git clone command', value: 'custom' },
|
|
209
|
+
],
|
|
210
|
+
}));
|
|
139
211
|
template = repoPrompt.gitRepoUrl;
|
|
140
212
|
}
|
|
141
213
|
else if (template === 'Local template') {
|
|
142
|
-
const dirPrompt = await (
|
|
214
|
+
const dirPrompt = await prompts({
|
|
143
215
|
type: 'text',
|
|
144
216
|
name: 'templateDir',
|
|
145
|
-
validate: (dir) => {
|
|
217
|
+
validate: async (dir) => {
|
|
146
218
|
if (dir) {
|
|
147
|
-
const fullDir =
|
|
148
|
-
if (
|
|
219
|
+
const fullDir = path.resolve(process.cwd(), dir);
|
|
220
|
+
if (await fs.pathExists(fullDir)) {
|
|
149
221
|
return true;
|
|
150
222
|
}
|
|
151
|
-
return
|
|
223
|
+
return logger.red(logger.interpolate `path=${fullDir} does not exist.`);
|
|
152
224
|
}
|
|
153
|
-
return
|
|
225
|
+
return logger.red('Please enter a valid path.');
|
|
154
226
|
},
|
|
155
227
|
message: 'Enter a local folder path, relative to the current working directory.',
|
|
156
228
|
});
|
|
157
229
|
template = dirPrompt.templateDir;
|
|
158
230
|
}
|
|
159
231
|
if (!template) {
|
|
160
|
-
|
|
232
|
+
logger.error('Template should not be empty');
|
|
233
|
+
process.exit(1);
|
|
161
234
|
}
|
|
162
|
-
|
|
163
|
-
${chalk_1.default.cyan('Creating new Docusaurus project...')}
|
|
164
|
-
`);
|
|
235
|
+
logger.info('Creating new Docusaurus project...');
|
|
165
236
|
if (isValidGitRepoUrl(template)) {
|
|
166
|
-
|
|
167
|
-
if (
|
|
168
|
-
.
|
|
169
|
-
|
|
237
|
+
logger.info `Cloning Git template path=${template}...`;
|
|
238
|
+
if (!gitStrategies.includes(gitStrategy)) {
|
|
239
|
+
logger.error `Invalid git strategy: name=${gitStrategy}. Value must be one of ${gitStrategies.join(', ')}.`;
|
|
240
|
+
process.exit(1);
|
|
241
|
+
}
|
|
242
|
+
const command = await getGitCommand(gitStrategy);
|
|
243
|
+
if (shell.exec(`${command} ${template} ${dest}`).code !== 0) {
|
|
244
|
+
logger.error `Cloning Git template name=${template} failed!`;
|
|
245
|
+
process.exit(1);
|
|
246
|
+
}
|
|
247
|
+
if (gitStrategy === 'copy') {
|
|
248
|
+
await fs.remove(path.join(dest, '.git'));
|
|
170
249
|
}
|
|
171
250
|
}
|
|
172
251
|
else if (templates.includes(template)) {
|
|
173
252
|
// Docusaurus templates.
|
|
174
253
|
if (useTS) {
|
|
175
|
-
if (!hasTS(template)) {
|
|
176
|
-
|
|
254
|
+
if (!(await hasTS(template))) {
|
|
255
|
+
logger.error `Template name=${template} doesn't provide the Typescript variant.`;
|
|
256
|
+
process.exit(1);
|
|
177
257
|
}
|
|
178
258
|
template = `${template}${TypeScriptTemplateSuffix}`;
|
|
179
259
|
}
|
|
@@ -181,87 +261,87 @@ ${chalk_1.default.cyan('Creating new Docusaurus project...')}
|
|
|
181
261
|
await copyTemplate(templatesDir, template, dest);
|
|
182
262
|
}
|
|
183
263
|
catch (err) {
|
|
184
|
-
|
|
264
|
+
logger.error `Copying Docusaurus template name=${template} failed!`;
|
|
185
265
|
throw err;
|
|
186
266
|
}
|
|
187
267
|
}
|
|
188
|
-
else if (
|
|
189
|
-
const templateDir =
|
|
268
|
+
else if (await fs.pathExists(path.resolve(process.cwd(), template))) {
|
|
269
|
+
const templateDir = path.resolve(process.cwd(), template);
|
|
190
270
|
try {
|
|
191
|
-
await
|
|
271
|
+
await fs.copy(templateDir, dest);
|
|
192
272
|
}
|
|
193
273
|
catch (err) {
|
|
194
|
-
|
|
274
|
+
logger.error `Copying local template path=${templateDir} failed!`;
|
|
195
275
|
throw err;
|
|
196
276
|
}
|
|
197
277
|
}
|
|
198
278
|
else {
|
|
199
|
-
|
|
279
|
+
logger.error('Invalid template.');
|
|
280
|
+
process.exit(1);
|
|
200
281
|
}
|
|
201
282
|
// Update package.json info.
|
|
202
283
|
try {
|
|
203
|
-
await updatePkg(
|
|
204
|
-
name:
|
|
284
|
+
await updatePkg(path.join(dest, 'package.json'), {
|
|
285
|
+
name: _.kebabCase(name),
|
|
205
286
|
version: '0.0.0',
|
|
206
287
|
private: true,
|
|
207
288
|
});
|
|
208
289
|
}
|
|
209
290
|
catch (err) {
|
|
210
|
-
|
|
291
|
+
logger.error('Failed to update package.json.');
|
|
211
292
|
throw err;
|
|
212
293
|
}
|
|
213
294
|
// We need to rename the gitignore file to .gitignore
|
|
214
|
-
if (!
|
|
215
|
-
|
|
216
|
-
await
|
|
295
|
+
if (!(await fs.pathExists(path.join(dest, '.gitignore'))) &&
|
|
296
|
+
(await fs.pathExists(path.join(dest, 'gitignore')))) {
|
|
297
|
+
await fs.move(path.join(dest, 'gitignore'), path.join(dest, '.gitignore'));
|
|
217
298
|
}
|
|
218
|
-
if (
|
|
219
|
-
|
|
299
|
+
if (await fs.pathExists(path.join(dest, 'gitignore'))) {
|
|
300
|
+
await fs.remove(path.join(dest, 'gitignore'));
|
|
220
301
|
}
|
|
221
|
-
|
|
302
|
+
// Display the most elegant way to cd.
|
|
303
|
+
const cdpath = path.relative('.', dest);
|
|
304
|
+
const pkgManager = await getPackageManager(cliOptions.packageManager, cliOptions.skipInstall);
|
|
222
305
|
if (!cliOptions.skipInstall) {
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
env
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
},
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
306
|
+
shell.cd(dest);
|
|
307
|
+
logger.info `Installing dependencies with name=${pkgManager}...`;
|
|
308
|
+
if (shell.exec(pkgManager === 'yarn' ? 'yarn' : `${pkgManager} install --color always`, {
|
|
309
|
+
env: {
|
|
310
|
+
...process.env,
|
|
311
|
+
// Force coloring the output, since the command is invoked,
|
|
312
|
+
// by shelljs which is not the interactive shell
|
|
313
|
+
...(supportsColor.stdout ? { FORCE_COLOR: '1' } : {}),
|
|
314
|
+
},
|
|
315
|
+
}).code !== 0) {
|
|
316
|
+
logger.error('Dependency installation failed.');
|
|
317
|
+
logger.info `The site directory has already been created, and you can retry by typing:
|
|
318
|
+
|
|
319
|
+
code=${`cd ${cdpath}`}
|
|
320
|
+
code=${`${pkgManager} install`}`;
|
|
321
|
+
process.exit(0);
|
|
236
322
|
}
|
|
237
323
|
}
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
? name
|
|
242
|
-
: path_1.default.relative(process.cwd(), name);
|
|
243
|
-
console.log(`
|
|
244
|
-
Successfully created "${chalk_1.default.cyan(cdpath)}".
|
|
245
|
-
Inside that directory, you can run several commands:
|
|
324
|
+
const useNpm = pkgManager === 'npm';
|
|
325
|
+
logger.success `Created path=${cdpath}.`;
|
|
326
|
+
logger.info `Inside that directory, you can run several commands:
|
|
246
327
|
|
|
247
|
-
|
|
328
|
+
code=${`${pkgManager} start`}
|
|
248
329
|
Starts the development server.
|
|
249
330
|
|
|
250
|
-
|
|
331
|
+
code=${`${pkgManager} ${useNpm ? 'run ' : ''}build`}
|
|
251
332
|
Bundles your website into static files for production.
|
|
252
333
|
|
|
253
|
-
|
|
334
|
+
code=${`${pkgManager} ${useNpm ? 'run ' : ''}serve`}
|
|
254
335
|
Serves the built website locally.
|
|
255
336
|
|
|
256
|
-
|
|
337
|
+
code=${`${pkgManager} deploy`}
|
|
257
338
|
Publishes the website to GitHub pages.
|
|
258
339
|
|
|
259
340
|
We recommend that you begin by typing:
|
|
260
341
|
|
|
261
|
-
|
|
262
|
-
|
|
342
|
+
code=${`cd ${cdpath}`}
|
|
343
|
+
code=${`${pkgManager} start`}
|
|
263
344
|
|
|
264
345
|
Happy building awesome websites!
|
|
265
|
-
|
|
346
|
+
`;
|
|
266
347
|
}
|
|
267
|
-
exports.default = init;
|
package/package.json
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-docusaurus",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.16",
|
|
4
4
|
"description": "Create Docusaurus apps easily.",
|
|
5
|
+
"type": "module",
|
|
5
6
|
"repository": {
|
|
6
7
|
"type": "git",
|
|
7
8
|
"url": "https://github.com/facebook/docusaurus.git",
|
|
@@ -15,29 +16,27 @@
|
|
|
15
16
|
"build": "tsc",
|
|
16
17
|
"watch": "tsc --watch"
|
|
17
18
|
},
|
|
18
|
-
"bin":
|
|
19
|
-
"create-docusaurus": "bin/index.js"
|
|
20
|
-
},
|
|
19
|
+
"bin": "bin/index.js",
|
|
21
20
|
"publishConfig": {
|
|
22
21
|
"access": "public"
|
|
23
22
|
},
|
|
24
23
|
"license": "MIT",
|
|
25
24
|
"dependencies": {
|
|
26
|
-
"
|
|
25
|
+
"@docusaurus/logger": "2.0.0-beta.16",
|
|
27
26
|
"commander": "^5.1.0",
|
|
28
|
-
"fs-extra": "^10.0.
|
|
29
|
-
"lodash": "^4.17.
|
|
30
|
-
"prompts": "^2.4.
|
|
31
|
-
"semver": "^7.3.
|
|
32
|
-
"shelljs": "^0.8.
|
|
33
|
-
"supports-color": "^
|
|
27
|
+
"fs-extra": "^10.0.1",
|
|
28
|
+
"lodash": "^4.17.21",
|
|
29
|
+
"prompts": "^2.4.2",
|
|
30
|
+
"semver": "^7.3.5",
|
|
31
|
+
"shelljs": "^0.8.5",
|
|
32
|
+
"supports-color": "^9.2.1",
|
|
34
33
|
"tslib": "^2.3.1"
|
|
35
34
|
},
|
|
36
|
-
"engines": {
|
|
37
|
-
"node": ">=14"
|
|
38
|
-
},
|
|
39
35
|
"devDependencies": {
|
|
40
36
|
"@types/supports-color": "^8.1.1"
|
|
41
37
|
},
|
|
42
|
-
"
|
|
38
|
+
"engines": {
|
|
39
|
+
"node": ">=14"
|
|
40
|
+
},
|
|
41
|
+
"gitHead": "eb43c4d4f95a4fb97dc9bb9dc615413e0dc2e1e7"
|
|
43
42
|
}
|
|
@@ -24,13 +24,13 @@ const config = {
|
|
|
24
24
|
docs: {
|
|
25
25
|
sidebarPath: require.resolve('./sidebars.js'),
|
|
26
26
|
// Please change this to your repo.
|
|
27
|
-
editUrl: 'https://github.com/facebook/docusaurus/
|
|
27
|
+
editUrl: 'https://github.com/facebook/docusaurus/tree/main/packages/create-docusaurus/templates/shared/',
|
|
28
28
|
},
|
|
29
29
|
blog: {
|
|
30
30
|
showReadingTime: true,
|
|
31
31
|
// Please change this to your repo.
|
|
32
32
|
editUrl:
|
|
33
|
-
'https://github.com/facebook/docusaurus/
|
|
33
|
+
'https://github.com/facebook/docusaurus/tree/main/packages/create-docusaurus/templates/shared/',
|
|
34
34
|
},
|
|
35
35
|
theme: {
|
|
36
36
|
customCss: require.resolve('./src/css/custom.css'),
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "docusaurus-2-classic-template",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.16",
|
|
4
4
|
"private": true,
|
|
5
5
|
"scripts": {
|
|
6
6
|
"docusaurus": "docusaurus",
|
|
@@ -14,9 +14,9 @@
|
|
|
14
14
|
"write-heading-ids": "docusaurus write-heading-ids"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@docusaurus/core": "2.0.0-beta.
|
|
18
|
-
"@docusaurus/preset-classic": "2.0.0-beta.
|
|
19
|
-
"@mdx-js/react": "^1.6.
|
|
17
|
+
"@docusaurus/core": "2.0.0-beta.16",
|
|
18
|
+
"@docusaurus/preset-classic": "2.0.0-beta.16",
|
|
19
|
+
"@mdx-js/react": "^1.6.22",
|
|
20
20
|
"clsx": "^1.1.1",
|
|
21
21
|
"prism-react-renderer": "^1.2.1",
|
|
22
22
|
"react": "^17.0.1",
|