diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 4b7ff7e4..d4bc00ce 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -1,5 +1,46 @@ # 更新日志 +### [1.3.94](https://github.com/novlan1/t-comm/compare/v1.3.93...v1.3.94) (2024-07-29) + + +### Features 🎉 + +* **console.image:** add consoleImage ([9e0b022](https://github.com/novlan1/t-comm/commit/9e0b022c308aaf9e150bab6d8324df03bf1c73c1)) +* **vconsole:** vconsole增加aegis性能数据的展示 ([3d8eeec](https://github.com/novlan1/t-comm/commit/3d8eeec569842933a8fe3b254c41962b2b744ba0)) + +### [1.3.93](https://github.com/novlan1/t-comm/compare/v1.3.92...v1.3.93) (2024-07-10) + + +### Bug Fixes 🐞 + +* **daily-merge:** 打印日志,分支过滤优化 ([d6f575d](https://github.com/novlan1/t-comm/commit/d6f575dae05bdf798ed6871ccc2842e90c0327e6)) + +### [1.3.92](https://github.com/novlan1/t-comm/compare/v1.3.91...v1.3.92) (2024-07-10) + + +### Features 🎉 + +* **daily-merge:** add whiteBranchReg param ([3a3d313](https://github.com/novlan1/t-comm/commit/3a3d3132a36f85ca1531258acffa0df797607137)) + +### [1.3.91](https://github.com/novlan1/t-comm/compare/v1.3.90...v1.3.91) (2024-07-02) + + +### Chore 🚀 + +* update test cases ([45fff0c](https://github.com/novlan1/t-comm/commit/45fff0c072994376abef3e7d1fece54aae73b1da)) + + +### Documentation 📖 + +* 文档优化 ([b4842d0](https://github.com/novlan1/t-comm/commit/b4842d037bb151734ed55f39885b30f9fa940fbe)) +* update ast docs ([b1d11d1](https://github.com/novlan1/t-comm/commit/b1d11d11985af896b7f33f1d0b71a348caecdc55)) + + +### Features 🎉 + +* **slug-sdk:** update js sdk ([70d9f18](https://github.com/novlan1/t-comm/commit/70d9f188c7e206e9ea4f060df67e925a74dd92bb)) +* update docs ([7d63379](https://github.com/novlan1/t-comm/commit/7d633790f360fe34c7db1d97a1a876517b29b44d)) + ### [1.3.90](https://github.com/novlan1/t-comm/compare/v1.3.89...v1.3.90) (2024-05-23) diff --git a/docs/zh/daily-merge.md b/docs/zh/daily-merge.md index 058ae62a..44f349bc 100644 --- a/docs/zh/daily-merge.md +++ b/docs/zh/daily-merge.md @@ -30,6 +30,7 @@ import { dailyMerge} from 't-comm/lib/daily-merge/index'; | param0.privateToken | string | |

密钥

| | [param0.isDryRun] | boolean | false |

是否演练

| | [param0.mainBranch] | string | "'develop'" |

主分支

| +| [param0.whiteBranchReg] | Regexp | /^release\|develop\|hotfix\\/.+$/ |

不处理的分支正则

