diff --git a/.github/workflows/contributors.yml b/.github/workflows/contributors.yml index 209c6f7..0d7b46e 100644 --- a/.github/workflows/contributors.yml +++ b/.github/workflows/contributors.yml @@ -2,12 +2,13 @@ name: gen-org-contributors on: schedule: - - cron: "0 0 * * *" + - cron: '0 0 * * *' workflow_dispatch: jobs: generate: runs-on: ubuntu-latest + if: github.repository == 'EternalHeartTeam/leetcode-practice' steps: - uses: thinkasany/organize-contributors@master with: @@ -16,5 +17,5 @@ jobs: png_path: images/contributors.png json_path: contributors.json branch: svg - commit_message: "chore: update contributors" - excludes_list: "ImgBotApp,github-actions[bot],actions-user,imgbot[bot],dependabot[bot]" \ No newline at end of file + commit_message: 'chore: update contributors' + excludes_list: 'ImgBotApp,github-actions[bot],actions-user,imgbot[bot],dependabot[bot]' diff --git a/.github/workflows/pr-add-label.yml b/.github/workflows/pr-add-label.yml index 5eb10eb..e3e8cae 100644 --- a/.github/workflows/pr-add-label.yml +++ b/.github/workflows/pr-add-label.yml @@ -20,5 +20,5 @@ jobs: with: github_token: ${{ secrets.ACTION_TOKEN }} pr_number: ${{ env.PR_NUMBER }} - organize_name: "EternalHeartTeam" - team_name: "eternalheartteam" + organize_name: EternalHeartTeam + team_name: eternalheartteam diff --git a/.github/workflows/release-cli.yml b/.github/workflows/release-cli.yml new file mode 100644 index 0000000..87c2c7a --- /dev/null +++ b/.github/workflows/release-cli.yml @@ -0,0 +1,23 @@ +name: Create Cli Release + +on: + push: + tags: + - 'cli-v*' + +jobs: + build: + runs-on: ubuntu-latest + if: github.repository == 'EternalHeartTeam/leetcode-practice' + steps: + - uses: actions/checkout@v3 + # Setup .npmrc file to publish to npm + - uses: actions/setup-node@v3 + with: + node-version: '20' + registry-url: 'https://registry.npmjs.org' + - run: npm install + - run: npm run build-cli + - run: npm ci && npm publish + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }} diff --git a/.npmignore b/.npmignore new file mode 100644 index 0000000..f185b90 --- /dev/null +++ b/.npmignore @@ -0,0 +1,2 @@ +.tgz +httpData/ diff --git a/.npmrc b/.npmrc new file mode 100644 index 0000000..38f11c6 --- /dev/null +++ b/.npmrc @@ -0,0 +1 @@ +registry=https://registry.npmjs.org diff --git a/README.md b/README.md index 1a1a1df..d1ed329 100644 --- a/README.md +++ b/README.md @@ -499,4 +499,4 @@ If you encounter any `issues` or have some `great suggestions`, feel free to joi ## Star History -[![Star History Chart](https://api.star-history.com/svg?repos=EternalHeartTeam/leetcode-practice&type=Date)](https://star-history.com/#EternalHeartTeam/leetcode-practice&Date) \ No newline at end of file +[![Star History Chart](https://api.star-history.com/svg?repos=EternalHeartTeam/leetcode-practice&type=Date)](https://star-history.com/#EternalHeartTeam/leetcode-practice&Date) diff --git a/bin/release.js b/bin/release.js new file mode 100644 index 0000000..0f81b06 --- /dev/null +++ b/bin/release.js @@ -0,0 +1,52 @@ +import fs from 'node:fs' +import { fileURLToPath } from 'node:url' +import path, { dirname } from 'node:path' +import * as child_process from 'node:child_process' +import packageJson from '../package.json' assert { type: 'json' } + +const __filename = fileURLToPath(import.meta.url) +const __dirname = dirname(__filename) +;(async function () { + // 自动更新版本 + // version可以传递如 6.1.1 | patch | minor | major + const execCommand = (arr) => + (Array.isArray(arr) ? arr : [arr]).forEach((c) => { + try { + console.log(`start: ${c}...`) + console.log(child_process.execSync(c).toString('utf8')) + } catch (error) { + console.log('\x1B[31m%s\x1B[0m', error.stdout.toString()) + process.exit(1) + } + }) + const getNewVersion = (oldVersion, version = 'patch') => { + // [ | major | minor | patch] + if (/^([0-9]+\.*)+$/.test(version)) return version + const types = ['major', 'minor', 'patch'] + const index = types.indexOf(version) + if (index >= 0) { + const versionArr = oldVersion.split('.') + versionArr[index] = Number(versionArr[index]) + 1 + return versionArr.map((e, i) => (i > index ? 0 : e)).join('.') + } + return getNewVersion(oldVersion) + } + const newVersionObj = { + version: getNewVersion(packageJson.version, process.argv[2]) + } + fs.writeFileSync( + path.resolve(__dirname, '../package.json'), + `${JSON.stringify( + Object.assign({}, packageJson, newVersionObj), + null, + 2 + )}\n` + ) + console.log(newVersionObj) + execCommand([ + `git commit -a -m 'chore: update version cli-v${newVersionObj.version}'`, + `git tag cli-v${newVersionObj.version}`, + 'git push && git push --tags' + ]) + console.log('\x1B[32m%s\x1B[0m', '发布完成,请关注github CI构建') +})() diff --git a/common/utils/file/getRootPath.js b/common/utils/file/getRootPath.js index 5f7b831..0971a80 100644 --- a/common/utils/file/getRootPath.js +++ b/common/utils/file/getRootPath.js @@ -1,6 +1,7 @@ import path from 'node:path' import { __dirname } from '#common/utils/file/getDirname.js' import { currentEnv } from '#common/utils/etc/checkEnv.js' + // 在cli环境下 执行目录为 bin 目录 根目录就是上一层目录 export const rootPath = currentEnv() === 'project' diff --git a/package.json b/package.json index 0d60a9d..17eee0f 100644 --- a/package.json +++ b/package.json @@ -29,6 +29,7 @@ "lc": "node bin/lc.js -d src", "lk": "node bin/lk.js -d src", "lf": "node bin/lf.js -d src", + "release:cli": "node ./bin/release.js", "update": "node scripts/update.js", "build-cli": "node esbuild.config.js", "publish-cli": "cd pl-cli && npm publish --registry https://registry.npmjs.org/",