Comparing version 0.0.8 to 0.0.9
@@ -1,1 +0,1 @@ | ||
"use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}var t=e(require("@babel/runtime/helpers/defineProperty")),r=e(require("path")),n=e(require("co")),o=e(require("chalk")),i=e(require("glob")),s=e(require("@babel/parser")),c=e(require("@babel/traverse")),l=e(require("@babel/generator")),u=e(require("fs-extra")),a=e(require("recursive-copy")),f=e(require("mkdirp")),d=e(require("vfile")),m=e(require("tma-code-audit")),g=e(require("@babel/types")),p=e(require("lodash")),y=e(require("unified")),w=e(require("dependency-graph")),b=e(require("stricter-htmlparser2"));let O=1;const h={info:[],warning:[],error:[],success:[]},j={info(e){h.info.push(e)},warning(e){h.warning.push(e)},error(e){h.error.push(e)},success(e){h.success.push(e)},underline(e){h.success.push(e)}};var x={logStore:h,logger:function(e,t){!function(e,t){if("error"!==t)return;e.row&&console.log(o.keyword("orange")(`☠️ ${O++} ${o.redBright("[ERROR]:")} ${e.file}:----row:${e.row}-column:${e.column}:`)),console.log(o.redBright(` ${e.message}`)),console.log("--------------------------------------------------------")}(e,t),function(e,t){if("warning"!==t)return;e.row&&console.log(o.keyword("orange")(`⚡ ${o.yellow("[WARNING]:")} ${e.file}:----row:${e.row}-column:${e.column}:`)),console.log(o.yellow(` ${e.message}`)),console.log("--------------------------------------------------------")}(e,t),j[t](e)},saveLog:function(e){let t=[];Object.keys(h).forEach(e=>{t=t.concat(h[e])}),E.saveLog(`${e}/log.txt`,JSON.stringify(t,null,4))},emptyLog:function(){h.info=[],h.warning=[],h.error=[],h.success=[]}};function $(e){return/wxml/.test(e)?(x.logger({time:new Date,type:"transform wxml file suffix",file:e,message:"转换了视图文件后缀, wxml ==> ttml"},"info"),e.replace(/wxml$/,"ttml")):/wxss/.test(e)?(x.logger({time:new Date,type:"transform wxss file suffix",file:e,message:"转换了样式文件后缀, wxss ==> ttss"},"info"),e.replace(/wxss$/,"ttss")):e}function D(e){return!r.extname(e)}function P(e,t="info",r=!1){r?x.logger({time:new Date,type:"stdOut",message:e},t):"underline"===t?console.log(o.blue.underline.bold(e)):console.log(o[S[t]](e))}const S={info:"cyan",error:"red",success:"green",warning:"yellow"},v={1128:"抖音",13:"今日头条",35:"今日头条极速版"};var E={ttmlFileSuffix:"ttml",ttssFileSuffix:"ttss",copyProject:function(e,t){return D(e)?function(e,t){const n=u.readdirSync(e).filter((function(e){return!/(node_modules|DS_store)/i.test(e)})),o={overwrite:!0,expand:!0,dot:!0,rename:e=>$(e)},i=[];for(let s=0;s<n.length;s++)i.push(a(r.join(e,n[s]),r.join(t,n[s].replace(/wxml$/,"ttml").replace(/wxss$/,"ttss")),o));return Promise.all(i)}(e,t):function(e,t){try{let n=r.basename(e);return D(t)&&(n=$(n),t=r.join(t,n)),u.copy(e,t)}catch(e){console.error("copyFile error:",e)}}(e,t)},isDirectory:D,getContent:function(e){return new Promise((function(t){u.readFile(e,(function(e,r){t(r.toString())}))}))},getContentSync:function(e){return u.readFileSync(e).toString()},saveFile:function(e,t){return new Promise((r,n)=>{u.writeFile(e,t,e=>{e?n(e):r(!0)})})},saveLog:function(e,t){return new Promise((n,o)=>{f(r.dirname(e),r=>{r?o(r):u.writeFileSync(e,t)})})},object2String:function(e){const t=[];return JSON.stringify(e,(function(e,r){if("object"==typeof r&&null!==r){if(-1!==t.indexOf(r))return;t.push(r)}return r}),2)},toVFile:function(e,t){const n=d({path:e,contents:t}),o={style:"ttss",view:"ttml",js:"js",config:"json"},{cwd:i,dirname:s,stem:c,extname:l}=n;return n.data.relatedFiles=Object.keys(o).reduce((e,t)=>{const n=`.${o[t]}`;if(n!==l){const o=r.resolve(i,s,c+n);u.existsSync(o)&&(e[t]=o)}return e},{}),n},isObject:function(e){return null!=e&&"object"==typeof e&&!1===Array.isArray(e)},getDefaultDist:function(e){let t="";return t=D(e)?r.join(r.dirname(e),r.basename(e)+"_tt"):r.join(r.dirname(e)+"_tt",r.basename(e)),t},stdOut:P,auditCode:function*(e){try{const t=m,r=e.dist,n=yield t(r);Object.keys(n).forEach(t=>{const r=t.startsWith("$")?t.slice(1):t;P(`⚡ [warning]${t.startsWith("$")?"组件":"API"} "${r}" 在宿主-- ${n[t].map(e=>v[e]).join(", ")} --中不支持`,"warning",e.isIDE)})}catch(t){P(`audit code error: ${t.message}`,"error",e.isIDE)}}},F={ctx:{wx:"tt"}};const k=c.default||c,q=l.default||l;function C(e,t,r,n,o,i){try{const t=s.parse(e,{sourceType:"module",plugins:["*"]});return k(t,{enter(e){!function(e,t,r,n){if(g.isIdentifier(e.node,{name:r})){const o=e.node;e.replaceWithSourceString(n[r]),x.logger({time:new Date,type:"transform function call arg name",file:t,row:o.loc.start.line,column:o.loc.start.column,before:r,after:n[r],message:"转换了上下文, wx ==> tt"},"info")}}(e,o,r,n)}}),q(t,{}).code}catch(e){throw E.stdOut(`⛔ transfrom js file ${o} error: ${e}`,"error",i.isIDE),new Error(`⛔ transfrom js file ${o} error: ${e}`)}}var I=function*(e){try{const t=yield new Promise(t=>{let n=e.dist;E.isDirectory(n)&&(n+="/**/*.js"),".js"===r.extname(n)?i(n,{ignore:["**/node_modules/**/*.js"]},(function(e,r){t(e?[]:r)})):t([])}),n=F,o="wx",s=n.ctx;let c;for(let r=0;r<t.length;r++){c=yield E.getContent(t[r]);const i=C(c,n,o,s,t[r],e);yield E.saveFile(t[r],i)}E.stdOut("🍻 Successfully transform js file","info",e.isIDE)}catch(t){E.stdOut("⛔ Something error when transforming js file","error",e.isIDE)}};const{Parser:A,DomHandler:N}=b;var R={fakeRoot:Symbol("fake-root"),getHtmlParser:function(e){e=e||{xmlMode:!1,lowerCaseAttributeNames:!1,recognizeSelfClosing:!0,lowerCaseTags:!1};const t=new N;return{htmlParser:new A(t,e),handler:t}}};const{fakeRoot:L,getHtmlParser:T}=R;var W=function(e){e=e||{xmlMode:!1,lowerCaseAttributeNames:!1,recognizeSelfClosing:!0,lowerCaseTags:!1},this.Parser=function(t){const{htmlParser:r,handler:n}=T(e);return r.end(t),{type:"tag",name:L,attribs:{},children:p.isArray(n.dom)?n.dom:[n.dom]}}};const _=R.fakeRoot,H=(...e)=>e.filter(e=>!!e).join(" ");var Q=function(e={}){this.Compiler=function e(t,r){if(!t)return"";if(Array.isArray(t))return t.map(t=>e(t,r)).join("");const{type:n,children:o,data:i}=t;switch(n){case"tag":{if(t.name===_)return e(o,r);const n=o.map(t=>e(t,r)).join("");return function(e,t,r){const{name:n,attribs:o,singleQuoteAttribs:i={},selfclose:s}=e,c=function(e,t,r){if(!e)return"";return Object.keys(e).map(n=>{let o=e[n];if(""===o)return n;const i=t[n]?"'":'"';return'"'===i&&o.indexOf('\\"')>=0&&(o=o.replace(/\\"/g,"'"),r.message('Danger \\" in attribute value')),""!==n?`${n}=${i}${o}${i}`:`${n}`}).join(" ")}(o,i,r);return s?`<${H(n,c)} />`:`<${H(n,c)}>${t}</${n}>`}(t,n,r)}case"text":return i;case"comment":return`\x3c!--${i}--\x3e`}}};function z(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function B(e){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?z(Object(n),!0).forEach((function(r){t(e,r,n[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):z(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}const G=E.ttmlFileSuffix;var J=function(e={}){return function(e,t){!function e(t,r){if(p.isArray(t))return t.map(t=>e(t));if("tag"===t.type){const{name:r,children:n}=t;"import"!==r&&"include"!==r||(t=function(e,t,r){const n=e.attribs;if(n&&n.src){let t=n.src.replace(/\.wxml$/i,`.${G}`);return/\w+\.\w+$/.test(t)||(t+=`.${G}`),B({},e,{attribs:B({},n,{src:t})})}return e}(t)),t.children=n.map(t=>e(t)),t=function(e,t,r){const{attribs:n,singleQuoteAttribs:o={}}=e;if(!n)return e;const i=Object.keys(n).reduce((e,t)=>{let r=t.replace(/^wx:$/,"").replace(/^wx:/,"tt:");let o=n[t];return e[r]=o,e},{});return B({},e,{attribs:i,singleQuoteAttribs:Object.keys(o).reduce((e,t)=>B({},e,{[t.replace(/^wx:/,"s-")]:o[t]}),{})})}(t)}"comment"===t.type&&(t=function(e,t,r){const n=e.data;if(n){let t=n.replace(/\.wxml$/i,`.${G}`);return B({},e,{data:t})}return e}(t));return t}(e)}};function M(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}const V=w.DepGraph,K=R.getHtmlParser;function U(e,t,r){try{return y().use(W).use(J,{context:r}).use(Q).process(E.toVFile(e,t))}catch(t){throw E.stdOut(`⛔ transfrom ttml file ${e} error: ${t}`,"error",r.isIDE),new Error(`⛔ transfrom ttml file ${e} error: ${t}`)}}var X=function*(e){try{const n=yield new Promise(t=>{let n=e.dist;E.isDirectory(n)&&(n+=`/**/*.${E.ttmlFileSuffix}`),r.extname(n)===`.${E.ttmlFileSuffix}`?i(n,(function(e,r){t(e?[]:r)})):t([])});e.data.ttmlRenamedComponents=function(e,n){const{htmlParser:o,handler:i}=K(),s=e.reduce((e,t)=>(e.addNode(t),o.end(E.getContentSync(t)),function e(t,n,o){if(!p.isArray(t)){const{type:i,name:s,attribs:c,children:l=[]}=t;if("tag"===i&&("import"===s||"include"===s)&&c.src){let e=r.resolve(r.dirname(o),c.src);e=e.replace(/\.wxml/,`.${E.ttmlFileSuffix}`),e=e.endsWith(`.${E.ttmlFileSuffix}`)?e:`${e}.${E.ttmlFileSuffix}`,n.addNode(e),n.addDependency(o,e)}return void e(l,n,o)}t.forEach(t=>e(t,n,o))}(i.dom,e,t),o.reset(),e),new V);return Object.keys(n.data.renamedComponents||{}).map(e=>e.replace(/\.json$/,`.${E.ttmlFileSuffix}`)).filter(e=>s.hasNode(e)).map(e=>({file:e,deps:s.dependenciesOf(e)})).reduce((e,{file:r,deps:o})=>{const i=r.replace(new RegExp(`.${E.ttmlFileSuffix}`),".json"),s=n.data.renamedComponents[i]||{};return o.forEach(r=>e[r]=e[r]?function(e){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?M(Object(n),!0).forEach((function(r){t(e,r,n[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):M(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}({},e[r],{},s):s),e[r]=s,e},{})}(n,e);for(let t=0;t<n.length;t++){const r=yield E.getContent(n[t]),o=yield U(n[t],r,e);yield E.saveFile(n[t],String(o))}E.stdOut("🍻 Successfully transform wxml file","info",e.isIDE)}catch(t){E.stdOut("⛔ Something error when transforming wxml file","error",e.isIDE)}};function Y(e){return e.replace(/\.wxss/gi,`.${E.ttssFileSuffix}`)}var Z=function*(e){const t=yield new Promise(t=>{let n=e.dist;const o=E.ttssFileSuffix;E.isDirectory(n)&&(n=n+"/**/*."+o),r.extname(n)==="."+o?i(n,(function(e,r){t(e?[]:r)})):t([])});let n;for(let e=0;e<t.length;e++)n=yield E.getContent(t[e]),n=Y(n),yield E.saveFile(t[e],n);E.stdOut("🍻 Successfully transform wxss file","info",e.isIDE)};function ee(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}module.exports=function(e,o){if(!e.src)return void E.stdOut("⛔ argument options.src is required","error",e.isIDE);e.dist=e.dist||E.getDefaultDist(e.src);let i=e.dist||e.src;E.isDirectory(i)||(i=r.dirname(i)),e.log=e.log||i,e.isIDE=e.isIDE||!1;const s=function(e){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?ee(Object(n),!0).forEach((function(r){t(e,r,n[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):ee(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}({},e,{logs:[],data:{}});return x.emptyLog(),E.stdOut("🛠️ Transform source project...","info",e.isIDE),n((function*(){yield E.copyProject(e.src,e.dist),yield I(s),yield X(s),yield Z(s),yield E.auditCode(s)})).then((function(){E.stdOut("🎊 Congratulations, transform done! Please check transform log in","success",e.isIDE),E.stdOut("📝 "+r.resolve(e.log,"log.txt"),"underline",e.isIDE),x.saveLog(e.log),o&&o(null,x.logStore)})).catch((function(t){E.stdOut(`😱 Transform error: ${t}`,"error",e.isIDE),x.saveLog(e.log),o&&o(t)})),x.logStore}; | ||
"use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}var t=e(require("@babel/runtime/helpers/defineProperty")),r=e(require("path")),n=e(require("co")),o=e(require("chalk")),i=e(require("glob")),s=e(require("@babel/parser")),c=e(require("@babel/traverse")),l=e(require("@babel/generator")),u=e(require("fs-extra")),a=e(require("recursive-copy")),f=e(require("mkdirp")),d=e(require("vfile")),m=e(require("tma-code-audit")),g=e(require("@babel/types")),p=e(require("lodash")),y=e(require("unified")),w=e(require("dependency-graph")),b=e(require("stricter-htmlparser2"));let O=1;const h={info:[],warning:[],error:[],success:[]},j={info(e){h.info.push(e)},warning(e){h.warning.push(e)},error(e){h.error.push(e)},success(e){h.success.push(e)},underline(e){h.success.push(e)}};var x={logStore:h,logger:function(e,t){!function(e,t){if("error"!==t)return;e.row&&console.log(o.keyword("orange")(`☠️ ${O++} ${o.redBright("[ERROR]:")} ${e.file}:----row:${e.row}-column:${e.column}:`)),console.log(o.redBright(` ${e.message}`)),console.log("--------------------------------------------------------")}(e,t),function(e,t){if("warning"!==t)return;e.row&&console.log(o.keyword("orange")(`⚡ ${o.yellow("[WARNING]:")} ${e.file}:----row:${e.row}-column:${e.column}:`)),console.log(o.yellow(` ${e.message}`)),console.log("--------------------------------------------------------")}(e,t),j[t](e)},saveLog:function(e){let t=[];Object.keys(h).forEach(e=>{t=t.concat(h[e])}),E.saveLog(`${e}/log.txt`,JSON.stringify(t,null,4))},emptyLog:function(){h.info=[],h.warning=[],h.error=[],h.success=[]}};function $(e){return/wxml/.test(e)?(x.logger({time:new Date,type:"transform wxml file suffix",file:e,message:"转换了视图文件后缀, wxml ==> ttml"},"info"),e.replace(/wxml$/,"ttml")):/wxss/.test(e)?(x.logger({time:new Date,type:"transform wxss file suffix",file:e,message:"转换了样式文件后缀, wxss ==> ttss"},"info"),e.replace(/wxss$/,"ttss")):e}function D(e){return!r.extname(e)}function P(e,t="info",r=!1){r?x.logger({time:new Date,type:"stdOut",message:e},t):"underline"===t?console.log(o.blue.underline.bold(e)):console.log(o[S[t]](e))}const S={info:"cyan",error:"red",success:"green",warning:"yellow"},v={1128:"抖音",13:"今日头条",35:"今日头条极速版"};var E={ttmlFileSuffix:"ttml",ttssFileSuffix:"ttss",copyProject:function(e,t){return D(e)?function(e,t){const n=u.readdirSync(e).filter((function(e){return!/(node_modules|DS_store)/i.test(e)})),o={overwrite:!0,expand:!0,dot:!0,rename:e=>$(e)},i=[];for(let s=0;s<n.length;s++)i.push(a(r.join(e,n[s]),r.join(t,n[s].replace(/wxml$/,"ttml").replace(/wxss$/,"ttss")),o));return Promise.all(i)}(e,t):function(e,t){try{let n=r.basename(e);return D(t)&&(n=$(n),t=r.join(t,n)),u.copy(e,t)}catch(e){console.error("copyFile error:",e)}}(e,t)},isDirectory:D,getContent:function(e){return new Promise((function(t){u.readFile(e,(function(e,r){t(r.toString())}))}))},getContentSync:function(e){return u.readFileSync(e).toString()},saveFile:function(e,t){return new Promise((r,n)=>{u.writeFile(e,t,e=>{e?n(e):r(!0)})})},saveLog:function(e,t){return new Promise((n,o)=>{f(r.dirname(e),r=>{r?o(r):u.writeFileSync(e,t)})})},object2String:function(e){const t=[];return JSON.stringify(e,(function(e,r){if("object"==typeof r&&null!==r){if(-1!==t.indexOf(r))return;t.push(r)}return r}),2)},toVFile:function(e,t){const n=d({path:e,contents:t}),o={style:"ttss",view:"ttml",js:"js",config:"json"},{cwd:i,dirname:s,stem:c,extname:l}=n;return n.data.relatedFiles=Object.keys(o).reduce((e,t)=>{const n=`.${o[t]}`;if(n!==l){const o=r.resolve(i,s,c+n);u.existsSync(o)&&(e[t]=o)}return e},{}),n},isObject:function(e){return null!=e&&"object"==typeof e&&!1===Array.isArray(e)},getDefaultDist:function(e){let t="";return t=D(e)?r.join(r.dirname(e),r.basename(e)+"_tt"):r.join(r.dirname(e)+"_tt",r.basename(e)),t},stdOut:P,auditCode:function*(e){try{const t=m,r=e.dist,n=yield t(r);Object.keys(n).forEach(t=>{const r=t.startsWith("$")?t.slice(1):t;P(`⚡ [warning]${t.startsWith("$")?"组件":"API"} "${r}" 在宿主-- ${n[t].map(e=>v[e]).join(", ")} --中不支持`,"warning",e.isIDE)})}catch(t){P(`audit code error: ${t.message}`,"error",e.isIDE)}}},F={ctx:{wx:"tt"}};const k=c.default||c,q=l.default||l;function C(e,t,r,n,o,i){try{const t=s.parse(e,{sourceType:"module",plugins:["*"]});return k(t,{enter(e){!function(e,t,r,n){if(g.isIdentifier(e.node,{name:r})){const o=e.node;e.replaceWithSourceString(n[r]),x.logger({time:new Date,type:"transform function call arg name",file:t,row:o.loc.start.line,column:o.loc.start.column,before:r,after:n[r],message:"转换了上下文, wx ==> tt"},"info")}}(e,o,r,n)}}),q(t,{}).code}catch(e){throw E.stdOut(`⛔ transfrom js file ${o} error: ${e}`,"error",i.isIDE),new Error(`⛔ transfrom js file ${o} error: ${e}`)}}var I=function*(e){try{const t=yield new Promise(t=>{let n=e.dist;E.isDirectory(n)&&(n+="/**/*.js"),".js"===r.extname(n)?i(n,{ignore:["**/node_modules/**/*.js","**/*.ttpkg.js"]},(function(e,r){t(e?[]:r)})):t([])}),n=F,o="wx",s=n.ctx;let c;for(let r=0;r<t.length;r++){c=yield E.getContent(t[r]);const i=C(c,n,o,s,t[r],e);yield E.saveFile(t[r],i)}E.stdOut("🍻 Successfully transform js file","info",e.isIDE)}catch(t){E.stdOut("⛔ Something error when transforming js file","error",e.isIDE)}};const{Parser:A,DomHandler:N}=b;var R={fakeRoot:Symbol("fake-root"),getHtmlParser:function(e){e=e||{xmlMode:!1,lowerCaseAttributeNames:!1,recognizeSelfClosing:!0,lowerCaseTags:!1};const t=new N;return{htmlParser:new A(t,e),handler:t}}};const{fakeRoot:L,getHtmlParser:T}=R;var W=function(e){e=e||{xmlMode:!1,lowerCaseAttributeNames:!1,recognizeSelfClosing:!0,lowerCaseTags:!1},this.Parser=function(t){const{htmlParser:r,handler:n}=T(e);return r.end(t),{type:"tag",name:L,attribs:{},children:p.isArray(n.dom)?n.dom:[n.dom]}}};const _=R.fakeRoot,H=(...e)=>e.filter(e=>!!e).join(" ");var Q=function(e={}){this.Compiler=function e(t,r){if(!t)return"";if(Array.isArray(t))return t.map(t=>e(t,r)).join("");const{type:n,children:o,data:i}=t;switch(n){case"tag":{if(t.name===_)return e(o,r);const n=o.map(t=>e(t,r)).join("");return function(e,t,r){const{name:n,attribs:o,singleQuoteAttribs:i={},selfclose:s}=e,c=function(e,t,r){if(!e)return"";return Object.keys(e).map(n=>{let o=e[n];if(""===o)return n;const i=t[n]?"'":'"';return'"'===i&&o.indexOf('\\"')>=0&&(o=o.replace(/\\"/g,"'"),r.message('Danger \\" in attribute value')),""!==n?`${n}=${i}${o}${i}`:`${n}`}).join(" ")}(o,i,r);return s?`<${H(n,c)} />`:`<${H(n,c)}>${t}</${n}>`}(t,n,r)}case"text":return i;case"comment":return`\x3c!--${i}--\x3e`}}};function z(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function B(e){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?z(Object(n),!0).forEach((function(r){t(e,r,n[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):z(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}const G=E.ttmlFileSuffix;var J=function(e={}){return function(e,t){!function e(t,r){if(p.isArray(t))return t.map(t=>e(t));if("tag"===t.type){const{name:r,children:n}=t;"import"!==r&&"include"!==r||(t=function(e,t,r){const n=e.attribs;if(n&&n.src){let t=n.src.replace(/\.wxml$/i,`.${G}`);return/\w+\.\w+$/.test(t)||(t+=`.${G}`),B({},e,{attribs:B({},n,{src:t})})}return e}(t)),t.children=n.map(t=>e(t)),t=function(e,t,r){const{attribs:n,singleQuoteAttribs:o={}}=e;if(!n)return e;const i=Object.keys(n).reduce((e,t)=>{let r=t.replace(/^wx:$/,"").replace(/^wx:/,"tt:");let o=n[t];return e[r]=o,e},{});return B({},e,{attribs:i,singleQuoteAttribs:Object.keys(o).reduce((e,t)=>B({},e,{[t.replace(/^wx:/,"s-")]:o[t]}),{})})}(t)}"comment"===t.type&&(t=function(e,t,r){const n=e.data;if(n){let t=n.replace(/\.wxml$/i,`.${G}`);return B({},e,{data:t})}return e}(t));return t}(e)}};function M(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}const V=w.DepGraph,K=R.getHtmlParser;function U(e,t,r){try{return y().use(W).use(J,{context:r}).use(Q).process(E.toVFile(e,t))}catch(t){throw E.stdOut(`⛔ transfrom ttml file ${e} error: ${t}`,"error",r.isIDE),new Error(`⛔ transfrom ttml file ${e} error: ${t}`)}}var X=function*(e){try{const n=yield new Promise(t=>{let n=e.dist;E.isDirectory(n)&&(n+=`/**/*.${E.ttmlFileSuffix}`),r.extname(n)===`.${E.ttmlFileSuffix}`?i(n,(function(e,r){t(e?[]:r)})):t([])});e.data.ttmlRenamedComponents=function(e,n){const{htmlParser:o,handler:i}=K(),s=e.reduce((e,t)=>(e.addNode(t),o.end(E.getContentSync(t)),function e(t,n,o){if(!p.isArray(t)){const{type:i,name:s,attribs:c,children:l=[]}=t;if("tag"===i&&("import"===s||"include"===s)&&c.src){let e=r.resolve(r.dirname(o),c.src);e=e.replace(/\.wxml/,`.${E.ttmlFileSuffix}`),e=e.endsWith(`.${E.ttmlFileSuffix}`)?e:`${e}.${E.ttmlFileSuffix}`,n.addNode(e),n.addDependency(o,e)}return void e(l,n,o)}t.forEach(t=>e(t,n,o))}(i.dom,e,t),o.reset(),e),new V);return Object.keys(n.data.renamedComponents||{}).map(e=>e.replace(/\.json$/,`.${E.ttmlFileSuffix}`)).filter(e=>s.hasNode(e)).map(e=>({file:e,deps:s.dependenciesOf(e)})).reduce((e,{file:r,deps:o})=>{const i=r.replace(new RegExp(`.${E.ttmlFileSuffix}`),".json"),s=n.data.renamedComponents[i]||{};return o.forEach(r=>e[r]=e[r]?function(e){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?M(Object(n),!0).forEach((function(r){t(e,r,n[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):M(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}({},e[r],{},s):s),e[r]=s,e},{})}(n,e);for(let t=0;t<n.length;t++){const r=yield E.getContent(n[t]),o=yield U(n[t],r,e);yield E.saveFile(n[t],String(o))}E.stdOut("🍻 Successfully transform wxml file","info",e.isIDE)}catch(t){E.stdOut("⛔ Something error when transforming wxml file","error",e.isIDE)}};function Y(e){return e.replace(/\.wxss/gi,`.${E.ttssFileSuffix}`)}var Z=function*(e){const t=yield new Promise(t=>{let n=e.dist;const o=E.ttssFileSuffix;E.isDirectory(n)&&(n=n+"/**/*."+o),r.extname(n)==="."+o?i(n,(function(e,r){t(e?[]:r)})):t([])});let n;for(let e=0;e<t.length;e++)n=yield E.getContent(t[e]),n=Y(n),yield E.saveFile(t[e],n);E.stdOut("🍻 Successfully transform wxss file","info",e.isIDE)};function ee(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}module.exports=function(e,o){if(!e.src)return void E.stdOut("⛔ argument options.src is required","error",e.isIDE);e.dist=e.dist||E.getDefaultDist(e.src);let i=e.dist||e.src;E.isDirectory(i)||(i=r.dirname(i)),e.log=e.log||i,e.isIDE=e.isIDE||!1;const s=function(e){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?ee(Object(n),!0).forEach((function(r){t(e,r,n[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):ee(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}({},e,{logs:[],data:{}});return x.emptyLog(),E.stdOut("🛠️ Transform source project...","info",e.isIDE),n((function*(){yield E.copyProject(e.src,e.dist),yield I(s),yield X(s),yield Z(s),yield E.auditCode(s)})).then((function(){E.stdOut("🎊 Congratulations, transform done! Please check transform log in","success",e.isIDE),E.stdOut("📝 "+r.resolve(e.log,"log.txt"),"underline",e.isIDE),x.saveLog(e.log),o&&o(null,x.logStore)})).catch((function(t){E.stdOut(`😱 Transform error: ${t}`,"error",e.isIDE),x.saveLog(e.log),o&&o(t)})),x.logStore}; |
{ | ||
"name": "wx-to-tt", | ||
"version": "0.0.8", | ||
"version": "0.0.9", | ||
"description": "transform wx micro app to bytedance micro app", | ||
@@ -5,0 +5,0 @@ "main": "dest/index.js", |
17057