Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,15 @@
"@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",
"@types/react-loadable": "^5.5.3",
"@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",
Expand Down
2 changes: 1 addition & 1 deletion packages/docusaurus-init/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
35 changes: 21 additions & 14 deletions packages/docusaurus-init/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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) {
Expand All @@ -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)) {
Expand All @@ -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();
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,27 @@
* LICENSE file in the root directory of this source tree.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For some reason, copyUntypedFiles kept failing on this file locally, so I just ported it to TypeScript.

*/

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],
Expand All @@ -27,12 +34,10 @@ class WaitPlugin {
.then(() => {
callback();
})
.catch((error) => {
.catch((error: Error) => {
console.warn(`WaitPlugin error: ${error}`);
});
});
});
}
}

module.exports = WaitPlugin;
32 changes: 22 additions & 10 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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" "*"

Expand All @@ -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"
Expand Down Expand Up @@ -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==
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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==
Expand Down