facebook / docusaurus

Easy to maintain open source documentation websites.
https://docusaurus.io
MIT License
56.38k stars 8.46k forks source link

[v2]: Add option to skip dependency install when initializing new Docusaurus project #3450

Closed facultymatt closed 3 years ago

facultymatt commented 4 years ago

šŸš€ Feature

When initializing a new Docusaurus project, a user might wish to skip the dependency install and handle it later on their own. This would be done by passing a flag such as npx @docusaurus/init@next init [name] [template] --skip-install. This is supported in other React ecosystem libraries such as Storybook, and there is an open issue on Create React App for this feature, too: https://github.com/facebook/create-react-app/issues/7568

Have you read the Contributing Guidelines on issues?

Yes

Motivation

This feature would be especially useful when installing Docusarus as one of many packages in a project and wanting to install all dependencies at one time at the end to help avoid conflicts and speed up each individual install. A Lerna project or Yarn Workspace comes to mind.

Pitch

Run npx @docusaurus/init@next init [name] [template] --skip-install and get work done faster!

facultymatt commented 4 years ago

For implementation, since Docusaurus already uses commander it would be easy to support a flag. See https://github.com/facebook/docusaurus/blob/master/packages/docusaurus-init/bin/index.js#L39-L44. The code would look like this which uses almost the exact syntax from Storybooks which the addition of defaulting to false

program
  .command('init [siteName] [template] [rootDir]')
  .option('-s --skip-install', 'Skip installing deps', false)
  .description('Initialize website')
  .action((siteName, template, rootDir = '.', cmdObj) => {
    wrapCommand(init)(path.resolve(rootDir), siteName, template, cmdObj.skipInstall);
  });

This change would wrap the following lines in a conditional based on the flag: https://github.com/facebook/docusaurus/blob/master/packages/docusaurus-init/src/index.ts#L154-L164

if (skipInstall === false) {
  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;
  }
  console.log();
}

NOTE this change would also require updating the docs

slorber commented 4 years ago

@facultymatt I'm not against, but do you actually plan to use this feature? I wonder if it's useful to add an option if nobody feels the need for using it right now, as it seems a particularly niche usecase and our userbase is likely smaller than CRA/Storybook. Any option that we provide and is never used is cluttering the project.

If so, as you have a good idea of how to implement it, are you interested to submit a PR?

alexnaiman commented 4 years ago

Hello! Can I try to tackle this issue for the Hacktoberfest2020? If so, can you assign it to me?

facultymatt commented 4 years ago

Hello, we have a branch what fixes this, just waiting on our company to address the CLA to open the PR.

Iā€™d suggest tackling something else for the hack event! šŸ‘šŸ‘

On Sun, Oct 11, 2020 at 2:35 PM Alexandru Naiman notifications@github.com wrote:

Hello! Can I try to tackle this issue for the Hacktoberfest2020? If so, can you assign it to me?

ā€” You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/facebook/docusaurus/issues/3450#issuecomment-706771497, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAKXKMSKZYTCUUDQPT35WMDSKIQINANCNFSM4RMCV33Q .

slorber commented 4 years ago

Thanks, waiting for your PR @facultymatt

Still interested to know: do you actually need this feature? I'm not 100% sure to understand in which case I'd use it. Do yu often init a new docusaurus project at the same time as you bootstrap a monorepo?

facultymatt commented 3 years ago

Thanks @kumaraditya303 for the PR. Yes @slorber we do this quite frequently - we always use Docusaurus for the landing page / docs and then create react app for the application. Testing out the new flag now. Thanks again!