Skip to content

Commit

Permalink
feat(v2): allow init project via npm (#3729)
Browse files Browse the repository at this point in the history
* feat(v2: allow init project via npm

* Add test-website to workspace

* Remove test-website from workspace

* Refactor
  • Loading branch information
lex111 authored Nov 16, 2020
1 parent d05d703 commit 5f20200
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
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

0 comments on commit 5f20200

Please sign in to comment.