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): allow init project via npm #3729

Merged
merged 5 commits into from
Nov 16, 2020
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
9 changes: 7 additions & 2 deletions admin/scripts/test-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,14 @@ set -euo pipefail
CUSTOM_REGISTRY_URL="http://localhost:4873"
NEW_VERSION="$(node -p "require('./packages/docusaurus/package.json').version").NEW"
CONTAINER_NAME="verdaccio"
EXTRA_OPTS=""

if getopts ":n" arg; then
EXTRA_OPTS="--use-npm"
fi

# 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
yarn build:packages
Expand All @@ -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 --

# 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
if [[ -z "${KEEP_CONTAINER:-}" ]] && ( $(docker container inspect "$CONTAINER_NAME" > /dev/null 2>&1) ); then
Expand Down
5 changes: 3 additions & 2 deletions packages/docusaurus-init/bin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@ program

program
.command('init [siteName] [template] [rootDir]')
.option('--use-npm')
.description('Initialize website')
.action((siteName, template, rootDir = '.') => {
wrapCommand(init)(path.resolve(rootDir), siteName, template);
.action((siteName, template, rootDir = '.', {useNpm}) => {
wrapCommand(init)(path.resolve(rootDir), siteName, template, {useNpm});
});

program.arguments('<command>').action((cmd) => {
Expand Down
5 changes: 4 additions & 1 deletion packages/docusaurus-init/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,11 @@ export default async function init(
rootDir: string,
siteName?: string,
reqTemplate?: string,
cliOptions: Partial<{
useNpm: boolean;
}> = {},
): Promise<void> {
const useYarn = hasYarn();
const useYarn = !cliOptions.useNpm ? hasYarn() : false;
const templatesDir = path.resolve(__dirname, '../templates');
const templates = fs
.readdirSync(templatesDir)
Expand Down