Skip to content

Commit f052d76

Browse files
http support
1 parent 241fbfe commit f052d76

File tree

4 files changed

+46
-40
lines changed

4 files changed

+46
-40
lines changed

packages/cli/src/commands/push/index.ts

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,7 @@ import {
88
getErrorMessage,
99
type Logger,
1010
} from '../../core/index.js';
11-
import {
12-
loadJsonConfig,
13-
loadJsonFromSource,
14-
loadBundleConfig,
15-
} from '../../config/index.js';
11+
import { loadFlowConfig, loadJsonFromSource } from '../../config/index.js';
1612
import { bundleCore } from '../bundle/bundler.js';
1713
import type { PushCommandOptions, PushResult } from './types.js';
1814

@@ -62,20 +58,17 @@ export async function pushCommand(options: PushCommandOptions): Promise<void> {
6258

6359
// Step 2: Load config
6460
logger.debug('Loading flow configuration');
65-
const configPath = path.resolve(options.config);
66-
const rawConfig = await loadJsonConfig(configPath);
67-
const { flowConfig, buildOptions, flowName, isMultiFlow } =
68-
loadBundleConfig(rawConfig, {
69-
configPath: options.config,
70-
flowName: options.flow,
71-
logger,
72-
});
61+
const { flowConfig, buildOptions } = await loadFlowConfig(options.config, {
62+
flowName: options.flow,
63+
logger,
64+
});
7365

7466
const platform = getPlatform(flowConfig);
7567

7668
// Step 3: Bundle to temp file in config directory (so Node.js can find node_modules)
7769
logger.debug('Bundling flow configuration');
78-
const configDir = path.dirname(configPath);
70+
// buildOptions.configDir already handles URLs (uses cwd) vs local paths
71+
const configDir = buildOptions.configDir || process.cwd();
7972
const tempDir = path.join(
8073
configDir,
8174
'.tmp',

packages/cli/src/commands/simulate/simulator.ts

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ import type { Flow } from '@walkeros/core';
44
import { getPlatform } from '@walkeros/core';
55
import { createLogger, getErrorMessage } from '../../core/index.js';
66
import {
7-
loadJsonConfig,
8-
loadBundleConfig,
7+
loadFlowConfig,
98
isObject,
109
type BuildOptions,
1110
} from '../../config/index.js';
@@ -39,29 +38,17 @@ export async function simulateCore(
3938
});
4039

4140
try {
42-
logger.info('🎯 Starting walkerOS simulation...');
43-
4441
// Load and validate configuration
45-
logger.info('📦 Loading bundle configuration...');
46-
const fullConfigPath = path.resolve(configPath);
47-
const rawConfig = await loadJsonConfig(fullConfigPath);
48-
loadBundleConfig(rawConfig, { configPath: fullConfigPath });
42+
logger.debug('Loading configuration');
43+
await loadFlowConfig(configPath);
4944

5045
// Execute simulation
51-
logger.info(`🚀 Executing simulation with event: ${JSON.stringify(event)}`);
52-
const result = await executeSimulation(event, fullConfigPath);
53-
54-
// Report results
55-
if (result.success) {
56-
logger.info(`✅ Simulation completed successfully`);
57-
} else {
58-
logger.error(`❌ Simulation failed: ${result.error}`);
59-
}
46+
logger.debug(`Simulating event: ${JSON.stringify(event)}`);
47+
const result = await executeSimulation(event, configPath);
6048

6149
return result;
6250
} catch (error) {
6351
const errorMessage = getErrorMessage(error);
64-
logger.error(`💥 Simulation error: ${errorMessage}`);
6552

6653
return {
6754
success: false,
@@ -87,9 +74,9 @@ export function formatSimulationResult(
8774
}
8875

8976
if (result.success) {
90-
return 'Simulation completed successfully';
77+
return 'Simulation completed';
9178
} else {
92-
return `Simulation failed: ${result.error}`;
79+
return `Simulation failed: ${result.error}`;
9380
}
9481
}
9582

@@ -122,10 +109,7 @@ export async function executeSimulation(
122109
await fs.ensureDir(tempDir);
123110

124111
// 1. Load config
125-
const rawConfig = await loadJsonConfig(configPath);
126-
const { flowConfig, buildOptions } = loadBundleConfig(rawConfig, {
127-
configPath,
128-
});
112+
const { flowConfig, buildOptions } = await loadFlowConfig(configPath);
129113

130114
// Detect platform from flowConfig
131115
const platform = getPlatform(flowConfig);

packages/cli/src/config/index.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,12 @@ export {
3232
} from './utils.js';
3333

3434
// Loader
35-
export { loadBundleConfig, loadAllFlows, getAvailableFlows } from './loader.js';
35+
export {
36+
loadBundleConfig,
37+
loadAllFlows,
38+
getAvailableFlows,
39+
loadFlowConfig,
40+
} from './loader.js';
3641
export type { LoadConfigResult, LoadConfigOptions } from './loader.js';
3742

3843
// Type re-exports

packages/cli/src/config/loader.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
getAvailableFlows as getFlowNames,
1616
} from './validators.js';
1717
import { getBuildDefaults, getDefaultOutput } from './build-defaults.js';
18-
import { isUrl } from './utils.js';
18+
import { isUrl, loadJsonConfig } from './utils.js';
1919

2020
/** Default folder for includes if it exists */
2121
const DEFAULT_INCLUDE_FOLDER = './shared';
@@ -232,3 +232,27 @@ export function getAvailableFlows(rawConfig: unknown): string[] {
232232
}
233233
return [];
234234
}
235+
236+
/**
237+
* Load flow configuration from file or URL.
238+
*
239+
* Single entry point for all commands (bundle, simulate, push).
240+
* Handles URL vs local path detection automatically.
241+
*
242+
* @param configPath - Path to config file or URL
243+
* @param options - Loading options (flowName, logger, buildOverrides)
244+
* @returns Parsed configuration with flow and build options
245+
*
246+
* @example
247+
* ```typescript
248+
* const { flowConfig, buildOptions } = await loadFlowConfig('./flow.json');
249+
* const { flowConfig } = await loadFlowConfig('https://example.com/flow.json');
250+
* ```
251+
*/
252+
export async function loadFlowConfig(
253+
configPath: string,
254+
options?: Omit<LoadConfigOptions, 'configPath'>,
255+
): Promise<LoadConfigResult> {
256+
const rawConfig = await loadJsonConfig(configPath);
257+
return loadBundleConfig(rawConfig, { configPath, ...options });
258+
}

0 commit comments

Comments
 (0)