airport2 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +17 -5
- package/airport.ts +0 -2
- package/bun.lock +5 -0
- package/package.json +4 -1
- package/src/airport/air/pipeline.ts +3 -3
- package/src/airport/air/step.ts +7 -5
- package/src/airport/air/task.ts +8 -8
- package/src/airport/index.ts +1 -20
- package/src/airport/lib/color.ts +10 -0
- package/src/airport/lib/index.ts +5 -0
- package/src/airport/lib/log.ts +2 -1
- package/src/airport/lib/run.ts +3 -2
- package/src/airport/types.ts +1 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,10 +1,22 @@
|
|
|
1
1
|
# CHANGELOG
|
|
2
2
|
|
|
3
|
+
|
|
4
|
+
## [0.0.3] - 2025-06-26
|
|
5
|
+
|
|
6
|
+
* 日志染色,高亮关键信息,更容易区分日志信息
|
|
7
|
+
* 优化部分代码,提高可读性和可维护性
|
|
8
|
+
* Step添加`skip`属性,支持跳过执行,默认为`false`
|
|
9
|
+
|
|
10
|
+
## [0.0.2] - 2025-06-26
|
|
11
|
+
|
|
12
|
+
* 一些优化
|
|
13
|
+
|
|
14
|
+
|
|
3
15
|
## [0.0.1] - 2025-06-25
|
|
4
16
|
|
|
5
17
|
### 初始版本发布
|
|
6
|
-
-
|
|
7
|
-
-
|
|
8
|
-
-
|
|
9
|
-
-
|
|
10
|
-
-
|
|
18
|
+
- 实现Pipeline-Task-Step三级架构
|
|
19
|
+
- 支持本地命令执行和远程SSH操作
|
|
20
|
+
- 添加单元测试框架和示例测试
|
|
21
|
+
- 实现测试模式,支持命令预览
|
|
22
|
+
- 完成基础文档和开发计划
|
package/airport.ts
CHANGED
|
@@ -18,10 +18,8 @@ const deployTask = new Task({
|
|
|
18
18
|
{
|
|
19
19
|
name: '发布到远程服务器',
|
|
20
20
|
async run() {
|
|
21
|
-
exec(true, 'ls -al .cache')
|
|
22
21
|
const ssh = remote('gavin@192.168.5.121')
|
|
23
22
|
const dir = (path?: string) => join('/home/gavin/test', path ?? '')
|
|
24
|
-
|
|
25
23
|
try {
|
|
26
24
|
await ssh.run('rm -f', dir('latest'))
|
|
27
25
|
await ssh.run('mkdir -p', dir(version))
|
package/bun.lock
CHANGED
|
@@ -3,6 +3,9 @@
|
|
|
3
3
|
"workspaces": {
|
|
4
4
|
"": {
|
|
5
5
|
"name": "ts-cicd",
|
|
6
|
+
"dependencies": {
|
|
7
|
+
"chalk": "^5.4.1",
|
|
8
|
+
},
|
|
6
9
|
"devDependencies": {
|
|
7
10
|
"@types/bun": "latest",
|
|
8
11
|
"@types/node": "^20.12.7",
|
|
@@ -136,6 +139,8 @@
|
|
|
136
139
|
|
|
137
140
|
"chai": ["chai@4.5.0", "", { "dependencies": { "assertion-error": "^1.1.0", "check-error": "^1.0.3", "deep-eql": "^4.1.3", "get-func-name": "^2.0.2", "loupe": "^2.3.6", "pathval": "^1.1.1", "type-detect": "^4.1.0" } }, "sha512-RITGBfijLkBddZvnn8jdqoTypxvqbOLYQkGGxXzeFjVHvudaPw0HNFD9x928/eUwYWd2dPCugVqspGALTZZQKw=="],
|
|
138
141
|
|
|
142
|
+
"chalk": ["chalk@5.4.1", "", {}, "sha512-zgVZuo2WcZgfUEmsn6eO3kINexW8RAE4maiQ8QNs8CtpPCSyMiYsULR3HQYkm3w8FIA3SberyMJMSldGsW+U3w=="],
|
|
143
|
+
|
|
139
144
|
"check-error": ["check-error@1.0.3", "", { "dependencies": { "get-func-name": "^2.0.2" } }, "sha512-iKEoDYaRmd1mxM90a2OEfWhjsjPpYPuQ+lMYsoxB126+t8fw7ySEO48nmDg5COTjxDI65/Y2OWpeEHk3ZOe8zg=="],
|
|
140
145
|
|
|
141
146
|
"confbox": ["confbox@0.1.8", "", {}, "sha512-RMtmw0iFkeR4YV+fUOSucriAQNb9g8zFR52MWCtl+cCZOFRNL6zeB395vPzFhEjjn4fMxXudmELnl/KF/WrK6w=="],
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "airport2",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"main": "src/index.ts",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
@@ -33,5 +33,8 @@
|
|
|
33
33
|
"@types/bun": "latest",
|
|
34
34
|
"@types/node": "^20.12.7",
|
|
35
35
|
"vitest": "^1.6.0"
|
|
36
|
+
},
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"chalk": "^5.4.1"
|
|
36
39
|
}
|
|
37
40
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Task } from './task'
|
|
2
|
-
import { log } from '../lib
|
|
2
|
+
import { log, purple, gray } from '../lib'
|
|
3
3
|
|
|
4
4
|
export class PipeLine {
|
|
5
5
|
public name?: string
|
|
@@ -17,12 +17,12 @@ export class PipeLine {
|
|
|
17
17
|
* 执行任务中的所有步骤
|
|
18
18
|
*/
|
|
19
19
|
async run() {
|
|
20
|
-
log('Start
|
|
20
|
+
log(purple('Pipe'), gray('Start'), ' -------------------------')
|
|
21
21
|
|
|
22
22
|
for (const task of this.tasks) {
|
|
23
23
|
await task.execute()
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
log(
|
|
26
|
+
log(`------------- ${purple("Pipe")} ${gray('End')} -------------`)
|
|
27
27
|
}
|
|
28
28
|
}
|
package/src/airport/air/step.ts
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
|
-
import { run } from '../lib
|
|
1
|
+
import { log, run } from '../lib'
|
|
2
2
|
import type { StepRaw } from '../types'
|
|
3
3
|
|
|
4
4
|
export class Step {
|
|
5
5
|
public name: string
|
|
6
|
-
|
|
6
|
+
public skip: boolean = false
|
|
7
7
|
private step: StepRaw
|
|
8
|
+
private test: boolean
|
|
8
9
|
|
|
9
10
|
constructor(step: StepRaw, test: boolean = false) {
|
|
10
11
|
this.test = test
|
|
11
12
|
this.step = step
|
|
12
13
|
this.name = step.name
|
|
14
|
+
this.skip = step.skip ?? false
|
|
13
15
|
}
|
|
14
16
|
|
|
15
17
|
/**
|
|
@@ -23,7 +25,7 @@ export class Step {
|
|
|
23
25
|
} else {
|
|
24
26
|
// 函数类型的步骤
|
|
25
27
|
if (this.test) {
|
|
26
|
-
|
|
28
|
+
log(`[TEST MODE] Would execute function: ${this.step.run.name}`)
|
|
27
29
|
} else {
|
|
28
30
|
// 实际执行函数
|
|
29
31
|
return await this.step.run()
|
|
@@ -37,7 +39,7 @@ export class Step {
|
|
|
37
39
|
private async runString() {
|
|
38
40
|
const runString = this.step.run as string
|
|
39
41
|
if (this.test) {
|
|
40
|
-
|
|
42
|
+
log(`[TEST MODE] Would execute: ${runString}`)
|
|
41
43
|
} else {
|
|
42
44
|
return await run(runString)
|
|
43
45
|
}
|
|
@@ -49,7 +51,7 @@ export class Step {
|
|
|
49
51
|
private async runArray() {
|
|
50
52
|
const runArray = this.step.run as string[]
|
|
51
53
|
if (this.test) {
|
|
52
|
-
|
|
54
|
+
log(`[TEST MODE] Would execute array: ${runArray}`)
|
|
53
55
|
} else {
|
|
54
56
|
for (const cmd of runArray) {
|
|
55
57
|
await run(cmd)
|
package/src/airport/air/task.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Step } from './step'
|
|
2
|
-
import { log } from '../lib
|
|
2
|
+
import { log, purple, gray, blue } from '../lib'
|
|
3
3
|
import type { TaskOptions, StepRaw } from '../types'
|
|
4
4
|
|
|
5
5
|
export class Task {
|
|
@@ -19,16 +19,16 @@ export class Task {
|
|
|
19
19
|
async execute(test: boolean = false) {
|
|
20
20
|
const steps = this.steps.map((step) => new Step(step, test))
|
|
21
21
|
|
|
22
|
-
log(
|
|
22
|
+
log(purple('Task'), gray('Start'), blue(this.name))
|
|
23
23
|
|
|
24
24
|
for (const step of steps) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
25
|
+
if (!step.skip) {
|
|
26
|
+
log(purple('Step'), gray('Start'), blue(step.name))
|
|
27
|
+
step.skip || (await step.execute())
|
|
28
|
+
log(purple('Step'), gray('End'), blue(step.name))
|
|
29
|
+
}
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
log(
|
|
32
|
+
log(purple('Task'), gray('End'), blue(this.name))
|
|
33
33
|
}
|
|
34
34
|
}
|
package/src/airport/index.ts
CHANGED
|
@@ -1,23 +1,4 @@
|
|
|
1
|
+
export * from './lib'
|
|
1
2
|
export * from './air/step'
|
|
2
3
|
export * from './air/task'
|
|
3
4
|
export * from './air/pipeline'
|
|
4
|
-
export * from './lib/run'
|
|
5
|
-
export * from './lib/remote'
|
|
6
|
-
export * from './lib/log'
|
|
7
|
-
|
|
8
|
-
// 导出默认的核心API
|
|
9
|
-
import { PipeLine } from './air/pipeline'
|
|
10
|
-
import { Task } from './air/task'
|
|
11
|
-
import { Step } from './air/step'
|
|
12
|
-
import { run, exec } from './lib/run'
|
|
13
|
-
import { log, logError } from './lib/log'
|
|
14
|
-
import { remote } from './lib/remote'
|
|
15
|
-
|
|
16
|
-
export default {
|
|
17
|
-
PipeLine,
|
|
18
|
-
Task,
|
|
19
|
-
Step,
|
|
20
|
-
remote,
|
|
21
|
-
run, exec,
|
|
22
|
-
log, logError,
|
|
23
|
-
}
|
package/src/airport/lib/log.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import { gray } from './color'
|
|
1
2
|
import { formatTimestamp } from './date'
|
|
2
3
|
|
|
3
4
|
export const log = (...args: any[]) => {
|
|
4
|
-
console.log(`[${formatTimestamp()}]
|
|
5
|
+
console.log(gray(`[${formatTimestamp()}]`), ...args)
|
|
5
6
|
}
|
|
6
7
|
|
|
7
8
|
export const logError = (...args: any[]) => {
|
package/src/airport/lib/run.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { log } from './log'
|
|
2
|
+
import { green, gray } from './color'
|
|
2
3
|
import { spawn, execSync } from 'child_process'
|
|
3
4
|
|
|
4
5
|
/**
|
|
@@ -10,7 +11,7 @@ import { spawn, execSync } from 'child_process'
|
|
|
10
11
|
*/
|
|
11
12
|
export const run = (command: string) =>
|
|
12
13
|
new Promise((resolve, reject) => {
|
|
13
|
-
log('Running:', command)
|
|
14
|
+
log(gray('Running:'), green(command))
|
|
14
15
|
const child = spawn(command, {
|
|
15
16
|
shell: true,
|
|
16
17
|
stdio: 'inherit',
|
|
@@ -37,7 +38,7 @@ export function exec(print: boolean | string, command?: string): string {
|
|
|
37
38
|
}
|
|
38
39
|
let output = execSync(command ?? 'echo').toString()
|
|
39
40
|
if (print) {
|
|
40
|
-
log('Running:', command)
|
|
41
|
+
log(gray('Running:'), green(command))
|
|
41
42
|
log(output)
|
|
42
43
|
}
|
|
43
44
|
return output
|