@walkeros/cli 0.3.6 → 0.4.0
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 +12 -0
- package/dist/__tests__/bundle/bundler.test.js +6 -0
- package/dist/__tests__/bundle/bundler.test.js.map +1 -1
- package/dist/__tests__/bundle/programmatic.test.js +4 -0
- package/dist/__tests__/bundle/programmatic.test.js.map +1 -1
- package/dist/__tests__/cli-e2e.test.js +1 -1
- package/dist/__tests__/cli-e2e.test.js.map +1 -1
- package/dist/__tests__/cli.test.js +6 -2
- package/dist/__tests__/cli.test.js.map +1 -1
- package/dist/__tests__/simulate/programmatic.test.js +1 -1
- package/dist/__tests__/simulate/programmatic.test.js.map +1 -1
- package/dist/__tests__/simulate/simulator.test.js +1 -1
- package/dist/__tests__/simulate/simulator.test.js.map +1 -1
- package/dist/commands/bundle/bundler.js +20 -20
- package/dist/commands/bundle/bundler.js.map +1 -1
- package/dist/commands/bundle/template-engine.d.ts.map +1 -1
- package/dist/commands/bundle/template-engine.js +2 -0
- package/dist/commands/bundle/template-engine.js.map +1 -1
- package/dist/commands/simulate/index.d.ts.map +1 -1
- package/dist/commands/simulate/index.js +6 -3
- package/dist/commands/simulate/index.js.map +1 -1
- package/dist/commands/simulate/jsdom-executor.d.ts +32 -0
- package/dist/commands/simulate/jsdom-executor.d.ts.map +1 -0
- package/dist/commands/simulate/jsdom-executor.js +160 -0
- package/dist/commands/simulate/jsdom-executor.js.map +1 -0
- package/dist/commands/simulate/simulator.d.ts +0 -4
- package/dist/commands/simulate/simulator.d.ts.map +1 -1
- package/dist/commands/simulate/simulator.js +22 -104
- package/dist/commands/simulate/simulator.js.map +1 -1
- package/dist/config/defaults.d.ts.map +1 -1
- package/dist/config/defaults.js +0 -1
- package/dist/config/defaults.js.map +1 -1
- package/dist/config/index.d.ts +1 -1
- package/dist/config/index.d.ts.map +1 -1
- package/dist/config/index.js +1 -1
- package/dist/config/index.js.map +1 -1
- package/dist/config/parser.d.ts.map +1 -1
- package/dist/config/parser.js +9 -0
- package/dist/config/parser.js.map +1 -1
- package/dist/config/utils.d.ts +46 -0
- package/dist/config/utils.d.ts.map +1 -1
- package/dist/config/utils.js +102 -0
- package/dist/config/utils.js.map +1 -1
- package/dist/index.d.ts +26 -12
- package/dist/index.js +123 -2103
- package/dist/index.js.map +1 -1
- package/dist/types/bundle.d.ts +26 -12
- package/dist/types/bundle.d.ts.map +1 -1
- package/examples/.npm-cache/content-v2/sha512/0d/2d/7581c288670eaf8538ddd9df145b78756ce3be0791c6e0b9cd33429b3bae894525b9bda287a3cedffbcdd2c7b3107bafc03f2b0367eea489eee1cc042abb +1 -0
- package/examples/.npm-cache/content-v2/sha512/12/20/bc4f5acca143809f7e07da1fdafb38137d93243de4d5b403e6e10b92d0d3a6e51eab24fe9dbc9d3ed1cd72e8f7a406085e99c422bb2c7d1166cf9f1f564e +0 -0
- package/examples/.npm-cache/content-v2/sha512/22/ee/fb2695b01871c1d36946bdcfb49f1b520a57200d0a0b221b1e7d5f047ab38a8b2ab0e5f0e25a00acde1f3f2f9d24430a18f1092d438bc1a9e9891cc45f75 +0 -0
- package/examples/.npm-cache/content-v2/sha512/24/89/da1ce6a61bca6de7e132f241a675c01c83738bf6b78af25b5cce01d3030361332b3fe938571e2b721f1555da9ddf930fdcf8c02f0471556071590e68cc09 +0 -0
- package/examples/.npm-cache/content-v2/sha512/47/fd/c6be997da99228c3e279b95d4a46d6913947078a178f54ac71795a159f3513b1483232f4c2d0a1f403178bf9f96bb19615de32a9e2133e949880c6bc15e2 +0 -0
- package/examples/.npm-cache/content-v2/sha512/4b/1c/c1cb7f8b32102071a89fef97158daa32080ebaedfbbd596880d2213d84e305abc76d2a95a412ded55c1c3d487adcb1ceff87fc2c85d7e2856ebd9d3f16f3 +0 -0
- package/examples/.npm-cache/content-v2/sha512/6e/53/ff864769671f44f39d8a3bf904cd646535b745cc4824a8bb3189193b474678049f43b5178ba15cad7f0289046105e70f1565afc84e907120b35a466690fd +1 -0
- package/examples/.npm-cache/content-v2/sha512/70/4c/4c8837d446965c5551b4ea527e95fa011744fb727581d82cf35bb5599ea0b57d18baa490f7af93ef9a16e8e45e5c0802737da20575f4056a4a5c9a3cd288 +0 -0
- package/examples/.npm-cache/content-v2/sha512/96/ad/05de3bbb12d7de8ea353f962bdaea7d2eb44f707f2973462a6635daf537c67b46cca7764fed7d464fe62152c3f783a07aba1ceb35e09ad446bff05a4b466 +1 -0
- package/examples/.npm-cache/content-v2/sha512/b5/20/52dde94e6cef7170f6089c64a4843e57be18be450d956f4e455905aed047ae6a368451c93035e6ac3ee59576b600f03f815afba0836b3a16e10a9aaca4ba +1 -0
- package/examples/.npm-cache/content-v2/sha512/c7/a9/d166a1c39f97df312c59261319ba1cf9aac178bda0a0cb697d5ddd78bd8dd38ef1bf40017bcc8633c2049896c2d70696d9bff9280851f270792ff38bb3a0 +1 -0
- package/examples/.npm-cache/content-v2/sha512/e0/d0/8c14083b633e6adbd3c6a93da5fc0f6bbd456c5512ef276920bedd8d85d551052adff992de977aff326616a211aaa2d6ddcc801149e9b7f914f566359b6a +1 -0
- package/examples/.npm-cache/content-v2/sha512/e7/c5/06ad3fd79ac4f1031fe0b16ea5e54e232ca397bbcd7592c679021cbfb027276099f8c848f3f7a7691f0102ad53aa64f9141e61d729b037a678bd60440d17 +1 -0
- package/examples/.npm-cache/content-v2/sha512/f3/28/d5d32329604ed7d471a4949105daa2cc98858cf24f45b0b97c41d0eb0d5a9fe7bf1f69c792161cc6693e4fc1b52e886ac41875ebfb8fe47fafe417ca3e6e +0 -0
- package/examples/.npm-cache/index-v5/04/5a/2b5d7a7c407d85d746baa0f5c9388a333e35a717a8a0a81943daa6cb1364 +3 -0
- package/examples/.npm-cache/index-v5/12/9a/eba560cbace295d8ee04cf283015377bd77b379e70968fb6bc407c7fc410 +15 -0
- package/examples/.npm-cache/index-v5/2f/a2/7b047564b0ee21ac835ec609e89153dd6549be554d098584d5bfd19fe043 +15 -0
- package/examples/.npm-cache/index-v5/32/8e/322d58dd8d1e000be248ada51385bf96288e56039de9feec1a4c6a467653 +3 -0
- package/examples/.npm-cache/index-v5/57/93/d1d7cd1402e3e26468db03f2870822bb2c9018a506cdfb3b405f38cd3e1c +3 -0
- package/examples/.npm-cache/index-v5/5d/f8/0a1f4fa7149e4ff33e09eb6aea41ac8d1730c868a5d3ace91f762698acff +3 -0
- package/examples/.npm-cache/index-v5/69/a4/a92c72d838259b051cdf8e0acfb2bc680b6d4cfc642314a7836c3f7b2c50 +15 -0
- package/examples/.npm-cache/index-v5/71/31/6da3423bb203f3de5eb16c942431073f89be2cfcb40058ec91dcb5ce0abc +15 -0
- package/examples/.npm-cache/index-v5/7b/94/72b6bffa050d9ef52a558dd220663695bc606f756be0dfa196ef4f3913ba +3 -0
- package/examples/.npm-cache/index-v5/85/9e/99e97fdd562517e56285337db91d1a8f2f416b8d631cf4d7d754fa671299 +15 -0
- package/examples/.npm-cache/index-v5/92/4c/9416ada81a9b3c679539fd1ab53f8de3d41ff268f35eba7a194389a85b06 +3 -0
- package/examples/.npm-cache/index-v5/c1/5a/13df76b218deed8a6ef12961116af5183db98c53fad1b922fd9edc075247 +3 -0
- package/examples/.npm-cache/index-v5/cb/11/253c55410a8ab7c4a9ea9d6e1bf8ef1450a581da64c478074dfd82c8bff6 +3 -0
- package/examples/.npm-cache/index-v5/d5/ae/b57fad3a62b5ba2dbdf24b042a9e7b70820f3db00e5a630f02e1fea020dc +3 -0
- package/examples/.npm-cache/index-v5/d6/32/2f620f83c7d14451de98de8298c2408e05a16cc0829bd16c891ac19d7a67 +3 -0
- package/examples/.npm-cache/index-v5/dd/b5/01dc7a3cd8b6a03a69aee9af500d51ae19cb0aa12631a4aafd152148b8e5 +15 -0
- package/examples/.npm-cache/index-v5/e0/cf/6b862c15d74630d3871cd813d305210ab741311deb10baf8813014e0bc30 +3 -0
- package/examples/.npm-cache/index-v5/e2/be/e880ccd35950a814d3c1dded34d3938ac61b15a195321dc51357f801aad4 +15 -0
- package/examples/.npm-cache/index-v5/e5/1f/f4affe0b392cd03288f23cc03abcb274ff11a2c8f8965299de681914abb2 +3 -0
- package/examples/.npm-cache/index-v5/f3/5b/9ebe450958ff0d7cc44ab0a00080cb8a3ff1389744b5eab5f97b68a6a6af +3 -0
- package/examples/.npm-cache/index-v5/fb/c1/0de405e902866d53e7c30cf36a97dc2578838622b261816f44dc377c9a80 +3 -0
- package/examples/README.md +4 -4
- package/examples/event.json +53 -0
- package/examples/flow-order-complete.json +68 -0
- package/examples/flow-simple.json +32 -0
- package/examples/flow.json +82 -0
- package/examples/test.html +43 -0
- package/examples/web-serve.js +45 -0
- package/examples/web-serve.json +4 -3
- package/package.json +2 -2
- package/templates/server.hbs +2 -2
- package/templates/web.hbs +12 -11
- package/examples/web-serve.mjs +0 -19456
package/dist/index.js
CHANGED
|
@@ -1,2112 +1,132 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
console.log(chalk.yellow(message));
|
|
52
|
-
}
|
|
53
|
-
},
|
|
54
|
-
warn: (...args) => {
|
|
55
|
-
if (shouldLog) {
|
|
56
|
-
const message = args.map((arg) => String(arg)).join(" ");
|
|
57
|
-
console.log(chalk.yellow(message));
|
|
58
|
-
}
|
|
59
|
-
},
|
|
60
|
-
error: (...args) => {
|
|
61
|
-
if (!json) {
|
|
62
|
-
const message = args.map((arg) => String(arg)).join(" ");
|
|
63
|
-
console.error(chalk.red(message));
|
|
64
|
-
}
|
|
65
|
-
},
|
|
66
|
-
debug: (...args) => {
|
|
67
|
-
if (shouldDebug) {
|
|
68
|
-
const message = args.map((arg) => String(arg)).join(" ");
|
|
69
|
-
console.log(chalk.gray(message));
|
|
70
|
-
}
|
|
71
|
-
},
|
|
72
|
-
gray: (...args) => {
|
|
73
|
-
if (shouldLog) {
|
|
74
|
-
const message = args.map((arg) => String(arg)).join(" ");
|
|
75
|
-
console.log(chalk.gray(message));
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
// src/core/timer.ts
|
|
82
|
-
function createTimer() {
|
|
83
|
-
let startTime = 0;
|
|
84
|
-
let endTime = 0;
|
|
85
|
-
return {
|
|
86
|
-
start() {
|
|
87
|
-
startTime = Date.now();
|
|
88
|
-
endTime = 0;
|
|
89
|
-
},
|
|
90
|
-
end() {
|
|
91
|
-
endTime = Date.now();
|
|
92
|
-
return endTime - startTime;
|
|
93
|
-
},
|
|
94
|
-
getElapsed() {
|
|
95
|
-
const currentTime = endTime || Date.now();
|
|
96
|
-
return currentTime - startTime;
|
|
97
|
-
},
|
|
98
|
-
format() {
|
|
99
|
-
const elapsed = this.getElapsed();
|
|
100
|
-
return (elapsed / 1e3).toFixed(2) + "s";
|
|
101
|
-
}
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
// src/core/output.ts
|
|
106
|
-
function createJsonOutput(success, data, error, duration) {
|
|
107
|
-
return {
|
|
108
|
-
success,
|
|
109
|
-
...data && { data },
|
|
110
|
-
...error && { error },
|
|
111
|
-
...duration && { duration }
|
|
112
|
-
};
|
|
113
|
-
}
|
|
114
|
-
function createSuccessOutput(data, duration) {
|
|
115
|
-
return createJsonOutput(true, data, void 0, duration);
|
|
116
|
-
}
|
|
117
|
-
function createErrorOutput(error, duration) {
|
|
118
|
-
return createJsonOutput(false, void 0, error, duration);
|
|
119
|
-
}
|
|
120
|
-
function formatBytes(bytes) {
|
|
121
|
-
return (bytes / 1024).toFixed(2);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
// src/core/docker.ts
|
|
125
|
-
import { spawn } from "child_process";
|
|
126
|
-
import path2 from "path";
|
|
127
|
-
import { readFileSync } from "fs";
|
|
128
|
-
import { fileURLToPath } from "url";
|
|
129
|
-
import { VERSION as DOCKER_VERSION } from "@walkeros/docker";
|
|
130
|
-
|
|
131
|
-
// src/config/utils.ts
|
|
132
|
-
import fs from "fs-extra";
|
|
133
|
-
import path from "path";
|
|
134
|
-
import os from "os";
|
|
135
|
-
function isUrl(str) {
|
|
136
|
-
try {
|
|
137
|
-
const url = new URL(str);
|
|
138
|
-
return url.protocol === "http:" || url.protocol === "https:";
|
|
139
|
-
} catch {
|
|
140
|
-
return false;
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
async function downloadFromUrl(url) {
|
|
144
|
-
if (!isUrl(url)) {
|
|
145
|
-
throw new Error(`Invalid URL: ${url}`);
|
|
146
|
-
}
|
|
147
|
-
try {
|
|
148
|
-
const response = await fetch(url);
|
|
149
|
-
if (!response.ok) {
|
|
150
|
-
throw new Error(
|
|
151
|
-
`Failed to download ${url}: ${response.status} ${response.statusText}`
|
|
152
|
-
);
|
|
153
|
-
}
|
|
154
|
-
const content = await response.text();
|
|
155
|
-
const urlObj = new URL(url);
|
|
156
|
-
const urlFilename = path.basename(urlObj.pathname);
|
|
157
|
-
const extension = path.extname(urlFilename) || ".json";
|
|
158
|
-
const randomId = Math.random().toString(36).substring(2, 11);
|
|
159
|
-
const filename = `walkeros-download-${Date.now()}-${randomId}${extension}`;
|
|
160
|
-
const tempPath = path.join(os.tmpdir(), filename);
|
|
161
|
-
await fs.writeFile(tempPath, content, "utf-8");
|
|
162
|
-
return tempPath;
|
|
163
|
-
} catch (error) {
|
|
164
|
-
if (error instanceof Error) {
|
|
165
|
-
throw new Error(`Failed to download from URL: ${error.message}`);
|
|
166
|
-
}
|
|
167
|
-
throw error;
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
async function loadJsonConfig(configPath) {
|
|
171
|
-
let absolutePath;
|
|
172
|
-
let isTemporary = false;
|
|
173
|
-
if (isUrl(configPath)) {
|
|
174
|
-
absolutePath = await downloadFromUrl(configPath);
|
|
175
|
-
isTemporary = true;
|
|
176
|
-
} else {
|
|
177
|
-
absolutePath = path.resolve(configPath);
|
|
178
|
-
if (!await fs.pathExists(absolutePath)) {
|
|
179
|
-
throw new Error(`Configuration file not found: ${absolutePath}`);
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
try {
|
|
183
|
-
const rawConfig = await fs.readJson(absolutePath);
|
|
184
|
-
return rawConfig;
|
|
185
|
-
} catch (error) {
|
|
186
|
-
throw new Error(
|
|
187
|
-
`Invalid JSON in config file: ${configPath}. ${error instanceof Error ? error.message : error}`
|
|
188
|
-
);
|
|
189
|
-
} finally {
|
|
190
|
-
if (isTemporary) {
|
|
191
|
-
try {
|
|
192
|
-
await fs.remove(absolutePath);
|
|
193
|
-
} catch {
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
function getTempDir(tempDir = ".tmp") {
|
|
199
|
-
const randomId = Math.random().toString(36).substring(2, 11);
|
|
200
|
-
const basePath = path.isAbsolute(tempDir) ? tempDir : path.join(process.cwd(), tempDir);
|
|
201
|
-
return path.join(basePath, `cli-${Date.now()}-${randomId}`);
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
// src/core/docker.ts
|
|
205
|
-
function readPackageVersion() {
|
|
206
|
-
const moduleFilename = fileURLToPath(import.meta.url);
|
|
207
|
-
const moduleDir = path2.dirname(moduleFilename);
|
|
208
|
-
const prodPath = path2.join(moduleDir, "../package.json");
|
|
209
|
-
try {
|
|
210
|
-
const pkg = JSON.parse(readFileSync(prodPath, "utf-8"));
|
|
211
|
-
return pkg.version;
|
|
212
|
-
} catch {
|
|
213
|
-
const devPath = path2.join(moduleDir, "../../package.json");
|
|
214
|
-
const pkg = JSON.parse(readFileSync(devPath, "utf-8"));
|
|
215
|
-
return pkg.version;
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
var CLI_VERSION = readPackageVersion();
|
|
219
|
-
var CLI_DOCKER_IMAGE = process.env.WALKEROS_CLI_DOCKER_IMAGE || `walkeros/cli:${CLI_VERSION}`;
|
|
220
|
-
var RUNTIME_DOCKER_IMAGE = process.env.WALKEROS_RUNTIME_DOCKER_IMAGE || `walkeros/docker:${DOCKER_VERSION}`;
|
|
221
|
-
function buildDockerCommand(command, args, options = {}, configFile) {
|
|
222
|
-
const cwd = process.cwd();
|
|
223
|
-
const cmd = ["docker", "run", "--rm"];
|
|
224
|
-
if (configFile && !isUrl(configFile)) {
|
|
225
|
-
const configPath = path2.resolve(cwd, configFile);
|
|
226
|
-
cmd.push("-v", `${configPath}:/config/flow.json:ro`);
|
|
227
|
-
args = args.map((arg) => arg === configFile ? "/config/flow.json" : arg);
|
|
228
|
-
}
|
|
229
|
-
cmd.push("-v", `${cwd}:/workspace`);
|
|
230
|
-
cmd.push("-w", "/workspace");
|
|
231
|
-
if (process.platform !== "win32") {
|
|
232
|
-
try {
|
|
233
|
-
const uid = process.getuid?.();
|
|
234
|
-
const gid = process.getgid?.();
|
|
235
|
-
if (uid !== void 0 && gid !== void 0) {
|
|
236
|
-
cmd.push("--user", `${uid}:${gid}`);
|
|
237
|
-
}
|
|
238
|
-
} catch {
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
if (options.verbose) {
|
|
242
|
-
cmd.push("-e", "VERBOSE=true");
|
|
243
|
-
}
|
|
244
|
-
if (options.silent) {
|
|
245
|
-
cmd.push("-e", "SILENT=true");
|
|
246
|
-
}
|
|
247
|
-
cmd.push(CLI_DOCKER_IMAGE);
|
|
248
|
-
cmd.push(command, ...args);
|
|
249
|
-
return cmd;
|
|
250
|
-
}
|
|
251
|
-
async function executeInDocker(command, args, options = {}, configFile) {
|
|
252
|
-
const containerArgs = [...args, "--local"];
|
|
253
|
-
const dockerCmd = buildDockerCommand(
|
|
254
|
-
command,
|
|
255
|
-
containerArgs,
|
|
256
|
-
options,
|
|
257
|
-
configFile
|
|
258
|
-
);
|
|
259
|
-
return new Promise((resolve, reject) => {
|
|
260
|
-
const proc = spawn(dockerCmd[0], dockerCmd.slice(1), {
|
|
261
|
-
stdio: options.silent ? "ignore" : "inherit",
|
|
262
|
-
shell: false
|
|
263
|
-
});
|
|
264
|
-
proc.on("error", (error) => {
|
|
265
|
-
reject(new Error(`Docker execution failed: ${error.message}`));
|
|
266
|
-
});
|
|
267
|
-
proc.on("exit", (code) => {
|
|
268
|
-
if (code === 0) {
|
|
269
|
-
resolve();
|
|
270
|
-
} else {
|
|
271
|
-
reject(new Error(`Docker command exited with code ${code}`));
|
|
272
|
-
}
|
|
273
|
-
});
|
|
274
|
-
});
|
|
275
|
-
}
|
|
276
|
-
async function isDockerAvailable() {
|
|
277
|
-
return new Promise((resolve) => {
|
|
278
|
-
const proc = spawn("docker", ["--version"], {
|
|
279
|
-
stdio: "ignore"
|
|
280
|
-
});
|
|
281
|
-
proc.on("error", () => resolve(false));
|
|
282
|
-
proc.on("exit", (code) => resolve(code === 0));
|
|
283
|
-
});
|
|
284
|
-
}
|
|
285
|
-
function buildDockerRunCommand(mode, flowPath, options = {}) {
|
|
286
|
-
const cwd = process.cwd();
|
|
287
|
-
const cmd = ["docker", "run", "--rm"];
|
|
288
|
-
cmd.push("-e", `MODE=${mode}`);
|
|
289
|
-
if (mode === "collect" && flowPath) {
|
|
290
|
-
const absoluteFlowPath = path2.resolve(cwd, flowPath);
|
|
291
|
-
cmd.push("-v", `${absoluteFlowPath}:/app/flow.mjs:ro`);
|
|
292
|
-
cmd.push("-e", "FLOW=/app/flow.mjs");
|
|
293
|
-
}
|
|
294
|
-
if (mode === "serve" && flowPath) {
|
|
295
|
-
const absoluteFilePath = path2.resolve(cwd, flowPath);
|
|
296
|
-
cmd.push("-v", `${absoluteFilePath}:/app/bundle.mjs:ro`);
|
|
297
|
-
cmd.push("-e", "FILE_PATH=/app/bundle.mjs");
|
|
298
|
-
}
|
|
299
|
-
const port = options.port !== void 0 ? options.port : 8080;
|
|
300
|
-
cmd.push("-p", `${port}:${port}`);
|
|
301
|
-
cmd.push("-e", `PORT=${port}`);
|
|
302
|
-
if (options.host) {
|
|
303
|
-
cmd.push("-e", `HOST=${options.host}`);
|
|
304
|
-
}
|
|
305
|
-
if (options.serveName) {
|
|
306
|
-
cmd.push("-e", `SERVE_NAME=${options.serveName}`);
|
|
307
|
-
}
|
|
308
|
-
if (options.servePath) {
|
|
309
|
-
cmd.push("-e", `SERVE_PATH=${options.servePath}`);
|
|
310
|
-
}
|
|
311
|
-
if (process.platform !== "win32") {
|
|
312
|
-
try {
|
|
313
|
-
const uid = process.getuid?.();
|
|
314
|
-
const gid = process.getgid?.();
|
|
315
|
-
if (uid !== void 0 && gid !== void 0) {
|
|
316
|
-
cmd.push("--user", `${uid}:${gid}`);
|
|
317
|
-
}
|
|
318
|
-
} catch {
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
cmd.push(RUNTIME_DOCKER_IMAGE);
|
|
322
|
-
return cmd;
|
|
323
|
-
}
|
|
324
|
-
async function executeRunInDocker(mode, flowPath, options = {}) {
|
|
325
|
-
const dockerCmd = buildDockerRunCommand(mode, flowPath, options);
|
|
326
|
-
return new Promise((resolve, reject) => {
|
|
327
|
-
const proc = spawn(dockerCmd[0], dockerCmd.slice(1), {
|
|
328
|
-
stdio: options.silent ? "ignore" : "inherit",
|
|
329
|
-
shell: false
|
|
330
|
-
});
|
|
331
|
-
proc.on("error", (error) => {
|
|
332
|
-
reject(new Error(`Docker execution failed: ${error.message}`));
|
|
333
|
-
});
|
|
334
|
-
proc.on("exit", (code) => {
|
|
335
|
-
if (code === 0) {
|
|
336
|
-
resolve();
|
|
337
|
-
} else {
|
|
338
|
-
reject(new Error(`Docker command exited with code ${code}`));
|
|
339
|
-
}
|
|
340
|
-
});
|
|
341
|
-
});
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
// src/core/execution.ts
|
|
345
|
-
function getExecutionMode(options) {
|
|
346
|
-
if (options.local || process.env.WALKEROS_CONTAINER === "true") {
|
|
347
|
-
return "local";
|
|
348
|
-
}
|
|
349
|
-
return "docker";
|
|
350
|
-
}
|
|
351
|
-
async function executeCommand(localHandler, dockerCommand, dockerArgs, options, logger, configFile) {
|
|
352
|
-
const mode = getExecutionMode(options);
|
|
353
|
-
if (options.dryRun) {
|
|
354
|
-
if (mode === "docker") {
|
|
355
|
-
const cmd = `docker run walkeros/cli:latest ${dockerCommand} ${dockerArgs.join(" ")}`;
|
|
356
|
-
logger?.info(`[DRY-RUN] Would execute: ${cmd}`);
|
|
357
|
-
} else {
|
|
358
|
-
logger?.info(
|
|
359
|
-
`[DRY-RUN] Would execute locally: ${dockerCommand} ${dockerArgs.join(" ")}`
|
|
360
|
-
);
|
|
361
|
-
}
|
|
362
|
-
return;
|
|
363
|
-
}
|
|
364
|
-
if (mode === "local") {
|
|
365
|
-
if (logger && !options.silent) {
|
|
366
|
-
logger.info("\u{1F5A5}\uFE0F Executing locally...");
|
|
367
|
-
}
|
|
368
|
-
await localHandler();
|
|
369
|
-
} else {
|
|
370
|
-
const dockerAvailable = await isDockerAvailable();
|
|
371
|
-
if (!dockerAvailable) {
|
|
372
|
-
throw new Error(
|
|
373
|
-
"Docker is not available. Please install Docker or use --local flag to execute locally."
|
|
374
|
-
);
|
|
375
|
-
}
|
|
376
|
-
if (logger && !options.silent) {
|
|
377
|
-
logger.info("\u{1F433} Executing in Docker container...");
|
|
378
|
-
}
|
|
379
|
-
await executeInDocker(dockerCommand, dockerArgs, options, configFile);
|
|
380
|
-
}
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
// src/core/asset-resolver.ts
|
|
384
|
-
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
385
|
-
import path3 from "path";
|
|
386
|
-
function getPackageRoot() {
|
|
387
|
-
const currentFile = fileURLToPath2(import.meta.url);
|
|
388
|
-
if (currentFile.includes("/src/")) {
|
|
389
|
-
const srcIndex = currentFile.indexOf("/src/");
|
|
390
|
-
return currentFile.substring(0, srcIndex);
|
|
391
|
-
}
|
|
392
|
-
return path3.resolve(currentFile, "../..");
|
|
393
|
-
}
|
|
394
|
-
function resolveAsset(assetPath, assetType, baseDir) {
|
|
395
|
-
const packageRoot = getPackageRoot();
|
|
396
|
-
if (!assetPath.includes("/") && !assetPath.includes("\\")) {
|
|
397
|
-
if (assetType === "template") {
|
|
398
|
-
return path3.join(packageRoot, "templates", assetPath);
|
|
399
|
-
}
|
|
400
|
-
return path3.join(packageRoot, "examples", assetPath);
|
|
401
|
-
}
|
|
402
|
-
if (path3.isAbsolute(assetPath)) {
|
|
403
|
-
return assetPath;
|
|
404
|
-
}
|
|
405
|
-
const resolveBase = baseDir || process.cwd();
|
|
406
|
-
return path3.resolve(resolveBase, assetPath);
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
// src/config/validators.ts
|
|
410
|
-
function isObject(value) {
|
|
411
|
-
return typeof value === "object" && value !== null && !Array.isArray(value) && Object.prototype.toString.call(value) === "[object Object]";
|
|
412
|
-
}
|
|
413
|
-
function validatePlatform(platform) {
|
|
414
|
-
return platform === "web" || platform === "server";
|
|
415
|
-
}
|
|
416
|
-
function isMultiEnvConfig(data) {
|
|
417
|
-
return isObject(data) && "version" in data && data.version === 1 && "environments" in data && isObject(data.environments);
|
|
418
|
-
}
|
|
419
|
-
function isSingleEnvConfig(data) {
|
|
420
|
-
return isObject(data) && "flow" in data && "build" in data && isObject(data.flow) && isObject(data.build) && "platform" in data.flow && validatePlatform(data.flow.platform);
|
|
421
|
-
}
|
|
422
|
-
|
|
423
|
-
// src/config/defaults.ts
|
|
424
|
-
function getDefaultBuildOptions(platform, code, output) {
|
|
425
|
-
const common = {
|
|
426
|
-
code,
|
|
427
|
-
packages: {},
|
|
428
|
-
minify: false,
|
|
429
|
-
sourcemap: false,
|
|
430
|
-
cache: true
|
|
431
|
-
};
|
|
432
|
-
if (platform === "web") {
|
|
433
|
-
return {
|
|
434
|
-
...common,
|
|
435
|
-
platform: "browser",
|
|
436
|
-
format: "iife",
|
|
437
|
-
target: "es2020",
|
|
438
|
-
output: output || "./dist/walker.js",
|
|
439
|
-
globalName: "walkerOS"
|
|
440
|
-
};
|
|
441
|
-
}
|
|
442
|
-
return {
|
|
443
|
-
...common,
|
|
444
|
-
platform: "node",
|
|
445
|
-
format: "esm",
|
|
446
|
-
target: "node18",
|
|
447
|
-
output: output || "./dist/bundle.js"
|
|
448
|
-
};
|
|
449
|
-
}
|
|
450
|
-
function ensureBuildOptions(buildOptions, flowPlatform) {
|
|
451
|
-
const defaults = getDefaultBuildOptions(
|
|
452
|
-
flowPlatform,
|
|
453
|
-
buildOptions.code || "",
|
|
454
|
-
buildOptions.output
|
|
455
|
-
);
|
|
456
|
-
if (!buildOptions.output && !defaults.output) {
|
|
457
|
-
throw new Error("BuildOptions.output is required");
|
|
458
|
-
}
|
|
459
|
-
return {
|
|
460
|
-
...defaults,
|
|
461
|
-
...buildOptions,
|
|
462
|
-
code: buildOptions.code || defaults.code || "",
|
|
463
|
-
output: buildOptions.output || defaults.output,
|
|
464
|
-
packages: buildOptions.packages || defaults.packages
|
|
465
|
-
};
|
|
466
|
-
}
|
|
467
|
-
|
|
468
|
-
// src/config/parser.ts
|
|
469
|
-
import path4 from "path";
|
|
470
|
-
function parseBundleConfig(data) {
|
|
471
|
-
if (!isObject(data)) {
|
|
472
|
-
throw new Error(`Invalid config: expected object, got ${typeof data}`);
|
|
473
|
-
}
|
|
474
|
-
if (!("flow" in data) || !isObject(data.flow)) {
|
|
475
|
-
throw new Error(
|
|
476
|
-
`Invalid config: missing "flow" field. Expected format: { flow: { platform: "web" | "server", ... }, build: { ... } }`
|
|
477
|
-
);
|
|
478
|
-
}
|
|
479
|
-
if (!("build" in data) || !isObject(data.build)) {
|
|
480
|
-
throw new Error(
|
|
481
|
-
`Invalid config: missing "build" field. Expected format: { flow: { platform: "web" | "server", ... }, build: { ... } }`
|
|
482
|
-
);
|
|
483
|
-
}
|
|
484
|
-
const flowData = data.flow;
|
|
485
|
-
if (!("platform" in flowData) || flowData.platform !== "web" && flowData.platform !== "server") {
|
|
486
|
-
throw new Error(
|
|
487
|
-
`Invalid config: flow.platform must be "web" or "server", got "${flowData.platform}"`
|
|
488
|
-
);
|
|
489
|
-
}
|
|
490
|
-
const buildData = data.build;
|
|
491
|
-
if ("packages" in buildData && !isObject(buildData.packages)) {
|
|
492
|
-
throw new Error(
|
|
493
|
-
`Invalid config: build.packages must be an object, got ${typeof buildData.packages}`
|
|
494
|
-
);
|
|
495
|
-
}
|
|
496
|
-
const config = data;
|
|
497
|
-
return normalizeConfigs(config, "/unknown/path");
|
|
498
|
-
}
|
|
499
|
-
function normalizeConfigs(config, configPath) {
|
|
500
|
-
const flowConfig = config.flow;
|
|
501
|
-
const platform = flowConfig.platform;
|
|
502
|
-
if (!validatePlatform(platform)) {
|
|
503
|
-
throw new Error(
|
|
504
|
-
`Invalid platform "${platform}". Must be "web" or "server".`
|
|
505
|
-
);
|
|
506
|
-
}
|
|
507
|
-
const buildDefaults = platform === "web" ? {
|
|
508
|
-
platform: "browser",
|
|
509
|
-
format: "iife",
|
|
510
|
-
target: "es2020",
|
|
511
|
-
minify: false,
|
|
512
|
-
sourcemap: false,
|
|
513
|
-
tempDir: ".tmp",
|
|
514
|
-
cache: true
|
|
515
|
-
} : {
|
|
516
|
-
platform: "node",
|
|
517
|
-
format: "esm",
|
|
518
|
-
target: "node20",
|
|
519
|
-
minify: false,
|
|
520
|
-
sourcemap: false,
|
|
521
|
-
tempDir: ".tmp",
|
|
522
|
-
cache: true
|
|
523
|
-
};
|
|
524
|
-
const buildConfig = {
|
|
525
|
-
...buildDefaults,
|
|
526
|
-
...config.build
|
|
527
|
-
};
|
|
528
|
-
if (buildConfig.template === void 0) {
|
|
529
|
-
buildConfig.template = platform === "server" ? "server.hbs" : "web.hbs";
|
|
530
|
-
}
|
|
531
|
-
if (configPath && buildConfig.template && !path4.isAbsolute(buildConfig.template)) {
|
|
532
|
-
if (buildConfig.template.startsWith("./") || buildConfig.template.startsWith("../")) {
|
|
533
|
-
const configDir = path4.dirname(configPath);
|
|
534
|
-
buildConfig.template = path4.resolve(configDir, buildConfig.template);
|
|
535
|
-
}
|
|
536
|
-
}
|
|
537
|
-
const buildOptions = ensureBuildOptions(buildConfig, platform);
|
|
538
|
-
return {
|
|
539
|
-
flowConfig,
|
|
540
|
-
buildOptions
|
|
541
|
-
};
|
|
542
|
-
}
|
|
543
|
-
|
|
544
|
-
// src/config/loader.ts
|
|
545
|
-
function loadBundleConfig(rawConfig, options) {
|
|
546
|
-
if (isMultiEnvConfig(rawConfig)) {
|
|
547
|
-
return loadMultiEnvironmentConfig(rawConfig, options);
|
|
548
|
-
}
|
|
549
|
-
if (isSingleEnvConfig(rawConfig)) {
|
|
550
|
-
return loadSingleEnvironmentConfig(rawConfig, options);
|
|
551
|
-
}
|
|
552
|
-
const configType = isObject(rawConfig) ? "platform" in rawConfig ? `invalid platform value: "${rawConfig.platform}"` : 'missing "flow" and "build" fields' : `not an object (got ${typeof rawConfig})`;
|
|
553
|
-
throw new Error(
|
|
554
|
-
`Invalid configuration format at ${options.configPath}.
|
|
555
|
-
Configuration ${configType}.
|
|
556
|
-
|
|
557
|
-
Expected either:
|
|
558
|
-
1. Multi-environment: { version: 1, environments: { prod: { flow: {...}, build: {...} } } }
|
|
559
|
-
2. Single-environment: { flow: { platform: "web" | "server", ... }, build: { packages: {...}, ... } }`
|
|
560
|
-
);
|
|
561
|
-
}
|
|
562
|
-
function loadMultiEnvironmentConfig(setup, options) {
|
|
563
|
-
const availableEnvironments = Object.keys(setup.environments);
|
|
564
|
-
if (!options.environment) {
|
|
565
|
-
throw new Error(
|
|
566
|
-
`Multi-environment configuration detected. Please specify an environment using --env flag.
|
|
567
|
-
Available environments: ${availableEnvironments.join(", ")}`
|
|
568
|
-
);
|
|
569
|
-
}
|
|
570
|
-
const selectedEnv = options.environment;
|
|
571
|
-
if (!setup.environments[selectedEnv]) {
|
|
572
|
-
throw new Error(
|
|
573
|
-
`Environment "${selectedEnv}" not found in configuration.
|
|
574
|
-
Available environments: ${availableEnvironments.join(", ")}`
|
|
575
|
-
);
|
|
576
|
-
}
|
|
577
|
-
const envConfig = setup.environments[selectedEnv];
|
|
578
|
-
const { flowConfig, buildOptions } = normalizeConfigs(
|
|
579
|
-
envConfig,
|
|
580
|
-
options.configPath
|
|
581
|
-
);
|
|
582
|
-
if (options.logger) {
|
|
583
|
-
options.logger.info(
|
|
584
|
-
`\u{1F4E6} Using environment: ${selectedEnv} (${availableEnvironments.length} total)`
|
|
585
|
-
);
|
|
586
|
-
}
|
|
587
|
-
return {
|
|
588
|
-
flowConfig,
|
|
589
|
-
buildOptions,
|
|
590
|
-
environment: selectedEnv,
|
|
591
|
-
isMultiEnvironment: true,
|
|
592
|
-
availableEnvironments
|
|
593
|
-
};
|
|
594
|
-
}
|
|
595
|
-
function loadSingleEnvironmentConfig(config, options) {
|
|
596
|
-
const { flowConfig, buildOptions } = normalizeConfigs(
|
|
597
|
-
config,
|
|
598
|
-
options.configPath
|
|
599
|
-
);
|
|
600
|
-
if (options.logger && options.environment) {
|
|
601
|
-
options.logger.warn(
|
|
602
|
-
`--env flag specified but configuration is single-environment. Ignoring flag.`
|
|
603
|
-
);
|
|
604
|
-
}
|
|
605
|
-
return {
|
|
606
|
-
flowConfig,
|
|
607
|
-
buildOptions,
|
|
608
|
-
environment: "default",
|
|
609
|
-
isMultiEnvironment: false
|
|
610
|
-
};
|
|
611
|
-
}
|
|
612
|
-
function loadAllEnvironments(rawConfig, options) {
|
|
613
|
-
if (!isMultiEnvConfig(rawConfig)) {
|
|
614
|
-
throw new Error(
|
|
615
|
-
`--all flag requires a multi-environment configuration (Setup format).
|
|
616
|
-
Your configuration appears to be single-environment.`
|
|
617
|
-
);
|
|
618
|
-
}
|
|
619
|
-
const setup = rawConfig;
|
|
620
|
-
const environments = Object.keys(setup.environments);
|
|
621
|
-
if (options.logger) {
|
|
622
|
-
options.logger.info(
|
|
623
|
-
`\u{1F4E6} Loading all ${environments.length} environments: ${environments.join(", ")}`
|
|
624
|
-
);
|
|
625
|
-
}
|
|
626
|
-
return environments.map(
|
|
627
|
-
(envName) => loadMultiEnvironmentConfig(setup, {
|
|
628
|
-
...options,
|
|
629
|
-
environment: envName
|
|
630
|
-
})
|
|
631
|
-
);
|
|
632
|
-
}
|
|
633
|
-
|
|
634
|
-
// src/commands/bundle/bundler.ts
|
|
635
|
-
import esbuild from "esbuild";
|
|
636
|
-
import path6 from "path";
|
|
637
|
-
import fs4 from "fs-extra";
|
|
638
|
-
|
|
639
|
-
// src/commands/bundle/package-manager.ts
|
|
640
|
-
import pacote from "pacote";
|
|
641
|
-
import path5 from "path";
|
|
642
|
-
import fs2 from "fs-extra";
|
|
643
|
-
function getPackageDirectory(baseDir, packageName, version) {
|
|
644
|
-
return path5.join(baseDir, "node_modules", packageName);
|
|
645
|
-
}
|
|
646
|
-
function getCachedPackagePath(pkg, tempDir) {
|
|
647
|
-
const cacheDir = path5.join(".tmp", "cache", "packages");
|
|
648
|
-
const safeName = pkg.name.replace(/\//g, "-").replace(/@/g, "");
|
|
649
|
-
return path5.join(cacheDir, `${safeName}-${pkg.version}`);
|
|
650
|
-
}
|
|
651
|
-
async function isPackageCached(pkg, tempDir) {
|
|
652
|
-
const cachedPath = getCachedPackagePath(pkg, tempDir);
|
|
653
|
-
return fs2.pathExists(cachedPath);
|
|
654
|
-
}
|
|
655
|
-
function validateNoDuplicatePackages(packages) {
|
|
656
|
-
const packageMap = /* @__PURE__ */ new Map();
|
|
657
|
-
for (const pkg of packages) {
|
|
658
|
-
if (!packageMap.has(pkg.name)) {
|
|
659
|
-
packageMap.set(pkg.name, []);
|
|
660
|
-
}
|
|
661
|
-
packageMap.get(pkg.name).push(pkg.version);
|
|
662
|
-
}
|
|
663
|
-
const conflicts = [];
|
|
664
|
-
for (const [name, versions] of packageMap.entries()) {
|
|
665
|
-
const uniqueVersions = [...new Set(versions)];
|
|
666
|
-
if (uniqueVersions.length > 1) {
|
|
667
|
-
conflicts.push(`${name}: [${uniqueVersions.join(", ")}]`);
|
|
668
|
-
}
|
|
669
|
-
}
|
|
670
|
-
if (conflicts.length > 0) {
|
|
671
|
-
throw new Error(
|
|
672
|
-
`Version conflicts detected:
|
|
673
|
-
${conflicts.map((c) => ` - ${c}`).join("\n")}
|
|
674
|
-
|
|
675
|
-
Each package must use the same version across all declarations. Please update your configuration to use consistent versions.`
|
|
676
|
-
);
|
|
677
|
-
}
|
|
678
|
-
}
|
|
679
|
-
async function resolveDependencies(pkg, packageDir, logger, visited = /* @__PURE__ */ new Set()) {
|
|
680
|
-
const dependencies = [];
|
|
681
|
-
const pkgKey = `${pkg.name}@${pkg.version}`;
|
|
682
|
-
if (visited.has(pkgKey)) {
|
|
683
|
-
return dependencies;
|
|
684
|
-
}
|
|
685
|
-
visited.add(pkgKey);
|
|
686
|
-
try {
|
|
687
|
-
const packageJsonPath = path5.join(packageDir, "package.json");
|
|
688
|
-
if (await fs2.pathExists(packageJsonPath)) {
|
|
689
|
-
const packageJson2 = await fs2.readJson(packageJsonPath);
|
|
690
|
-
const deps = {
|
|
691
|
-
...packageJson2.dependencies,
|
|
692
|
-
...packageJson2.peerDependencies
|
|
693
|
-
};
|
|
694
|
-
for (const [name, versionSpec] of Object.entries(deps)) {
|
|
695
|
-
if (typeof versionSpec === "string") {
|
|
696
|
-
dependencies.push({ name, version: versionSpec });
|
|
697
|
-
}
|
|
698
|
-
}
|
|
699
|
-
}
|
|
700
|
-
} catch (error) {
|
|
701
|
-
logger.debug(`Failed to read dependencies for ${pkgKey}: ${error}`);
|
|
702
|
-
}
|
|
703
|
-
return dependencies;
|
|
704
|
-
}
|
|
705
|
-
async function downloadPackages(packages, targetDir, logger, useCache = true) {
|
|
706
|
-
const packagePaths = /* @__PURE__ */ new Map();
|
|
707
|
-
const downloadQueue = [...packages];
|
|
708
|
-
const processed = /* @__PURE__ */ new Set();
|
|
709
|
-
validateNoDuplicatePackages(packages);
|
|
710
|
-
await fs2.ensureDir(targetDir);
|
|
711
|
-
while (downloadQueue.length > 0) {
|
|
712
|
-
const pkg = downloadQueue.shift();
|
|
713
|
-
const pkgKey = `${pkg.name}@${pkg.version}`;
|
|
714
|
-
if (processed.has(pkgKey)) {
|
|
715
|
-
continue;
|
|
716
|
-
}
|
|
717
|
-
processed.add(pkgKey);
|
|
718
|
-
const packageSpec = `${pkg.name}@${pkg.version}`;
|
|
719
|
-
const packageDir = getPackageDirectory(targetDir, pkg.name, pkg.version);
|
|
720
|
-
const cachedPath = getCachedPackagePath(pkg, targetDir);
|
|
721
|
-
if (useCache && await isPackageCached(pkg, targetDir)) {
|
|
722
|
-
logger.debug(`Using cached ${packageSpec}...`);
|
|
723
|
-
try {
|
|
724
|
-
await fs2.ensureDir(path5.dirname(packageDir));
|
|
725
|
-
await fs2.copy(cachedPath, packageDir);
|
|
726
|
-
packagePaths.set(pkg.name, packageDir);
|
|
727
|
-
const deps = await resolveDependencies(pkg, packageDir, logger);
|
|
728
|
-
for (const dep of deps) {
|
|
729
|
-
const depKey = `${dep.name}@${dep.version}`;
|
|
730
|
-
if (!processed.has(depKey)) {
|
|
731
|
-
downloadQueue.push(dep);
|
|
732
|
-
}
|
|
733
|
-
}
|
|
734
|
-
continue;
|
|
735
|
-
} catch (error) {
|
|
736
|
-
logger.debug(
|
|
737
|
-
`Failed to use cache for ${packageSpec}, downloading fresh: ${error}`
|
|
738
|
-
);
|
|
739
|
-
}
|
|
740
|
-
}
|
|
741
|
-
logger.debug(`Downloading ${packageSpec}...`);
|
|
742
|
-
try {
|
|
743
|
-
await fs2.ensureDir(path5.dirname(packageDir));
|
|
744
|
-
const cacheDir = process.env.NPM_CACHE_DIR || path5.join(process.cwd(), ".npm-cache");
|
|
745
|
-
await pacote.extract(packageSpec, packageDir, {
|
|
746
|
-
// Force npm registry download, prevent workspace resolution
|
|
747
|
-
registry: "https://registry.npmjs.org",
|
|
748
|
-
// Force online fetching from registry (don't use cached workspace packages)
|
|
749
|
-
preferOnline: true,
|
|
750
|
-
// Cache for performance
|
|
751
|
-
cache: cacheDir,
|
|
752
|
-
// Don't resolve relative to workspace context
|
|
753
|
-
where: void 0
|
|
754
|
-
});
|
|
755
|
-
if (useCache) {
|
|
756
|
-
try {
|
|
757
|
-
await fs2.ensureDir(path5.dirname(cachedPath));
|
|
758
|
-
await fs2.copy(packageDir, cachedPath);
|
|
759
|
-
logger.debug(`Cached ${packageSpec} for future use`);
|
|
760
|
-
} catch (cacheError) {
|
|
761
|
-
logger.debug(`Failed to cache ${packageSpec}: ${cacheError}`);
|
|
762
|
-
}
|
|
763
|
-
}
|
|
764
|
-
packagePaths.set(pkg.name, packageDir);
|
|
765
|
-
const deps = await resolveDependencies(pkg, packageDir, logger);
|
|
766
|
-
for (const dep of deps) {
|
|
767
|
-
const depKey = `${dep.name}@${dep.version}`;
|
|
768
|
-
if (!processed.has(depKey)) {
|
|
769
|
-
downloadQueue.push(dep);
|
|
770
|
-
}
|
|
771
|
-
}
|
|
772
|
-
} catch (error) {
|
|
773
|
-
throw new Error(`Failed to download ${packageSpec}: ${error}`);
|
|
774
|
-
}
|
|
775
|
-
}
|
|
776
|
-
return packagePaths;
|
|
777
|
-
}
|
|
778
|
-
|
|
779
|
-
// src/commands/bundle/template-engine.ts
|
|
780
|
-
import fs3 from "fs-extra";
|
|
781
|
-
import Handlebars from "handlebars";
|
|
782
|
-
|
|
783
|
-
// src/commands/bundle/serializer.ts
|
|
784
|
-
function serializeToJS(value, options = {}) {
|
|
785
|
-
const { indent = 2, singleQuotes = false } = options;
|
|
786
|
-
const quote = singleQuotes ? "'" : '"';
|
|
787
|
-
function serialize(val, currentIndent = 0) {
|
|
788
|
-
if (val === null) return "null";
|
|
789
|
-
if (val === void 0) return "undefined";
|
|
790
|
-
if (typeof val === "boolean" || typeof val === "number") {
|
|
791
|
-
return String(val);
|
|
792
|
-
}
|
|
793
|
-
if (typeof val === "string") {
|
|
794
|
-
if (val.includes("=>")) {
|
|
795
|
-
const arrowPatterns = [
|
|
796
|
-
/^\s*\([^)]*\)\s*=>/,
|
|
797
|
-
// (param) => or () =>
|
|
798
|
-
/^\s*\w+\s*=>/,
|
|
799
|
-
// param =>
|
|
800
|
-
/^\s*\([^)]*\)\s*=>\s*\{/,
|
|
801
|
-
// (param) => {
|
|
802
|
-
/^\s*\w+\s*=>\s*\{/
|
|
803
|
-
// param => {
|
|
804
|
-
];
|
|
805
|
-
if (arrowPatterns.some((pattern) => pattern.test(val))) {
|
|
806
|
-
return val;
|
|
807
|
-
}
|
|
808
|
-
}
|
|
809
|
-
return quote + val.replace(/\\/g, "\\\\").replace(/'/g, "\\'").replace(/"/g, '\\"') + quote;
|
|
810
|
-
}
|
|
811
|
-
if (Array.isArray(val)) {
|
|
812
|
-
if (val.length === 0) return "[]";
|
|
813
|
-
const nextIndent = currentIndent + indent;
|
|
814
|
-
const spacing = " ".repeat(nextIndent);
|
|
815
|
-
const items = val.map((item) => spacing + serialize(item, nextIndent)).join(",\n");
|
|
816
|
-
return `[
|
|
817
|
-
${items}
|
|
818
|
-
${" ".repeat(currentIndent)}]`;
|
|
819
|
-
}
|
|
820
|
-
if (isObject(val)) {
|
|
821
|
-
const entries = Object.entries(val);
|
|
822
|
-
if (entries.length === 0) return "{}";
|
|
823
|
-
const nextIndent = currentIndent + indent;
|
|
824
|
-
const spacing = " ".repeat(nextIndent);
|
|
825
|
-
const props = entries.map(([key, value2]) => {
|
|
826
|
-
const needsQuotes = /[^a-zA-Z0-9_$]/.test(key) || /^[0-9]/.test(key);
|
|
827
|
-
const keyStr = needsQuotes ? quote + key + quote : key;
|
|
828
|
-
return spacing + keyStr + ": " + serialize(value2, nextIndent);
|
|
829
|
-
}).join(",\n");
|
|
830
|
-
return `{
|
|
831
|
-
${props}
|
|
832
|
-
${" ".repeat(currentIndent)}}`;
|
|
833
|
-
}
|
|
834
|
-
return String(val);
|
|
835
|
-
}
|
|
836
|
-
return serialize(value);
|
|
837
|
-
}
|
|
838
|
-
function serializeConfig(config) {
|
|
839
|
-
if (!config || Object.keys(config).length === 0) {
|
|
840
|
-
return "{}";
|
|
841
|
-
}
|
|
842
|
-
return serializeToJS(config, { indent: 2, singleQuotes: true });
|
|
843
|
-
}
|
|
844
|
-
function processTemplateVariables(variables) {
|
|
845
|
-
const processed = { ...variables };
|
|
846
|
-
if (isObject(processed.sources)) {
|
|
847
|
-
const sourcesObj = processed.sources;
|
|
848
|
-
const processedSources = {};
|
|
849
|
-
for (const [name, source] of Object.entries(sourcesObj)) {
|
|
850
|
-
const typedSource = source;
|
|
851
|
-
const { env: _, ...sourceWithoutEnv } = typedSource;
|
|
852
|
-
processedSources[name] = {
|
|
853
|
-
...sourceWithoutEnv,
|
|
854
|
-
config: isObject(typedSource.config) ? serializeConfig(typedSource.config) : typedSource.config,
|
|
855
|
-
// Pass through string configs unchanged
|
|
856
|
-
...typedSource.env !== void 0 && { env: typedSource.env }
|
|
857
|
-
};
|
|
858
|
-
}
|
|
859
|
-
processed.sources = processedSources;
|
|
860
|
-
}
|
|
861
|
-
if (isObject(processed.destinations)) {
|
|
862
|
-
const destinationsObj = processed.destinations;
|
|
863
|
-
const processedDestinations = {};
|
|
864
|
-
for (const [name, dest] of Object.entries(destinationsObj)) {
|
|
865
|
-
const typedDest = dest;
|
|
866
|
-
const { env: _, ...destWithoutEnv } = typedDest;
|
|
867
|
-
processedDestinations[name] = {
|
|
868
|
-
...destWithoutEnv,
|
|
869
|
-
config: isObject(typedDest.config) ? serializeConfig(typedDest.config) : typedDest.config,
|
|
870
|
-
...typedDest.env !== void 0 && { env: typedDest.env }
|
|
871
|
-
};
|
|
872
|
-
}
|
|
873
|
-
processed.destinations = processedDestinations;
|
|
874
|
-
}
|
|
875
|
-
if (isObject(processed.collector)) {
|
|
876
|
-
processed.collector = serializeConfig(
|
|
877
|
-
processed.collector
|
|
878
|
-
);
|
|
879
|
-
}
|
|
880
|
-
return processed;
|
|
881
|
-
}
|
|
882
|
-
|
|
883
|
-
// src/commands/bundle/template-engine.ts
|
|
884
|
-
var TemplateEngine = class {
|
|
885
|
-
handlebars;
|
|
886
|
-
constructor() {
|
|
887
|
-
this.handlebars = Handlebars.create();
|
|
888
|
-
}
|
|
889
|
-
/**
|
|
890
|
-
* Load template content from file path
|
|
891
|
-
*
|
|
892
|
-
* @param templatePath - Template path (bare name, relative, or absolute)
|
|
893
|
-
*/
|
|
894
|
-
async loadTemplate(templatePath) {
|
|
895
|
-
const resolvedPath = resolveAsset(templatePath, "template");
|
|
896
|
-
if (!await fs3.pathExists(resolvedPath)) {
|
|
897
|
-
throw new Error(`Template file not found: ${resolvedPath}`);
|
|
898
|
-
}
|
|
899
|
-
return await fs3.readFile(resolvedPath, "utf-8");
|
|
900
|
-
}
|
|
901
|
-
/**
|
|
902
|
-
* Apply template with user code and variable substitution
|
|
903
|
-
*/
|
|
904
|
-
applyTemplate(template, userCode, sources, destinations, collector, build) {
|
|
905
|
-
const processedVariables = processTemplateVariables({
|
|
906
|
-
sources,
|
|
907
|
-
destinations,
|
|
908
|
-
collector
|
|
909
|
-
});
|
|
910
|
-
const templateData = {
|
|
911
|
-
CODE: userCode,
|
|
912
|
-
build: build || {},
|
|
913
|
-
...processedVariables
|
|
914
|
-
};
|
|
915
|
-
const compiledTemplate = this.handlebars.compile(template);
|
|
916
|
-
return compiledTemplate(templateData);
|
|
917
|
-
}
|
|
918
|
-
/**
|
|
919
|
-
* Process template with user code
|
|
920
|
-
*/
|
|
921
|
-
async process(templatePath, userCode, sources, destinations, collector, build) {
|
|
922
|
-
const template = await this.loadTemplate(templatePath);
|
|
923
|
-
return this.applyTemplate(
|
|
924
|
-
template,
|
|
925
|
-
userCode,
|
|
926
|
-
sources,
|
|
927
|
-
destinations,
|
|
928
|
-
collector,
|
|
929
|
-
build
|
|
930
|
-
);
|
|
931
|
-
}
|
|
932
|
-
};
|
|
933
|
-
|
|
934
|
-
// src/commands/bundle/bundler.ts
|
|
935
|
-
async function bundleCore(flowConfig, buildOptions, logger, showStats = false) {
|
|
936
|
-
const bundleStartTime = Date.now();
|
|
937
|
-
const TEMP_DIR = buildOptions.tempDir ? path6.isAbsolute(buildOptions.tempDir) ? buildOptions.tempDir : path6.resolve(buildOptions.tempDir) : getTempDir();
|
|
938
|
-
try {
|
|
939
|
-
if (!buildOptions.tempDir) {
|
|
940
|
-
await fs4.emptyDir(TEMP_DIR);
|
|
941
|
-
}
|
|
942
|
-
logger.debug("Cleaned temporary directory");
|
|
943
|
-
logger.info("\u{1F4E5} Downloading packages...");
|
|
944
|
-
const packagesArray = Object.entries(buildOptions.packages).map(
|
|
945
|
-
([name, packageConfig]) => ({
|
|
946
|
-
name,
|
|
947
|
-
version: packageConfig.version || "latest"
|
|
948
|
-
})
|
|
949
|
-
);
|
|
950
|
-
const packagePaths = await downloadPackages(
|
|
951
|
-
packagesArray,
|
|
952
|
-
TEMP_DIR,
|
|
953
|
-
logger,
|
|
954
|
-
buildOptions.cache
|
|
955
|
-
);
|
|
956
|
-
for (const [pkgName, pkgPath] of packagePaths.entries()) {
|
|
957
|
-
if (pkgName.startsWith("@walkeros/")) {
|
|
958
|
-
const pkgJsonPath = path6.join(pkgPath, "package.json");
|
|
959
|
-
const pkgJson = await fs4.readJSON(pkgJsonPath);
|
|
960
|
-
if (!pkgJson.exports && pkgJson.module) {
|
|
961
|
-
pkgJson.exports = {
|
|
962
|
-
".": {
|
|
963
|
-
import: pkgJson.module,
|
|
964
|
-
require: pkgJson.main
|
|
965
|
-
}
|
|
966
|
-
};
|
|
967
|
-
await fs4.writeJSON(pkgJsonPath, pkgJson, { spaces: 2 });
|
|
968
|
-
}
|
|
969
|
-
}
|
|
970
|
-
}
|
|
971
|
-
const packageJsonPath = path6.join(TEMP_DIR, "package.json");
|
|
972
|
-
await fs4.writeFile(
|
|
973
|
-
packageJsonPath,
|
|
974
|
-
JSON.stringify({ type: "module" }, null, 2)
|
|
975
|
-
);
|
|
976
|
-
logger.info("\u{1F4DD} Creating entry point...");
|
|
977
|
-
const entryContent = await createEntryPoint(
|
|
978
|
-
flowConfig,
|
|
979
|
-
buildOptions,
|
|
980
|
-
packagePaths
|
|
981
|
-
);
|
|
982
|
-
const entryPath = path6.join(TEMP_DIR, "entry.js");
|
|
983
|
-
await fs4.writeFile(entryPath, entryContent);
|
|
984
|
-
logger.info("\u26A1 Bundling with esbuild...");
|
|
985
|
-
const outputPath = path6.resolve(buildOptions.output);
|
|
986
|
-
await fs4.ensureDir(path6.dirname(outputPath));
|
|
987
|
-
const esbuildOptions = createEsbuildOptions(
|
|
988
|
-
buildOptions,
|
|
989
|
-
entryPath,
|
|
990
|
-
outputPath,
|
|
991
|
-
TEMP_DIR,
|
|
992
|
-
packagePaths,
|
|
993
|
-
logger
|
|
994
|
-
);
|
|
995
|
-
try {
|
|
996
|
-
await esbuild.build(esbuildOptions);
|
|
997
|
-
} catch (buildError) {
|
|
998
|
-
throw createBuildError(
|
|
999
|
-
buildError,
|
|
1000
|
-
buildOptions.code || ""
|
|
1001
|
-
);
|
|
1002
|
-
}
|
|
1003
|
-
logger.gray(`Output: ${outputPath}`);
|
|
1004
|
-
let stats;
|
|
1005
|
-
if (showStats) {
|
|
1006
|
-
stats = await collectBundleStats(
|
|
1007
|
-
outputPath,
|
|
1008
|
-
buildOptions.packages,
|
|
1009
|
-
bundleStartTime,
|
|
1010
|
-
entryContent
|
|
1011
|
-
);
|
|
1012
|
-
}
|
|
1013
|
-
if (!buildOptions.tempDir) {
|
|
1014
|
-
await fs4.remove(TEMP_DIR);
|
|
1015
|
-
logger.debug("Cleaned up temporary files");
|
|
1016
|
-
}
|
|
1017
|
-
return stats;
|
|
1018
|
-
} catch (error) {
|
|
1019
|
-
if (!buildOptions.tempDir) {
|
|
1020
|
-
await fs4.remove(TEMP_DIR).catch(() => {
|
|
1021
|
-
});
|
|
1022
|
-
}
|
|
1023
|
-
throw error;
|
|
1024
|
-
}
|
|
1025
|
-
}
|
|
1026
|
-
async function collectBundleStats(outputPath, packages, startTime, entryContent) {
|
|
1027
|
-
const stats = await fs4.stat(outputPath);
|
|
1028
|
-
const totalSize = stats.size;
|
|
1029
|
-
const buildTime = Date.now() - startTime;
|
|
1030
|
-
const packageStats = Object.entries(packages).map(([name, pkg]) => {
|
|
1031
|
-
const importPattern = new RegExp(`from\\s+['"]${name}['"]`, "g");
|
|
1032
|
-
const namedImportPattern = new RegExp(
|
|
1033
|
-
`import\\s+\\{[^}]*\\}\\s+from\\s+['"]${name}['"]`,
|
|
1034
|
-
"g"
|
|
1035
|
-
);
|
|
1036
|
-
const hasImports = importPattern.test(entryContent) || namedImportPattern.test(entryContent);
|
|
1037
|
-
const packagesCount = Object.keys(packages).length;
|
|
1038
|
-
const estimatedSize = hasImports ? Math.floor(totalSize / packagesCount) : 0;
|
|
1039
|
-
return {
|
|
1040
|
-
name: `${name}@${pkg.version || "latest"}`,
|
|
1041
|
-
size: estimatedSize
|
|
1042
|
-
};
|
|
1043
|
-
});
|
|
1044
|
-
const hasWildcardImports = /import\s+\*\s+as\s+\w+\s+from/.test(entryContent);
|
|
1045
|
-
const treeshakingEffective = !hasWildcardImports;
|
|
1046
|
-
return {
|
|
1047
|
-
totalSize,
|
|
1048
|
-
packages: packageStats,
|
|
1049
|
-
buildTime,
|
|
1050
|
-
treeshakingEffective
|
|
1051
|
-
};
|
|
1052
|
-
}
|
|
1053
|
-
function createEsbuildOptions(buildOptions, entryPath, outputPath, tempDir, packagePaths, logger) {
|
|
1054
|
-
const alias = {};
|
|
1055
|
-
const baseOptions = {
|
|
1056
|
-
entryPoints: [entryPath],
|
|
1057
|
-
bundle: true,
|
|
1058
|
-
format: buildOptions.format,
|
|
1059
|
-
platform: buildOptions.platform,
|
|
1060
|
-
outfile: outputPath,
|
|
1061
|
-
absWorkingDir: tempDir,
|
|
1062
|
-
// Resolve modules from temp directory
|
|
1063
|
-
// alias removed - not needed with absWorkingDir
|
|
1064
|
-
mainFields: ["module", "main"],
|
|
1065
|
-
// Prefer ESM over CJS
|
|
1066
|
-
treeShaking: true,
|
|
1067
|
-
logLevel: "error",
|
|
1068
|
-
minify: buildOptions.minify,
|
|
1069
|
-
sourcemap: buildOptions.sourcemap,
|
|
1070
|
-
resolveExtensions: [".mjs", ".js", ".ts", ".json"],
|
|
1071
|
-
// Prefer .mjs
|
|
1072
|
-
// Enhanced minification options when minify is enabled
|
|
1073
|
-
...buildOptions.minify && {
|
|
1074
|
-
minifyWhitespace: buildOptions.minifyOptions?.whitespace ?? true,
|
|
1075
|
-
minifyIdentifiers: buildOptions.minifyOptions?.identifiers ?? true,
|
|
1076
|
-
minifySyntax: buildOptions.minifyOptions?.syntax ?? true,
|
|
1077
|
-
legalComments: buildOptions.minifyOptions?.legalComments ?? "none",
|
|
1078
|
-
keepNames: buildOptions.minifyOptions?.keepNames ?? false,
|
|
1079
|
-
charset: "utf8"
|
|
1080
|
-
}
|
|
1081
|
-
};
|
|
1082
|
-
if (buildOptions.platform === "browser") {
|
|
1083
|
-
baseOptions.define = {
|
|
1084
|
-
"process.env.NODE_ENV": '"production"',
|
|
1085
|
-
global: "globalThis"
|
|
1086
|
-
};
|
|
1087
|
-
baseOptions.external = buildOptions.external || [];
|
|
1088
|
-
} else if (buildOptions.platform === "node") {
|
|
1089
|
-
const nodeBuiltins = [
|
|
1090
|
-
"crypto",
|
|
1091
|
-
"fs",
|
|
1092
|
-
"path",
|
|
1093
|
-
"os",
|
|
1094
|
-
"util",
|
|
1095
|
-
"stream",
|
|
1096
|
-
"buffer",
|
|
1097
|
-
"events",
|
|
1098
|
-
"http",
|
|
1099
|
-
"https",
|
|
1100
|
-
"url",
|
|
1101
|
-
"querystring",
|
|
1102
|
-
"zlib"
|
|
1103
|
-
];
|
|
1104
|
-
const npmPackages = ["express", "express/*", "cors", "cors/*"];
|
|
1105
|
-
baseOptions.external = buildOptions.external ? [...nodeBuiltins, ...npmPackages, ...buildOptions.external] : [...nodeBuiltins, ...npmPackages];
|
|
1106
|
-
}
|
|
1107
|
-
if (buildOptions.target) {
|
|
1108
|
-
baseOptions.target = buildOptions.target;
|
|
1109
|
-
} else if (buildOptions.platform === "node") {
|
|
1110
|
-
baseOptions.target = "node18";
|
|
1111
|
-
} else {
|
|
1112
|
-
baseOptions.target = "es2018";
|
|
1113
|
-
}
|
|
1114
|
-
if (buildOptions.globalName && buildOptions.format === "iife") {
|
|
1115
|
-
baseOptions.globalName = buildOptions.globalName;
|
|
1116
|
-
}
|
|
1117
|
-
return baseOptions;
|
|
1118
|
-
}
|
|
1119
|
-
function packageNameToVariable(packageName) {
|
|
1120
|
-
return packageName.replace("@", "_").replace(/[/-]/g, "_").split("_").map(
|
|
1121
|
-
(part, i) => i === 0 ? part : part.charAt(0).toUpperCase() + part.slice(1)
|
|
1122
|
-
).join("");
|
|
1123
|
-
}
|
|
1124
|
-
async function createEntryPoint(flowConfig, buildOptions, packagePaths) {
|
|
1125
|
-
const importStatements = [];
|
|
1126
|
-
const examplesMappings = [];
|
|
1127
|
-
const destinationPackages = /* @__PURE__ */ new Set();
|
|
1128
|
-
const destinations = flowConfig.destinations;
|
|
1129
|
-
if (destinations) {
|
|
1130
|
-
for (const [destKey, destConfig] of Object.entries(destinations)) {
|
|
1131
|
-
if (typeof destConfig === "object" && destConfig !== null && "package" in destConfig && typeof destConfig.package === "string") {
|
|
1132
|
-
destinationPackages.add(destConfig.package);
|
|
1133
|
-
}
|
|
1134
|
-
}
|
|
1135
|
-
}
|
|
1136
|
-
for (const [packageName, packageConfig] of Object.entries(
|
|
1137
|
-
buildOptions.packages
|
|
1138
|
-
)) {
|
|
1139
|
-
if (packageConfig.imports && packageConfig.imports.length > 0) {
|
|
1140
|
-
const uniqueImports = [...new Set(packageConfig.imports)];
|
|
1141
|
-
const defaultImports = [];
|
|
1142
|
-
const namedImports = [];
|
|
1143
|
-
for (const imp of uniqueImports) {
|
|
1144
|
-
if (imp.startsWith("default as ")) {
|
|
1145
|
-
defaultImports.push(imp.replace("default as ", ""));
|
|
1146
|
-
} else {
|
|
1147
|
-
namedImports.push(imp);
|
|
1148
|
-
}
|
|
1149
|
-
}
|
|
1150
|
-
if (defaultImports.length > 0) {
|
|
1151
|
-
for (const defaultImport of defaultImports) {
|
|
1152
|
-
importStatements.push(
|
|
1153
|
-
`import ${defaultImport} from '${packageName}';`
|
|
1154
|
-
);
|
|
1155
|
-
}
|
|
1156
|
-
}
|
|
1157
|
-
if (namedImports.length > 0) {
|
|
1158
|
-
const importList = namedImports.join(", ");
|
|
1159
|
-
importStatements.push(
|
|
1160
|
-
`import { ${importList} } from '${packageName}';`
|
|
1161
|
-
);
|
|
1162
|
-
}
|
|
1163
|
-
const examplesImport = uniqueImports.find(
|
|
1164
|
-
(imp) => imp.includes("examples as ")
|
|
1165
|
-
);
|
|
1166
|
-
if (examplesImport) {
|
|
1167
|
-
const examplesVarName = examplesImport.split(" as ")[1];
|
|
1168
|
-
const destinationMatch = packageName.match(
|
|
1169
|
-
/@walkeros\/web-destination-(.+)$/
|
|
1170
|
-
);
|
|
1171
|
-
if (destinationMatch) {
|
|
1172
|
-
const destinationName = destinationMatch[1];
|
|
1173
|
-
examplesMappings.push(
|
|
1174
|
-
` ${destinationName}: typeof ${examplesVarName} !== 'undefined' ? ${examplesVarName} : undefined`
|
|
1175
|
-
);
|
|
1176
|
-
}
|
|
1177
|
-
}
|
|
1178
|
-
} else {
|
|
1179
|
-
const varName = packageNameToVariable(packageName);
|
|
1180
|
-
importStatements.push(
|
|
1181
|
-
`import * as ${varName} from '${packageName}'; // Consider specifying explicit imports`
|
|
1182
|
-
);
|
|
1183
|
-
}
|
|
1184
|
-
if (destinationPackages.has(packageName)) {
|
|
1185
|
-
const destinationMatch = packageName.match(
|
|
1186
|
-
/@walkeros\/(?:(?:web|server)-)?destination-(.+)$/
|
|
1187
|
-
);
|
|
1188
|
-
if (destinationMatch) {
|
|
1189
|
-
const destinationName = destinationMatch[1];
|
|
1190
|
-
const examplesVarName = `${destinationName.replace(/-/g, "_")}_examples`;
|
|
1191
|
-
const isDemoPackage = packageName.includes("-demo");
|
|
1192
|
-
if (isDemoPackage) {
|
|
1193
|
-
importStatements.push(
|
|
1194
|
-
`import { examples as ${examplesVarName} } from '${packageName}';`
|
|
1195
|
-
);
|
|
1196
|
-
} else {
|
|
1197
|
-
importStatements.push(
|
|
1198
|
-
`import * as ${examplesVarName} from '${packageName}/examples';`
|
|
1199
|
-
);
|
|
1200
|
-
}
|
|
1201
|
-
examplesMappings.push(` ${destinationName}: ${examplesVarName}`);
|
|
1202
|
-
}
|
|
1203
|
-
}
|
|
1204
|
-
}
|
|
1205
|
-
const examplesObject = examplesMappings.length > 0 ? `const examples = {
|
|
1206
|
-
${examplesMappings.join(",\n")}
|
|
1207
|
-
};
|
|
1208
|
-
|
|
1209
|
-
` : "";
|
|
1210
|
-
const importsCode = importStatements.join("\n");
|
|
1211
|
-
let templatedCode;
|
|
1212
|
-
if (buildOptions.template) {
|
|
1213
|
-
const templateEngine = new TemplateEngine();
|
|
1214
|
-
const flowWithProps = flowConfig;
|
|
1215
|
-
templatedCode = await templateEngine.process(
|
|
1216
|
-
buildOptions.template,
|
|
1217
|
-
buildOptions.code || "",
|
|
1218
|
-
// Pass user code as parameter (empty if undefined)
|
|
1219
|
-
flowWithProps.sources || {},
|
|
1220
|
-
flowWithProps.destinations || {},
|
|
1221
|
-
flowWithProps.collector || {},
|
|
1222
|
-
buildOptions
|
|
1223
|
-
// Pass build config to template
|
|
1224
|
-
);
|
|
1225
|
-
} else {
|
|
1226
|
-
templatedCode = buildOptions.code || "";
|
|
1227
|
-
}
|
|
1228
|
-
let wrappedCode = templatedCode;
|
|
1229
|
-
const hasExport = /^\s*export\s/m.test(templatedCode);
|
|
1230
|
-
if (!hasExport) {
|
|
1231
|
-
if (buildOptions.format === "esm") {
|
|
1232
|
-
wrappedCode = `export default ${templatedCode}`;
|
|
1233
|
-
} else if (buildOptions.platform === "browser" && buildOptions.globalName) {
|
|
1234
|
-
wrappedCode = `window['${buildOptions.globalName}'] = ${templatedCode}`;
|
|
1235
|
-
}
|
|
1236
|
-
}
|
|
1237
|
-
let finalCode = importsCode ? `${importsCode}
|
|
1238
|
-
|
|
1239
|
-
${examplesObject}${wrappedCode}` : `${examplesObject}${wrappedCode}`;
|
|
1240
|
-
if (examplesObject && buildOptions.format === "esm") {
|
|
1241
|
-
finalCode += `
|
|
1242
|
-
|
|
1243
|
-
export { examples };`;
|
|
1244
|
-
}
|
|
1245
|
-
return finalCode;
|
|
1246
|
-
}
|
|
1247
|
-
function createBuildError(buildError, code) {
|
|
1248
|
-
if (!buildError.errors || buildError.errors.length === 0) {
|
|
1249
|
-
return new Error(`Build failed: ${buildError.message || buildError}`);
|
|
1250
|
-
}
|
|
1251
|
-
const firstError = buildError.errors[0];
|
|
1252
|
-
const location = firstError.location;
|
|
1253
|
-
if (location && location.file && location.file.includes("entry.js")) {
|
|
1254
|
-
const line = location.line;
|
|
1255
|
-
const column = location.column;
|
|
1256
|
-
const codeLines = code.split("\n");
|
|
1257
|
-
const errorLine = codeLines[line - 1] || "";
|
|
1258
|
-
return new Error(
|
|
1259
|
-
`Code syntax error at line ${line}, column ${column}:
|
|
1260
|
-
${errorLine}
|
|
1261
|
-
${" ".repeat(column - 1)}^
|
|
1262
|
-
${firstError.text}`
|
|
1263
|
-
);
|
|
1264
|
-
}
|
|
1265
|
-
return new Error(
|
|
1266
|
-
`Build error: ${firstError.text}
|
|
1267
|
-
` + (location ? ` at ${location.file}:${location.line}:${location.column}` : "")
|
|
1268
|
-
);
|
|
1269
|
-
}
|
|
1270
|
-
|
|
1271
|
-
// src/commands/bundle/stats.ts
|
|
1272
|
-
function displayStats(stats, logger) {
|
|
1273
|
-
logger.info("\n\u{1F4CA} Bundle Statistics");
|
|
1274
|
-
logger.info("\u2500".repeat(50));
|
|
1275
|
-
const sizeKB = formatBytes(stats.totalSize);
|
|
1276
|
-
logger.info(`Total Size: ${sizeKB} KB`);
|
|
1277
|
-
const timeSeconds = (stats.buildTime / 1e3).toFixed(2);
|
|
1278
|
-
logger.info(`Build Time: ${timeSeconds}s`);
|
|
1279
|
-
const treeshakingStatus = stats.treeshakingEffective ? "\u2705 Effective" : "\u26A0\uFE0F Not optimal (consider using named imports)";
|
|
1280
|
-
logger.info(`Tree-shaking: ${treeshakingStatus}`);
|
|
1281
|
-
if (stats.packages.length > 0) {
|
|
1282
|
-
logger.info(`
|
|
1283
|
-
Package Breakdown:`);
|
|
1284
|
-
stats.packages.forEach((pkg) => {
|
|
1285
|
-
if (pkg.size > 0) {
|
|
1286
|
-
const pkgSizeKB = formatBytes(pkg.size);
|
|
1287
|
-
logger.info(` \u2022 ${pkg.name}: ${pkgSizeKB} KB`);
|
|
1288
|
-
}
|
|
1289
|
-
});
|
|
1290
|
-
}
|
|
1291
|
-
logger.info("\u2500".repeat(50));
|
|
1292
|
-
}
|
|
1293
|
-
|
|
1294
|
-
// src/commands/bundle/index.ts
|
|
1295
|
-
async function bundleCommand(options) {
|
|
1296
|
-
const timer = createTimer();
|
|
1297
|
-
timer.start();
|
|
1298
|
-
const logger = createLogger({
|
|
1299
|
-
verbose: options.verbose,
|
|
1300
|
-
silent: options.silent ?? false,
|
|
1301
|
-
json: options.json
|
|
1302
|
-
});
|
|
1303
|
-
const dockerArgs = [options.config];
|
|
1304
|
-
if (options.env) dockerArgs.push("--env", options.env);
|
|
1305
|
-
if (options.all) dockerArgs.push("--all");
|
|
1306
|
-
if (options.stats) dockerArgs.push("--stats");
|
|
1307
|
-
if (options.json) dockerArgs.push("--json");
|
|
1308
|
-
if (options.cache === false) dockerArgs.push("--no-cache");
|
|
1309
|
-
if (options.verbose) dockerArgs.push("--verbose");
|
|
1310
|
-
if (options.silent) dockerArgs.push("--silent");
|
|
1311
|
-
await executeCommand(
|
|
1312
|
-
async () => {
|
|
1313
|
-
try {
|
|
1314
|
-
if (options.env && options.all) {
|
|
1315
|
-
throw new Error("Cannot use both --env and --all flags together");
|
|
1316
|
-
}
|
|
1317
|
-
logger.info("\u{1F4E6} Reading configuration...");
|
|
1318
|
-
const configPath = options.config;
|
|
1319
|
-
const rawConfig = await loadJsonConfig(configPath);
|
|
1320
|
-
const configsToBundle = options.all ? loadAllEnvironments(rawConfig, { configPath, logger }) : [
|
|
1321
|
-
loadBundleConfig(rawConfig, {
|
|
1322
|
-
configPath,
|
|
1323
|
-
environment: options.env,
|
|
1324
|
-
logger
|
|
1325
|
-
})
|
|
1326
|
-
];
|
|
1327
|
-
const results = [];
|
|
1328
|
-
for (const {
|
|
1329
|
-
flowConfig,
|
|
1330
|
-
buildOptions,
|
|
1331
|
-
environment,
|
|
1332
|
-
isMultiEnvironment
|
|
1333
|
-
} of configsToBundle) {
|
|
1334
|
-
try {
|
|
1335
|
-
if (options.cache !== void 0) {
|
|
1336
|
-
buildOptions.cache = options.cache;
|
|
1337
|
-
}
|
|
1338
|
-
if (isMultiEnvironment || options.all) {
|
|
1339
|
-
logger.info(`
|
|
1340
|
-
\u{1F527} Building environment: ${environment}`);
|
|
1341
|
-
} else {
|
|
1342
|
-
logger.info("\u{1F527} Starting bundle process...");
|
|
1343
|
-
}
|
|
1344
|
-
const shouldCollectStats = options.stats || options.json;
|
|
1345
|
-
const stats = await bundleCore(
|
|
1346
|
-
flowConfig,
|
|
1347
|
-
buildOptions,
|
|
1348
|
-
logger,
|
|
1349
|
-
shouldCollectStats
|
|
1350
|
-
);
|
|
1351
|
-
results.push({
|
|
1352
|
-
environment,
|
|
1353
|
-
success: true,
|
|
1354
|
-
stats
|
|
1355
|
-
});
|
|
1356
|
-
if (!options.json && !options.all && options.stats && stats) {
|
|
1357
|
-
displayStats(stats, logger);
|
|
1358
|
-
}
|
|
1359
|
-
} catch (error) {
|
|
1360
|
-
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
1361
|
-
results.push({
|
|
1362
|
-
environment,
|
|
1363
|
-
success: false,
|
|
1364
|
-
error: errorMessage
|
|
1365
|
-
});
|
|
1366
|
-
if (!options.all) {
|
|
1367
|
-
throw error;
|
|
1368
|
-
}
|
|
1369
|
-
}
|
|
1370
|
-
}
|
|
1371
|
-
const duration = timer.end() / 1e3;
|
|
1372
|
-
const successCount = results.filter((r) => r.success).length;
|
|
1373
|
-
const failureCount = results.filter((r) => !r.success).length;
|
|
1374
|
-
if (options.json) {
|
|
1375
|
-
const outputLogger = createLogger({ silent: false, json: false });
|
|
1376
|
-
const output = failureCount === 0 ? createSuccessOutput(
|
|
1377
|
-
{
|
|
1378
|
-
environments: results,
|
|
1379
|
-
summary: {
|
|
1380
|
-
total: results.length,
|
|
1381
|
-
success: successCount,
|
|
1382
|
-
failed: failureCount
|
|
1383
|
-
}
|
|
1384
|
-
},
|
|
1385
|
-
duration
|
|
1386
|
-
) : createErrorOutput(
|
|
1387
|
-
`${failureCount} environment(s) failed to build`,
|
|
1388
|
-
duration
|
|
1389
|
-
);
|
|
1390
|
-
outputLogger.log("white", JSON.stringify(output, null, 2));
|
|
1391
|
-
} else {
|
|
1392
|
-
if (options.all) {
|
|
1393
|
-
logger.info(`
|
|
1394
|
-
\u{1F4CA} Build Summary:`);
|
|
1395
|
-
logger.info(` Total: ${results.length}`);
|
|
1396
|
-
logger.success(` \u2705 Success: ${successCount}`);
|
|
1397
|
-
if (failureCount > 0) {
|
|
1398
|
-
logger.error(` \u274C Failed: ${failureCount}`);
|
|
1399
|
-
}
|
|
1400
|
-
}
|
|
1401
|
-
if (failureCount === 0) {
|
|
1402
|
-
logger.success(
|
|
1403
|
-
`
|
|
1404
|
-
\u2705 Bundle created successfully in ${timer.format()}`
|
|
1405
|
-
);
|
|
1406
|
-
} else {
|
|
1407
|
-
throw new Error(`${failureCount} environment(s) failed to build`);
|
|
1408
|
-
}
|
|
1409
|
-
}
|
|
1410
|
-
} catch (error) {
|
|
1411
|
-
const duration = timer.getElapsed() / 1e3;
|
|
1412
|
-
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
1413
|
-
if (options.json) {
|
|
1414
|
-
const outputLogger = createLogger({ silent: false, json: false });
|
|
1415
|
-
const output = createErrorOutput(errorMessage, duration);
|
|
1416
|
-
outputLogger.log("white", JSON.stringify(output, null, 2));
|
|
1417
|
-
} else {
|
|
1418
|
-
logger.error("\u274C Bundle failed:");
|
|
1419
|
-
logger.error(errorMessage);
|
|
1420
|
-
}
|
|
1421
|
-
process.exit(1);
|
|
1422
|
-
}
|
|
1423
|
-
},
|
|
1424
|
-
"bundle",
|
|
1425
|
-
dockerArgs,
|
|
1426
|
-
options,
|
|
1427
|
-
logger,
|
|
1428
|
-
options.config
|
|
1429
|
-
);
|
|
1430
|
-
}
|
|
1431
|
-
async function bundle(configOrPath, options = {}) {
|
|
1432
|
-
let rawConfig;
|
|
1433
|
-
if (typeof configOrPath === "string") {
|
|
1434
|
-
rawConfig = await loadJsonConfig(configOrPath);
|
|
1435
|
-
} else {
|
|
1436
|
-
rawConfig = configOrPath;
|
|
1437
|
-
}
|
|
1438
|
-
const { flowConfig, buildOptions } = parseBundleConfig(rawConfig);
|
|
1439
|
-
if (options.cache !== void 0) {
|
|
1440
|
-
buildOptions.cache = options.cache;
|
|
1441
|
-
}
|
|
1442
|
-
const logger = createLogger({
|
|
1443
|
-
silent: options.silent ?? false,
|
|
1444
|
-
verbose: options.verbose ?? false
|
|
1445
|
-
});
|
|
1446
|
-
return await bundleCore(
|
|
1447
|
-
flowConfig,
|
|
1448
|
-
buildOptions,
|
|
1449
|
-
logger,
|
|
1450
|
-
options.stats ?? false
|
|
1451
|
-
);
|
|
1452
|
-
}
|
|
1453
|
-
|
|
1454
|
-
// src/commands/simulate/simulator.ts
|
|
1455
|
-
import path7 from "path";
|
|
1456
|
-
import fs5 from "fs-extra";
|
|
1457
|
-
|
|
1458
|
-
// src/commands/simulate/tracker.ts
|
|
1459
|
-
var CallTracker = class {
|
|
1460
|
-
calls = /* @__PURE__ */ new Map();
|
|
1461
|
-
/**
|
|
1462
|
-
* Wrap a function to track its calls
|
|
1463
|
-
*/
|
|
1464
|
-
wrapFunction(name, fn) {
|
|
1465
|
-
const self = this;
|
|
1466
|
-
const targetFn = fn || (() => {
|
|
1467
|
-
});
|
|
1468
|
-
return new Proxy(targetFn, {
|
|
1469
|
-
apply(_target, thisArg, args) {
|
|
1470
|
-
self.logCall(name, args);
|
|
1471
|
-
return targetFn.apply(thisArg, args);
|
|
1472
|
-
}
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import { readFileSync } from 'fs';
|
|
3
|
+
import { fileURLToPath } from 'url';
|
|
4
|
+
import { dirname, join } from 'path';
|
|
5
|
+
import { bundleCommand } from './commands/bundle';
|
|
6
|
+
import { simulateCommand } from './commands/simulate';
|
|
7
|
+
import { runCommand } from './commands/run';
|
|
8
|
+
// Get package version dynamically
|
|
9
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
10
|
+
const __dirname = dirname(__filename);
|
|
11
|
+
const packageJson = JSON.parse(readFileSync(join(__dirname, '../package.json'), 'utf-8'));
|
|
12
|
+
const VERSION = packageJson.version;
|
|
13
|
+
// === CLI Commands ===
|
|
14
|
+
// Export CLI command handlers
|
|
15
|
+
export { bundleCommand, simulateCommand, runCommand };
|
|
16
|
+
// === Programmatic API ===
|
|
17
|
+
// High-level functions for library usage
|
|
18
|
+
export { bundle } from './commands/bundle';
|
|
19
|
+
export { simulate } from './commands/simulate';
|
|
20
|
+
export { run } from './commands/run';
|
|
21
|
+
const program = new Command();
|
|
22
|
+
program
|
|
23
|
+
.name('walkeros')
|
|
24
|
+
.description('walkerOS CLI - Bundle and deploy walkerOS components')
|
|
25
|
+
.version(VERSION);
|
|
26
|
+
// Bundle command
|
|
27
|
+
program
|
|
28
|
+
.command('bundle [file]')
|
|
29
|
+
.description('Bundle NPM packages with custom code')
|
|
30
|
+
.option('-e, --env <name>', 'environment to build (for multi-environment configs)')
|
|
31
|
+
.option('--all', 'build all environments (for multi-environment configs)')
|
|
32
|
+
.option('-s, --stats', 'show bundle statistics')
|
|
33
|
+
.option('--json', 'output statistics in JSON format (implies --stats)')
|
|
34
|
+
.option('--no-cache', 'disable package caching and download fresh packages')
|
|
35
|
+
.option('-v, --verbose', 'verbose output')
|
|
36
|
+
.option('--local', 'execute in local Node.js instead of Docker')
|
|
37
|
+
.option('--dry-run', 'preview command without executing')
|
|
38
|
+
.option('--silent', 'suppress output')
|
|
39
|
+
.action(async (file, options) => {
|
|
40
|
+
await bundleCommand({
|
|
41
|
+
config: file || 'bundle.config.json',
|
|
42
|
+
env: options.env,
|
|
43
|
+
all: options.all,
|
|
44
|
+
stats: options.stats,
|
|
45
|
+
json: options.json,
|
|
46
|
+
cache: options.cache,
|
|
47
|
+
verbose: options.verbose,
|
|
48
|
+
local: options.local,
|
|
49
|
+
dryRun: options.dryRun,
|
|
50
|
+
silent: options.silent,
|
|
1473
51
|
});
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
const cleanPath = path9.replace(/^call:/, "");
|
|
1495
|
-
const parts = cleanPath.split(".");
|
|
1496
|
-
let current = wrapped;
|
|
1497
|
-
let source = env;
|
|
1498
|
-
for (let i = 0; i < parts.length - 1; i++) {
|
|
1499
|
-
const part = parts[i];
|
|
1500
|
-
if (!current[part]) {
|
|
1501
|
-
current[part] = {};
|
|
1502
|
-
}
|
|
1503
|
-
current = current[part];
|
|
1504
|
-
source = source && typeof source[part] === "object" && source[part] !== null ? source[part] : void 0;
|
|
1505
|
-
}
|
|
1506
|
-
const finalKey = parts[parts.length - 1];
|
|
1507
|
-
const originalFn = source?.[finalKey];
|
|
1508
|
-
current[finalKey] = this.wrapFunction(
|
|
1509
|
-
`${destKey}:${cleanPath}`,
|
|
1510
|
-
typeof originalFn === "function" ? originalFn : void 0
|
|
1511
|
-
);
|
|
1512
|
-
}
|
|
1513
|
-
return wrapped;
|
|
1514
|
-
}
|
|
1515
|
-
logCall(fullPath, args) {
|
|
1516
|
-
const [destKey, ...pathParts] = fullPath.split(":");
|
|
1517
|
-
const apiPath = pathParts.join(":");
|
|
1518
|
-
if (!this.calls.has(destKey)) {
|
|
1519
|
-
this.calls.set(destKey, []);
|
|
1520
|
-
}
|
|
1521
|
-
this.calls.get(destKey).push({
|
|
1522
|
-
type: "call",
|
|
1523
|
-
path: apiPath,
|
|
1524
|
-
args,
|
|
1525
|
-
timestamp: Date.now()
|
|
52
|
+
});
|
|
53
|
+
// Simulate command
|
|
54
|
+
program
|
|
55
|
+
.command('simulate [file]')
|
|
56
|
+
.description('Simulate event processing and capture API calls')
|
|
57
|
+
.option('-e, --event <source>', 'Event to simulate (JSON string, file path, or URL)')
|
|
58
|
+
.option('--json', 'Output results as JSON')
|
|
59
|
+
.option('-v, --verbose', 'Verbose output')
|
|
60
|
+
.option('--local', 'execute in local Node.js instead of Docker')
|
|
61
|
+
.option('--dry-run', 'preview command without executing')
|
|
62
|
+
.option('--silent', 'suppress output')
|
|
63
|
+
.action(async (file, options) => {
|
|
64
|
+
await simulateCommand({
|
|
65
|
+
config: file || 'bundle.config.json',
|
|
66
|
+
event: options.event,
|
|
67
|
+
json: options.json,
|
|
68
|
+
verbose: options.verbose,
|
|
69
|
+
local: options.local,
|
|
70
|
+
dryRun: options.dryRun,
|
|
71
|
+
silent: options.silent,
|
|
1526
72
|
});
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
try {
|
|
1547
|
-
logger.info("\u{1F3AF} Starting walkerOS simulation...");
|
|
1548
|
-
logger.info("\u{1F4E6} Loading bundle configuration...");
|
|
1549
|
-
const fullConfigPath = path7.resolve(configPath);
|
|
1550
|
-
const rawConfig = await loadJsonConfig(fullConfigPath);
|
|
1551
|
-
parseBundleConfig(rawConfig);
|
|
1552
|
-
logger.info(`\u{1F680} Executing simulation with event: ${JSON.stringify(event)}`);
|
|
1553
|
-
const result = await executeSimulation(event, fullConfigPath);
|
|
1554
|
-
if (result.success) {
|
|
1555
|
-
logger.info(`\u2705 Simulation completed successfully`);
|
|
1556
|
-
} else {
|
|
1557
|
-
logger.error(`\u274C Simulation failed: ${result.error}`);
|
|
1558
|
-
}
|
|
1559
|
-
return result;
|
|
1560
|
-
} catch (error) {
|
|
1561
|
-
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
1562
|
-
logger.error(`\u{1F4A5} Simulation error: ${errorMessage}`);
|
|
1563
|
-
return {
|
|
1564
|
-
success: false,
|
|
1565
|
-
error: errorMessage
|
|
1566
|
-
};
|
|
1567
|
-
}
|
|
1568
|
-
}
|
|
1569
|
-
function parseEventInput(eventString = "") {
|
|
1570
|
-
if (!eventString) {
|
|
1571
|
-
return {};
|
|
1572
|
-
}
|
|
1573
|
-
try {
|
|
1574
|
-
const parsed = JSON.parse(eventString);
|
|
1575
|
-
return isObject(parsed) ? parsed : {};
|
|
1576
|
-
} catch {
|
|
1577
|
-
return { name: eventString };
|
|
1578
|
-
}
|
|
1579
|
-
}
|
|
1580
|
-
function formatSimulationResult(result, options = {}) {
|
|
1581
|
-
if (options.json) {
|
|
1582
|
-
const output = {
|
|
1583
|
-
result: result.elbResult,
|
|
1584
|
-
usage: result.usage,
|
|
1585
|
-
duration: result.duration
|
|
1586
|
-
};
|
|
1587
|
-
return JSON.stringify(output, null, 2);
|
|
1588
|
-
}
|
|
1589
|
-
if (result.success) {
|
|
1590
|
-
return "\u2705 Simulation completed successfully";
|
|
1591
|
-
} else {
|
|
1592
|
-
return `\u274C Simulation failed: ${result.error}`;
|
|
1593
|
-
}
|
|
1594
|
-
}
|
|
1595
|
-
async function executeSimulation(event, configPath) {
|
|
1596
|
-
const startTime = Date.now();
|
|
1597
|
-
let bundlePath;
|
|
1598
|
-
const tempDir = getTempDir();
|
|
1599
|
-
try {
|
|
1600
|
-
await fs5.ensureDir(tempDir);
|
|
1601
|
-
const rawConfig = await loadJsonConfig(configPath);
|
|
1602
|
-
const { flowConfig, buildOptions } = parseBundleConfig(rawConfig);
|
|
1603
|
-
const packagesArray = Object.entries(buildOptions.packages).map(
|
|
1604
|
-
([name, packageConfig]) => ({
|
|
1605
|
-
name,
|
|
1606
|
-
version: (typeof packageConfig === "object" && packageConfig !== null && "version" in packageConfig && typeof packageConfig.version === "string" ? packageConfig.version : void 0) || "latest"
|
|
1607
|
-
})
|
|
1608
|
-
);
|
|
1609
|
-
const packagePaths = await downloadPackages(
|
|
1610
|
-
packagesArray,
|
|
1611
|
-
tempDir,
|
|
1612
|
-
// downloadPackages will add 'node_modules' subdirectory itself
|
|
1613
|
-
createLogger({ silent: true }),
|
|
1614
|
-
buildOptions.cache
|
|
1615
|
-
);
|
|
1616
|
-
const tracker = new CallTracker();
|
|
1617
|
-
const envSetupCode = [];
|
|
1618
|
-
const destinations = flowConfig.destinations;
|
|
1619
|
-
if (destinations) {
|
|
1620
|
-
for (const [key, dest] of Object.entries(destinations)) {
|
|
1621
|
-
const destName = key.replace(/-/g, "_");
|
|
1622
|
-
envSetupCode.push(`
|
|
1623
|
-
// Inject tracked env for destination '${key}' using examples from bundle
|
|
1624
|
-
if (examples && examples['${key}'] && examples['${key}'].env) {
|
|
1625
|
-
const mockEnv = examples['${key}'].env.push;
|
|
1626
|
-
const trackPaths = examples['${key}'].env.simulation || [];
|
|
1627
|
-
if (mockEnv) {
|
|
1628
|
-
const wrappedPaths = trackPaths.map((p) => '${key}:' + p);
|
|
1629
|
-
const trackedEnv = __simulationTracker.wrapEnv(mockEnv, wrappedPaths);
|
|
1630
|
-
if (config.destinations && config.destinations['${key}']) {
|
|
1631
|
-
config.destinations['${key}'].env = trackedEnv;
|
|
1632
|
-
}
|
|
1633
|
-
}
|
|
1634
|
-
}
|
|
1635
|
-
`);
|
|
1636
|
-
}
|
|
1637
|
-
}
|
|
1638
|
-
const modifiedCode = `
|
|
1639
|
-
// Inject tracked envs into destination configs
|
|
1640
|
-
${envSetupCode.join("\n")}
|
|
1641
|
-
|
|
1642
|
-
${buildOptions.code || ""}
|
|
1643
|
-
`;
|
|
1644
|
-
const tempOutput = path7.join(
|
|
1645
|
-
tempDir,
|
|
1646
|
-
`simulation-bundle-${generateId()}.mjs`
|
|
1647
|
-
);
|
|
1648
|
-
const simulationBuildOptions = {
|
|
1649
|
-
...buildOptions,
|
|
1650
|
-
code: modifiedCode,
|
|
1651
|
-
output: tempOutput,
|
|
1652
|
-
tempDir,
|
|
1653
|
-
// Use same temp dir for bundle
|
|
1654
|
-
format: "esm",
|
|
1655
|
-
// Force node platform for simulation since we're running in Node.js
|
|
1656
|
-
platform: "node"
|
|
1657
|
-
};
|
|
1658
|
-
await bundleCore(
|
|
1659
|
-
flowConfig,
|
|
1660
|
-
simulationBuildOptions,
|
|
1661
|
-
createLogger({ silent: true }),
|
|
1662
|
-
false
|
|
1663
|
-
);
|
|
1664
|
-
bundlePath = tempOutput;
|
|
1665
|
-
const globalWithSim = globalThis;
|
|
1666
|
-
if (!globalWithSim.window) {
|
|
1667
|
-
globalWithSim.window = {};
|
|
1668
|
-
}
|
|
1669
|
-
if (!globalWithSim.document) {
|
|
1670
|
-
globalWithSim.document = {};
|
|
1671
|
-
}
|
|
1672
|
-
const timestamp = Date.now();
|
|
1673
|
-
const moduleUrl = `file://${bundlePath}?t=${timestamp}`;
|
|
1674
|
-
const module = await import(moduleUrl);
|
|
1675
|
-
const importedExamples = module.examples;
|
|
1676
|
-
const destinations2 = flowConfig.destinations;
|
|
1677
|
-
if (importedExamples && destinations2) {
|
|
1678
|
-
for (const [key, dest] of Object.entries(destinations2)) {
|
|
1679
|
-
const destEnv = importedExamples[key]?.env?.push;
|
|
1680
|
-
if (destEnv) {
|
|
1681
|
-
if (destEnv.window && typeof globalWithSim.window === "object" && globalWithSim.window !== null) {
|
|
1682
|
-
Object.assign(globalWithSim.window, destEnv.window);
|
|
1683
|
-
}
|
|
1684
|
-
if (destEnv.document && typeof globalWithSim.document === "object" && globalWithSim.document !== null) {
|
|
1685
|
-
Object.assign(globalWithSim.document, destEnv.document);
|
|
1686
|
-
}
|
|
1687
|
-
}
|
|
1688
|
-
}
|
|
1689
|
-
}
|
|
1690
|
-
const flowResult = await module.default({ tracker });
|
|
1691
|
-
if (!flowResult || typeof flowResult.elb !== "function") {
|
|
1692
|
-
throw new Error(
|
|
1693
|
-
"Bundle did not export valid flow object with elb function"
|
|
1694
|
-
);
|
|
1695
|
-
}
|
|
1696
|
-
const { elb } = flowResult;
|
|
1697
|
-
const elbResult = await elb(event);
|
|
1698
|
-
const usage = tracker.getCalls();
|
|
1699
|
-
const duration = Date.now() - startTime;
|
|
1700
|
-
return {
|
|
1701
|
-
success: true,
|
|
1702
|
-
elbResult,
|
|
1703
|
-
usage,
|
|
1704
|
-
duration,
|
|
1705
|
-
logs: []
|
|
1706
|
-
};
|
|
1707
|
-
} catch (error) {
|
|
1708
|
-
const duration = Date.now() - startTime;
|
|
1709
|
-
return {
|
|
1710
|
-
success: false,
|
|
1711
|
-
error: error instanceof Error ? error.message : String(error),
|
|
1712
|
-
duration
|
|
1713
|
-
};
|
|
1714
|
-
} finally {
|
|
1715
|
-
if (tempDir) {
|
|
1716
|
-
await fs5.remove(tempDir).catch(() => {
|
|
1717
|
-
});
|
|
1718
|
-
}
|
|
1719
|
-
const globalWithSim = globalThis;
|
|
1720
|
-
delete globalWithSim.window;
|
|
1721
|
-
delete globalWithSim.document;
|
|
1722
|
-
}
|
|
1723
|
-
}
|
|
1724
|
-
|
|
1725
|
-
// src/commands/simulate/index.ts
|
|
1726
|
-
async function simulateCommand(options) {
|
|
1727
|
-
const logger = createLogger({
|
|
1728
|
-
verbose: options.verbose,
|
|
1729
|
-
silent: options.silent ?? false,
|
|
1730
|
-
json: options.json
|
|
1731
|
-
});
|
|
1732
|
-
const dockerArgs = [options.config];
|
|
1733
|
-
if (options.event) dockerArgs.push("--event", options.event);
|
|
1734
|
-
if (options.json) dockerArgs.push("--json");
|
|
1735
|
-
if (options.verbose) dockerArgs.push("--verbose");
|
|
1736
|
-
if (options.silent) dockerArgs.push("--silent");
|
|
1737
|
-
await executeCommand(
|
|
1738
|
-
async () => {
|
|
1739
|
-
const startTime = Date.now();
|
|
1740
|
-
try {
|
|
1741
|
-
const event = parseEventInput(options.event);
|
|
1742
|
-
const result = await simulateCore(options.config, event, {
|
|
1743
|
-
json: options.json,
|
|
1744
|
-
verbose: options.verbose,
|
|
1745
|
-
silent: options.silent
|
|
1746
|
-
});
|
|
1747
|
-
const resultWithDuration = {
|
|
1748
|
-
...result,
|
|
1749
|
-
duration: (Date.now() - startTime) / 1e3
|
|
1750
|
-
};
|
|
1751
|
-
const outputLogger = createLogger({ silent: false, json: false });
|
|
1752
|
-
const output = formatSimulationResult(resultWithDuration, {
|
|
1753
|
-
json: options.json
|
|
1754
|
-
});
|
|
1755
|
-
outputLogger.log("white", output);
|
|
1756
|
-
if (!result.success) {
|
|
1757
|
-
process.exit(1);
|
|
1758
|
-
}
|
|
1759
|
-
} catch (error) {
|
|
1760
|
-
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
1761
|
-
if (options.json) {
|
|
1762
|
-
const outputLogger = createLogger({ silent: false, json: false });
|
|
1763
|
-
const errorOutput = JSON.stringify(
|
|
1764
|
-
{
|
|
1765
|
-
success: false,
|
|
1766
|
-
error: errorMessage,
|
|
1767
|
-
duration: (Date.now() - startTime) / 1e3
|
|
1768
|
-
},
|
|
1769
|
-
null,
|
|
1770
|
-
2
|
|
1771
|
-
);
|
|
1772
|
-
outputLogger.log("white", errorOutput);
|
|
1773
|
-
} else {
|
|
1774
|
-
const errorLogger = createLogger({ silent: false, json: false });
|
|
1775
|
-
errorLogger.error(`\u274C Simulate command failed: ${errorMessage}`);
|
|
1776
|
-
}
|
|
1777
|
-
process.exit(1);
|
|
1778
|
-
}
|
|
1779
|
-
},
|
|
1780
|
-
"simulate",
|
|
1781
|
-
dockerArgs,
|
|
1782
|
-
options,
|
|
1783
|
-
logger,
|
|
1784
|
-
options.config
|
|
1785
|
-
);
|
|
1786
|
-
}
|
|
1787
|
-
async function simulate(configOrPath, event, options = {}) {
|
|
1788
|
-
if (typeof configOrPath !== "string") {
|
|
1789
|
-
throw new Error(
|
|
1790
|
-
"simulate() currently only supports config file paths. Config object support will be added in a future version. Please provide a path to a configuration file."
|
|
1791
|
-
);
|
|
1792
|
-
}
|
|
1793
|
-
return await simulateCore(configOrPath, event, {
|
|
1794
|
-
json: options.json ?? false,
|
|
1795
|
-
verbose: options.verbose ?? false
|
|
1796
|
-
});
|
|
1797
|
-
}
|
|
1798
|
-
|
|
1799
|
-
// src/commands/run/index.ts
|
|
1800
|
-
import path8 from "path";
|
|
1801
|
-
import os2 from "os";
|
|
1802
|
-
import {
|
|
1803
|
-
runFlow,
|
|
1804
|
-
runServeMode
|
|
1805
|
-
} from "@walkeros/docker";
|
|
1806
|
-
|
|
1807
|
-
// src/commands/run/validators.ts
|
|
1808
|
-
import { existsSync } from "fs";
|
|
1809
|
-
var VALID_MODES = ["collect", "serve"];
|
|
1810
|
-
function validateMode(mode) {
|
|
1811
|
-
if (!VALID_MODES.includes(mode)) {
|
|
1812
|
-
throw new Error(
|
|
1813
|
-
`Invalid mode: "${mode}"
|
|
1814
|
-
Valid modes: ${VALID_MODES.join(", ")}
|
|
1815
|
-
Example: walkeros run collect ./flow.json`
|
|
1816
|
-
);
|
|
1817
|
-
}
|
|
1818
|
-
}
|
|
1819
|
-
function validateFlowFile(filePath) {
|
|
1820
|
-
const absolutePath = resolveAsset(filePath, "bundle");
|
|
1821
|
-
if (!existsSync(absolutePath)) {
|
|
1822
|
-
throw new Error(
|
|
1823
|
-
`Flow file not found: ${filePath}
|
|
1824
|
-
Resolved path: ${absolutePath}
|
|
1825
|
-
Make sure the file exists and the path is correct`
|
|
1826
|
-
);
|
|
1827
|
-
}
|
|
1828
|
-
return absolutePath;
|
|
1829
|
-
}
|
|
1830
|
-
function validatePort(port) {
|
|
1831
|
-
if (!Number.isInteger(port) || port < 1 || port > 65535) {
|
|
1832
|
-
throw new Error(
|
|
1833
|
-
`Invalid port: ${port}
|
|
1834
|
-
Port must be an integer between 1 and 65535
|
|
1835
|
-
Example: --port 8080`
|
|
1836
|
-
);
|
|
1837
|
-
}
|
|
1838
|
-
}
|
|
1839
|
-
|
|
1840
|
-
// src/commands/run/index.ts
|
|
1841
|
-
async function runCommand(mode, options) {
|
|
1842
|
-
const timer = createTimer();
|
|
1843
|
-
timer.start();
|
|
1844
|
-
const logger = createLogger({
|
|
1845
|
-
verbose: options.verbose,
|
|
1846
|
-
silent: options.silent ?? false,
|
|
1847
|
-
json: options.json
|
|
1848
|
-
});
|
|
1849
|
-
try {
|
|
1850
|
-
validateMode(mode);
|
|
1851
|
-
const configPath = validateFlowFile(options.config);
|
|
1852
|
-
if (options.port !== void 0) {
|
|
1853
|
-
validatePort(options.port);
|
|
1854
|
-
}
|
|
1855
|
-
const isPreBuilt = configPath.endsWith(".mjs") || configPath.endsWith(".js") || configPath.endsWith(".cjs");
|
|
1856
|
-
let flowPath = null;
|
|
1857
|
-
if (mode === "collect") {
|
|
1858
|
-
if (isPreBuilt) {
|
|
1859
|
-
flowPath = path8.resolve(configPath);
|
|
1860
|
-
if (!options.json && !options.silent) {
|
|
1861
|
-
logger.info(`\u{1F4E6} Using pre-built flow: ${path8.basename(flowPath)}`);
|
|
1862
|
-
}
|
|
1863
|
-
} else {
|
|
1864
|
-
if (!options.json && !options.silent) {
|
|
1865
|
-
logger.info("\u{1F528} Building flow bundle...");
|
|
1866
|
-
}
|
|
1867
|
-
const rawConfig = await loadJsonConfig(configPath);
|
|
1868
|
-
const tempPath = path8.join(
|
|
1869
|
-
os2.tmpdir(),
|
|
1870
|
-
`walkeros-${Date.now()}-${Math.random().toString(36).slice(2, 9)}.mjs`
|
|
1871
|
-
);
|
|
1872
|
-
const existingBuild = typeof rawConfig === "object" && rawConfig !== null && "build" in rawConfig && typeof rawConfig.build === "object" ? rawConfig.build : {};
|
|
1873
|
-
const configWithOutput = {
|
|
1874
|
-
...rawConfig,
|
|
1875
|
-
build: {
|
|
1876
|
-
...existingBuild,
|
|
1877
|
-
output: tempPath
|
|
1878
|
-
}
|
|
1879
|
-
};
|
|
1880
|
-
await bundle(configWithOutput, {
|
|
1881
|
-
cache: true,
|
|
1882
|
-
verbose: options.verbose,
|
|
1883
|
-
silent: options.json || options.silent
|
|
1884
|
-
});
|
|
1885
|
-
flowPath = tempPath;
|
|
1886
|
-
if (!options.json && !options.silent) {
|
|
1887
|
-
logger.success("\u2705 Bundle ready");
|
|
1888
|
-
}
|
|
1889
|
-
}
|
|
1890
|
-
}
|
|
1891
|
-
const executionMode = getExecutionMode(options);
|
|
1892
|
-
if (executionMode === "docker") {
|
|
1893
|
-
const dockerAvailable = await isDockerAvailable();
|
|
1894
|
-
if (!dockerAvailable) {
|
|
1895
|
-
throw new Error(
|
|
1896
|
-
"Docker is not available. Please install Docker or use --local flag to execute locally."
|
|
1897
|
-
);
|
|
1898
|
-
}
|
|
1899
|
-
if (!options.json && !options.silent) {
|
|
1900
|
-
logger.info("\u{1F433} Executing in production runtime container...");
|
|
1901
|
-
}
|
|
1902
|
-
await executeRunInDocker(mode, flowPath, {
|
|
73
|
+
});
|
|
74
|
+
// Run command with subcommands
|
|
75
|
+
const runCmd = program
|
|
76
|
+
.command('run')
|
|
77
|
+
.description('Run walkerOS flows in collect or serve mode');
|
|
78
|
+
// Run collect subcommand
|
|
79
|
+
runCmd
|
|
80
|
+
.command('collect [file]')
|
|
81
|
+
.description('Run collector mode (event collection endpoint). Defaults to server-collect.mjs if no file specified.')
|
|
82
|
+
.option('-p, --port <number>', 'Port to listen on (default: 8080)', parseInt)
|
|
83
|
+
.option('-h, --host <address>', 'Host address (default: 0.0.0.0)')
|
|
84
|
+
.option('--json', 'Output results as JSON')
|
|
85
|
+
.option('-v, --verbose', 'Verbose output')
|
|
86
|
+
.option('--local', 'execute in local Node.js instead of Docker')
|
|
87
|
+
.option('--dry-run', 'preview command without executing')
|
|
88
|
+
.option('--silent', 'suppress output')
|
|
89
|
+
.action(async (file, options) => {
|
|
90
|
+
await runCommand('collect', {
|
|
91
|
+
config: file || 'server-collect.mjs',
|
|
1903
92
|
port: options.port,
|
|
1904
93
|
host: options.host,
|
|
1905
|
-
|
|
1906
|
-
servePath: options.servePath,
|
|
1907
|
-
silent: options.silent
|
|
1908
|
-
});
|
|
1909
|
-
} else {
|
|
1910
|
-
if (!options.json && !options.silent) {
|
|
1911
|
-
const modeLabel = mode === "collect" ? "Collector" : "Server";
|
|
1912
|
-
logger.info(`\u{1F5A5}\uFE0F Starting ${modeLabel} locally...`);
|
|
1913
|
-
}
|
|
1914
|
-
switch (mode) {
|
|
1915
|
-
case "collect": {
|
|
1916
|
-
if (!flowPath) {
|
|
1917
|
-
throw new Error("Flow path is required for collect mode");
|
|
1918
|
-
}
|
|
1919
|
-
const config = {
|
|
1920
|
-
port: options.port,
|
|
1921
|
-
host: options.host
|
|
1922
|
-
};
|
|
1923
|
-
await runFlow(flowPath, config);
|
|
1924
|
-
break;
|
|
1925
|
-
}
|
|
1926
|
-
case "serve": {
|
|
1927
|
-
const config = {
|
|
1928
|
-
port: options.port,
|
|
1929
|
-
host: options.host,
|
|
1930
|
-
serveName: options.serveName,
|
|
1931
|
-
servePath: options.servePath,
|
|
1932
|
-
filePath: flowPath || void 0
|
|
1933
|
-
};
|
|
1934
|
-
await runServeMode(config);
|
|
1935
|
-
break;
|
|
1936
|
-
}
|
|
1937
|
-
default:
|
|
1938
|
-
throw new Error(`Unknown mode: ${mode}`);
|
|
1939
|
-
}
|
|
1940
|
-
}
|
|
1941
|
-
} catch (error) {
|
|
1942
|
-
const duration = timer.getElapsed() / 1e3;
|
|
1943
|
-
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
1944
|
-
if (options.json) {
|
|
1945
|
-
const output = {
|
|
1946
|
-
success: false,
|
|
1947
|
-
mode,
|
|
1948
|
-
error: errorMessage,
|
|
1949
|
-
duration
|
|
1950
|
-
};
|
|
1951
|
-
console.log(JSON.stringify(output, null, 2));
|
|
1952
|
-
} else {
|
|
1953
|
-
logger.error("\u274C Run failed:");
|
|
1954
|
-
logger.error(errorMessage);
|
|
1955
|
-
}
|
|
1956
|
-
process.exit(1);
|
|
1957
|
-
}
|
|
1958
|
-
}
|
|
1959
|
-
async function run(mode, options) {
|
|
1960
|
-
const startTime = Date.now();
|
|
1961
|
-
try {
|
|
1962
|
-
validateMode(mode);
|
|
1963
|
-
let flowFile;
|
|
1964
|
-
if (typeof options.config === "string") {
|
|
1965
|
-
flowFile = validateFlowFile(options.config);
|
|
1966
|
-
} else {
|
|
1967
|
-
throw new Error("Programmatic run() requires config file path");
|
|
1968
|
-
}
|
|
1969
|
-
if (options.port !== void 0) {
|
|
1970
|
-
validatePort(options.port);
|
|
1971
|
-
}
|
|
1972
|
-
const isPreBuilt = flowFile.endsWith(".mjs") || flowFile.endsWith(".js") || flowFile.endsWith(".cjs");
|
|
1973
|
-
let flowPath;
|
|
1974
|
-
if (isPreBuilt) {
|
|
1975
|
-
flowPath = path8.resolve(flowFile);
|
|
1976
|
-
} else {
|
|
1977
|
-
const rawConfig = await loadJsonConfig(flowFile);
|
|
1978
|
-
const tempPath = path8.join(
|
|
1979
|
-
os2.tmpdir(),
|
|
1980
|
-
`walkeros-${Date.now()}-${Math.random().toString(36).slice(2, 9)}.mjs`
|
|
1981
|
-
);
|
|
1982
|
-
const existingBuild = typeof rawConfig === "object" && rawConfig !== null && "build" in rawConfig && typeof rawConfig.build === "object" ? rawConfig.build : {};
|
|
1983
|
-
const configWithOutput = {
|
|
1984
|
-
...rawConfig,
|
|
1985
|
-
build: {
|
|
1986
|
-
...existingBuild,
|
|
1987
|
-
output: tempPath
|
|
1988
|
-
}
|
|
1989
|
-
};
|
|
1990
|
-
await bundle(configWithOutput, {
|
|
1991
|
-
cache: true,
|
|
94
|
+
json: options.json,
|
|
1992
95
|
verbose: options.verbose,
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
}
|
|
1997
|
-
switch (mode) {
|
|
1998
|
-
case "collect": {
|
|
1999
|
-
const config = {
|
|
2000
|
-
port: options.port,
|
|
2001
|
-
host: options.host
|
|
2002
|
-
};
|
|
2003
|
-
await runFlow(flowPath, config);
|
|
2004
|
-
break;
|
|
2005
|
-
}
|
|
2006
|
-
case "serve": {
|
|
2007
|
-
const config = {
|
|
2008
|
-
port: options.port,
|
|
2009
|
-
host: options.host,
|
|
2010
|
-
serveName: options.serveName,
|
|
2011
|
-
servePath: options.servePath,
|
|
2012
|
-
filePath: flowPath
|
|
2013
|
-
};
|
|
2014
|
-
await runServeMode(config);
|
|
2015
|
-
break;
|
|
2016
|
-
}
|
|
2017
|
-
default:
|
|
2018
|
-
throw new Error(`Unknown mode: ${mode}`);
|
|
2019
|
-
}
|
|
2020
|
-
return {
|
|
2021
|
-
success: true,
|
|
2022
|
-
exitCode: 0,
|
|
2023
|
-
duration: Date.now() - startTime
|
|
2024
|
-
};
|
|
2025
|
-
} catch (error) {
|
|
2026
|
-
return {
|
|
2027
|
-
success: false,
|
|
2028
|
-
exitCode: 1,
|
|
2029
|
-
duration: Date.now() - startTime,
|
|
2030
|
-
error: error instanceof Error ? error.message : String(error)
|
|
2031
|
-
};
|
|
2032
|
-
}
|
|
2033
|
-
}
|
|
2034
|
-
|
|
2035
|
-
// src/index.ts
|
|
2036
|
-
var __filename = fileURLToPath3(import.meta.url);
|
|
2037
|
-
var __dirname = dirname(__filename);
|
|
2038
|
-
var packageJson = JSON.parse(
|
|
2039
|
-
readFileSync2(join(__dirname, "../package.json"), "utf-8")
|
|
2040
|
-
);
|
|
2041
|
-
var VERSION = packageJson.version;
|
|
2042
|
-
var program = new Command();
|
|
2043
|
-
program.name("walkeros").description("walkerOS CLI - Bundle and deploy walkerOS components").version(VERSION);
|
|
2044
|
-
program.command("bundle [file]").description("Bundle NPM packages with custom code").option(
|
|
2045
|
-
"-e, --env <name>",
|
|
2046
|
-
"environment to build (for multi-environment configs)"
|
|
2047
|
-
).option("--all", "build all environments (for multi-environment configs)").option("-s, --stats", "show bundle statistics").option("--json", "output statistics in JSON format (implies --stats)").option("--no-cache", "disable package caching and download fresh packages").option("-v, --verbose", "verbose output").option("--local", "execute in local Node.js instead of Docker").option("--dry-run", "preview command without executing").option("--silent", "suppress output").action(async (file, options) => {
|
|
2048
|
-
await bundleCommand({
|
|
2049
|
-
config: file || "bundle.config.json",
|
|
2050
|
-
env: options.env,
|
|
2051
|
-
all: options.all,
|
|
2052
|
-
stats: options.stats,
|
|
2053
|
-
json: options.json,
|
|
2054
|
-
cache: options.cache,
|
|
2055
|
-
verbose: options.verbose,
|
|
2056
|
-
local: options.local,
|
|
2057
|
-
dryRun: options.dryRun,
|
|
2058
|
-
silent: options.silent
|
|
2059
|
-
});
|
|
2060
|
-
});
|
|
2061
|
-
program.command("simulate [file]").description("Simulate event processing and capture API calls").option("-e, --event <json>", "Event to simulate (JSON string)").option("--json", "Output results as JSON").option("-v, --verbose", "Verbose output").option("--local", "execute in local Node.js instead of Docker").option("--dry-run", "preview command without executing").option("--silent", "suppress output").action(async (file, options) => {
|
|
2062
|
-
await simulateCommand({
|
|
2063
|
-
config: file || "bundle.config.json",
|
|
2064
|
-
event: options.event,
|
|
2065
|
-
json: options.json,
|
|
2066
|
-
verbose: options.verbose,
|
|
2067
|
-
local: options.local,
|
|
2068
|
-
dryRun: options.dryRun,
|
|
2069
|
-
silent: options.silent
|
|
2070
|
-
});
|
|
2071
|
-
});
|
|
2072
|
-
var runCmd = program.command("run").description("Run walkerOS flows in collect or serve mode");
|
|
2073
|
-
runCmd.command("collect [file]").description(
|
|
2074
|
-
"Run collector mode (event collection endpoint). Defaults to server-collect.mjs if no file specified."
|
|
2075
|
-
).option("-p, --port <number>", "Port to listen on (default: 8080)", parseInt).option("-h, --host <address>", "Host address (default: 0.0.0.0)").option("--json", "Output results as JSON").option("-v, --verbose", "Verbose output").option("--local", "execute in local Node.js instead of Docker").option("--dry-run", "preview command without executing").option("--silent", "suppress output").action(async (file, options) => {
|
|
2076
|
-
await runCommand("collect", {
|
|
2077
|
-
config: file || "server-collect.mjs",
|
|
2078
|
-
port: options.port,
|
|
2079
|
-
host: options.host,
|
|
2080
|
-
json: options.json,
|
|
2081
|
-
verbose: options.verbose,
|
|
2082
|
-
local: options.local,
|
|
2083
|
-
dryRun: options.dryRun,
|
|
2084
|
-
silent: options.silent
|
|
2085
|
-
});
|
|
96
|
+
local: options.local,
|
|
97
|
+
dryRun: options.dryRun,
|
|
98
|
+
silent: options.silent,
|
|
99
|
+
});
|
|
2086
100
|
});
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
|
|
101
|
+
// Run serve subcommand
|
|
102
|
+
runCmd
|
|
103
|
+
.command('serve [file]')
|
|
104
|
+
.description('Run serve mode (single-file server for browser bundles). Defaults to baked-in web-serve.js if no file specified.')
|
|
105
|
+
.option('-p, --port <number>', 'Port to listen on (default: 8080)', parseInt)
|
|
106
|
+
.option('-h, --host <address>', 'Host address (default: 0.0.0.0)')
|
|
107
|
+
.option('--name <filename>', 'Filename in URL (default: walker.js)')
|
|
108
|
+
.option('--path <directory>', 'URL directory path (e.g., libs/v1)')
|
|
109
|
+
.option('--json', 'Output results as JSON')
|
|
110
|
+
.option('-v, --verbose', 'Verbose output')
|
|
111
|
+
.option('--local', 'execute in local Node.js instead of Docker')
|
|
112
|
+
.option('--dry-run', 'preview command without executing')
|
|
113
|
+
.option('--silent', 'suppress output')
|
|
114
|
+
.action(async (file, options) => {
|
|
115
|
+
await runCommand('serve', {
|
|
116
|
+
config: file || 'web-serve.js',
|
|
117
|
+
port: options.port,
|
|
118
|
+
host: options.host,
|
|
119
|
+
serveName: options.name,
|
|
120
|
+
servePath: options.path,
|
|
121
|
+
json: options.json,
|
|
122
|
+
verbose: options.verbose,
|
|
123
|
+
local: options.local,
|
|
124
|
+
dryRun: options.dryRun,
|
|
125
|
+
silent: options.silent,
|
|
126
|
+
});
|
|
2102
127
|
});
|
|
128
|
+
// Run the CLI
|
|
129
|
+
// Note: This file is marked as a bin script in package.json,
|
|
130
|
+
// so it's always executed directly (never imported as a library)
|
|
2103
131
|
program.parse();
|
|
2104
|
-
export {
|
|
2105
|
-
bundle,
|
|
2106
|
-
bundleCommand,
|
|
2107
|
-
run,
|
|
2108
|
-
runCommand,
|
|
2109
|
-
simulate,
|
|
2110
|
-
simulateCommand
|
|
2111
|
-
};
|
|
2112
132
|
//# sourceMappingURL=index.js.map
|