Comparing version 0.0.3 to 0.0.4
@@ -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")),a=e(require("fs-extra")),u=e(require("recursive-copy")),f=e(require("mkdirp")),m=e(require("vfile")),d=e(require("@babel/types")),p=e(require("lodash")),g=e(require("unified")),y=e(require("dependency-graph")),b=e(require("stricter-htmlparser2"));let w=1;const j={info:[],warning:[],error:[]},O={info(e){j.info.push(e)},warning(e){j.warning.push(e)},error(e){j.error.push(e)}};var x=function(e,t){!function(e,t){if("error"!==t)return;console.log(o.keyword("orange")(`☠️ ${w++} ${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;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),O[t](e)},h=function(e){let t=[];Object.keys(j).forEach(e=>{t=t.concat(j[e])}),S.saveLog(`${e}/log.txt`,JSON.stringify(t,null,4))};function $(e){return/wxml/.test(e)?(x({time:new Date,type:"transform wxml file suffix",file:e,message:"转换了视图文件后缀, wxml ==> ttml"},"info"),e.replace(/wxml$/,"ttml")):/wxss/.test(e)?(x({time:new Date,type:"transform wxss file suffix",file:e,message:"转换了样式文件后缀, wxss ==> ttss"},"info"),e.replace(/wxss$/,"ttss")):e}function P(e){return!r.extname(e)}var S={ttmlFileSuffix:"ttml",ttssFileSuffix:"ttss",copyProject:function(e,t){return P(e)?function(e,t){const n=a.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(u(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 P(t)&&(n=$(n),t=r.join(t,n)),a.copy(e,t)}catch(e){console.error("copyFile error:",e)}}(e,t)},isDirectory:P,getContent:function(e){return new Promise((function(t){a.readFile(e,(function(e,r){t(r.toString())}))}))},getContentSync:function(e){return a.readFileSync(e).toString()},saveFile:function(e,t){return new Promise((r,n)=>{a.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):a.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=m({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);a.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=P(e)?r.join(r.dirname(e),r.basename(e)+"_tt"):r.join(r.dirname(e)+"_tt",r.basename(e)),t}},v={ctx:{wx:"tt"}};const D=c.default||c,F=l.default||l;function k(e,t,r,n,o){const i=s.parse(e,{sourceType:"module",plugins:["*"]});return D(i,{enter(e){!function(e,t,r,n){if(d.isIdentifier(e.node,{name:r})){const o=e.node;e.replaceWithSourceString(n[r]),x({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)}}),F(i,{}).code}var q=function*(e){const t=yield new Promise(t=>{let n=e.dist;S.isDirectory(n)&&(n+="/**/*.js"),".js"===r.extname(n)?i(n,{ignore:"**/node_modules/**/*.js"},(function(e,r){t(e?[]:r)})):t([])}),n=v,s=n.ctx;let c;for(let e=0;e<t.length;e++){c=yield S.getContent(t[e]);const r=k(c,n,"wx",s,t[e]);yield S.saveFile(t[e],r)}console.log(o.cyan("🍻 Successfully transform js file"))};const{Parser:C,DomHandler:A}=b;var E={fakeRoot:Symbol("fake-root"),getHtmlParser:function(e){e=e||{xmlMode:!1,lowerCaseAttributeNames:!1,recognizeSelfClosing:!0,lowerCaseTags:!1};const t=new A;return{htmlParser:new C(t,e),handler:t}}};const{fakeRoot:N,getHtmlParser:R}=E;var T=function(e){e=e||{xmlMode:!1,lowerCaseAttributeNames:!1,recognizeSelfClosing:!0,lowerCaseTags:!1},this.Parser=function(t){const{htmlParser:r,handler:n}=R(e);return r.end(t),{type:"tag",name:N,attribs:{},children:p.isArray(n.dom)?n.dom:[n.dom]}}};const _=E.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 W(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 z(e){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?W(Object(n),!0).forEach((function(r){t(e,r,n[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):W(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}const B=S.ttmlFileSuffix;var G=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,`.${B}`);return/\w+\.\w+$/.test(t)||(t+=`.${B}`),z({},e,{attribs:z({},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 z({},e,{attribs:i,singleQuoteAttribs:Object.keys(o).reduce((e,t)=>z({},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,`.${B}`);return z({},e,{data:t})}return e}(t));return t}(e)}};function I(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 J=y.DepGraph,L=E.getHtmlParser;function M(e,t,r){return g().use(T).use(G,{context:r}).use(Q).process(S.toVFile(e,t))}var V=function*(e){const n=yield new Promise(t=>{let n=e.dist;S.isDirectory(n)&&(n+=`/**/*.${S.ttmlFileSuffix}`),r.extname(n)===`.${S.ttmlFileSuffix}`?i(n,(function(e,r){t(e?[]:r)})):t([])});e.data.ttmlRenamedComponents=function(e,n){const{htmlParser:o,handler:i}=L(),s=e.reduce((e,t)=>(e.addNode(t),o.end(S.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/,`.${S.ttmlFileSuffix}`),e=e.endsWith(`.${S.ttmlFileSuffix}`)?e:`${e}.${S.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 J);return Object.keys(n.data.renamedComponents||{}).map(e=>e.replace(/\.json$/,`.${S.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(`.${S.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?I(Object(n),!0).forEach((function(r){t(e,r,n[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):I(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 S.getContent(n[t]),o=yield M(n[t],r,e);yield S.saveFile(n[t],String(o))}console.log(o.cyan("🍻 Successfully transform wxml file"))};function K(e){return e.replace(/\.wxss/gi,`.${S.ttssFileSuffix}`)}var U=function*(e){const t=yield new Promise(t=>{let n=e.dist;const o=S.ttssFileSuffix;S.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 S.getContent(t[e]),n=K(n),yield S.saveFile(t[e],n);console.log(o.cyan("🍻 Successfully transform wxss file"))};function X(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,i){if(!e.src)return void console.log(o.red("⛔ argument options.src is required"));e.dist=e.dist||S.getDefaultDist(e.src);let s=e.dist||e.src;S.isDirectory(s)||(s=r.dirname(s)),e.log=e.log||s;const c=function(e){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?X(Object(n),!0).forEach((function(r){t(e,r,n[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):X(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}({},e,{logs:[],data:{}});console.log(o.blue("🛠️ Transform source project...")),n((function*(){yield S.copyProject(e.src,e.dist),yield q(c),yield V(c),yield U(c)})).then((function(){h(e.log),i&&i(null),console.log(o.green("🎊 Congratulations, transform done! Please check transform log in")),console.log(o.blue.underline.bold(r.dirname(e.log)+"/log.txt"))})).catch((function(e){i&&i(e),console.log(o.red("😱 Transform error:",e))}))}; | ||
"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")),p=e(require("@babel/types")),y=e(require("lodash")),g=e(require("unified")),w=e(require("dependency-graph")),b=e(require("stricter-htmlparser2"));let O=1;const j={info:[],warning:[],error:[],success:[]},h={info(e){j.info.push(e)},warning(e){j.warning.push(e)},error(e){j.error.push(e)},success(e){j.success.push(e)},underline(e){j.success.push(e)}};var x=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),h[t](e)},$=function(e){let t=[];Object.keys(j).forEach(e=>{t=t.concat(j[e])}),F.saveLog(`${e}/log.txt`,JSON.stringify(t,null,4))};function P(e){return/wxml/.test(e)?(x({time:new Date,type:"transform wxml file suffix",file:e,message:"转换了视图文件后缀, wxml ==> ttml"},"info"),e.replace(/wxml$/,"ttml")):/wxss/.test(e)?(x({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 S(e,t="info",r=!1){r?x({time:new Date,type:"stdOut",message:e},t):"underline"===t?console.log(o.blue.underline.bold(e)):console.log(o[v[t]](e))}const v={info:"cyan",error:"red",success:"green",warning:"yellow"},E={1128:"抖音",13:"今日头条",35:"今日头条极速版"};var F={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=>P(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=P(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:S,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;S(`⚡ [warning]${t.startsWith("$")?"组件":"API"} "${r}" 在宿主----${n[t].map(e=>E[e]).join(", ")} ----中不支持`,"warning",e.isIDE)})}catch(t){S(`audit code error: ${t.message}`,"error",e.isIDE)}}},k={ctx:{wx:"tt"}};const q=c.default||c,C=l.default||l;function I(e,t,r,n,o){const i=s.parse(e,{sourceType:"module",plugins:["*"]});return q(i,{enter(e){!function(e,t,r,n){if(p.isIdentifier(e.node,{name:r})){const o=e.node;e.replaceWithSourceString(n[r]),x({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)}}),C(i,{}).code}var A=function*(e){const t=yield new Promise(t=>{let n=e.dist;F.isDirectory(n)&&(n+="/**/*.js"),".js"===r.extname(n)?i(n,{ignore:"**/node_modules/**/*.js"},(function(e,r){t(e?[]:r)})):t([])}),n=k,o=n.ctx;let s;for(let e=0;e<t.length;e++){s=yield F.getContent(t[e]);const r=I(s,n,"wx",o,t[e]);yield F.saveFile(t[e],r)}F.stdOut("🍻 Successfully transform js file","info",e.isIDE)};const{Parser:N,DomHandler:R}=b;var T={fakeRoot:Symbol("fake-root"),getHtmlParser:function(e){e=e||{xmlMode:!1,lowerCaseAttributeNames:!1,recognizeSelfClosing:!0,lowerCaseTags:!1};const t=new R;return{htmlParser:new N(t,e),handler:t}}};const{fakeRoot:W,getHtmlParser:_}=T;var H=function(e){e=e||{xmlMode:!1,lowerCaseAttributeNames:!1,recognizeSelfClosing:!0,lowerCaseTags:!1},this.Parser=function(t){const{htmlParser:r,handler:n}=_(e);return r.end(t),{type:"tag",name:W,attribs:{},children:y.isArray(n.dom)?n.dom:[n.dom]}}};const Q=T.fakeRoot,z=(...e)=>e.filter(e=>!!e).join(" ");var B=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===Q)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?`<${z(n,c)} />`:`<${z(n,c)}>${t}</${n}>`}(t,n,r)}case"text":return i;case"comment":return`\x3c!--${i}--\x3e`}}};function G(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 J(e){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?G(Object(n),!0).forEach((function(r){t(e,r,n[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):G(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}const L=F.ttmlFileSuffix;var M=function(e={}){return function(e,t){!function e(t,r){if(y.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,`.${L}`);return/\w+\.\w+$/.test(t)||(t+=`.${L}`),J({},e,{attribs:J({},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 J({},e,{attribs:i,singleQuoteAttribs:Object.keys(o).reduce((e,t)=>J({},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,`.${L}`);return J({},e,{data:t})}return e}(t));return t}(e)}};function V(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 K=w.DepGraph,U=T.getHtmlParser;function X(e,t,r){return g().use(H).use(M,{context:r}).use(B).process(F.toVFile(e,t))}var Y=function*(e){const n=yield new Promise(t=>{let n=e.dist;F.isDirectory(n)&&(n+=`/**/*.${F.ttmlFileSuffix}`),r.extname(n)===`.${F.ttmlFileSuffix}`?i(n,(function(e,r){t(e?[]:r)})):t([])});e.data.ttmlRenamedComponents=function(e,n){const{htmlParser:o,handler:i}=U(),s=e.reduce((e,t)=>(e.addNode(t),o.end(F.getContentSync(t)),function e(t,n,o){if(!y.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/,`.${F.ttmlFileSuffix}`),e=e.endsWith(`.${F.ttmlFileSuffix}`)?e:`${e}.${F.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 K);return Object.keys(n.data.renamedComponents||{}).map(e=>e.replace(/\.json$/,`.${F.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(`.${F.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?V(Object(n),!0).forEach((function(r){t(e,r,n[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):V(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 F.getContent(n[t]),o=yield X(n[t],r,e);yield F.saveFile(n[t],String(o))}F.stdOut("🍻 Successfully transform wxml file","info",e.isIDE)};function Z(e){return e.replace(/\.wxss/gi,`.${F.ttssFileSuffix}`)}var ee=function*(e){const t=yield new Promise(t=>{let n=e.dist;const o=F.ttssFileSuffix;F.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 F.getContent(t[e]),n=Z(n),yield F.saveFile(t[e],n);F.stdOut("🍻 Successfully transform wxss file","info",e.isIDE)};function te(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 F.stdOut("⛔ argument options.src is required","error",e.isIDE);e.dist=e.dist||F.getDefaultDist(e.src);let i=e.dist||e.src;F.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?te(Object(n),!0).forEach((function(r){t(e,r,n[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):te(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}({},e,{logs:[],data:{}});F.stdOut("🛠️ Transform source project...","warning",e.isIDE),n((function*(){yield F.copyProject(e.src,e.dist),yield A(s),yield Y(s),yield ee(s),yield F.auditCode(s)})).then((function(){$(e.log),o&&o(null),F.stdOut("🎊 Congratulations, transform done! Please check transform log in","success",e.isIDE),F.stdOut(r.dirname(e.log)+"/log.txt","underline",e.isIDE)})).catch((function(t){o&&o(t),F.stdOut(`😱 Transform error: ${t}`,"error",e.isIDE)}))}; |
{ | ||
"name": "wx-to-tt", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"description": "transform wx micro app to bytedance micro app", | ||
@@ -39,2 +39,3 @@ "main": "dest/index.js", | ||
"stricter-htmlparser2": "^3.9.6", | ||
"tma-code-audit": "0.0.1", | ||
"unified": "^8.4.2", | ||
@@ -41,0 +42,0 @@ "vfile": "^4.0.2" |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
16364
101
17
+ Addedtma-code-audit@0.0.1
+ Addedtma-code-audit@0.0.1(transitive)