From 816cc89dadd7bbf253fe5da6668c6969a04e769f Mon Sep 17 00:00:00 2001 From: Luk Date: Sat, 7 Dec 2024 09:26:04 +0800 Subject: [PATCH] u --- boot_link.js | 6 +++++- env_loc.js | 34 ++++++++++------------------------ 2 files changed, 15 insertions(+), 25 deletions(-) diff --git a/boot_link.js b/boot_link.js index bcb51b2..7933ecd 100644 --- a/boot_link.js +++ b/boot_link.js @@ -6,6 +6,7 @@ const path = require('path') const openSharePath = fs.existsSync(path.resolve('./env_loc.gitomit.sfomit.json')) ? require(path.resolve('./env_loc.gitomit.sfomit.json')).openShare : '' console.log('openShare:', openSharePath) if (!openSharePath) { + console.log('openShare not found, exiting now.') return } @@ -22,7 +23,7 @@ libs.forEach((libName) => { const sourceFiles = fs.readdirSync(libPath).filter((fileName) => fileName.endsWith('.js') || fileName.endsWith('.json')) sourceFiles.forEach((file) => { const sourceFile = path.join(libPath, file) - const tempFile = path.join(nodeModulesPath, libName, file + '.temp') + const tempFile = path.join(nodeModulesPath, libName, file + `.${Date.now()}`) const destFile = path.join(nodeModulesPath, libName, file) // fs.symlinkSync(sourceFile, tempFile, 'file') // through symbolic links, 例如 tic-crypto 安装后,报错 tweetnacl module 找不到,因为跟着 symbolic links 去原始文件所在的位置找了。 try { @@ -32,6 +33,9 @@ libs.forEach((libName) => { // Fallback to copy if hard link fails fs.copyFileSync(sourceFile, tempFile) } + try { + fs.unlinkSync(destFile) + } catch {} fs.renameSync(tempFile, destFile) }) } diff --git a/env_loc.js b/env_loc.js index 04a359a..c29f1f5 100644 --- a/env_loc.js +++ b/env_loc.js @@ -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)