fix: 修复构建
This commit is contained in:
@@ -1,53 +1,55 @@
|
|||||||
const fs = require('fs')
|
// const fs = require('fs')
|
||||||
const fsPromises = require('fs').promises
|
// const fsPromises = require('fs').promises
|
||||||
const path = require('path')
|
// const path = require('path')
|
||||||
const { Arch } = require('electron-builder')
|
// const { Arch } = require('electron-builder')
|
||||||
// const nodeAbi = require('node-abi')
|
// const nodeAbi = require('node-abi')
|
||||||
const { beforePack } = require('./deps')
|
const { beforePack, copyLib } = require('./deps')
|
||||||
|
|
||||||
const better_sqlite3_fileNameMap = {
|
// const better_sqlite3_fileNameMap = {
|
||||||
[Arch.x64]: 'linux-x64',
|
// [Arch.x64]: 'linux-x64',
|
||||||
[Arch.arm64]: 'linux-arm64',
|
// [Arch.arm64]: 'linux-arm64',
|
||||||
[Arch.armv7l]: 'linux-arm',
|
// [Arch.armv7l]: 'linux-arm',
|
||||||
}
|
// }
|
||||||
|
|
||||||
const replaceSqliteLib = async(electronNodeAbi, arch) => {
|
// const replaceSqliteLib = async(arch) => {
|
||||||
// console.log(await fs.readdir(path.join(context.appOutDir, './resources/')))
|
// // console.log(await fs.readdir(path.join(context.appOutDir, './resources/')))
|
||||||
// if (context.electronPlatformName != 'linux' || context.arch != Arch.arm64) return
|
// // 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/1102
|
||||||
// https://github.com/lyswhut/lx-music-desktop/issues/1161
|
// // https://github.com/lyswhut/lx-music-desktop/issues/1161
|
||||||
console.log('replace sqlite lib...')
|
// 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_${better_sqlite3_fileNameMap[arch]}.node`)
|
||||||
console.log(filePath)
|
// console.log(filePath)
|
||||||
const targetPath = path.join(__dirname, '../node_modules/better-sqlite3/build/Release/better_sqlite3.node')
|
// const targetPath = path.join(__dirname, '../node_modules/better-sqlite3/build/Release/better_sqlite3.node')
|
||||||
await fsPromises.unlink(targetPath).catch(_ => _)
|
// await fsPromises.unlink(targetPath).catch(_ => _)
|
||||||
await fsPromises.copyFile(filePath, targetPath)
|
// await fsPromises.copyFile(filePath, targetPath)
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
|
||||||
module.exports = async(context) => {
|
module.exports = async(context) => {
|
||||||
await beforePack()
|
await beforePack()
|
||||||
const { electronPlatformName, arch } = context
|
const { arch } = context
|
||||||
|
await copyLib(arch)
|
||||||
// const electronVersion = context.packager?.info?._framework?.version ?? require('../package.json').devDependencies.electron.replace(/^[^\d]*?(\d+)/, '$1')
|
// const electronVersion = context.packager?.info?._framework?.version ?? require('../package.json').devDependencies.electron.replace(/^[^\d]*?(\d+)/, '$1')
|
||||||
// const electronNodeAbi = nodeAbi.getAbi(electronVersion, 'electron')
|
// const electronNodeAbi = nodeAbi.getAbi(electronVersion, 'electron')
|
||||||
if (electronPlatformName !== 'linux' || process.env.FORCE) return
|
// if (electronPlatformName !== 'linux' || process.env.FORCE) return
|
||||||
const bindingFilePath = path.join(__dirname, '../node_modules/better-sqlite3/binding.gyp')
|
// // const bindingFilePath = path.join(__dirname, '../node_modules/better-sqlite3/binding.gyp')
|
||||||
const bindingBakFilePath = path.join(__dirname, '../node_modules/better-sqlite3/binding.gyp.bak')
|
// // const bindingBakFilePath = path.join(__dirname, '../node_modules/better-sqlite3/binding.gyp.bak')
|
||||||
switch (arch) {
|
// switch (arch) {
|
||||||
case Arch.x64:
|
// case Arch.x64:
|
||||||
case Arch.arm64:
|
// case Arch.arm64:
|
||||||
case Arch.armv7l:
|
// case Arch.armv7l:
|
||||||
if (fs.existsSync(bindingFilePath)) {
|
// // if (fs.existsSync(bindingFilePath)) {
|
||||||
// console.log('rename binding file...')
|
// // // console.log('rename binding file...')
|
||||||
await fsPromises.rename(bindingFilePath, bindingBakFilePath)
|
// // await fsPromises.rename(bindingFilePath, bindingBakFilePath)
|
||||||
}
|
// // }
|
||||||
await replaceSqliteLib(arch)
|
// await replaceSqliteLib(arch)
|
||||||
break
|
// break
|
||||||
|
|
||||||
default:
|
// default:
|
||||||
if (fs.existsSync(bindingFilePath)) return
|
// // if (fs.existsSync(bindingFilePath)) return
|
||||||
// console.log('restore binding file...')
|
// // console.log('restore binding file...')
|
||||||
await fsPromises.rename(bindingBakFilePath, bindingFilePath)
|
// // await fsPromises.rename(bindingBakFilePath, bindingFilePath)
|
||||||
break
|
// await copyLib(arch)
|
||||||
}
|
// break
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|||||||
+21
-21
@@ -1,30 +1,30 @@
|
|||||||
const fs = require('fs')
|
const fs = require('fs')
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
const bindingFilePath = path.join(__dirname, '../node_modules/better-sqlite3/binding.gyp')
|
const bindingFilePath = path.join(__dirname, '../node_modules/better-sqlite3/binding.gyp')
|
||||||
// const bindingBakFilePath = path.join(__dirname, '../node_modules/better-sqlite3/binding.gyp.bak')
|
const bindingBakFilePath = path.join(__dirname, '../node_modules/better-sqlite3/binding.gyp.bak')
|
||||||
exports.beforePack = async() => {
|
exports.beforePack = async() => {
|
||||||
// if (!fs.existsSync(bindingFilePath)) return
|
if (!fs.existsSync(bindingFilePath)) return
|
||||||
// fs.renameSync(bindingFilePath, bindingBakFilePath)
|
fs.renameSync(bindingFilePath, bindingBakFilePath)
|
||||||
try {
|
// try {
|
||||||
fs.writeFileSync(
|
// fs.writeFileSync(
|
||||||
bindingFilePath,
|
// bindingFilePath,
|
||||||
fs.readFileSync(bindingFilePath, 'utf-8').replace('\'force_build%\': 0,', '\'force_build%\': 1,'),
|
// fs.readFileSync(bindingFilePath, 'utf-8').replace('\'force_build%\': 0,', '\'force_build%\': 1,'),
|
||||||
)
|
// )
|
||||||
} catch (error) {
|
// } catch (error) {
|
||||||
console.error(error)
|
// console.error(error)
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
exports.afterPack = async() => {
|
exports.afterPack = async() => {
|
||||||
// if (fs.existsSync(bindingFilePath)) return
|
if (fs.existsSync(bindingFilePath)) return
|
||||||
// fs.renameSync(bindingBakFilePath, bindingFilePath)
|
fs.renameSync(bindingBakFilePath, bindingFilePath)
|
||||||
try {
|
// try {
|
||||||
fs.writeFileSync(
|
// fs.writeFileSync(
|
||||||
bindingFilePath,
|
// bindingFilePath,
|
||||||
fs.readFileSync(bindingFilePath, 'utf-8').replace('\'force_build%\': 1,', '\'force_build%\': 0,'),
|
// fs.readFileSync(bindingFilePath, 'utf-8').replace('\'force_build%\': 1,', '\'force_build%\': 0,'),
|
||||||
)
|
// )
|
||||||
} catch (error) {
|
// } catch (error) {
|
||||||
console.error(error)
|
// console.error(error)
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user