Skip to content

Commit

Permalink
feat(canyon-platform): use swc
Browse files Browse the repository at this point in the history
  • Loading branch information
Allen Zhang (张涛) committed Oct 24, 2024
1 parent cc8eebb commit b6140fb
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 47 deletions.
2 changes: 1 addition & 1 deletion plugins/babel-plugin-canyon/package.json
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>",
"license": "MIT",
Expand Down
6 changes: 4 additions & 2 deletions plugins/babel-plugin-canyon/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}


// 必须校验数据完整性
Expand Down
81 changes: 56 additions & 25 deletions plugins/babel-plugin-canyon/templates/inject-in-page-popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -130,7 +130,7 @@
.__canyon__close-wrap{
display: flex;
justify-content: flex-end;
padding-top: 30px;
padding-top: 45px;
padding-right: 10px
}
.__canyon__close{
Expand All @@ -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__) {
Expand All @@ -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'
})

// 逻辑结束
}
}
}
Expand Down
72 changes: 53 additions & 19 deletions plugins/inject-popup/test.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<style>
.__canyon__modal{
/*display: none;*/
display: none;
position: fixed;
top: 0;
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;
}
Expand Down Expand Up @@ -43,7 +43,7 @@
.__canyon__close-wrap{
display: flex;
justify-content: flex-end;
padding-top: 30px;
padding-top: 45px;
padding-right: 10px
}
.__canyon__close{
Expand Down Expand Up @@ -94,6 +94,14 @@
<div>DSN: </div>
<div style="word-break: break-all" class="canyon-form-value-dsn"></div>
</div>
<div class="__canyon__form_wrap">
<div>Interval Report: </div>
<input type="checkbox" class="canyon-form-value-auto"/>
</div>
<div class="__canyon__form_wrap">
<div>Report ID: </div>
<input style="width: 240px" class="canyon-form-value-reportid" type="text"/>
</div>
<div class="__canyon__form_wrap">
<div>Coverage: </div>
<div class="canyon-form-value-coverage"></div>
Expand Down Expand Up @@ -144,8 +152,10 @@
window.__coverage__ = {
}

const canyon = window.__canyon__
const coverage = window.__coverage__
const globalObj = window

const canyon = globalObj.__canyon__
const coverage = globalObj.__coverage__

// 步骤一:连点5次打开弹窗+检查页面变量合法性
let clickCount = 0;
Expand All @@ -158,16 +168,16 @@
clickTimeout = setTimeout(() => {
// 1秒结束,重置计数
clickCount = 0;
}, 1000);
}, 500);
}

if (clickCount >= 5) {
if (clickCount >= 3) {
// 1秒内点击超过6次,触发弹窗
clearTimeout(clickTimeout); // 清除计时器
clickCount = 0; // 重置计数

// 检查参数
if (window.__canyon__ && window.__coverage__) {
if (globalObj.__canyon__ && globalObj.__coverage__) {
document.querySelector('.__canyon__modal').style.display = 'block'
} else {
alert('window.__canyon__ or window.__coverage__ is not defined')
Expand All @@ -186,30 +196,54 @@
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-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__btn_upload').addEventListener('click', function () {

// 状态置为上传中

document.querySelector('.__canyon__result').innerHTML = 'Uploading...'

fetch(canyon.dsn, {
const uploadPromise = ()=>{
return fetch(canyon.dsn, {
method: 'POST',
body: JSON.stringify({
...canyon,
coverage: window.__coverage__
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) => {
Expand Down

0 comments on commit b6140fb

Please sign in to comment.