create-docusaurus 2.0.0-beta.17 → 2.0.0-beta.20

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
@@ -13,7 +13,6 @@ import semver from 'semver';
13
13
  import path from 'path';
14
14
  import {program} from 'commander';
15
15
  import {createRequire} from 'module';
16
- import init from '../lib/index.js';
17
16
 
18
17
  const packageJson = createRequire(import.meta.url)('../package.json');
19
18
  const requiredVersion = packageJson.engines.node;
@@ -24,14 +23,6 @@ if (!semver.satisfies(process.version, requiredVersion)) {
24
23
  process.exit(1);
25
24
  }
26
25
 
27
- function wrapCommand(fn) {
28
- return (...args) =>
29
- fn(...args).catch((err) => {
30
- logger.error(err.stack);
31
- process.exitCode = 1;
32
- });
33
- }
34
-
35
26
  program.version(packageJson.version);
36
27
 
37
28
  program
@@ -61,11 +52,14 @@ program
61
52
  rootDir = '.',
62
53
  {packageManager, skipInstall, typescript, gitStrategy} = {},
63
54
  ) => {
64
- wrapCommand(init)(path.resolve(rootDir), siteName, template, {
65
- packageManager,
66
- skipInstall,
67
- typescript,
68
- gitStrategy,
55
+ // See https://github.com/facebook/docusaurus/pull/6860
56
+ import('../lib/index.js').then(({default: init}) => {
57
+ init(path.resolve(rootDir), siteName, template, {
58
+ packageManager,
59
+ skipInstall,
60
+ typescript,
61
+ gitStrategy,
62
+ });
69
63
  });
70
64
  },
71
65
  );
@@ -75,3 +69,8 @@ program.parse(process.argv);
75
69
  if (!process.argv.slice(1).length) {
76
70
  program.outputHelp();
77
71
  }
72
+
73
+ process.on('unhandledRejection', (err) => {
74
+ logger.error(err);
75
+ process.exit(1);
76
+ });
package/lib/index.js CHANGED
@@ -25,7 +25,7 @@ const SupportedPackageManagers = {
25
25
  const PackageManagersList = Object.keys(SupportedPackageManagers);
26
26
  async function findPackageManagerFromLockFile() {
27
27
  for (const packageManager of PackageManagersList) {
28
- const lockFilePath = path.resolve(process.cwd(), SupportedPackageManagers[packageManager]);
28
+ const lockFilePath = path.resolve(SupportedPackageManagers[packageManager]);
29
29
  if (await fs.pathExists(lockFilePath)) {
30
30
  return packageManager;
31
31
  }
@@ -37,11 +37,11 @@ function findPackageManagerFromUserAgent() {
37
37
  }
38
38
  async function askForPackageManagerChoice() {
39
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) {
40
+ const hasPnpm = shell.exec('pnpm --version', { silent: true }).code === 0;
41
+ if (!hasYarn && !hasPnpm) {
42
42
  return 'npm';
43
43
  }
44
- const choices = ['npm', hasYarn && 'yarn', hasPNPM && 'pnpm']
44
+ const choices = ['npm', hasYarn && 'yarn', hasPnpm && 'pnpm']
45
45
  .filter((p) => Boolean(p))
46
46
  .map((p) => ({ title: p, value: p }));
47
47
  return (await prompts({
@@ -66,8 +66,7 @@ function isValidGitRepoUrl(gitRepoUrl) {
66
66
  return ['https://', 'git@'].some((item) => gitRepoUrl.startsWith(item));
67
67
  }
68
68
  async function updatePkg(pkgPath, obj) {
69
- const content = await fs.readFile(pkgPath, 'utf-8');
70
- const pkg = JSON.parse(content);
69
+ const pkg = await fs.readJSON(pkgPath);
71
70
  const newPkg = Object.assign(pkg, obj);
72
71
  await fs.outputFile(pkgPath, `${JSON.stringify(newPkg, null, 2)}\n`);
73
72
  }
@@ -97,7 +96,7 @@ function getTypeScriptBaseTemplate(template) {
97
96
  return undefined;
98
97
  }
99
98
  async function copyTemplate(templatesDir, template, dest) {
100
- await fs.copy(path.resolve(templatesDir, 'shared'), dest);
99
+ await fs.copy(path.join(templatesDir, 'shared'), dest);
101
100
  // TypeScript variants will copy duplicate resources like CSS & config from
102
101
  // base template
103
102
  const tsBaseTemplate = getTypeScriptBaseTemplate(template);
@@ -110,7 +109,7 @@ async function copyTemplate(templatesDir, template, dest) {
110
109
  });
111
110
  }
112
111
  await fs.copy(path.resolve(templatesDir, template), dest, {
113
- // Symlinks don't exist in published NPM packages anymore, so this is only
112
+ // Symlinks don't exist in published npm packages anymore, so this is only
114
113
  // to prevent errors during local testing
115
114
  filter: async (filePath) => !(await fs.lstat(filePath)).isSymbolicLink(),
116
115
  });
@@ -137,7 +136,7 @@ async function getGitCommand(gitStrategy) {
137
136
  export default async function init(rootDir, siteName, reqTemplate, cliOptions = {}) {
138
137
  const templatesDir = fileURLToPath(new URL('../templates', import.meta.url));
139
138
  const templates = await readTemplates(templatesDir);
140
- const hasTS = (templateName) => fs.pathExists(path.resolve(templatesDir, `${templateName}${TypeScriptTemplateSuffix}`));
139
+ const hasTS = (templateName) => fs.pathExists(path.join(templatesDir, `${templateName}${TypeScriptTemplateSuffix}`));
141
140
  let name = siteName;
142
141
  // Prompt if siteName is not passed from CLI.
143
142
  if (!name) {
@@ -192,7 +191,7 @@ export default async function init(rootDir, siteName, reqTemplate, cliOptions =
192
191
  return logger.red('Invalid repository URL');
193
192
  },
194
193
  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'})`,
194
+ (e.g: url=${'https://github.com/ownerName/repoName.git'})`,
196
195
  });
197
196
  ({ gitStrategy } = await prompts({
198
197
  type: 'select',
@@ -216,7 +215,7 @@ export default async function init(rootDir, siteName, reqTemplate, cliOptions =
216
215
  name: 'templateDir',
217
216
  validate: async (dir) => {
218
217
  if (dir) {
219
- const fullDir = path.resolve(process.cwd(), dir);
218
+ const fullDir = path.resolve(dir);
220
219
  if (await fs.pathExists(fullDir)) {
221
220
  return true;
222
221
  }
@@ -234,7 +233,7 @@ export default async function init(rootDir, siteName, reqTemplate, cliOptions =
234
233
  }
235
234
  logger.info('Creating new Docusaurus project...');
236
235
  if (isValidGitRepoUrl(template)) {
237
- logger.info `Cloning Git template path=${template}...`;
236
+ logger.info `Cloning Git template url=${template}...`;
238
237
  if (!gitStrategies.includes(gitStrategy)) {
239
238
  logger.error `Invalid git strategy: name=${gitStrategy}. Value must be one of ${gitStrategies.join(', ')}.`;
240
239
  process.exit(1);
@@ -252,7 +251,7 @@ export default async function init(rootDir, siteName, reqTemplate, cliOptions =
252
251
  // Docusaurus templates.
253
252
  if (useTS) {
254
253
  if (!(await hasTS(template))) {
255
- logger.error `Template name=${template} doesn't provide the Typescript variant.`;
254
+ logger.error `Template name=${template} doesn't provide the TypeScript variant.`;
256
255
  process.exit(1);
257
256
  }
258
257
  template = `${template}${TypeScriptTemplateSuffix}`;
@@ -265,8 +264,8 @@ export default async function init(rootDir, siteName, reqTemplate, cliOptions =
265
264
  throw err;
266
265
  }
267
266
  }
268
- else if (await fs.pathExists(path.resolve(process.cwd(), template))) {
269
- const templateDir = path.resolve(process.cwd(), template);
267
+ else if (await fs.pathExists(path.resolve(template))) {
268
+ const templateDir = path.resolve(template);
270
269
  try {
271
270
  await fs.copy(templateDir, dest);
272
271
  }
@@ -322,7 +321,7 @@ export default async function init(rootDir, siteName, reqTemplate, cliOptions =
322
321
  }
323
322
  }
324
323
  const useNpm = pkgManager === 'npm';
325
- logger.success `Created path=${cdpath}.`;
324
+ logger.success `Created name=${cdpath}.`;
326
325
  logger.info `Inside that directory, you can run several commands:
327
326
 
328
327
  code=${`${pkgManager} start`}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-docusaurus",
3
- "version": "2.0.0-beta.17",
3
+ "version": "2.0.0-beta.20",
4
4
  "description": "Create Docusaurus apps easily.",
5
5
  "type": "module",
6
6
  "repository": {
@@ -13,8 +13,8 @@
13
13
  },
14
14
  "scripts": {
15
15
  "create-docusaurus": "create-docusaurus",
16
- "build": "tsc",
17
- "watch": "tsc --watch"
16
+ "build": "tsc -p tsconfig.build.json",
17
+ "watch": "tsc -p tsconfig.build.json --watch"
18
18
  },
19
19
  "bin": "bin/index.js",
20
20
  "publishConfig": {
@@ -22,15 +22,15 @@
22
22
  },
23
23
  "license": "MIT",
24
24
  "dependencies": {
25
- "@docusaurus/logger": "2.0.0-beta.17",
25
+ "@docusaurus/logger": "2.0.0-beta.20",
26
26
  "commander": "^5.1.0",
27
- "fs-extra": "^10.0.1",
27
+ "fs-extra": "^10.1.0",
28
28
  "lodash": "^4.17.21",
29
29
  "prompts": "^2.4.2",
30
- "semver": "^7.3.5",
30
+ "semver": "^7.3.7",
31
31
  "shelljs": "^0.8.5",
32
- "supports-color": "^9.2.1",
33
- "tslib": "^2.3.1"
32
+ "supports-color": "^9.2.2",
33
+ "tslib": "^2.4.0"
34
34
  },
35
35
  "devDependencies": {
36
36
  "@types/supports-color": "^8.1.1"
@@ -38,5 +38,5 @@
38
38
  "engines": {
39
39
  "node": ">=14"
40
40
  },
41
- "gitHead": "0032c0b0480083227af2e1b4da2d3ee6ce992403"
41
+ "gitHead": "ed5cdba401a5948e187e927039b142a0decc702d"
42
42
  }
@@ -13,9 +13,20 @@ const config = {
13
13
  onBrokenLinks: 'throw',
14
14
  onBrokenMarkdownLinks: 'warn',
15
15
  favicon: 'img/favicon.ico',
16
+
17
+ // GitHub pages deployment config.
18
+ // If you aren't using GitHub pages, you don't need these.
16
19
  organizationName: 'facebook', // Usually your GitHub org/user name.
17
20
  projectName: 'docusaurus', // Usually your repo name.
18
21
 
22
+ // Even if you don't use internalization, you can use this field to set useful
23
+ // metadata like html lang. For example, if your site is Chinese, you may want
24
+ // to replace "en" with "zh-Hans".
25
+ i18n: {
26
+ defaultLocale: 'en',
27
+ locales: ['en'],
28
+ },
29
+
19
30
  presets: [
20
31
  [
21
32
  'classic',
@@ -24,11 +35,14 @@ const config = {
24
35
  docs: {
25
36
  sidebarPath: require.resolve('./sidebars.js'),
26
37
  // Please change this to your repo.
27
- editUrl: 'https://github.com/facebook/docusaurus/tree/main/packages/create-docusaurus/templates/shared/',
38
+ // Remove this to remove the "edit this page" links.
39
+ editUrl:
40
+ 'https://github.com/facebook/docusaurus/tree/main/packages/create-docusaurus/templates/shared/',
28
41
  },
29
42
  blog: {
30
43
  showReadingTime: true,
31
44
  // Please change this to your repo.
45
+ // Remove this to remove the "edit this page" links.
32
46
  editUrl:
33
47
  'https://github.com/facebook/docusaurus/tree/main/packages/create-docusaurus/templates/shared/',
34
48
  },
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "docusaurus-2-classic-template",
3
- "version": "2.0.0-beta.17",
3
+ "version": "2.0.0-beta.20",
4
4
  "private": true,
5
5
  "scripts": {
6
6
  "docusaurus": "docusaurus",
@@ -14,13 +14,16 @@
14
14
  "write-heading-ids": "docusaurus write-heading-ids"
15
15
  },
16
16
  "dependencies": {
17
- "@docusaurus/core": "2.0.0-beta.17",
18
- "@docusaurus/preset-classic": "2.0.0-beta.17",
17
+ "@docusaurus/core": "2.0.0-beta.20",
18
+ "@docusaurus/preset-classic": "2.0.0-beta.20",
19
19
  "@mdx-js/react": "^1.6.22",
20
20
  "clsx": "^1.1.1",
21
- "prism-react-renderer": "^1.2.1",
22
- "react": "^17.0.1",
23
- "react-dom": "^17.0.1"
21
+ "prism-react-renderer": "^1.3.1",
22
+ "react": "^17.0.2",
23
+ "react-dom": "^17.0.2"
24
+ },
25
+ "devDependencies": {
26
+ "@docusaurus/module-type-aliases": "2.0.0-beta.20"
24
27
  },
25
28
  "browserslist": {
26
29
  "production": [
@@ -14,6 +14,7 @@
14
14
  --ifm-color-primary-lighter: #359962;
15
15
  --ifm-color-primary-lightest: #3cad6e;
16
16
  --ifm-code-font-size: 95%;
17
+ --docusaurus-highlighted-code-line-bg: rgba(0, 0, 0, 0.1);
17
18
  }
18
19
 
19
20
  /* For readability concerns, you should choose a lighter palette in dark mode. */
@@ -25,15 +26,5 @@
25
26
  --ifm-color-primary-light: #29d5b0;
26
27
  --ifm-color-primary-lighter: #32d8b4;
27
28
  --ifm-color-primary-lightest: #4fddbf;
28
- }
29
-
30
- .docusaurus-highlight-code-line {
31
- background-color: rgba(0, 0, 0, 0.1);
32
- display: block;
33
- margin: 0 calc(-1 * var(--ifm-pre-padding));
34
- padding: 0 var(--ifm-pre-padding);
35
- }
36
-
37
- [data-theme='dark'] .docusaurus-highlight-code-line {
38
- background-color: rgba(0, 0, 0, 0.3);
29
+ --docusaurus-highlighted-code-line-bg: rgba(0, 0, 0, 0.3);
39
30
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "docusaurus-2-classic-typescript-template",
3
- "version": "2.0.0-beta.17",
3
+ "version": "2.0.0-beta.20",
4
4
  "private": true,
5
5
  "scripts": {
6
6
  "docusaurus": "docusaurus",
@@ -15,18 +15,18 @@
15
15
  "typecheck": "tsc"
16
16
  },
17
17
  "dependencies": {
18
- "@docusaurus/core": "2.0.0-beta.17",
19
- "@docusaurus/preset-classic": "2.0.0-beta.17",
18
+ "@docusaurus/core": "2.0.0-beta.20",
19
+ "@docusaurus/preset-classic": "2.0.0-beta.20",
20
20
  "@mdx-js/react": "^1.6.22",
21
21
  "clsx": "^1.1.1",
22
- "prism-react-renderer": "^1.2.1",
23
- "react": "^17.0.1",
24
- "react-dom": "^17.0.1"
22
+ "prism-react-renderer": "^1.3.1",
23
+ "react": "^17.0.2",
24
+ "react-dom": "^17.0.2"
25
25
  },
26
26
  "devDependencies": {
27
- "@docusaurus/module-type-aliases": "2.0.0-beta.17",
28
- "@tsconfig/docusaurus": "^1.0.4",
29
- "typescript": "^4.6.2"
27
+ "@docusaurus/module-type-aliases": "2.0.0-beta.20",
28
+ "@tsconfig/docusaurus": "^1.0.5",
29
+ "typescript": "^4.6.4"
30
30
  },
31
31
  "browserslist": {
32
32
  "production": [
@@ -18,6 +18,9 @@ const config = {
18
18
  onBrokenLinks: 'throw',
19
19
  onBrokenMarkdownLinks: 'warn',
20
20
  favicon: 'img/favicon.ico',
21
+
22
+ // GitHub pages deployment config.
23
+ // If you aren't using GitHub pages, you don't need these.
21
24
  organizationName: 'facebook', // Usually your GitHub org/user name.
22
25
  projectName: 'docusaurus', // Usually your repo name.
23
26
 
@@ -29,12 +32,14 @@ const config = {
29
32
  docs: {
30
33
  sidebarPath: require.resolve('./sidebars.js'),
31
34
  // Please change this to your repo.
35
+ // Remove this to remove the "edit this page" links.
32
36
  editUrl:
33
37
  'https://github.com/facebook/docusaurus/tree/main/packages/create-docusaurus/templates/shared/',
34
38
  },
35
39
  blog: {
36
40
  showReadingTime: true,
37
41
  // Please change this to your repo.
42
+ // Remove this to remove the "edit this page" links.
38
43
  editUrl:
39
44
  'https://github.com/facebook/docusaurus/tree/main/packages/create-docusaurus/templates/shared/',
40
45
  },
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "docusaurus-2-facebook-template",
3
- "version": "2.0.0-beta.17",
3
+ "version": "2.0.0-beta.20",
4
4
  "private": true,
5
5
  "scripts": {
6
6
  "docusaurus": "docusaurus",
@@ -18,25 +18,25 @@
18
18
  "format:diff": "prettier --config .prettierrc --list-different \"**/*.{js,jsx,ts,tsx,md,mdx}\""
19
19
  },
20
20
  "dependencies": {
21
- "@docusaurus/core": "2.0.0-beta.17",
22
- "@docusaurus/preset-classic": "2.0.0-beta.17",
21
+ "@docusaurus/core": "2.0.0-beta.20",
22
+ "@docusaurus/preset-classic": "2.0.0-beta.20",
23
23
  "@mdx-js/react": "^1.6.22",
24
24
  "clsx": "^1.1.1",
25
- "react": "^17.0.1",
26
- "react-dom": "^17.0.1"
25
+ "react": "^17.0.2",
26
+ "react-dom": "^17.0.2"
27
27
  },
28
28
  "devDependencies": {
29
- "@babel/eslint-parser": "^7.16.3",
30
- "eslint": "^8.8.0",
31
- "eslint-config-airbnb": "^19.0.0",
32
- "eslint-config-prettier": "^8.4.0",
29
+ "@babel/eslint-parser": "^7.17.0",
30
+ "eslint": "^8.14.0",
31
+ "eslint-config-airbnb": "^19.0.4",
32
+ "eslint-config-prettier": "^8.5.0",
33
33
  "eslint-plugin-header": "^3.1.1",
34
- "eslint-plugin-import": "^2.25.3",
34
+ "eslint-plugin-import": "^2.26.0",
35
35
  "eslint-plugin-jsx-a11y": "^6.5.1",
36
- "eslint-plugin-react": "^7.29.2",
37
- "eslint-plugin-react-hooks": "^4.3.0",
38
- "prettier": "^2.5.1",
39
- "stylelint": "^14.5.3"
36
+ "eslint-plugin-react": "^7.29.4",
37
+ "eslint-plugin-react-hooks": "^4.5.0",
38
+ "prettier": "^2.6.2",
39
+ "stylelint": "^14.8.1"
40
40
  },
41
41
  "browserslist": {
42
42
  "production": [
@@ -35,10 +35,3 @@
35
35
  --ifm-color-primary-lighter: #32d8b4;
36
36
  --ifm-color-primary-lightest: #4fddbf;
37
37
  }
38
-
39
- .docusaurus-highlight-code-line {
40
- background-color: rgb(72, 77, 91);
41
- display: block;
42
- margin: 0 calc(-1 * var(--ifm-pre-padding));
43
- padding: 0 var(--ifm-pre-padding);
44
- }
@@ -1,4 +1,8 @@
1
1
  {
2
2
  "label": "Tutorial - Basics",
3
- "position": 2
3
+ "position": 2,
4
+ "link": {
5
+ "type": "generated-index",
6
+ "description": "5 minutes to learn the most important Docusaurus concepts."
7
+ }
4
8
  }
@@ -41,14 +41,14 @@ This is my **first Docusaurus document**!
41
41
 
42
42
  It is also possible to create your sidebar explicitly in `sidebars.js`:
43
43
 
44
- ```diff title="sidebars.js"
44
+ ```js title="sidebars.js"
45
45
  module.exports = {
46
46
  tutorialSidebar: [
47
47
  {
48
48
  type: 'category',
49
49
  label: 'Tutorial',
50
- - items: [...],
51
- + items: ['hello'],
50
+ // highlight-next-line
51
+ items: ['hello'],
52
52
  },
53
53
  ],
54
54
  };
@@ -43,7 +43,7 @@ Let's see how to [Create a page](./create-a-page.md).
43
43
 
44
44
  Regular Markdown images are supported.
45
45
 
46
- Add an image at `static/img/docusaurus.png` and display it in Markdown:
46
+ You can use absolute paths to reference images in the static directory (`static/img/docusaurus.png`):
47
47
 
48
48
  ```md
49
49
  ![Docusaurus logo](/img/docusaurus.png)
@@ -51,6 +51,8 @@ Add an image at `static/img/docusaurus.png` and display it in Markdown:
51
51
 
52
52
  ![Docusaurus logo](/img/docusaurus.png)
53
53
 
54
+ You can reference images relative to the current file as well, as shown in [the extra guides](../tutorial-extras/manage-docs-versions.md).
55
+
54
56
  ## Code Blocks
55
57
 
56
58
  Markdown code blocks are supported with Syntax highlighting.
@@ -1,4 +1,7 @@
1
1
  {
2
2
  "label": "Tutorial - Extras",
3
- "position": 3
3
+ "position": 3,
4
+ "link": {
5
+ "type": "generated-index"
6
+ }
4
7
  }
@@ -45,7 +45,7 @@ module.exports = {
45
45
 
46
46
  The docs version dropdown appears in your navbar:
47
47
 
48
- ![Docs Version Dropdown](/img/tutorial/docsVersionDropdown.png)
48
+ ![Docs Version Dropdown](./img/docsVersionDropdown.png)
49
49
 
50
50
  ## Update an existing version
51
51
 
@@ -71,7 +71,7 @@ module.exports = {
71
71
 
72
72
  The locale dropdown now appears in your navbar:
73
73
 
74
- ![Locale Dropdown](/img/tutorial/localeDropdown.png)
74
+ ![Locale Dropdown](./img/localeDropdown.png)
75
75
 
76
76
  ## Build your localized site
77
77