diff --git a/.eslintignore b/.eslintignore index 21a7faf1..38702545 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,5 +1,6 @@ /dist/ /lib/ +/es/ /node_modules/ /public/ /config/ diff --git a/.gitignore b/.gitignore index 7a35f749..18d1917d 100644 --- a/.gitignore +++ b/.gitignore @@ -100,7 +100,8 @@ dist # TernJS port file .tern-port -lib +lib/ +es/ temp *.bak diff --git a/.husky/commit-msg b/.husky/commit-msg new file mode 100755 index 00000000..fa530c80 --- /dev/null +++ b/.husky/commit-msg @@ -0,0 +1,4 @@ +#!/bin/sh +. "$(dirname "$0")/_/husky.sh" + +npx --no -- commitlint@18 --edit diff --git a/commitlint.config.js b/commitlint.config.js new file mode 100644 index 00000000..422b1944 --- /dev/null +++ b/commitlint.config.js @@ -0,0 +1 @@ +module.exports = { extends: ['@commitlint/config-conventional'] }; diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index d4bc00ce..22822f7b 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -1,5 +1,68 @@ # 更新日志 +### [1.3.101](https://github.com/novlan1/t-comm/compare/v1.3.100...v1.3.101) (2024-09-07) + + +### Chore 🚀 + +* add es module ([f03724d](https://github.com/novlan1/t-comm/commit/f03724d68e12afb8855e369389a09eb5a454afcc)) + +### [1.3.100](https://github.com/novlan1/t-comm/compare/v1.3.99...v1.3.100) (2024-08-28) + + +### Features 🎉 + +* **mp-ci:** update mp-cli modify ([d939c1b](https://github.com/novlan1/t-comm/commit/d939c1be2cb8b0f663666adf4cf16dd6798b258a)) + +### [1.3.99](https://github.com/novlan1/t-comm/compare/v1.3.98...v1.3.99) (2024-08-26) + + +### Features 🎉 + +* **mp-ci:** 优化修改配置 ([03149d3](https://github.com/novlan1/t-comm/commit/03149d35c126739e58828b806bd9bb3eddf53659)) + +### [1.3.98](https://github.com/novlan1/t-comm/compare/v1.3.97...v1.3.98) (2024-08-26) + + +### Features 🎉 + +* **base64:** encode, decode 支持非拉丁字符 ([e9ec697](https://github.com/novlan1/t-comm/commit/e9ec697faef416c024d6ab8ed2e8b4a961e6f655)) +* **mp-ci:** 优化修改配置 ([82f74da](https://github.com/novlan1/t-comm/commit/82f74da9e7bbecdc763da99f69bb4238d9477145)) +* **mp-ci:** 优化修改mp-ci配置 ([1fbabac](https://github.com/novlan1/t-comm/commit/1fbabac83b8cc45d961ecf879863317085d77b27)) + +### [1.3.97](https://github.com/novlan1/t-comm/compare/v1.3.96...v1.3.97) (2024-08-15) + + +### Bug Fixes 🐞 + +* **bump-version:** 修复bump-version ([ebb3cb4](https://github.com/novlan1/t-comm/commit/ebb3cb4fe802a2b2832ecf25527ff49d1bafaba0)) + +### [1.3.96](https://github.com/novlan1/t-comm/compare/v1.3.95...v1.3.96) (2024-08-15) + + +### Chore 🚀 + +* add commit-msg husky ([5a082a3](https://github.com/novlan1/t-comm/commit/5a082a386d10211fa5397b1e0c8c72114e0bf1dc)) + + +### Features 🎉 + +* add base64 encode & decode ([7b0aa6a](https://github.com/novlan1/t-comm/commit/7b0aa6ab0c679fa75f34b1545432549a1ef179d8)) +* **bump-version:** add bump-version ([762a219](https://github.com/novlan1/t-comm/commit/762a2190745c0ec26636d2bc4241e5c9f496127a)) + +### [1.3.95](https://github.com/novlan1/t-comm/compare/v1.3.94...v1.3.95) (2024-08-07) + + +### Tests ✅ + +* update test case ([a8761c6](https://github.com/novlan1/t-comm/commit/a8761c6cb9f86399aebc1253c83792c2f849cca3)) + + +### Features 🎉 + +* **devops-ci:** support useDevopsWXCIPlugin ([2b72ba3](https://github.com/novlan1/t-comm/commit/2b72ba343184e7401321e8ea19cf0bd7b9bad4fb)) +* **list:** add split long list ([406c543](https://github.com/novlan1/t-comm/commit/406c54374abd3e0b7cc283eacdf932eb4386113d)) + ### [1.3.94](https://github.com/novlan1/t-comm/compare/v1.3.93...v1.3.94) (2024-07-29) diff --git a/package.json b/package.json index 7e8d3cb1..b85a23be 100644 --- a/package.json +++ b/package.json @@ -1,12 +1,13 @@ { "name": "t-comm", - "version": "1.3.94", + "version": "1.3.101", "description": "丰富易用的工具库", "main": "lib/index.js", "module": "lib/index.esm.js", "typings": "lib/index.d.ts", "files": [ "lib", + "es", "bin", "barcode", "LICENSE", @@ -123,6 +124,7 @@ }, "dependencies": { "@babel/runtime": "^7.17.2", + "@commitlint/config-conventional": "^17.1.0", "axios": "*", "cheerio": "^1.0.0-rc.12", "commander": "^10.0.1", diff --git a/rollup.config.js b/rollup.config.js index e63b3d31..6a4a0813 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -13,6 +13,7 @@ const pkg = require('./package.json'); const PATHS = { input: path.join(__dirname, '/src/index.ts'), output: path.join(__dirname, '/lib'), + outputES: path.join(__dirname, '/es'), }; @@ -86,6 +87,21 @@ const allRollupConfig = [ ...ROLLUP_PLUGINS, ], }, + { + input: getAllSourceInput(), + output: [{ + format: 'es', + exports: 'named', + dir: PATHS.outputES, + }], + external: ROLLUP_EXTERNALS, + plugins: [ + typescript({ + tsconfig: './tsconfig-es.json', + }), + ...ROLLUP_PLUGINS, + ], + }, { input: PATHS.input, output: [{ diff --git a/src/base/list/index.ts b/src/base/list/index.ts index 09da57ee..458eba61 100644 --- a/src/base/list/index.ts +++ b/src/base/list/index.ts @@ -8,3 +8,4 @@ export { flattenPreData, compareTwoList, } from './parse-list'; +export { splitLongList } from './split'; diff --git a/src/base/list/split.ts b/src/base/list/split.ts new file mode 100644 index 00000000..421fa34b --- /dev/null +++ b/src/base/list/split.ts @@ -0,0 +1,29 @@ +export function getStrListLength(list: Array) { + return list.reduce((acc, item) => acc + item.length, 0); +} + +export function splitLongList(list: Array, threshold = 3800, max = 3) { + const strLen = getStrListLength(list); + if (strLen <= threshold) { + return [list]; + } + const result = []; + let temp = []; + for (let i = 0; i < list.length;i++) { + const item = list[i]; + temp.push(item); + + const tempLen = getStrListLength(temp); + if (tempLen >= threshold) { + result.push(temp); + temp = []; + + if (result.length >= max - 1) { + temp = list.slice(i + 1); + break; + } + } + } + result.push(temp); + return result; +} diff --git a/src/base64/config.ts b/src/base64/config.ts new file mode 100644 index 00000000..67419b12 --- /dev/null +++ b/src/base64/config.ts @@ -0,0 +1,3 @@ +export const B64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; +export const B64RE = /^(?:[A-Za-z\d+/]{4})*?(?:[A-Za-z\d+/]{2}(?:==)?|[A-Za-z\d+/]{3}=?)?$/; +export const _fromCC = String.fromCharCode.bind(String); diff --git a/src/base64/decode.ts b/src/base64/decode.ts new file mode 100644 index 00000000..f310fd0d --- /dev/null +++ b/src/base64/decode.ts @@ -0,0 +1,59 @@ +/* eslint-disable */ +import { B64, B64RE, _fromCC } from './config'; + +const re_btou = /[\xC0-\xDF][\x80-\xBF]|[\xE0-\xEF][\x80-\xBF]{2}|[\xF0-\xF7][\x80-\xBF]{3}/g; + + +const _tidyB64 = function (s: string) { + return s.replace(/[^A-Za-z0-9\+\/]/g, ''); +}; + +const cb_btou = function (cccc: string) { + switch (cccc.length) { + case 4: + var cp = ((0x07 & cccc.charCodeAt(0)) << 18) + | ((0x3f & cccc.charCodeAt(1)) << 12) + | ((0x3f & cccc.charCodeAt(2)) << 6) + | (0x3f & cccc.charCodeAt(3)); var offset = cp - 0x10000; + return (_fromCC((offset >>> 10) + 0xD800) + + _fromCC((offset & 0x3FF) + 0xDC00)); + case 3: + return _fromCC(((0x0f & cccc.charCodeAt(0)) << 12) + | ((0x3f & cccc.charCodeAt(1)) << 6) + | (0x3f & cccc.charCodeAt(2))); + default: + return _fromCC(((0x1f & cccc.charCodeAt(0)) << 6) + | (0x3f & cccc.charCodeAt(1))); + } +}; + +const btou = function (b: string) { + return b.replace(re_btou, cb_btou); +}; + + +const _unURI = function (a: string) { + return _tidyB64(a.replace(/[-_]/g, m0 => (m0 == '-' ? '+' : '/'))); +}; + + +export const decode = (str: string) => btou(innerDecode(_unURI(str))); + + +// 小程序版本的atob +export const innerDecode = function (string: string) { + string = String(string).replace(/[\t\n\f\r ]+/g, ''); + if (!B64RE.test(string)) throw new TypeError('Failed to execute \'atob\' on \'Window\': The string to be decoded is not correctly encoded.'); + string += '=='.slice(2 - (string.length & 3)); + let bitmap; let result = ''; + let r1; let r2; let i = 0; + for (; i < string.length;) { + bitmap = B64.indexOf(string.charAt(i++)) << 18 | B64.indexOf(string.charAt(i++)) << 12 + | (r1 = B64.indexOf(string.charAt(i++))) << 6 | (r2 = B64.indexOf(string.charAt(i++))); + + result += r1 === 64 ? String.fromCharCode(bitmap >> 16 & 255) + : r2 === 64 ? String.fromCharCode(bitmap >> 16 & 255, bitmap >> 8 & 255) + : String.fromCharCode(bitmap >> 16 & 255, bitmap >> 8 & 255, bitmap & 255); + } + return result; +}; diff --git a/src/base64/encode.ts b/src/base64/encode.ts new file mode 100644 index 00000000..31139bed --- /dev/null +++ b/src/base64/encode.ts @@ -0,0 +1,52 @@ +/* eslint-disable */ +import { B64, _fromCC } from './config'; +const re_utob = /[\uD800-\uDBFF][\uDC00-\uDFFFF]|[^\x00-\x7F]/g; + +const utob = function (u: string) { + return u.replace(re_utob, cb_utob); +}; + + +const cb_utob = function (c: string) { + if (c.length < 2) { + var cc: any = c.charCodeAt(0); + return cc < 0x80 ? c + : cc < 0x800 ? (_fromCC(0xc0 | (cc >>> 6)) + + _fromCC(0x80 | (cc & 0x3f))) + : (_fromCC(0xe0 | ((cc >>> 12) & 0x0f)) + + _fromCC(0x80 | ((cc >>> 6) & 0x3f)) + + _fromCC(0x80 | (cc & 0x3f))); + } + + var cc: any = 0x10000 + + (c.charCodeAt(0) - 0xD800) * 0x400 + + (c.charCodeAt(1) - 0xDC00); + return (_fromCC(0xf0 | ((cc >>> 18) & 0x07)) + + _fromCC(0x80 | ((cc >>> 12) & 0x3f)) + + _fromCC(0x80 | ((cc >>> 6) & 0x3f)) + + _fromCC(0x80 | (cc & 0x3f))); +}; + +export const encode = (str: string) => innerEncode(utob(str)); + + +// 小程序版本的btoa +export const innerEncode = function (string: string) { + string = String(string); + let bitmap; let a; let b; let c; + let result = ''; + let i = 0; + const rest = string.length % 3; + + for (; i < string.length;) { + if ((a = string.charCodeAt(i++)) > 255 + || (b = string.charCodeAt(i++)) > 255 + || (c = string.charCodeAt(i++)) > 255) throw new TypeError('Failed to execute \'btoa\' on \'Window\': The string to be encoded contains characters outside of the Latin1 range.'); + + bitmap = (a << 16) | (b << 8) | c; + result += B64.charAt(bitmap >> 18 & 63) + B64.charAt(bitmap >> 12 & 63) + + B64.charAt(bitmap >> 6 & 63) + B64.charAt(bitmap & 63); + } + + return rest ? result.slice(0, rest - 3) + '==='.substring(rest) : result; +}; diff --git a/src/base64/index.ts b/src/base64/index.ts new file mode 100644 index 00000000..a1f09904 --- /dev/null +++ b/src/base64/index.ts @@ -0,0 +1,2 @@ +export { encode } from './encode'; +export { decode } from './decode'; diff --git a/src/devops/mp-ci/devops-mp-ci.ts b/src/devops/mp-ci/devops-mp-ci.ts index b4aac203..6448587e 100644 --- a/src/devops/mp-ci/devops-mp-ci.ts +++ b/src/devops/mp-ci/devops-mp-ci.ts @@ -118,6 +118,7 @@ async function realUpdateOrCreatePipeline({ rainbowConfigKey: mpCIKey, repo: newConfig.ci.repo, isWxCI, + devopsParams: newConfig.devopsParams || {}, }), ], }) diff --git a/src/devops/mp-ci/helper.ts b/src/devops/mp-ci/helper.ts index 89502601..0122b1f0 100644 --- a/src/devops/mp-ci/helper.ts +++ b/src/devops/mp-ci/helper.ts @@ -105,6 +105,7 @@ export function getPipelineParam({ rainbowConfigKey, repo, isWxCI, + devopsParams, }: Record) { const res = [ { @@ -159,6 +160,14 @@ export function getPipelineParam({ desc: 'Tam上报ID', readOnly: false, }, + { + id: 'useDevopsWXCIPlugin', + required: true, + type: 'STRING', + defaultValue: devopsParams?.useDevopsWXCIPlugin || '0', + desc: '是否使用蓝盾平台小程序CI插件', + readOnly: false, + }, ]); } return res; diff --git a/src/index.ts b/src/index.ts index 7b8dcbab..de66ed35 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,5 +1,6 @@ export * from './ast'; export * from './base'; +export * from './base64'; export * from './bite'; export * from './build-upload'; export * from './bundle-analyze'; diff --git a/src/mp-ci/manage-config/helper.ts b/src/mp-ci/manage-config/helper.ts index 9eadd64a..1047ea88 100644 --- a/src/mp-ci/manage-config/helper.ts +++ b/src/mp-ci/manage-config/helper.ts @@ -59,11 +59,16 @@ export function updateQQTencentSheetLine(rainbowConfig: Record) { Object.keys(qqRobotMap).forEach((branch) => { const value = qqRobotMap[branch] || {}; if (!value.tencentDocsLine) { - value.tencentDocsLine = { - test: restLines[cur], - release: restLines[cur + 1], - }; - cur += 2; + const temp: Record = {}; + if (value.test) { + temp.test = restLines[cur]; + cur += 1; + } + if (value.release) { + temp.release = restLines[cur]; + cur += 1; + } + value.tencentDocsLine = temp; } }); } diff --git a/src/mp-ci/manage-config/manage-config.ts b/src/mp-ci/manage-config/manage-config.ts index 2915d585..ccba214d 100644 --- a/src/mp-ci/manage-config/manage-config.ts +++ b/src/mp-ci/manage-config/manage-config.ts @@ -2,33 +2,72 @@ import { ERROR_MAP } from './config'; import { sortRobotMapByRobot, updateQQTencentSheetLine } from './helper'; import { sortObjectByKey } from '../../base/object/sort'; + +function changeRobot({ + info, + robot, + env, + testRobot, + releaseRobot, +}: { + info: Record; + testRobot?: number; + releaseRobot?: number; + + robot?: number; + env?: string; +}) { + if (robot && env) { + info[env] = robot; + } else { + info.test = testRobot; + info.release = releaseRobot; + } +} + export function updateMpCIRainbowConfig({ rainbowConfig, branch, originBranch, + testRobot, releaseRobot, + + robot, + env, + useMpQQ, - errorMap = ERROR_MAP, + // errorMap = ERROR_MAP, }: { rainbowConfig: Record; branch: string; originBranch?: string; - testRobot: number; - releaseRobot: number; + testRobot?: number; + releaseRobot?: number; + + robot?: number; + env?: string; + useMpQQ?: boolean; errorMap?: typeof ERROR_MAP; }): { error: string; - } | { + } |{ newRainbowConfig: Record; rainbowKey: string; } { function setWxRobot() { - rainbowConfig.robotMap[branch] = { - test: testRobot, - release: releaseRobot, - }; + if (!rainbowConfig.robotMap[branch]) { + rainbowConfig.robotMap[branch] = {}; + } + + changeRobot({ + info: rainbowConfig.robotMap[branch], + testRobot, + releaseRobot, + robot, + env, + }); } function setQQRobot() { @@ -40,50 +79,73 @@ export function updateMpCIRainbowConfig({ if (!rainbowConfig.qqRobotMap[branch]) { rainbowConfig.qqRobotMap[branch] = {}; } - rainbowConfig.qqRobotMap[branch].test = testRobot; - rainbowConfig.qqRobotMap[branch].release = releaseRobot; + + changeRobot({ + info: rainbowConfig.qqRobotMap[branch], + testRobot, + releaseRobot, + robot, + env, + }); } else { - delete rainbowConfig.qqRobotMap[branch]; + if (rainbowConfig.qqRobotMap?.[branch]) { + delete rainbowConfig.qqRobotMap[branch].test; + delete rainbowConfig.qqRobotMap[branch].release; + } } } - const originUseMpQQ = !!rainbowConfig.qqRobotMap?.[branch]; + // const originUseMpQQ = !!rainbowConfig.qqRobotMap?.[branch]; - // 新增 - if (!originBranch) { - // 该分支已经有配置了 - if (rainbowConfig.robotMap[branch]) { - return { - error: errorMap.BRANCH_EXIST, - }; + if (originBranch) { + if (rainbowConfig.robotMap?.[originBranch]) { + delete rainbowConfig.robotMap[originBranch].test; + delete rainbowConfig.robotMap[originBranch].release; } - - setWxRobot(); - setQQRobot(); - } else { - // 修改 - - // 分支相同,说明是仅修改qq配置 - if (originBranch === branch) { - if (originUseMpQQ === useMpQQ) { - return { - error: errorMap.SAME_CONFIG, - }; - } - setQQRobot(); - } else { - if (rainbowConfig.robotMap[branch]) { - return { - error: errorMap.BRANCH_EXIST, - }; - } - setWxRobot(); - setQQRobot(); - delete rainbowConfig.robotMap[originBranch]; - delete rainbowConfig.qqRobotMap[originBranch]; + if (rainbowConfig.qqRobotMap?.[originBranch]) { + delete rainbowConfig.qqRobotMap[originBranch].test; + delete rainbowConfig.qqRobotMap[originBranch].release; + delete rainbowConfig.qqRobotMap[originBranch].tencentDocsLine; } } + setWxRobot(); + setQQRobot(); + // 新增 + // if (!originBranch) { + // // 该分支已经有配置了 + // if (rainbowConfig.robotMap[branch]) { + // return { + // error: errorMap.BRANCH_EXIST, + // }; + // } + + // setWxRobot(); + // setQQRobot(); + // } else { + // // 修改 + + // // 分支相同,说明是仅修改qq配置 + // if (originBranch === branch) { + // if (originUseMpQQ === useMpQQ) { + // return { + // error: errorMap.SAME_CONFIG, + // }; + // } + // setQQRobot(); + // } else { + // if (rainbowConfig.robotMap[branch]) { + // return { + // error: errorMap.BRANCH_EXIST, + // }; + // } + // setWxRobot(); + // setQQRobot(); + // delete rainbowConfig.robotMap[originBranch]; + // delete rainbowConfig.qqRobotMap[originBranch]; + // } + // } + rainbowConfig.robotMap = sortRobotMapByRobot(rainbowConfig.robotMap); const { rainbowKey } = rainbowConfig; diff --git a/src/node/node-command.ts b/src/node/node-command.ts index 61bd605c..6f799c63 100644 --- a/src/node/node-command.ts +++ b/src/node/node-command.ts @@ -2,7 +2,8 @@ /** - * nodejs中调用 child_process.execSync 执行命令 + * nodejs 中调用 child_process.execSync 执行命令, + * 这个方法会对输出结果截断,只返回第一行内容 * @param {string} command 命令 * @param {string} root 执行命令的目录 * @param {string} stdio 结果输出,默认为 pipe @@ -23,3 +24,27 @@ export function execCommand(command: string, root?: string, stdio?: string): str ?.trim() || '' ); } + + +/** + * nodejs中调用 child_process.execSync 执行命令 + * @param {string} command 命令 + * @param {string} root 执行命令的目录 + * @param {string} stdio 结果输出,默认为 pipe + * @returns {string} 命令执行结果 + */ +export function execCommandAll(command: string, root?: string, stdio?: string): string { + if (!root) { + root = process.cwd(); + } + const { execSync } = require('child_process'); + return ( + execSync(command, { + cwd: root || process.cwd(), + encoding: 'utf-8', + stdio: stdio || 'pipe', + }) + ?.split('\n')[0] + ?.trim() || '' + ); +} diff --git a/src/version/bump.ts b/src/version/bump.ts new file mode 100644 index 00000000..2548c160 --- /dev/null +++ b/src/version/bump.ts @@ -0,0 +1,53 @@ +/** + * 生成 alpha、beta 等这些预发布的版本 + * @param key 关键词 + * @returns 生成的版本 + */ +export function getPreReleaseVersion(key = '') { + if (!key) { + return; + } + + // eslint-disable-next-line @typescript-eslint/no-require-imports + const { execSync } = require('child_process'); + + const res = execSync('npm dist-tag ls', { + cwd: process.cwd(), + encoding: 'utf-8', + stdio: 'pipe', + }); + const obj = parseDistTagResult(res); + return genVersion(obj, key); +} + + +export function genVersion(obj: Record = {}, key = '') { + if (!obj[key]) { + const { latest } = obj as unknown as Record; + if (!latest) { + return `0.0.1-${key}.1`; + } + return `${latest}-${key}.1`; + } + + + const last = obj[key]; + const list = last.split(`${key}.`); + + return `${list[0]}${key}.${+list[1] + 1}`; +} + +function parseDistTagResult(str = ''): Record { + return str.trim() + .split('\n') + .reduce((acc, item) => { + const str = item.trim(); + + const temp = str.split(':'); + + return { + ...acc, + [temp[0].trim()]: temp[1].trim(), + }; + }, {}); +} diff --git a/src/version/index.ts b/src/version/index.ts index 4cc2c474..63a2bea8 100644 --- a/src/version/index.ts +++ b/src/version/index.ts @@ -1 +1,2 @@ -export { compareVersion } from './version' +export { getPreReleaseVersion } from './bump'; +export { compareVersion } from './version'; diff --git a/test/base/list-split.test.ts b/test/base/list-split.test.ts new file mode 100644 index 00000000..9650b5ec --- /dev/null +++ b/test/base/list-split.test.ts @@ -0,0 +1,20 @@ +import { splitLongList } from '../../src/base/list'; + +describe('splitLongList', () => { + it('splitLongList', () => { + const list = Array.from({ length: 7 }).map((_, i) => `${i + 1}`); + const result = splitLongList(list, 2, 3); + expect(result).toMatchObject([ + ['1', '2'], + ['3', '4'], + ['5', '6', '7'], + ]); + + const result2 = splitLongList(list, 3, 3); + expect(result2).toMatchObject([ + ['1', '2', '3'], + ['4', '5', '6'], + ['7'], + ]); + }); +}); diff --git a/test/base64/decode.spec.ts b/test/base64/decode.spec.ts new file mode 100644 index 00000000..22dffb6c --- /dev/null +++ b/test/base64/decode.spec.ts @@ -0,0 +1,19 @@ +import { decode } from '../../src/base64/'; + + +describe('decode', () => { + it('decode', () => { + expect(decode('ZGFua29nYWk=')).toBe('dankogai'); + expect(decode('emhvbmdndW8=')).toBe('zhongguo'); + expect(decode('YWJj')).toBe('abc'); + expect(decode('eHh4eHh4eGFkZmFkZg==')).toBe('xxxxxxxadfadf'); + }); + + it('chinese', () => { + expect(decode('5p2o')).toBe('杨'); + expect(decode('5Lit5Zu9')).toBe('中国'); + expect(decode('5LiJ5Liq5a2X')).toBe('三个字'); + expect(decode('5aSn5rGf5aSn5rKz')).toBe('大江大河'); + expect(decode('5pWZ6IKy6YOo5a2m57GN5Zyo57q/6aqM6K+B5oql5ZGK')).toBe('教育部学籍在线验证报告'); + }); +}); diff --git a/test/base64/encode.spec.ts b/test/base64/encode.spec.ts new file mode 100644 index 00000000..ae5c9467 --- /dev/null +++ b/test/base64/encode.spec.ts @@ -0,0 +1,19 @@ +import { encode } from '../../src/base64'; + + +describe('encode', () => { + it('encode', () => { + expect(encode('dankogai')).toBe('ZGFua29nYWk='); + expect(encode('zhongguo')).toBe('emhvbmdndW8='); + expect(encode('abc')).toBe('YWJj'); + expect(encode('xxxxxxxadfadf')).toBe('eHh4eHh4eGFkZmFkZg=='); + }); + + it('chinese', () => { + expect(encode('杨')).toBe('5p2o'); + expect(encode('中国')).toBe('5Lit5Zu9'); + expect(encode('三个字')).toBe('5LiJ5Liq5a2X'); + expect(encode('大江大河')).toBe('5aSn5rGf5aSn5rKz'); + expect(encode('教育部学籍在线验证报告')).toBe('5pWZ6IKy6YOo5a2m57GN5Zyo57q/6aqM6K+B5oql5ZGK'); + }); +}); diff --git a/test/version/bump.spec.ts b/test/version/bump.spec.ts new file mode 100644 index 00000000..bb054d22 --- /dev/null +++ b/test/version/bump.spec.ts @@ -0,0 +1,25 @@ +import { genVersion } from '../../src/version/bump'; + +describe('genVersion', () => { + it('genVersion', () => { + expect(genVersion({ + alpha: '1.6.0-alpha.5', + beta: '1.6.0-beta.6', + latest: '1.5.127', + }, 'beta')).toBe('1.6.0-beta.7'); + + expect(genVersion({ + alpha: '1.6.0-alpha.5', + beta: '1.6.0-beta.6', + latest: '1.5.127', + }, 'alpha')).toBe('1.6.0-alpha.6'); + + expect(genVersion({ + alpha: '1.6.0-alpha.5', + beta: '1.6.0-beta.6', + latest: '1.5.127', + }, 'next')).toBe('1.5.127-next.1'); + + expect(genVersion({}, 'alpha')).toBe('0.0.1-alpha.1'); + }); +}); diff --git a/tsconfig-es.json b/tsconfig-es.json new file mode 100644 index 00000000..f7ff0b5f --- /dev/null +++ b/tsconfig-es.json @@ -0,0 +1,7 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "outDir": "es", + "declarationDir": "es", + }, +} \ No newline at end of file