更新构建设置
This commit is contained in:
@@ -2,45 +2,47 @@ const fs = require('fs')
|
||||
const fsPromises = require('fs').promises
|
||||
const path = require('path')
|
||||
const { Arch } = require('electron-builder')
|
||||
const nodeAbi = require('node-abi')
|
||||
|
||||
const better_sqlite3_fileNameMap = {
|
||||
[Arch.x64]: 'electron-v110-linux-x64',
|
||||
[Arch.arm64]: 'electron-v110-linux-arm64',
|
||||
[Arch.armv7l]: 'electron-v110-linux-arm',
|
||||
[Arch.x64]: 'linux-x64',
|
||||
[Arch.arm64]: 'linux-arm64',
|
||||
[Arch.armv7l]: 'linux-arm',
|
||||
}
|
||||
|
||||
const qrc_decode_fileNameMap = {
|
||||
win32: {
|
||||
[Arch.x64]: 'electron-v110-win32-x64',
|
||||
[Arch.ia32]: 'electron-v110-win32-ia32',
|
||||
[Arch.arm64]: 'electron-v110-win32-arm64',
|
||||
[Arch.x64]: 'win32-x64',
|
||||
[Arch.ia32]: 'win32-ia32',
|
||||
[Arch.arm64]: 'win32-arm64',
|
||||
},
|
||||
linux: {
|
||||
[Arch.x64]: 'electron-v110-linux-x64',
|
||||
[Arch.arm64]: 'electron-v110-linux-arm64',
|
||||
[Arch.armv7l]: 'electron-v110-linux-arm',
|
||||
[Arch.x64]: 'linux-x64',
|
||||
[Arch.arm64]: 'linux-arm64',
|
||||
[Arch.armv7l]: 'linux-arm',
|
||||
},
|
||||
darwin: {
|
||||
[Arch.x64]: 'electron-v110-darwin-x64',
|
||||
[Arch.arm64]: 'electron-v110-darwin-arm64',
|
||||
[Arch.x64]: 'darwin-x64',
|
||||
[Arch.arm64]: 'darwin-arm64',
|
||||
},
|
||||
}
|
||||
|
||||
const replaceSqliteLib = async(arch) => {
|
||||
const replaceSqliteLib = async(electronNodeAbi, arch) => {
|
||||
// console.log(await fs.readdir(path.join(context.appOutDir, './resources/')))
|
||||
// if (context.electronPlatformName != 'linux' || context.arch != Arch.arm64) return
|
||||
// https://github.com/lyswhut/lx-music-desktop/issues/1102
|
||||
// https://github.com/lyswhut/lx-music-desktop/issues/1161
|
||||
console.log('replace sqlite lib...')
|
||||
const filePath = path.join(__dirname, `./lib/better_sqlite3_${better_sqlite3_fileNameMap[arch]}.node`)
|
||||
const filePath = path.join(__dirname, `./lib/better_sqlite3_electron-v${electronNodeAbi}-${better_sqlite3_fileNameMap[arch]}.node`)
|
||||
console.log(filePath)
|
||||
const targetPath = path.join(__dirname, '../node_modules/better-sqlite3/build/Release/better_sqlite3.node')
|
||||
await fsPromises.unlink(targetPath).catch(_ => _)
|
||||
await fsPromises.copyFile(filePath, targetPath)
|
||||
}
|
||||
|
||||
const replaceQrcDecodeLib = async(platform, arch) => {
|
||||
console.log('replace qrc_decode lib...', platform, qrc_decode_fileNameMap[platform][arch])
|
||||
const filePath = path.join(__dirname, `./lib/qrc_decode_${qrc_decode_fileNameMap[platform][arch]}.node`)
|
||||
const replaceQrcDecodeLib = async(electronNodeAbi, platform, arch) => {
|
||||
console.log('replace qrc_decode lib...', platform, electronNodeAbi, qrc_decode_fileNameMap[platform][arch])
|
||||
const filePath = path.join(__dirname, `./lib/qrc_decode_electron-v${electronNodeAbi}-${qrc_decode_fileNameMap[platform][arch]}.node`)
|
||||
const targetPath = path.join(__dirname, '../build/Release/qrc_decode.node')
|
||||
const targetDir = path.dirname(targetPath)
|
||||
if (fs.existsSync(targetDir)) await fsPromises.unlink(targetPath).catch(_ => _)
|
||||
@@ -51,7 +53,8 @@ const replaceQrcDecodeLib = async(platform, arch) => {
|
||||
|
||||
module.exports = async(context) => {
|
||||
const { electronPlatformName, arch } = context
|
||||
await replaceQrcDecodeLib(electronPlatformName, arch)
|
||||
const electronNodeAbi = nodeAbi.getAbi(context.packager.info._framework.version, 'electron')
|
||||
await replaceQrcDecodeLib(electronNodeAbi, electronPlatformName, arch)
|
||||
if (electronPlatformName !== 'linux' || process.env.FORCE) return
|
||||
const bindingFilePath = path.join(__dirname, '../node_modules/better-sqlite3/binding.gyp')
|
||||
const bindingBakFilePath = path.join(__dirname, '../node_modules/better-sqlite3/binding.gyp.bak')
|
||||
@@ -63,7 +66,7 @@ module.exports = async(context) => {
|
||||
// console.log('rename binding file...')
|
||||
await fsPromises.rename(bindingFilePath, bindingBakFilePath)
|
||||
}
|
||||
await replaceSqliteLib(arch)
|
||||
await replaceSqliteLib(electronNodeAbi, arch)
|
||||
break
|
||||
|
||||
default:
|
||||
|
||||
@@ -0,0 +1,297 @@
|
||||
/* eslint-disable no-template-curly-in-string */
|
||||
|
||||
const builder = require('electron-builder')
|
||||
const beforePack = require('./build-before-pack')
|
||||
const afterPack = require('./build-after-pack')
|
||||
|
||||
/**
|
||||
* @type {import('electron-builder').Configuration}
|
||||
* @see https://www.electron.build/configuration/configuration
|
||||
*/
|
||||
const options = {
|
||||
appId: 'cn.toside.music.desktop',
|
||||
beforePack,
|
||||
afterPack,
|
||||
protocols: {
|
||||
name: 'lx-music-protocol',
|
||||
schemes: [
|
||||
'lxmusic',
|
||||
],
|
||||
},
|
||||
directories: {
|
||||
buildResources: './resources',
|
||||
output: './build',
|
||||
},
|
||||
files: [
|
||||
'!node_modules/**/*',
|
||||
'node_modules/font-list',
|
||||
'node_modules/better-sqlite3/lib',
|
||||
'node_modules/better-sqlite3/package.json',
|
||||
'node_modules/better-sqlite3/build/Release/better_sqlite3.node',
|
||||
'node_modules/electron-font-manager/index.js',
|
||||
'node_modules/electron-font-manager/package.json',
|
||||
'node_modules/electron-font-manager/build/Release/font_manager.node',
|
||||
'node_modules/node-gyp-build',
|
||||
'node_modules/bufferutil',
|
||||
'node_modules/utf-8-validate',
|
||||
'build/Release/qrc_decode.node',
|
||||
'dist/**/*',
|
||||
],
|
||||
asar: {
|
||||
smartUnpack: false,
|
||||
},
|
||||
extraResources: [
|
||||
'./licenses',
|
||||
],
|
||||
publish: [
|
||||
{
|
||||
provider: 'github',
|
||||
owner: 'lyswhut',
|
||||
repo: 'lx-music-desktop',
|
||||
},
|
||||
],
|
||||
}
|
||||
/**
|
||||
* @type {import('electron-builder').Configuration}
|
||||
* @see https://www.electron.build/configuration/configuration
|
||||
*/
|
||||
const winOptions = {
|
||||
win: {
|
||||
icon: './resources/icons/icon.ico',
|
||||
legalTrademarks: 'lyswhut',
|
||||
// artifactName: '${productName}-v${version}-${env.ARCH}-${env.TARGET}.${ext}',
|
||||
},
|
||||
nsis: {
|
||||
oneClick: false,
|
||||
language: '2052',
|
||||
allowToChangeInstallationDirectory: true,
|
||||
differentialPackage: true,
|
||||
license: './licenses/license.rtf',
|
||||
shortcutName: 'LX Music',
|
||||
},
|
||||
}
|
||||
/**
|
||||
* @type {import('electron-builder').Configuration}
|
||||
* @see https://www.electron.build/configuration/configuration
|
||||
*/
|
||||
const linuxOptions = {
|
||||
linux: {
|
||||
maintainer: 'lyswhut <lyswhut@qq.com>',
|
||||
// artifactName: '${productName}-${version}.${env.ARCH}.${ext}',
|
||||
icon: './resources/icons',
|
||||
category: 'Utility;AudioVideo;Audio;Player;Music;',
|
||||
desktop: {
|
||||
Name: 'LX Music',
|
||||
'Name[zh_CN]': 'LX Music',
|
||||
'Name[zh_TW]': 'LX Music',
|
||||
Encoding: 'UTF-8',
|
||||
MimeType: 'x-scheme-handler/lxmusic',
|
||||
StartupNotify: 'false',
|
||||
},
|
||||
},
|
||||
appImage: {
|
||||
license: './licenses/license_zh.txt',
|
||||
category: 'Utility;AudioVideo;Audio;Player;Music;',
|
||||
},
|
||||
}
|
||||
/**
|
||||
* @type {import('electron-builder').Configuration}
|
||||
* @see https://www.electron.build/configuration/configuration
|
||||
*/
|
||||
const macOptions = {
|
||||
mac: {
|
||||
icon: './resources/icons/icon.icns',
|
||||
category: 'public.app-category.music',
|
||||
// artifactName: '${productName}-${version}.${ext}',
|
||||
},
|
||||
dmg: {
|
||||
window: {
|
||||
width: 600,
|
||||
height: 400,
|
||||
},
|
||||
contents: [
|
||||
{
|
||||
x: 106,
|
||||
y: 252,
|
||||
name: 'LX Music',
|
||||
},
|
||||
{
|
||||
x: 490,
|
||||
y: 252,
|
||||
type: 'link',
|
||||
path: '/Applications',
|
||||
},
|
||||
],
|
||||
title: '洛雪音乐助手 v${version}',
|
||||
},
|
||||
}
|
||||
|
||||
// win: {
|
||||
// tagret: {
|
||||
// setup: ['nsis', '${productName}-v${version}-${env.ARCH}-Setup.${ext}'],
|
||||
// green: ['7z', '${productName}-v${version}-${env.ARCH}-green.${ext}'],
|
||||
// portable: ['portable', '${productName}-v${version}-${env.ARCH}-portable.${ext}'],
|
||||
// },
|
||||
// },
|
||||
// linux: {
|
||||
// platform: Platform.WINDOWS,
|
||||
// arch: {
|
||||
// x64: builder.Arch.x64,
|
||||
// arm64: builder.Arch.arm64,
|
||||
// armv7l: builder.Arch.armv7l,
|
||||
// },
|
||||
// tagret: {
|
||||
// deb: ['deb', '${productName}_${version}_${env.ARCH}.${ext}'],
|
||||
// appImage: ['AppImage', '${productName}_${version}_${env.ARCH}.${ext}'],
|
||||
// pacman: ['pacman', '${productName}_${version}_${env.ARCH}.${ext}'],
|
||||
// rpm: ['rpm', '${productName}-${version}.${env.ARCH}.${ext}'],
|
||||
// },
|
||||
// },
|
||||
// mac: {
|
||||
// arch: {
|
||||
// x64: builder.Arch.x64,
|
||||
// x86: builder.Arch.ia32,
|
||||
// arm64: builder.Arch.arm64,
|
||||
// },
|
||||
// tagret: {
|
||||
// dmg: ['dmg', '${productName}-${version}-${env.ARCH}.${ext}'],
|
||||
// },
|
||||
// },
|
||||
|
||||
const createTarget = {
|
||||
/**
|
||||
*
|
||||
* @param {*} arch
|
||||
* @param {*} packageType
|
||||
* @returns {{ buildOptions: import('electron-builder').CliOptions, options: import('electron-builder').Configuration }}
|
||||
*/
|
||||
win(arch, packageType) {
|
||||
switch (packageType) {
|
||||
case 'setup':
|
||||
winOptions.artifactName = `\${productName}-v\${version}-${arch}-Setup.\${ext}`
|
||||
return {
|
||||
buildOptions: { win: ['nsis'] },
|
||||
options: winOptions,
|
||||
}
|
||||
case 'green':
|
||||
winOptions.artifactName = `\${productName}-v\${version}-win_${arch}-green.\${ext}`
|
||||
return {
|
||||
buildOptions: { win: ['7z'] },
|
||||
options: winOptions,
|
||||
}
|
||||
case 'win7_green':
|
||||
winOptions.artifactName = `\${productName}-v\${version}-win7_${arch}-green.\${ext}`
|
||||
return {
|
||||
buildOptions: { win: ['7z'] },
|
||||
options: winOptions,
|
||||
}
|
||||
case 'portable':
|
||||
winOptions.artifactName = `\${productName}-v\${version}-${arch}-portable.\${ext}`
|
||||
return {
|
||||
buildOptions: { win: ['portable'] },
|
||||
options: winOptions,
|
||||
}
|
||||
default: throw new Error('Unknown package type: ' + packageType)
|
||||
}
|
||||
},
|
||||
/**
|
||||
*
|
||||
* @param {*} arch
|
||||
* @param {*} packageType
|
||||
* @returns {{ buildOptions: import('electron-builder').CliOptions, options: import('electron-builder').Configuration }}
|
||||
*/
|
||||
linux(arch, packageType) {
|
||||
switch (packageType) {
|
||||
case 'deb':
|
||||
linuxOptions.artifactName = `\${productName}_\${version}_${arch == 'x64' ? 'amd64' : arch}.\${ext}`
|
||||
return {
|
||||
buildOptions: { linux: ['deb'] },
|
||||
options: linuxOptions,
|
||||
}
|
||||
case 'appImage':
|
||||
linuxOptions.artifactName = `\${productName}_\${version}_${arch}.\${ext}`
|
||||
return {
|
||||
buildOptions: { linux: ['AppImage'] },
|
||||
options: linuxOptions,
|
||||
}
|
||||
case 'pacman':
|
||||
linuxOptions.artifactName = `\${productName}_\${version}_${arch}.\${ext}`
|
||||
return {
|
||||
buildOptions: { linux: ['pacman'] },
|
||||
options: linuxOptions,
|
||||
}
|
||||
case 'rpm':
|
||||
linuxOptions.artifactName = `\${productName}-\${version}.${arch}.\${ext}`
|
||||
return {
|
||||
buildOptions: { linux: ['rpm'] },
|
||||
options: linuxOptions,
|
||||
}
|
||||
default: throw new Error('Unknown package type: ' + packageType)
|
||||
}
|
||||
},
|
||||
/**
|
||||
*
|
||||
* @param {*} arch
|
||||
* @param {*} packageType
|
||||
* @returns {{ buildOptions: import('electron-builder').CliOptions, options: import('electron-builder').Configuration }}
|
||||
*/
|
||||
mac(arch, packageType) {
|
||||
switch (packageType) {
|
||||
case 'dmg':
|
||||
macOptions.artifactName = `\${productName}-\${version}-${arch}.\${ext}`
|
||||
return {
|
||||
buildOptions: { mac: ['dmg'] },
|
||||
options: macOptions,
|
||||
}
|
||||
default: throw new Error('Unknown package type: ' + packageType)
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {'win' | 'mac' | 'linux' | 'dir'} target 构建目标平台
|
||||
* @param {'x86_64' | 'x64' | 'x86' | 'arm64' | 'armv7l'} arch 包架构
|
||||
* @param {*} packageType 包类型
|
||||
* @param {'onTagOrDraft' | 'always' | 'never'} publishType 发布类型
|
||||
*/
|
||||
const build = async(target, arch, packageType, publishType) => {
|
||||
if (target == 'dir') {
|
||||
await builder.build({
|
||||
dir: true,
|
||||
config: { ...options, ...winOptions, ...linuxOptions, ...macOptions },
|
||||
})
|
||||
return
|
||||
}
|
||||
const targetInfo = createTarget[target](arch, packageType)
|
||||
// Promise is returned
|
||||
await builder.build({
|
||||
...targetInfo.buildOptions,
|
||||
publish: publishType ?? 'never',
|
||||
x64: arch == 'x64' || arch == 'x86_64',
|
||||
ia32: arch == 'x86' || arch == 'x86_64',
|
||||
arm64: arch == 'arm64',
|
||||
armv7l: arch == 'armv7l',
|
||||
config: { ...options, ...targetInfo.options },
|
||||
})
|
||||
// .then((result) => {
|
||||
// console.log(JSON.stringify(result))
|
||||
// })
|
||||
// .catch((error) => {
|
||||
// console.error(error)
|
||||
// })
|
||||
}
|
||||
|
||||
const params = {}
|
||||
|
||||
for (const param of process.argv.slice(2)) {
|
||||
const [name, value] = param.split('=')
|
||||
params[name] = value
|
||||
}
|
||||
|
||||
if (params.target == null) throw new Error('Missing target')
|
||||
if (params.target != 'dir' && params.arch == null) throw new Error('Missing arch')
|
||||
if (params.target != 'dir' && params.type == null) throw new Error('Missing type')
|
||||
|
||||
console.log(params.target, params.arch, params.type, params.publish ?? '')
|
||||
build(params.target, params.arch, params.type, params.publish)
|
||||
@@ -0,0 +1,53 @@
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const tar = require('tar')
|
||||
|
||||
const libDir = path.join(__dirname, 'lib')
|
||||
|
||||
const getGzipFiles = async() => {
|
||||
const names = await fs.promises.readdir(libDir)
|
||||
for (const name of names) {
|
||||
if (name.endsWith('.node')) await fs.promises.unlink(path.join(libDir, name))
|
||||
}
|
||||
return names.filter(name => name.endsWith('.gz'))
|
||||
}
|
||||
|
||||
const unzip = async(filePath) => {
|
||||
const targetDir = filePath.replace('.tar.gz', '')
|
||||
if (fs.existsSync(targetDir)) await fs.promises.rm(targetDir, { recursive: true })
|
||||
await fs.promises.mkdir(targetDir)
|
||||
await tar.x({
|
||||
file: filePath,
|
||||
strip: 1,
|
||||
C: targetDir,
|
||||
})
|
||||
return targetDir
|
||||
}
|
||||
|
||||
const files = [
|
||||
'qrc_decode',
|
||||
'better_sqlite3',
|
||||
]
|
||||
const moveFile = async(filePath) => {
|
||||
const name = 'electron-' + path.basename(filePath).split('-electron-')[1]
|
||||
for (const fileName of files) {
|
||||
if (fileName == 'better_sqlite3' && !name.includes('linux')) continue
|
||||
const targetPath = path.join(libDir, `${fileName}_${name}.node`)
|
||||
if (fs.existsSync(targetPath)) await fs.promises.unlink(targetPath)
|
||||
await fs.promises.rename(path.join(filePath, 'Release', fileName + '.node'), targetPath)
|
||||
}
|
||||
await fs.promises.rm(filePath, { recursive: true })
|
||||
}
|
||||
|
||||
const run = async() => {
|
||||
const files = await getGzipFiles()
|
||||
for (const name of files) {
|
||||
await moveFile(await unzip(path.join(libDir, name)))
|
||||
}
|
||||
for (const name of files) {
|
||||
await fs.promises.unlink(path.join(libDir, name))
|
||||
}
|
||||
}
|
||||
|
||||
run()
|
||||
|
||||
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user