feat: add inject script in github workflow

pull/49/head
moonrailgun 3 years ago
parent 43c5c04056
commit f51d6e6a41

@ -12,6 +12,8 @@ jobs:
steps:
- name: checkout
uses: actions/checkout@v2
- name: Inject Analytics
run: node ./web/build/inject-analytics.js
- name: Deploy Prod
uses: amondnet/vercel-action@master
env:

@ -0,0 +1,20 @@
/**
* 注入 nightly 分析脚本
*
* 请确保该脚本仅在nightly环境下生效
*/
const fs = require('fs');
const path = require('path');
const templatePath = path.resolve(__dirname, '../assets/template.html');
const script = `<script type="text/javascript">(function (w) {w.frontjsConfig={token:"acd42b4b4e2b2a9fa33b36e9cd60e866",behaviour:15,captureConsoleLog:true,trustVendor:true,ignoreVendor:true,optimisedForSPA:true,useHistory:true,FPSThreshold:10};w.frontjsTmpData = {r:[],e:[],l:[]};w.frontjsTmpCollector = function (ev) {(ev.message ? window.frontjsTmpData.e : window.frontjsTmpData.r).push([new Date().getTime(), ev])};w.FrontJS = {addEventListener: function (t, f) {w.frontjsTmpData.l.push([t, f]);return f;},removeEventListener: function (t, f) {for (var i = 0; i < w.frontjsTmpData.l.length; i++) {t === w.frontjsTmpData.l[i][0] && f === w.frontjsTmpData.l[i][1] && w.frontjsTmpData.l.splice(i, 1);}return f;}};w.document.addEventListener("error", w.frontjsTmpCollector, true);w.addEventListener("error", w.frontjsTmpCollector, true);w.addEventListener("load", function () {var n = w.document.createElement("script");n.src = "https://frontjs-static.pgyer.com/dist/current/frontjs.web.min.js"; w.document.body.appendChild(n);}, true);})(window);</script>`;
console.log('templatePath', templatePath);
let template = fs.readFileSync(templatePath, {
encoding: 'utf-8',
});
template = template.replace('</head>', script + '</head>');
fs.writeFileSync(templatePath, template);
Loading…
Cancel
Save