Skip to content

Commit

Permalink
feat(console): add consoleImage
Browse files Browse the repository at this point in the history
  • Loading branch information
novlan1 committed Jul 29, 2024
1 parent fe91f3a commit d8ce19b
Show file tree
Hide file tree
Showing 12 changed files with 177 additions and 9 deletions.
41 changes: 41 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)


Expand Down
1 change: 1 addition & 0 deletions docs/zh/daily-merge.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { dailyMerge} from 't-comm/lib/daily-merge/index';
| param0.privateToken | <code>string</code> | | <p>密钥</p> |
| [param0.isDryRun] | <code>boolean</code> | <code>false</code> | <p>是否演练</p> |
| [param0.mainBranch] | <code>string</code> | <code>&quot;&#x27;develop&#x27;&quot;</code> | <p>主分支</p> |
| [param0.whiteBranchReg] | <code>Regexp</code> | <code>/^release\|develop\|hotfix\\/.+$/</code> | <p>不处理的分支正则</p> |



Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
41 changes: 41 additions & 0 deletions src/console/image.ts
Original file line number Diff line number Diff line change
@@ -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;
});
}

4 changes: 4 additions & 0 deletions src/console/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export {
consoleImage,
getBase64FromUrl,
} from './image';
21 changes: 14 additions & 7 deletions src/daily-merge/daily-merge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'];


Expand 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,
Expand All @@ -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;
}

Expand Down Expand Up @@ -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
*
Expand Down Expand Up @@ -206,6 +207,8 @@ export async function dailyMerge({

isDryRun = false,
mainBranch = 'develop',

whiteBranchReg = DEFAULT_WHITE_REG,
}: {
webhookUrl: string;
appName: string;
Expand All @@ -217,6 +220,8 @@ export async function dailyMerge({

isDryRun?: boolean;
mainBranch?: string;

whiteBranchReg?: RegExp;
}) {
console.log('\nSTART Daily Merge =====>');
if (!baseUrl) {
Expand All @@ -233,6 +238,8 @@ export async function dailyMerge({
baseUrl,
repoName,
privateToken,

whiteBranchReg,
});

if (!branches || !branches.length) {
Expand Down
5 changes: 5 additions & 0 deletions src/daily-merge/helper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const DEFAULT_WHITE_REG = /^release|develop|hotfix\/.+$/;

export function shouldInclude(branch = '', reg = DEFAULT_WHITE_REG) {
return !reg.test(branch);
}
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion src/msdk/msdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}
Expand Down
33 changes: 33 additions & 0 deletions src/v-console/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 首屏耗时',
},
];
22 changes: 22 additions & 0 deletions src/v-console/plugin/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -41,6 +44,8 @@ function renderPlugin(callback: Function) {
})
.concat(EMPTY_LINE)
.concat(getVersionHtml())
.concat(EMPTY_LINE)
.concat(getAegisPerformanceInfo())
.join('\n');

html += `
Expand Down Expand Up @@ -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 `<div class="${V_CONSOLE_DOM.LINE}">${label}: ${perfInfo[key] ?? ''}</div>`;
});


return [
EMPTY_LINE,
...perfHtmlList,
EMPTY_LINE,
].join('\n');
}
13 changes: 13 additions & 0 deletions test/daily-merge/helper.test.ts
Original file line number Diff line number Diff line change
@@ -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);
});
});

0 comments on commit d8ce19b

Please sign in to comment.