zen-app-plugin 0.4.9 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/compress.js +1 -1
- package/package.json +1 -1
package/compress.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(){const e=require("os"),t=require("simple-git")("./"),
|
|
1
|
+
!function(){const e=require("os"),t=(require("simple-git")("./"),require("shelljs")),n=require("pako"),s=new RegExp("(https?:)?//((b|a)\\.(ebus))\\.vip/.+?\\.(svg|js|png|gif|jpe?g|ttf|woff2?|eot|css)","gi"),i=[".js",".css",".svg"],o=[".js",".css",".xml"],c=require("fs"),{join:r,dirname:a,resolve:f,extname:u}=require("path");let l="/";const d=require("cos-nodejs-sdk-v5"),p=require("ali-oss"),{TosClient:g}=require("@volcengine/tos-sdk");let S,y,x,m,h;function O(e){const t=r(e,"package.json"),n=c.readFileSync(t,"utf8");return JSON.parse(n)}function b(e,t){let s={Bucket:x.bucket,Region:x.region,Key:e,StorageClass:"STANDARD"},i=e.indexOf(".js")>-1;i||e.indexOf(".css")>-1?(s.Headers={"Content-Encoding":"gzip","Content-Type":i?"application/javascript":"text/css"},s.Body=Buffer.from(n.gzip(c.readFileSync(t,"utf8")))):s.Body=c.createReadStream(t),y.putObject(s,((t,n)=>{if(t)return console.log(t,n);console.log(l+e)}))}function j(e,t){let s={bucket:x.tosBucket,key:e},i=e.indexOf(".js")>-1;i||e.indexOf(".css")>-1?(s.headers={"Content-Encoding":"gzip","Content-Type":i?"application/javascript":"text/css"},s.body=Buffer.from(n.gzip(c.readFileSync(t,"utf8")))):s.body=c.createReadStream(t),y.putObject(s,((t,n)=>{if(t)return console.log(t,n);console.log(l+e)}))}function w(e,t){let s,i,o=e.indexOf(".js")>-1;o||e.indexOf(".css")>-1?(i={"Content-Encoding":"gzip","Content-Type":o?"application/javascript":"text/css"},s=Buffer.from(n.gzip(c.readFileSync(t,"utf8")))):(s=c.createReadStream(t),i={}),y.put(e,s,{headers:i})}function z(e,t){c.readdirSync(e).forEach((n=>{if(0===n.indexOf(".")||n.indexOf(".html")>-1)return;let s=r(e,n),i=c.statSync(s);if(i.isDirectory()&&z(s,r(t,n)),i.isFile()){let e=r(t,n).replace(/\\/gi,"/");console.log(e),h(e,s)}}))}function k(e){const f=u(e);if(0===e.indexOf(".")||".html"===f)return;let l;if(l=e.indexOf("dist")>-1?S+e.substr(m.length+5):S+e.substr(m.length+7),t.mkdir("-p",a(l)),!i.includes(f))return t.cp(e,l);const d=c.readFileSync(e,"utf8").replace(s,(e=>e.indexOf("'")>-1||e.indexOf('"')>-1?e:function(e){let n=e.substr(e.indexOf(".vip")+4);n.startsWith("/f01")&&(n=n.substr(4));const s=r(S,n),i=u(s);if(!c.existsSync(s)||o.includes(i)){t.mkdir("-p",a(s));const n=e.indexOf(":")>-1?e:`https:${e}`;let i=`wget --timeout=15 -O "${s}" "${n}"`;(s.indexOf(".js")>-1||s.indexOf(".css")>-1)&&(i=`wget -qO- "${n}" | gzip > "${s}"`);const o=t.exec(i);if(0!==o.code)return console.error(`Failed to download ${i}: ${o.stderr}`),e}return n}(e)));c.writeFileSync(l,Buffer.from(n.gzip(d)),"utf8")}function F(e){const t=c.readdirSync(e);for(const n of t){if(n.startsWith("."))continue;const t=r(e,n),s=c.statSync(t);s.isDirectory()?F(t):s.isFile()&&k(t)}}function $(e,t){const n=c.readdirSync(e);for(const s of n){const n=r(e,s);if(c.statSync(n).isDirectory())$(n,t);else if(e.indexOf(".lowcode")>-1&&"data"===s){const e=c.readFileSync(n,"utf8"),{path:s,basic:i,actions:o=[]}=JSON.parse(e);if(!s)continue;const r=[];i.actions.forEach((({_id:e,label:t,mode:n,href:s})=>{const i={id:e+"",label:t};"link"===n&&s&&(i.link=s.substr(1)),r.push(i)})),o.forEach((({_id:e,label:t,mode:n,href:s})=>{const i={id:e+"",label:t};"link"===n&&s&&(i.link=s.substr(1)),r.push(i)})),r.length>0&&(t[s]=r)}}}function v(e){const t={};$(r(e,"src"),t);const n=r(S,"..","points");c.writeFileSync(n,JSON.stringify(t),"utf8")}async function q(){const e=r(S,"..","config","app");c.existsSync(e)||t.mkdir("-p",a(e));try{const t=function(){const e=new Date;return e.getFullYear().toString().slice(-2)+(e.getMonth()+1).toString().padStart(2,"0")+e.getDate().toString().padStart(2,"0")+e.getHours().toString().padStart(2,"0")+e.getMinutes().toString().padStart(2,"0")}();let n={};return c.existsSync(e)&&(n=JSON.parse(c.readFileSync(e,"utf8"))),n["fd"]=t,c.writeFileSync(e,JSON.stringify(n),"utf8"),t}catch(e){return""}}exports.remote=async function(n,s){if(!s)return;m=n,x=JSON.parse(c.readFileSync(r(e.homedir(),".cc.json"))),"tos"===s?(y=new g({accessKeyId:x.tosId,accessKeySecret:x.tosSecret,region:x.tosRegion,endpoint:x.tosEndpoint}),l=x.tosDomain+"/",h=j):"oss"===s?(y=new p({region:x.ossRegion,accessKeyId:x.ossId,accessKeySecret:x.ossSecret,bucket:x.ossBucket,authorizationV4:!0}),l=x.ossDomain+"/",h=w):(y=new d({SecretId:x.id,SecretKey:x.key}),l=x.cosDomain+"/",h=b);let i,o,a=O(n).name;i=r(n,"dist"),o=r(n,"public");["zen.js","zen.css","zen.wap.js","zen.wap.css"].forEach((e=>{const n=`wget --timeout=15 "https://b.ebus.vip/zeto/latest/${e}" -O - | gunzip > "${r(o,e)}"`;console.log(n),t.exec(n)})),S=f(n,"..",a,"src","main","resources","static");const u=await q();v(n),z(i,`${a}/${u}`),c.existsSync(o)&&z(o,`${a}/${u}`)},exports.locale=async function(e){m=e;const n=O(e).name;S=f(e,"..",n,"src","main","resources","static"),v(e),await q();const s=r(e,"public"),i=r(e,"dist");["zen.js","zen.css","zen.wap.js","zen.wap.css"].forEach((e=>{const n=`wget --timeout=15 "https://b.ebus.vip/zeto/latest/${e}" -O - | gunzip > "${r(s,e)}"`;console.log(n),t.exec(n)})),F(i),c.existsSync(s)&&F(s)}}();
|