Skip to content

Commit

Permalink
ci: release supported sqlite.db inner
Browse files Browse the repository at this point in the history
  • Loading branch information
helson-lin committed Sep 16, 2024
1 parent 30acff2 commit fadb3b3
Show file tree
Hide file tree
Showing 19 changed files with 3,135 additions and 2,454 deletions.
5 changes: 4 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ module.exports = {
es2021: true,
node: true,
},
extends: 'standard',
extends: [
'eslint:recommended',
'plugin:prettier/recommended',
],
overrides: [
],
parserOptions: {
Expand Down
3 changes: 0 additions & 3 deletions .github/workflows/upload.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ jobs:
# Runs a set of commands using the runners shell
- name: Install Dependencies
run: npm install

- name: Copy SqlLite
run: mkdir -p ./node_modules/sqlite3/lib/binding/ && cp -R package/* ./node_modules/sqlite3/lib/binding/

- name: Build Release
run: npm run pkg
Expand Down
38 changes: 1 addition & 37 deletions bin/utils/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@
const childProcess = require('child_process')
const si = require('systeminformation')
const os = require('os')
const m3u8ToMp4 = require('../m3u8')
const logger = require('../log')
const { msg } = require('./message')
const converter = new m3u8ToMp4()
const cpuNum = os.cpus().length
const logger = require('./log')

/**
* @description exec command
Expand Down Expand Up @@ -57,38 +53,6 @@ const getNetwork = () => {
})
}

/**
* @description: download m3u8 video to local storage
* @param {string} url m3u8 url
* @param {string} name fielName
* @param {string} filePath file output path
* @param {string} webhooks webhooks url
* @param {string} webhookType webhooks type
* @return {Promise}
*/
const download = (url, name, filePath, { webhooks, webhookType, downloadThread }) => {
return new Promise((resolve, reject) => {
converter
.setInputFile(url)
.setThreads(downloadThread ? cpuNum : 0)
.setOutputFile(filePath)
.start()
.then(res => {
if (webhooks) {
console.log('下载成功:' + name)
msg(webhooks, webhookType, `${name}.mp4 下载成功`)
}
resolve()
}).catch(err => {
console.log('下载失败', webhooks)
console.log('下载失败:' + err)
if (webhooks) {
msg(webhooks, webhookType, `${name}.mp4 下载失败`, err + '')
}
reject(err)
})
})
}

/**
* @description check input url is be supported
Expand Down
2 changes: 1 addition & 1 deletion bin/utils/env.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const logger = require('../log')
const logger = require('./log')
const colors = require('colors')
const path = require('path')
const DOWNLOADZIP = require('download')
Expand Down
14 changes: 7 additions & 7 deletions bin/utils/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
const CONFIG = require('./config')
const PROCESS = require('./process')
const SYSTEM = require('./system')
const MSG = require('./message')
const WSHELPER = require('./ws')
const VERSION = require('./version')
const LOG = require('./log')
const CONFIG = require('./config.js')
const PROCESS = require('./process.js')
const SYSTEM = require('./system.js')
const MSG = require('./message.js')
const WSHELPER = require('./ws.js')
const VERSION = require('./version.js')
const LOG = require('./log.js')
module.exports = {
...CONFIG,
...PROCESS,
Expand Down
92 changes: 92 additions & 0 deletions build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#!/usr/bin/env node
const fs = require('fs')
const path = require('path')
const { execSync } = require('child_process')
// 源文件路径(根据你的项目结构调整)
let isDebug = false
let releaseName
const argv = process.argv.slice(2)
if (argv && argv[0] === '--debug') isDebug = true
const sourcePath = path.join(__dirname, 'package/')
// 目标路径
const targetPath = path.join(__dirname, 'node_modules/sqlite3/build/Release/')
if (!fs.existsSync(targetPath)) {
fs.mkdirSync(targetPath, { recursive: true })
}

const moveNodeSqlite = (targetPlatform) => {
// 根据目标平台选择正确的文件
let targetFile
const name = targetPlatform.split('-').slice(1).join('-')
switch (name) {
case 'linux-x64':
targetFile = 'linux_x64_node_sqlite3.node'
break
case 'linux-arm64':
targetFile = 'linux_arm64_node_sqlite3.node'
break
case 'macos-arm64':
targetFile = 'macos_arm64_node_sqlite3.node'
break
case 'macos-x64':
targetFile = 'macos_x64_node_sqlite3.node'
break
case 'alpine-x64':
targetFile = 'alpine_x64_node_sqlite3.node'
break
case 'alpine-arm64':
targetFile = 'alpine_arm64_node_sqlite3.node'
break
case 'windows-x64':
targetFile = 'windows_x64_node_sqlite3.node'
break
case 'windows-arm64':
targetFile = 'windows_arm64_node_sqlite3.node'
break
default:
console.error(`\n ❗️ Unsupported target platform:${targetPlatform} \n`)
}
if (targetFile) {
// 复制文件
fs.copyFileSync(
path.join(sourcePath, targetFile),
path.join(targetPath, 'node_sqlite3.node'),
)

console.log(
`\n ✅ Copied ${path.join(sourcePath, targetFile)} to ${path.join(
targetPath,
'node_sqlite3.node',
)}\n`,
)
}
}

const pkgRelease = (targetPlatform) => {
moveNodeSqlite(targetPlatform)
// 执行打包命令
execSync(
`pkg . -t ${targetPlatform} --output ./dist/${releaseName}${targetPlatform.replace(/node\d+/g, '')}${targetPlatform.indexOf('windows') !== -1 ? '.exe' : ''
}` + (isDebug ? ' --debug' : ''),
{ stdio: 'inherit' },
)
}

const start = () => {
try {
const dataString = fs.readFileSync(
path.join(__dirname, 'package.json'),
'utf-8',
)
const data = JSON.parse(dataString)
const platforms = data.pkg.targets
releaseName = data.name
for (let item of platforms) {
pkgRelease(item)
}
} catch (e) {
console.error('❗️ read package.json failed', e)
}
}

start()
21 changes: 11 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
"start": "node bootstrap.js --debug=true",
"dev": "nodemon",
"clean": "rimraf dist",
"cp": "cp -R package/* ./node_modules/sqlite3/lib/binding/",
"pkg": "pkg ./ --debug=true",
"pkg": "node build.js",
"build": "npm run clean && npm run cp && npm run pkg",
"rmi": "docker rmi h55205l/ffandown:latest",
"build:image": "docker build . -t h55205l/ffandown:latest",
Expand Down Expand Up @@ -61,24 +60,26 @@
"node_modules/sqlite3/lib/binding/**/*"
],
"targets": [
"node16-macos-arm64",
"node16-macos-x64",
"node16-windows-x64",
"node16-linux-x64",
"node16-linux-arm64",
"node16-alpine-x64",
"node16-alpine-arm64"
"node18-macos-arm64",
"node18-macos-x64",
"node18-windows-x64",
"node18-linux-x64",
"node18-linux-arm64",
"node18-alpine-x64",
"node18-alpine-arm64"
],
"outputPath": "dist"
},
"devDependencies": {
"colors": "^1.4.0",
"eslint": "^8.0.1",
"eslint-config-standard": "^17.0.0",
"eslint-plugin-import": "^2.25.2",
"eslint-plugin-n": "^15.0.0",
"eslint-plugin-promise": "^6.0.0",
"pkg": "^5.8.1",
"rimraf": "^4.4.0"
},
"engines": {
"node": ">=18.20.3"
}
}
Binary file not shown.
Binary file not shown.
File renamed without changes.
Binary file added package/linux_x64_node_sqlite3.node
Binary file not shown.
Binary file added package/macos_arm64_node_sqlite3.node
Binary file not shown.
File renamed without changes.
Binary file removed package/napi-v3-linux-glibc-x64/node_sqlite3.node
Binary file not shown.
Binary file removed package/napi-v3-win32-unknown-ia32/node_sqlite3.node
Binary file not shown.
Binary file not shown.
Binary file added package/node_sqlite3.node
Binary file not shown.
File renamed without changes.
Loading

0 comments on commit fadb3b3

Please sign in to comment.