@walkeros/cli 0.5.1-next.0 → 0.6.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 +35 -0
- package/README.md +51 -28
- package/dist/__tests__/bundle/bundler-helpers.test.d.ts +2 -0
- package/dist/__tests__/bundle/bundler-helpers.test.d.ts.map +1 -0
- package/dist/__tests__/bundle/bundler-helpers.test.js +151 -0
- package/dist/__tests__/bundle/bundler-helpers.test.js.map +1 -0
- package/dist/__tests__/bundle/bundler.test.d.ts +2 -0
- package/dist/__tests__/bundle/bundler.test.d.ts.map +1 -0
- package/dist/__tests__/bundle/bundler.test.js +352 -0
- package/dist/__tests__/bundle/bundler.test.js.map +1 -0
- package/dist/__tests__/bundle/programmatic.test.d.ts +2 -0
- package/dist/__tests__/bundle/programmatic.test.d.ts.map +1 -0
- package/dist/__tests__/bundle/programmatic.test.js +148 -0
- package/dist/__tests__/bundle/programmatic.test.js.map +1 -0
- package/dist/__tests__/cli-e2e.test.d.ts +8 -0
- package/dist/__tests__/cli-e2e.test.d.ts.map +1 -0
- package/dist/__tests__/cli-e2e.test.js +145 -0
- package/dist/__tests__/cli-e2e.test.js.map +1 -0
- package/dist/__tests__/cli.test.d.ts +2 -0
- package/dist/__tests__/cli.test.d.ts.map +1 -0
- package/dist/__tests__/cli.test.js +179 -0
- package/dist/__tests__/cli.test.js.map +1 -0
- package/dist/__tests__/config-loader.test.d.ts +7 -0
- package/dist/__tests__/config-loader.test.d.ts.map +1 -0
- package/dist/__tests__/config-loader.test.js +414 -0
- package/dist/__tests__/config-loader.test.js.map +1 -0
- package/dist/__tests__/core/asset-resolver.test.d.ts +2 -0
- package/dist/__tests__/core/asset-resolver.test.d.ts.map +1 -0
- package/dist/__tests__/core/asset-resolver.test.js +14 -0
- package/dist/__tests__/core/asset-resolver.test.js.map +1 -0
- package/dist/__tests__/core/build-cache.test.d.ts +2 -0
- package/dist/__tests__/core/build-cache.test.d.ts.map +1 -0
- package/dist/__tests__/core/build-cache.test.js +55 -0
- package/dist/__tests__/core/build-cache.test.js.map +1 -0
- package/dist/__tests__/core/cache-utils.test.d.ts +2 -0
- package/dist/__tests__/core/cache-utils.test.d.ts.map +1 -0
- package/dist/__tests__/core/cache-utils.test.js +70 -0
- package/dist/__tests__/core/cache-utils.test.js.map +1 -0
- package/dist/__tests__/core/config.test.d.ts +2 -0
- package/dist/__tests__/core/config.test.d.ts.map +1 -0
- package/dist/__tests__/core/config.test.js +79 -0
- package/dist/__tests__/core/config.test.js.map +1 -0
- package/dist/__tests__/core/logger.test.d.ts +2 -0
- package/dist/__tests__/core/logger.test.d.ts.map +1 -0
- package/dist/__tests__/core/logger.test.js +53 -0
- package/dist/__tests__/core/logger.test.js.map +1 -0
- package/dist/__tests__/integration/bundle-run.integration.test.d.ts +8 -0
- package/dist/__tests__/integration/bundle-run.integration.test.d.ts.map +1 -0
- package/dist/__tests__/integration/bundle-run.integration.test.js +54 -0
- package/dist/__tests__/integration/bundle-run.integration.test.js.map +1 -0
- package/dist/__tests__/push/push.test.d.ts +7 -0
- package/dist/__tests__/push/push.test.d.ts.map +1 -0
- package/dist/__tests__/push/push.test.js +197 -0
- package/dist/__tests__/push/push.test.js.map +1 -0
- package/dist/__tests__/simulate/env-loader.test.d.ts +2 -0
- package/dist/__tests__/simulate/env-loader.test.d.ts.map +1 -0
- package/dist/__tests__/simulate/env-loader.test.js +47 -0
- package/dist/__tests__/simulate/env-loader.test.js.map +1 -0
- package/dist/__tests__/simulate/node-executor.test.d.ts +5 -0
- package/dist/__tests__/simulate/node-executor.test.d.ts.map +1 -0
- package/dist/__tests__/simulate/node-executor.test.js +25 -0
- package/dist/__tests__/simulate/node-executor.test.js.map +1 -0
- package/dist/__tests__/simulate/server-simulate.integration.test.d.ts +5 -0
- package/dist/__tests__/simulate/server-simulate.integration.test.d.ts.map +1 -0
- package/dist/__tests__/simulate/server-simulate.integration.test.js +58 -0
- package/dist/__tests__/simulate/server-simulate.integration.test.js.map +1 -0
- package/dist/__tests__/smoke/production.smoke.test.d.ts +8 -0
- package/dist/__tests__/smoke/production.smoke.test.d.ts.map +1 -0
- package/dist/__tests__/smoke/production.smoke.test.js +65 -0
- package/dist/__tests__/smoke/production.smoke.test.js.map +1 -0
- package/dist/commands/bundle/bundler.d.ts +32 -0
- package/dist/commands/bundle/bundler.d.ts.map +1 -0
- package/dist/commands/bundle/bundler.js +569 -0
- package/dist/commands/bundle/bundler.js.map +1 -0
- package/dist/commands/bundle/index.d.ts +59 -0
- package/dist/commands/bundle/index.d.ts.map +1 -0
- package/dist/commands/bundle/index.js +184 -0
- package/dist/commands/bundle/index.js.map +1 -0
- package/dist/commands/bundle/package-manager.d.ts +8 -0
- package/dist/commands/bundle/package-manager.d.ts.map +1 -0
- package/dist/commands/bundle/package-manager.js +220 -0
- package/dist/commands/bundle/package-manager.js.map +1 -0
- package/dist/commands/bundle/stats.d.ts +23 -0
- package/dist/commands/bundle/stats.d.ts.map +1 -0
- package/dist/commands/bundle/stats.js +52 -0
- package/dist/commands/bundle/stats.js.map +1 -0
- package/dist/commands/cache.d.ts +7 -0
- package/dist/commands/cache.d.ts.map +1 -0
- package/dist/commands/cache.js +68 -0
- package/dist/commands/cache.js.map +1 -0
- package/dist/commands/push/index.d.ts +7 -0
- package/dist/commands/push/index.d.ts.map +1 -0
- package/dist/commands/push/index.js +247 -0
- package/dist/commands/push/index.js.map +1 -0
- package/dist/commands/push/types.d.ts +22 -0
- package/dist/commands/push/types.d.ts.map +1 -0
- package/dist/commands/push/types.js +2 -0
- package/dist/commands/push/types.js.map +1 -0
- package/dist/commands/run/__tests__/run.integration.test.d.ts +7 -0
- package/dist/commands/run/__tests__/run.integration.test.d.ts.map +1 -0
- package/dist/commands/run/__tests__/run.integration.test.js +51 -0
- package/dist/commands/run/__tests__/run.integration.test.js.map +1 -0
- package/dist/commands/run/__tests__/validators.test.d.ts +2 -0
- package/dist/commands/run/__tests__/validators.test.d.ts.map +1 -0
- package/dist/commands/run/__tests__/validators.test.js +80 -0
- package/dist/commands/run/__tests__/validators.test.js.map +1 -0
- package/dist/commands/run/execution.d.ts +14 -0
- package/dist/commands/run/execution.d.ts.map +1 -0
- package/dist/commands/run/execution.js +41 -0
- package/dist/commands/run/execution.js.map +1 -0
- package/dist/commands/run/index.d.ts +38 -0
- package/dist/commands/run/index.d.ts.map +1 -0
- package/dist/commands/run/index.js +154 -0
- package/dist/commands/run/index.js.map +1 -0
- package/dist/commands/run/types.d.ts +65 -0
- package/dist/commands/run/types.d.ts.map +1 -0
- package/dist/commands/run/types.js +7 -0
- package/dist/commands/run/types.js.map +1 -0
- package/dist/commands/run/utils.d.ts +29 -0
- package/dist/commands/run/utils.d.ts.map +1 -0
- package/dist/commands/run/utils.js +52 -0
- package/dist/commands/run/utils.js.map +1 -0
- package/dist/commands/run/validators.d.ts +33 -0
- package/dist/commands/run/validators.d.ts.map +1 -0
- package/dist/commands/run/validators.js +58 -0
- package/dist/commands/run/validators.js.map +1 -0
- package/dist/commands/simulate/env-loader.d.ts +19 -0
- package/dist/commands/simulate/env-loader.d.ts.map +1 -0
- package/dist/commands/simulate/env-loader.js +44 -0
- package/dist/commands/simulate/env-loader.js.map +1 -0
- package/dist/commands/simulate/index.d.ts +48 -0
- package/dist/commands/simulate/index.d.ts.map +1 -0
- package/dist/commands/simulate/index.js +113 -0
- package/dist/commands/simulate/index.js.map +1 -0
- package/dist/commands/simulate/jsdom-executor.d.ts +37 -0
- package/dist/commands/simulate/jsdom-executor.d.ts.map +1 -0
- package/dist/commands/simulate/jsdom-executor.js +137 -0
- package/dist/commands/simulate/jsdom-executor.js.map +1 -0
- package/dist/commands/simulate/node-executor.d.ts +28 -0
- package/dist/commands/simulate/node-executor.d.ts.map +1 -0
- package/dist/commands/simulate/node-executor.js +94 -0
- package/dist/commands/simulate/node-executor.js.map +1 -0
- package/dist/commands/simulate/simulator.d.ts +14 -0
- package/dist/commands/simulate/simulator.d.ts.map +1 -0
- package/dist/commands/simulate/simulator.js +163 -0
- package/dist/commands/simulate/simulator.js.map +1 -0
- package/dist/commands/simulate/tracker.d.ts +30 -0
- package/dist/commands/simulate/tracker.d.ts.map +1 -0
- package/dist/commands/simulate/tracker.js +96 -0
- package/dist/commands/simulate/tracker.js.map +1 -0
- package/dist/commands/simulate/types.d.ts +20 -0
- package/dist/commands/simulate/types.d.ts.map +1 -0
- package/dist/commands/simulate/types.js +2 -0
- package/dist/commands/simulate/types.js.map +1 -0
- package/dist/config/build-defaults.d.ts +49 -0
- package/dist/config/build-defaults.d.ts.map +1 -0
- package/dist/config/build-defaults.js +68 -0
- package/dist/config/build-defaults.js.map +1 -0
- package/dist/config/index.d.ts +13 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +15 -0
- package/dist/config/index.js.map +1 -0
- package/dist/config/loader.d.ts +81 -0
- package/dist/config/loader.d.ts.map +1 -0
- package/dist/config/loader.js +153 -0
- package/dist/config/loader.js.map +1 -0
- package/dist/config/utils.d.ts +101 -0
- package/dist/config/utils.d.ts.map +1 -0
- package/dist/config/utils.js +235 -0
- package/dist/config/utils.js.map +1 -0
- package/dist/config/validators.d.ts +52 -0
- package/dist/config/validators.d.ts.map +1 -0
- package/dist/config/validators.js +85 -0
- package/dist/config/validators.js.map +1 -0
- package/dist/core/asset-resolver.d.ts +34 -0
- package/dist/core/asset-resolver.d.ts.map +1 -0
- package/dist/core/asset-resolver.js +70 -0
- package/dist/core/asset-resolver.js.map +1 -0
- package/dist/core/build-cache.d.ts +23 -0
- package/dist/core/build-cache.d.ts.map +1 -0
- package/dist/core/build-cache.js +44 -0
- package/dist/core/build-cache.js.map +1 -0
- package/dist/core/cache-utils.d.ts +27 -0
- package/dist/core/cache-utils.d.ts.map +1 -0
- package/dist/core/cache-utils.js +60 -0
- package/dist/core/cache-utils.js.map +1 -0
- package/dist/core/index.d.ts +8 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +8 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/local-packages.d.ts +19 -0
- package/dist/core/local-packages.d.ts.map +1 -0
- package/dist/core/local-packages.js +60 -0
- package/dist/core/local-packages.js.map +1 -0
- package/dist/core/logger.d.ts +30 -0
- package/dist/core/logger.d.ts.map +1 -0
- package/dist/core/logger.js +85 -0
- package/dist/core/logger.js.map +1 -0
- package/dist/core/output.d.ts +30 -0
- package/dist/core/output.d.ts.map +1 -0
- package/dist/core/output.js +46 -0
- package/dist/core/output.js.map +1 -0
- package/dist/core/timer.d.ts +14 -0
- package/dist/core/timer.d.ts.map +1 -0
- package/dist/core/timer.js +29 -0
- package/dist/core/timer.js.map +1 -0
- package/dist/core/tmp.d.ts +27 -0
- package/dist/core/tmp.d.ts.map +1 -0
- package/dist/core/tmp.js +36 -0
- package/dist/core/tmp.js.map +1 -0
- package/dist/core/utils.d.ts +10 -0
- package/dist/core/utils.d.ts.map +1 -0
- package/dist/core/utils.js +12 -0
- package/dist/core/utils.js.map +1 -0
- package/dist/index.d.ts +20 -13
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +633 -761
- package/dist/index.js.map +1 -1
- package/dist/runtime/index.d.ts +10 -0
- package/dist/runtime/index.d.ts.map +1 -0
- package/dist/runtime/index.js +10 -0
- package/dist/runtime/index.js.map +1 -0
- package/dist/runtime/main.d.ts +2 -0
- package/dist/runtime/main.d.ts.map +1 -0
- package/dist/runtime/main.js +268 -0
- package/dist/runtime/main.js.map +1 -0
- package/dist/runtime/runner.d.ts +20 -0
- package/dist/runtime/runner.d.ts.map +1 -0
- package/dist/runtime/runner.js +72 -0
- package/dist/runtime/runner.js.map +1 -0
- package/dist/runtime/serve.d.ts +19 -0
- package/dist/runtime/serve.d.ts.map +1 -0
- package/dist/runtime/serve.js +97 -0
- package/dist/runtime/serve.js.map +1 -0
- package/dist/schemas/index.d.ts +9 -0
- package/dist/schemas/index.d.ts.map +1 -0
- package/dist/schemas/index.js +9 -0
- package/dist/schemas/index.js.map +1 -0
- package/dist/schemas/primitives.d.ts +37 -0
- package/dist/schemas/primitives.d.ts.map +1 -0
- package/dist/schemas/primitives.js +43 -0
- package/dist/schemas/primitives.js.map +1 -0
- package/dist/schemas/run.d.ts +23 -0
- package/dist/schemas/run.d.ts.map +1 -0
- package/dist/schemas/run.js +20 -0
- package/dist/schemas/run.js.map +1 -0
- package/dist/types/bundle.d.ts +141 -0
- package/dist/types/bundle.d.ts.map +1 -0
- package/dist/types/bundle.js +10 -0
- package/dist/types/bundle.js.map +1 -0
- package/dist/types/global.d.ts +38 -0
- package/dist/types/global.d.ts.map +1 -0
- package/dist/types/global.js +24 -0
- package/dist/types/global.js.map +1 -0
- package/dist/types/index.d.ts +8 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +8 -0
- package/dist/types/index.js.map +1 -0
- package/dist/version.d.ts +3 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +27 -0
- package/dist/version.js.map +1 -0
- package/dist/walker.js +1 -0
- package/package.json +7 -4
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration Utility Functions
|
|
3
|
+
*/
|
|
4
|
+
import fs from 'fs-extra';
|
|
5
|
+
import path from 'path';
|
|
6
|
+
import { getErrorMessage } from '../core/index.js';
|
|
7
|
+
import { getTmpPath } from '../core/tmp.js';
|
|
8
|
+
/**
|
|
9
|
+
* Check if a string is a valid URL
|
|
10
|
+
*
|
|
11
|
+
* @param str - String to check
|
|
12
|
+
* @returns True if string is a valid HTTP/HTTPS URL
|
|
13
|
+
*/
|
|
14
|
+
export function isUrl(str) {
|
|
15
|
+
try {
|
|
16
|
+
const url = new URL(str);
|
|
17
|
+
return url.protocol === 'http:' || url.protocol === 'https:';
|
|
18
|
+
}
|
|
19
|
+
catch {
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Download a file from a URL to a temporary location
|
|
25
|
+
*
|
|
26
|
+
* @param url - HTTP/HTTPS URL to download
|
|
27
|
+
* @returns Path to downloaded temporary file
|
|
28
|
+
* @throws Error if download fails or response is not OK
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```typescript
|
|
32
|
+
* const tempPath = await downloadFromUrl('https://example.com/config.json')
|
|
33
|
+
* // Returns: "/tmp/walkeros-download-1647261462000-abc123.json"
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export async function downloadFromUrl(url) {
|
|
37
|
+
if (!isUrl(url)) {
|
|
38
|
+
throw new Error(`Invalid URL: ${url}`);
|
|
39
|
+
}
|
|
40
|
+
try {
|
|
41
|
+
const response = await fetch(url);
|
|
42
|
+
if (!response.ok) {
|
|
43
|
+
throw new Error(`Failed to download ${url}: ${response.status} ${response.statusText}`);
|
|
44
|
+
}
|
|
45
|
+
const content = await response.text();
|
|
46
|
+
// Write to .tmp/downloads/ directory
|
|
47
|
+
const downloadsDir = getTmpPath(undefined, 'downloads');
|
|
48
|
+
await fs.ensureDir(downloadsDir);
|
|
49
|
+
// Use a consistent filename - always re-downloaded fresh anyway
|
|
50
|
+
const tempPath = path.join(downloadsDir, 'flow.json');
|
|
51
|
+
await fs.writeFile(tempPath, content, 'utf-8');
|
|
52
|
+
return tempPath;
|
|
53
|
+
}
|
|
54
|
+
catch (error) {
|
|
55
|
+
if (error instanceof Error) {
|
|
56
|
+
throw new Error(`Failed to download from URL: ${error.message}`);
|
|
57
|
+
}
|
|
58
|
+
throw error;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Substitute environment variables in a string.
|
|
63
|
+
*
|
|
64
|
+
* @param value - String with ${VAR} placeholders
|
|
65
|
+
* @returns String with environment variables substituted
|
|
66
|
+
* @throws Error if environment variable is not found
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```typescript
|
|
70
|
+
* substituteEnvVariables('${HOME}/config') // "/Users/name/config"
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
export function substituteEnvVariables(value) {
|
|
74
|
+
return value.replace(/\${([^}]+)}/g, (_, envVar) => {
|
|
75
|
+
const envValue = process.env[envVar];
|
|
76
|
+
if (!envValue) {
|
|
77
|
+
throw new Error(`Environment variable ${envVar} not found`);
|
|
78
|
+
}
|
|
79
|
+
return envValue;
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Load and parse JSON configuration file from local path or URL.
|
|
84
|
+
*
|
|
85
|
+
* @param configPath - Path to JSON file or HTTP/HTTPS URL
|
|
86
|
+
* @returns Parsed configuration object and cleanup function
|
|
87
|
+
* @throws Error if file not found, download fails, or invalid JSON
|
|
88
|
+
*
|
|
89
|
+
* @example
|
|
90
|
+
* ```typescript
|
|
91
|
+
* // Local file
|
|
92
|
+
* const config = await loadJsonConfig('./config.json')
|
|
93
|
+
*
|
|
94
|
+
* // Remote URL
|
|
95
|
+
* const config = await loadJsonConfig('https://example.com/config.json')
|
|
96
|
+
* ```
|
|
97
|
+
*/
|
|
98
|
+
export async function loadJsonConfig(configPath) {
|
|
99
|
+
let absolutePath;
|
|
100
|
+
let isTemporary = false;
|
|
101
|
+
// Check if input is a URL
|
|
102
|
+
if (isUrl(configPath)) {
|
|
103
|
+
// Download from URL to temp location
|
|
104
|
+
absolutePath = await downloadFromUrl(configPath);
|
|
105
|
+
isTemporary = true;
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
// Local file path
|
|
109
|
+
absolutePath = path.resolve(configPath);
|
|
110
|
+
if (!(await fs.pathExists(absolutePath))) {
|
|
111
|
+
throw new Error(`Configuration file not found: ${absolutePath}`);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
try {
|
|
115
|
+
const rawConfig = await fs.readJson(absolutePath);
|
|
116
|
+
return rawConfig;
|
|
117
|
+
}
|
|
118
|
+
catch (error) {
|
|
119
|
+
throw new Error(`Invalid JSON in config file: ${configPath}. ${error instanceof Error ? error.message : error}`);
|
|
120
|
+
}
|
|
121
|
+
finally {
|
|
122
|
+
// Clean up temporary downloaded file
|
|
123
|
+
if (isTemporary) {
|
|
124
|
+
try {
|
|
125
|
+
await fs.remove(absolutePath);
|
|
126
|
+
}
|
|
127
|
+
catch {
|
|
128
|
+
// Ignore cleanup errors
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Load JSON from inline string, file path, or URL.
|
|
135
|
+
*
|
|
136
|
+
* Supports three input formats:
|
|
137
|
+
* 1. Inline JSON string - parsed directly
|
|
138
|
+
* 2. Local file path - read and parsed
|
|
139
|
+
* 3. HTTP/HTTPS URL - downloaded and parsed
|
|
140
|
+
*
|
|
141
|
+
* Detection priority:
|
|
142
|
+
* 1. URL (http://, https://) → download and parse
|
|
143
|
+
* 2. Existing file path → read and parse
|
|
144
|
+
* 3. Valid JSON string → parse directly
|
|
145
|
+
* 4. Simple string → treat as {name: string} for backward compatibility
|
|
146
|
+
*
|
|
147
|
+
* @param source - JSON string, file path, or URL
|
|
148
|
+
* @param options - Optional configuration
|
|
149
|
+
* @param options.name - Parameter name for error messages (e.g., "event", "config")
|
|
150
|
+
* @param options.required - Throw error if source is empty (default: false)
|
|
151
|
+
* @param options.fallback - Default value if source is empty
|
|
152
|
+
* @returns Parsed JSON object
|
|
153
|
+
* @throws Error if source is required but empty, or if loading/parsing fails
|
|
154
|
+
*
|
|
155
|
+
* @example
|
|
156
|
+
* ```typescript
|
|
157
|
+
* // Inline JSON
|
|
158
|
+
* await loadJsonFromSource('{"name":"order complete","data":{}}')
|
|
159
|
+
*
|
|
160
|
+
* // File path
|
|
161
|
+
* await loadJsonFromSource('./examples/event.json')
|
|
162
|
+
*
|
|
163
|
+
* // URL
|
|
164
|
+
* await loadJsonFromSource('https://example.com/event.json')
|
|
165
|
+
*
|
|
166
|
+
* // With options
|
|
167
|
+
* await loadJsonFromSource(input, {
|
|
168
|
+
* name: 'event',
|
|
169
|
+
* required: true,
|
|
170
|
+
* fallback: { name: 'default' }
|
|
171
|
+
* })
|
|
172
|
+
* ```
|
|
173
|
+
*/
|
|
174
|
+
export async function loadJsonFromSource(source, options) {
|
|
175
|
+
const paramName = options?.name || 'input';
|
|
176
|
+
// Handle empty/undefined input
|
|
177
|
+
if (!source || source.trim() === '') {
|
|
178
|
+
if (options?.required) {
|
|
179
|
+
throw new Error(`${paramName} is required`);
|
|
180
|
+
}
|
|
181
|
+
if (options?.fallback !== undefined) {
|
|
182
|
+
return options.fallback;
|
|
183
|
+
}
|
|
184
|
+
return {};
|
|
185
|
+
}
|
|
186
|
+
const trimmedSource = source.trim();
|
|
187
|
+
// 1. Check if URL
|
|
188
|
+
if (isUrl(trimmedSource)) {
|
|
189
|
+
try {
|
|
190
|
+
const tempPath = await downloadFromUrl(trimmedSource);
|
|
191
|
+
try {
|
|
192
|
+
const data = await fs.readJson(tempPath);
|
|
193
|
+
return data;
|
|
194
|
+
}
|
|
195
|
+
finally {
|
|
196
|
+
// Clean up temp file
|
|
197
|
+
try {
|
|
198
|
+
await fs.remove(tempPath);
|
|
199
|
+
}
|
|
200
|
+
catch {
|
|
201
|
+
// Ignore cleanup errors
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
catch (error) {
|
|
206
|
+
throw new Error(`Failed to load ${paramName} from URL ${trimmedSource}: ${getErrorMessage(error)}`);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
// 2. Check if file path exists
|
|
210
|
+
const resolvedPath = path.resolve(trimmedSource);
|
|
211
|
+
if (await fs.pathExists(resolvedPath)) {
|
|
212
|
+
try {
|
|
213
|
+
const data = await fs.readJson(resolvedPath);
|
|
214
|
+
return data;
|
|
215
|
+
}
|
|
216
|
+
catch (error) {
|
|
217
|
+
throw new Error(`Failed to parse ${paramName} from file ${trimmedSource}: ${getErrorMessage(error)}`);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
// 3. Try to parse as inline JSON
|
|
221
|
+
try {
|
|
222
|
+
const parsed = JSON.parse(trimmedSource);
|
|
223
|
+
return parsed;
|
|
224
|
+
}
|
|
225
|
+
catch (jsonError) {
|
|
226
|
+
// 4. Fallback: treat as event name string for backward compatibility
|
|
227
|
+
// This allows simple strings like "page view" to work
|
|
228
|
+
if (!trimmedSource.startsWith('{') && !trimmedSource.startsWith('[')) {
|
|
229
|
+
return { name: trimmedSource };
|
|
230
|
+
}
|
|
231
|
+
// If it looks like JSON but failed to parse, throw helpful error
|
|
232
|
+
throw new Error(`Failed to parse ${paramName}. Input appears to be JSON but contains errors: ${jsonError instanceof Error ? jsonError.message : String(jsonError)}`);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/config/utils.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,MAAM,UAAU,CAAC;AAC1B,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAE5C;;;;;GAKG;AACH,MAAM,UAAU,KAAK,CAAC,GAAW;IAC/B,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC;QACzB,OAAO,GAAG,CAAC,QAAQ,KAAK,OAAO,IAAI,GAAG,CAAC,QAAQ,KAAK,QAAQ,CAAC;IAC/D,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,GAAW;IAC/C,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC;QAChB,MAAM,IAAI,KAAK,CAAC,gBAAgB,GAAG,EAAE,CAAC,CAAC;IACzC,CAAC;IAED,IAA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;YACH,MAAM,IAAI,GAAG,MAAM,EAAE,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC;YAC7C,OAAO,IAAS,CAAC;QACnB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,IAAI,KAAK,CACb,mBAAmB,SAAS,cAAc,aAAa,KAAK,eAAe,CAAC,KAAK,CAAC,EAAE,CACrF,CAAC;QACJ,CAAC;IACH,CAAC;IAED,iCAAiC;IACjC,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC;QACzC,OAAO,MAAW,CAAC;IACrB,CAAC;IAAC,OAAO,SAAS,EAAE,CAAC;QACnB,qEAAqE;QACrE,sDAAsD;QACtD,IAAI,CAAC,aAAa,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,aAAa,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;YACrE,OAAO,EAAE,IAAI,EAAE,aAAa,EAAO,CAAC;QACtC,CAAC;QAED,iEAAiE;QACjE,MAAM,IAAI,KAAK,CACb,mBAAmB,SAAS,mDAAmD,SAAS,YAAY,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,EAAE,CACpJ,CAAC;IACJ,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration Type Guards and Validators
|
|
3
|
+
*
|
|
4
|
+
* Type checking utilities for configuration validation.
|
|
5
|
+
* Uses Zod schemas from @walkeros/core for Flow.Setup validation.
|
|
6
|
+
*/
|
|
7
|
+
import type { Flow } from '@walkeros/core';
|
|
8
|
+
/**
|
|
9
|
+
* Type guard: Check if value is a plain object.
|
|
10
|
+
*/
|
|
11
|
+
export declare function isObject(value: unknown): value is Record<string, unknown>;
|
|
12
|
+
/**
|
|
13
|
+
* Detect platform from flow config.
|
|
14
|
+
*
|
|
15
|
+
* Platform is determined by the presence of `web` or `server` key.
|
|
16
|
+
*/
|
|
17
|
+
export declare function detectPlatform(flowConfig: Record<string, unknown>): 'web' | 'server' | undefined;
|
|
18
|
+
/**
|
|
19
|
+
* Type guard: Check if config is a valid Flow.Setup structure.
|
|
20
|
+
*
|
|
21
|
+
* @remarks
|
|
22
|
+
* Uses Zod validation from @walkeros/core.
|
|
23
|
+
* Returns false instead of throwing on invalid input.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```typescript
|
|
27
|
+
* if (isFlowSetup(config)) {
|
|
28
|
+
* const flowConfig = getFlowConfig(config, 'production');
|
|
29
|
+
* }
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export declare function isFlowSetup(data: unknown): data is Flow.Setup;
|
|
33
|
+
/**
|
|
34
|
+
* Validate Flow.Setup and throw descriptive error if invalid.
|
|
35
|
+
*
|
|
36
|
+
* @remarks
|
|
37
|
+
* Uses Zod validation from @walkeros/core.
|
|
38
|
+
* Provides detailed error messages from Zod.
|
|
39
|
+
*
|
|
40
|
+
* @param data - Raw configuration data
|
|
41
|
+
* @returns Validated Flow.Setup
|
|
42
|
+
* @throws Error with descriptive message if validation fails
|
|
43
|
+
*/
|
|
44
|
+
export declare function validateFlowSetup(data: unknown): Flow.Setup;
|
|
45
|
+
/**
|
|
46
|
+
* Get available flow names from a Flow.Setup.
|
|
47
|
+
*
|
|
48
|
+
* @param setup - Flow.Setup configuration
|
|
49
|
+
* @returns Array of flow names
|
|
50
|
+
*/
|
|
51
|
+
export declare function getAvailableFlows(setup: Flow.Setup): string[];
|
|
52
|
+
//# sourceMappingURL=validators.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validators.d.ts","sourceRoot":"","sources":["../../src/config/validators.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAK3C;;GAEG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAOzE;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAC5B,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAClC,KAAK,GAAG,QAAQ,GAAG,SAAS,CAQ9B;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,IAAI,IAAI,CAAC,KAAK,CAG7D;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,CAAC,KAAK,CAkB3D;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,GAAG,MAAM,EAAE,CAE7D"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration Type Guards and Validators
|
|
3
|
+
*
|
|
4
|
+
* Type checking utilities for configuration validation.
|
|
5
|
+
* Uses Zod schemas from @walkeros/core for Flow.Setup validation.
|
|
6
|
+
*/
|
|
7
|
+
import { schemas } from '@walkeros/core/dev';
|
|
8
|
+
const { safeParseSetup } = schemas;
|
|
9
|
+
/**
|
|
10
|
+
* Type guard: Check if value is a plain object.
|
|
11
|
+
*/
|
|
12
|
+
export function isObject(value) {
|
|
13
|
+
return (typeof value === 'object' &&
|
|
14
|
+
value !== null &&
|
|
15
|
+
!Array.isArray(value) &&
|
|
16
|
+
Object.prototype.toString.call(value) === '[object Object]');
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Detect platform from flow config.
|
|
20
|
+
*
|
|
21
|
+
* Platform is determined by the presence of `web` or `server` key.
|
|
22
|
+
*/
|
|
23
|
+
export function detectPlatform(flowConfig) {
|
|
24
|
+
if ('web' in flowConfig && flowConfig.web !== undefined) {
|
|
25
|
+
return 'web';
|
|
26
|
+
}
|
|
27
|
+
if ('server' in flowConfig && flowConfig.server !== undefined) {
|
|
28
|
+
return 'server';
|
|
29
|
+
}
|
|
30
|
+
return undefined;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Type guard: Check if config is a valid Flow.Setup structure.
|
|
34
|
+
*
|
|
35
|
+
* @remarks
|
|
36
|
+
* Uses Zod validation from @walkeros/core.
|
|
37
|
+
* Returns false instead of throwing on invalid input.
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```typescript
|
|
41
|
+
* if (isFlowSetup(config)) {
|
|
42
|
+
* const flowConfig = getFlowConfig(config, 'production');
|
|
43
|
+
* }
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
export function isFlowSetup(data) {
|
|
47
|
+
const result = safeParseSetup(data);
|
|
48
|
+
return result.success;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Validate Flow.Setup and throw descriptive error if invalid.
|
|
52
|
+
*
|
|
53
|
+
* @remarks
|
|
54
|
+
* Uses Zod validation from @walkeros/core.
|
|
55
|
+
* Provides detailed error messages from Zod.
|
|
56
|
+
*
|
|
57
|
+
* @param data - Raw configuration data
|
|
58
|
+
* @returns Validated Flow.Setup
|
|
59
|
+
* @throws Error with descriptive message if validation fails
|
|
60
|
+
*/
|
|
61
|
+
export function validateFlowSetup(data) {
|
|
62
|
+
const result = safeParseSetup(data);
|
|
63
|
+
if (!result.success) {
|
|
64
|
+
// Format Zod errors for CLI display
|
|
65
|
+
const errors = result.error.issues
|
|
66
|
+
.map((issue) => {
|
|
67
|
+
const path = issue.path.length > 0 ? issue.path.map(String).join('.') : 'root';
|
|
68
|
+
return ` - ${path}: ${issue.message}`;
|
|
69
|
+
})
|
|
70
|
+
.join('\n');
|
|
71
|
+
throw new Error(`Invalid configuration:\n${errors}`);
|
|
72
|
+
}
|
|
73
|
+
// Cast to Flow.Setup since Zod's inferred type is compatible but not identical
|
|
74
|
+
return result.data;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Get available flow names from a Flow.Setup.
|
|
78
|
+
*
|
|
79
|
+
* @param setup - Flow.Setup configuration
|
|
80
|
+
* @returns Array of flow names
|
|
81
|
+
*/
|
|
82
|
+
export function getAvailableFlows(setup) {
|
|
83
|
+
return Object.keys(setup.flows);
|
|
84
|
+
}
|
|
85
|
+
//# sourceMappingURL=validators.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validators.js","sourceRoot":"","sources":["../../src/config/validators.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAE7C,MAAM,EAAE,cAAc,EAAE,GAAG,OAAO,CAAC;AAEnC;;GAEG;AACH,MAAM,UAAU,QAAQ,CAAC,KAAc;IACrC,OAAO,CACL,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,KAAK,IAAI;QACd,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QACrB,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,iBAAiB,CAC5D,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,cAAc,CAC5B,UAAmC;IAEnC,IAAI,KAAK,IAAI,UAAU,IAAI,UAAU,CAAC,GAAG,KAAK,SAAS,EAAE,CAAC;QACxD,OAAO,KAAK,CAAC;IACf,CAAC;IACD,IAAI,QAAQ,IAAI,UAAU,IAAI,UAAU,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;QAC9D,OAAO,QAAQ,CAAC;IAClB,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,WAAW,CAAC,IAAa;IACvC,MAAM,MAAM,GAAG,cAAc,CAAC,IAAI,CAAC,CAAC;IACpC,OAAO,MAAM,CAAC,OAAO,CAAC;AACxB,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,iBAAiB,CAAC,IAAa;IAC7C,MAAM,MAAM,GAAG,cAAc,CAAC,IAAI,CAAC,CAAC;IAEpC,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;QACpB,oCAAoC;QACpC,MAAM,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,MAAM;aAC/B,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE;YACb,MAAM,IAAI,GACR,KAAK,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;YACpE,OAAO,OAAO,IAAI,KAAK,KAAK,CAAC,OAAO,EAAE,CAAC;QACzC,CAAC,CAAC;aACD,IAAI,CAAC,IAAI,CAAC,CAAC;QAEd,MAAM,IAAI,KAAK,CAAC,2BAA2B,MAAM,EAAE,CAAC,CAAC;IACvD,CAAC;IAED,+EAA+E;IAC/E,OAAO,MAAM,CAAC,IAAkB,CAAC;AACnC,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB,CAAC,KAAiB;IACjD,OAAO,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;AAClC,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Asset Resolver
|
|
3
|
+
*
|
|
4
|
+
* Unified path resolution for package assets (examples) and user assets.
|
|
5
|
+
* Assets are always siblings to the CLI entry point (in dist/ for production).
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Get the directory containing CLI assets (examples).
|
|
9
|
+
*
|
|
10
|
+
* In production: assets are in dist/ alongside the bundled CLI
|
|
11
|
+
* In development: assets are at package root
|
|
12
|
+
*
|
|
13
|
+
* @returns Absolute path to assets directory
|
|
14
|
+
*/
|
|
15
|
+
export declare function getAssetDir(): string;
|
|
16
|
+
/**
|
|
17
|
+
* Asset type for resolution strategy
|
|
18
|
+
*/
|
|
19
|
+
export type AssetType = 'config' | 'bundle';
|
|
20
|
+
/**
|
|
21
|
+
* Resolve asset path using unified strategy
|
|
22
|
+
*
|
|
23
|
+
* Resolution rules:
|
|
24
|
+
* 1. Bare names (no / or \) → Package asset (examples)
|
|
25
|
+
* 2. Relative paths (./ or ../) → User asset relative to base directory
|
|
26
|
+
* 3. Absolute paths → Use as-is
|
|
27
|
+
*
|
|
28
|
+
* @param assetPath - Path to resolve
|
|
29
|
+
* @param assetType - Type of asset (determines package subdirectory)
|
|
30
|
+
* @param baseDir - Base directory for relative paths (defaults to cwd)
|
|
31
|
+
* @returns Absolute path to asset
|
|
32
|
+
*/
|
|
33
|
+
export declare function resolveAsset(assetPath: string, assetType: AssetType, baseDir?: string): string;
|
|
34
|
+
//# sourceMappingURL=asset-resolver.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"asset-resolver.d.ts","sourceRoot":"","sources":["../../src/core/asset-resolver.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAYH;;;;;;;GAOG;AACH,wBAAgB,WAAW,IAAI,MAAM,CAkBpC;AAED;;GAEG;AACH,MAAM,MAAM,SAAS,GAAG,QAAQ,GAAG,QAAQ,CAAC;AAE5C;;;;;;;;;;;;GAYG;AACH,wBAAgB,YAAY,CAC1B,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,SAAS,EACpB,OAAO,CAAC,EAAE,MAAM,GACf,MAAM,CAmBR"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Asset Resolver
|
|
3
|
+
*
|
|
4
|
+
* Unified path resolution for package assets (examples) and user assets.
|
|
5
|
+
* Assets are always siblings to the CLI entry point (in dist/ for production).
|
|
6
|
+
*/
|
|
7
|
+
import { fileURLToPath } from 'url';
|
|
8
|
+
import { existsSync } from 'fs';
|
|
9
|
+
import path from 'path';
|
|
10
|
+
import { isUrl } from '../config/utils.js';
|
|
11
|
+
/**
|
|
12
|
+
* Cached asset directory to avoid repeated filesystem checks
|
|
13
|
+
*/
|
|
14
|
+
let cachedAssetDir;
|
|
15
|
+
/**
|
|
16
|
+
* Get the directory containing CLI assets (examples).
|
|
17
|
+
*
|
|
18
|
+
* In production: assets are in dist/ alongside the bundled CLI
|
|
19
|
+
* In development: assets are at package root
|
|
20
|
+
*
|
|
21
|
+
* @returns Absolute path to assets directory
|
|
22
|
+
*/
|
|
23
|
+
export function getAssetDir() {
|
|
24
|
+
if (cachedAssetDir)
|
|
25
|
+
return cachedAssetDir;
|
|
26
|
+
const currentFile = fileURLToPath(import.meta.url);
|
|
27
|
+
let dir = path.dirname(currentFile);
|
|
28
|
+
// Walk up until we find a directory with examples/ sibling
|
|
29
|
+
while (dir !== path.dirname(dir)) {
|
|
30
|
+
if (existsSync(path.join(dir, 'examples'))) {
|
|
31
|
+
cachedAssetDir = dir;
|
|
32
|
+
return dir;
|
|
33
|
+
}
|
|
34
|
+
dir = path.dirname(dir);
|
|
35
|
+
}
|
|
36
|
+
// Fallback to current file's directory (shouldn't happen if build is correct)
|
|
37
|
+
cachedAssetDir = path.dirname(currentFile);
|
|
38
|
+
return cachedAssetDir;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Resolve asset path using unified strategy
|
|
42
|
+
*
|
|
43
|
+
* Resolution rules:
|
|
44
|
+
* 1. Bare names (no / or \) → Package asset (examples)
|
|
45
|
+
* 2. Relative paths (./ or ../) → User asset relative to base directory
|
|
46
|
+
* 3. Absolute paths → Use as-is
|
|
47
|
+
*
|
|
48
|
+
* @param assetPath - Path to resolve
|
|
49
|
+
* @param assetType - Type of asset (determines package subdirectory)
|
|
50
|
+
* @param baseDir - Base directory for relative paths (defaults to cwd)
|
|
51
|
+
* @returns Absolute path to asset
|
|
52
|
+
*/
|
|
53
|
+
export function resolveAsset(assetPath, assetType, baseDir) {
|
|
54
|
+
// URL → pass through unchanged
|
|
55
|
+
if (isUrl(assetPath)) {
|
|
56
|
+
return assetPath;
|
|
57
|
+
}
|
|
58
|
+
// Bare name → package asset (examples directory)
|
|
59
|
+
if (!assetPath.includes('/') && !assetPath.includes('\\')) {
|
|
60
|
+
const assetDir = getAssetDir();
|
|
61
|
+
return path.join(assetDir, 'examples', assetPath);
|
|
62
|
+
}
|
|
63
|
+
// Absolute path → use as-is
|
|
64
|
+
if (path.isAbsolute(assetPath)) {
|
|
65
|
+
return assetPath;
|
|
66
|
+
}
|
|
67
|
+
// Relative path → resolve from base directory
|
|
68
|
+
return path.resolve(baseDir || process.cwd(), assetPath);
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=asset-resolver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"asset-resolver.js","sourceRoot":"","sources":["../../src/core/asset-resolver.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,MAAM,IAAI,CAAC;AAChC,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAE3C;;GAEG;AACH,IAAI,cAAkC,CAAC;AAEvC;;;;;;;GAOG;AACH,MAAM,UAAU,WAAW;IACzB,IAAI,cAAc;QAAE,OAAO,cAAc,CAAC;IAE1C,MAAM,WAAW,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACnD,IAAI,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;IAEpC,2DAA2D;IAC3D,OAAO,GAAG,KAAK,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;QACjC,IAAI,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,UAAU,CAAC,CAAC,EAAE,CAAC;YAC3C,cAAc,GAAG,GAAG,CAAC;YACrB,OAAO,GAAG,CAAC;QACb,CAAC;QACD,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAC1B,CAAC;IAED,8EAA8E;IAC9E,cAAc,GAAG,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;IAC3C,OAAO,cAAc,CAAC;AACxB,CAAC;AAOD;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,YAAY,CAC1B,SAAiB,EACjB,SAAoB,EACpB,OAAgB;IAEhB,+BAA+B;IAC/B,IAAI,KAAK,CAAC,SAAS,CAAC,EAAE,CAAC;QACrB,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,iDAAiD;IACjD,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;QAC1D,MAAM,QAAQ,GAAG,WAAW,EAAE,CAAC;QAC/B,OAAO,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,UAAU,EAAE,SAAS,CAAC,CAAC;IACpD,CAAC;IAED,4BAA4B;IAC5B,IAAI,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE,CAAC;QAC/B,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,8CAA8C;IAC9C,OAAO,IAAI,CAAC,OAAO,CAAC,OAAO,IAAI,OAAO,CAAC,GAAG,EAAE,EAAE,SAAS,CAAC,CAAC;AAC3D,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Build artifact cache for flow.json configurations
|
|
3
|
+
*
|
|
4
|
+
* Caches compiled bundles based on configuration content + date.
|
|
5
|
+
* Enables intelligent cache reuse with daily rebuild guarantee.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Get the cache file path for a flow.json configuration
|
|
9
|
+
*/
|
|
10
|
+
export declare function getBuildCachePath(configContent: string, tmpDir?: string): Promise<string>;
|
|
11
|
+
/**
|
|
12
|
+
* Check if a cached build exists for the given configuration
|
|
13
|
+
*/
|
|
14
|
+
export declare function isBuildCached(configContent: string, tmpDir?: string): Promise<boolean>;
|
|
15
|
+
/**
|
|
16
|
+
* Store a build artifact in the cache
|
|
17
|
+
*/
|
|
18
|
+
export declare function cacheBuild(configContent: string, buildOutput: string, tmpDir?: string): Promise<void>;
|
|
19
|
+
/**
|
|
20
|
+
* Retrieve a cached build artifact
|
|
21
|
+
*/
|
|
22
|
+
export declare function getCachedBuild(configContent: string, tmpDir?: string): Promise<string | null>;
|
|
23
|
+
//# sourceMappingURL=build-cache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build-cache.d.ts","sourceRoot":"","sources":["../../src/core/build-cache.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAOH;;GAEG;AACH,wBAAsB,iBAAiB,CACrC,aAAa,EAAE,MAAM,EACrB,MAAM,CAAC,EAAE,MAAM,GACd,OAAO,CAAC,MAAM,CAAC,CAIjB;AAED;;GAEG;AACH,wBAAsB,aAAa,CACjC,aAAa,EAAE,MAAM,EACrB,MAAM,CAAC,EAAE,MAAM,GACd,OAAO,CAAC,OAAO,CAAC,CAGlB;AAED;;GAEG;AACH,wBAAsB,UAAU,CAC9B,aAAa,EAAE,MAAM,EACrB,WAAW,EAAE,MAAM,EACnB,MAAM,CAAC,EAAE,MAAM,GACd,OAAO,CAAC,IAAI,CAAC,CAIf;AAED;;GAEG;AACH,wBAAsB,cAAc,CAClC,aAAa,EAAE,MAAM,EACrB,MAAM,CAAC,EAAE,MAAM,GACd,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAQxB"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Build artifact cache for flow.json configurations
|
|
3
|
+
*
|
|
4
|
+
* Caches compiled bundles based on configuration content + date.
|
|
5
|
+
* Enables intelligent cache reuse with daily rebuild guarantee.
|
|
6
|
+
*/
|
|
7
|
+
import fs from 'fs-extra';
|
|
8
|
+
import path from 'path';
|
|
9
|
+
import { getFlowConfigCacheKey } from './cache-utils.js';
|
|
10
|
+
import { getTmpPath } from './tmp.js';
|
|
11
|
+
/**
|
|
12
|
+
* Get the cache file path for a flow.json configuration
|
|
13
|
+
*/
|
|
14
|
+
export async function getBuildCachePath(configContent, tmpDir) {
|
|
15
|
+
const cacheDir = getTmpPath(tmpDir, 'cache', 'builds');
|
|
16
|
+
const cacheKey = await getFlowConfigCacheKey(configContent);
|
|
17
|
+
return path.join(cacheDir, `${cacheKey}.js`);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Check if a cached build exists for the given configuration
|
|
21
|
+
*/
|
|
22
|
+
export async function isBuildCached(configContent, tmpDir) {
|
|
23
|
+
const cachePath = await getBuildCachePath(configContent, tmpDir);
|
|
24
|
+
return fs.pathExists(cachePath);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Store a build artifact in the cache
|
|
28
|
+
*/
|
|
29
|
+
export async function cacheBuild(configContent, buildOutput, tmpDir) {
|
|
30
|
+
const cachePath = await getBuildCachePath(configContent, tmpDir);
|
|
31
|
+
await fs.ensureDir(path.dirname(cachePath));
|
|
32
|
+
await fs.writeFile(cachePath, buildOutput, 'utf-8');
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Retrieve a cached build artifact
|
|
36
|
+
*/
|
|
37
|
+
export async function getCachedBuild(configContent, tmpDir) {
|
|
38
|
+
const cachePath = await getBuildCachePath(configContent, tmpDir);
|
|
39
|
+
if (await fs.pathExists(cachePath)) {
|
|
40
|
+
return await fs.readFile(cachePath, 'utf-8');
|
|
41
|
+
}
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=build-cache.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build-cache.js","sourceRoot":"","sources":["../../src/core/build-cache.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,E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AE,CAAC;QACnC,OAAO,MAAM,EAAE,CAAC,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;IAC/C,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cache utility functions for hash-based cache keys
|
|
3
|
+
*
|
|
4
|
+
* Implements content-based and date-based cache invalidation for:
|
|
5
|
+
* - NPM package cache (mutable versions include daily date)
|
|
6
|
+
* - Build artifact cache (content + date hashing)
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Check if a version specifier is mutable (can change over time)
|
|
10
|
+
*/
|
|
11
|
+
export declare function isMutableVersion(version: string): boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Get today's date in YYYY-MM-DD format
|
|
14
|
+
*/
|
|
15
|
+
export declare function getTodayDate(): string;
|
|
16
|
+
/**
|
|
17
|
+
* Generate cache key for npm package.
|
|
18
|
+
* Mutable versions include date for daily invalidation.
|
|
19
|
+
* Exact versions are cached indefinitely.
|
|
20
|
+
*/
|
|
21
|
+
export declare function getPackageCacheKey(packageName: string, version: string, date?: string): Promise<string>;
|
|
22
|
+
/**
|
|
23
|
+
* Generate cache key for flow.json configuration.
|
|
24
|
+
* Includes date for daily rebuild guarantee.
|
|
25
|
+
*/
|
|
26
|
+
export declare function getFlowConfigCacheKey(content: string, date?: string): Promise<string>;
|
|
27
|
+
//# sourceMappingURL=cache-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache-utils.d.ts","sourceRoot":"","sources":["../../src/core/cache-utils.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAMH;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAQzD;AAED;;GAEG;AACH,wBAAgB,YAAY,IAAI,MAAM,CAErC;AAED;;;;GAIG;AACH,wBAAsB,kBAAkB,CACtC,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,MAAM,EACf,IAAI,CAAC,EAAE,MAAM,GACZ,OAAO,CAAC,MAAM,CAAC,CAYjB;AAWD;;;GAGG;AACH,wBAAsB,qBAAqB,CACzC,OAAO,EAAE,MAAM,EACf,IAAI,CAAC,EAAE,MAAM,GACZ,OAAO,CAAC,MAAM,CAAC,CAKjB"}
|