mirror of
https://github.com/whyour/qinglong.git
synced 2026-07-01 04:40:38 +08:00
JavaScript 和 Python 执行脚本前执行 task_before
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
const { execSync } = require('child_process');
|
||||
require(`./env.js`);
|
||||
|
||||
function expandRange(rangeStr, max) {
|
||||
@@ -17,6 +18,28 @@ function expandRange(rangeStr, max) {
|
||||
}
|
||||
|
||||
function run() {
|
||||
try {
|
||||
const splitStr = '__sitecustomize__';
|
||||
let command = `bash -c "source ${process.env.taskBefore} ${process.env.fileName}`;
|
||||
if (process.env.task_before) {
|
||||
command = `${command} && echo -e '执行前置命令\n' && eval "${process.env.task_before}" && echo -e '\n执行前置命令结束\n'`;
|
||||
}
|
||||
const res = execSync(
|
||||
`${command} && echo "${splitStr}" && NODE_OPTIONS= node -p 'JSON.stringify(process.env)'"`,
|
||||
{
|
||||
encoding: 'utf-8',
|
||||
},
|
||||
);
|
||||
const [output, envStr] = res.split(splitStr);
|
||||
const json = JSON.parse(envStr.trim());
|
||||
for (const key in json) {
|
||||
process.env[key] = json[key];
|
||||
}
|
||||
console.log(output);
|
||||
} catch (error) {
|
||||
console.log(`run task before error `, error);
|
||||
}
|
||||
|
||||
if (process.env.envParam && process.env.numParam) {
|
||||
const { envParam, numParam } = process.env;
|
||||
const array = (process.env[envParam] || '').split('&');
|
||||
|
||||
Reference in New Issue
Block a user