create-docusaurus 0.0.0-4593 → 0.0.0-4597

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
@@ -8,12 +8,15 @@
8
8
 
9
9
  // @ts-check
10
10
 
11
- const logger = require('@docusaurus/logger').default;
12
- const semver = require('semver');
13
- const path = require('path');
14
- const {program} = require('commander');
15
- const {default: init} = require('../lib');
16
- const requiredVersion = require('../package.json').engines.node;
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;
17
20
 
18
21
  if (!semver.satisfies(process.version, requiredVersion)) {
19
22
  logger.error('Minimum Node.js version not met :(');
@@ -29,7 +32,7 @@ function wrapCommand(fn) {
29
32
  });
30
33
  }
31
34
 
32
- program.version(require('../package.json').version);
35
+ program.version(packageJson.version);
33
36
 
34
37
  program
35
38
  .arguments('[siteName] [template] [rootDir]')
package/lib/index.js CHANGED
@@ -1,26 +1,22 @@
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
- Object.defineProperty(exports, "__esModule", { value: true });
9
- const tslib_1 = require("tslib");
10
- const logger_1 = (0, tslib_1.__importDefault)(require("@docusaurus/logger"));
11
- const fs_extra_1 = (0, tslib_1.__importDefault)(require("fs-extra"));
12
- const child_process_1 = require("child_process");
13
- const prompts_1 = (0, tslib_1.__importDefault)(require("prompts"));
14
- const path_1 = (0, tslib_1.__importDefault)(require("path"));
15
- const shelljs_1 = (0, tslib_1.__importDefault)(require("shelljs"));
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
17
  function hasYarn() {
21
18
  try {
22
- (0, child_process_1.execSync)('yarnpkg --version', { stdio: 'ignore' });
23
- return true;
19
+ return shell.exec('yarnpkg --version', { silent: true }).code === 0;
24
20
  }
25
21
  catch (e) {
26
22
  return false;
@@ -30,20 +26,20 @@ function isValidGitRepoUrl(gitRepoUrl) {
30
26
  return ['https://', 'git@'].some((item) => gitRepoUrl.startsWith(item));
31
27
  }
32
28
  async function updatePkg(pkgPath, obj) {
33
- const content = await fs_extra_1.default.readFile(pkgPath, 'utf-8');
29
+ const content = await fs.readFile(pkgPath, 'utf-8');
34
30
  const pkg = JSON.parse(content);
35
31
  const newPkg = Object.assign(pkg, obj);
36
- await fs_extra_1.default.outputFile(pkgPath, `${JSON.stringify(newPkg, null, 2)}\n`);
32
+ await fs.outputFile(pkgPath, `${JSON.stringify(newPkg, null, 2)}\n`);
37
33
  }
38
34
  function readTemplates(templatesDir) {
39
- const templates = fs_extra_1.default
35
+ const templates = fs
40
36
  .readdirSync(templatesDir)
41
37
  .filter((d) => !d.startsWith('.') &&
42
38
  !d.startsWith('README') &&
43
39
  !d.endsWith(TypeScriptTemplateSuffix) &&
44
40
  d !== 'shared');
45
41
  // Classic should be first in list!
46
- return (0, lodash_1.sortBy)(templates, (t) => t !== RecommendedTemplate);
42
+ return _.sortBy(templates, (t) => t !== RecommendedTemplate);
47
43
  }
48
44
  function createTemplateChoices(templates) {
49
45
  function makeNameAndValueChoice(value) {
@@ -63,22 +59,22 @@ function getTypeScriptBaseTemplate(template) {
63
59
  return undefined;
64
60
  }
65
61
  async function copyTemplate(templatesDir, template, dest) {
66
- await fs_extra_1.default.copy(path_1.default.resolve(templatesDir, 'shared'), dest);
62
+ await fs.copy(path.resolve(templatesDir, 'shared'), dest);
67
63
  // TypeScript variants will copy duplicate resources like CSS & config from
68
64
  // base template
69
65
  const tsBaseTemplate = getTypeScriptBaseTemplate(template);
70
66
  if (tsBaseTemplate) {
71
- const tsBaseTemplatePath = path_1.default.resolve(templatesDir, tsBaseTemplate);
72
- await fs_extra_1.default.copy(tsBaseTemplatePath, dest, {
73
- filter: (filePath) => fs_extra_1.default.statSync(filePath).isDirectory() ||
74
- path_1.default.extname(filePath) === '.css' ||
75
- path_1.default.basename(filePath) === 'docusaurus.config.js',
67
+ const tsBaseTemplatePath = path.resolve(templatesDir, tsBaseTemplate);
68
+ await fs.copy(tsBaseTemplatePath, dest, {
69
+ filter: (filePath) => fs.statSync(filePath).isDirectory() ||
70
+ path.extname(filePath) === '.css' ||
71
+ path.basename(filePath) === 'docusaurus.config.js',
76
72
  });
77
73
  }
78
- await fs_extra_1.default.copy(path_1.default.resolve(templatesDir, template), dest, {
74
+ await fs.copy(path.resolve(templatesDir, template), dest, {
79
75
  // Symlinks don't exist in published NPM packages anymore, so this is only
80
76
  // to prevent errors during local testing
81
- filter: (filePath) => !fs_extra_1.default.lstatSync(filePath).isSymbolicLink(),
77
+ filter: (filePath) => !fs.lstatSync(filePath).isSymbolicLink(),
82
78
  });
83
79
  }
84
80
  const gitStrategies = ['deep', 'shallow', 'copy', 'custom'];
@@ -88,7 +84,7 @@ async function getGitCommand(gitStrategy) {
88
84
  case 'copy':
89
85
  return 'git clone --recursive --depth 1';
90
86
  case 'custom': {
91
- const { command } = await (0, prompts_1.default)({
87
+ const { command } = await prompts({
92
88
  type: 'text',
93
89
  name: 'command',
94
90
  message: 'Write your own git clone command. The repository URL and destination directory will be supplied. E.g. "git clone --depth 10"',
@@ -100,16 +96,16 @@ async function getGitCommand(gitStrategy) {
100
96
  return 'git clone';
101
97
  }
102
98
  }
103
- async function init(rootDir, siteName, reqTemplate, cliOptions = {}) {
99
+ export default async function init(rootDir, siteName, reqTemplate, cliOptions = {}) {
104
100
  var _a;
105
101
  const useYarn = cliOptions.useNpm ? false : hasYarn();
106
- const templatesDir = path_1.default.resolve(__dirname, '../templates');
102
+ const templatesDir = fileURLToPath(new URL('../templates', import.meta.url));
107
103
  const templates = readTemplates(templatesDir);
108
- const hasTS = (templateName) => fs_extra_1.default.pathExistsSync(path_1.default.resolve(templatesDir, `${templateName}${TypeScriptTemplateSuffix}`));
104
+ const hasTS = (templateName) => fs.pathExistsSync(path.resolve(templatesDir, `${templateName}${TypeScriptTemplateSuffix}`));
109
105
  let name = siteName;
110
106
  // Prompt if siteName is not passed from CLI.
111
107
  if (!name) {
112
- const prompt = await (0, prompts_1.default)({
108
+ const prompt = await prompts({
113
109
  type: 'text',
114
110
  name: 'name',
115
111
  message: 'What should we name this site?',
@@ -118,19 +114,19 @@ async function init(rootDir, siteName, reqTemplate, cliOptions = {}) {
118
114
  name = prompt.name;
119
115
  }
120
116
  if (!name) {
121
- logger_1.default.error('A website name is required.');
117
+ logger.error('A website name is required.');
122
118
  process.exit(1);
123
119
  }
124
- const dest = path_1.default.resolve(rootDir, name);
125
- if (fs_extra_1.default.existsSync(dest)) {
126
- logger_1.default.error `Directory already exists at path=${dest}!`;
120
+ const dest = path.resolve(rootDir, name);
121
+ if (fs.existsSync(dest)) {
122
+ logger.error `Directory already exists at path=${dest}!`;
127
123
  process.exit(1);
128
124
  }
129
125
  let template = reqTemplate;
130
126
  let useTS = cliOptions.typescript;
131
127
  // Prompt if template is not provided from CLI.
132
128
  if (!template) {
133
- const templatePrompt = await (0, prompts_1.default)({
129
+ const templatePrompt = await prompts({
134
130
  type: 'select',
135
131
  name: 'template',
136
132
  message: 'Select a template below...',
@@ -138,7 +134,7 @@ async function init(rootDir, siteName, reqTemplate, cliOptions = {}) {
138
134
  });
139
135
  template = templatePrompt.template;
140
136
  if (template && !useTS && hasTS(template)) {
141
- const tsPrompt = await (0, prompts_1.default)({
137
+ const tsPrompt = await prompts({
142
138
  type: 'confirm',
143
139
  name: 'useTS',
144
140
  message: 'This template is available in TypeScript. Do you want to use the TS variant?',
@@ -150,19 +146,19 @@ async function init(rootDir, siteName, reqTemplate, cliOptions = {}) {
150
146
  let gitStrategy = (_a = cliOptions.gitStrategy) !== null && _a !== void 0 ? _a : 'deep';
151
147
  // If user choose Git repository, we'll prompt for the url.
152
148
  if (template === 'Git repository') {
153
- const repoPrompt = await (0, prompts_1.default)({
149
+ const repoPrompt = await prompts({
154
150
  type: 'text',
155
151
  name: 'gitRepoUrl',
156
152
  validate: (url) => {
157
153
  if (url && isValidGitRepoUrl(url)) {
158
154
  return true;
159
155
  }
160
- return logger_1.default.red('Invalid repository URL');
156
+ return logger.red('Invalid repository URL');
161
157
  },
162
- message: logger_1.default.interpolate `Enter a repository URL from GitHub, Bitbucket, GitLab, or any other public repo.
158
+ message: logger.interpolate `Enter a repository URL from GitHub, Bitbucket, GitLab, or any other public repo.
163
159
  (e.g: path=${'https://github.com/ownerName/repoName.git'})`,
164
160
  });
165
- ({ gitStrategy } = await (0, prompts_1.default)({
161
+ ({ gitStrategy } = await prompts({
166
162
  type: 'select',
167
163
  name: 'gitStrategy',
168
164
  message: 'How should we clone this repo?',
@@ -179,48 +175,48 @@ async function init(rootDir, siteName, reqTemplate, cliOptions = {}) {
179
175
  template = repoPrompt.gitRepoUrl;
180
176
  }
181
177
  else if (template === 'Local template') {
182
- const dirPrompt = await (0, prompts_1.default)({
178
+ const dirPrompt = await prompts({
183
179
  type: 'text',
184
180
  name: 'templateDir',
185
181
  validate: (dir) => {
186
182
  if (dir) {
187
- const fullDir = path_1.default.resolve(process.cwd(), dir);
188
- if (fs_extra_1.default.existsSync(fullDir)) {
183
+ const fullDir = path.resolve(process.cwd(), dir);
184
+ if (fs.existsSync(fullDir)) {
189
185
  return true;
190
186
  }
191
- return logger_1.default.red(logger_1.default.interpolate `path=${fullDir} does not exist.`);
187
+ return logger.red(logger.interpolate `path=${fullDir} does not exist.`);
192
188
  }
193
- return logger_1.default.red('Please enter a valid path.');
189
+ return logger.red('Please enter a valid path.');
194
190
  },
195
191
  message: 'Enter a local folder path, relative to the current working directory.',
196
192
  });
197
193
  template = dirPrompt.templateDir;
198
194
  }
199
195
  if (!template) {
200
- logger_1.default.error('Template should not be empty');
196
+ logger.error('Template should not be empty');
201
197
  process.exit(1);
202
198
  }
203
- logger_1.default.info('Creating new Docusaurus project...');
199
+ logger.info('Creating new Docusaurus project...');
204
200
  if (isValidGitRepoUrl(template)) {
205
- logger_1.default.info `Cloning Git template path=${template}...`;
201
+ logger.info `Cloning Git template path=${template}...`;
206
202
  if (!gitStrategies.includes(gitStrategy)) {
207
- logger_1.default.error `Invalid git strategy: name=${gitStrategy}. Value must be one of ${gitStrategies.join(', ')}.`;
203
+ logger.error `Invalid git strategy: name=${gitStrategy}. Value must be one of ${gitStrategies.join(', ')}.`;
208
204
  process.exit(1);
209
205
  }
210
206
  const command = await getGitCommand(gitStrategy);
211
- if (shelljs_1.default.exec(`${command} ${template} ${dest}`).code !== 0) {
212
- logger_1.default.error `Cloning Git template name=${template} failed!`;
207
+ if (shell.exec(`${command} ${template} ${dest}`).code !== 0) {
208
+ logger.error `Cloning Git template name=${template} failed!`;
213
209
  process.exit(1);
214
210
  }
215
211
  if (gitStrategy === 'copy') {
216
- await fs_extra_1.default.remove(path_1.default.join(dest, '.git'));
212
+ await fs.remove(path.join(dest, '.git'));
217
213
  }
218
214
  }
219
215
  else if (templates.includes(template)) {
220
216
  // Docusaurus templates.
221
217
  if (useTS) {
222
218
  if (!hasTS(template)) {
223
- logger_1.default.error `Template name=${template} doesn't provide the Typescript variant.`;
219
+ logger.error `Template name=${template} doesn't provide the Typescript variant.`;
224
220
  process.exit(1);
225
221
  }
226
222
  template = `${template}${TypeScriptTemplateSuffix}`;
@@ -229,68 +225,68 @@ async function init(rootDir, siteName, reqTemplate, cliOptions = {}) {
229
225
  await copyTemplate(templatesDir, template, dest);
230
226
  }
231
227
  catch (err) {
232
- logger_1.default.error `Copying Docusaurus template name=${template} failed!`;
228
+ logger.error `Copying Docusaurus template name=${template} failed!`;
233
229
  throw err;
234
230
  }
235
231
  }
236
- else if (fs_extra_1.default.existsSync(path_1.default.resolve(process.cwd(), template))) {
237
- const templateDir = path_1.default.resolve(process.cwd(), template);
232
+ else if (fs.existsSync(path.resolve(process.cwd(), template))) {
233
+ const templateDir = path.resolve(process.cwd(), template);
238
234
  try {
239
- await fs_extra_1.default.copy(templateDir, dest);
235
+ await fs.copy(templateDir, dest);
240
236
  }
241
237
  catch (err) {
242
- logger_1.default.error `Copying local template path=${templateDir} failed!`;
238
+ logger.error `Copying local template path=${templateDir} failed!`;
243
239
  throw err;
244
240
  }
245
241
  }
246
242
  else {
247
- logger_1.default.error('Invalid template.');
243
+ logger.error('Invalid template.');
248
244
  process.exit(1);
249
245
  }
250
246
  // Update package.json info.
251
247
  try {
252
- await updatePkg(path_1.default.join(dest, 'package.json'), {
253
- name: (0, lodash_1.kebabCase)(name),
248
+ await updatePkg(path.join(dest, 'package.json'), {
249
+ name: _.kebabCase(name),
254
250
  version: '0.0.0',
255
251
  private: true,
256
252
  });
257
253
  }
258
254
  catch (err) {
259
- logger_1.default.error('Failed to update package.json.');
255
+ logger.error('Failed to update package.json.');
260
256
  throw err;
261
257
  }
262
258
  // We need to rename the gitignore file to .gitignore
263
- if (!fs_extra_1.default.pathExistsSync(path_1.default.join(dest, '.gitignore')) &&
264
- fs_extra_1.default.pathExistsSync(path_1.default.join(dest, 'gitignore'))) {
265
- await fs_extra_1.default.move(path_1.default.join(dest, 'gitignore'), path_1.default.join(dest, '.gitignore'));
259
+ if (!fs.pathExistsSync(path.join(dest, '.gitignore')) &&
260
+ fs.pathExistsSync(path.join(dest, 'gitignore'))) {
261
+ await fs.move(path.join(dest, 'gitignore'), path.join(dest, '.gitignore'));
266
262
  }
267
- if (fs_extra_1.default.pathExistsSync(path_1.default.join(dest, 'gitignore'))) {
268
- fs_extra_1.default.removeSync(path_1.default.join(dest, 'gitignore'));
263
+ if (fs.pathExistsSync(path.join(dest, 'gitignore'))) {
264
+ fs.removeSync(path.join(dest, 'gitignore'));
269
265
  }
270
266
  const pkgManager = useYarn ? 'yarn' : 'npm';
271
267
  // Display the most elegant way to cd.
272
- const cdpath = path_1.default.relative('.', dest);
268
+ const cdpath = path.relative('.', dest);
273
269
  if (!cliOptions.skipInstall) {
274
- shelljs_1.default.cd(dest);
275
- logger_1.default.info `Installing dependencies with name=${pkgManager}...`;
276
- if (shelljs_1.default.exec(useYarn ? 'yarn' : 'npm install --color always', {
270
+ shell.cd(dest);
271
+ logger.info `Installing dependencies with name=${pkgManager}...`;
272
+ if (shell.exec(useYarn ? 'yarn' : 'npm install --color always', {
277
273
  env: {
278
274
  ...process.env,
279
275
  // Force coloring the output, since the command is invoked by shelljs,
280
276
  // which is not the interactive shell
281
- ...(supports_color_1.default.stdout ? { FORCE_COLOR: '1' } : {}),
277
+ ...(supportsColor.stdout ? { FORCE_COLOR: '1' } : {}),
282
278
  },
283
279
  }).code !== 0) {
284
- logger_1.default.error('Dependency installation failed.');
285
- logger_1.default.info `The site directory has already been created, and you can retry by typing:
280
+ logger.error('Dependency installation failed.');
281
+ logger.info `The site directory has already been created, and you can retry by typing:
286
282
 
287
283
  code=${`cd ${cdpath}`}
288
284
  code=${`${pkgManager} install`}`;
289
285
  process.exit(0);
290
286
  }
291
287
  }
292
- logger_1.default.success `Created path=${cdpath}.`;
293
- logger_1.default.info `Inside that directory, you can run several commands:
288
+ logger.success `Created path=${cdpath}.`;
289
+ logger.info `Inside that directory, you can run several commands:
294
290
 
295
291
  code=${`${pkgManager} start`}
296
292
  Starts the development server.
@@ -312,4 +308,3 @@ We recommend that you begin by typing:
312
308
  Happy building awesome websites!
313
309
  `;
314
310
  }
315
- exports.default = init;
package/package.json CHANGED
@@ -1,7 +1,8 @@
1
1
  {
2
2
  "name": "create-docusaurus",
3
- "version": "0.0.0-4593",
3
+ "version": "0.0.0-4597",
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",
@@ -21,14 +22,14 @@
21
22
  },
22
23
  "license": "MIT",
23
24
  "dependencies": {
24
- "@docusaurus/logger": "0.0.0-4593",
25
+ "@docusaurus/logger": "0.0.0-4597",
25
26
  "commander": "^5.1.0",
26
27
  "fs-extra": "^10.0.0",
27
- "lodash": "^4.17.20",
28
+ "lodash": "^4.17.21",
28
29
  "prompts": "^2.4.2",
29
30
  "semver": "^7.3.5",
30
31
  "shelljs": "^0.8.5",
31
- "supports-color": "^8.1.1",
32
+ "supports-color": "^9.2.1",
32
33
  "tslib": "^2.3.1"
33
34
  },
34
35
  "engines": {
@@ -37,5 +38,5 @@
37
38
  "devDependencies": {
38
39
  "@types/supports-color": "^8.1.1"
39
40
  },
40
- "gitHead": "fc32eabcb5fb2b1f75d1582d2ea5aa7a0679f241"
41
+ "gitHead": "635ab60e7cf821111d46dee45baf932c5bf8220f"
41
42
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "docusaurus-2-classic-template",
3
- "version": "0.0.0-4593",
3
+ "version": "0.0.0-4597",
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-4593",
18
- "@docusaurus/preset-classic": "0.0.0-4593",
17
+ "@docusaurus/core": "0.0.0-4597",
18
+ "@docusaurus/preset-classic": "0.0.0-4597",
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-4593",
3
+ "version": "0.0.0-4597",
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-4593",
19
- "@docusaurus/preset-classic": "0.0.0-4593",
18
+ "@docusaurus/core": "0.0.0-4597",
19
+ "@docusaurus/preset-classic": "0.0.0-4597",
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-4593",
27
+ "@docusaurus/module-type-aliases": "0.0.0-4597",
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-4593",
3
+ "version": "0.0.0-4597",
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-4593",
22
- "@docusaurus/preset-classic": "0.0.0-4593",
21
+ "@docusaurus/core": "0.0.0-4597",
22
+ "@docusaurus/preset-classic": "0.0.0-4597",
23
23
  "@mdx-js/react": "^1.6.22",
24
24
  "clsx": "^1.1.1",
25
25
  "react": "^17.0.1",