create-docusaurus 0.0.0-4565 → 0.0.0-4569

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 CHANGED
@@ -11,7 +11,7 @@
11
11
  const logger = require('@docusaurus/logger').default;
12
12
  const semver = require('semver');
13
13
  const path = require('path');
14
- const program = require('commander');
14
+ const {program} = require('commander');
15
15
  const {default: init} = require('../lib');
16
16
  const requiredVersion = require('../package.json').engines.node;
17
17
 
@@ -29,36 +29,41 @@ function wrapCommand(fn) {
29
29
  });
30
30
  }
31
31
 
32
- program
33
- .version(require('../package.json').version)
34
- .usage('<command> [options]');
32
+ program.version(require('../package.json').version);
35
33
 
36
34
  program
37
- .command('init [siteName] [template] [rootDir]', {isDefault: true})
38
- .option('--use-npm')
39
- .option('--skip-install')
40
- .option('--typescript')
35
+ .arguments('[siteName] [template] [rootDir]')
36
+ .option('--use-npm', 'Use NPM as package manage even with Yarn installed')
37
+ .option(
38
+ '--skip-install',
39
+ 'Do not run package manager immediately after scaffolding',
40
+ )
41
+ .option('--typescript', 'Use the TypeScript template variant')
42
+ .option(
43
+ '--git-strategy <strategy>',
44
+ `Only used if the template is a git repository.
45
+ \`deep\`: preserve full history
46
+ \`shallow\`: clone with --depth=1
47
+ \`copy\`: do a shallow clone, but do not create a git repo
48
+ \`custom\`: enter your custom git clone command. We will prompt you for it.`,
49
+ )
41
50
  .description('Initialize website.')
42
51
  .action(
43
52
  (
44
53
  siteName,
45
54
  template,
46
55
  rootDir = '.',
47
- {useNpm, skipInstall, typescript} = {},
56
+ {useNpm, skipInstall, typescript, gitStrategy} = {},
48
57
  ) => {
49
58
  wrapCommand(init)(path.resolve(rootDir), siteName, template, {
50
59
  useNpm,
51
60
  skipInstall,
52
61
  typescript,
62
+ gitStrategy,
53
63
  });
54
64
  },
55
65
  );
56
66
 
57
- program.arguments('<command>').action((cmd) => {
58
- program.outputHelp();
59
- logger.error`Unknown command code=${cmd}.`;
60
- });
61
-
62
67
  program.parse(process.argv);
63
68
 
64
69
  if (!process.argv.slice(1).length) {
package/lib/index.d.ts CHANGED
@@ -4,8 +4,11 @@
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 gitStrategies: readonly ["deep", "shallow", "copy", "custom"];
7
8
  export default function init(rootDir: string, siteName?: string, reqTemplate?: string, cliOptions?: Partial<{
8
9
  useNpm: boolean;
9
10
  skipInstall: boolean;
10
11
  typescript: boolean;
12
+ gitStrategy: typeof gitStrategies[number];
11
13
  }>): Promise<void>;
14
+ export {};
package/lib/index.js CHANGED
@@ -81,7 +81,27 @@ async function copyTemplate(templatesDir, template, dest) {
81
81
  filter: (filePath) => !fs_extra_1.default.lstatSync(filePath).isSymbolicLink(),
82
82
  });
83
83
  }
84
+ const gitStrategies = ['deep', 'shallow', 'copy', 'custom'];
85
+ async function getGitCommand(gitStrategy) {
86
+ switch (gitStrategy) {
87
+ case 'shallow':
88
+ case 'copy':
89
+ return 'git clone --recursive --depth 1';
90
+ case 'custom': {
91
+ const { command } = await (0, prompts_1.default)({
92
+ type: 'text',
93
+ name: 'command',
94
+ message: 'Write your own git clone command. The repository URL and destination directory will be supplied. E.g. "git clone --depth 10"',
95
+ });
96
+ return command;
97
+ }
98
+ case 'deep':
99
+ default:
100
+ return 'git clone';
101
+ }
102
+ }
84
103
  async function init(rootDir, siteName, reqTemplate, cliOptions = {}) {
104
+ var _a;
85
105
  const useYarn = cliOptions.useNpm ? false : hasYarn();
86
106
  const templatesDir = path_1.default.resolve(__dirname, '../templates');
87
107
  const templates = readTemplates(templatesDir);
@@ -127,6 +147,7 @@ async function init(rootDir, siteName, reqTemplate, cliOptions = {}) {
127
147
  useTS = tsPrompt.useTS;
128
148
  }
129
149
  }
150
+ let gitStrategy = (_a = cliOptions.gitStrategy) !== null && _a !== void 0 ? _a : 'deep';
130
151
  // If user choose Git repository, we'll prompt for the url.
