mirror of
https://github.com/whyour/qinglong.git
synced 2026-06-30 20:35:09 +08:00
Javascript 和 Python 增加内置函数 QLAPI.notify
This commit is contained in:
@@ -1,6 +1,13 @@
|
||||
const { execSync } = require('child_process');
|
||||
const { sendNotify } = require('./notify.js');
|
||||
require(`./env.js`);
|
||||
|
||||
function initGlobal() {
|
||||
global.QLAPI = {
|
||||
notify: sendNotify,
|
||||
};
|
||||
}
|
||||
|
||||
function expandRange(rangeStr, max) {
|
||||
const tempRangeStr = rangeStr
|
||||
.trim()
|
||||
@@ -19,6 +26,7 @@ function expandRange(rangeStr, max) {
|
||||
|
||||
function run() {
|
||||
try {
|
||||
// TODO: big size
|
||||
const splitStr = '__sitecustomize__';
|
||||
let command = `bash -c "source ${process.env.taskBefore} ${process.env.fileName}`;
|
||||
if (process.env.task_before) {
|
||||
@@ -31,17 +39,17 @@ function run() {
|
||||
},
|
||||
);
|
||||
const [output, envStr] = res.split(splitStr);
|
||||
const json = JSON.parse(envStr.trim());
|
||||
for (const key in json) {
|
||||
process.env[key] = json[key];
|
||||
const newEnvObject = JSON.parse(envStr.trim());
|
||||
for (const key in newEnvObject) {
|
||||
process.env[key] = newEnvObject[key];
|
||||
}
|
||||
console.log(output);
|
||||
} catch (error) {
|
||||
console.log(`run task before error `, error);
|
||||
console.log(`run task before error: `, error.message);
|
||||
}
|
||||
|
||||
if (process.env.envParam && process.env.numParam) {
|
||||
const { envParam, numParam } = process.env;
|
||||
const { envParam, numParam } = process.env;
|
||||
if (envParam && numParam) {
|
||||
const array = (process.env[envParam] || '').split('&');
|
||||
const runArr = expandRange(numParam, array.length);
|
||||
const arrayRun = runArr.map((i) => array[i - 1]);
|
||||
@@ -50,4 +58,5 @@ function run() {
|
||||
}
|
||||
}
|
||||
|
||||
initGlobal();
|
||||
run();
|
||||
|
||||
@@ -3,6 +3,18 @@ import re
|
||||
import env
|
||||
import subprocess
|
||||
import json
|
||||
import builtins
|
||||
from notify import send
|
||||
|
||||
|
||||
class BaseApi:
|
||||
def notify(self, *args, **kwargs):
|
||||
return send(*args, **kwargs)
|
||||
|
||||
|
||||
def init_global():
|
||||
QLAPI = BaseApi()
|
||||
builtins.QLAPI = QLAPI
|
||||
|
||||
|
||||
def try_parse_int(value):
|
||||
@@ -66,4 +78,5 @@ def run():
|
||||
os.environ[env_param] = env_str
|
||||
|
||||
|
||||
init_global()
|
||||
run()
|
||||
|
||||
@@ -27,8 +27,6 @@ ql_static_repo=$dir_repo/static
|
||||
## 文件
|
||||
file_config_sample=$dir_sample/config.sample.sh
|
||||
file_env=$dir_preload/env.sh
|
||||
js_file_env=$dir_preload/env.js
|
||||
py_file_env=$dir_preload/env.py
|
||||
preload_js_file=$dir_preload/sitecustomize.js
|
||||
file_sharecode=$dir_config/sharecode.sh
|
||||
file_config_user=$dir_config/config.sh
|
||||
|
||||
Reference in New Issue
Block a user