diff --git a/package.json b/package.json index 59bffe17290d..9deae82df296 100644 --- a/package.json +++ b/package.json @@ -86,6 +86,7 @@ "@types/lodash.sortby": "^4.6.6", "@types/node": "^13.11.0", "@types/prismjs": "^1.16.1", + "@types/prompts": "^2.0.9", "@types/react": "^16.9.52", "@types/react-dev-utils": "^9.0.1", "@types/react-helmet": "^6.0.0", @@ -93,6 +94,7 @@ "@types/react-router-config": "^5.0.1", "@types/semver": "^7.1.0", "@types/shelljs": "^0.8.6", + "@types/wait-on": "^5.2.0", "@types/webpack": "^4.41.0", "@types/webpack-dev-server": "^3.9.0", "@types/webpack-merge": "^4.1.5", diff --git a/packages/docusaurus-init/package.json b/packages/docusaurus-init/package.json index b3b479414771..ef995cf5e4bc 100644 --- a/packages/docusaurus-init/package.json +++ b/packages/docusaurus-init/package.json @@ -25,8 +25,8 @@ "chalk": "^3.0.0", "commander": "^4.0.1", "fs-extra": "^9.0.1", - "inquirer": "^7.1.0", "lodash.kebabcase": "^4.1.1", + "prompts": "^2.4.0", "semver": "^6.3.0", "shelljs": "^0.8.4" }, diff --git a/packages/docusaurus-init/src/index.ts b/packages/docusaurus-init/src/index.ts index 9544054c09b8..877d1c61da98 100644 --- a/packages/docusaurus-init/src/index.ts +++ b/packages/docusaurus-init/src/index.ts @@ -8,7 +8,7 @@ import chalk from 'chalk'; import fs from 'fs-extra'; import {execSync} from 'child_process'; -import inquirer from 'inquirer'; +import prompts, {Choice} from 'prompts'; import path from 'path'; import shell from 'shelljs'; import kebabCase from 'lodash.kebabcase'; @@ -52,20 +52,27 @@ export default async function init( .readdirSync(templatesDir) .filter((d) => !d.startsWith('.') && !d.startsWith('README')); - const gitChoice = 'Git repository'; - const templateChoices = [...templates, gitChoice]; + function makeNameAndValueChoice(value: string): Choice { + return {title: value, value} as Choice; + } + + const gitChoice = makeNameAndValueChoice('Git repository'); + const templateChoices = [ + ...templates.map((template) => makeNameAndValueChoice(template)), + gitChoice, + ]; let name = siteName; // Prompt if siteName is not passed from CLI. if (!name) { - const {name: promptedName} = await inquirer.prompt({ - type: 'input', + const prompt = await prompts({ + type: 'text', name: 'name', message: 'What should we name this site?', - default: 'website', + initial: 'website', }); - name = promptedName; + name = prompt.name; } if (!name) { @@ -80,19 +87,19 @@ export default async function init( let template = reqTemplate; // Prompt if template is not provided from CLI. if (!template) { - const {template: promptedTemplate} = await inquirer.prompt({ - type: 'list', + const templatePrompt = await prompts({ + type: 'select', name: 'template', message: 'Select a template below...', choices: templateChoices, }); - template = promptedTemplate; + template = templatePrompt.template; } // If user choose Git repository, we'll prompt for the url. - if (template === gitChoice) { - const {gitRepoUrl} = await inquirer.prompt({ - type: 'input', + if (template === 'Git repository') { + const repoPrompt = await prompts({ + type: 'text', name: 'gitRepoUrl', validate: (url?: string) => { if (url && isValidGitRepoUrl(url)) { @@ -103,7 +110,7 @@ export default async function init( message: 'Enter a repository URL from GitHub, BitBucket, GitLab, or any other public repo. \n(e.g: https://github.com/ownerName/repoName.git)', }); - template = gitRepoUrl; + template = repoPrompt.gitRepoUrl; } console.log(); diff --git a/packages/docusaurus/README.MD b/packages/docusaurus/README.md similarity index 100% rename from packages/docusaurus/README.MD rename to packages/docusaurus/README.md diff --git a/packages/docusaurus/src/webpack/plugins/WaitPlugin.js b/packages/docusaurus/src/webpack/plugins/WaitPlugin.ts similarity index 64% rename from packages/docusaurus/src/webpack/plugins/WaitPlugin.js rename to packages/docusaurus/src/webpack/plugins/WaitPlugin.ts index aa2abce5fc31..e626504abaa1 100644 --- a/packages/docusaurus/src/webpack/plugins/WaitPlugin.js +++ b/packages/docusaurus/src/webpack/plugins/WaitPlugin.ts @@ -5,20 +5,27 @@ * LICENSE file in the root directory of this source tree. */ -const path = require('path'); -const fs = require('fs-extra'); -const waitOn = require('wait-on'); +import path from 'path'; +import fs from 'fs-extra'; +import waitOn from 'wait-on'; +import {Compiler} from 'webpack'; -class WaitPlugin { - constructor(options) { +interface WaitPluginOptions { + filepath: string; +} + +export default class WaitPlugin { + filepath: string; + + constructor(options: WaitPluginOptions) { this.filepath = options.filepath; } - apply(compiler) { + apply(compiler: Compiler) { // Before finishing the compilation step compiler.hooks.make.tapAsync('WaitPlugin', (compilation, callback) => { // To prevent 'waitFile' error on waiting non-existing directory - fs.ensureDir(path.dirname(this.filepath), () => { + fs.ensureDir(path.dirname(this.filepath), {}, () => { // Wait until file exist waitOn({ resources: [this.filepath], @@ -27,12 +34,10 @@ class WaitPlugin { .then(() => { callback(); }) - .catch((error) => { + .catch((error: Error) => { console.warn(`WaitPlugin error: ${error}`); }); }); }); } } - -module.exports = WaitPlugin; diff --git a/yarn.lock b/yarn.lock index 24d514146b38..6ce2ba1192c6 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3581,6 +3581,13 @@ resolved "https://registry.yarnpkg.com/@types/prismjs/-/prismjs-1.16.1.tgz#50b82947207847db6abcbcd14caa89e3b897c259" integrity sha512-RNgcK3FEc1GpeOkamGDq42EYkb6yZW5OWQwTS56NJIB8WL0QGISQglA7En7NUx9RGP8AC52DOe+squqbAckXlA== +"@types/prompts@^2.0.9": + version "2.0.9" + resolved "https://registry.yarnpkg.com/@types/prompts/-/prompts-2.0.9.tgz#19f419310eaa224a520476b19d4183f6a2b3bd8f" + integrity sha512-TORZP+FSjTYMWwKadftmqEn6bziN5RnfygehByGsjxoK5ydnClddtv6GikGWPvCm24oI+YBwck5WDxIIyNxUrA== + dependencies: + "@types/node" "*" + "@types/prop-types@*": version "15.7.3" resolved "https://registry.yarnpkg.com/@types/prop-types/-/prop-types-15.7.3.tgz#2ab0d5da2e5815f94b0b9d4b95d1e5f243ab2ca7" @@ -3724,9 +3731,9 @@ integrity sha512-/gG2M/Imw7cQFp8PGvz/SwocNrmKFjFsm5Pb8HdbHkZ1K8pmuPzOX4VeVoiEecFCVf4CsN1r3/BRvx+6sNqwtQ== "@types/through@*": - version "0.0.29" - resolved "https://registry.yarnpkg.com/@types/through/-/through-0.0.29.tgz#72943aac922e179339c651fa34a4428a4d722f93" - integrity sha512-9a7C5VHh+1BKblaYiq+7Tfc+EOmjMdZaD1MYtkQjSoxgB69tBjW98ry6SKsi4zEIWztLOMRuL87A3bdT/Fc/4w== + version "0.0.30" + resolved "https://registry.yarnpkg.com/@types/through/-/through-0.0.30.tgz#e0e42ce77e897bd6aead6f6ea62aeb135b8a3895" + integrity sha512-FvnCJljyxhPM3gkRgWmxmDZyAQSiBQQWLI0A0VFL0K7W1oRUrPJSqNO0NvTnLkBcotdlp3lKvaT0JrnyRDkzOg== dependencies: "@types/node" "*" @@ -3742,6 +3749,11 @@ resolved "https://registry.yarnpkg.com/@types/unist/-/unist-2.0.3.tgz#9c088679876f374eb5983f150d4787aa6fb32d7e" integrity sha512-FvUupuM3rlRsRtCN+fDudtmytGO6iHJuuRKS1Ss0pG5z8oX0diNEw94UEL7hgDbpN94rgaK5R7sWm6RrSkZuAQ== +"@types/wait-on@^5.2.0": + version "5.2.0" + resolved "https://registry.yarnpkg.com/@types/wait-on/-/wait-on-5.2.0.tgz#f9096b7bd0c9c03052d6d402ae5cd51714480b2d" + integrity sha512-3+jsMyPm8aot1mqDUDLOl+dejPvpysUUoUXD6CCRY20MNNhcjEfvdcBnGdnk7DEYs9Hr16ubGJA/9/QW0Df/9g== + "@types/webpack-dev-server@*", "@types/webpack-dev-server@^3.9.0": version "3.10.1" resolved "https://registry.yarnpkg.com/@types/webpack-dev-server/-/webpack-dev-server-3.10.1.tgz#93b7133cc9dab1ca1b76659f5ef8b763ad54c28a" @@ -10937,7 +10949,7 @@ inquirer@^6.2.0, inquirer@^6.5.1: strip-ansi "^5.1.0" through "^2.3.6" -inquirer@^7.0.0, inquirer@^7.1.0, inquirer@^7.2.0: +inquirer@^7.0.0, inquirer@^7.2.0: version "7.2.0" resolved "https://registry.yarnpkg.com/inquirer/-/inquirer-7.2.0.tgz#63ce99d823090de7eb420e4bb05e6f3449aa389a" integrity sha512-E0c4rPwr9ByePfNlTIB8z51kK1s2n6jrHuJeEHENl/sbq2G/S1auvibgEwNR4uSyiU+PiYHqSwsgGiXjG8p5ZQ== @@ -16358,13 +16370,13 @@ promise@^7.1.1: dependencies: asap "~2.0.3" -prompts@^2.0.1: - version "2.3.2" - resolved "https://registry.yarnpkg.com/prompts/-/prompts-2.3.2.tgz#480572d89ecf39566d2bd3fe2c9fccb7c4c0b068" - integrity sha512-Q06uKs2CkNYVID0VqwfAl9mipo99zkBv/n2JtWY89Yxa3ZabWSrs0e2KTudKVa3peLUvYXMefDqIleLPVUBZMA== +prompts@^2.0.1, prompts@^2.4.0: + version "2.4.0" + resolved "https://registry.yarnpkg.com/prompts/-/prompts-2.4.0.tgz#4aa5de0723a231d1ee9121c40fdf663df73f61d7" + integrity sha512-awZAKrk3vN6CroQukBL+R9051a4R3zCZBlJm/HBfrSZ8iTpYix3VX1vU4mveiLpiwmOJT4wokTF9m6HUk4KqWQ== dependencies: kleur "^3.0.3" - sisteransi "^1.0.4" + sisteransi "^1.0.5" promzard@^0.3.0: version "0.3.0" @@ -18230,7 +18242,7 @@ simple-swizzle@^0.2.2: dependencies: is-arrayish "^0.3.1" -sisteransi@^1.0.4: +sisteransi@^1.0.5: version "1.0.5" resolved "https://registry.yarnpkg.com/sisteransi/-/sisteransi-1.0.5.tgz#134d681297756437cc05ca01370d3a7a571075ed" integrity sha512-bLGGlR1QxBcynn2d5YmDX4MGjlZvy2MRBDRNHLJ8VI6l6+9FUiyTFNJ0IveOSP0bcXgVDPRcfGqA0pjaqUpfVg==