feat(bin): 优化打包脚本,遇到没有修改的模块就跳过发布流程
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -110,3 +110,4 @@ Network Trash Folder
|
|||||||
Temporary Items
|
Temporary Items
|
||||||
.apdisk
|
.apdisk
|
||||||
**/temp/
|
**/temp/
|
||||||
|
.build
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
import {$, fetch, fs, glob, os, path, spinner, syncProcessCwd, usePowerShell} from 'zx'
|
import {$, fetch, fs, glob, os, path, spinner, syncProcessCwd, usePowerShell} from 'zx'
|
||||||
import {isEqual, trim, fileSize} from "licia";
|
import {fileSize, isEqual, trim} from "licia";
|
||||||
import md5file from 'md5-file'
|
import md5file from 'md5-file'
|
||||||
|
|
||||||
syncProcessCwd(true)
|
syncProcessCwd(true)
|
||||||
@@ -41,7 +41,38 @@ const millisecondToString = (timestamp) => {
|
|||||||
return parts.join('')
|
return parts.join('')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const projectRootPath = () => path.dirname(import.meta.dirname)
|
||||||
|
|
||||||
|
export const isModified = async (target) => {
|
||||||
|
if (!target || !(await fs.exists(target))) {
|
||||||
|
throw new Error("Target 不存在")
|
||||||
|
}
|
||||||
|
let stat = fs.statSync(target)
|
||||||
|
let currentModifiedTime = stat.mtimeMs
|
||||||
|
|
||||||
|
let buildPath = `${projectRootPath()}/.build`
|
||||||
|
if (!(await fs.exists(buildPath))) {
|
||||||
|
fs.mkdirSync(buildPath, {recursive: true})
|
||||||
|
}
|
||||||
|
let modifiedTimeDataPath = `${buildPath}/modified_time.json`
|
||||||
|
if (!(await fs.exists(modifiedTimeDataPath))) {
|
||||||
|
fs.writeFileSync(modifiedTimeDataPath, '{}')
|
||||||
|
}
|
||||||
|
let modifiedTimeData = JSON.parse(await fs.readFile(modifiedTimeDataPath, 'utf-8'))
|
||||||
|
let lastModifiedTime = modifiedTimeData[target]
|
||||||
|
if (lastModifiedTime && isEqual(currentModifiedTime, lastModifiedTime)) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
modifiedTimeData[target] = currentModifiedTime
|
||||||
|
fs.writeFileSync(modifiedTimeDataPath, JSON.stringify(modifiedTimeData, null, 2))
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
export const run_deploy = async (project) => {
|
export const run_deploy = async (project) => {
|
||||||
|
if (!(await isModified(`${projectRootPath()}/${project}`))) {
|
||||||
|
console.log(`✅ Skip deploy ${project}`)
|
||||||
|
return
|
||||||
|
}
|
||||||
let output = await spinner(
|
let output = await spinner(
|
||||||
`Deploying project ${project}`,
|
`Deploying project ${project}`,
|
||||||
() => $`mvn -pl ${project} clean deploy -D skipTests -s ${maven_setting}`
|
() => $`mvn -pl ${project} clean deploy -D skipTests -s ${maven_setting}`
|
||||||
@@ -50,6 +81,10 @@ export const run_deploy = async (project) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const run_deploy_root = async () => {
|
export const run_deploy_root = async () => {
|
||||||
|
if (!(await isModified(`${projectRootPath()}/pom.xml`))) {
|
||||||
|
console.log(`✅ Skip deploy root`)
|
||||||
|
return
|
||||||
|
}
|
||||||
let output = await spinner(
|
let output = await spinner(
|
||||||
`Deploying root`,
|
`Deploying root`,
|
||||||
() => $`mvn clean deploy -N -D skipTests -s ${maven_setting}`
|
() => $`mvn clean deploy -N -D skipTests -s ${maven_setting}`
|
||||||
|
|||||||
3
bin/test.js
Normal file
3
bin/test.js
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
import {isModified} from './library.js'
|
||||||
|
|
||||||
|
console.log(await isModified('/Users/lanyuanxiaoyao/Project/IdeaProjects/hudi-service/pom.xml'))
|
||||||
Reference in New Issue
Block a user