Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
2ue committed Jul 30, 2024
1 parent 213728d commit 3365c5f
Show file tree
Hide file tree
Showing 9 changed files with 2,628 additions and 23 deletions.
14 changes: 14 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"presets": [
[
"@babel/preset-env",
{
"useBuiltIns": "entry",
"corejs": "3.6.4",
"modules": false
},
"@babel/preset-typescript"
]
],
"exclude": "node_modules/**"
}
6 changes: 6 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# ESLint 的忽略配置文件
# http://eslint.cn/docs/user-guide/configuring

build/
dist/
dev/
36 changes: 36 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
module.exports = {
"env": {
"browser": true,
"es6": true,
"node": true
},
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended"
],
"globals": {
"Atomics": "readonly",
"SharedArrayBuffer": "readonly",
"globalThis":"readonly"
},
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 11,
"sourceType": "module"
},
"plugins": [
"@typescript-eslint"
],
"rules": {
// 允许 debugger 运行在 开发 环境中
'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off',
// 关闭 var 关键字的提示
"no-var":'off',
// 警告 case 穿透
"no-fallthrough":'warn',
// 无用变量
"no-unused-vars": "off",
// typescript 的 无用变量
"@typescript-eslint/no-unused-vars": "error",
}
};
73 changes: 73 additions & 0 deletions .github/workflows/pre-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
name: Pre Publish
on:
push:
branches:
- master

jobs:
pre-publish:
# needs: test
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: true
fetch-depth: 0

- name: Set timezone to Asia/Shanghai
uses: szenius/[email protected]
with:
timezoneLinux: "Asia/Shanghai"

- name: Echo current time
run: timedatectl

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 20.11.1

- name: Install pnpm
run: |
npm install -g pnpm
# pnpm config set store-dir $(pwd)/.pnpm-store
# pnpm config set recursive-optional true
- name: Install Dependence
run: pnpm install --no-frozen-lockfile

- name: Build dist
run: |
git pull -p
pnpm run build
- name: Pre publish
run: npm publish --dry-run
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}

- uses: dorny/paths-filter@v3
id: changes
with:
filters: |
update:
- 'main/**'
- 'types/**'
- 'utils/**'
- README.md
- package.json
- rollup.config.js
- tsconfig.json
- .babelrc
- .github/workflows/publish.yml
- name: Repository Dispatch
if: steps.changes.outputs.update == 'true'
uses: peter-evans/repository-dispatch@v3
with:
token: ${{ secrets.TOKEN }}
# 也可以直接写成R: GITHUB_REPOSITORY
# https://docs.github.com/zh/actions/learn-github-actions/variables
repository: ${{ github.repository }}
event-type: to-publish-npm
107 changes: 107 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
name: Publish
on:
repository_dispatch:
types: [to-publish-npm]

jobs:
pre-publish:
# needs: test
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: true
fetch-depth: 0

- name: Set timezone to Asia/Shanghai
uses: szenius/[email protected]
with:
timezoneLinux: "Asia/Shanghai"

- name: Echo current time
run: timedatectl

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 20.11.1

- name: Set Git user and email
run: |
git config --local user.name ${{vars.NAME}}
git config --local user.email ${{vars.EMAIL}}
git config --local --list
- name: Update Version
run: |
# 更新版本号并获取新版本号
VERSION=$(npm version patch --no-git-tag-version --silent)
echo "VERSION=$VERSION"
# 将新版本号输出到环境变量
echo "NEW_VERSION=$VERSION" >> $GITHUB_ENV
SHORT_GITHUB_SHA=$(echo ${GITHUB_SHA:0:8})
echo "SHORT_GITHUB_SHA=$SHORT_GITHUB_SHA"
# 将八位hash输出到环境变量
echo "SHORT_GITHUB_SHA=$SHORT_GITHUB_SHA" >> $GITHUB_ENV
TAG_NAME="${VERSION}-${SHORT_GITHUB_SHA}"
echo "TAG_NAME=$TAG_NAME"
# 将组合的TAG_NAME输出到环境变量
echo "TAG_NAME=$TAG_NAME" >> $GITHUB_ENV
- name: Install pnpm
run: |
npm install -g pnpm
# pnpm config set store-dir $(pwd)/.pnpm-store
# pnpm config set recursive-optional true
- name: Install Dependence
run: pnpm install --no-frozen-lockfile

- name: Build dist
run: |
git pull -p
pnpm run build
- name: Add Npm Token
run: |
echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" >> ./.npmrc
ls -al
cat ./.npmrc
- name: Publish
run: npm publish
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}

- name: Package specific files
run: |
zip -r ${{ env.TAG_NAME }}.zip ./package.json ./dist ./LICENSE
ls -al
# - name: "✏️ Generate release changelog"
# uses: heinrichreimer/[email protected]
# with:
# token: ${{ secrets.TOKEN }}

- name: Create GitHub Release
uses: softprops/action-gh-release@v2
env:
GITHUB_TOKEN: ${{ secrets.TOKEN }}
with:
token: ${{ secrets.TOKEN }}
name: "Release ${{ env.NEW_VERSION }}"
tag_name: "${{ env.TAG_NAME }}"
body: "Check the changelog for details."
draft: false
prerelease: false
generate_release_notes: true
files: ${{ env.TAG_NAME }}.zip

- name: Commit and push Version
run: |
git add package.json
git commit -m "Bump version to ${{ env.TAG_NAME }}"
git tag -a "${{ env.TAG_NAME }}" -m "Release ${{ env.TAG_NAME }}"
git push origin main
25 changes: 20 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
{
"name": "cn-nm",
"version": "0.0.13",
"version": "0.0.21",
"description": "A tool is that can inner-transformation Number and Chinese",
"main": "src/cn-nm.js",
"main": "dist/cn-nm.cjs.js",
"module": "dist/cn-nm.es.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"pub": "npm publish"
"pub": "npm publish",
"dev": "rollup -c -w",
"build": "rimraf -rf ./dist && rollup --config"
},
"keywords": [
"Chinese",
"Nmuber",
"Number",
"transformation"
],
"author": {
Expand All @@ -25,5 +28,17 @@
"bugs": {
"url": "https://github.com/2ue/cn-nm/issues"
},
"license": "MIT"
"license": "MIT",
"devDependencies": {
"@babel/core": "^7.24.4",
"@babel/preset-env": "^7.24.4",
"@rollup/plugin-commonjs": "^25.0.7",
"@rollup/plugin-node-resolve": "^15.2.3",
"@rollup/plugin-typescript": "^11.1.6",
"rimraf": "^5.0.5",
"rollup": "^4.14.3",
"rollup-plugin-babel": "^4.4.0",
"rollup-plugin-terser": "^7.0.2",
"tslib": "^2.6.2"
}
}
Loading

0 comments on commit 3365c5f

Please sign in to comment.