修复 js py 变量分割

This commit is contained in:
whyour 2024-07-13 23:53:59 +08:00
parent a2812d9c03
commit 738fe04ce4
2 changed files with 19 additions and 7 deletions

View File

@ -210,13 +210,18 @@ export default class EnvService {
.replace(/'/g, "'\\''") .replace(/'/g, "'\\''")
.trim(); .trim();
env_string += `export ${key}='${value}'\n`; env_string += `export ${key}='${value}'\n`;
const _env_value = `'${group const _env_value = `${group
.map((x) => x.value) .map((x) => x.value)
.join('&') .join('&')
.replace(/\\/g, '\\\\') .replace(/\\/g, '\\\\')}`;
.replace(/'/g, "\\'")}'`; js_env_string += `process.env.${key}=\`${_env_value.replace(
js_env_string += `process.env.${key}=${_env_value};\n`; /\`/g,
py_env_string += `os.environ['${key}']=${_env_value}\n`; '\\`',
)}\`;\n`;
py_env_string += `os.environ['${key}']='''${_env_value.replace(
/\'/g,
"\\'",
)}'''\n`;
} }
} }
} }

View File

@ -87,8 +87,11 @@ check_server() {
} }
env_str_to_array() { env_str_to_array() {
. $file_env
local IFS="&" local IFS="&"
read -ra array <<<"${!env_param}" read -ra array <<<"${!env_param}"
array_length=${#array[@]}
clear_env
} }
clear_non_sh_env() { clear_non_sh_env() {
@ -123,7 +126,7 @@ handle_env_split() {
fi fi
env_str_to_array env_str_to_array
local tempArr=$(echo $num_param | sed "s/-max/-${#array[@]}/g" | sed "s/max-/${#array[@]}-/g" | perl -pe "s|(\d+)(-\|~\|_)(\d+)|{\1..\3}|g") local tempArr=$(echo $num_param | sed "s/-max/-${array_length}/g" | sed "s/max-/${array_length}-/g" | perl -pe "s|(\d+)(-\|~\|_)(\d+)|{\1..\3}|g")
local runArr=($(eval echo $tempArr)) local runArr=($(eval echo $tempArr))
array_run=($(awk -v RS=' ' '!a[$1]++' <<<${runArr[@]})) array_run=($(awk -v RS=' ' '!a[$1]++' <<<${runArr[@]}))
} }
@ -229,16 +232,20 @@ main() {
isJsOrPythonFile="true" isJsOrPythonFile="true"
fi fi
if [[ -f $file_env ]]; then if [[ -f $file_env ]]; then
get_env_array
if [[ $isJsOrPythonFile == 'true' ]]; then if [[ $isJsOrPythonFile == 'true' ]]; then
export NODE_OPTIONS="${NODE_OPTIONS} -r ${preload_js_file}" export NODE_OPTIONS="${NODE_OPTIONS} -r ${preload_js_file}"
export PYTHONPATH="${PYTHONPATH}:${dir_preload}" export PYTHONPATH="${PYTHONPATH}:${dir_preload}"
else else
get_env_array
. $file_env . $file_env
fi fi
fi fi
if [[ $1 == *.js ]] || [[ $1 == *.py ]] || [[ $1 == *.pyc ]] || [[ $1 == *.sh ]] || [[ $1 == *.ts ]]; then if [[ $1 == *.js ]] || [[ $1 == *.py ]] || [[ $1 == *.pyc ]] || [[ $1 == *.sh ]] || [[ $1 == *.ts ]]; then
if [[ $1 == *.sh ]]; then
timeoutCmd=""
fi
case $# in case $# in
1) 1)
run_normal "$1" run_normal "$1"