Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(v2): skip dependency install on docusaurus init #3986

Merged
merged 2 commits into from
Jan 4, 2021
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
8 changes: 6 additions & 2 deletions packages/docusaurus-init/bin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,13 @@ program
program
.command('init [siteName] [template] [rootDir]')
.option('--use-npm')
.option('--skip-install')
.description('Initialize website')
.action((siteName, template, rootDir = '.', {useNpm}) => {
wrapCommand(init)(path.resolve(rootDir), siteName, template, {useNpm});
.action((siteName, template, rootDir = '.', {useNpm, skipInstall}) => {
wrapCommand(init)(path.resolve(rootDir), siteName, template, {
useNpm,
skipInstall,
});
});

program.arguments('<command>').action((cmd) => {
Expand Down
16 changes: 9 additions & 7 deletions packages/docusaurus-init/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export default async function init(
reqTemplate?: string,
cliOptions: Partial<{
useNpm: boolean;
skipInstall: boolean;
}> = {},
): Promise<void> {
const useYarn = !cliOptions.useNpm ? hasYarn() : false;
Expand Down Expand Up @@ -155,14 +156,15 @@ 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'));
throw err;
try {
shell.exec(`cd "${name}" && ${useYarn ? 'yarn' : 'npm install'}`);
} catch (err) {
console.log(chalk.red('Installation failed'));
throw err;
}
}
console.log();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ module.exports = {
items: [{label: 'Twitter', to: 'https://twitter.com/docusaurus'}],
},
],
copyright: 'Copyright © 2020 Facebook Inc.',
copyright: 'Copyright © 2021 Facebook Inc.',
logo: {src: 'img/docusaurus_monochrome.svg'},
},
algolia: {
Expand Down
6 changes: 6 additions & 0 deletions website/docs/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ npx @docusaurus/init@latest init my-website facebook
npx @docusaurus/init@latest init my-website bootstrap
```

If you want to skip installing dependencies, use the `--skip-install` option, like the following:

```bash
npx @docusaurus/init@latest init my-website classic --skip-install
```

## Project structure

Assuming you chose the classic template and named your site `my-website`, you will see the following files generated under a new directory `my-website/`:
Expand Down