From c27047b34864cb9c10c927806ec14568af9b734e Mon Sep 17 00:00:00 2001 From: Luk Date: Sat, 7 Dec 2024 19:43:20 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20event.emit('ENVAR=5FUPDATE?= =?UTF-8?q?D',=20{envarFile})?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- envar-tool.js | 41 +---------------------------------------- 1 file changed, 1 insertion(+), 40 deletions(-) diff --git a/envar-tool.js b/envar-tool.js index 4c7a4b5..647f544 100644 --- a/envar-tool.js +++ b/envar-tool.js @@ -2,7 +2,6 @@ const fs = require('fs') const path = require('path') const chokidar = require('chokidar') const assign_deep = require('assign-deep') -const readlineSync = require('readline-sync') //const deepmerge = require('deepmerge') // https://github.com/jonschlinkert/assign-deep // 类似 Object.assign 直接赋值到第一个对象里。只下载2个包。assign 优选。 @@ -26,51 +25,13 @@ module.exports = { // 目前的解决方案里,已通过 base2app 参数来确保只在发送给前端时才设置 undefined,但为防万一,在这里通过 JSON.stringify 确保删除了 undefined assign_deep(rawEnvar, JSON.parse(JSON.stringify(newEnvar))) console.log(`envarTool.start_watching: OK reload ${onpath}`) + globalthis.wo?.eventCenter?.emit?.('ENVAR_UPDATED', { envarFile: onpath }) } catch (expt) { console.log(`envarTool.start_watching: Fail reload ${onpath}`) } }) }, - get_simsimPath ({ envarFiles = [], readable = false, readPrompt = '' }) { - let simsimPath - // 用户自己定义的优先 - for (let configFile of envarFiles) { - try { - const envar = require(path.resolve(configFile)) - if (envar?.simsimPath) { - try { - require(path.resolve(envar.simsimPath)) - simsimPath = envar?.simsimPath - } catch (expt) { - console.log('!!! ' + path.resolve(envar.simsimPath) + ' is invalid.') - } - } - } catch (expt) { - console.log('!!! ' + path.resolve(configFile) + ' is malformed.') - } - } - // 其次检测是否已安装 - if (!simsimPath) { - module.paths.forEach((modulesPath) => { - if (fs.existsSync(`${modulesPath}/sesame-basic`)) { - simsimPath = `${modulesPath}/sesame-basic` - } - }) - } - // 最后等待用户输入 - while (!simsimPath && readable) { - simsimPath = readlineSync.question(readPrompt) - try { - require(path.resolve(simsimPath)) - } catch (expt) { - console.log('!!! ' + path.resolve(simsimPath) + ' is invalid.') - simsimPath = '' - } - } - return simsimPath - }, - /** 合并 envar files 和 commander parameters 中的环境变量。 * @param envarFiles: * - 字符串: 导入文件,内容应当是字符串数组,或者对象。