diff --git a/README.md b/README.md index e1ea1e3..a868979 100644 --- a/README.md +++ b/README.md @@ -10,10 +10,10 @@ React 应用脚手架。创建新项目时,包名、源码和 `src` 下文件 ## 创建项目 -需要 Node.js,以及已登录的 GitHub CLI(`gh auth login`)。 +需要 Node.js 和 curl。 ```bash -curl -fsSL https://raw.githubusercontent.com/bql-691/bq_react/v0.1.0/scripts/create.sh | bash -s -- shop +curl -fsSL https://raw.githubusercontent.com/bql-691/bq_react/v0.1.1/scripts/create.sh | bash -s -- shop ``` 这会在当前目录生成 `shop`,并执行 `npm install`。 diff --git a/scripts/create.sh b/scripts/create.sh index 94ae12e..db0c688 100755 --- a/scripts/create.sh +++ b/scripts/create.sh @@ -1,12 +1,12 @@ #!/usr/bin/env bash # 从公开 GitHub 仓库创建项目,并把源码中的 bq 前缀换成项目名。 # 用法: -# curl -fsSL https://raw.githubusercontent.com/bql-691/bq_react/v0.1.0/scripts/create.sh | bash -s -- shop +# curl -fsSL https://raw.githubusercontent.com/bql-691/bq_react/v0.1.1/scripts/create.sh | bash -s -- shop set -euo pipefail OWNER="bql-691" REPO="bq_react" -REF="${BQ_REF:-v0.1.0}" +REF="${BQ_REF:-v0.1.1}" NAME="${1:-}" if [[ ! "$NAME" =~ ^[a-z][a-z0-9-]*$ ]]; then @@ -20,26 +20,23 @@ if [[ -e "$NAME" ]]; then exit 1 fi -command -v gh >/dev/null 2>&1 || { - echo "需要 GitHub CLI。安装后执行: gh auth login" >&2 +command -v curl >/dev/null 2>&1 || { + echo "需要 curl" >&2 exit 1 } command -v node >/dev/null 2>&1 || { echo "需要 Node.js" >&2 exit 1 } -gh auth status >/dev/null 2>&1 || { - echo "请先登录 GitHub CLI: gh auth login" >&2 - exit 1 -} TMP="$(mktemp -d)" cleanup() { rm -rf "$TMP"; } trap cleanup EXIT ARCHIVE="$TMP/src.tar.gz" -if ! gh api "repos/${OWNER}/${REPO}/tarball/${REF}" >"$ARCHIVE"; then - echo "下载失败。请确认 ${OWNER}/${REPO} 上存在引用 ${REF}。" >&2 +URL="https://github.com/${OWNER}/${REPO}/archive/refs/tags/${REF}.tar.gz" +if ! curl -fsSL "$URL" -o "$ARCHIVE"; then + echo "下载失败。请确认 ${OWNER}/${REPO} 上存在标签 ${REF}。" >&2 exit 1 fi if ! tar -tzf "$ARCHIVE" >/dev/null 2>&1; then