refactor(v2): cleanup console output (#4979)

* refactor(v2): cleanup console output

* fix jest issue

Co-authored-by: slorber <lorber.sebastien@gmail.com>
This commit is contained in:
Alexey Pyltsyn 2021-06-16 12:37:28 +03:00 committed by GitHub
parent 8501db78a1
commit 41d9288e3d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
86 changed files with 382 additions and 339 deletions

View file

@ -76,12 +76,12 @@ export default async function init(
}
if (!name) {
throw new Error(chalk.red('A site name is required'));
throw new Error(chalk.red('A website name is required.'));
}
const dest = path.resolve(rootDir, name);
if (fs.existsSync(dest)) {
throw new Error(`Directory already exists at ${dest} !`);
throw new Error(`Directory already exists at "${dest}"!`);
}
let template = reqTemplate;
@ -108,22 +108,22 @@ export default async function init(
return chalk.red(`Invalid repository URL`);
},
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 = repoPrompt.gitRepoUrl;
}
console.log();
console.log(chalk.cyan('Creating new Docusaurus project ...'));
console.log(chalk.cyan('Creating new Docusaurus project...'));
console.log();
if (template && isValidGitRepoUrl(template)) {
console.log(`Cloning Git template: ${chalk.cyan(template)}`);
console.log(`Cloning Git template ${chalk.cyan(template)}...`);
if (
shell.exec(`git clone --recursive ${template} ${dest}`, {silent: true})
.code !== 0
) {
throw new Error(chalk.red(`Cloning Git template: ${template} failed!`));
throw new Error(chalk.red(`Cloning Git template ${template} failed!`));
}
} else if (template && templates.includes(template)) {
// Docusaurus templates.
@ -131,12 +131,12 @@ export default async function init(
await fs.copy(path.resolve(templatesDir, template), dest);
} catch (err) {
console.log(
`Copying Docusaurus template: ${chalk.cyan(template)} failed!`,
`Copying Docusaurus template ${chalk.cyan(template)} failed!`,
);
throw err;
}
} else {
throw new Error('Invalid template');
throw new Error('Invalid template.');
}
// Update package.json info.
@ -147,7 +147,7 @@ export default async function init(
private: true,
});
} catch (err) {
console.log(chalk.red('Failed to update package.json'));
console.log(chalk.red('Failed to update package.json.'));
throw err;
}
@ -164,12 +164,12 @@ export default async function init(
const pkgManager = useYarn ? 'yarn' : 'npm';
if (!cliOptions.skipInstall) {
console.log(`Installing dependencies with: ${chalk.cyan(pkgManager)}`);
console.log(`Installing dependencies with ${chalk.cyan(pkgManager)}...`);
try {
shell.exec(`cd "${name}" && ${useYarn ? 'yarn' : 'npm install'}`);
} catch (err) {
console.log(chalk.red('Installation failed'));
console.log(chalk.red('Installation failed.'));
throw err;
}
}
@ -182,23 +182,26 @@ export default async function init(
: path.relative(process.cwd(), name);
console.log();
console.log(`Success! Created ${chalk.cyan(cdpath)}`);
console.log(`Successfully created "${chalk.cyan(cdpath)}".`);
console.log('Inside that directory, you can run several commands:');
console.log();
console.log(chalk.cyan(` ${pkgManager} start`));
console.log(' Starts the development server.');
console.log();
console.log(chalk.cyan(` ${pkgManager} ${useYarn ? '' : 'run '}build`));
console.log(' Bundles the app into static files for production.');
console.log(' Bundles your website into static files for production.');
console.log();
console.log(chalk.cyan(` ${pkgManager} ${useYarn ? '' : 'run '}serve`));
console.log(' Serve the built website locally.');
console.log();
console.log(chalk.cyan(` ${pkgManager} deploy`));
console.log(' Publish website to GitHub pages.');
console.log(' Publish the website to GitHub pages.');
console.log();
console.log('We suggest that you begin by typing:');
console.log('We recommend that you begin by typing:');
console.log();
console.log(chalk.cyan(' cd'), cdpath);
console.log(` ${chalk.cyan(`${pkgManager} start`)}`);
console.log();
console.log('Happy hacking!');
console.log('Happy building awesome websites!');
}