Skip to content

Commit

Permalink
🐎 ci: 增加文件夹同名校验
Browse files Browse the repository at this point in the history
  • Loading branch information
白云苍狗 committed Oct 30, 2023
1 parent 7faf3a5 commit 5da5618
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 5 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/publish-cli.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: NPM Publish

on:
push:
tags:
- "cli-v*"
jobs:
build:
permissions:
contents: write
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v3
with:
node-version: 16
registry-url: "https://registry.npmjs.org"
cache: yarn
- run: yarn install --frozen-lockfile

- name: Build
run: |
node ./scripts/publish.mjs
cd ./packages/async-cli
npm run build
npm publish
env:
RELEASE_VERSION: ${{ github.ref }}
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
File renamed without changes.
3 changes: 2 additions & 1 deletion packages/async-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"license": "MIT",
"keywords": [
"vitepress-theme",
"blog-theme"
"blog-theme",
"async-cli"
],
"bin": {
"async-cli": "./dist/index.js"
Expand Down
6 changes: 5 additions & 1 deletion packages/async-cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,15 @@ console.log();

function createThemeProject(destination: string) {
const templatePath = path.join(__dirname, 'template');
if (fs.existsSync(destination)) {
console.log(`❌ The ${projectName} folder already exists.!`);
console.log();
return;
}

fs.copy(templatePath, destination, async err => {
// 同步创建.gitignore文件和配置文件
await fs.copy(path.join(__dirname, 'move/gitignore'), path.join(destination, '.gitignore'));

await fs.copy(path.join(__dirname, 'move/package'), path.join(destination, 'package.json'));

const sourceRc = isBun ? 'bunfig.toml' : 'npmrc';
Expand Down
10 changes: 7 additions & 3 deletions scripts/publish.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import { writeFileSync } from "fs";
import { resolve } from "path";
import { fileURLToPath } from "url";
import pkg from "../packages/vitepress-theme-async/package.json" assert { type: "json" };
import themepkg from "../packages/vitepress-theme-async/package.json" assert { type: "json" };
import clipkg from "../packages/async-cli/package.json" assert { type: "json" };


if (process.env.RELEASE_VERSION) {
const version = process.env.RELEASE_VERSION.split("/").reverse()[0];
console.log("当前版本:", version);
pkg.version = version.replace("v", "");
writeFileSync(resolve(fileURLToPath(import.meta.url), "../../packages/vitepress-theme-async/package.json"), JSON.stringify(pkg, null, 4), "utf-8");
themepkg.version = version.replace("v", "");
clipkg.version = version.replace("cli-v", "");
writeFileSync(resolve(fileURLToPath(import.meta.url), "../../packages/vitepress-theme-async/package.json"), JSON.stringify(themepkg, null, 4), "utf-8");
writeFileSync(resolve(fileURLToPath(import.meta.url), "../../packages/async-cli/package.json"), JSON.stringify(clipkg, null, 4), "utf-8");
}

0 comments on commit 5da5618

Please sign in to comment.