mirror of
https://github.com/msojocs/wx-compiler.git
synced 2025-07-19 00:00:04 +08:00
40 lines
1.3 KiB
JavaScript
Executable File
40 lines
1.3 KiB
JavaScript
Executable File
#!/usr/bin/env node
|
|
|
|
const fs = require('fs')
|
|
const path = require('path')
|
|
const scan = require('./utils/scan')
|
|
const MODE = typeof nw === 'object' ? 'wine' : 'linux'
|
|
const COMPILER = require(`./wcc_${MODE}/lib`)
|
|
|
|
|
|
const init = async()=>{
|
|
const configPaths = scan.scanFiles(`${__dirname}/cases/wcc`);
|
|
for (const configPath of configPaths) {
|
|
const casePath = path.dirname(configPath);
|
|
const caseName = path.basename(casePath);
|
|
const type = path.basename(path.dirname(casePath));
|
|
const config = JSON.parse(fs.readFileSync(configPath).toString());
|
|
// const projectPath = path.join(casePath, config.cwd);
|
|
const storagePath = path.join(casePath, `output`);
|
|
config.cwd = path.join(configPath, config.cwd);
|
|
if(!fs.existsSync(config.cwd)){
|
|
throw new Error('cwd not exists!')
|
|
}
|
|
|
|
try {
|
|
fs.mkdirSync(storagePath, { recursive: true });
|
|
} catch (error) {}
|
|
|
|
let nodeResult = await COMPILER.wcc(config);
|
|
|
|
if(!!config.lazyloadConfig){
|
|
fs.writeFileSync(`${storagePath}/wine-output.json`, JSON.stringify(nodeResult, null, 4));
|
|
}else{
|
|
// nodeResult = nodeResult.substring(0, nodeResult.length - 1);
|
|
fs.writeFileSync(`${storagePath}/wine-output.js`, nodeResult);
|
|
}
|
|
}
|
|
}
|
|
module.exports = {
|
|
init
|
|
} |