create-docusaurus 3.10.1-canary-6621 → 3.10.1-canary-6624
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/lib/commands.d.ts +12 -0
- package/lib/commands.js +77 -0
- package/lib/constants.d.ts +34 -0
- package/lib/constants.js +23 -0
- package/lib/index.d.ts +2 -10
- package/lib/index.js +24 -103
- package/lib/prompts.d.ts +1 -0
- package/lib/prompts.js +12 -0
- package/lib/utils.d.ts +9 -11
- package/lib/utils.js +43 -28
- package/package.json +3 -3
- package/templates/classic/package.json +6 -6
- package/templates/classic-typescript/package.json +7 -7
- package/lib/types.d.ts +0 -7
- package/lib/types.js +0 -7
|
@@ -0,0 +1,12 @@
|
|
|
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
|
+
import { type PackageManager, type Source } from './constants.js';
|
|
8
|
+
export declare function getAvailablePackageManagers(): Promise<PackageManager[]>;
|
|
9
|
+
export declare function runPackageManagerInstallCommand(pkgManager: PackageManager): Promise<boolean>;
|
|
10
|
+
export declare function runGitCloneCommand(source: Source & {
|
|
11
|
+
type: 'git';
|
|
12
|
+
}, dest: string): Promise<boolean>;
|
package/lib/commands.js
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
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
|
+
// We use cross-spawn instead of spawn because of Windows compatibility issues.
|
|
8
|
+
// For example, "yarn" doesn't work on Windows, it requires "yarn.cmd"
|
|
9
|
+
// Tools like execa() use cross-spawn under the hood, and "resolve" the command
|
|
10
|
+
import crossSpawn from 'cross-spawn';
|
|
11
|
+
import supportsColor from 'supports-color';
|
|
12
|
+
import { PackageManagers, } from './constants.js';
|
|
13
|
+
import { askForCustomGitCloneCommand } from './prompts.js';
|
|
14
|
+
/**
|
|
15
|
+
* Run a command, similar to execa(cmd,args) but simpler
|
|
16
|
+
* @param command
|
|
17
|
+
* @param args
|
|
18
|
+
* @param options
|
|
19
|
+
* @returns the command exit code
|
|
20
|
+
*/
|
|
21
|
+
async function runCommand(command, args = [], options = {}) {
|
|
22
|
+
// This does something similar to execa.command()
|
|
23
|
+
// we split a string command (with optional args) into command+args
|
|
24
|
+
// this way it's compatible with spawn()
|
|
25
|
+
const [realCommand, ...baseArgs] = command.split(' ');
|
|
26
|
+
const allArgs = [...baseArgs, ...args];
|
|
27
|
+
if (!realCommand) {
|
|
28
|
+
throw new Error(`Invalid command: ${command}`);
|
|
29
|
+
}
|
|
30
|
+
return new Promise((resolve, reject) => {
|
|
31
|
+
const p = crossSpawn(realCommand, allArgs, { stdio: 'ignore', ...options });
|
|
32
|
+
p.on('error', reject);
|
|
33
|
+
p.on('close', (exitCode) => exitCode !== null
|
|
34
|
+
? resolve(exitCode)
|
|
35
|
+
: reject(new Error(`No exit code for command ${command}`)));
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
async function hasPackageManager(packageManager) {
|
|
39
|
+
return (await runCommand(packageManager, ['--version'])) === 0;
|
|
40
|
+
}
|
|
41
|
+
export async function getAvailablePackageManagers() {
|
|
42
|
+
const list = await Promise.all(PackageManagers.map(async (name) => {
|
|
43
|
+
return (await hasPackageManager(name)) ? name : null;
|
|
44
|
+
}));
|
|
45
|
+
return list.filter((item) => item !== null);
|
|
46
|
+
}
|
|
47
|
+
export async function runPackageManagerInstallCommand(pkgManager) {
|
|
48
|
+
const installCommand = pkgManager === 'yarn'
|
|
49
|
+
? 'yarn'
|
|
50
|
+
: pkgManager === 'bun'
|
|
51
|
+
? 'bun install'
|
|
52
|
+
: `${pkgManager} install --color always`;
|
|
53
|
+
return ((await runCommand(installCommand, [], {
|
|
54
|
+
env: {
|
|
55
|
+
...process.env,
|
|
56
|
+
// Force coloring the output
|
|
57
|
+
...(supportsColor.stdout ? { FORCE_COLOR: '1' } : {}),
|
|
58
|
+
},
|
|
59
|
+
})) === 0);
|
|
60
|
+
}
|
|
61
|
+
async function getGitCloneCommand(gitStrategy) {
|
|
62
|
+
switch (gitStrategy) {
|
|
63
|
+
case 'shallow':
|
|
64
|
+
case 'copy':
|
|
65
|
+
return 'git clone --recursive --depth 1';
|
|
66
|
+
case 'custom': {
|
|
67
|
+
return askForCustomGitCloneCommand();
|
|
68
|
+
}
|
|
69
|
+
case 'deep':
|
|
70
|
+
default:
|
|
71
|
+
return 'git clone';
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
export async function runGitCloneCommand(source, dest) {
|
|
75
|
+
const gitCommand = await getGitCloneCommand(source.strategy);
|
|
76
|
+
return (await runCommand(gitCommand, [source.url, dest])) === 0;
|
|
77
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
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
|
+
export declare const DefaultPackageManager = "npm";
|
|
8
|
+
export declare const LockfileNames: {
|
|
9
|
+
npm: string;
|
|
10
|
+
yarn: string;
|
|
11
|
+
pnpm: string;
|
|
12
|
+
bun: string;
|
|
13
|
+
};
|
|
14
|
+
export type PackageManager = keyof typeof LockfileNames;
|
|
15
|
+
export declare const PackageManagers: PackageManager[];
|
|
16
|
+
export declare const GitCloneStrategies: readonly ["deep", "shallow", "copy", "custom"];
|
|
17
|
+
export type GitCloneStrategy = (typeof GitCloneStrategies)[number];
|
|
18
|
+
export type Template = {
|
|
19
|
+
name: string;
|
|
20
|
+
path: string;
|
|
21
|
+
tsVariantPath: string | undefined;
|
|
22
|
+
};
|
|
23
|
+
export type Source = {
|
|
24
|
+
type: 'template';
|
|
25
|
+
template: Template;
|
|
26
|
+
language: 'javascript' | 'typescript';
|
|
27
|
+
} | {
|
|
28
|
+
type: 'git';
|
|
29
|
+
url: string;
|
|
30
|
+
strategy: GitCloneStrategy;
|
|
31
|
+
} | {
|
|
32
|
+
type: 'local';
|
|
33
|
+
path: string;
|
|
34
|
+
};
|
package/lib/constants.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
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
|
+
// Only used in the rare, rare case of running globally installed create +
|
|
8
|
+
// using --skip-install. We need a default name to show the tip text
|
|
9
|
+
export const DefaultPackageManager = 'npm';
|
|
10
|
+
// Order matters
|
|
11
|
+
export const LockfileNames = {
|
|
12
|
+
npm: 'package-lock.json',
|
|
13
|
+
yarn: 'yarn.lock',
|
|
14
|
+
pnpm: 'pnpm-lock.yaml',
|
|
15
|
+
bun: 'bun.lockb',
|
|
16
|
+
};
|
|
17
|
+
export const PackageManagers = Object.keys(LockfileNames);
|
|
18
|
+
export const GitCloneStrategies = [
|
|
19
|
+
'deep',
|
|
20
|
+
'shallow',
|
|
21
|
+
'copy',
|
|
22
|
+
'custom',
|
|
23
|
+
];
|
package/lib/index.d.ts
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
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
|
+
import { type PackageManager, type GitCloneStrategy } from './constants.js';
|
|
7
8
|
type LanguagesOptions = {
|
|
8
9
|
javascript?: boolean;
|
|
9
10
|
typescript?: boolean;
|
|
@@ -11,16 +12,7 @@ type LanguagesOptions = {
|
|
|
11
12
|
type CLIOptions = LanguagesOptions & {
|
|
12
13
|
packageManager?: PackageManager;
|
|
13
14
|
skipInstall?: boolean;
|
|
14
|
-
gitStrategy?:
|
|
15
|
+
gitStrategy?: GitCloneStrategy;
|
|
15
16
|
};
|
|
16
|
-
declare const lockfileNames: {
|
|
17
|
-
npm: string;
|
|
18
|
-
yarn: string;
|
|
19
|
-
pnpm: string;
|
|
20
|
-
bun: string;
|
|
21
|
-
};
|
|
22
|
-
type PackageManager = keyof typeof lockfileNames;
|
|
23
|
-
declare const gitStrategies: readonly ["deep", "shallow", "copy", "custom"];
|
|
24
|
-
type GitStrategy = (typeof gitStrategies)[number];
|
|
25
17
|
export default function init(rootDir: string, reqName?: string, reqTemplate?: string, cliOptions?: CLIOptions): Promise<void>;
|
|
26
18
|
export {};
|
package/lib/index.js
CHANGED
|
@@ -12,8 +12,9 @@ import path from 'node:path';
|
|
|
12
12
|
// TODO try to remove these third-party dependencies if possible
|
|
13
13
|
import { logger } from '@docusaurus/logger';
|
|
14
14
|
import prompts from 'prompts';
|
|
15
|
-
import
|
|
16
|
-
import {
|
|
15
|
+
import { LockfileNames, PackageManagers, DefaultPackageManager, GitCloneStrategies, } from './constants.js';
|
|
16
|
+
import { getAvailablePackageManagers, runGitCloneCommand, runPackageManagerInstallCommand, } from './commands.js';
|
|
17
|
+
import { siteNameToPackageName, updatePkg, pathExists, printPackageManagerHelp, } from './utils.js';
|
|
17
18
|
import { askPreferredLanguage } from './prompts.js';
|
|
18
19
|
async function getLanguage(options) {
|
|
19
20
|
if (options.typescript) {
|
|
@@ -24,25 +25,9 @@ async function getLanguage(options) {
|
|
|
24
25
|
}
|
|
25
26
|
return askPreferredLanguage();
|
|
26
27
|
}
|
|
27
|
-
// Only used in the rare, rare case of running globally installed create +
|
|
28
|
-
// using --skip-install. We need a default name to show the tip text
|
|
29
|
-
const defaultPackageManager = 'npm';
|
|
30
|
-
const lockfileNames = {
|
|
31
|
-
npm: 'package-lock.json',
|
|
32
|
-
yarn: 'yarn.lock',
|
|
33
|
-
pnpm: 'pnpm-lock.yaml',
|
|
34
|
-
bun: 'bun.lockb',
|
|
35
|
-
};
|
|
36
|
-
const packageManagers = Object.keys(lockfileNames);
|
|
37
|
-
function pathExists(filePath) {
|
|
38
|
-
return fs
|
|
39
|
-
.access(filePath, fs.constants.F_OK)
|
|
40
|
-
.then(() => true)
|
|
41
|
-
.catch(() => false);
|
|
42
|
-
}
|
|
43
28
|
async function findPackageManagerFromLockFile(rootDir) {
|
|
44
|
-
for (const packageManager of
|
|
45
|
-
const lockFilePath = path.join(rootDir,
|
|
29
|
+
for (const packageManager of PackageManagers) {
|
|
30
|
+
const lockFilePath = path.join(rootDir, LockfileNames[packageManager]);
|
|
46
31
|
if (await pathExists(lockFilePath)) {
|
|
47
32
|
return packageManager;
|
|
48
33
|
}
|
|
@@ -50,18 +35,18 @@ async function findPackageManagerFromLockFile(rootDir) {
|
|
|
50
35
|
return undefined;
|
|
51
36
|
}
|
|
52
37
|
function findPackageManagerFromUserAgent() {
|
|
53
|
-
return
|
|
38
|
+
return PackageManagers.find((packageManager) => process.env.npm_config_user_agent?.startsWith(packageManager));
|
|
54
39
|
}
|
|
55
40
|
async function askForPackageManagerChoice() {
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
41
|
+
const packageManagers = await getAvailablePackageManagers();
|
|
42
|
+
if (packageManagers.length === 0) {
|
|
43
|
+
logger.warn `No package maintainer available? Trying with name=${DefaultPackageManager}`;
|
|
44
|
+
return DefaultPackageManager;
|
|
45
|
+
}
|
|
46
|
+
if (packageManagers.length === 1) {
|
|
47
|
+
return packageManagers[0];
|
|
61
48
|
}
|
|
62
|
-
const choices =
|
|
63
|
-
.filter((p) => Boolean(p))
|
|
64
|
-
.map((p) => ({ title: p, value: p }));
|
|
49
|
+
const choices = packageManagers.map((p) => ({ title: p, value: p }));
|
|
65
50
|
return ((await prompts({
|
|
66
51
|
type: 'select',
|
|
67
52
|
name: 'packageManager',
|
|
@@ -69,13 +54,13 @@ async function askForPackageManagerChoice() {
|
|
|
69
54
|
choices,
|
|
70
55
|
}, {
|
|
71
56
|
onCancel() {
|
|
72
|
-
logger.info `Falling back to name=${
|
|
57
|
+
logger.info `Falling back to name=${DefaultPackageManager}`;
|
|
73
58
|
},
|
|
74
|
-
})).packageManager ??
|
|
59
|
+
})).packageManager ?? DefaultPackageManager);
|
|
75
60
|
}
|
|
76
61
|
async function getPackageManager(dest, { packageManager, skipInstall }) {
|
|
77
|
-
if (packageManager && !
|
|
78
|
-
throw new Error(`Invalid package manager choice ${packageManager}. Must be one of ${
|
|
62
|
+
if (packageManager && !PackageManagers.includes(packageManager)) {
|
|
63
|
+
throw new Error(`Invalid package manager choice ${packageManager}. Must be one of ${PackageManagers.join(', ')}`);
|
|
79
64
|
}
|
|
80
65
|
return (
|
|
81
66
|
// If dest already contains a lockfile (e.g. if using a local template), we
|
|
@@ -85,7 +70,7 @@ async function getPackageManager(dest, { packageManager, skipInstall }) {
|
|
|
85
70
|
(await findPackageManagerFromLockFile('.')) ??
|
|
86
71
|
findPackageManagerFromUserAgent() ??
|
|
87
72
|
// This only happens if the user has a global installation in PATH
|
|
88
|
-
(skipInstall ?
|
|
73
|
+
(skipInstall ? DefaultPackageManager : await askForPackageManagerChoice()));
|
|
89
74
|
}
|
|
90
75
|
const recommendedTemplate = 'classic';
|
|
91
76
|
const typeScriptTemplateSuffix = '-typescript';
|
|
@@ -164,29 +149,6 @@ async function askTemplateChoice({ templates, cliOptions, }) {
|
|
|
164
149
|
function isValidGitRepoUrl(gitRepoUrl) {
|
|
165
150
|
return ['https://', 'git@'].some((item) => gitRepoUrl.startsWith(item));
|
|
166
151
|
}
|
|
167
|
-
const gitStrategies = ['deep', 'shallow', 'copy', 'custom'];
|
|
168
|
-
async function getGitCommand(gitStrategy) {
|
|
169
|
-
switch (gitStrategy) {
|
|
170
|
-
case 'shallow':
|
|
171
|
-
case 'copy':
|
|
172
|
-
return 'git clone --recursive --depth 1';
|
|
173
|
-
case 'custom': {
|
|
174
|
-
const { command } = (await prompts({
|
|
175
|
-
type: 'text',
|
|
176
|
-
name: 'command',
|
|
177
|
-
message: 'Write your own git clone command. The repository URL and destination directory will be supplied. E.g. "git clone --depth 10"',
|
|
178
|
-
}, {
|
|
179
|
-
onCancel() {
|
|
180
|
-
logger.info `Falling back to code=${'git clone'}`;
|
|
181
|
-
},
|
|
182
|
-
}));
|
|
183
|
-
return command ?? 'git clone';
|
|
184
|
-
}
|
|
185
|
-
case 'deep':
|
|
186
|
-
default:
|
|
187
|
-
return 'git clone';
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
152
|
async function getSiteName(reqName, rootDir) {
|
|
191
153
|
async function validateSiteName(siteName) {
|
|
192
154
|
if (!siteName) {
|
|
@@ -246,8 +208,8 @@ async function getTemplateSource({ templateName, templates, cliOptions, }) {
|
|
|
246
208
|
async function getUserProvidedSource({ reqTemplate, templates, cliOptions, }) {
|
|
247
209
|
if (isValidGitRepoUrl(reqTemplate)) {
|
|
248
210
|
if (cliOptions.gitStrategy &&
|
|
249
|
-
!
|
|
250
|
-
logger.error `Invalid git strategy: name=${cliOptions.gitStrategy}. Value must be one of ${
|
|
211
|
+
!GitCloneStrategies.includes(cliOptions.gitStrategy)) {
|
|
212
|
+
logger.error `Invalid git strategy: name=${cliOptions.gitStrategy}. Value must be one of ${GitCloneStrategies.join(', ')}.`;
|
|
251
213
|
process.exit(1);
|
|
252
214
|
}
|
|
253
215
|
return {
|
|
@@ -358,12 +320,6 @@ async function getSource(reqTemplate, templates, cliOptions) {
|
|
|
358
320
|
cliOptions,
|
|
359
321
|
});
|
|
360
322
|
}
|
|
361
|
-
async function updatePkg(pkgPath, obj) {
|
|
362
|
-
const pkg = JSON.parse(await fs.readFile(pkgPath, 'utf8'));
|
|
363
|
-
const newPkg = Object.assign(pkg, obj);
|
|
364
|
-
await fs.mkdir(path.dirname(pkgPath), { recursive: true });
|
|
365
|
-
await fs.writeFile(pkgPath, `${JSON.stringify(newPkg, null, 2)}\n`);
|
|
366
|
-
}
|
|
367
323
|
export default async function init(rootDir, reqName, reqTemplate, cliOptions = {}) {
|
|
368
324
|
const [templates, siteName] = await Promise.all([
|
|
369
325
|
readTemplates(),
|
|
@@ -373,8 +329,7 @@ export default async function init(rootDir, reqName, reqTemplate, cliOptions = {
|
|
|
373
329
|
const source = await getSource(reqTemplate, templates, cliOptions);
|
|
374
330
|
logger.info('Creating new Docusaurus project...');
|
|
375
331
|
if (source.type === 'git') {
|
|
376
|
-
|
|
377
|
-
if ((await runCommand(gitCommand, [source.url, dest])) !== 0) {
|
|
332
|
+
if (!(await runGitCloneCommand(source, dest))) {
|
|
378
333
|
logger.error `Cloning Git template failed!`;
|
|
379
334
|
process.exit(1);
|
|
380
335
|
}
|
|
@@ -427,17 +382,7 @@ export default async function init(rootDir, reqName, reqTemplate, cliOptions = {
|
|
|
427
382
|
process.chdir(dest);
|
|
428
383
|
logger.info `Installing dependencies with name=${pkgManager}...`;
|
|
429
384
|
// ...
|
|
430
|
-
if ((await
|
|
431
|
-
? 'yarn'
|
|
432
|
-
: pkgManager === 'bun'
|
|
433
|
-
? 'bun install'
|
|
434
|
-
: `${pkgManager} install --color always`, [], {
|
|
435
|
-
env: {
|
|
436
|
-
...process.env,
|
|
437
|
-
// Force coloring the output
|
|
438
|
-
...(supportsColor.stdout ? { FORCE_COLOR: '1' } : {}),
|
|
439
|
-
},
|
|
440
|
-
})) !== 0) {
|
|
385
|
+
if (!(await runPackageManagerInstallCommand(pkgManager))) {
|
|
441
386
|
logger.error('Dependency installation failed.');
|
|
442
387
|
logger.info `The site directory has already been created, and you can retry by typing:
|
|
443
388
|
|
|
@@ -446,29 +391,5 @@ export default async function init(rootDir, reqName, reqTemplate, cliOptions = {
|
|
|
446
391
|
process.exit(0);
|
|
447
392
|
}
|
|
448
393
|
}
|
|
449
|
-
|
|
450
|
-
const useBun = pkgManager === 'bun';
|
|
451
|
-
const useRunCommand = useNpm || useBun;
|
|
452
|
-
logger.success `Created name=${cdpath}.`;
|
|
453
|
-
logger.info `Inside that directory, you can run several commands:
|
|
454
|
-
|
|
455
|
-
code=${`${pkgManager} start`}
|
|
456
|
-
Starts the development server.
|
|
457
|
-
|
|
458
|
-
code=${`${pkgManager} ${useRunCommand ? 'run ' : ''}build`}
|
|
459
|
-
Bundles your website into static files for production.
|
|
460
|
-
|
|
461
|
-
code=${`${pkgManager} ${useRunCommand ? 'run ' : ''}serve`}
|
|
462
|
-
Serves the built website locally.
|
|
463
|
-
|
|
464
|
-
code=${`${pkgManager} ${useRunCommand ? 'run ' : ''}deploy`}
|
|
465
|
-
Publishes the website to GitHub pages.
|
|
466
|
-
|
|
467
|
-
We recommend that you begin by typing:
|
|
468
|
-
|
|
469
|
-
code=${`cd ${cdpath}`}
|
|
470
|
-
code=${`${pkgManager} start`}
|
|
471
|
-
|
|
472
|
-
Happy building awesome websites!
|
|
473
|
-
`;
|
|
394
|
+
printPackageManagerHelp({ pkgManager, cdpath });
|
|
474
395
|
}
|
package/lib/prompts.d.ts
CHANGED
package/lib/prompts.js
CHANGED
|
@@ -21,3 +21,15 @@ export async function askPreferredLanguage() {
|
|
|
21
21
|
}
|
|
22
22
|
return language;
|
|
23
23
|
}
|
|
24
|
+
export async function askForCustomGitCloneCommand() {
|
|
25
|
+
const { command } = (await prompts({
|
|
26
|
+
type: 'text',
|
|
27
|
+
name: 'command',
|
|
28
|
+
message: 'Write your own git clone command. The repository URL and destination directory will be supplied. E.g. "git clone --depth 10"',
|
|
29
|
+
}, {
|
|
30
|
+
onCancel() {
|
|
31
|
+
logger.info `Falling back to code=${'git clone'}`;
|
|
32
|
+
},
|
|
33
|
+
}));
|
|
34
|
+
return command ?? 'git clone';
|
|
35
|
+
}
|
package/lib/utils.d.ts
CHANGED
|
@@ -4,16 +4,7 @@
|
|
|
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
|
-
import
|
|
8
|
-
type SpawnOptions = NonNullable<Parameters<typeof crossSpawn>[2]>;
|
|
9
|
-
/**
|
|
10
|
-
* Run a command, similar to execa(cmd,args) but simpler
|
|
11
|
-
* @param command
|
|
12
|
-
* @param args
|
|
13
|
-
* @param options
|
|
14
|
-
* @returns the command exit code
|
|
15
|
-
*/
|
|
16
|
-
export declare function runCommand(command: string, args?: string[], options?: SpawnOptions): Promise<number>;
|
|
7
|
+
import { type PackageManager } from './constants.js';
|
|
17
8
|
/**
|
|
18
9
|
* We use a simple kebab-case-like conversion
|
|
19
10
|
* It's not perfect, but good enough
|
|
@@ -22,4 +13,11 @@ export declare function runCommand(command: string, args?: string[], options?: S
|
|
|
22
13
|
* @param siteName
|
|
23
14
|
*/
|
|
24
15
|
export declare function siteNameToPackageName(siteName: string): string;
|
|
25
|
-
export {
|
|
16
|
+
export declare function updatePkg(pkgPath: string, obj: {
|
|
17
|
+
[key: string]: unknown;
|
|
18
|
+
}): Promise<void>;
|
|
19
|
+
export declare function pathExists(filePath: string): Promise<boolean>;
|
|
20
|
+
export declare function printPackageManagerHelp({ pkgManager, cdpath, }: {
|
|
21
|
+
pkgManager: PackageManager;
|
|
22
|
+
cdpath: string;
|
|
23
|
+
}): void;
|
package/lib/utils.js
CHANGED
|
@@ -4,34 +4,9 @@
|
|
|
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
|
-
import
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
// Tools like execa() use cross-spawn under the hood, and "resolve" the command
|
|
11
|
-
/**
|
|
12
|
-
* Run a command, similar to execa(cmd,args) but simpler
|
|
13
|
-
* @param command
|
|
14
|
-
* @param args
|
|
15
|
-
* @param options
|
|
16
|
-
* @returns the command exit code
|
|
17
|
-
*/
|
|
18
|
-
export async function runCommand(command, args = [], options = {}) {
|
|
19
|
-
// This does something similar to execa.command()
|
|
20
|
-
// we split a string command (with optional args) into command+args
|
|
21
|
-
// this way it's compatible with spawn()
|
|
22
|
-
const [realCommand, ...baseArgs] = command.split(' ');
|
|
23
|
-
const allArgs = [...baseArgs, ...args];
|
|
24
|
-
if (!realCommand) {
|
|
25
|
-
throw new Error(`Invalid command: ${command}`);
|
|
26
|
-
}
|
|
27
|
-
return new Promise((resolve, reject) => {
|
|
28
|
-
const p = crossSpawn(realCommand, allArgs, { stdio: 'ignore', ...options });
|
|
29
|
-
p.on('error', reject);
|
|
30
|
-
p.on('close', (exitCode) => exitCode !== null
|
|
31
|
-
? resolve(exitCode)
|
|
32
|
-
: reject(new Error(`No exit code for command ${command}`)));
|
|
33
|
-
});
|
|
34
|
-
}
|
|
7
|
+
import fs from 'node:fs/promises';
|
|
8
|
+
import path from 'node:path';
|
|
9
|
+
import { logger } from '@docusaurus/logger';
|
|
35
10
|
/**
|
|
36
11
|
* We use a simple kebab-case-like conversion
|
|
37
12
|
* It's not perfect, but good enough
|
|
@@ -46,3 +21,43 @@ export function siteNameToPackageName(siteName) {
|
|
|
46
21
|
}
|
|
47
22
|
return siteName;
|
|
48
23
|
}
|
|
24
|
+
export async function updatePkg(pkgPath, obj) {
|
|
25
|
+
const pkg = JSON.parse(await fs.readFile(pkgPath, 'utf8'));
|
|
26
|
+
const newPkg = Object.assign(pkg, obj);
|
|
27
|
+
await fs.mkdir(path.dirname(pkgPath), { recursive: true });
|
|
28
|
+
await fs.writeFile(pkgPath, `${JSON.stringify(newPkg, null, 2)}\n`);
|
|
29
|
+
}
|
|
30
|
+
// No need for fs-extra dependency
|
|
31
|
+
export async function pathExists(filePath) {
|
|
32
|
+
return fs
|
|
33
|
+
.access(filePath, fs.constants.F_OK)
|
|
34
|
+
.then(() => true)
|
|
35
|
+
.catch(() => false);
|
|
36
|
+
}
|
|
37
|
+
export function printPackageManagerHelp({ pkgManager, cdpath, }) {
|
|
38
|
+
const useNpm = pkgManager === 'npm';
|
|
39
|
+
const useBun = pkgManager === 'bun';
|
|
40
|
+
const run = useNpm || useBun ? 'run ' : '';
|
|
41
|
+
logger.success `Created name=${cdpath}.`;
|
|
42
|
+
logger.info `Inside that directory, you can run several commands:
|
|
43
|
+
|
|
44
|
+
code=${`${pkgManager} start`}
|
|
45
|
+
Starts the development server.
|
|
46
|
+
|
|
47
|
+
code=${`${pkgManager} ${run}build`}
|
|
48
|
+
Bundles your website into static files for production.
|
|
49
|
+
|
|
50
|
+
code=${`${pkgManager} ${run}serve`}
|
|
51
|
+
Serves the built website locally.
|
|
52
|
+
|
|
53
|
+
code=${`${pkgManager} ${run}deploy`}
|
|
54
|
+
Publishes the website to GitHub pages.
|
|
55
|
+
|
|
56
|
+
We recommend that you begin by typing:
|
|
57
|
+
|
|
58
|
+
code=${`cd ${cdpath}`}
|
|
59
|
+
code=${`${pkgManager} start`}
|
|
60
|
+
|
|
61
|
+
Happy building awesome websites!
|
|
62
|
+
`;
|
|
63
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-docusaurus",
|
|
3
|
-
"version": "3.10.1-canary-
|
|
3
|
+
"version": "3.10.1-canary-6624",
|
|
4
4
|
"description": "Create Docusaurus apps easily.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
},
|
|
23
23
|
"license": "MIT",
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@docusaurus/logger": "3.10.1-canary-
|
|
25
|
+
"@docusaurus/logger": "3.10.1-canary-6624",
|
|
26
26
|
"commander": "^5.1.0",
|
|
27
27
|
"cross-spawn": "^7.0.6",
|
|
28
28
|
"prompts": "^2.4.2",
|
|
@@ -37,5 +37,5 @@
|
|
|
37
37
|
"engines": {
|
|
38
38
|
"node": ">=24.14"
|
|
39
39
|
},
|
|
40
|
-
"gitHead": "
|
|
40
|
+
"gitHead": "5a5f7cc5a3f1aae9354d65625b4eb5ad96b7365d"
|
|
41
41
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "docusaurus-2-classic-template",
|
|
3
|
-
"version": "3.10.1-canary-
|
|
3
|
+
"version": "3.10.1-canary-6624",
|
|
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": "3.10.1-canary-
|
|
18
|
-
"@docusaurus/faster": "3.10.1-canary-
|
|
19
|
-
"@docusaurus/preset-classic": "3.10.1-canary-
|
|
17
|
+
"@docusaurus/core": "3.10.1-canary-6624",
|
|
18
|
+
"@docusaurus/faster": "3.10.1-canary-6624",
|
|
19
|
+
"@docusaurus/preset-classic": "3.10.1-canary-6624",
|
|
20
20
|
"@mdx-js/react": "^3.1.1",
|
|
21
21
|
"clsx": "^2.0.0",
|
|
22
22
|
"prism-react-renderer": "^2.4.1",
|
|
@@ -24,8 +24,8 @@
|
|
|
24
24
|
"react-dom": "^19.2.5"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"@docusaurus/module-type-aliases": "3.10.1-canary-
|
|
28
|
-
"@docusaurus/types": "3.10.1-canary-
|
|
27
|
+
"@docusaurus/module-type-aliases": "3.10.1-canary-6624",
|
|
28
|
+
"@docusaurus/types": "3.10.1-canary-6624"
|
|
29
29
|
},
|
|
30
30
|
"browserslist": {
|
|
31
31
|
"production": [
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "docusaurus-2-classic-typescript-template",
|
|
3
|
-
"version": "3.10.1-canary-
|
|
3
|
+
"version": "3.10.1-canary-6624",
|
|
4
4
|
"private": true,
|
|
5
5
|
"scripts": {
|
|
6
6
|
"docusaurus": "docusaurus",
|
|
@@ -15,9 +15,9 @@
|
|
|
15
15
|
"typecheck": "tsc"
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@docusaurus/core": "3.10.1-canary-
|
|
19
|
-
"@docusaurus/faster": "3.10.1-canary-
|
|
20
|
-
"@docusaurus/preset-classic": "3.10.1-canary-
|
|
18
|
+
"@docusaurus/core": "3.10.1-canary-6624",
|
|
19
|
+
"@docusaurus/faster": "3.10.1-canary-6624",
|
|
20
|
+
"@docusaurus/preset-classic": "3.10.1-canary-6624",
|
|
21
21
|
"@mdx-js/react": "^3.1.1",
|
|
22
22
|
"clsx": "^2.0.0",
|
|
23
23
|
"prism-react-renderer": "^2.4.1",
|
|
@@ -25,9 +25,9 @@
|
|
|
25
25
|
"react-dom": "^19.2.5"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"@docusaurus/module-type-aliases": "3.10.1-canary-
|
|
29
|
-
"@docusaurus/tsconfig": "3.10.1-canary-
|
|
30
|
-
"@docusaurus/types": "3.10.1-canary-
|
|
28
|
+
"@docusaurus/module-type-aliases": "3.10.1-canary-6624",
|
|
29
|
+
"@docusaurus/tsconfig": "3.10.1-canary-6624",
|
|
30
|
+
"@docusaurus/types": "3.10.1-canary-6624",
|
|
31
31
|
"@types/react": "^19.2.14",
|
|
32
32
|
"typescript": "~6.0.3"
|
|
33
33
|
},
|
package/lib/types.d.ts
DELETED