feat: npm init docusaurus, yarn create docusaurus (#5635)

* initial create-docusaurus impl

* cleanup

* @docusaurus/init renamed to create-docusaurus

* 0.0.6

* update lockfile

* fix lint

* remove npm2yarn for "npm init" because npm2yarn doesn't convert it and yarn result fails to execute

* prettier

* add correct version

* prettier

* prettier

* prettier

* prettier

* fix annoying --config .prettierrc issue
This commit is contained in:
Sébastien Lorber 2021-10-07 16:06:42 +02:00 committed by GitHub
parent e1b4da04fe
commit f6ec757aa0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
102 changed files with 80 additions and 93 deletions

View file

@ -15,4 +15,5 @@ packages/docusaurus-*/lib/*
packages/docusaurus-*/lib-next/
packages/docusaurus-plugin-ideal-image/copyUntypedFiles.js
packages/docusaurus-init/templates/facebook/.eslintrc.js
packages/create-docusaurus/lib/*
packages/create-docusaurus/templates/facebook/.eslintrc.js

View file

@ -136,9 +136,9 @@ module.exports = {
overrides: [
{
files: [
'packages/docusaurus-init/templates/**/*.js',
'packages/docusaurus-init/templates/**/*.ts',
'packages/docusaurus-init/templates/**/*.tsx',
'packages/create-docusaurus/templates/**/*.js',
'packages/create-docusaurus/templates/**/*.ts',
'packages/create-docusaurus/templates/**/*.tsx',
],
rules: {
'header/header': OFF,

View file

@ -9,10 +9,6 @@ on:
pull_request:
branches:
- main
paths-ignore:
- 'website-1.x/**'
- 'packages/docusaurus-1.x/**'
- 'packages/docusaurus-init-1.x/**'
jobs:
build:

View file

@ -6,9 +6,6 @@ on:
- main
paths-ignore:
- 'website/docs/**'
- 'website-1.x/**'
- 'packages/docusaurus-1.x/**'
- 'packages/docusaurus-init-1.x/**'
jobs:
build:

View file

@ -4,10 +4,6 @@ on:
pull_request_target:
branches:
- main
paths-ignore:
- 'website-1.x/**'
- 'packages/docusaurus-1.x/**'
- 'packages/docusaurus-init-1.x/**'
jobs:
build:

View file

@ -7,10 +7,6 @@ on:
pull_request:
branches:
- main
paths-ignore:
- 'website-1.x/**'
- 'packages/docusaurus-1.x/**'
- 'packages/docusaurus-init-1.x/**'
jobs:
yarn-v1:

View file

@ -4,10 +4,6 @@ on:
pull_request:
branches:
- main
paths-ignore:
- 'website-1.x/**'
- 'packages/docusaurus-1.x/**'
- 'packages/docusaurus-init-1.x/**'
jobs:
build:

View file

@ -4,10 +4,6 @@ on:
pull_request:
branches:
- main
paths-ignore:
- 'website-1.x/**'
- 'packages/docusaurus-1.x/**'
- 'packages/docusaurus-init-1.x/**'
jobs:
test:

1
.gitignore vendored
View file

@ -19,6 +19,7 @@ types
test-website
test-website-in-workspace
packages/create-docusaurus/lib/
packages/docusaurus/lib/
packages/docusaurus-*/lib/*
packages/docusaurus-*/lib-next/

View file

@ -7,7 +7,8 @@ coverage
packages/docusaurus/lib/
packages/docusaurus-*/lib/*
packages/docusaurus-*/lib-next/
packages/docusaurus-init/templates/*/docusaurus.config.js
packages/create-docusaurus/lib/*
packages/create-docusaurus/templates/*/docusaurus.config.js
__fixtures__
website/i18n

View file

@ -1,2 +1,2 @@
packages/docusaurus-init/templates/
packages/create-docusaurus/templates/
examples

View file

@ -48,13 +48,13 @@ Short on time? Check out our [5-minute tutorial ⏱️](https://tutorial.docusau
Use the initialization cli to create your site:
```bash
npx @docusaurus/init@latest init [name] [template]
npm init docusaurus@latest [name] [template]
```
Example:
```bash
npx @docusaurus/init@latest init my-website classic
npm init docusaurus@latest my-website classic
```
## Contributing

View file

@ -6,7 +6,7 @@ There are two reasonable ways to use a local version of the Docusaurus npm packa
## Install from a local Docusaurus repo
> If you want to use the docusaurus-init script for testing, you will have to update the `initialize.js` file to point to the local Docusaurus repo instead of installing it from the npm server. In some ways, it is just easier to do the manual steps.
> If you want to use the docusaurus init script for testing, you will have to update the `initialize.js` file to point to the local Docusaurus repo instead of installing it from the npm server. In some ways, it is just easier to do the manual steps.
### Install the package from the Docusaurus repo

View file

@ -153,12 +153,11 @@ npm access ls-packages
"@docusaurus/theme-live-codeblock": "read-write",
"@docusaurus/plugin-google-analytics": "read-write",
"@docusaurus/plugin-google-gtag": "read-write",
"@docusaurus/init": "read-write",
"@docusaurus/plugin-content-docs-legacy": "read-write",
"@docusaurus/plugin-ideal-image": "read-write",
"@docusaurus/types": "read-write",
"create-docusaurus": "read-write",
"docusaurus": "read-write",
"docusaurus-init": "read-write",
"stylelint-copyright": "read-write"
}
</pre>
@ -166,11 +165,10 @@ npm access ls-packages
It can happen that some accesses are not granted, as an admin might add you to the @docusaurus NPM organization, but you don't have access to the packages that are not in that organization.
Please **double-check your permissions on these 3 packages**, otherwise you'll publish a half-release and will have to release a new version.
Please **double-check your permissions on these packages**, otherwise you'll publish a half-release and will have to release a new version.
```
"docusaurus": "read-write",
"docusaurus-init": "read-write",
"create-docusaurus": "read-write",
"stylelint-copyright": "read-write"
```

View file

@ -32,7 +32,7 @@ shift $((OPTIND-1))
if [ ! -z $EXTRA_OPTS ]
then
echo docusaurus-init extra options = ${EXTRA_OPTS}
echo create-docusaurus extra options = ${EXTRA_OPTS}
fi
# Run Docker container with private npm registry Verdaccio
@ -48,7 +48,7 @@ npx --no-install lerna publish --exact --yes --no-verify-access --no-git-reset -
git diff --name-only -- '*.json' | sed 's, ,\\&,g' | xargs git checkout --
# Build skeleton website with new version
npm_config_registry="$CUSTOM_REGISTRY_URL" npx @docusaurus/init@"$NEW_VERSION" init test-website classic $EXTRA_OPTS
npm_config_registry="$CUSTOM_REGISTRY_URL" npm init docusaurus@"$NEW_VERSION" test-website classic $EXTRA_OPTS
# Stop Docker container
if [[ -z "${KEEP_CONTAINER:-}" ]] && ( $(docker container inspect "$CONTAINER_NAME" > /dev/null 2>&1) ); then

View file

@ -27,7 +27,7 @@ function generateTemplateExample(template) {
// /!\ we use the published init script on purpose,
// because using the local init script is too early and could generate upcoming/unavailable config options
// remember CodeSandbox templates will use the published version, not the repo version
`npx @docusaurus/init@latest init examples/${template} ${command}`,
`npm init docusaurus@latest examples/${template} ${command}`,
// `node ./packages/docusaurus-init/bin/index.js init examples/${template} ${template}`,
{
stdio: 'inherit',
@ -175,9 +175,9 @@ function run() {
console.log('## Generate example folders...');
console.log('');
const excludes = ['README.md', 'shared'];
const templates = readdirSync('./packages/docusaurus-init/templates').filter(
(name) => !excludes.includes(name),
);
const templates = readdirSync(
'./packages/create-docusaurus/templates',
).filter((name) => !excludes.includes(name));
console.log(`Will generate examples for templates: ${templates}`);
templates.forEach(generateTemplateExample);
console.log('Commiting changes');

View file

@ -4,7 +4,7 @@
"packages/*",
"website",
"test-website-in-workspace",
"packages/docusaurus-init/templates/*",
"packages/create-docusaurus/templates/*",
"admin/new.docusaurus.io"
],
"scripts": {
@ -119,10 +119,10 @@
"lint-staged": {
"*.{js,jsx,ts,tsx}": [
"eslint --fix",
"prettier --write"
"prettier --config .prettierrc --write"
],
"*.{md,mdx}": [
"prettier --write"
"prettier --config .prettierrc --write"
]
},
"engines": {

View file

@ -1,6 +1,14 @@
# `@docusaurus/init`
# `create-docusaurus`
Create Docusaurus apps easily.
Create Docusaurus apps easily with simplified commands:
```bash
npm init docusaurus
```
```bash
yarn create docusaurus
```
## Usage
@ -13,7 +21,7 @@ For Docusaurus maintainers, templates can be tested with:
```bash
cd `git rev-parse --show-toplevel` # Back to repo root
rm -rf test-website
yarn docusaurus-init init test-website classic
yarn create-docusaurus test-website classic
cd test-website
yarn start
```
@ -25,7 +33,7 @@ Use the following to test the templates against local packages:
```bash
cd `git rev-parse --show-toplevel` # Back to repo root
rm -rf test-website-in-workspace
yarn docusaurus-init init test-website-in-workspace classic
yarn create-docusaurus test-website-in-workspace classic
cd test-website-in-workspace
yarn start
```

View file

@ -36,7 +36,7 @@ program
.usage('<command> [options]');
program
.command('init [siteName] [template] [rootDir]')
.command('init [siteName] [template] [rootDir]', {isDefault: true})
.option('--use-npm')
.option('--skip-install')
.option('--typescript')
@ -59,6 +59,6 @@ program.arguments('<command>').action((cmd) => {
program.parse(process.argv);
if (!process.argv.slice(2).length) {
if (!process.argv.slice(1).length) {
program.outputHelp();
}

View file

@ -1,21 +1,22 @@
{
"name": "@docusaurus/init",
"name": "create-docusaurus",
"version": "2.0.0-beta.6",
"description": "Create Docusaurus apps easily.",
"repository": {
"type": "git",
"url": "https://github.com/facebook/docusaurus.git",
"directory": "packages/docusaurus-init"
"directory": "packages/create-docusaurus"
},
"bugs": {
"url": "https://github.com/facebook/docusaurus/issues"
},
"scripts": {
"create-docusaurus": "create-docusaurus",
"build": "tsc",
"watch": "tsc --watch"
},
"bin": {
"docusaurus-init": "bin/index.js"
"create-docusaurus": "bin/index.js"
},
"publishConfig": {
"access": "public"

View file

@ -1,6 +1,6 @@
# Templates
Official templates provided by Docusaurus. They are designed to be selected when using the `npx @docusaurus/init init [name] [template]` CLI command.
Official templates provided by Docusaurus. They are designed to be selected when using the `npm init docusaurus` CLI command.
## Guide to Test Templates for Developer

View file

Before

Width:  |  Height:  |  Size: 4.6 KiB

After

Width:  |  Height:  |  Size: 4.6 KiB

View file

@ -17,7 +17,7 @@ Or **try Docusaurus immediately** with **[docusaurus.new](https://docusaurus.new
Generate a new Docusaurus site using the **classic template**:
```shell
npx @docusaurus/init@latest init my-website classic
npm init docusaurus@latest my-website classic
```
## Start your site

View file

Before

Width:  |  Height:  |  Size: 3.5 KiB

After

Width:  |  Height:  |  Size: 3.5 KiB

View file

Before

Width:  |  Height:  |  Size: 6.3 KiB

After

Width:  |  Height:  |  Size: 6.3 KiB

View file

@ -51,7 +51,7 @@ The end result can be seen at [docusaurus-crowdin-example.netlify.app](https://d
Initialize a new Docusaurus site:
```bash
npx @docusaurus/init@latest init website classic
npm init docusaurus@latest website classic
```
Add the site configuration for the French language:

View file

@ -39,7 +39,7 @@ This is a walk-through of using Git to translate a newly initialized English Doc
Initialize a new Docusaurus site:
```bash
npx @docusaurus/init@latest init website classic
npm init docusaurus@latest website classic
```
Add the site configuration for the French language:

View file

@ -8,7 +8,7 @@ This tutorial will walk you through the basis of the **Docusaurus i18n system**.
We will add **French** translations to a **newly initialized English Docusaurus website**.
Initialize a new site with `npx @docusaurus/init@latest init website classic` (like [this one](https://github.com/facebook/docusaurus/tree/main/examples/classic)).
Initialize a new site with `npm init docusaurus@latest website classic` (like [this one](https://github.com/facebook/docusaurus/tree/main/examples/classic)).
## Configure your site {#configure-your-site}

View file

@ -23,33 +23,33 @@ Use **[docusaurus.new](https://docusaurus.new)** to test Docusaurus immediately
The easiest way to install Docusaurus is to use the command line tool that helps you scaffold a skeleton Docusaurus website. You can run this command anywhere in a new empty repository or within an existing repository, it will create a new directory containing the scaffolded files.
```bash
npx @docusaurus/init@latest init [name] [template]
npm init docusaurus@latest [name] [template]
```
Example:
```bash
npx @docusaurus/init@latest init my-website classic
npm init docusaurus@latest website classic
```
If you do not specify `name` or `template`, it will prompt you for them. We recommend the `classic` template so that you can get started quickly and it contains features found in Docusaurus 1. The `classic` template contains `@docusaurus/preset-classic` which includes standard documentation, a blog, custom pages, and a CSS framework (with dark mode support). You can get up and running extremely quickly with the classic template and customize things later on when you have gained more familiarity with Docusaurus.
If you do not specify `name` or `template`, it will prompt you for them. We recommend the `classic` template so that you can get started quickly, and it contains features found in Docusaurus 1. The `classic` template contains `@docusaurus/preset-classic` which includes standard documentation, a blog, custom pages, and a CSS framework (with dark mode support). You can get up and running extremely quickly with the classic template and customize things later on when you have gained more familiarity with Docusaurus.
**[FB-Only]:** If you are setting up a new Docusaurus website for a Facebook open source project, use the `facebook` template instead, which comes with some useful Facebook-specific defaults:
```bash
npx @docusaurus/init@latest init my-website facebook
npm init docusaurus@latest my-website facebook
```
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
npm init docusaurus@latest my-website classic --skip-install
```
You can also use the template's TypeScript variant by passing the `--typescript` flag.
```bash
npx @docusaurus/init@latest init my-website classic --typescript
npm init docusaurus@latest my-website classic --typescript
```
## Project structure {#project-structure}

View file

@ -26,7 +26,7 @@ Create a new Docusaurus site and follow the **very short** embedded tutorial.
Install [Node.js](https://nodejs.org/en/download/) and create a new Docusaurus site:
```bash
npx @docusaurus/init@latest init my-website classic
npm init docusaurus@latest my-website classic
```
Start the site:

View file

@ -122,7 +122,7 @@ yarn-error.log*
### `README` {#readme}
The D1 website may have an existing README file. You can modify it to reflect the D2 changes, or copy the default [Docusaurus v2 README](https://github.com/facebook/docusaurus/blob/main/packages/docusaurus-init/templates/classic/README.md).
The D1 website may have an existing README file. You can modify it to reflect the D2 changes, or copy the default [Docusaurus v2 README](https://github.com/facebook/docusaurus/blob/main/packages/create-docusaurus/templates/classic/README.md).
## Site configurations {#site-configurations}

View file

@ -10,7 +10,7 @@ Docusaurus is written in TypeScript, and provides first-class TypeScript support
Docusaurus supports writing and using TypeScript theme components. If the init template provides a Typescript variant, you can directly initialize a site with full TypeScript support by using the `--typescript` flag.
```bash
npx @docusaurus/init@latest init my-website classic --typescript
npm init docusaurus@latest my-website classic --typescript
```
Below are some guides on how to migrate an existing project to TypeScript.

View file

@ -51,7 +51,7 @@ The end result can be seen at [docusaurus-crowdin-example.netlify.app](https://d
Initialize a new Docusaurus site:
```bash
npx @docusaurus/init@latest init website classic
npm init docusaurus@latest website classic
```
Add the site configuration for the French language:

View file

@ -39,7 +39,7 @@ This is a walk-through of using Git to translate a newly initialized English Doc
Initialize a new Docusaurus site:
```bash
npx @docusaurus/init@latest init website classic
npm init docusaurus@latest website classic
```
Add the site configuration for the French language:

View file

@ -8,7 +8,7 @@ This tutorial will walk you through the basis of the **Docusaurus i18n system**.
We will add **French** translations to a **newly initialized English Docusaurus website**.
Initialize a new site with `npx @docusaurus/init@latest init website classic` (like [this one](https://github.com/facebook/docusaurus/tree/main/examples/classic)).
Initialize a new site with `npm init docusaurus@latest website classic` (like [this one](https://github.com/facebook/docusaurus/tree/main/examples/classic)).
## Configure your site {#configure-your-site}

View file

@ -23,13 +23,13 @@ Use **[docusaurus.new](https://docusaurus.new)** to test Docusaurus immediately
The easiest way to install Docusaurus is to use the command line tool that helps you scaffold a skeleton Docusaurus website. You can run this command anywhere in a new empty repository or within an existing repository, it will create a new directory containing the scaffolded files.
```bash
npx @docusaurus/init@latest init [name] [template]
npm init docusaurus@latest [name] [template]
```
Example:
```bash
npx @docusaurus/init@latest init my-website classic
npm init docusaurus@latest my-website classic
```
If you do not specify `name` or `template`, it will prompt you for them. We recommend the `classic` template so that you can get started quickly and it contains features found in Docusaurus 1. The `classic` template contains `@docusaurus/preset-classic` which includes standard documentation, a blog, custom pages, and a CSS framework (with dark mode support). You can get up and running extremely quickly with the classic template and customize things later on when you have gained more familiarity with Docusaurus.
@ -37,25 +37,25 @@ If you do not specify `name` or `template`, it will prompt you for them. We reco
**[FB-Only]:** If you are setting up a new Docusaurus website for a Facebook open source project, use the `facebook` template instead, which comes with some useful Facebook-specific defaults:
```bash
npx @docusaurus/init@latest init my-website facebook
npm init docusaurus@latest my-website facebook
```
**[Experimental]:** If you want setting up a new website using [bootstrap](https://getbootstrap.com/), use the `bootstrap` template, like the following:
```bash
npx @docusaurus/init@latest init my-website bootstrap
npm init docusaurus@latest 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
npm init docusaurus@latest my-website classic --skip-install
```
You can also use the template's TypeScript variant by passing the `--typescript` flag.
```bash
npx @docusaurus/init@latest init my-website classic --typescript
npm init docusaurus@latest my-website classic --typescript
```
## Project structure {#project-structure}

View file

@ -26,7 +26,7 @@ Create a new Docusaurus site and follow the **very short** embedded tutorial.
Install [Node.js](https://nodejs.org/en/download/) and create a new Docusaurus site:
```bash
npx @docusaurus/init@latest init my-website classic
npm init docusaurus@latest my-website classic
```
Start the site:

View file

@ -122,7 +122,7 @@ yarn-error.log*
### `README` {#readme}
The D1 website may have an existing README file. You can modify it to reflect the D2 changes, or copy the default [Docusaurus v2 README](https://github.com/facebook/docusaurus/blob/main/packages/docusaurus-init/templates/classic/README.md).
The D1 website may have an existing README file. You can modify it to reflect the D2 changes, or copy the default [Docusaurus v2 README](https://github.com/facebook/docusaurus/blob/main/packages/create-docusaurus/templates/classic/README.md).
## Site configurations {#site-configurations}

View file

@ -10,7 +10,7 @@ Docusaurus is written in TypeScript, and provide first-class TypeScript support.
Docusaurus supports writing and using TypeScript theme components. If the init template provides a Typescript variant, you can directly initialize a site with full TypeScript support by using the `--typescript` flag.
```bash
npx @docusaurus/init@latest init my-website classic --typescript
npm init docusaurus@latest my-website classic --typescript
```
Below are some guides on how to migrate an existing project to TypeScript.

View file

@ -51,7 +51,7 @@ The end result can be seen at [docusaurus-crowdin-example.netlify.app](https://d
Initialize a new Docusaurus site:
```bash
npx @docusaurus/init@latest init website classic
npm init docusaurus@latest website classic
```
Add the site configuration for the French language:

View file

@ -39,7 +39,7 @@ This is a walk-through of using Git to translate a newly initialized English Doc
Initialize a new Docusaurus site:
```bash
npx @docusaurus/init@latest init website classic
npm init docusaurus@latest website classic
```
Add the site configuration for the French language:

View file

@ -8,7 +8,7 @@ This tutorial will walk you through the basis of the **Docusaurus i18n system**.
We will add **French** translations to a **newly initialized English Docusaurus website**.
Initialize a new site with `npx @docusaurus/init@latest init website classic` (like [this one](https://github.com/facebook/docusaurus/tree/main/examples/classic)).
Initialize a new site with `npm init docusaurus@latest website classic` (like [this one](https://github.com/facebook/docusaurus/tree/main/examples/classic)).
## Configure your site {#configure-your-site}

View file

@ -23,13 +23,13 @@ Use **[docusaurus.new](https://docusaurus.new)** to test Docusaurus immediately
The easiest way to install Docusaurus is to use the command line tool that helps you scaffold a skeleton Docusaurus website. You can run this command anywhere in a new empty repository or within an existing repository, it will create a new directory containing the scaffolded files.
```bash
npx @docusaurus/init@latest init [name] [template]
npm init docusaurus@latest [name] [template]
```
Example:
```bash
npx @docusaurus/init@latest init my-website classic
npm init docusaurus@latest my-website classic
```
If you do not specify `name` or `template`, it will prompt you for them. We recommend the `classic` template so that you can get started quickly and it contains features found in Docusaurus 1. The `classic` template contains `@docusaurus/preset-classic` which includes standard documentation, a blog, custom pages, and a CSS framework (with dark mode support). You can get up and running extremely quickly with the classic template and customize things later on when you have gained more familiarity with Docusaurus.
@ -37,25 +37,25 @@ If you do not specify `name` or `template`, it will prompt you for them. We reco
**[FB-Only]:** If you are setting up a new Docusaurus website for a Facebook open source project, use the `facebook` template instead, which comes with some useful Facebook-specific defaults:
```bash
npx @docusaurus/init@latest init my-website facebook
npm init docusaurus@latest my-website facebook
```
**[Experimental]:** If you want setting up a new website using [bootstrap](https://getbootstrap.com/), use the `bootstrap` template, like the following:
```bash
npx @docusaurus/init@latest init my-website bootstrap
npm init docusaurus@latest 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
npm init docusaurus@latest my-website classic --skip-install
```
You can also use the template's TypeScript variant by passing the `--typescript` flag.
```bash
npx @docusaurus/init@latest init my-website classic --typescript
npm init docusaurus@latest my-website classic --typescript
```
## Project structure {#project-structure}

View file

@ -26,7 +26,7 @@ Create a new Docusaurus site and follow the **very short** embedded tutorial.
Install [Node.js](https://nodejs.org/en/download/) and create a new Docusaurus site:
```bash
npx @docusaurus/init@latest init my-website classic
npm init docusaurus@latest my-website classic
```
Start the site:

Some files were not shown because too many files have changed in this diff Show more