mirror of
https://github.com/facebook/docusaurus.git
synced 2025-04-29 18:27:56 +02:00
chore(v2): docusaurus-init: switch from inquirer to prompts (#4012)
Signed-off-by: Reece Dunham <me@rdil.rocks>
This commit is contained in:
parent
c19c9e5003
commit
a406a3c9aa
6 changed files with 61 additions and 35 deletions
|
@ -86,6 +86,7 @@
|
||||||
"@types/lodash.sortby": "^4.6.6",
|
"@types/lodash.sortby": "^4.6.6",
|
||||||
"@types/node": "^13.11.0",
|
"@types/node": "^13.11.0",
|
||||||
"@types/prismjs": "^1.16.1",
|
"@types/prismjs": "^1.16.1",
|
||||||
|
"@types/prompts": "^2.0.9",
|
||||||
"@types/react": "^16.9.52",
|
"@types/react": "^16.9.52",
|
||||||
"@types/react-dev-utils": "^9.0.1",
|
"@types/react-dev-utils": "^9.0.1",
|
||||||
"@types/react-helmet": "^6.0.0",
|
"@types/react-helmet": "^6.0.0",
|
||||||
|
@ -93,6 +94,7 @@
|
||||||
"@types/react-router-config": "^5.0.1",
|
"@types/react-router-config": "^5.0.1",
|
||||||
"@types/semver": "^7.1.0",
|
"@types/semver": "^7.1.0",
|
||||||
"@types/shelljs": "^0.8.6",
|
"@types/shelljs": "^0.8.6",
|
||||||
|
"@types/wait-on": "^5.2.0",
|
||||||
"@types/webpack": "^4.41.0",
|
"@types/webpack": "^4.41.0",
|
||||||
"@types/webpack-dev-server": "^3.9.0",
|
"@types/webpack-dev-server": "^3.9.0",
|
||||||
"@types/webpack-merge": "^4.1.5",
|
"@types/webpack-merge": "^4.1.5",
|
||||||
|
|
|
@ -25,8 +25,8 @@
|
||||||
"chalk": "^3.0.0",
|
"chalk": "^3.0.0",
|
||||||
"commander": "^4.0.1",
|
"commander": "^4.0.1",
|
||||||
"fs-extra": "^9.0.1",
|
"fs-extra": "^9.0.1",
|
||||||
"inquirer": "^7.1.0",
|
|
||||||
"lodash.kebabcase": "^4.1.1",
|
"lodash.kebabcase": "^4.1.1",
|
||||||
|
"prompts": "^2.4.0",
|
||||||
"semver": "^6.3.0",
|
"semver": "^6.3.0",
|
||||||
"shelljs": "^0.8.4"
|
"shelljs": "^0.8.4"
|
||||||
},
|
},
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
import chalk from 'chalk';
|
import chalk from 'chalk';
|
||||||
import fs from 'fs-extra';
|
import fs from 'fs-extra';
|
||||||
import {execSync} from 'child_process';
|
import {execSync} from 'child_process';
|
||||||
import inquirer from 'inquirer';
|
import prompts, {Choice} from 'prompts';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import shell from 'shelljs';
|
import shell from 'shelljs';
|
||||||
import kebabCase from 'lodash.kebabcase';
|
import kebabCase from 'lodash.kebabcase';
|
||||||
|
@ -52,20 +52,27 @@ export default async function init(
|
||||||
.readdirSync(templatesDir)
|
.readdirSync(templatesDir)
|
||||||
.filter((d) => !d.startsWith('.') && !d.startsWith('README'));
|
.filter((d) => !d.startsWith('.') && !d.startsWith('README'));
|
||||||
|
|
||||||
const gitChoice = 'Git repository';
|
function makeNameAndValueChoice(value: string): Choice {
|
||||||
const templateChoices = [...templates, gitChoice];
|
return {title: value, value} as Choice;
|
||||||
|
}
|
||||||
|
|
||||||
|
const gitChoice = makeNameAndValueChoice('Git repository');
|
||||||
|
const templateChoices = [
|
||||||
|
...templates.map((template) => makeNameAndValueChoice(template)),
|
||||||
|
gitChoice,
|
||||||
|
];
|
||||||
|
|
||||||
let name = siteName;
|
let name = siteName;
|
||||||
|
|
||||||
// Prompt if siteName is not passed from CLI.
|
// Prompt if siteName is not passed from CLI.
|
||||||
if (!name) {
|
if (!name) {
|
||||||
const {name: promptedName} = await inquirer.prompt({
|
const prompt = await prompts({
|
||||||
type: 'input',
|
type: 'text',
|
||||||
name: 'name',
|
name: 'name',
|
||||||
message: 'What should we name this site?',
|
message: 'What should we name this site?',
|
||||||
default: 'website',
|
initial: 'website',
|
||||||
});
|
});
|
||||||
name = promptedName;
|
name = prompt.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!name) {
|
if (!name) {
|
||||||
|
@ -80,19 +87,19 @@ export default async function init(
|
||||||
let template = reqTemplate;
|
let template = reqTemplate;
|
||||||
// Prompt if template is not provided from CLI.
|
// Prompt if template is not provided from CLI.
|
||||||
if (!template) {
|
if (!template) {
|
||||||
const {template: promptedTemplate} = await inquirer.prompt({
|
const templatePrompt = await prompts({
|
||||||
type: 'list',
|
type: 'select',
|
||||||
name: 'template',
|
name: 'template',
|
||||||
message: 'Select a template below...',
|
message: 'Select a template below...',
|
||||||
choices: templateChoices,
|
choices: templateChoices,
|
||||||
});
|
});
|
||||||
template = promptedTemplate;
|
template = templatePrompt.template;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If user choose Git repository, we'll prompt for the url.
|
// If user choose Git repository, we'll prompt for the url.
|
||||||
if (template === gitChoice) {
|
if (template === 'Git repository') {
|
||||||
const {gitRepoUrl} = await inquirer.prompt({
|
const repoPrompt = await prompts({
|
||||||
type: 'input',
|
type: 'text',
|
||||||
name: 'gitRepoUrl',
|
name: 'gitRepoUrl',
|
||||||
validate: (url?: string) => {
|
validate: (url?: string) => {
|
||||||
if (url && isValidGitRepoUrl(url)) {
|
if (url && isValidGitRepoUrl(url)) {
|
||||||
|
@ -103,7 +110,7 @@ export default async function init(
|
||||||
message:
|
message:
|
||||||
'Enter a repository URL from GitHub, BitBucket, GitLab, or any other public repo. \n(e.g: https://github.com/ownerName/repoName.git)',
|
'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();
|
console.log();
|
||||||
|
|
|
@ -5,20 +5,27 @@
|
||||||
* LICENSE file in the root directory of this source tree.
|
* LICENSE file in the root directory of this source tree.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const path = require('path');
|
import path from 'path';
|
||||||
const fs = require('fs-extra');
|
import fs from 'fs-extra';
|
||||||
const waitOn = require('wait-on');
|
import waitOn from 'wait-on';
|
||||||
|
import {Compiler} from 'webpack';
|
||||||
|
|
||||||
class WaitPlugin {
|
interface WaitPluginOptions {
|
||||||
constructor(options) {
|
filepath: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default class WaitPlugin {
|
||||||
|
filepath: string;
|
||||||
|
|
||||||
|
constructor(options: WaitPluginOptions) {
|
||||||
this.filepath = options.filepath;
|
this.filepath = options.filepath;
|
||||||
}
|
}
|
||||||
|
|
||||||
apply(compiler) {
|
apply(compiler: Compiler) {
|
||||||
// Before finishing the compilation step
|
// Before finishing the compilation step
|
||||||
compiler.hooks.make.tapAsync('WaitPlugin', (compilation, callback) => {
|
compiler.hooks.make.tapAsync('WaitPlugin', (compilation, callback) => {
|
||||||
// To prevent 'waitFile' error on waiting non-existing directory
|
// 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
|
// Wait until file exist
|
||||||
waitOn({
|
waitOn({
|
||||||
resources: [this.filepath],
|
resources: [this.filepath],
|
||||||
|
@ -27,12 +34,10 @@ class WaitPlugin {
|
||||||
.then(() => {
|
.then(() => {
|
||||||
callback();
|
callback();
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error: Error) => {
|
||||||
console.warn(`WaitPlugin error: ${error}`);
|
console.warn(`WaitPlugin error: ${error}`);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = WaitPlugin;
|
|
32
yarn.lock
32
yarn.lock
|
@ -3581,6 +3581,13 @@
|
||||||
resolved "https://registry.yarnpkg.com/@types/prismjs/-/prismjs-1.16.1.tgz#50b82947207847db6abcbcd14caa89e3b897c259"
|
resolved "https://registry.yarnpkg.com/@types/prismjs/-/prismjs-1.16.1.tgz#50b82947207847db6abcbcd14caa89e3b897c259"
|
||||||
integrity sha512-RNgcK3FEc1GpeOkamGDq42EYkb6yZW5OWQwTS56NJIB8WL0QGISQglA7En7NUx9RGP8AC52DOe+squqbAckXlA==
|
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@*":
|
"@types/prop-types@*":
|
||||||
version "15.7.3"
|
version "15.7.3"
|
||||||
resolved "https://registry.yarnpkg.com/@types/prop-types/-/prop-types-15.7.3.tgz#2ab0d5da2e5815f94b0b9d4b95d1e5f243ab2ca7"
|
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==
|
integrity sha512-/gG2M/Imw7cQFp8PGvz/SwocNrmKFjFsm5Pb8HdbHkZ1K8pmuPzOX4VeVoiEecFCVf4CsN1r3/BRvx+6sNqwtQ==
|
||||||
|
|
||||||
"@types/through@*":
|
"@types/through@*":
|
||||||
version "0.0.29"
|
version "0.0.30"
|
||||||
resolved "https://registry.yarnpkg.com/@types/through/-/through-0.0.29.tgz#72943aac922e179339c651fa34a4428a4d722f93"
|
resolved "https://registry.yarnpkg.com/@types/through/-/through-0.0.30.tgz#e0e42ce77e897bd6aead6f6ea62aeb135b8a3895"
|
||||||
integrity sha512-9a7C5VHh+1BKblaYiq+7Tfc+EOmjMdZaD1MYtkQjSoxgB69tBjW98ry6SKsi4zEIWztLOMRuL87A3bdT/Fc/4w==
|
integrity sha512-FvnCJljyxhPM3gkRgWmxmDZyAQSiBQQWLI0A0VFL0K7W1oRUrPJSqNO0NvTnLkBcotdlp3lKvaT0JrnyRDkzOg==
|
||||||
dependencies:
|
dependencies:
|
||||||
"@types/node" "*"
|
"@types/node" "*"
|
||||||
|
|
||||||
|
@ -3742,6 +3749,11 @@
|
||||||
resolved "https://registry.yarnpkg.com/@types/unist/-/unist-2.0.3.tgz#9c088679876f374eb5983f150d4787aa6fb32d7e"
|
resolved "https://registry.yarnpkg.com/@types/unist/-/unist-2.0.3.tgz#9c088679876f374eb5983f150d4787aa6fb32d7e"
|
||||||
integrity sha512-FvUupuM3rlRsRtCN+fDudtmytGO6iHJuuRKS1Ss0pG5z8oX0diNEw94UEL7hgDbpN94rgaK5R7sWm6RrSkZuAQ==
|
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":
|
"@types/webpack-dev-server@*", "@types/webpack-dev-server@^3.9.0":
|
||||||
version "3.10.1"
|
version "3.10.1"
|
||||||
resolved "https://registry.yarnpkg.com/@types/webpack-dev-server/-/webpack-dev-server-3.10.1.tgz#93b7133cc9dab1ca1b76659f5ef8b763ad54c28a"
|
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"
|
strip-ansi "^5.1.0"
|
||||||
through "^2.3.6"
|
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"
|
version "7.2.0"
|
||||||
resolved "https://registry.yarnpkg.com/inquirer/-/inquirer-7.2.0.tgz#63ce99d823090de7eb420e4bb05e6f3449aa389a"
|
resolved "https://registry.yarnpkg.com/inquirer/-/inquirer-7.2.0.tgz#63ce99d823090de7eb420e4bb05e6f3449aa389a"
|
||||||
integrity sha512-E0c4rPwr9ByePfNlTIB8z51kK1s2n6jrHuJeEHENl/sbq2G/S1auvibgEwNR4uSyiU+PiYHqSwsgGiXjG8p5ZQ==
|
integrity sha512-E0c4rPwr9ByePfNlTIB8z51kK1s2n6jrHuJeEHENl/sbq2G/S1auvibgEwNR4uSyiU+PiYHqSwsgGiXjG8p5ZQ==
|
||||||
|
@ -16358,13 +16370,13 @@ promise@^7.1.1:
|
||||||
dependencies:
|
dependencies:
|
||||||
asap "~2.0.3"
|
asap "~2.0.3"
|
||||||
|
|
||||||
prompts@^2.0.1:
|
prompts@^2.0.1, prompts@^2.4.0:
|
||||||
version "2.3.2"
|
version "2.4.0"
|
||||||
resolved "https://registry.yarnpkg.com/prompts/-/prompts-2.3.2.tgz#480572d89ecf39566d2bd3fe2c9fccb7c4c0b068"
|
resolved "https://registry.yarnpkg.com/prompts/-/prompts-2.4.0.tgz#4aa5de0723a231d1ee9121c40fdf663df73f61d7"
|
||||||
integrity sha512-Q06uKs2CkNYVID0VqwfAl9mipo99zkBv/n2JtWY89Yxa3ZabWSrs0e2KTudKVa3peLUvYXMefDqIleLPVUBZMA==
|
integrity sha512-awZAKrk3vN6CroQukBL+R9051a4R3zCZBlJm/HBfrSZ8iTpYix3VX1vU4mveiLpiwmOJT4wokTF9m6HUk4KqWQ==
|
||||||
dependencies:
|
dependencies:
|
||||||
kleur "^3.0.3"
|
kleur "^3.0.3"
|
||||||
sisteransi "^1.0.4"
|
sisteransi "^1.0.5"
|
||||||
|
|
||||||
promzard@^0.3.0:
|
promzard@^0.3.0:
|
||||||
version "0.3.0"
|
version "0.3.0"
|
||||||
|
@ -18230,7 +18242,7 @@ simple-swizzle@^0.2.2:
|
||||||
dependencies:
|
dependencies:
|
||||||
is-arrayish "^0.3.1"
|
is-arrayish "^0.3.1"
|
||||||
|
|
||||||
sisteransi@^1.0.4:
|
sisteransi@^1.0.5:
|
||||||
version "1.0.5"
|
version "1.0.5"
|
||||||
resolved "https://registry.yarnpkg.com/sisteransi/-/sisteransi-1.0.5.tgz#134d681297756437cc05ca01370d3a7a571075ed"
|
resolved "https://registry.yarnpkg.com/sisteransi/-/sisteransi-1.0.5.tgz#134d681297756437cc05ca01370d3a7a571075ed"
|
||||||
integrity sha512-bLGGlR1QxBcynn2d5YmDX4MGjlZvy2MRBDRNHLJ8VI6l6+9FUiyTFNJ0IveOSP0bcXgVDPRcfGqA0pjaqUpfVg==
|
integrity sha512-bLGGlR1QxBcynn2d5YmDX4MGjlZvy2MRBDRNHLJ8VI6l6+9FUiyTFNJ0IveOSP0bcXgVDPRcfGqA0pjaqUpfVg==
|
||||||
|
|
Loading…
Add table
Reference in a new issue