This commit is contained in:
Luk
2024-12-07 09:26:04 +08:00
parent bc0b982a09
commit 816cc89dad
2 changed files with 15 additions and 25 deletions

View File

@@ -1,4 +1,4 @@
// usage: node env_loc.js hbxCli iosTransporter simsimPath openShare
// usage: node env_loc.js hbxCli iosTransporter // defaultEnv里不存在的作为参数
const fs = require('fs')
const path = require('path')
@@ -9,22 +9,16 @@ 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')
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'
)
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'))
)
simsimPath: module.paths.some((modulesPath) => fs.existsSync(path.join(modulesPath, 'sesame-basic')))
? 'sesame-basic'
: fs.existsSync('../../../simsim/sesame-basic')
? path.resolve('../../../simsim/sesame-basic')
@@ -35,29 +29,21 @@ const defaultEnv = {
? 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] = ''
}
// 把参数名数组转化为对象
acc[cur] = ''
return acc
}, {}),
fs.existsSync('./env_loc.gitomit.sfomit.json')
? require(path.resolve('./env_loc.gitomit.sfomit.json'))
: {}
defaultEnv, // 继承所有默认值
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'
)
fs.writeFileSync(path.resolve('./env_loc.gitomit.sfomit.json'), JSON.stringify(localEnv, null, 2), 'utf8')
console.log(localEnv)