131
152
  if (template === 'Git repository') {
132
153
  const repoPrompt = await (0, prompts_1.default)({
@@ -141,6 +162,20 @@ async function init(rootDir, siteName, reqTemplate, cliOptions = {}) {
141
162
  message: logger_1.default.interpolate `Enter a repository URL from GitHub, Bitbucket, GitLab, or any other public repo.
142
163
  (e.g: path=${'https://github.com/ownerName/repoName.git'})`,
143
164
  });
165
+ ({ gitStrategy } = await (0, prompts_1.default)({
166
+ type: 'select',
167
+ name: 'gitStrategy',
168
+ message: 'How should we clone this repo?',
169
+ choices: [
170
+ { title: 'Deep clone: preserve full history', value: 'deep' },
171
+ { title: 'Shallow clone: clone with --depth=1', value: 'shallow' },
172
+ {
173
+ title: 'Copy: do a shallow clone, but do not create a git repo',
174
+ value: 'copy',
175
+ },
176
+ { title: 'Custom: enter your custom git clone command', value: 'custom' },
177
+ ],
178
+ }));
144
179
  template = repoPrompt.gitRepoUrl;
145
180
  }
146
181
  else if (template === 'Local template') {
@@ -168,11 +203,18 @@ async function init(rootDir, siteName, reqTemplate, cliOptions = {}) {
168
203
  logger_1.default.info('Creating new Docusaurus project...');
169
204
  if (isValidGitRepoUrl(template)) {
170
205
  logger_1.default.info `Cloning Git template path=${template}...`;
171
- if (shelljs_1.default.exec(`git clone --recursive ${template} ${dest}`, { silent: true })
172
- .code !== 0) {
206
+ if (!gitStrategies.includes(gitStrategy)) {
207
+ logger_1.default.error `Invalid git strategy: name=${gitStrategy}. Value must be one of ${gitStrategies.join(', ')}.`;
208
+ process.exit(1);
209
+ }
210
+ const command = await getGitCommand(gitStrategy);
211
+ if (shelljs_1.default.exec(`${command} ${template} ${dest}`).code !== 0) {
173
212
  logger_1.default.error `Cloning Git template name=${template} failed!`;
174
213
  process.exit(1);
175
214
  }
215
+ if (gitStrategy === 'copy') {
216
+ await fs_extra_1.default.remove(path_1.default.join(dest, '.git'));
217
+ }
176
218
  }
177
219
  else if (templates.includes(template)) {
178
220
  // Docusaurus templates.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-docusaurus",
3
- "version": "0.0.0-4565",
3
+ "version": "0.0.0-4569",
4
4
  "description": "Create Docusaurus apps easily.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -21,7 +21,7 @@
21
21
  },
22
22
  "license": "MIT",
23
23
  "dependencies": {
24
- "@docusaurus/logger": "0.0.0-4565",
24
+ "@docusaurus/logger": "0.0.0-4569",
25
25
  "commander": "^5.1.0",
26
26
  "fs-extra": "^10.0.0",
27
27
  "lodash": "^4.17.20",
@@ -37,5 +37,5 @@
37
37
  "devDependencies": {
38
38
  "@types/supports-color": "^8.1.1"
39
39
  },
40
- "gitHead": "58480c4de1725cbcc30a12b6b73bd30ba6655b05"
40
+ "gitHead": "a7df81db396427f7bab23237363f041d793e3c93"
41
41
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "docusaurus-2-classic-template",
3
- "version": "0.0.0-4565",
3
+ "version": "0.0.0-4569",
4
4
  "private": true,
5
5
  "scripts": {
6
6
  "docusaurus": "docusaurus",
@@ -14,8 +14,8 @@
14
14
  "write-heading-ids": "docusaurus write-heading-ids"
15
15
  },
16
16
  "dependencies": {
17
- "@docusaurus/core": "0.0.0-4565",
18
- "@docusaurus/preset-classic": "0.0.0-4565",
17
+ "@docusaurus/core": "0.0.0-4569",
18
+ "@docusaurus/preset-classic": "0.0.0-4569",
19
19
  "@mdx-js/react": "^1.6.22",
20
20
  "clsx": "^1.1.1",
21
21
  "prism-react-renderer": "^1.2.1",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "docusaurus-2-classic-typescript-template",
3
- "version": "0.0.0-4565",
3
+ "version": "0.0.0-4569",
4
4
  "private": true,
5
5
  "scripts": {
6
6
  "docusaurus": "docusaurus",
@@ -15,8 +15,8 @@
15
15
  "typecheck": "tsc"
16
16
  },
17
17
  "dependencies": {
18
- "@docusaurus/core": "0.0.0-4565",
19
- "@docusaurus/preset-classic": "0.0.0-4565",
18
+ "@docusaurus/core": "0.0.0-4569",
19
+ "@docusaurus/preset-classic": "0.0.0-4569",
20
20
  "@mdx-js/react": "^1.6.22",
21
21
  "clsx": "^1.1.1",
22
22
  "prism-react-renderer": "^1.2.1",
@@ -24,7 +24,7 @@
24
24
  "react-dom": "^17.0.1"
25
25
  },
26
26
  "devDependencies": {
27
- "@docusaurus/module-type-aliases": "0.0.0-4565",
27
+ "@docusaurus/module-type-aliases": "0.0.0-4569",
28
28
  "@tsconfig/docusaurus": "^1.0.4",
29
29
  "typescript": "^4.5.2"
30
30
  },
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "docusaurus-2-facebook-template",
3
- "version": "0.0.0-4565",
3
+ "version": "0.0.0-4569",
4
4
  "private": true,
5
5
  "scripts": {
6
6
  "docusaurus": "docusaurus",
@@ -18,8 +18,8 @@
18
18
  "format:diff": "prettier --config .prettierrc --list-different \"**/*.{js,jsx,ts,tsx,md,mdx}\""
19
19
  },
20
20
  "dependencies": {
21
- "@docusaurus/core": "0.0.0-4565",
22
- "@docusaurus/preset-classic": "0.0.0-4565",
21
+ "@docusaurus/core": "0.0.0-4569",
22
+ "@docusaurus/preset-classic": "0.0.0-4569",
23
23
  "@mdx-js/react": "^1.6.22",
24
24
  "clsx": "^1.1.1",
25
25
  "react": "^17.0.1",