@atomservice/functions-cli 0.1.14 → 0.1.16
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/package.json +2 -2
- package/src/commands/bundle.ts +1 -1
- package/src/commands/dev.ts +15 -5
- package/src/commands/list.ts +1 -3
- package/src/commands/logs.ts +0 -1
- package/src/commands/rollback.ts +12 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atomservice/functions-cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.16",
|
|
4
4
|
"description": "函数服务命令行工具(atomfunctions):项目脚手架、本地构建、部署、运维",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"author": "openorson",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"atomfn": "./bin/functions.ts"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@atomservice/functions-sdk": "0.1.
|
|
33
|
+
"@atomservice/functions-sdk": "0.1.16",
|
|
34
34
|
"@clack/prompts": "1.5.0",
|
|
35
35
|
"change-case": "5.4.4",
|
|
36
36
|
"citty": "0.2.2",
|
package/src/commands/bundle.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import path from "node:path"
|
|
2
|
-
import { $ } from "bun"
|
|
3
2
|
import { confirm, intro, isCancel, log, outro, select, text } from "@clack/prompts"
|
|
3
|
+
import { $ } from "bun"
|
|
4
4
|
import { defineCommand } from "citty"
|
|
5
5
|
import pc from "picocolors"
|
|
6
6
|
import { BUNDLE_FILE, BUNDLES_DIR } from "../consts.ts"
|
package/src/commands/dev.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { existsSync, readdirSync } from "node:fs"
|
|
2
1
|
import type { Dirent } from "node:fs"
|
|
2
|
+
import { existsSync, readdirSync } from "node:fs"
|
|
3
3
|
import { rm, writeFile } from "node:fs/promises"
|
|
4
4
|
import { connect } from "node:net"
|
|
5
5
|
import path from "node:path"
|
|
@@ -7,7 +7,7 @@ import { intro, log, outro, select, text } from "@clack/prompts"
|
|
|
7
7
|
import { defineCommand } from "citty"
|
|
8
8
|
import pc from "picocolors"
|
|
9
9
|
import { resolveFunctions, writeEntry } from "../build.ts"
|
|
10
|
-
import {
|
|
10
|
+
import { BUNDLE_FILE, BUNDLES_DIR, DEFAULT_DEV_PORT, DEV_PID_FILE } from "../consts.ts"
|
|
11
11
|
import { loadContext } from "../context.ts"
|
|
12
12
|
import type { BundleConfig } from "../types.ts"
|
|
13
13
|
import { isValidSlug, readJson, unwrap, writeJson } from "../utils.ts"
|
|
@@ -67,7 +67,9 @@ const startCommand = defineCommand({
|
|
|
67
67
|
log.error("尚未创建任何 bundle,请先运行 atomfunctions bundle create")
|
|
68
68
|
process.exit(1)
|
|
69
69
|
}
|
|
70
|
-
bundle = unwrap(
|
|
70
|
+
bundle = unwrap(
|
|
71
|
+
await select({ message: "选择函数包", options: bundles.map((b) => ({ value: b, label: b })) }),
|
|
72
|
+
) as string
|
|
71
73
|
}
|
|
72
74
|
|
|
73
75
|
const bundleDir = path.join(ctx.root, BUNDLES_DIR, bundle)
|
|
@@ -102,7 +104,11 @@ const startCommand = defineCommand({
|
|
|
102
104
|
|
|
103
105
|
const pf = pidFile(bundleDir)
|
|
104
106
|
if (existsSync(pf)) {
|
|
105
|
-
const oldPid = Number(
|
|
107
|
+
const oldPid = Number(
|
|
108
|
+
await Bun.file(pf)
|
|
109
|
+
.text()
|
|
110
|
+
.catch(() => ""),
|
|
111
|
+
)
|
|
106
112
|
if (oldPid && isProcessAlive(oldPid)) {
|
|
107
113
|
log.error(`bundle ${bundle} 已在运行中(pid ${oldPid})`)
|
|
108
114
|
process.exit(1)
|
|
@@ -177,7 +183,11 @@ const stopCommand = defineCommand({
|
|
|
177
183
|
for (const b of bundles) {
|
|
178
184
|
const pf = pidFile(path.join(ctx.root, BUNDLES_DIR, b))
|
|
179
185
|
if (!existsSync(pf)) continue
|
|
180
|
-
const pid = Number(
|
|
186
|
+
const pid = Number(
|
|
187
|
+
await Bun.file(pf)
|
|
188
|
+
.text()
|
|
189
|
+
.catch(() => ""),
|
|
190
|
+
)
|
|
181
191
|
if (!pid) continue
|
|
182
192
|
if (isProcessAlive(pid)) {
|
|
183
193
|
try {
|
package/src/commands/list.ts
CHANGED
|
@@ -53,9 +53,7 @@ export const listCommand = defineCommand({
|
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
for (const b of bundles) {
|
|
56
|
-
log.info(
|
|
57
|
-
`${pc.bold(b.bundle)} ${pc.dim(`${b.artifact}:${b.version}`)}\n 函数:${b.functions.join(", ")}`,
|
|
58
|
-
)
|
|
56
|
+
log.info(`${pc.bold(b.bundle)} ${pc.dim(`${b.artifact}:${b.version}`)}\n 函数:${b.functions.join(", ")}`)
|
|
59
57
|
}
|
|
60
58
|
outro(pc.green(`共 ${bundles.length} 个函数包`))
|
|
61
59
|
},
|
package/src/commands/logs.ts
CHANGED
package/src/commands/rollback.ts
CHANGED
|
@@ -81,7 +81,9 @@ export const rollbackCommand = defineCommand({
|
|
|
81
81
|
let bundle: string
|
|
82
82
|
if (args.bundle) {
|
|
83
83
|
if (!commonBundles.includes(args.bundle)) {
|
|
84
|
-
const missingOn = bundlesResults
|
|
84
|
+
const missingOn = bundlesResults
|
|
85
|
+
.filter((r) => !r.bundles.some((b) => b.bundle === args.bundle))
|
|
86
|
+
.map((r) => r.host)
|
|
85
87
|
log.error(`bundle ${args.bundle} 未在 ${missingOn.join("、")} 上部署`)
|
|
86
88
|
process.exit(1)
|
|
87
89
|
}
|
|
@@ -106,7 +108,12 @@ export const rollbackCommand = defineCommand({
|
|
|
106
108
|
for (const t of targets) {
|
|
107
109
|
try {
|
|
108
110
|
const c = new AdminClient(t.server, t.token)
|
|
109
|
-
versionResults.push({
|
|
111
|
+
versionResults.push({
|
|
112
|
+
host: t.host,
|
|
113
|
+
server: t.server,
|
|
114
|
+
token: t.token,
|
|
115
|
+
versions: await c.versions(ctx.project, bundle),
|
|
116
|
+
})
|
|
110
117
|
} catch (err) {
|
|
111
118
|
log.error(`${t.host}: ${err instanceof Error ? err.message : "获取版本历史失败"}`)
|
|
112
119
|
process.exit(1)
|
|
@@ -125,7 +132,9 @@ export const rollbackCommand = defineCommand({
|
|
|
125
132
|
let version: string
|
|
126
133
|
if (args.version) {
|
|
127
134
|
if (!commonVersions.includes(args.version)) {
|
|
128
|
-
const missingOn = versionResults
|
|
135
|
+
const missingOn = versionResults
|
|
136
|
+
.filter((r) => !r.versions.some((v) => v.version === args.version))
|
|
137
|
+
.map((r) => r.host)
|
|
129
138
|
log.error(`版本 ${args.version} 未在 ${missingOn.join("、")} 上存在`)
|
|
130
139
|
process.exit(1)
|
|
131
140
|
}
|