gpt4 book ai didi

node.js - 在电子构建器中配置 pkg 选项脚本的最佳方法是什么?

转载 作者:太空宇宙 更新时间:2023-11-03 22:20:38 25 4
gpt4 key购买 nike

我在电子构建器的 package.json 配置中使用 pkg 选项。我有一些预安装脚本想要在安装时运行。我已经关注了electron-builder instructions为了设置脚本的位置,但 npm 似乎无法正确找到文件。

我尝试使用 chmod +x file 命令更改文件和文件夹的所有权,但错误仍然存​​在。

这是有关 pkg 脚本配置的代码:

"build": {
"mac": {
"target":[
"pkg"
]
},
"pkg":{
"scripts":"build/pkg-scripts"
}
}

我收到的错误消息是:

Error: Exit code: 1. Command failed: pkgbuild --root /Users/user/myApp/myApp-out/electron-builder/mac --component-plist /Users/user/myApp/myApp/electron-builder/com.dessci.myApp.plist --install-location /Applications --scripts /Users/user/myApp/build/build/pkg-scripts /Users/user/mtdesktop/mtdesktop-out/electron-builder/com.dessci.myApp.pkg
pkgbuild: error: Cannot write package to "/Users/user/mtdesktop/mtdesktop-out/electron-builder/com.dessci.myApp.pkg". (The file “pkg-scripts” couldn’t be opened.)

pkgbuild: Reading components from /Users/user/mtdesktop/mtdesktop-out/electron-builder/com.dessci.myApp.plist
pkgbuild: Adding component at myApp.app

pkgbuild: error: Cannot write package to "/Users/user/mtdesktop/mtdesktop-out/electron-builder/com.dessci.myApp.pkg". (The file “pkg-scripts” couldn’t be opened.)

at /Users/user/mtdesktop/node_modules/builder-util/src/util.ts:126:16
at ChildProcess.exithandler (child_process.js:306:5)
at ChildProcess.emit (events.js:193:13)
at maybeClose (internal/child_process.js:999:16)
at Process.ChildProcess._handle.onexit (internal/child_process.js:266:5)
From previous event:
at /Users/user/mtdesktop/node_modules/graceful-fs/graceful-fs.js:111:16
at /Users/user/mtdesktop/node_modules/graceful-fs/graceful-fs.js:45:10
at FSReqCallback.args [as oncomplete] (fs.js:145:20)
From previous event:
at PkgTarget.buildComponentPackage (/Users/user/mtdesktop/node_modules/app-builder-lib/src/targets/pkg.ts:115:113)
at /Users/user/mtdesktop/node_modules/app-builder-lib/src/targets/pkg.ts:57:12
at Generator.next (<anonymous>)
From previous event:
at PkgTarget.build (/Users/user/mtdesktop/node_modules/app-builder-lib/src/targets/pkg.ts:31:42)
at Function.buildAsyncTargets (/Users/user/mtdesktop/node_modules/app-builder-lib/src/platformPackager.ts:140:36)
at MacPackager.packageInDistributableFormat (/Users/user/mtdesktop/node_modules/app-builder-lib/src/platformPackager.ts:119:24)
at nonMasPromise.then.then (/Users/user/mtdesktop/node_modules/app-builder-lib/src/macPackager.ts:90:26)
at processImmediate (internal/timers.js:443:21)
From previous event:
at /Users/user/mtdesktop/node_modules/app-builder-lib/src/macPackager.ts:90:10
at Generator.next (<anonymous>)
From previous event:
at MacPackager.pack (/Users/user/mtdesktop/node_modules/app-builder-lib/src/macPackager.ts:80:95)
at /Users/user/mtdesktop/node_modules/app-builder-lib/src/packager.ts:430:24
at Generator.next (<anonymous>)
at xfs.stat (/Users/user/mtdesktop/node_modules/fs-extra-p/node_modules/fs-extra/lib/mkdirs/mkdirs.js:56:16)
at /Users/user/mtdesktop/node_modules/graceful-fs/polyfills.js:285:20
at FSReqCallback.oncomplete (fs.js:159:5)
From previous event:
at Packager.doBuild (/Users/user/mtdesktop/node_modules/app-builder-lib/src/packager.ts:396:24)
at /Users/user/mtdesktop/node_modules/app-builder-lib/src/packager.ts:366:57
at Generator.next (<anonymous>)
at /Users/user/mtdesktop/node_modules/graceful-fs/graceful-fs.js:111:16
at /Users/user/mtdesktop/node_modules/graceful-fs/graceful-fs.js:45:10
at FSReqCallback.args [as oncomplete] (fs.js:145:20)
From previous event:
at Packager._build (/Users/user/mtdesktop/node_modules/app-builder-lib/src/packager.ts:335:133)
at /Users/user/mtdesktop/node_modules/app-builder-lib/src/packager.ts:331:23
at Generator.next (<anonymous>)
at processImmediate (internal/timers.js:443:21)
From previous event:
at Packager.build (/Users/user/mtdesktop/node_modules/app-builder-lib/src/packager.ts:288:14)
at build (/Users/user/mtdesktop/node_modules/app-builder-lib/src/index.ts:59:28)
at build (/Users/user/mtdesktop/node_modules/electron-builder/src/builder.ts:227:10)
at then (/Users/user/mtdesktop/node_modules/electron-builder/src/cli/cli.ts:46:19)

最佳答案

您需要为脚本值提供 pkg-scripts 的相对路径

package.json

"build": {
"appId": "com.audio.application",
"productName": "Audio-App",
"artifactName": "${productName}-Setup-${version}.${ext}",
"copyright": "Copyright © 2020 Audio Corp",
"mac": {
"category": "com.audio.application",
"target": [
"pkg"
],
"icon": "dist",
"identity": "identity",
"darkModeSupport": true,
"hardenedRuntime": true,
"gatekeeperAssess": false,
"artifactName": "${productName}.${ext}"
},
"pkg": {
"scripts": "../build/pkg-scripts",
"installLocation": "/Applications",
"background": {
"file": "build/icon/sound.png",
"alignment": "bottomleft"
},
"allowAnywhere": true,
"allowCurrentUserHome": true,
"allowRootDirectory": true,
"license": "build/license.html",
"welcome": "build/resources/welcome.txt",
"conclusion": "build/resources/conclusion.txt",
"isVersionChecked": true,
"isRelocatable": false,
"overwriteAction": "upgrade"
},
"directories": {
"buildResources": "release",
"output": "release"
}
},
<小时/>

构建目录的文件夹结构 -
(位于项目的根级别)

enter image description here

<小时/>

preinstall.sh -
(确保您已对此文件运行 chmod +x 以使其可执行)

#!/bin/sh
echo "Executing preinstaller script for custom installer"

# Deleting App components from Application folder.
echo "Deleting Audio-Configration Logs"
logsPath=~/Library/Logs/Audio-Configration
if [ -d "$logsPath" ]
then
rm -rf ~/Library/Logs/Audio-Configration
echo "***Deleted Audio-Configration Logs Successfully***"
fi

echo "Deleting Audio-Configration Application Support"
applicationSupportPath=~/Library/Application\ Support/Audio-Configration
if [ -d "$applicationSupportPath" ]
then
rm -rf ~/Library/Application\ Support/Audio-Configration
echo "***Deleted Audio-Configration Application Support Successfully***"
fi

echo "Finished:preflight"
exit 0

以上预安装脚本是为了确保用户重新安装应用程序时,需要删除Application Support目录中之前的日志和应用程序相关内容

关于node.js - 在电子构建器中配置 pkg 选项脚本的最佳方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56174761/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com