feat(bin): 优化打包脚本到跨平台

This commit is contained in:
v-zhangjc9
2025-05-21 17:56:10 +08:00
parent 6e7cef6170
commit 8c2b94f6c9
55 changed files with 631 additions and 193 deletions

80
bin/library.js Normal file
View File

@@ -0,0 +1,80 @@
import {$, fetch, fs, glob, os, path, spinner, syncProcessCwd, usePowerShell} from 'zx'
import {isEqual, trim} from "licia";
syncProcessCwd(true)
if (isEqual(os.platform(), 'win32')) {
usePowerShell()
}
const maven_setting = '/Users/lanyuanxiaoyao/.m2/settings-nas.xml'
const upload_url = 'http://132.126.207.124:36800'
const upload_username = 'AxhEbscwsJDbYMH2'
const upload_password = 'cYxg3b4PtWoVD5SjFayWxtnSVsjzRsg4'
export const run_deploy = async (project) => {
await spinner(
`Deploying project ${project}`,
() => $`mvn -pl ${project} clean deploy -D skipTests -s ${maven_setting}`
)
console.log(`✅ Finish deploy ${project}`)
}
export const run_deploy_root = async () => {
await spinner(
`Deploying root`,
() => $`mvn clean deploy -N -D skipTests -s ${maven_setting}`
)
console.log(`✅ Finish deploy root`)
}
export const run_deploy_batch = async (projects) => {
for (const project of projects) {
await run_deploy(project)
}
}
export const run_package = async (project, profile = 'b2b12') => {
await spinner(
`Packaging project ${project} ${isEqual(profile, 'b2b12') ? '' : profile}`,
() => $`mvn -pl ${project} clean package -D skipTests -P ${profile} -s ${maven_setting}`
)
console.log(`✅ Finish package ${project} ${isEqual(profile, 'b2b12') ? '' : profile}`)
}
export const run_package_batch = async (projects) => {
for (const project of projects) {
await run_package(project)
}
}
const upload = async (file_path) => {
let response = await spinner(
`Uploading project ${file_path}`,
() => fetch(`${upload_url}/file/upload/${path.basename(file_path)}`, {
method: 'POST',
headers: {
'Content-Type': 'application/octet-stream',
'Authorization': `Basic ${Buffer.from(`${upload_username}:${upload_password}`).toString('base64')}`,
},
body: fs.createReadStream(file_path),
duplex: 'half',
})
)
if (!isEqual(response.status, 200)) {
throw response
}
console.log(`✅ Finish upload ${file_path}`)
fs.rmSync(file_path)
}
export const run_upload = async (pattern) => {
for (let p of glob.sync(pattern)) {
await upload(path.join(trim($.sync`pwd`.text()), p))
}
}
export const run_upload_normal = async (project) => {
await run_upload(`${project}/target/${project}-1.0.0-SNAPSHOT.jar`)
}