Compare commits
2 Commits
main
..
186a4bc48c
| Author | SHA1 | Date | |
|---|---|---|---|
| 186a4bc48c | |||
| 3994bca0ab |
+7
-101
@@ -3,18 +3,15 @@ name: Node.js Build
|
|||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches: ["main", "master"]
|
branches: ["main", "master"]
|
||||||
|
pull_request:
|
||||||
|
branches: ["main", "master"]
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
if: contains(github.event.head_commit.message, 'chore') && contains(github.event.head_commit.message, '版本') && contains(github.event.head_commit.message, '更新')
|
runs-on: docker # 匹配你 runner 的标签
|
||||||
runs-on: docker
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout code
|
- name: Checkout code
|
||||||
run: |
|
uses: actions/checkout@v4
|
||||||
git init
|
|
||||||
git remote add origin http://gitea:3000/windychen/windyChenUtils.git
|
|
||||||
git fetch --depth 1 origin ${{ github.sha }}
|
|
||||||
git checkout ${{ github.sha }}
|
|
||||||
|
|
||||||
- name: Setup npm for Verdaccio
|
- name: Setup npm for Verdaccio
|
||||||
run: |
|
run: |
|
||||||
@@ -22,101 +19,10 @@ jobs:
|
|||||||
npm config set //verdaccio:4873/:_authToken ${{ secrets.NPM_TOKEN }}
|
npm config set //verdaccio:4873/:_authToken ${{ secrets.NPM_TOKEN }}
|
||||||
|
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: npm i --registry http://verdaccio:4873/
|
run: npm i --registry http://verdaccio:4873/ # 或 npm install
|
||||||
|
|
||||||
- name: Run build
|
- name: Run build
|
||||||
run: npm run build
|
run: npm run build
|
||||||
|
|
||||||
- name: Publish to Verdaccio
|
- name: Publish package
|
||||||
id: publish-verdaccio
|
run: npm publish
|
||||||
run: |
|
|
||||||
VERSION=$(node -p "require('./package.json').version")
|
|
||||||
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" http://verdaccio:4873/windychen-utils/$VERSION)
|
|
||||||
if [ "$HTTP_CODE" = "200" ]; then
|
|
||||||
echo "Verdaccio: version $VERSION already exists, skipping."
|
|
||||||
echo "verdaccio_result=skipped|版本 ${VERSION} 已存在" >> $GITHUB_OUTPUT
|
|
||||||
else
|
|
||||||
if npm publish 2>&1; then
|
|
||||||
echo "verdaccio_result=published|已发布 v${VERSION}" >> $GITHUB_OUTPUT
|
|
||||||
else
|
|
||||||
echo "verdaccio_result=failed|发布失败" >> $GITHUB_OUTPUT
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
- name: Publish to Gitea
|
|
||||||
id: publish-gitea
|
|
||||||
run: |
|
|
||||||
npm config set //gitea:3000/api/packages/windychen/npm/:_authToken ${{ secrets.NPM_GITEA_TOKEN }}
|
|
||||||
VERSION=$(node -p "require('./package.json').version")
|
|
||||||
EXISTS=$(curl -s "http://gitea:3000/api/v1/packages/windychen?q=windychen-utils" -H "Authorization: token ${{ secrets.NPM_GITEA_TOKEN }}" | grep -c "\"version\":\"$VERSION\"" || true)
|
|
||||||
if [ "$EXISTS" -gt 0 ]; then
|
|
||||||
echo "Gitea: version $VERSION already exists, skipping."
|
|
||||||
echo "gitea_result=skipped|版本 ${VERSION} 已存在" >> $GITHUB_OUTPUT
|
|
||||||
else
|
|
||||||
if npm publish --registry http://gitea:3000/api/packages/windychen/npm/ 2>&1; then
|
|
||||||
echo "gitea_result=published|已发布 v${VERSION}" >> $GITHUB_OUTPUT
|
|
||||||
else
|
|
||||||
echo "gitea_result=failed|发布失败" >> $GITHUB_OUTPUT
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
- name: Create Gitea Release
|
|
||||||
if: always() && steps.publish-gitea.outcome == 'success'
|
|
||||||
run: |
|
|
||||||
VERSION=$(node -p "require('./package.json').version")
|
|
||||||
EXISTS=$(curl -s "http://gitea:3000/api/v1/repos/windychen/windyChenUtils/releases/tags/v${VERSION}" -H "Authorization: token ${{ secrets.NPM_GITEA_TOKEN }}" | grep -c "\"tag_name\"" || true)
|
|
||||||
if [ "$EXISTS" = "0" ]; then
|
|
||||||
curl -s -X POST \
|
|
||||||
"http://gitea:3000/api/v1/repos/windychen/windyChenUtils/releases" \
|
|
||||||
-H "Authorization: token ${{ secrets.NPM_GITEA_TOKEN }}" \
|
|
||||||
-H "Content-Type: application/json" \
|
|
||||||
-d "{\"tag_name\":\"v${VERSION}\",\"name\":\"v${VERSION}\",\"body\":\"## windychen-utils v${VERSION}\n\n- 发布到 Verdaccio\n- 发布到 Gitea Packages\",\"target_commitish\":\"main\"}"
|
|
||||||
else
|
|
||||||
echo "Release v${VERSION} already exists, skipping."
|
|
||||||
fi
|
|
||||||
|
|
||||||
- name: Notify DingTalk
|
|
||||||
if: always()
|
|
||||||
run: |
|
|
||||||
STATUS="${{ job.status }}"
|
|
||||||
VERSION=$(node -p "require('./package.json').version")
|
|
||||||
|
|
||||||
parse_result() {
|
|
||||||
local raw="$1"
|
|
||||||
local target="$2"
|
|
||||||
local icon="${raw%%|*}"
|
|
||||||
local detail="${raw#*|}"
|
|
||||||
case "$icon" in
|
|
||||||
published) echo "📦 ${target}: ${detail}" ;;
|
|
||||||
skipped) echo "⏭️ ${target}: ${detail}" ;;
|
|
||||||
failed) echo "❌ ${target}: ${detail}" ;;
|
|
||||||
*) echo "⚠️ ${target}: ${detail}" ;;
|
|
||||||
esac
|
|
||||||
}
|
|
||||||
|
|
||||||
VERD_RESULT="${{ steps.publish-verdaccio.outputs.verdaccio_result }}"
|
|
||||||
GITEA_RESULT="${{ steps.publish-gitea.outputs.gitea_result }}"
|
|
||||||
|
|
||||||
if [ -n "$VERD_RESULT" ]; then
|
|
||||||
VERD_LINE=$(parse_result "$VERD_RESULT" "Verdaccio")
|
|
||||||
else
|
|
||||||
VERD_LINE="⚠️ Verdaccio: 未执行"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -n "$GITEA_RESULT" ]; then
|
|
||||||
GITEA_LINE=$(parse_result "$GITEA_RESULT" "Gitea")
|
|
||||||
else
|
|
||||||
GITEA_LINE="⚠️ Gitea: 未执行"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ "$STATUS" = "success" ]; then
|
|
||||||
TITLE="✅ windychen-utils v${VERSION} 构建完成 chen-fnos"
|
|
||||||
else
|
|
||||||
TITLE="❌ windychen-utils v${VERSION} 构建失败 chen-fnos"
|
|
||||||
fi
|
|
||||||
|
|
||||||
curl -s -X POST "https://oapi.dingtalk.com/robot/send?access_token=${{ secrets.DINGDING_TOKEN }}" \
|
|
||||||
-H "Content-Type: application/json" \
|
|
||||||
-d "{\"msgtype\":\"markdown\",\"markdown\":{\"title\":\"${TITLE}\",\"text\":\"## ${TITLE}\n\n${VERD_LINE}\n${GITEA_LINE}\n\n- 仓库: windychen/windyChenUtils\n- 分支: ${{ github.ref_name }}\n- 提交: ${{ github.sha }}\"}}"
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
## 安装
|
## 安装
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
npm install windychen-utils
|
npm install windychen-untils
|
||||||
```
|
```
|
||||||
|
|
||||||
## 使用
|
## 使用
|
||||||
@@ -13,7 +13,7 @@ npm install windychen-utils
|
|||||||
### Node.js / Bun.js
|
### Node.js / Bun.js
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
require('windychen-utils');
|
require('windychen-untils');
|
||||||
|
|
||||||
// Object 扩展
|
// Object 扩展
|
||||||
const obj = { a: { b: { c: 1 } } };
|
const obj = { a: { b: { c: 1 } } };
|
||||||
@@ -33,7 +33,7 @@ obj.setPro('x.y.z', 'hello');
|
|||||||
### ES Module
|
### ES Module
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
import from 'windychen-utils/dist/windychen-utils.esm.js';
|
import from 'windychen-untils/dist/windychen-utils.esm.js';
|
||||||
```
|
```
|
||||||
|
|
||||||
## API 参考
|
## API 参考
|
||||||
@@ -80,7 +80,7 @@ arr.findPro(item => item.id > 1);
|
|||||||
- 仅支持 localStorage → 使用 `ILocalStorage`(内存缓存)
|
- 仅支持 localStorage → 使用 `ILocalStorage`(内存缓存)
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
import storage from 'windychen-utils';
|
import storage from 'windychen-untils';
|
||||||
|
|
||||||
await storage.set('key', { data: 123 });
|
await storage.set('key', { data: 123 });
|
||||||
await storage.get('key', null); // { data: 123 }
|
await storage.get('key', null); // { data: 123 }
|
||||||
|
|||||||
+23
-27
@@ -1,29 +1,25 @@
|
|||||||
{
|
{
|
||||||
"name": "windychen-utils",
|
"name": "windychen-untils",
|
||||||
"version": "1.1.12",
|
"version": "1.1.1",
|
||||||
"main": "dist/windychen-utils.cjs.js",
|
"main": "dist/windychen-utils.cjs.js",
|
||||||
"module": "dist/windychen-utils.esm.js",
|
"module": "dist/windychen-utils.esm.js",
|
||||||
"browser": "dist/windychen-utils.js",
|
"browser": "dist/windychen-utils.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "webpack --mode production",
|
"build": "webpack --mode production",
|
||||||
"build:cjs": "webpack --mode production --env format=cjs",
|
"build:cjs": "webpack --mode production --env format=cjs",
|
||||||
"build:esm": "webpack --mode production --env format=esm",
|
"build:esm": "webpack --mode production --env format=esm",
|
||||||
"build:umd": "webpack --mode production --env format=umd",
|
"build:umd": "webpack --mode production --env format=umd",
|
||||||
"dev": "webpack --mode development",
|
"dev": "webpack --mode development",
|
||||||
"test": "node test.js"
|
"test": "node test.js"
|
||||||
},
|
},
|
||||||
"author": "windychen",
|
"author": "windychen",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"description": "",
|
"description": "",
|
||||||
"repository": {
|
"devDependencies": {
|
||||||
"type": "git",
|
"webpack": "^5.90.0",
|
||||||
"url": "http://gitea.windychen00n.work/windychen/windyChenUtils.git"
|
"webpack-cli": "^5.1.4"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"dependencies": {
|
||||||
"webpack": "^5.90.0",
|
"better-sqlite3": "^12.10.0"
|
||||||
"webpack-cli": "^5.1.4"
|
}
|
||||||
},
|
|
||||||
"dependencies": {
|
|
||||||
"better-sqlite3": "^12.10.0"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-3
@@ -241,9 +241,9 @@ class MemoryStorage {
|
|||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
var _SqliteStorageClass = function () {
|
var _SqliteStorageClass = function () {
|
||||||
var Database = require(/* webpackIgnore: true */ "better-sqlite3");
|
var Database = require("better-sqlite3");
|
||||||
var pathModule = require(/* webpackIgnore: true */ "path");
|
var pathModule = require("path");
|
||||||
var fs = require(/* webpackIgnore: true */ "fs");
|
var fs = require("fs");
|
||||||
|
|
||||||
return class SqliteStorage {
|
return class SqliteStorage {
|
||||||
/**
|
/**
|
||||||
|
|||||||
+13
-29
@@ -1,41 +1,26 @@
|
|||||||
const path = require("path");
|
const path = require('path');
|
||||||
|
|
||||||
const nodeExternalModules = ["better-sqlite3"];
|
|
||||||
|
|
||||||
const commonConfig = {
|
|
||||||
externals: {
|
|
||||||
"better-sqlite3": "commonjs2 better-sqlite3",
|
|
||||||
},
|
|
||||||
resolve: {
|
|
||||||
fallback: {
|
|
||||||
fs: false,
|
|
||||||
path: false,
|
|
||||||
util: false,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
const configs = {
|
const configs = {
|
||||||
cjs: {
|
cjs: {
|
||||||
output: {
|
output: {
|
||||||
path: path.resolve(__dirname, "dist"),
|
path: path.resolve(__dirname, 'dist'),
|
||||||
filename: "windychen-utils.cjs.js",
|
filename: 'windychen-utils.cjs.js',
|
||||||
libraryTarget: "commonjs2",
|
libraryTarget: 'commonjs2',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
esm: {
|
esm: {
|
||||||
experiments: { outputModule: true },
|
experiments: { outputModule: true },
|
||||||
output: {
|
output: {
|
||||||
path: path.resolve(__dirname, "dist"),
|
path: path.resolve(__dirname, 'dist'),
|
||||||
filename: "windychen-utils.esm.js",
|
filename: 'windychen-utils.esm.js',
|
||||||
libraryTarget: "module",
|
libraryTarget: 'module',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
umd: {
|
umd: {
|
||||||
output: {
|
output: {
|
||||||
path: path.resolve(__dirname, "dist"),
|
path: path.resolve(__dirname, 'dist'),
|
||||||
filename: "windychen-utils.js",
|
filename: 'windychen-utils.js',
|
||||||
library: { name: "WindychenUtils", type: "umd", export: "default" },
|
library: { name: 'WindychenUtils', type: 'umd', export: 'default' },
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@@ -43,11 +28,10 @@ const configs = {
|
|||||||
module.exports = (env = {}) => {
|
module.exports = (env = {}) => {
|
||||||
const format = env.format;
|
const format = env.format;
|
||||||
|
|
||||||
if (!format || format === "all") {
|
if (!format || format === 'all') {
|
||||||
return Object.keys(configs).map((key) => ({
|
return Object.keys(configs).map((key) => ({
|
||||||
name: key,
|
name: key,
|
||||||
entry: "./index.js",
|
entry: './index.js',
|
||||||
...commonConfig,
|
|
||||||
...configs[key],
|
...configs[key],
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
@@ -56,5 +40,5 @@ module.exports = (env = {}) => {
|
|||||||
throw new Error(`不支持的格式: ${format},可选值: cjs, esm, umd`);
|
throw new Error(`不支持的格式: ${format},可选值: cjs, esm, umd`);
|
||||||
}
|
}
|
||||||
|
|
||||||
return { entry: "./index.js", ...commonConfig, ...configs[format] };
|
return { entry: './index.js', ...configs[format] };
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user