From b6140fb0b44e8b7e95b40161538d2be63b23965a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Allen=20Zhang=20=28=E5=BC=A0=E6=B6=9B=29?= Date: Thu, 24 Oct 2024 17:15:50 +0800 Subject: [PATCH] feat(canyon-platform): use swc --- plugins/babel-plugin-canyon/package.json | 2 +- plugins/babel-plugin-canyon/src/index.js | 6 +- .../templates/inject-in-page-popup.js | 81 +++++++++++++------ plugins/inject-popup/test.html | 72 ++++++++++++----- 4 files changed, 114 insertions(+), 47 deletions(-) diff --git a/plugins/babel-plugin-canyon/package.json b/plugins/babel-plugin-canyon/package.json index 5aa449e7..7ad87f5c 100644 --- a/plugins/babel-plugin-canyon/package.json +++ b/plugins/babel-plugin-canyon/package.json @@ -1,6 +1,6 @@ { "name": "babel-plugin-canyon", - "version": "1.8.78-beta.18", + "version": "1.8.78-beta.19", "description": "A Babel plugin cooperates with istanbul to report the coverage", "author": "Allen Zhang ", "license": "MIT", diff --git a/plugins/babel-plugin-canyon/src/index.js b/plugins/babel-plugin-canyon/src/index.js index 096cad1e..a57cf395 100644 --- a/plugins/babel-plugin-canyon/src/index.js +++ b/plugins/babel-plugin-canyon/src/index.js @@ -79,8 +79,10 @@ export default declare((api,config) => { // TODO: 需要删除writeCanyonToLocal path.node.body.unshift(writeCanyonToLocal) - // TODO: 测试代码 - path.node.body.unshift(injectInPagePopup) + if (config.injectInPagePopup){ + // TODO: 测试代码 + path.node.body.unshift(injectInPagePopup) + } // 必须校验数据完整性 diff --git a/plugins/babel-plugin-canyon/templates/inject-in-page-popup.js b/plugins/babel-plugin-canyon/templates/inject-in-page-popup.js index 70129c0c..7fd6a411 100644 --- a/plugins/babel-plugin-canyon/templates/inject-in-page-popup.js +++ b/plugins/babel-plugin-canyon/templates/inject-in-page-popup.js @@ -100,7 +100,7 @@ left: 0; right: 0; bottom: 0; - background: rgba(0,0,0,0.5); + background: rgba(0,0,0,0.9); font-size: 12px; color: white; } @@ -130,7 +130,7 @@ .__canyon__close-wrap{ display: flex; justify-content: flex-end; - padding-top: 30px; + padding-top: 45px; padding-right: 10px } .__canyon__close{ @@ -155,24 +155,24 @@ const canyon = globalObj.__canyon__ const coverage = globalObj.__coverage__ - // 步骤一:连点5次打开弹窗+检查页面变量合法性 - let clickCount = 0 - let clickTimeout + // 步骤一:连点3次打开弹窗+检查页面变量合法性 + let clickCount = 0; + let clickTimeout; document.addEventListener('click', () => { - clickCount++ + clickCount++; if (clickCount === 1) { // 开始1秒计时 clickTimeout = setTimeout(() => { // 1秒结束,重置计数 - clickCount = 0 - }, 1000) + clickCount = 0; + }, 500); } - if (clickCount >= 5) { + if (clickCount >= 3) { // 1秒内点击超过6次,触发弹窗 - clearTimeout(clickTimeout) // 清除计时器 - clickCount = 0 // 重置计数 + clearTimeout(clickTimeout); // 清除计时器 + clickCount = 0; // 重置计数 // 检查参数 if (globalObj.__canyon__ && globalObj.__coverage__) { @@ -181,55 +181,86 @@ alert('window.__canyon__ or window.__coverage__ is not defined') } } - }) + }); // 点击关闭按钮关闭弹窗 document.querySelector('.__canyon__close').addEventListener('click', () => { document.querySelector('.__canyon__modal').style.display = 'none' }) + document.querySelector('.canyon-form-value-projectid').innerHTML = canyon.projectID document.querySelector('.canyon-form-value-sha').innerHTML = canyon.sha document.querySelector('.canyon-form-value-branch').innerHTML = canyon.branch document.querySelector('.canyon-form-value-dsn').innerHTML = canyon.dsn document.querySelector('.canyon-form-value-coverage').innerHTML = String(Object.keys(coverage).length) + document.querySelector('.canyon-form-value-auto').checked = Boolean(localStorage.getItem('canyon-auto')) + document.querySelector('.canyon-form-value-reportid').value = localStorage.getItem('canyon-reportid') || '' -// 添加事件 - document.querySelector('.__canyon__btn_upload').addEventListener('click', function () { + document.querySelector('.canyon-form-value-auto').addEventListener('change',function () { + if (this.checked === true){ + localStorage.setItem('canyon-auto','true') + }else{ + localStorage.removeItem('canyon-auto') + } + }) - // 状态置为上传中 + document.querySelector('.canyon-form-value-reportid').addEventListener('change',function () { + localStorage.setItem('canyon-reportid',this.value) + }) - document.querySelector('.__canyon__result').innerHTML = 'Uploading...' - fetch(canyon.dsn, { - method: 'post', + const uploadPromise = ()=>{ + return fetch(canyon.dsn, { + method: 'POST', body: JSON.stringify({ ...canyon, + reportID: document.querySelector('.canyon-form-value-reportid').value, coverage: globalObj.__coverage__ }), headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${canyon.reporter}` } - }).then(res => { + }) + } + + + setInterval(()=>{ + if (document.querySelector('.canyon-form-value-auto').checked === true){ + uploadPromise() + } + },2000) + +// 添加事件 + + document.querySelector('.__canyon__btn_upload').addEventListener('click', function () { + + // 状态置为上传中 + + document.querySelector('.__canyon__result').innerHTML = 'Uploading...' + + uploadPromise().then(res=>{ return res.json() }) .then((res) => { if (res.statusCode > 300) { - document.querySelector('.__canyon__result').innerHTML = JSON.stringify(res) + document.querySelector('.__canyon__result').innerHTML = JSON.stringify(res); } else { - document.querySelector('.__canyon__result').innerHTML = 'Upload Success!' + document.querySelector('.__canyon__result').innerHTML = 'Upload Success!'; } }) .catch((err) => { - alert(String(err)) - document.querySelector('.__canyon__result').innerHTML = 'Upload Failed!' - }) + alert(String(err)); + document.querySelector('.__canyon__result').innerHTML = 'Upload Failed!'; + }); }) - document.querySelector('.__canyon__btn_refresh').addEventListener('click', function () { + document.querySelector('.__canyon__btn_refresh').addEventListener('click',function () { document.querySelector('.__canyon__result').innerHTML = 'Please upload coverage' }) + + // 逻辑结束 } } } diff --git a/plugins/inject-popup/test.html b/plugins/inject-popup/test.html index b02b7b4b..23d3cafe 100644 --- a/plugins/inject-popup/test.html +++ b/plugins/inject-popup/test.html @@ -7,13 +7,13 @@