diff --git a/packages/core/src/config.js b/packages/core/src/config.js index c1d70bf1..7025f091 100644 --- a/packages/core/src/config.js +++ b/packages/core/src/config.js @@ -17,12 +17,12 @@ function get () { const getDefaultConfigBasePath = function () { return get().server.setting.userBasePath } -function _getRemoteSavePath () { +function _getRemoteSavePath (prefix = '') { const dir = getDefaultConfigBasePath() if (!fs.existsSync(dir)) { fs.mkdirSync(dir) } - return path.join(dir, 'remote_config.json5') + return path.join(dir, prefix + 'remote_config.json5') } function _getConfigPath () { const dir = getDefaultConfigBasePath() @@ -64,6 +64,10 @@ const configApi = { return } if (response && response.statusCode === 200) { + const originalRemoteSavePath = _getRemoteSavePath('original_') + fs.writeFileSync(originalRemoteSavePath, body) + log.info('保存原来的远程配置文件成功:', originalRemoteSavePath) + // 尝试解析远程配置,如果解析失败,则不保存它 let remoteConfig try { @@ -74,7 +78,9 @@ const configApi = { } if (remoteConfig != null) { - fs.writeFileSync(_getRemoteSavePath(), body) + const remoteSavePath = _getRemoteSavePath() + fs.writeFileSync(remoteSavePath, JSON.stringify(remoteConfig, null, '\t')) + log.info('保存远程配置文件成功:', remoteSavePath) } resolve() @@ -120,7 +126,9 @@ const configApi = { // 计算新配置与默认配置(启用远程配置时,含远程配置)的差异,并保存到 config.json5 中 const diffConfig = mergeApi.doDiff(defConfig, newConfig) - fs.writeFileSync(_getConfigPath(), JSON5.stringify(diffConfig, null, 2)) + const configPath = _getConfigPath() + fs.writeFileSync(configPath, JSON.stringify(diffConfig, null, '\t')) + log.info('保存自定义配置文件成功:', configPath) configApi.reload() return diffConfig }, diff --git a/packages/core/src/modules/server/index.js b/packages/core/src/modules/server/index.js index 20839f0d..d514ef6e 100644 --- a/packages/core/src/modules/server/index.js +++ b/packages/core/src/modules/server/index.js @@ -70,7 +70,8 @@ const serverApi = { // fireStatus('ing') // 启动中 const basePath = serverConfig.setting.userBasePath const runningConfigPath = path.join(basePath, '/running.json') - fs.writeFileSync(runningConfigPath, JSON5.stringify(serverConfig, null, 2)) + fs.writeFileSync(runningConfigPath, JSON.stringify(serverConfig, null, '\t')) + log.info('保存运行时配置文件成功:', runningConfigPath) const serverProcess = fork(mitmproxyPath, [runningConfigPath]) server = { id: serverProcess.pid, diff --git a/packages/core/start/mitmproxy.js b/packages/core/start/mitmproxy.js index 79981281..2a026d46 100644 --- a/packages/core/start/mitmproxy.js +++ b/packages/core/start/mitmproxy.js @@ -3,9 +3,11 @@ const server = require('@docmirror/mitmproxy') const JSON5 = require('json5') const path = require('path') const home = process.env.USER_HOME || process.env.HOME || 'C:/Users/Administrator/' -let configPath = path.join(home, '.dev-sidecar/running.json') +let configPath if (process.argv && process.argv.length > 3) { configPath = process.argv[2] +} else { + configPath = path.join(home, '.dev-sidecar/running.json') } const fs = require('fs') diff --git a/packages/gui/src/bridge/api/backend.js b/packages/gui/src/bridge/api/backend.js index 39b0b2c7..d4339498 100644 --- a/packages/gui/src/bridge/api/backend.js +++ b/packages/gui/src/bridge/api/backend.js @@ -64,7 +64,8 @@ const localApi = { }, save (setting = {}) { const settingPath = _getSettingsPath() - fs.writeFileSync(settingPath, JSON5.stringify(setting, null, 2)) + fs.writeFileSync(settingPath, JSON.stringify(setting, null, '\t')) + log.info('保存setting配置文件成功', settingPath) } }, /**