Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

wx-to-tt

Package Overview
Dependencies
Maintainers
6
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

wx-to-tt - npm Package Compare versions

Comparing version 0.2.9-beta.1 to 0.2.9-beta.2

static/index.html

2

dist/index.js

@@ -1,1 +0,1 @@

"use strict";var t=this&&this.__createBinding||(Object.create?function(t,e,r,o){void 0===o&&(o=r);var i=Object.getOwnPropertyDescriptor(e,r);i&&!("get"in i?!e.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,o,i)}:function(t,e,r,o){void 0===o&&(o=r),t[o]=e[r]}),e=this&&this.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),r=this&&this.__importStar||function(r){if(r&&r.__esModule)return r;var o={};if(null!=r)for(var i in r)"default"!==i&&Object.prototype.hasOwnProperty.call(r,i)&&t(o,r,i);return e(o,r),o},o=this&&this.__awaiter||function(t,e,r,o){return new(r||(r=Promise))((function(i,n){function s(t){try{a(o.next(t))}catch(t){n(t)}}function l(t){try{a(o.throw(t))}catch(t){n(t)}}function a(t){var e;t.done?i(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(s,l)}a((o=o.apply(t,e||[])).next())}))},i=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.wx2tt=void 0;const n=i(require("path")),s=r(require("./utils/index")),l=require("./utils/log"),a=require("./transform"),u=require("./utils/constant");exports.wx2tt=function(t,e){return o(this,void 0,void 0,(function*(){if(t.isIDE=t.isIDE||!1,t.dist=s.isDirectory(t.dist)?t.dist:s.getDefaultDest(t.src),l.log.init({isIDE:t.isIDE,src:t.src,dist:t.dist,logPath:n.default.join(t.dist,"__wxToTT/report/record.html")}),!t.src){const t="argument options.src is required";return l.log.printLog(`⛔ ${t}`,l.Level.ERROR),void(e&&e(t))}if(!s.isDirValid(t.src)){const r=`${t.src} is not a wx miniprogram project`;return l.log.printLog(`⛔ ${r}`,l.Level.INFO),void(e&&e(r))}let r=t.dist||t.src;s.isDirectory(r)||(r=n.default.dirname(r)),t.log=r;const o=Object.assign(Object.assign({},t),{data:{}});l.log.printLog("🛠️ Transform source project...",l.Level.INFO);try{yield s.copyProject(t.src,t.dist),yield(0,a.transformApi)(o),yield(0,a.transformView)(o),yield(0,a.transformScript)(o),yield(0,a.transformStyle)(o),yield(0,a.transformConfig)(o),yield s.auditCode(o),l.log.printLog("🎊 Congratulations, transform done! Please check transform log in",l.Level.SUCCESS),l.log.printLog(`📝 ${n.default.resolve(t.log,"log.txt")}`,l.Level.UNDERLINE),l.log.save(t.log),e&&e(null,l.log.result)}catch(r){l.log.recordLog({type:u.ERROR_TYPE.compileError,message:`Transform error: ${r}`},l.Level.ERROR,!0),l.log.printLog(`📝 ${n.default.resolve(t.log,"log.txt")}`,l.Level.UNDERLINE),l.log.save(t.log),e&&e(r,l.log.result)}return l.log.result}))};
"use strict";var t=this&&this.__createBinding||(Object.create?function(t,e,r,i){void 0===i&&(i=r);var o=Object.getOwnPropertyDescriptor(e,r);o&&!("get"in o?!e.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,i,o)}:function(t,e,r,i){void 0===i&&(i=r),t[i]=e[r]}),e=this&&this.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),r=this&&this.__importStar||function(r){if(r&&r.__esModule)return r;var i={};if(null!=r)for(var o in r)"default"!==o&&Object.prototype.hasOwnProperty.call(r,o)&&t(i,r,o);return e(i,r),i},i=this&&this.__awaiter||function(t,e,r,i){return new(r||(r=Promise))((function(o,n){function s(t){try{c(i.next(t))}catch(t){n(t)}}function l(t){try{c(i.throw(t))}catch(t){n(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(s,l)}c((i=i.apply(t,e||[])).next())}))},o=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.wx2tt=void 0;const n=o(require("path")),s=r(require("./utils/index")),l=require("./utils/log"),c=require("./transform"),a=require("./utils/constant");exports.wx2tt=function(t,e){return i(this,void 0,void 0,(function*(){t.isIDE=t.isIDE||!1,t.dist=s.isDirectory(t.dist)?t.dist:s.getDefaultDest(t.src);let r=t.log||t.dist||t.src;if(s.isDirectory(r)||(r=n.default.dirname(r)),t.log=r,l.log.init({isIDE:t.isIDE,src:t.src,dist:t.dist,logPath:t.log}),!t.src){const t="argument options.src is required";return l.log.printLog(`⛔ ${t}`,l.Level.ERROR),void(e&&e(t))}if(!s.isDirValid(t.src)){const r=`${t.src} is not a wx miniprogram project`;return l.log.printLog(`⛔ ${r}`,l.Level.INFO),void(e&&e(r))}const i=Object.assign(Object.assign({},t),{data:{}});l.log.printLog("🛠️ Transform source project...",l.Level.INFO);try{yield s.copyProject(t.src,t.dist),yield(0,c.transformApi)(i),yield(0,c.transformView)(i),yield(0,c.transformScript)(i),yield(0,c.transformStyle)(i),yield(0,c.transformConfig)(i),yield s.auditCode(i),l.log.printLog("🎊 Congratulations, transform done! Please check transform log in",l.Level.SUCCESS),l.log.save(),e&&e(null,l.log.result)}catch(t){l.log.recordLog({type:a.ERROR_TYPE.compileError,message:`Transform error: ${t}`},l.Level.ERROR,!0),l.log.save(),e&&e(t,l.log.result)}return l.log.result}))};

@@ -42,3 +42,3 @@ import vfile from 'vfile';

export declare const saveFile: (path: string, con: string) => Promise<boolean>;
export declare const saveLog: (ContentPath: string, con: string) => Promise<unknown>;
export declare const saveLog: (logPath: string, con: string) => Promise<unknown>;
/**

@@ -45,0 +45,0 @@ * 创建虚拟文件,并添加关联文件

@@ -1,1 +0,1 @@

"use strict";var e=this&&this.__awaiter||function(e,t,r,n){return new(r||(r=Promise))((function(s,o){function i(e){try{u(n.next(e))}catch(e){o(e)}}function a(e){try{u(n.throw(e))}catch(e){o(e)}}function u(e){var t;e.done?s(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(i,a)}u((n=n.apply(e,t||[])).next())}))},t=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.auditCode=exports.getDefaultDest=exports.toVFile=exports.saveLog=exports.saveFile=exports.getContentSync=exports.getJSONContent=exports.getContent=exports.isDirectory=exports.copyProject=exports.traverseFiles=exports.getHtmlParser=exports.isDirValid=void 0;const r=t(require("fs-extra")),n=t(require("recursive-copy")),s=t(require("path")),o=t(require("vfile")),i=t(require("glob")),a=require("stricter-htmlparser2"),u=require("./constant"),l=require("./log"),c=require("lodash");exports.isDirValid=function(e){const t=`${e}/app.json`;try{return r.default.statSync(t).isFile()}catch(e){return!1}};exports.getHtmlParser=function(e){e=Object.assign({},{xmlMode:!1,lowerCaseAttributeNames:!1,recognizeSelfClosing:!0,lowerCaseTags:!1},e);const t=new a.DomHandler;return{htmlParser:new a.Parser(t,e),handler:t}};exports.traverseFiles=function(t,r){return e(this,void 0,void 0,(function*(){return yield new Promise((e=>{let n,o=t.dist;const a=x(t.src);if(a)o=`${o}/**/*.${r}`,n=s.default.extname(o);else{const e=p(t.src);o=s.default.resolve(o,s.default.basename(e)),n=s.default.extname(o)}n===`.${r}`?"js"==r?(0,i.default)(o,{ignore:["**/node_modules/**/*.js","**/*.ttpkg.js"],nodir:!0},((t,r)=>{e(t?[]:r)})):a?(0,i.default)(o,{nodir:!0},((t,r)=>{e(t?[]:r)})):e([o]):e([])}))}))};function d(e){return{overwrite:!0,expand:!0,dot:!0,rename:t=>function(e,t){if(x(s.default.join(e,t)))return t;if(u.WX_REGEXP.view.test(t))return t.replace(u.WX_REGEXP.view,`.${u.TT_SUFFIX.view}`);if(u.WX_REGEXP.style.test(t))return t.replace(u.WX_REGEXP.style,`.${u.TT_SUFFIX.style}`);if(u.WX_REGEXP.script.test(t))return t.replace(u.WX_REGEXP.script,`.${u.TT_SUFFIX.script}`);return t}(e,t)}}function f(e){if((0,c.isArray)(e))for(let t in e){if((0,c.isArray)(e[t])){f(e[t]);continue}const{src:r,dest:n,stats:s}=e[t];s.isDirectory()||(u.WX_REGEXP.view.test(r)?l.log.recordLog({type:u.LOG_TYPE.wxml2ttml,file:n,message:"转换视图文件后缀 wxml -> ttml"},l.Level.INFO):u.WX_REGEXP.style.test(r)?l.log.recordLog({type:u.LOG_TYPE.wxss2ttss,file:n,message:"转换样式文件后缀 wxss -> ttss"},l.Level.INFO):u.WX_REGEXP.script.test(r)&&l.log.recordLog({type:u.LOG_TYPE.wxs2sjs,file:n,message:"转换 wxs 文件后缀 wxs -> sjs"},l.Level.INFO))}}function p(e){const t=u.WX_REGEXP;let r;return Object.keys(t).forEach((n=>{t[n].test(e)&&(r=n)})),r?e.replace(t[r],`.${u.TT_SUFFIX[r]}`):e}function x(e){return r.default.statSync(e).isDirectory()}exports.copyProject=function(t,o){return x(t)?function(t,o){return e(this,void 0,void 0,(function*(){const e=/(node_modules|DS_store)/i,i=[],a=r.default.readdirSync(t).filter((t=>!e.test(t))),l=x(o),c=l?o:s.default.dirname(o);for(const e in a){const r=x(s.default.join(t,a[e]))?a[e]:a[e].replace(u.WX_REGEXP.view,`.${u.TT_SUFFIX.view}`).replace(u.WX_REGEXP.style,`.${u.TT_SUFFIX.style}`).replace(u.WX_REGEXP.script,`.${u.TT_SUFFIX.script}`);i.push((0,n.default)(s.default.join(t,a[e]),s.default.join(c,r),d(s.default.join(t,a[e]))))}const p=yield Promise.all(i);return f(p),p}))}(t,o):function(e,t){let n=s.default.basename(e);n=p(n),t=x(t)?s.default.join(t,n):s.default.join(s.default.dirname(t),n);return r.default.copy(e,t)}(t,o)},exports.isDirectory=x;exports.getContent=function(e){return new Promise((t=>{r.default.readFile(e,((e,r)=>{t(r.toString())}))}))};exports.getJSONContent=function(e){return new Promise((t=>{r.default.readJSON(e,((e,r)=>{t(r)}))}))};exports.getContentSync=function(e){return r.default.readFileSync(e).toString()};exports.saveFile=function(e,t){return new Promise(((n,s)=>{r.default.writeFile(e,t,(e=>{e?s(e):n(!0)}))}))};exports.saveLog=function(e,t){const n=s.default.join(__dirname,"../../static");return new Promise(((o,i)=>{const a=s.default.dirname(e);r.default.copy(n,a).then((()=>{r.default.writeFileSync(s.default.join(a,"js/data.js"),`const recordData=${t}`)})).catch((e=>{i(e)}))}))};exports.toVFile=function(e,t){const n=(0,o.default)({path:e,contents:t}),i={style:u.TT_SUFFIX.style,view:u.TT_SUFFIX.view,js:"js",config:"json",script:u.TT_SUFFIX.script},{cwd:a,dirname:l,stem:c,extname:d}=n;return n.data.relatedFiles=Object.keys(i).reduce(((e,t)=>{const n=`.${i[t]}`;if(n!==d){const o=s.default.resolve(a,l,c+n);r.default.existsSync(o)&&(e[t]=o)}return e}),{}),n};exports.getDefaultDest=function(e){return s.default.join(s.default.dirname(e),`${s.default.basename(e)}-tt`)};exports.auditCode=function(t){return e(this,void 0,void 0,(function*(){try{const e=require("tma-code-audit"),r=t.dist,n=yield e(r);Object.keys(n).forEach((e=>{e.startsWith("$")&&e.slice(1),e.startsWith("$"),n[e].map((e=>u.HOST_MAP[e])).join(", ")}))}catch(e){l.log.recordLog(`audit code error: ${e}`,l.Level.ERROR,!0)}}))};
"use strict";var e=this&&this.__awaiter||function(e,t,r,n){return new(r||(r=Promise))((function(s,o){function i(e){try{u(n.next(e))}catch(e){o(e)}}function a(e){try{u(n.throw(e))}catch(e){o(e)}}function u(e){var t;e.done?s(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(i,a)}u((n=n.apply(e,t||[])).next())}))},t=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.auditCode=exports.getDefaultDest=exports.toVFile=exports.saveLog=exports.saveFile=exports.getContentSync=exports.getJSONContent=exports.getContent=exports.isDirectory=exports.copyProject=exports.traverseFiles=exports.getHtmlParser=exports.isDirValid=void 0;const r=t(require("fs-extra")),n=t(require("recursive-copy")),s=t(require("path")),o=t(require("vfile")),i=t(require("glob")),a=require("stricter-htmlparser2"),u=require("./constant"),l=require("./log"),c=require("lodash"),d=t(require("open"));exports.isDirValid=function(e){const t=`${e}/app.json`;try{return r.default.statSync(t).isFile()}catch(e){return!1}};exports.getHtmlParser=function(e){e=Object.assign({},{xmlMode:!1,lowerCaseAttributeNames:!1,recognizeSelfClosing:!0,lowerCaseTags:!1},e);const t=new a.DomHandler;return{htmlParser:new a.Parser(t,e),handler:t}};exports.traverseFiles=function(t,r){return e(this,void 0,void 0,(function*(){return yield new Promise((e=>{let n,o=t.dist;const a=y(t.src);if(a)o=`${o}/**/*.${r}`,n=s.default.extname(o);else{const e=x(t.src);o=s.default.resolve(o,s.default.basename(e)),n=s.default.extname(o)}n===`.${r}`?"js"==r?(0,i.default)(o,{ignore:["**/node_modules/**/*.js","**/*.ttpkg.js"],nodir:!0},((t,r)=>{e(t?[]:r)})):a?(0,i.default)(o,{nodir:!0},((t,r)=>{e(t?[]:r)})):e([o]):e([])}))}))};function f(e){return{overwrite:!0,expand:!0,dot:!0,rename:t=>function(e,t){if(y(s.default.join(e,t)))return t;if(u.WX_REGEXP.view.test(t))return t.replace(u.WX_REGEXP.view,`.${u.TT_SUFFIX.view}`);if(u.WX_REGEXP.style.test(t))return t.replace(u.WX_REGEXP.style,`.${u.TT_SUFFIX.style}`);if(u.WX_REGEXP.script.test(t))return t.replace(u.WX_REGEXP.script,`.${u.TT_SUFFIX.script}`);return t}(e,t)}}function p(e){if((0,c.isArray)(e))for(let t in e){if((0,c.isArray)(e[t])){p(e[t]);continue}const{src:r,dest:n,stats:s}=e[t];s.isDirectory()||(u.WX_REGEXP.view.test(r)?l.log.recordLog({type:u.LOG_TYPE.wxml2ttml,file:n,message:"转换视图文件后缀 wxml -> ttml"},l.Level.INFO):u.WX_REGEXP.style.test(r)?l.log.recordLog({type:u.LOG_TYPE.wxss2ttss,file:n,message:"转换样式文件后缀 wxss -> ttss"},l.Level.INFO):u.WX_REGEXP.script.test(r)&&l.log.recordLog({type:u.LOG_TYPE.wxs2sjs,file:n,message:"转换 wxs 文件后缀 wxs -> sjs"},l.Level.INFO))}}function x(e){const t=u.WX_REGEXP;let r;return Object.keys(t).forEach((n=>{t[n].test(e)&&(r=n)})),r?e.replace(t[r],`.${u.TT_SUFFIX[r]}`):e}function y(e){return r.default.statSync(e).isDirectory()}exports.copyProject=function(t,o){return y(t)?function(t,o){return e(this,void 0,void 0,(function*(){const e=/(node_modules|DS_store)/i,i=[],a=r.default.readdirSync(t).filter((t=>!e.test(t))),l=y(o),c=l?o:s.default.dirname(o);for(const e in a){const r=y(s.default.join(t,a[e]))?a[e]:a[e].replace(u.WX_REGEXP.view,`.${u.TT_SUFFIX.view}`).replace(u.WX_REGEXP.style,`.${u.TT_SUFFIX.style}`).replace(u.WX_REGEXP.script,`.${u.TT_SUFFIX.script}`);i.push((0,n.default)(s.default.join(t,a[e]),s.default.join(c,r),f(s.default.join(t,a[e]))))}const d=yield Promise.all(i);return p(d),d}))}(t,o):function(e,t){let n=s.default.basename(e);n=x(n),t=y(t)?s.default.join(t,n):s.default.join(s.default.dirname(t),n);return r.default.copy(e,t)}(t,o)},exports.isDirectory=y;exports.getContent=function(e){return new Promise((t=>{r.default.readFile(e,((e,r)=>{t(r.toString())}))}))};exports.getJSONContent=function(e){return new Promise((t=>{r.default.readJSON(e,((e,r)=>{t(r)}))}))};exports.getContentSync=function(e){return r.default.readFileSync(e).toString()};exports.saveFile=function(e,t){return new Promise(((n,s)=>{r.default.writeFile(e,t,(e=>{e?s(e):n(!0)}))}))};exports.saveLog=function(e,t){const n=s.default.join(__dirname,"../../static");return new Promise(((o,i)=>{r.default.copy(n,e).then((()=>{r.default.writeFileSync(s.default.join(e,"js/data.js"),`const recordData=${t}`),(0,d.default)(s.default.join(e,"index.html"))})).catch((e=>{i(e)}))}))};exports.toVFile=function(e,t){const n=(0,o.default)({path:e,contents:t}),i={style:u.TT_SUFFIX.style,view:u.TT_SUFFIX.view,js:"js",config:"json",script:u.TT_SUFFIX.script},{cwd:a,dirname:l,stem:c,extname:d}=n;return n.data.relatedFiles=Object.keys(i).reduce(((e,t)=>{const n=`.${i[t]}`;if(n!==d){const o=s.default.resolve(a,l,c+n);r.default.existsSync(o)&&(e[t]=o)}return e}),{}),n};exports.getDefaultDest=function(e){return s.default.join(s.default.dirname(e),`${s.default.basename(e)}-tt`)};exports.auditCode=function(t){return e(this,void 0,void 0,(function*(){try{const e=require("tma-code-audit"),r=t.dist,n=yield e(r);Object.keys(n).forEach((e=>{e.startsWith("$")&&e.slice(1),e.startsWith("$"),n[e].map((e=>u.HOST_MAP[e])).join(", ")}))}catch(e){l.log.recordLog(`audit code error: ${e}`,l.Level.ERROR,!0)}}))};

@@ -92,3 +92,3 @@ import { LOG_TYPE, ERROR_TYPE } from './constant';

sortLog(): string;
save(logPath: string): void;
save(): void;
clear(): void;

@@ -95,0 +95,0 @@ getLogItem(log: LogInfo): {

@@ -1,1 +0,1 @@

"use strict";var t=this&&this.__createBinding||(Object.create?function(t,e,o,i){void 0===i&&(i=o);var s=Object.getOwnPropertyDescriptor(e,o);s&&!("get"in s?!e.__esModule:s.writable||s.configurable)||(s={enumerable:!0,get:function(){return e[o]}}),Object.defineProperty(t,i,s)}:function(t,e,o,i){void 0===i&&(i=o),t[i]=e[o]}),e=this&&this.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),o=this&&this.__importStar||function(o){if(o&&o.__esModule)return o;var i={};if(null!=o)for(var s in o)"default"!==s&&Object.prototype.hasOwnProperty.call(o,s)&&t(i,o,s);return e(i,o),i},i=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.log=exports.Level=void 0;const s=require("./constant"),r=i(require("chalk")),n=o(require("./index")),a=i(require("path"));var l;!function(t){t.SUCCESS="success",t.ERROR="error",t.WARNING="warning",t.INFO="info",t.UNDERLINE="underline"}(l=exports.Level||(exports.Level={}));exports.log=new class{constructor(){this.store={info:[],warning:[],error:[],success:[]},this.logMap=new Map,this.isIDE=!1,this.beginTime=null,this.endTime=null,this.result=null,this.status=null,this.logDetail={}}init(t){this.clear(),this.isIDE=t.isIDE,this.src=t.src,this.dist=t.dist,this.logPath=t.logPath,this.beginTime=new Date}isLogExist(t,e){let o=`${e}_${JSON.stringify(t)}`;return"string"!=typeof t&&t.file&&(o+=`_${t.file}`),!!this.logMap.has(o)||(this.logMap.set(o,1),!1)}recordLog(t,e,o=!1){this.isLogExist(t,e)||(o&&this.printLog(t,e),e===l.UNDERLINE?this.store.success.push(t):this.store[e].push(t))}printLog(t,e){let o="string"==typeof t?t:t.message;if("string"!=typeof t&&(t.type===s.ERROR_TYPE.apiNotSupport?o=`API: ${t.name} ${t.message}`:t.type===s.ERROR_TYPE.attribNotSupport?o=`<${t.name}> attribute: ${t.attr} ${t.message}`:t.type===s.ERROR_TYPE.componentNotSupport?o=`component: ${t.name} ${t.message}`:t.type===s.ERROR_TYPE.paramNotSupport?o=`API: ${t.name} param: ${t.param} ${t.message}`:t.type===s.ERROR_TYPE.configNotSupport&&(o=`${t.name} ${t.message}`)),e===l.UNDERLINE)console.log(r.default.blue.underline.bold(o));else{if(this.attentionLog(t,e,o))return;console.log(r.default[s.LOG_COLOR_TYPE[e]](o))}}attentionLog(t,e,o){return"string"!=typeof t&&e!==l.INFO&&e!==l.SUCCESS&&(e===l.WARNING?(console.log(r.default.keyword("orange")(`⚡ ${r.default.yellow("[Warning]: ")} ${o}`)),t.file&&console.log(r.default.yellow(` ${t.file}`)),console.log("--------------------------------------------------------")):(console.log(r.default.keyword("orange")(`⛔ ${r.default.redBright("[Error]: ")} ${o}`)),t.file&&console.log(r.default.redBright(` ${t.file}`)),console.log("--------------------------------------------------------")),!0)}sortLog(){const t={"项目目录":this.src,"输出目录":this.dist,"日志路径":this.logPath},e=[s.ERROR_TYPE.apiNotSupport,s.ERROR_TYPE.attribNotSupport,s.ERROR_TYPE.componentNotSupport,s.ERROR_TYPE.configNotSupport,s.ERROR_TYPE.paramNotSupport],o=new Map;for(let t in this.store.warning){const i=this.store.warning[t];if("string"!=typeof i&&e.includes(i.type)){const t=a.default.relative(this.dist,i.file);o.has(t)||o.set(t,[]),o.set(t,o.get(t).concat(i))}}for(const t of o.keys()){const e=this.logDetail[t];e.level=1;const i=o.get(t);e.log=i.map((t=>("string"==typeof t||t.type!==s.ERROR_TYPE.apiNotSupport&&t.type!==s.ERROR_TYPE.componentNotSupport||(e.level=2),this.getLogItem(t))))}const i={detail:this.logDetail,info:t};return JSON.stringify(i)}save(t){this.endTime=new Date;const e=this.sortLog();this.result=e,n.saveLog(this.logPath,e)}clear(){this.store.info=[],this.store.warning=[],this.store.error=[],this.store.success=[],this.result=null,this.logMap.clear(),this.beginTime=null,this.endTime=null,this.status=null}getLogItem(t){if("string"!=typeof t){const e=t.type;if(e===s.ERROR_TYPE.apiNotSupport)return{name:t.name,info:"不支持该API",hint:t.message||"暂不支持,请尝试其他方式",doc:t.doc};if(e===s.ERROR_TYPE.attribNotSupport)return{name:t.name,info:t.attr,hint:t.message||"暂不支持,请尝试其他方式",doc:t.doc};if(e===s.ERROR_TYPE.componentNotSupport)return{name:t.name,info:"不支持该组件",hint:t.message||"暂不支持,请尝试其他方式",doc:t.doc};if(e===s.ERROR_TYPE.paramNotSupport)return{name:t.name,info:t.param,hint:t.message||"暂不支持,请尝试其他方式",doc:t.doc};if(e===s.ERROR_TYPE.configNotSupport)return{name:t.name,info:"不支持该配置",hint:t.message||"暂不支持,请尝试其他方式",doc:t.doc}}}recordTransformFile(t){const e=a.default.relative(this.dist,t);if(!this.logDetail[e]){const t=a.default.extname(e).split(".")[1];this.logDetail[e]={type:"js"===t?"javascript":t,level:0,log:[]}}}};
"use strict";var t=this&&this.__createBinding||(Object.create?function(t,e,o,i){void 0===i&&(i=o);var s=Object.getOwnPropertyDescriptor(e,o);s&&!("get"in s?!e.__esModule:s.writable||s.configurable)||(s={enumerable:!0,get:function(){return e[o]}}),Object.defineProperty(t,i,s)}:function(t,e,o,i){void 0===i&&(i=o),t[i]=e[o]}),e=this&&this.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),o=this&&this.__importStar||function(o){if(o&&o.__esModule)return o;var i={};if(null!=o)for(var s in o)"default"!==s&&Object.prototype.hasOwnProperty.call(o,s)&&t(i,o,s);return e(i,o),i},i=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.log=exports.Level=void 0;const s=require("./constant"),r=i(require("chalk")),n=o(require("./index")),a=i(require("path"));var l;!function(t){t.SUCCESS="success",t.ERROR="error",t.WARNING="warning",t.INFO="info",t.UNDERLINE="underline"}(l=exports.Level||(exports.Level={}));exports.log=new class{constructor(){this.store={info:[],warning:[],error:[],success:[]},this.logMap=new Map,this.isIDE=!1,this.beginTime=null,this.endTime=null,this.result=null,this.status=null,this.logDetail={}}init(t){this.clear(),this.isIDE=t.isIDE,this.src=t.src,this.dist=t.dist,this.logPath=a.default.join(t.logPath,"__wxToTT/report"),this.beginTime=new Date}isLogExist(t,e){let o=`${e}_${JSON.stringify(t)}`;return"string"!=typeof t&&t.file&&(o+=`_${t.file}`),!!this.logMap.has(o)||(this.logMap.set(o,1),!1)}recordLog(t,e,o=!1){this.isLogExist(t,e)||(o&&this.printLog(t,e),e===l.UNDERLINE?this.store.success.push(t):this.store[e].push(t))}printLog(t,e){let o="string"==typeof t?t:t.message;if("string"!=typeof t&&(t.type===s.ERROR_TYPE.apiNotSupport?o=`API: ${t.name} ${t.message}`:t.type===s.ERROR_TYPE.attribNotSupport?o=`<${t.name}> attribute: ${t.attr} ${t.message}`:t.type===s.ERROR_TYPE.componentNotSupport?o=`component: ${t.name} ${t.message}`:t.type===s.ERROR_TYPE.paramNotSupport?o=`API: ${t.name} param: ${t.param} ${t.message}`:t.type===s.ERROR_TYPE.configNotSupport&&(o=`${t.name} ${t.message}`)),e===l.UNDERLINE)console.log(r.default.blue.underline.bold(o));else{if(this.attentionLog(t,e,o))return;console.log(r.default[s.LOG_COLOR_TYPE[e]](o))}}attentionLog(t,e,o){return"string"!=typeof t&&e!==l.INFO&&e!==l.SUCCESS&&(e===l.WARNING?(console.log(r.default.keyword("orange")(`⚡ ${r.default.yellow("[Warning]: ")} ${o}`)),t.file&&console.log(r.default.yellow(` ${t.file}`)),console.log("--------------------------------------------------------")):(console.log(r.default.keyword("orange")(`⛔ ${r.default.redBright("[Error]: ")} ${o}`)),t.file&&console.log(r.default.redBright(` ${t.file}`)),console.log("--------------------------------------------------------")),!0)}sortLog(){const t={"项目目录":this.src,"输出目录":this.dist,"日志路径":a.default.join(this.logPath,"index.html")},e=[s.ERROR_TYPE.apiNotSupport,s.ERROR_TYPE.attribNotSupport,s.ERROR_TYPE.componentNotSupport,s.ERROR_TYPE.configNotSupport,s.ERROR_TYPE.paramNotSupport],o=new Map;for(let t in this.store.warning){const i=this.store.warning[t];if("string"!=typeof i&&e.includes(i.type)){const t=a.default.relative(this.dist,i.file);o.has(t)||o.set(t,[]),o.set(t,o.get(t).concat(i))}}for(const t of o.keys()){const e=this.logDetail[t];e.level=1;const i=o.get(t);e.log=i.map((t=>("string"==typeof t||t.type!==s.ERROR_TYPE.apiNotSupport&&t.type!==s.ERROR_TYPE.componentNotSupport||(e.level=2),this.getLogItem(t))))}const i={detail:this.logDetail,info:t};return JSON.stringify(i)}save(){this.endTime=new Date;const t=this.sortLog();this.result=t,n.saveLog(this.logPath,t)}clear(){this.store.info=[],this.store.warning=[],this.store.error=[],this.store.success=[],this.result=null,this.logMap.clear(),this.beginTime=null,this.endTime=null,this.status=null}getLogItem(t){if("string"!=typeof t){const e=t.type;if(e===s.ERROR_TYPE.apiNotSupport)return{name:t.name,info:"不支持该API",hint:t.message||"暂不支持,请尝试其他方式",doc:t.doc};if(e===s.ERROR_TYPE.attribNotSupport)return{name:t.name,info:t.attr,hint:t.message||"暂不支持,请尝试其他方式",doc:t.doc};if(e===s.ERROR_TYPE.componentNotSupport)return{name:t.name,info:"不支持该组件",hint:t.message||"暂不支持,请尝试其他方式",doc:t.doc};if(e===s.ERROR_TYPE.paramNotSupport)return{name:t.name,info:t.param,hint:t.message||"暂不支持,请尝试其他方式",doc:t.doc};if(e===s.ERROR_TYPE.configNotSupport)return{name:t.name,info:"不支持该配置",hint:t.message||"暂不支持,请尝试其他方式",doc:t.doc}}}recordTransformFile(t){const e=a.default.relative(this.dist,t);if(!this.logDetail[e]){const t=a.default.extname(e).split(".")[1];this.logDetail[e]={type:"js"===t?"javascript":t,level:0,log:[]}}}};
{
"name": "wx-to-tt",
"version": "0.2.9-beta.1",
"version": "0.2.9-beta.2",
"description": "transform wx micro app to bytedance micro app",

@@ -43,3 +43,3 @@ "main": "dist/index.js",

"lodash": "^4.17.15",
"mkdirp": "^0.5.1",
"open": "^9.1.0",
"recursive-copy": "^2.0.10",

@@ -46,0 +46,0 @@ "stricter-htmlparser2": "^3.9.6",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc