mirror of
https://github.com/msojocs/wx-compiler.git
synced 2025-07-19 00:00:04 +08:00
87 lines
2.6 KiB
JavaScript
87 lines
2.6 KiB
JavaScript
|
|
const path = require("path");
|
|
const fs = require("fs");
|
|
const { spawn } = require("child_process");
|
|
|
|
const wcsc = (args, projectPath, outputPath = undefined) => {
|
|
const node_exec = spawn(
|
|
path.resolve(__dirname, "../../nodejs/wcsc"),
|
|
args,
|
|
{
|
|
cwd: projectPath,
|
|
env: {
|
|
WX_DEBUG_COMPILER_OUTPUT: outputPath,
|
|
},
|
|
// stdio: 'inherit'
|
|
}
|
|
);
|
|
const spwanData = [],
|
|
errData = [];
|
|
node_exec.stdout.on("data", (e) => {
|
|
spwanData.push(e);
|
|
// console.log(e.toString())
|
|
});
|
|
node_exec.stderr.on("data", (e) => {
|
|
errData.push(e);
|
|
// console.log(e.toString())
|
|
});
|
|
return new Promise((resolve, reject) => {
|
|
node_exec.on("close", (n) => {
|
|
outputPath && require('fs').writeFileSync(`${outputPath}/linux_err.js`, Buffer.concat(errData).toString())
|
|
|
|
if (0 === n) {
|
|
let result = Buffer.concat(spwanData).toString();
|
|
// result = JSON.parse(result);
|
|
resolve(result);
|
|
} else {
|
|
// process.stderr.write(Buffer.concat(errData).toString());
|
|
// process.stderr.write(Buffer.concat(spwanData).toString());
|
|
reject(n);
|
|
}
|
|
});
|
|
});
|
|
};
|
|
const wcc = (args, projectPath, outputPath = undefined) => {
|
|
const node_exec = spawn(
|
|
path.resolve(__dirname, "../../nodejs/wcc"),
|
|
args,
|
|
{
|
|
cwd: projectPath,
|
|
env: {
|
|
WX_DEBUG_COMPILER_OUTPUT: outputPath,
|
|
},
|
|
// stdio: 'inherit'
|
|
}
|
|
);
|
|
const spwanData = [],
|
|
errData = [];
|
|
node_exec.stdout.on("data", (e) => {
|
|
spwanData.push(e);
|
|
// console.log(e.toString())
|
|
});
|
|
node_exec.stderr.on("data", (e) => {
|
|
errData.push(e);
|
|
// console.log(e.toString())
|
|
});
|
|
return new Promise((resolve, reject) => {
|
|
node_exec.on("close", (n) => {
|
|
// console.log("node n: ", n);
|
|
outputPath && require('fs').writeFileSync(`${outputPath}/linux_err.js`, Buffer.concat(errData).toString())
|
|
if (0 === n) {
|
|
let result = Buffer.concat(spwanData).toString();
|
|
// process.stdout.write(result);
|
|
// result = JSON.parse(result);
|
|
resolve(result);
|
|
} else {
|
|
process.stderr.write(Buffer.concat(errData).toString());
|
|
// process.stderr.write(Buffer.concat(spwanData).toString());
|
|
reject(n);
|
|
}
|
|
});
|
|
});
|
|
};
|
|
|
|
module.exports= {
|
|
wcsc,
|
|
wcc
|
|
} |