Skip to content

Commit

Permalink
fix(update): 修复 update 本地 envConfig 文件时多行匹配处理错误的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
renxia committed May 16, 2024
1 parent 3e3e203 commit 1967763
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
},
"devDependencies": {
"@lzwme/fed-lint-helper": "^2.6.0",
"@types/node": "^20.12.8",
"@types/node": "^20.12.12",
"base64-js": "^1.5.1",
"crypto-js": "^4.2.0",
"husky": "^9.0.11",
Expand Down
8 changes: 4 additions & 4 deletions src/lib/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @Author: renxia
* @Date: 2024-01-11 13:38:34
* @LastEditors: renxia
* @LastEditTime: 2024-05-07 09:34:05
* @LastEditTime: 2024-05-16 13:39:24
* @Description:
*/
import fs from 'node:fs';
Expand Down Expand Up @@ -56,6 +56,7 @@ export async function updateToQlEnvConfig(envConfig: EnvConfig, updateEnvValue?:

params.id = item.id;
params.remarks = desc || item.remarks || '';
item.value = params.value;
r = await ql.updateEnv(params as QLEnvItem);
} else {
r = await ql.addEnv([params as QLEnvItem]);
Expand All @@ -64,7 +65,6 @@ export async function updateToQlEnvConfig(envConfig: EnvConfig, updateEnvValue?:
const isSuccess = r.code === 200;
const count = params.value.includes(sep) ? params.value.trim().split(sep).length : 1;
logger.info(`${item ? green('更新') : magenta('新增')}QL环境变量[${green(name)}][${count}]`, isSuccess ? '成功' : r);
if (isSuccess && item) item.value = value;

return value;
}
Expand All @@ -77,7 +77,7 @@ export async function updateEnvConfigFile(envConfig: EnvConfig, updateEnvValue:
const isExist = content.includes(`export ${name}=`);

if (isExist) {
const oldValue = content.match(new RegExp(`export ${name}="(.*)"`))?.[1] || '';
const oldValue = content.match(new RegExp(`export ${name}="([^"]+)"`))?.[1] || '';

if (oldValue.includes(value)) {
logger.log(`[UpdateEnv]${color.cyan(name)} 已存在`, color.gray(value));
Expand All @@ -93,7 +93,7 @@ export async function updateEnvConfigFile(envConfig: EnvConfig, updateEnvValue:
value = updateEnvValueByRegExp(/##([a-z0-9_\-*]+)/i, envConfig, value);
}

content = content.replace(new RegExp(`export ${name}=.*`, 'g'), `export ${name}="${value}"`);
content = content.replace(`export ${name}="${oldValue}"`, `export ${name}="${value}"`);
} else {
if (desc) content += `\n# ${desc}`;
content += `\nexport ${name}="${value}"`;
Expand Down

0 comments on commit 1967763

Please sign in to comment.