| diff --git a/package.json b/package.json index 69388cfb..7e8d3cb1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "t-comm", - "version": "1.3.90", + "version": "1.3.94", "description": "丰富易用的工具库", "main": "lib/index.js", "module": "lib/index.esm.js", diff --git a/src/console/image.ts b/src/console/image.ts new file mode 100644 index 00000000..cbb6638b --- /dev/null +++ b/src/console/image.ts @@ -0,0 +1,41 @@ +export const consoleImage = function (url: string) { + const image = new Image(); + image.onload = function (this: any) { + // @ts-ignore + const isChromium = navigator.userAgent.match(/chrome|chromium|crios/i) && !!window.chrome; + const style = [ + 'font-size: 0px;', + !isChromium ? `line-height: ${this.height}px;` : '', + `padding: ${this.height / 2}px ${this.width / 2}px;`, + `background: url(${url}) center center no-repeat;`, + 'background-size: contain;', + ].join(' '); + console.log('%c ', style); + }; + image.src = url; +}; + +/** + * 获取图片,并转 base64 + * + * @param url 图片链接 + * @returns 获取结果 + * @example + * ```ts + * getBase64FromUrl(imgUrl).then(consoleImage); + * ``` + */ +export async function getBase64FromUrl(url: string) { + const data = await fetch(url); + const blob = await data.blob(); + return new Promise((resolve, reject) => { + const reader = new FileReader(); + reader.readAsDataURL(blob); + reader.onloadend = () => { + const base64data = reader.result; + resolve(base64data); + }; + reader.onerror = reject; + }); +} + diff --git a/src/console/index.ts b/src/console/index.ts new file mode 100644 index 00000000..7111a1e8 --- /dev/null +++ b/src/console/index.ts @@ -0,0 +1,4 @@ +export { + consoleImage, + getBase64FromUrl, +} from './image'; diff --git a/src/daily-merge/daily-merge.ts b/src/daily-merge/daily-merge.ts index 500b56bf..bc9ed3be 100644 --- a/src/daily-merge/daily-merge.ts +++ b/src/daily-merge/daily-merge.ts @@ -4,13 +4,9 @@ import { getOneProjectDetail } from '../tgit/project'; import { execCommand } from '../node/node-command'; import { batchSendWxRobotMarkdown } from '../wecom-robot/batch-send'; import { getGitCommitInfo } from '../git/git'; +import { shouldInclude, DEFAULT_WHITE_REG } from './helper'; -const WHITE_BRANCH_LIST = [ - 'develop', - 'release', -]; - const CHAT_ID = ['ALL']; @@ -26,10 +22,13 @@ async function getBranches({ baseUrl, repoName, privateToken, + whiteBranchReg, }: { baseUrl: string; repoName: string; privateToken: string; + + whiteBranchReg?: RegExp }) { const res = await getBranchesByProjectName({ projectName: repoName, @@ -48,9 +47,10 @@ async function getBranches({ return false; }); + console.log('[Origin Branches]', list.map(item => item?.name)); - const branches = list.filter(branch => WHITE_BRANCH_LIST.indexOf(branch.name) <= -1); - console.log('[branches]', branches.map(item => item?.name)); + const branches = list.filter(branch => shouldInclude(branch.name, whiteBranchReg)); + console.log('[Filter Branches]', branches.map(item => item?.name)); return branches; } @@ -177,6 +177,7 @@ async function sendSendMsg(content: string, webhookUrl: string) { * @param {string} param0.privateToken 密钥 * @param {boolean} [param0.isDryRun=false] 是否演练 * @param {string} [param0.mainBranch='develop'] 主分支 + * @param {Regexp} [param0.whiteBranchReg=/^release\|develop\|hotfix\\/.+$/] 不处理的分支正则 * @returns {*} * @example * @@ -206,6 +207,8 @@ export async function dailyMerge({ isDryRun = false, mainBranch = 'develop', + + whiteBranchReg = DEFAULT_WHITE_REG, }: { webhookUrl: string; appName: string; @@ -217,6 +220,8 @@ export async function dailyMerge({ isDryRun?: boolean; mainBranch?: string; + + whiteBranchReg?: RegExp; }) { console.log('\nSTART Daily Merge =====>'); if (!baseUrl) { @@ -233,6 +238,8 @@ export async function dailyMerge({ baseUrl, repoName, privateToken, + + whiteBranchReg, }); if (!branches || !branches.length) { diff --git a/src/daily-merge/helper.ts b/src/daily-merge/helper.ts new file mode 100644 index 00000000..eb5d900d --- /dev/null +++ b/src/daily-merge/helper.ts @@ -0,0 +1,5 @@ +export const DEFAULT_WHITE_REG = /^release|develop|hotfix\/.+$/; + +export function shouldInclude(branch = '', reg = DEFAULT_WHITE_REG) { + return !reg.test(branch); +} diff --git a/src/index.ts b/src/index.ts index 83b18998..7b8dcbab 100644 --- a/src/index.ts +++ b/src/index.ts @@ -9,6 +9,7 @@ export * from './city'; export * from './clipboard'; export * from './color'; export * from './component'; +export * from './console'; export * from './constant'; export * from './cookie'; export * from './cron'; diff --git a/src/msdk/msdk.ts b/src/msdk/msdk.ts index 7663e19c..1c4631a7 100644 --- a/src/msdk/msdk.ts +++ b/src/msdk/msdk.ts @@ -123,7 +123,7 @@ export function callJsBrowserAdapter() { }); } } else if (env.isSlugSdk) { - loader('https://tiem-cdn.qq.com/slugteam/sdk/browser_adapt.js', () => { + loader('https://image-1251917893.file.myqcloud.com/igame/common/js/browser_adapt_20240702.js', () => { resolve(true); }); } diff --git a/src/v-console/config.ts b/src/v-console/config.ts index 264a9938..0782a236 100644 --- a/src/v-console/config.ts +++ b/src/v-console/config.ts @@ -128,3 +128,36 @@ export const COMMIT_LIST = [ label: 'Last Commit Hash', }, ]; + + +export const AEGIS_PERFORMANCE_KEY = '__AEGIS_PERFORMANCE'; +export const AEGIS_PERFORMANCE_LIST = [ + { + key: 'dnsLookup', + label: 'Aegis DNS 查询', + }, + { + key: 'tcp', + label: 'Aegis TCP 链接', + }, + { + key: 'ttfb', + label: 'Aegis SSL 建连', + }, + { + key: 'contentDownload', + label: 'Aegis contentDownload', + }, + { + key: 'resourceDownload', + label: 'Aegis resourceDownload', + }, + { + key: 'domParse', + label: 'Aegis DOM解析', + }, + { + key: 'firstScreenTiming', + label: 'Aegis 首屏耗时', + }, +]; diff --git a/src/v-console/plugin/version.ts b/src/v-console/plugin/version.ts index 59e3b1db..397eeb10 100644 --- a/src/v-console/plugin/version.ts +++ b/src/v-console/plugin/version.ts @@ -4,6 +4,9 @@ import { V_CONSOLE_DOM, BUILD_LIST, COMMIT_LIST, + + AEGIS_PERFORMANCE_KEY, + AEGIS_PERFORMANCE_LIST, } from '../config'; import type { IPlugin } from '../types'; @@ -41,6 +44,8 @@ function renderPlugin(callback: Function) { }) .concat(EMPTY_LINE) .concat(getVersionHtml()) + .concat(EMPTY_LINE) + .concat(getAegisPerformanceInfo()) .join('\n'); html += ` @@ -183,3 +188,20 @@ function getVersionHtml() { EMPTY_LINE, ].join('\n'); } + + +function getAegisPerformanceInfo() { + const perfInfo = (window[AEGIS_PERFORMANCE_KEY as any] || {}) as any; + + const perfHtmlList = AEGIS_PERFORMANCE_LIST.map((item) => { + const { key, label } = item; + return `
${label}: ${perfInfo[key] ?? ''}
`; + }); + + + return [ + EMPTY_LINE, + ...perfHtmlList, + EMPTY_LINE, + ].join('\n'); +} diff --git a/test/daily-merge/helper.test.ts b/test/daily-merge/helper.test.ts new file mode 100644 index 00000000..aed2ccd5 --- /dev/null +++ b/test/daily-merge/helper.test.ts @@ -0,0 +1,13 @@ +import { shouldInclude } from '../../src/daily-merge/helper'; + +describe('shouldExclude', () => { + it('shouldExclude', () => { + expect(shouldInclude('release')).toBe(false); + expect(shouldInclude('develop')).toBe(false); + expect(shouldInclude('hotfix/abc-adf-123')).toBe(false); + + expect(shouldInclude('feature/manager-hp')).toBe(true); + expect(shouldInclude('123123-a')).toBe(true); + expect(shouldInclude('abc-d')).toBe(true); + }); +});