From f26d478f2d16a8f0fa249342ed92c53e0ecf7a11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Lorber?= Date: Mon, 16 Nov 2020 17:09:44 +0100 Subject: [PATCH] fix(v2): codesandbox generated examples should use published init package (#3760) * Fix codesandbox generated examples to use published init script instead of local one * Fix codesandbox generated examples to use published init script instead of local one --- examples/bootstrap/.gitignore | 20 -------------------- examples/bootstrap/docusaurus.config.js | 1 - examples/classic/docusaurus.config.js | 1 - examples/classic/package.json | 5 ++--- examples/classic/yarn.lock | 2 +- examples/facebook/docusaurus.config.js | 1 - examples/facebook/package.json | 5 ++--- examples/facebook/yarn.lock | 2 +- codesandboxscript.js => generateExamples.js | 13 +++++++++++-- package.json | 2 +- 10 files changed, 18 insertions(+), 34 deletions(-) delete mode 100644 examples/bootstrap/.gitignore rename codesandboxscript.js => generateExamples.js (75%) diff --git a/examples/bootstrap/.gitignore b/examples/bootstrap/.gitignore deleted file mode 100644 index b2d6de3062..0000000000 --- a/examples/bootstrap/.gitignore +++ /dev/null @@ -1,20 +0,0 @@ -# Dependencies -/node_modules - -# Production -/build - -# Generated files -.docusaurus -.cache-loader - -# Misc -.DS_Store -.env.local -.env.development.local -.env.test.local -.env.production.local - -npm-debug.log* -yarn-debug.log* -yarn-error.log* diff --git a/examples/bootstrap/docusaurus.config.js b/examples/bootstrap/docusaurus.config.js index 35a4b8f35d..1af4b31172 100644 --- a/examples/bootstrap/docusaurus.config.js +++ b/examples/bootstrap/docusaurus.config.js @@ -4,7 +4,6 @@ module.exports = { url: 'https://your-docusaurus-test-site.com', baseUrl: '/', onBrokenLinks: 'throw', - onBrokenMarkdownLinks: 'warn', favicon: 'img/favicon.ico', organizationName: 'facebook', // Usually your GitHub org/user name. projectName: 'docusaurus', // Usually your repo name. diff --git a/examples/classic/docusaurus.config.js b/examples/classic/docusaurus.config.js index 5344d32216..42e58acd74 100644 --- a/examples/classic/docusaurus.config.js +++ b/examples/classic/docusaurus.config.js @@ -4,7 +4,6 @@ module.exports = { url: 'https://your-docusaurus-test-site.com', baseUrl: '/', onBrokenLinks: 'throw', - onBrokenMarkdownLinks: 'warn', favicon: 'img/favicon.ico', organizationName: 'facebook', // Usually your GitHub org/user name. projectName: 'docusaurus', // Usually your repo name. diff --git a/examples/classic/package.json b/examples/classic/package.json index 9aa82b5eef..90dd360cc0 100644 --- a/examples/classic/package.json +++ b/examples/classic/package.json @@ -9,20 +9,19 @@ "swizzle": "docusaurus swizzle", "deploy": "docusaurus deploy", "serve": "docusaurus serve", - "clear": "docusaurus clear", "dev": "docusaurus start" }, "dependencies": { "@docusaurus/core": "2.0.0-alpha.66", "@docusaurus/preset-classic": "2.0.0-alpha.66", - "@mdx-js/react": "^1.6.21", + "@mdx-js/react": "^1.5.8", "clsx": "^1.1.1", "react": "^16.8.4", "react-dom": "^16.8.4" }, "browserslist": { "production": [ - ">0.5%", + ">0.2%", "not dead", "not op_mini all" ], diff --git a/examples/classic/yarn.lock b/examples/classic/yarn.lock index 8b86d3b4f1..2ebfa08a6f 100644 --- a/examples/classic/yarn.lock +++ b/examples/classic/yarn.lock @@ -1537,7 +1537,7 @@ unist-builder "2.0.3" unist-util-visit "2.0.3" -"@mdx-js/react@^1.5.8", "@mdx-js/react@^1.6.21": +"@mdx-js/react@^1.5.8": version "1.6.21" resolved "https://registry.yarnpkg.com/@mdx-js/react/-/react-1.6.21.tgz#86d962471a5e160c59a6b32054aa55c0c7ca404e" integrity sha512-CgSNT9sq2LAlhEbVlPg7DwUQkypz+CWaWGcJbkgmp9WCAy6vW33CQ44UbKPiH3wet9o+UbXeQOqzZd041va83g== diff --git a/examples/facebook/docusaurus.config.js b/examples/facebook/docusaurus.config.js index a81def4de1..7c9746ce1c 100644 --- a/examples/facebook/docusaurus.config.js +++ b/examples/facebook/docusaurus.config.js @@ -13,7 +13,6 @@ module.exports = { url: 'https://your-docusaurus-test-site.com', baseUrl: '/', onBrokenLinks: 'throw', - onBrokenMarkdownLinks: 'warn', favicon: 'img/favicon.ico', organizationName: 'facebook', // Usually your GitHub org/user name. projectName: 'docusaurus', // Usually your repo name. diff --git a/examples/facebook/package.json b/examples/facebook/package.json index 83d0492da2..1bca644b73 100644 --- a/examples/facebook/package.json +++ b/examples/facebook/package.json @@ -9,7 +9,6 @@ "swizzle": "docusaurus swizzle", "deploy": "docusaurus deploy", "serve": "docusaurus serve", - "clear": "docusaurus clear", "ci": "yarn lint && yarn prettier:diff", "lint": "eslint --cache \"**/*.js\" && stylelint \"**/*.css\"", "prettier": "prettier --config .prettierrc --write \"**/*.{js,md}\"", @@ -19,7 +18,7 @@ "dependencies": { "@docusaurus/core": "2.0.0-alpha.66", "@docusaurus/preset-classic": "2.0.0-alpha.66", - "@mdx-js/react": "^1.6.21", + "@mdx-js/react": "^1.5.8", "clsx": "^1.1.1", "react": "^16.8.4", "react-dom": "^16.8.4" @@ -39,7 +38,7 @@ }, "browserslist": { "production": [ - ">0.5%", + ">0.2%", "not dead", "not op_mini all" ], diff --git a/examples/facebook/yarn.lock b/examples/facebook/yarn.lock index 0d264f7dd2..f79b3af365 100644 --- a/examples/facebook/yarn.lock +++ b/examples/facebook/yarn.lock @@ -1537,7 +1537,7 @@ unist-builder "2.0.3" unist-util-visit "2.0.3" -"@mdx-js/react@^1.5.8", "@mdx-js/react@^1.6.21": +"@mdx-js/react@^1.5.8": version "1.6.21" resolved "https://registry.yarnpkg.com/@mdx-js/react/-/react-1.6.21.tgz#86d962471a5e160c59a6b32054aa55c0c7ca404e" integrity sha512-CgSNT9sq2LAlhEbVlPg7DwUQkypz+CWaWGcJbkgmp9WCAy6vW33CQ44UbKPiH3wet9o+UbXeQOqzZd041va83g== diff --git a/codesandboxscript.js b/generateExamples.js similarity index 75% rename from codesandboxscript.js rename to generateExamples.js index 9ece169d3b..0516bfdf4d 100644 --- a/codesandboxscript.js +++ b/generateExamples.js @@ -10,6 +10,9 @@ const rimraf = require('rimraf'); const {readFileSync, writeFileSync, readdir} = require('fs'); const {execSync} = require('child_process'); +// Generate one example per init template +// We use those generated examples as CodeSandbox projects +// See https://github.com/facebook/docusaurus/issues/1699 function generateTemplateExample(template) { try { console.log( @@ -18,8 +21,14 @@ function generateTemplateExample(template) { // run the docusaurus script to bootstrap the template in the examples folder execSync( - `node ./packages/docusaurus-init/bin/index.js init examples/${template} ${template}`, - {stdio: 'inherit'}, + // /!\ we use the published init script on purpose, + // because using the local init script is too early and could generate upcoming/unavailable config options + // remember CodeSandbox templates will use the published version, not the repo version + `npx @docusaurus/init@next init examples/${template} ${template}`, + // `node ./packages/docusaurus-init/bin/index.js init examples/${template} ${template}`, + { + stdio: 'inherit', + }, ); // read the content of the package.json diff --git a/package.json b/package.json index 166c1259fe..ad753f4530 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "start:v2:baseUrl": "yarn workspace docusaurus-2-website start:baseUrl", "start:v2:bootstrap": "yarn workspace docusaurus-2-website start:bootstrap", "start:v2:blogOnly": "yarn workspace docusaurus-2-website start:blogOnly", - "examples:generate": "node codesandboxscript", + "examples:generate": "node generateExamples", "build": "yarn build:packages && yarn build:v2", "build:packages": "lerna run build --no-private", "build:v1": "yarn workspace docusaurus-1-website build",