diff --git a/.github/workflows/npm-release.yml b/.github/workflows/npm-release.yml new file mode 100644 index 0000000..bc9c6cc --- /dev/null +++ b/.github/workflows/npm-release.yml @@ -0,0 +1,24 @@ + +name: Public Npm + +on: + push: + tags: + - 'cli-v*' + +jobs: + build: + runs-on: ubuntu-latest + 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: cd md-cli && npm ci && npm publish + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }} + diff --git a/bin/release.js b/bin/release.js new file mode 100644 index 0000000..29f485e --- /dev/null +++ b/bin/release.js @@ -0,0 +1,44 @@ +(async function () { + const fs = require('fs'); + const path = require('path'); + const packageJson = require('../md-cli/package.json'); + const child_process = require('child_process'); + // 自动更新版本 + // 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, '../md-cli/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/md-cli/.npmignore b/md-cli/.npmignore new file mode 100644 index 0000000..f185b90 --- /dev/null +++ b/md-cli/.npmignore @@ -0,0 +1,2 @@ +.tgz +httpData/ diff --git a/md-cli/.npmrc b/md-cli/.npmrc new file mode 100644 index 0000000..38f11c6 --- /dev/null +++ b/md-cli/.npmrc @@ -0,0 +1 @@ +registry=https://registry.npmjs.org diff --git a/md-cli/package-lock.json b/md-cli/package-lock.json index 823f641..61d0a3e 100644 --- a/md-cli/package-lock.json +++ b/md-cli/package-lock.json @@ -10,10 +10,10 @@ "license": "ISC", "dependencies": { "@wll8/process-manager": "^1.0.1", - "form-data": "2.3.3", + "form-data": "4.0.0", "get-port": "5.1.1", "mockm": "^1.1.27-alpha.2", - "node-fetch": "^3.1.0" + "node-fetch": "^3.2.10" }, "bin": { "md-cli": "index.js" @@ -1964,16 +1964,16 @@ } }, "node_modules/form-data": { - "version": "2.3.3", - "resolved": "https://registry.npmmirror.com/form-data/-/form-data-2.3.3.tgz", - "integrity": "sha512-1lLKB2Mu3aGP1Q/2eCOx0fNbRMe7XdwktwOruhfqqd0rIJWwN4Dh+E3hrPSlDCXnSR7UtZ1N38rVXm+6+MEhJQ==", + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", + "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==", "dependencies": { "asynckit": "^0.4.0", - "combined-stream": "^1.0.6", + "combined-stream": "^1.0.8", "mime-types": "^2.1.12" }, "engines": { - "node": ">= 0.12" + "node": ">= 6" } }, "node_modules/formdata-polyfill": { @@ -3238,9 +3238,9 @@ } }, "node_modules/node-fetch": { - "version": "3.2.0", - "resolved": "https://registry.npmmirror.com/node-fetch/-/node-fetch-3.2.0.tgz", - "integrity": "sha512-8xeimMwMItMw8hRrOl3C9/xzU49HV/yE6ORew/l+dxWimO5A4Ra8ld2rerlJvc/O7et5Z1zrWsPX43v1QBjCxw==", + "version": "3.3.2", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-3.3.2.tgz", + "integrity": "sha512-dRB78srN/l6gqWulah9SrxeYnxeddIG30+GOqK/9OlLVyLg3HPnr6SqOWTWOXKRwC2eGYCkZ59NNuSgvSrpgOA==", "dependencies": { "data-uri-to-buffer": "^4.0.0", "fetch-blob": "^3.1.4", @@ -3248,6 +3248,10 @@ }, "engines": { "node": "^12.20.0 || ^14.13.1 || >=16.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/node-fetch" } }, "node_modules/node-http-proxy-json": { @@ -3753,6 +3757,20 @@ "node": ">= 6" } }, + "node_modules/request/node_modules/form-data": { + "version": "2.3.3", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-2.3.3.tgz", + "integrity": "sha512-1lLKB2Mu3aGP1Q/2eCOx0fNbRMe7XdwktwOruhfqqd0rIJWwN4Dh+E3hrPSlDCXnSR7UtZ1N38rVXm+6+MEhJQ==", + "optional": true, + "dependencies": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.6", + "mime-types": "^2.1.12" + }, + "engines": { + "node": ">= 0.12" + } + }, "node_modules/request/node_modules/qs": { "version": "6.5.3", "resolved": "https://registry.npmjs.org/qs/-/qs-6.5.3.tgz", @@ -6405,12 +6423,12 @@ "optional": true }, "form-data": { - "version": "2.3.3", - "resolved": "https://registry.npmmirror.com/form-data/-/form-data-2.3.3.tgz", - "integrity": "sha512-1lLKB2Mu3aGP1Q/2eCOx0fNbRMe7XdwktwOruhfqqd0rIJWwN4Dh+E3hrPSlDCXnSR7UtZ1N38rVXm+6+MEhJQ==", + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", + "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==", "requires": { "asynckit": "^0.4.0", - "combined-stream": "^1.0.6", + "combined-stream": "^1.0.8", "mime-types": "^2.1.12" } }, @@ -7340,9 +7358,9 @@ "integrity": "sha512-/jKZoMpw0F8GRwl4/eLROPA3cfcXtLApP0QzLmUT/HuPCZWyB7IY9ZrMeKw2O/nFIqPQB3PVM9aYm0F312AXDQ==" }, "node-fetch": { - "version": "3.2.0", - "resolved": "https://registry.npmmirror.com/node-fetch/-/node-fetch-3.2.0.tgz", - "integrity": "sha512-8xeimMwMItMw8hRrOl3C9/xzU49HV/yE6ORew/l+dxWimO5A4Ra8ld2rerlJvc/O7et5Z1zrWsPX43v1QBjCxw==", + "version": "3.3.2", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-3.3.2.tgz", + "integrity": "sha512-dRB78srN/l6gqWulah9SrxeYnxeddIG30+GOqK/9OlLVyLg3HPnr6SqOWTWOXKRwC2eGYCkZ59NNuSgvSrpgOA==", "requires": { "data-uri-to-buffer": "^4.0.0", "fetch-blob": "^3.1.4", @@ -7726,6 +7744,17 @@ "uuid": "^3.3.2" }, "dependencies": { + "form-data": { + "version": "2.3.3", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-2.3.3.tgz", + "integrity": "sha512-1lLKB2Mu3aGP1Q/2eCOx0fNbRMe7XdwktwOruhfqqd0rIJWwN4Dh+E3hrPSlDCXnSR7UtZ1N38rVXm+6+MEhJQ==", + "optional": true, + "requires": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.6", + "mime-types": "^2.1.12" + } + }, "qs": { "version": "6.5.3", "resolved": "https://registry.npmjs.org/qs/-/qs-6.5.3.tgz", diff --git a/md-cli/package.json b/md-cli/package.json index bbd24d6..4fdab7b 100644 --- a/md-cli/package.json +++ b/md-cli/package.json @@ -21,9 +21,9 @@ "license": "ISC", "dependencies": { "@wll8/process-manager": "^1.0.1", - "form-data": "2.3.3", + "form-data": "4.0.0", "get-port": "5.1.1", "mockm": "^1.1.27-alpha.2", - "node-fetch": "^3.1.0" + "node-fetch": "^3.2.10" } } diff --git a/package.json b/package.json index 2153b8e..1296632 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,9 @@ { "name": "md", - "version": "1.5.9", + "version": "1.6.0", "private": false, "scripts": { + "release": "node ./bin/release.js", "prepare": "husky install", "lint": "vue-cli-service lint src", "start": "npm run lint -- --fix && run-p serve", @@ -16,6 +17,7 @@ "axios": "^1.6.0", "buffer-from": "^1.1.2", "codemirror": "^5.65.7", + "core-js": "^3.34.0", "cos-js-sdk-v5": "^1.3.9", "crypto-js": "^4.2.0", "element-ui": "^2.15.9",