mirror of
https://github.com/msojocs/wx-compiler.git
synced 2025-07-19 00:00:04 +08:00
feat: node module code generator for wine
This commit is contained in:
parent
e0b3276eb3
commit
66032edce7
@ -9,6 +9,6 @@
|
||||
"replaceContent": {
|
||||
"./packageComponent/pages/camera-scan-code/camera-scan-code.wxml": "<import data-ib-structured-id=\"0\" src=\"../../../common/head.wxml\" />\n<import data-ib-structured-id=\"1\" src=\"../../../common/foot.wxml\" />\n\n<view class=\"container page\" data-weui-theme=\"{{theme}}\" data-ib-structured-id=\"2\">\n <template data-ib-structured-id=\"3\" is=\"head\" data=\"{{title: 'camera'}}\"/>\n\n <view class=\"page-body\" data-ib-structured-id=\"4\">\n <view class=\"page-body-wrapper\" data-ib-structured-id=\"5\">\n <camera\n mode=\"scanCode\"\n flash=\"off\"\n bindscancode=\"scanCode\"\n binderror=\"error\"\n data-ib-structured-id=\"6\">\n </camera>\n <view class=\"btn-area\" data-ib-structured-id=\"7\">\n <button type=\"primary\" bindtap=\"navigateBack\" data-ib-structured-id=\"8\">\n 返回正常模式\n </button>\n </view>\n <form data-ib-structured-id=\"9\">\n <view class=\"page-section\" data-ib-structured-id=\"10\">\n <view class=\"weui-cells weui-cells_after-title\" data-ib-structured-id=\"11\">\n <view class=\"weui-cell weui-cell_input\" data-ib-structured-id=\"12\">\n <view class=\"weui-cell__hd\" data-ib-structured-id=\"13\">\n <view class=\"weui-label\" data-ib-structured-id=\"14\">类型</view>\n </view>\n <view class=\"weui-cell__bd\" data-ib-structured-id=\"15\">\n {{ result.type }}\n </view>\n </view>\n <view class=\"weui-cell weui-cell_input\" data-ib-structured-id=\"16\">\n <view class=\"weui-cell__hd\" data-ib-structured-id=\"17\">\n <view class=\"weui-label\" data-ib-structured-id=\"18\">结果</view>\n </view>\n <view class=\"weui-cell__bd\" data-ib-structured-id=\"19\">\n {{ result.result }}\n </view>\n </view>\n </view>\n </view>\n </form>\n </view>\n </view>\n\n <template data-ib-structured-id=\"20\" is=\"foot\" />\n</view>\n"
|
||||
},
|
||||
"cwd": "/mnt/disk1/WeChatProjects/miniprogram-demo/miniprogram/",
|
||||
"cwd": "miniprogram-demo/miniprogram/",
|
||||
"lazyloadConfig": ""
|
||||
}
|
1421
test/node-modules/cases/wcc/case1/output/wcc_node_wine.js
Normal file
1421
test/node-modules/cases/wcc/case1/output/wcc_node_wine.js
Normal file
File diff suppressed because it is too large
Load Diff
28
test/node-modules/cases/wcsc/case1/config.json
Normal file
28
test/node-modules/cases/wcsc/case1/config.json
Normal file
@ -0,0 +1,28 @@
|
||||
{
|
||||
"pageCount": 12,
|
||||
"files": [
|
||||
"./page/component/index.wxss",
|
||||
"./page/API/index.wxss",
|
||||
"./page/cloud/index.wxss",
|
||||
"./page/extend/index.wxss",
|
||||
"./component/navigation-bar/navigation-bar.wxss",
|
||||
"./components/navigation-bar/index.wxss",
|
||||
"./components/page-scroll/index.wxss",
|
||||
"./miniprogram_npm/miniprogram-barrage/index.wxss",
|
||||
"./miniprogram_npm/miniprogram-recycle-view/recycle-item.wxss",
|
||||
"./miniprogram_npm/miniprogram-recycle-view/recycle-view.wxss",
|
||||
"./miniprogram_npm/wxml-to-canvas/index.wxss",
|
||||
"./page/API/components/set-tab-bar/set-tab-bar.wxss",
|
||||
"./app.wxss",
|
||||
"./common/common-skyline.wxss",
|
||||
"./common/reset.wxss",
|
||||
"./common/lib/weui.wxss",
|
||||
"./page/common/index-skyline.wxss"
|
||||
],
|
||||
"cwd": "../../../../examples/miniprogram-demo/miniprogram/",
|
||||
"lazyload": true,
|
||||
"replaceContent": {
|
||||
"./page/component/index.wxss": "@import \"../../common/reset.wxss\";\r\n@import \"../common/index-skyline.wxss\";\r\n\r\n.weui-agree__link {\r\n display: inline;\r\n color: #576b95;\r\n}\r\n\r\n[data-weui-theme=dark] .weui-agree__link {\r\n color: #7d90a9;\r\n}\r\n"
|
||||
},
|
||||
"debug": true
|
||||
}
|
File diff suppressed because one or more lines are too long
@ -2,7 +2,12 @@
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
console.log("---index.js----")
|
||||
|
||||
const WCC = require('./wcc_test')
|
||||
WCC.init();
|
||||
const WCSC = require('./wcsc_test')
|
||||
WCSC.init();
|
||||
|
||||
// const WCSC = require('./wcsc_test')
|
||||
const scanFiles = function(dir) {
|
||||
var results = []
|
||||
|
30
test/node-modules/utils/scan.js
Normal file
30
test/node-modules/utils/scan.js
Normal file
@ -0,0 +1,30 @@
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
|
||||
const scanFiles = function(dir) {
|
||||
var results = []
|
||||
var list = fs.readdirSync(dir)
|
||||
list.forEach(function(file) {
|
||||
// 排除static静态目录(可按你需求进行新增)
|
||||
// if (file === 'config.json') {
|
||||
// return false
|
||||
// }
|
||||
const filePath = dir + '/' + file
|
||||
var stat = fs.statSync(filePath)
|
||||
if (stat && stat.isDirectory()) {
|
||||
results = results.concat(scanFiles(filePath))
|
||||
} else {
|
||||
// 过滤后缀名(可按你需求进行新增)
|
||||
// if (path.extname(filePath) === '.json') {
|
||||
// results.push(path.resolve(__dirname, filePath))
|
||||
// }
|
||||
if (file === 'config.json') {
|
||||
results.push(path.resolve(__dirname, filePath))
|
||||
}
|
||||
}
|
||||
})
|
||||
return results
|
||||
}
|
||||
module.exports = {
|
||||
scanFiles
|
||||
}
|
@ -2,7 +2,9 @@
|
||||
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const scan = require('./utils/scan')
|
||||
const MODE = typeof nw === 'object' ? 'wine' : 'linux'
|
||||
|
||||
const wcc_options = []
|
||||
const wcc_options1 = {
|
||||
"files": ["./miniprogram_npm/miniprogram-barrage/index.wxml", "./miniprogram_npm/miniprogram-recycle-view/recycle-item.wxml", "./miniprogram_npm/miniprogram-recycle-view/recycle-view.wxml", "./miniprogram_npm/wxml-to-canvas/index.wxml", "./page/API/index.wxml", "./page/API/components/set-tab-bar/set-tab-bar.wxml", "./page/cloud/index.wxml", "./page/common/foot.wxml", "./page/common/head.wxml", "./page/component/index.wxml", "./page/extend/index.wxml"],
|
||||
@ -158,52 +160,38 @@ const wcc_options11 = {
|
||||
}
|
||||
wcc_options.push([wcc_options11, 11])
|
||||
|
||||
const test = async (options, id) => {
|
||||
console.log("============")
|
||||
const run = async (filepath) => {
|
||||
const configStr = fs.readFileSync(filepath).toString()
|
||||
const options = JSON.parse(configStr)
|
||||
options.cwd = path.join(__dirname, '../examples', options.cwd)
|
||||
const outputPath = path.dirname(filepath) + '/output'
|
||||
console.log('outputPath:', outputPath)
|
||||
try {
|
||||
fs.mkdirSync(path.resolve(__dirname, `${id}`))
|
||||
fs.mkdirSync(outputPath)
|
||||
} catch (err) {
|
||||
}
|
||||
process.env.WX_DEBUG_COMPILER_OUTPUT = path.resolve(__dirname, `${id}`)
|
||||
console.log(process.env.WX_DEBUG_COMPILER_OUTPUT)
|
||||
const wcc = require("wcc_" + MODE).wcc;
|
||||
// process.env.WX_DEBUG_COMPILER_OUTPUT = outputPath
|
||||
// console.log(process.env.WX_DEBUG_COMPILER_OUTPUT)
|
||||
const wcc = require(`./wcc_${MODE}/lib`).wcc;
|
||||
const wcc_result = await wcc(options);
|
||||
let result = wcc_result
|
||||
if (!!options.lazyloadConfig)
|
||||
if (!!options.lazyloadConfig){
|
||||
result = JSON.stringify(wcc_result, null, 4)
|
||||
fs.writeFileSync(path.resolve(__dirname, `${id}/wcc_node_${MODE}.txt`), result)
|
||||
fs.writeFileSync(path.resolve(outputPath, `wcc_node_${MODE}.json`), result)
|
||||
}else{
|
||||
fs.writeFileSync(path.resolve(outputPath, `wcc_node_${MODE}.js`), result)
|
||||
}
|
||||
console.log('run done')
|
||||
};
|
||||
|
||||
// (async () => {
|
||||
// for(let options of wcc_options){
|
||||
// await test(options[0], options[1]);
|
||||
// }
|
||||
// })();
|
||||
const scanFiles = function(dir) {
|
||||
var results = []
|
||||
var list = fs.readdirSync(dir)
|
||||
list.forEach(function(file) {
|
||||
// 排除static静态目录(可按你需求进行新增)
|
||||
// if (file === 'static') {
|
||||
// return false
|
||||
// }
|
||||
file = dir + '/' + file
|
||||
var stat = fs.statSync(file)
|
||||
if (stat && stat.isDirectory()) {
|
||||
results = results.concat(scanFiles(file))
|
||||
} else {
|
||||
// 过滤后缀名(可按你需求进行新增)
|
||||
console.log('path:', path)
|
||||
if (path.extname(file) === '.json') {
|
||||
results.push(path.resolve(__dirname, file))
|
||||
}
|
||||
}
|
||||
})
|
||||
return results
|
||||
}
|
||||
|
||||
|
||||
const init = ()=>{
|
||||
const files = scanFiles(__dirname)
|
||||
const files = scan.scanFiles(`${__dirname}/cases/wcc`)
|
||||
console.log(files)
|
||||
for (const file of files) {
|
||||
run(file)
|
||||
}
|
||||
}
|
||||
module.exports = {
|
||||
init
|
||||
|
@ -1,19 +1,69 @@
|
||||
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const scan = require('./utils/scan')
|
||||
const MODE = typeof nw === 'object' ? 'wine': 'linux'
|
||||
|
||||
const wcsc_options1 = {"pageCount":34,"files":["./packageComponent/pages/view/view/view.wxss","./packageComponent/pages/view/scroll-view/scroll-view.wxss","./packageComponent/pages/view/swiper/swiper.wxss","./packageComponent/pages/view/movable-view/movable-view.wxss","./packageComponent/pages/view/cover-view/cover-view.wxss","./packageComponent/pages/content/text/text.wxss","./packageComponent/pages/content/icon/icon.wxss","./packageComponent/pages/content/progress/progress.wxss","./packageComponent/pages/content/rich-text/rich-text.wxss","./packageComponent/pages/form/button/button.wxss","./packageComponent/pages/form/checkbox/checkbox.wxss","./packageComponent/pages/form/form/form.wxss","./packageComponent/pages/form/input/input.wxss","./packageComponent/pages/form/label/label.wxss","./packageComponent/pages/form/picker/picker.wxss","./packageComponent/pages/form/picker-view/picker-view.wxss","./packageComponent/pages/form/radio/radio.wxss","./packageComponent/pages/form/slider/slider.wxss","./packageComponent/pages/form/switch/switch.wxss","./packageComponent/pages/form/textarea/textarea.wxss","./packageComponent/pages/form/editor/editor.wxss","./packageComponent/pages/nav/navigator/navigator.wxss","./packageComponent/pages/media/image/image.wxss","./packageComponent/pages/media/video/video.wxss","./packageComponent/pages/media/camera/camera.wxss","./packageComponent/pages/media/live-pusher/live-pusher.wxss","./packageComponent/pages/media/live-player/live-player.wxss","./packageComponent/pages/map/map/map.wxss","./packageComponent/pages/canvas/canvas-2d/canvas-2d.wxss","./packageComponent/pages/canvas/webgl/webgl.wxss","./packageComponent/pages/open/ad/ad.wxss","./packageComponent/pages/open/open-data/open-data.wxss","./packageComponent/pages/open/web-view/web-view.wxss","./packageComponent/pages/obstacle-free/aria-component/aria-component.wxss","./app.wxss","./common/lib/weui.wxss","./miniprogram_npm/miniprogram-barrage/index.wxss","./miniprogram_npm/miniprogram-recycle-view/recycle-item.wxss","./miniprogram_npm/miniprogram-recycle-view/recycle-view.wxss","./miniprogram_npm/wxml-to-canvas/index.wxss","./page/API/index.wxss","./page/API/components/set-tab-bar/set-tab-bar.wxss","./page/cloud/index.wxss","./page/common/common.wxss","./page/common/index.wxss","./page/common/lib/weui.wxss","./page/component/index.wxss","./page/extend/index.wxss","./packageComponent/pages/form/editor/assets/iconfont.wxss"],"cwd":"/mnt/disk1/WeChatProjects/miniprogram-demo/miniprogram/","subPackage":"packageComponent/","replaceContent":{"./packageComponent/pages/camera-scan-code/camera-scan-code.wxss":"\n\ncamera {\n height: 250px;\n}\n\n.btn-area {\n margin-top: 0;\n}\n\nform {\n margin-top: 15px;\n}\n\n.weui-cell__bd {\n display: flex;\n justify-content: flex-start;\n align-items: center;\n padding: 10px 0;\n min-height: 30px;\n}"},"debug":true}
|
||||
const wcsc_options2 = {"pageCount":9,"files":["./page/component/index.wxss","./page/API/index.wxss","./page/cloud/index.wxss","./page/extend/index.wxss","./miniprogram_npm/miniprogram-barrage/index.wxss","./miniprogram_npm/miniprogram-recycle-view/recycle-item.wxss","./miniprogram_npm/miniprogram-recycle-view/recycle-view.wxss","./miniprogram_npm/wxml-to-canvas/index.wxss","./page/API/components/set-tab-bar/set-tab-bar.wxss","./app.wxss","./common/lib/weui.wxss","./page/common/common.wxss","./page/common/index.wxss","./page/common/lib/weui.wxss"],"cwd":"/mnt/disk1/WeChatProjects/miniprogram-demo/miniprogram/","replaceContent":{"./packageComponent/pages/camera-scan-code/camera-scan-code.wxss":"\n\ncamera {\n height: 250px;\n}\n\n.btn-area {\n margin-top: 0;\n}\n\nform {\n margin-top: 15px;\n}\n\n.weui-cell__bd {\n display: flex;\n justify-content: flex-start;\n align-items: center;\n padding: 10px 0;\n min-height: 30px;\n}"},"debug":true}
|
||||
|
||||
const test = async (options, id) => {
|
||||
console.log("============", id)
|
||||
try{
|
||||
fs.mkdirSync(path.resolve(__dirname, `${id}`))
|
||||
}catch(ignore){}
|
||||
const wcsc = require("wcc_" + MODE).wcsc;
|
||||
const run = async (filepath) => {
|
||||
const configStr = fs.readFileSync(filepath).toString()
|
||||
const options = JSON.parse(configStr)
|
||||
options.cwd = path.join(path.dirname(filepath), options.cwd)
|
||||
console.log('cwd:', options.cwd)
|
||||
const outputPath = path.dirname(filepath) + '/output'
|
||||
console.log('outputPath:', outputPath)
|
||||
try {
|
||||
fs.mkdirSync(outputPath)
|
||||
} catch (err) {
|
||||
}
|
||||
// process.env.WX_DEBUG_COMPILER_OUTPUT = outputPath
|
||||
// console.log(process.env.WX_DEBUG_COMPILER_OUTPUT)
|
||||
const wcsc = require(`./wcc_${MODE}/lib`).wcsc;
|
||||
const wcsc_result = await wcsc(options);
|
||||
fs.writeFileSync(path.resolve(__dirname, `${id}/wcsc_node_${MODE}.txt`), JSON.stringify(wcsc_result, null, 4))
|
||||
let result = wcsc_result
|
||||
if (options.lazyload){
|
||||
result = JSON.stringify(wcsc_result, null, 4)
|
||||
fs.writeFileSync(path.resolve(outputPath, `wcsc_node_${MODE}.json`), result)
|
||||
}else{
|
||||
fs.writeFileSync(path.resolve(outputPath, `wcsc_node_${MODE}.js`), result)
|
||||
}
|
||||
console.log('run done')
|
||||
};
|
||||
test(wcsc_options1, 1);
|
||||
test(wcsc_options2, 2);
|
||||
|
||||
|
||||
const scanFiles = function(dir) {
|
||||
var results = []
|
||||
var list = fs.readdirSync(dir)
|
||||
list.forEach(function(file) {
|
||||
// 排除static静态目录(可按你需求进行新增)
|
||||
// if (file === 'config.json') {
|
||||
// return false
|
||||
// }
|
||||
const filePath = dir + '/' + file
|
||||
var stat = fs.statSync(filePath)
|
||||
if (stat && stat.isDirectory()) {
|
||||
results = results.concat(scanFiles(filePath))
|
||||
} else {
|
||||
// 过滤后缀名(可按你需求进行新增)
|
||||
// if (path.extname(filePath) === '.json') {
|
||||
// results.push(path.resolve(__dirname, filePath))
|
||||
// }
|
||||
if (file === 'config.json') {
|
||||
results.push(path.resolve(__dirname, filePath))
|
||||
}
|
||||
}
|
||||
})
|
||||
return results
|
||||
}
|
||||
const init = ()=>{
|
||||
const files = scan.scanFiles(`${__dirname}/cases/wcsc`)
|
||||
console.log(files)
|
||||
for (const file of files) {
|
||||
run(file)
|
||||
}
|
||||
}
|
||||
module.exports = {
|
||||
init
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user