From 7b2584655706482e668724f85a9b9989876514f0 Mon Sep 17 00:00:00 2001 From: Haochen Duan Date: Mon, 10 Jun 2024 03:09:44 +0800 Subject: [PATCH] =?UTF-8?q?build:=20node-nim=E5=9C=A8=E7=BC=96=E8=AF=91?= =?UTF-8?q?=E5=90=8E=E6=8B=B7=E8=B4=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/unpack.mjs | 29 +++++++++++------------------ scripts/utils.mjs | 11 +++++++++-- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/scripts/unpack.mjs b/scripts/unpack.mjs index 6cc6b566..1bb8f280 100644 --- a/scripts/unpack.mjs +++ b/scripts/unpack.mjs @@ -1,10 +1,9 @@ import path from 'node:path'; -import fs from 'node:fs'; import fsP from 'node:fs/promises'; import { rimraf } from 'rimraf'; import fse from 'fs-extra/esm'; import builder from 'electron-builder'; -import { cwd, appDir, wwwDir, staticsDir, build, nodeNimSDK, sdkDownloadDir, output, unpacked, isMacOS, isArm64 } from './utils.mjs'; +import { cwd, appDir, wwwDir, staticsDir, build, sdkDownloadDir, output, unpacked, unpackedNodeModules, isMacOS, isArm64 } from './utils.mjs'; import taskfile from './taskfile.mjs'; import nimSdkDownload from './nimSdkDownload.mjs'; import packageJson from '../package.json' assert { type: 'json' }; @@ -69,7 +68,7 @@ function config(outputDir, target) { icon: icon.linux, executableName: '48tools' }, - includeSubNodeModules: true, + includeSubNodeModules: false, npmRebuild: false, nodeGypRebuild: false, electronDownload: { @@ -120,16 +119,11 @@ async function uglifyPackageJson() { /** * 替换sdk - * @param { string } [downloadDir] - 下载目录 + * @param { string } downloadDir - 下载目录 + * @param { string } nodeModulesDir - node_modules目录 */ -async function copySDK(downloadDir) { - if (fs.existsSync(nodeNimSDK)) { - await rimraf(nodeNimSDK); - } - - if (downloadDir) { - await fse.copy(path.join(downloadDir, 'node-nim'), nodeNimSDK); - } +async function copySDK(downloadDir, nodeModulesDir) { + await fse.copy(path.join(downloadDir, 'node-nim'), path.join(nodeModulesDir, 'node-nim')); } async function unpackOthers() { @@ -137,36 +131,36 @@ async function unpackOthers() { if (isMacOS) { // 编译mac console.log('⏳正在编译:mac'); - await copySDK(sdkDownloadDir.mac); await builder.build({ targets: builder.Platform.MAC.createTarget(), config: config(output.mac) }); + await copySDK(sdkDownloadDir.mac, unpackedNodeModules.mac); } // 编译win64 console.log('⏳正在编译:win64'); - await copySDK(sdkDownloadDir.win64); await builder.build({ targets: builder.Platform.WINDOWS.createTarget(), config: config(output.win) }); + await copySDK(sdkDownloadDir.win64, unpackedNodeModules.win); // 编译win32 console.log('⏳正在编译:win32'); - await copySDK(sdkDownloadDir.win32); await builder.build({ targets: builder.Platform.WINDOWS.createTarget(), config: config(output.win32, ['win', { target: 'dir', arch: 'ia32' }]) }); + await copySDK(sdkDownloadDir.win32, unpackedNodeModules.win32); // 编译linux console.log('⏳正在编译:linux'); - await copySDK(sdkDownloadDir.linux); await builder.build({ targets: builder.Platform.LINUX.createTarget(), config: config(output.linux) }); + await copySDK(sdkDownloadDir.linux, unpackedNodeModules.linux); // 拷贝许可文件 console.log('🚚正在拷贝许可文件'); @@ -184,11 +178,11 @@ async function unpackArm64() { if (isMacOS) { // 编译mac-arm64 console.log('⏳正在编译:mac-arm64'); - await copySDK(sdkDownloadDir.macArm64); await builder.build({ targets: builder.Platform.MAC.createTarget(), config: config(output.macArm64, ['mac', { target: 'dir', arch: 'arm64' }]) }); + await copySDK(sdkDownloadDir.macArm64, unpackedNodeModules.macArm64); } // 编译win-arm64 @@ -200,7 +194,6 @@ async function unpackArm64() { // 拷贝许可文件 console.log('🚚正在拷贝许可文件'); - await copySDK(); await Promise.all([ ...isMacOS ? copy(unpacked.macArm64, true) : [], ...copy(unpacked.winArm64) diff --git a/scripts/utils.mjs b/scripts/utils.mjs index 7cb1058f..f30b86b0 100644 --- a/scripts/utils.mjs +++ b/scripts/utils.mjs @@ -13,8 +13,6 @@ export const staticsDir = path.join(cwd, 'statics'); // 静态资源目录 export const build = path.join(cwd, 'build'); // 最终生成的可执行文件 // SDK -export const nodeNimSDK = path.join(wwwDir, 'node_modules/nim-sdk'); - const sdkDownloadBasicDir = path.join(build, 'node-nim-sdk'); export const sdkDownloadDir = { @@ -44,6 +42,15 @@ export const unpacked = { linux: path.join(output.linux, 'linux-unpacked') }; +export const unpackedNodeModules = { + mac: path.join(unpacked.mac, '48tools.app/Contents/Resources/app/node_modules'), + macArm64: path.join(unpacked.macArm64, '48tools.app/Contents/Resources/app/node_modules'), + win: path.join(unpacked.win, 'resources/app/node_modules'), + win32: path.join(unpacked.win32, 'resources/app/node_modules'), + winArm64: path.join(unpacked.winArm64, 'resources/app/node_modules'), + linux: path.join(unpacked.linux, 'resources/app/node_modules') +}; + // 系统环境 export const isMacOS = process.platform === 'darwin'; export const isWindows = process.platform === 'win32';