From 7a8d57a276a9a6c52aaa83bc1206c51b86481c69 Mon Sep 17 00:00:00 2001 From: luk Date: Thu, 31 Oct 2024 08:20:41 +0800 Subject: [PATCH] add env_loc.js --- boot_link.js | 13 ++++++----- env_loc.js | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+), 6 deletions(-) create mode 100644 env_loc.js diff --git a/boot_link.js b/boot_link.js index e7ebf93..b9f7049 100644 --- a/boot_link.js +++ b/boot_link.js @@ -4,11 +4,13 @@ const { execSync } = require('child_process') const path = require('path') // Main function to link libraries -const openNpmPath = fs.existsSync(path.resolve('./env_loc.gitomit.sfomit.json')) - ? require(path.resolve('./env_loc.gitomit.sfomit.json')).openNpm +const openSharePath = fs.existsSync( + path.resolve('./env_loc.gitomit.sfomit.json') +) + ? require(path.resolve('./env_loc.gitomit.sfomit.json')).openShare : '' -console.log('openNpm:', openNpmPath) -if (!openNpmPath) { +console.log('openShare:', openSharePath) +if (!openSharePath) { return } @@ -24,10 +26,9 @@ const libs = fs libName.startsWith('wo-') || libName === 'tic-crypto' ) -console.log('libs:', libs) libs.forEach(libName => { - const libPath = path.join(openNpmPath, libName) + const libPath = path.join(openSharePath, libName) if (fs.existsSync(libPath)) { console.log(`Copying ${libName}`) const sourceFiles = fs diff --git a/env_loc.js b/env_loc.js new file mode 100644 index 0000000..04a359a --- /dev/null +++ b/env_loc.js @@ -0,0 +1,64 @@ +// usage: node env_loc.js hbxCli iosTransporter simsimPath openShare + +const fs = require('fs') +const path = require('path') +const os = require('os') + +const params = process.argv.slice(2) + +// 默认值。如要覆盖,请在 env_loc.gitomit.sfomit.json 中修改。 +const defaultEnv = { + hbxCli: + os.type() === 'Darwin' && + fs.existsSync('/Applications/HBuilderX.app/Contents/MacOS/cli') + ? '/Applications/HBuilderX.app/Contents/MacOS/cli' + : os.type() === 'Windows_NT' && fs.existsSync('C:/HBuilderX/cli.exe') + ? 'C:/HBuilderX/cli.exe' + : '', + iosTransporter: + os.type() === 'Darwin' && + fs.existsSync( + '/Applications/Transporter.app/Contents/itms/bin/iTMSTransporter' + ) + ? '/Applications/Transporter.app/Contents/itms/bin/iTMSTransporter' + : '', + simsimPath: module.paths.some(modulesPath => + fs.existsSync(path.join(modulesPath, 'sesame-basic')) + ) + ? 'sesame-basic' + : fs.existsSync('../../../simsim/sesame-basic') + ? path.resolve('../../../simsim/sesame-basic') + : fs.existsSync(`${os.homedir()}/simsim/sesame-basic`) + ? path.resolve(`${os.homedir()}/simsim/sesame-basic`) + : '', + openShare: fs.existsSync('../../npm') + ? path.resolve('../../npm') + : fs.existsSync(`${os.homedir()}/openShare`) + ? path.resolve(`${os.homedir()}/openShare`) + : '' +} + +const localEnv = Object.assign( + {}, + params.reduce((acc, cur) => { + if (defaultEnv[cur]) { + acc[cur] = defaultEnv[cur] + } else { + acc[cur] = '' + } + return acc + }, {}), + fs.existsSync('./env_loc.gitomit.sfomit.json') + ? require(path.resolve('./env_loc.gitomit.sfomit.json')) + : {} +) + +fs.writeFileSync( + path.resolve('./env_loc.gitomit.sfomit.json'), + JSON.stringify(localEnv, null, 2), + 'utf8' +) + +console.log(localEnv) + +module.exports = localEnv