Skip to content

Commit

Permalink
fix(create): fix branch name, close#4019
Browse files Browse the repository at this point in the history
  • Loading branch information
Mister-Hope committed Apr 5, 2024
1 parent 98c9874 commit 1ce69c8
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 39 deletions.
36 changes: 36 additions & 0 deletions packages/create/src/config/i18n.ts
Expand Up @@ -38,6 +38,18 @@ export interface CreateLocale {
devServer: (packageManager: PackageManager) => string;
};

workflow: {
name: string;
checkout: string;
submodule: string;
setupPnpm: string;
setupNode: string;
install: string;
build: string;
deploy: string;
deployBranch: string;
};

error: {
name: string;
version: string;
Expand Down Expand Up @@ -85,6 +97,18 @@ export const i18n: Record<Lang, CreateLocale> = {
`提示: 请使用 "${packageManager} run docs:dev" 命令启动开发服务器`,
},

workflow: {
name: "部署文档",
checkout: "检出代码",
submodule: "如果你文档需要 Git 子模块,取消注释下一行",
setupPnpm: "设置 pnpm",
setupNode: "设置 Node.js",
install: "安装依赖",
build: "构建文档",
deploy: "部署文档",
deployBranch: "这是文档部署到的分支名称",
},

error: {
name: "应用名称应只包含小写字母、数字和连接线 (-)",
version: "此版本无效,版本号应为 'x.x.x'",
Expand Down Expand Up @@ -134,6 +158,18 @@ export const i18n: Record<Lang, CreateLocale> = {
`Hint: You should execute "${packageManager} run docs:dev" to start dev server.`,
},

workflow: {
name: "Deploy Docs",
checkout: "Checkout code",
submodule: "if your docs needs submodules, uncomment the following line",
setupPnpm: "Setup pnpm",
setupNode: "Setup Node.js",
install: "Install Deps",
build: "Build Docs",
deploy: "Deploy Docs",
deployBranch: "This is the branch where the docs are deployed to",
},

error: {
name: "package name should only contain lowercase characters, numbers and dash",
version:
Expand Down
5 changes: 2 additions & 3 deletions packages/create/src/config/template.ts
Expand Up @@ -35,7 +35,6 @@ interface TemplateOptions {
export const generateTemplate = async ({
cwd = process.cwd(),
targetDir,
lang,
locale,
preset,
packageManager,
Expand Down Expand Up @@ -122,7 +121,7 @@ export const generateTemplate = async ({

writeFileSync(
resolve(workflowDir, "deploy-docs.yml"),
getWorkflowContent(packageManager, targetDir, lang),
getWorkflowContent(packageManager, cwd, targetDir, locale),
{ encoding: "utf-8" },
);
}
Expand All @@ -145,7 +144,7 @@ export const generateTemplate = async ({
]);

if (git) {
execaCommandSync("git init", { cwd });
execaCommandSync("git init -b main", { cwd });
updateGitIgnore(targetDir, cwd);
}
}
Expand Down
58 changes: 22 additions & 36 deletions packages/create/src/config/workflow.ts
@@ -1,25 +1,23 @@
import { join } from "node:path";

import type { Lang } from "./i18n.js";
import { execaCommandSync } from "execa";

import type { CreateLocale } from "./i18n.js";
import type { PackageManager } from "../utils/index.js";

export const getWorkflowContent = (
packageManager: PackageManager,
cwd: string,
dir: string,
lang: Lang,
{ workflow }: CreateLocale,
): string =>
`
name: ${lang === "简体中文" ? "部署文档" : "Deploy Docs"}
name: ${workflow.name}
on:
push:
branches:
# ${
lang === "简体中文"
? "确保这是你正在使用的分支名称"
: "make sure this is the branch you are using"
}
- main
- ${execaCommandSync("git branch --show-current", { cwd }).stdout.trim()}
permissions:
contents: write
Expand All @@ -32,58 +30,46 @@ jobs:
uses: actions/checkout@v3
with:
fetch-depth: 0
# ${
lang === "简体中文"
? "如果你文档需要 Git 子模块,取消注释下一行"
: "if your docs needs submodules, uncomment the following line"
}
# ${workflow.submodule}
# submodules: true
${
packageManager === "pnpm"
? `\
- name: ${lang === "简体中文" ? "安装 pnpm" : "Install pnpm"}
- name: ${workflow.setupPnpm}
uses: pnpm/action-setup@v2
with:
run_install: true
version: 8
`
: ""
}
- name: ${lang === "简体中文" ? "设置 Node.js" : "Setup Node.js"}
- name: ${workflow.setupNode}
uses: actions/setup-node@v3
with:
node-version: 20
cache: ${packageManager}
${
packageManager === "pnpm"
? ""
: `\
- name: ${lang === "简体中文" ? "安装依赖" : "Install Deps"}
run: ${
packageManager === "npm"
? "npm ci"
: `${packageManager} install --frozen-lockfile`
}
`
}
- name: ${lang === "简体中文" ? "构建文档" : "Build Docs"}
- name: ${workflow.install}
run: |
corepack enable
${
packageManager === "npm"
? "npm ci"
: `${packageManager} install --frozen-lockfile`
}
- name: ${workflow.build}
env:
NODE_OPTIONS: --max_old_space_size=8192
run: |-
${packageManager} run docs:build
> ${join(dir, ".vuepress/dist/.nojekyll").replace(/\\/g, "/")}
- name: ${lang === "简体中文" ? "部署文档" : "Deploy Docs"}
- name: ${workflow.deploy}
uses: JamesIves/github-pages-deploy-action@v4
with:
# ${
lang === "简体中文"
? "这是文档部署到的分支名称"
: "This is the branch where the docs are deployed to"
}
# ${workflow.deploy}
branch: gh-pages
folder: ${join(dir, ".vuepress/dist").replace(/\\/g, "/")}
`;

0 comments on commit 1ce69c8

Please sign in to comment.