mirror of
https://github.com/facebook/docusaurus.git
synced 2025-06-06 04:42:40 +02:00
feat(v2): allow init project via npm (#3729)
* feat(v2: allow init project via npm * Add test-website to workspace * Remove test-website from workspace * Refactor
This commit is contained in:
parent
d05d703dad
commit
5f20200661
3 changed files with 14 additions and 5 deletions
|
@ -10,9 +10,14 @@ set -euo pipefail
|
||||||
CUSTOM_REGISTRY_URL="http://localhost:4873"
|
CUSTOM_REGISTRY_URL="http://localhost:4873"
|
||||||
NEW_VERSION="$(node -p "require('./packages/docusaurus/package.json').version").NEW"
|
NEW_VERSION="$(node -p "require('./packages/docusaurus/package.json').version").NEW"
|
||||||
CONTAINER_NAME="verdaccio"
|
CONTAINER_NAME="verdaccio"
|
||||||
|
EXTRA_OPTS=""
|
||||||
|
|
||||||
|
if getopts ":n" arg; then
|
||||||
|
EXTRA_OPTS="--use-npm"
|
||||||
|
fi
|
||||||
|
|
||||||
# Run Docker container with private npm registry Verdaccio
|
# Run Docker container with private npm registry Verdaccio
|
||||||
docker run -d --rm --name "$CONTAINER_NAME" -p 4873:4873 -v "$PWD/admin/verdaccio.yaml":/verdaccio/conf/config.yaml verdaccio/verdaccio:4
|
docker run -d --rm --name "$CONTAINER_NAME" -p 4873:4873 -v "$PWD/admin/verdaccio.yaml":/verdaccio/conf/config.yaml verdaccio/verdaccio:latest
|
||||||
|
|
||||||
# Build packages
|
# Build packages
|
||||||
yarn build:packages
|
yarn build:packages
|
||||||
|
@ -24,7 +29,7 @@ npx --no-install lerna publish --yes --no-verify-access --no-git-reset --no-git-
|
||||||
git diff --name-only -- '*.json' | sed 's, ,\\&,g' | xargs git checkout --
|
git diff --name-only -- '*.json' | sed 's, ,\\&,g' | xargs git checkout --
|
||||||
|
|
||||||
# Build skeleton website with new version
|
# Build skeleton website with new version
|
||||||
npm_config_registry="$CUSTOM_REGISTRY_URL" npx @docusaurus/init@"$NEW_VERSION" init test-website classic
|
npm_config_registry="$CUSTOM_REGISTRY_URL" npx @docusaurus/init@"$NEW_VERSION" init test-website classic $EXTRA_OPTS
|
||||||
|
|
||||||
# Stop Docker container
|
# Stop Docker container
|
||||||
if [[ -z "${KEEP_CONTAINER:-}" ]] && ( $(docker container inspect "$CONTAINER_NAME" > /dev/null 2>&1) ); then
|
if [[ -z "${KEEP_CONTAINER:-}" ]] && ( $(docker container inspect "$CONTAINER_NAME" > /dev/null 2>&1) ); then
|
||||||
|
|
|
@ -38,9 +38,10 @@ program
|
||||||
|
|
||||||
program
|
program
|
||||||
.command('init [siteName] [template] [rootDir]')
|
.command('init [siteName] [template] [rootDir]')
|
||||||
|
.option('--use-npm')
|
||||||
.description('Initialize website')
|
.description('Initialize website')
|
||||||
.action((siteName, template, rootDir = '.') => {
|
.action((siteName, template, rootDir = '.', {useNpm}) => {
|
||||||
wrapCommand(init)(path.resolve(rootDir), siteName, template);
|
wrapCommand(init)(path.resolve(rootDir), siteName, template, {useNpm});
|
||||||
});
|
});
|
||||||
|
|
||||||
program.arguments('<command>').action((cmd) => {
|
program.arguments('<command>').action((cmd) => {
|
||||||
|
|
|
@ -41,8 +41,11 @@ export default async function init(
|
||||||
rootDir: string,
|
rootDir: string,
|
||||||
siteName?: string,
|
siteName?: string,
|
||||||
reqTemplate?: string,
|
reqTemplate?: string,
|
||||||
|
cliOptions: Partial<{
|
||||||
|
useNpm: boolean;
|
||||||
|
}> = {},
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const useYarn = hasYarn();
|
const useYarn = !cliOptions.useNpm ? hasYarn() : false;
|
||||||
const templatesDir = path.resolve(__dirname, '../templates');
|
const templatesDir = path.resolve(__dirname, '../templates');
|
||||||
const templates = fs
|
const templates = fs
|
||||||
.readdirSync(templatesDir)
|
.readdirSync(templatesDir)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue