@buildepicshit/cli 0.0.4 → 0.0.5
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 +1 -1
- package/src/orchestrator/core/__tests__/command.test.ts +13 -13
- package/src/orchestrator/core/command.ts +6 -17
- package/src/orchestrator/core/index.ts +1 -1
- package/src/orchestrator/core/types.ts +2 -5
- package/src/orchestrator/index.ts +1 -1
- package/src/orchestrator/presets/docker.ts +8 -19
- package/src/orchestrator/presets/nextjs.ts +10 -17
package/package.json
CHANGED
|
@@ -133,14 +133,14 @@ describe("command identity", () => {
|
|
|
133
133
|
expect(c.identity.name).toBe("tsx");
|
|
134
134
|
});
|
|
135
135
|
|
|
136
|
-
it("overrides identity with .
|
|
137
|
-
const c = cmd("node server.js").
|
|
136
|
+
it("overrides identity with .withIdentity(suffix)", () => {
|
|
137
|
+
const c = cmd("node server.js").withIdentity("custom").dir("apps/api");
|
|
138
138
|
expect(c.identity.name).toBe("custom");
|
|
139
139
|
});
|
|
140
140
|
|
|
141
141
|
it("identity suffix propagates through builder chain", () => {
|
|
142
142
|
const c = cmd("node server.js")
|
|
143
|
-
.
|
|
143
|
+
.withIdentity("api")
|
|
144
144
|
.dir("apps/server")
|
|
145
145
|
.env({ KEY: "value" })
|
|
146
146
|
.flag("verbose");
|
|
@@ -149,13 +149,13 @@ describe("command identity", () => {
|
|
|
149
149
|
|
|
150
150
|
it("identity is immutable across branches", () => {
|
|
151
151
|
const base = cmd("node server.js");
|
|
152
|
-
const withId = base.
|
|
152
|
+
const withId = base.withIdentity("custom");
|
|
153
153
|
expect(base.identity.name).toBe("node");
|
|
154
154
|
expect(withId.identity.name).toBe("custom");
|
|
155
155
|
});
|
|
156
156
|
|
|
157
157
|
it("identity.port() returns a token", async () => {
|
|
158
|
-
const c = cmd("node server.js").
|
|
158
|
+
const c = cmd("node server.js").withIdentity("api").dir("apps/api");
|
|
159
159
|
const token = c.identity.port();
|
|
160
160
|
expect(typeof token).toBe("function");
|
|
161
161
|
const port = Number.parseInt(
|
|
@@ -167,14 +167,14 @@ describe("command identity", () => {
|
|
|
167
167
|
});
|
|
168
168
|
|
|
169
169
|
it("identity.localhostUrl() returns a token", async () => {
|
|
170
|
-
const c = cmd("node server.js").
|
|
170
|
+
const c = cmd("node server.js").withIdentity("api");
|
|
171
171
|
const token = c.identity.localhostUrl("/health");
|
|
172
172
|
const url = await (token as (ctx: ComputeContext) => Promise<string>)(ctx);
|
|
173
173
|
expect(url).toMatch(/^http:\/\/localhost:\d+\/health$/);
|
|
174
174
|
});
|
|
175
175
|
|
|
176
176
|
it("cross-command identity access works", async () => {
|
|
177
|
-
const server = cmd("node server.js").
|
|
177
|
+
const server = cmd("node server.js").withIdentity("api").dir("apps/api");
|
|
178
178
|
const built = await cmd("next dev")
|
|
179
179
|
.env({ API_URL: server.identity.localhostUrl() })
|
|
180
180
|
.build(ctx);
|
|
@@ -182,7 +182,7 @@ describe("command identity", () => {
|
|
|
182
182
|
});
|
|
183
183
|
|
|
184
184
|
it("identity.port(name) resolves a named sub-identity", async () => {
|
|
185
|
-
const c = cmd("docker compose").
|
|
185
|
+
const c = cmd("docker compose").withIdentity("infra");
|
|
186
186
|
const dbPortToken = c.identity.port("database");
|
|
187
187
|
const infraPortToken = c.identity.port();
|
|
188
188
|
const dbPort = await (dbPortToken as (ctx: ComputeContext) => Promise<string>)(ctx);
|
|
@@ -193,7 +193,7 @@ describe("command identity", () => {
|
|
|
193
193
|
});
|
|
194
194
|
|
|
195
195
|
it("identity.localhostUrl with portIdentity option", async () => {
|
|
196
|
-
const c = cmd("docker compose").
|
|
196
|
+
const c = cmd("docker compose").withIdentity("infra");
|
|
197
197
|
const urlToken = c.identity.localhostUrl("/health", { portIdentity: "minio" });
|
|
198
198
|
const url = await (urlToken as (ctx: ComputeContext) => Promise<string>)(ctx);
|
|
199
199
|
expect(url).toMatch(/^http:\/\/localhost:\d+\/health$/);
|
|
@@ -216,7 +216,7 @@ describe("multiple waitFor", () => {
|
|
|
216
216
|
|
|
217
217
|
it("accepts callback form for multiple waitFor", async () => {
|
|
218
218
|
const c = cmd("node server.js")
|
|
219
|
-
.
|
|
219
|
+
.withIdentity("api")
|
|
220
220
|
.waitFor((self) => health.http(self.identity.url("/livez")))
|
|
221
221
|
.waitFor((self) => health.tcp("localhost", self.identity.port()));
|
|
222
222
|
const built = await c.build(ctx);
|
|
@@ -227,7 +227,7 @@ describe("multiple waitFor", () => {
|
|
|
227
227
|
describe("waitFor callback form", () => {
|
|
228
228
|
it("accepts a callback that receives the command", async () => {
|
|
229
229
|
const c = cmd("node server.js")
|
|
230
|
-
.
|
|
230
|
+
.withIdentity("api")
|
|
231
231
|
.dir("apps/api")
|
|
232
232
|
.waitFor((self) => health.http(self.identity.url("/livez")));
|
|
233
233
|
|
|
@@ -240,7 +240,7 @@ describe("waitFor callback form", () => {
|
|
|
240
240
|
describe("env callback form", () => {
|
|
241
241
|
it("accepts a callback that receives the command", async () => {
|
|
242
242
|
const c = cmd("node server.js")
|
|
243
|
-
.
|
|
243
|
+
.withIdentity("api")
|
|
244
244
|
.env((self) => ({ PORT: self.identity.port() }));
|
|
245
245
|
|
|
246
246
|
const built = await c.build(ctx);
|
|
@@ -251,7 +251,7 @@ describe("env callback form", () => {
|
|
|
251
251
|
|
|
252
252
|
it("mixes callback env with record env", async () => {
|
|
253
253
|
const c = cmd("node server.js")
|
|
254
|
-
.
|
|
254
|
+
.withIdentity("api")
|
|
255
255
|
.env({ A: "1" })
|
|
256
256
|
.env((self) => ({ PORT: self.identity.port() }))
|
|
257
257
|
.env({ B: "2" });
|
|
@@ -14,7 +14,6 @@ import {
|
|
|
14
14
|
type HealthCheck,
|
|
15
15
|
type HealthCheckCallback,
|
|
16
16
|
type ICommand,
|
|
17
|
-
type IdentityAccessor,
|
|
18
17
|
isEnvCallback,
|
|
19
18
|
isLazyEnvSource,
|
|
20
19
|
type Runnable,
|
|
@@ -41,24 +40,14 @@ class Command implements ICommand {
|
|
|
41
40
|
this.state = state;
|
|
42
41
|
}
|
|
43
42
|
|
|
44
|
-
get identity()
|
|
45
|
-
|
|
43
|
+
get identity() {
|
|
44
|
+
return createIdentity(
|
|
46
45
|
this.state.identitySuffix ?? this.deriveName(),
|
|
47
46
|
);
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
};
|
|
52
|
-
// Function.name is read-only, must use defineProperty
|
|
53
|
-
Object.defineProperty(setter, "name", {
|
|
54
|
-
configurable: true,
|
|
55
|
-
value: id.name,
|
|
56
|
-
});
|
|
57
|
-
return Object.assign(setter, {
|
|
58
|
-
localhostUrl: id.localhostUrl,
|
|
59
|
-
port: id.port,
|
|
60
|
-
url: id.url,
|
|
61
|
-
}) as IdentityAccessor;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
withIdentity(suffix: string): ICommand {
|
|
50
|
+
return new Command({ ...this.state, identitySuffix: suffix });
|
|
62
51
|
}
|
|
63
52
|
|
|
64
53
|
flag(name: string, value?: Token): ICommand {
|
|
@@ -46,10 +46,6 @@ export interface BuiltCommand {
|
|
|
46
46
|
env: Record<string, string>;
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
export interface IdentityAccessor extends Identity {
|
|
50
|
-
(suffix: string): ICommand;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
49
|
export interface ICommand {
|
|
54
50
|
readonly __type: "command";
|
|
55
51
|
arg(value: Token): ICommand;
|
|
@@ -60,9 +56,10 @@ export interface ICommand {
|
|
|
60
56
|
dir(path: string): ICommand;
|
|
61
57
|
env(source: EnvSource): ICommand;
|
|
62
58
|
flag(name: string, value?: Token): ICommand;
|
|
63
|
-
readonly identity:
|
|
59
|
+
readonly identity: Identity;
|
|
64
60
|
run(): Promise<void>;
|
|
65
61
|
waitFor(check: HealthCheck | HealthCheckCallback): ICommand;
|
|
62
|
+
withIdentity(suffix: string): ICommand;
|
|
66
63
|
}
|
|
67
64
|
|
|
68
65
|
// ─── Compound ────────────────────────────────────────────────────────────────
|
|
@@ -6,14 +6,15 @@ import type {
|
|
|
6
6
|
HealthCheck,
|
|
7
7
|
HealthCheckCallback,
|
|
8
8
|
ICommand,
|
|
9
|
-
IdentityAccessor,
|
|
10
9
|
Runnable,
|
|
11
10
|
Token,
|
|
12
11
|
} from "../core/types.js";
|
|
12
|
+
import type { Identity } from "../utils/dna.js";
|
|
13
13
|
|
|
14
14
|
export interface IDockerCompose extends ICommand {
|
|
15
15
|
file(path: string): IDockerCompose;
|
|
16
16
|
up(options?: { detach?: boolean }): IDockerCompose;
|
|
17
|
+
withIdentity(suffix: string): IDockerCompose;
|
|
17
18
|
}
|
|
18
19
|
|
|
19
20
|
interface DockerComposeState {
|
|
@@ -49,24 +50,12 @@ class DockerCompose implements IDockerCompose {
|
|
|
49
50
|
|
|
50
51
|
// ─── ICommand delegation (returns IDockerCompose for chaining) ───────
|
|
51
52
|
|
|
52
|
-
get identity():
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
self.dcState,
|
|
59
|
-
);
|
|
60
|
-
};
|
|
61
|
-
Object.defineProperty(setter, "name", {
|
|
62
|
-
configurable: true,
|
|
63
|
-
value: innerAccessor.name,
|
|
64
|
-
});
|
|
65
|
-
return Object.assign(setter, {
|
|
66
|
-
localhostUrl: innerAccessor.localhostUrl,
|
|
67
|
-
port: innerAccessor.port,
|
|
68
|
-
url: innerAccessor.url,
|
|
69
|
-
}) as IdentityAccessor;
|
|
53
|
+
get identity(): Identity {
|
|
54
|
+
return this.inner.identity;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
withIdentity(suffix: string): IDockerCompose {
|
|
58
|
+
return new DockerCompose(this.inner.withIdentity(suffix), this.dcState);
|
|
70
59
|
}
|
|
71
60
|
|
|
72
61
|
flag(name: string, value?: Token): IDockerCompose {
|
|
@@ -6,12 +6,14 @@ import type {
|
|
|
6
6
|
HealthCheck,
|
|
7
7
|
HealthCheckCallback,
|
|
8
8
|
ICommand,
|
|
9
|
-
IdentityAccessor,
|
|
10
9
|
Runnable,
|
|
11
10
|
Token,
|
|
12
11
|
} from "../core/types.js";
|
|
12
|
+
import type { Identity } from "../utils/dna.js";
|
|
13
13
|
|
|
14
|
-
export interface INextjs extends ICommand {
|
|
14
|
+
export interface INextjs extends ICommand {
|
|
15
|
+
withIdentity(suffix: string): INextjs;
|
|
16
|
+
}
|
|
15
17
|
|
|
16
18
|
/** @deprecated Use `INextjs` instead */
|
|
17
19
|
export type NextPreset = INextjs;
|
|
@@ -26,21 +28,12 @@ class Nextjs implements INextjs {
|
|
|
26
28
|
|
|
27
29
|
// ─── ICommand delegation (returns INextjs for chaining) ─────────────
|
|
28
30
|
|
|
29
|
-
get identity():
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
Object.defineProperty(setter, "name", {
|
|
36
|
-
configurable: true,
|
|
37
|
-
value: innerAccessor.name,
|
|
38
|
-
});
|
|
39
|
-
return Object.assign(setter, {
|
|
40
|
-
localhostUrl: innerAccessor.localhostUrl,
|
|
41
|
-
port: innerAccessor.port,
|
|
42
|
-
url: innerAccessor.url,
|
|
43
|
-
}) as IdentityAccessor;
|
|
31
|
+
get identity(): Identity {
|
|
32
|
+
return this.inner.identity;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
withIdentity(suffix: string): INextjs {
|
|
36
|
+
return new Nextjs(this.inner.withIdentity(suffix));
|
|
44
37
|
}
|
|
45
38
|
|
|
46
39
|
flag(name: string, value?: Token): INextjs {
|