mirror of
https://github.com/msojocs/wx-compiler.git
synced 2025-07-19 00:00:04 +08:00
perf: node modules
This commit is contained in:
parent
26035ed77c
commit
e0b3276eb3
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,4 +1,4 @@
|
|||||||
node_modules
|
node_modules
|
||||||
test/**/*.json
|
test/**/*-output.json
|
||||||
test/**/*-output.js
|
test/**/*-output.js
|
||||||
nwjs
|
nwjs
|
5
package-lock.json
generated
5
package-lock.json
generated
@ -1,9 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "compiler",
|
"name": "wx_compiler",
|
||||||
|
"version": "1.0",
|
||||||
"lockfileVersion": 2,
|
"lockfileVersion": 2,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
|
"name": "wx_compiler",
|
||||||
|
"version": "1.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"miniprogram-compiler": "^0.2.1"
|
"miniprogram-compiler": "^0.2.1"
|
||||||
},
|
},
|
||||||
|
14
package.json
14
package.json
@ -1,6 +1,18 @@
|
|||||||
{
|
{
|
||||||
|
"forceVendor": true,
|
||||||
|
"name": "wx_compiler",
|
||||||
|
"main": "test/node-modules/index.html",
|
||||||
|
"productName": "wx_compiler",
|
||||||
|
"appname": "wx_compiler",
|
||||||
|
"version": "1.0",
|
||||||
|
"chromium-args": "--mixed-context",
|
||||||
|
"window": {
|
||||||
|
"frame": true
|
||||||
|
},
|
||||||
|
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "mocha --reporter-option maxDiffSize=1e9"
|
"test": "mocha --reporter-option maxDiffSize=1e9",
|
||||||
|
"start": "nw ./test/node-modules"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"miniprogram-compiler": "^0.2.1"
|
"miniprogram-compiler": "^0.2.1"
|
||||||
|
2
test/node-modules/.gitignore
vendored
2
test/node-modules/.gitignore
vendored
@ -1,2 +0,0 @@
|
|||||||
data
|
|
||||||
*.txt
|
|
14
test/node-modules/cases/wcc/case1/config.json
Normal file
14
test/node-modules/cases/wcc/case1/config.json
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
"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"],
|
||||||
|
"debugWXS": false,
|
||||||
|
"debug": true,
|
||||||
|
"genfuncname": "$gwx",
|
||||||
|
"isCut": true,
|
||||||
|
"wxmlCompileConfig": "9>_<1027./miniprogram_npm/miniprogram-barrage/index.wxml>_<10270>_<1027./miniprogram_npm/miniprogram-recycle-view/recycle-item.wxml>_<10270>_<1027./miniprogram_npm/miniprogram-recycle-view/recycle-view.wxml>_<10270>_<1027./miniprogram_npm/wxml-to-canvas/index.wxml>_<10270>_<1027./page/API/index.wxml>_<10271>_<1027set-tab-bar>_<1027./page/API/components/set-tab-bar/set-tab-bar.wxml>_<10270>_<1027./page/cloud/index.wxml>_<10270>_<1027./page/component/index.wxml>_<10270>_<1027./page/extend/index.wxml>_<10270",
|
||||||
|
"wxmlCompileConfigSplit": ">_<1027",
|
||||||
|
"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/",
|
||||||
|
"lazyloadConfig": ""
|
||||||
|
}
|
@ -5,9 +5,12 @@
|
|||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<button onclick="location.reload();">刷新</button>
|
<button onclick="location.reload();">刷新</button>
|
||||||
|
<pre id="result">
|
||||||
|
|
||||||
|
</pre>
|
||||||
|
<!-- <script src="index.js" ></script> -->
|
||||||
<script>
|
<script>
|
||||||
require('./wcc_test')
|
require('./index')
|
||||||
require('./wcsc_test')
|
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
@ -1,3 +1,36 @@
|
|||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
require('./wcc_test')
|
const fs = require('fs')
|
||||||
require('./wcsc_test')
|
const path = require('path')
|
||||||
|
console.log("---index.js----")
|
||||||
|
const WCC = require('./wcc_test')
|
||||||
|
// const WCSC = require('./wcsc_test')
|
||||||
|
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 = ()=>{
|
||||||
|
console.log(__dirname)
|
||||||
|
const files = scanFiles(__dirname)
|
||||||
|
console.log(files)
|
||||||
|
}
|
||||||
|
init()
|
@ -1,16 +0,0 @@
|
|||||||
{
|
|
||||||
"forceVendor": true,
|
|
||||||
"name": "nw_test",
|
|
||||||
"main": "index.html",
|
|
||||||
"productName": "test",
|
|
||||||
"appname": "nw_test",
|
|
||||||
"version": "1.0",
|
|
||||||
"window": {
|
|
||||||
"frame": true
|
|
||||||
},
|
|
||||||
"chromium-args": "--no-sandbox --ignore-gpu-blacklist --register-pepper-plugins=./node_modules/mpv.js/build/Release/mpvjs.node;application/x-mpvjs",
|
|
||||||
"dependencies": {
|
|
||||||
"mpv.js": "^0.3.0",
|
|
||||||
"spdlog": "^0.13.6"
|
|
||||||
}
|
|
||||||
}
|
|
@ -174,8 +174,37 @@ const test = async (options, id) => {
|
|||||||
fs.writeFileSync(path.resolve(__dirname, `${id}/wcc_node_${MODE}.txt`), result)
|
fs.writeFileSync(path.resolve(__dirname, `${id}/wcc_node_${MODE}.txt`), result)
|
||||||
};
|
};
|
||||||
|
|
||||||
(async () => {
|
// (async () => {
|
||||||
for(let options of wcc_options){
|
// for(let options of wcc_options){
|
||||||
await test(options[0], options[1]);
|
// 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)
|
||||||
|
console.log(files)
|
||||||
|
}
|
||||||
|
module.exports = {
|
||||||
|
init
|
||||||
|
}
|
BIN
test/node-modules/wcc_wine/build/Release/wcc.node
Normal file
BIN
test/node-modules/wcc_wine/build/Release/wcc.node
Normal file
Binary file not shown.
BIN
test/node-modules/wcc_wine/build/Release/wcsc.node
Normal file
BIN
test/node-modules/wcc_wine/build/Release/wcsc.node
Normal file
Binary file not shown.
4
test/node-modules/wcc_wine/lib/index.js
Normal file
4
test/node-modules/wcc_wine/lib/index.js
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
module.exports = {
|
||||||
|
wcc: require('./wcc'),
|
||||||
|
wcsc: require('./wcsc')
|
||||||
|
}
|
1134
test/node-modules/wcc_wine/lib/util.js
Normal file
1134
test/node-modules/wcc_wine/lib/util.js
Normal file
File diff suppressed because it is too large
Load Diff
94
test/node-modules/wcc_wine/lib/wcc.js
Normal file
94
test/node-modules/wcc_wine/lib/wcc.js
Normal file
@ -0,0 +1,94 @@
|
|||||||
|
const util = require('./util')
|
||||||
|
const path = require('path')
|
||||||
|
|
||||||
|
let wcc
|
||||||
|
|
||||||
|
function loadWccAddon() {
|
||||||
|
if (wcc) return
|
||||||
|
wcc = require('../build/Release/wcc.node')
|
||||||
|
}
|
||||||
|
|
||||||
|
const fs = util.fs
|
||||||
|
|
||||||
|
exports = async function (options) {
|
||||||
|
|
||||||
|
loadWccAddon()
|
||||||
|
|
||||||
|
if (!options) throw Error('options is required')
|
||||||
|
|
||||||
|
const lazyload = !!options.lazyloadConfig
|
||||||
|
|
||||||
|
options = Object.assign(
|
||||||
|
{
|
||||||
|
files: [],
|
||||||
|
contents: [],
|
||||||
|
replaceContent: {},
|
||||||
|
verbose: false,
|
||||||
|
debug: false,
|
||||||
|
debugWXS: false,
|
||||||
|
showNewTree: false,
|
||||||
|
isPlugin: false,
|
||||||
|
addTestAttre: false,
|
||||||
|
independent: false,
|
||||||
|
genfuncname: '$gwx',
|
||||||
|
isCut: false,
|
||||||
|
cwd: process.cwd,
|
||||||
|
debug: false,
|
||||||
|
lazyload,
|
||||||
|
lazyloadConfig: '',
|
||||||
|
},
|
||||||
|
options,
|
||||||
|
)
|
||||||
|
|
||||||
|
return new Promise(async (resolve, reject) => {
|
||||||
|
let st = Date.now()
|
||||||
|
|
||||||
|
// 获取文件内容
|
||||||
|
if (!options.contents.length) {
|
||||||
|
const tasks = options.files.map((file) => {
|
||||||
|
if (typeof options.replaceContent[file] === 'string') {
|
||||||
|
return options.replaceContent[file]
|
||||||
|
}
|
||||||
|
return fs.readFile(path.resolve(options.cwd, file), 'utf8')
|
||||||
|
})
|
||||||
|
options.contents = await Promise.all(tasks) || []
|
||||||
|
}
|
||||||
|
// console.log('wcc get files', Date.now() - st, options.contents)
|
||||||
|
let result
|
||||||
|
try {
|
||||||
|
result = wcc(options)
|
||||||
|
} catch(errmsg) {
|
||||||
|
reject(new Error(errmsg))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('wcc get compile', Date.now() - st)
|
||||||
|
if (options.output) {
|
||||||
|
const output = path.resolve(options.cwd, options.output)
|
||||||
|
const dir = path.dirname(output)
|
||||||
|
if (lazyload) {
|
||||||
|
// lazyload 为 true时,wcc 返回值是个对象, 需要序列化一下
|
||||||
|
result = JSON.stringify(result)
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
await fs.stat(dir)
|
||||||
|
} catch (e) {
|
||||||
|
await fs.mkdir(dir, {
|
||||||
|
recursive: true,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
await fs.writeFile(output, result, 'utf8')
|
||||||
|
}
|
||||||
|
console.log('wcc get output', Date.now() - st)
|
||||||
|
resolve(result)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
Object.defineProperty(exports, 'version', {
|
||||||
|
get() {
|
||||||
|
loadWccAddon()
|
||||||
|
return wcc.version
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
module.exports = exports
|
92
test/node-modules/wcc_wine/lib/wcsc.js
Normal file
92
test/node-modules/wcc_wine/lib/wcsc.js
Normal file
@ -0,0 +1,92 @@
|
|||||||
|
const util = require('./util')
|
||||||
|
const path = require('path')
|
||||||
|
const fs = util.fs
|
||||||
|
|
||||||
|
let wcsc
|
||||||
|
|
||||||
|
function loadWcscAddon() {
|
||||||
|
if (wcsc) return
|
||||||
|
wcsc = require('../build/Release/wcsc.node')
|
||||||
|
}
|
||||||
|
|
||||||
|
function tranWcscResultToObject(resultStr) {
|
||||||
|
const resultArr = resultStr.split('=')
|
||||||
|
const result = {}
|
||||||
|
for (let i = 0, len = resultArr.length; i < len && resultArr[i + 1]; i += 2) {
|
||||||
|
result[resultArr[i]] = resultArr[i + 1]
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
exports = async function (options) {
|
||||||
|
|
||||||
|
loadWcscAddon()
|
||||||
|
|
||||||
|
if (!options) throw Error('options is required')
|
||||||
|
|
||||||
|
// avoid undefined or null
|
||||||
|
if (typeof options.subPackage !== 'string') {
|
||||||
|
delete options.subPackage
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof options.lazyload !== 'boolean') {
|
||||||
|
delete options.lazyload
|
||||||
|
}
|
||||||
|
|
||||||
|
options = Object.assign(
|
||||||
|
{
|
||||||
|
files: [],
|
||||||
|
contents: [],
|
||||||
|
pageCount: 0,
|
||||||
|
cwd: process.cwd,
|
||||||
|
replaceContent: {},
|
||||||
|
debug: false,
|
||||||
|
classPrefix: '',
|
||||||
|
lazyload: false,
|
||||||
|
},
|
||||||
|
options,
|
||||||
|
)
|
||||||
|
|
||||||
|
if (!options.contents.length) {
|
||||||
|
const tasks = options.files.map((file) => {
|
||||||
|
if (typeof options.replaceContent[file] === 'string') {
|
||||||
|
return options.replaceContent[file]
|
||||||
|
}
|
||||||
|
return fs.readFile(path.resolve(options.cwd, file), 'utf8')
|
||||||
|
})
|
||||||
|
options.contents = await Promise.all(tasks) || []
|
||||||
|
}
|
||||||
|
|
||||||
|
let wccResult
|
||||||
|
try {
|
||||||
|
wccResult = wcsc(options)
|
||||||
|
} catch (errmsg) {
|
||||||
|
throw new Error(errmsg)
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = options.lazyload ? wccResult : tranWcscResultToObject(wccResult)
|
||||||
|
|
||||||
|
if (options.output) {
|
||||||
|
const output = path.resolve(options.cwd, options.output)
|
||||||
|
const dir = path.dirname(output)
|
||||||
|
try {
|
||||||
|
await fs.stat(dir)
|
||||||
|
} catch (e) {
|
||||||
|
await fs.mkdir(dir, {
|
||||||
|
recursive: true,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
await fs.writeFile(output, JSON.stringify(result, null, 2), 'utf8')
|
||||||
|
}
|
||||||
|
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
Object.defineProperty(exports, 'version', {
|
||||||
|
get() {
|
||||||
|
loadWcscAddon()
|
||||||
|
return wcsc.version
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
module.exports = exports
|
18
test/node-modules/wcc_wine/package.json
Normal file
18
test/node-modules/wcc_wine/package.json
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
{
|
||||||
|
"name": "miniprogram-wcc",
|
||||||
|
"version": "0.0.1",
|
||||||
|
"description": "WCC node C++ addon",
|
||||||
|
"main": "lib/index.js",
|
||||||
|
"scripts": {
|
||||||
|
"rebuild": "node-gyp rebuild",
|
||||||
|
"build": "node-gyp build",
|
||||||
|
"test": "node ./test/wcc/index && node ./test/wcsc/index",
|
||||||
|
"format": "prettier *.js test/*.js scripts/*.js --write"
|
||||||
|
},
|
||||||
|
"author": "coverguo",
|
||||||
|
"license": "MIT",
|
||||||
|
"devDependencies": {
|
||||||
|
"licia": "^1.21.2",
|
||||||
|
"node-gyp": "^7.0.0"
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user