@walkeros/cli 0.4.1 → 0.4.2
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 +13 -0
- package/README.md +112 -42
- package/dist/__tests__/bundle/bundler.test.js +174 -164
- package/dist/__tests__/bundle/bundler.test.js.map +1 -1
- package/dist/__tests__/bundle/programmatic.test.js +76 -53
- package/dist/__tests__/bundle/programmatic.test.js.map +1 -1
- package/dist/__tests__/cli.test.js +58 -46
- package/dist/__tests__/cli.test.js.map +1 -1
- package/dist/__tests__/config-loader.test.d.ts +1 -1
- package/dist/__tests__/config-loader.test.js +231 -212
- package/dist/__tests__/config-loader.test.js.map +1 -1
- 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__/integration/bundle-run.integration.test.js +8 -4
- package/dist/__tests__/integration/bundle-run.integration.test.js.map +1 -1
- 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 +59 -0
- package/dist/__tests__/simulate/server-simulate.integration.test.js.map +1 -0
- package/dist/__tests__/smoke/production.smoke.test.js +9 -2
- package/dist/__tests__/smoke/production.smoke.test.js.map +1 -1
- package/dist/commands/bundle/bundler.d.ts.map +1 -1
- package/dist/commands/bundle/bundler.js +93 -3
- package/dist/commands/bundle/bundler.js.map +1 -1
- package/dist/commands/bundle/index.d.ts +16 -10
- package/dist/commands/bundle/index.d.ts.map +1 -1
- package/dist/commands/bundle/index.js +44 -32
- package/dist/commands/bundle/index.js.map +1 -1
- package/dist/commands/bundle/package-manager.d.ts +2 -1
- package/dist/commands/bundle/package-manager.d.ts.map +1 -1
- package/dist/commands/bundle/package-manager.js +34 -7
- package/dist/commands/bundle/package-manager.js.map +1 -1
- package/dist/commands/cache.d.ts +3 -0
- package/dist/commands/cache.d.ts.map +1 -0
- package/dist/commands/cache.js +44 -0
- package/dist/commands/cache.js.map +1 -0
- package/dist/commands/push/index.d.ts.map +1 -1
- package/dist/commands/push/index.js +49 -44
- package/dist/commands/push/index.js.map +1 -1
- package/dist/commands/push/types.d.ts +1 -1
- package/dist/commands/push/types.d.ts.map +1 -1
- package/dist/commands/run/__tests__/run.integration.test.js +14 -15
- package/dist/commands/run/__tests__/run.integration.test.js.map +1 -1
- package/dist/commands/run/utils.d.ts +4 -1
- package/dist/commands/run/utils.d.ts.map +1 -1
- package/dist/commands/run/utils.js +18 -24
- package/dist/commands/run/utils.js.map +1 -1
- package/dist/commands/run/validators.d.ts +9 -5
- package/dist/commands/run/validators.d.ts.map +1 -1
- package/dist/commands/run/validators.js +14 -11
- package/dist/commands/run/validators.js.map +1 -1
- package/dist/commands/simulate/index.d.ts +1 -0
- package/dist/commands/simulate/index.d.ts.map +1 -1
- package/dist/commands/simulate/index.js +1 -0
- package/dist/commands/simulate/index.js.map +1 -1
- 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.map +1 -1
- package/dist/commands/simulate/simulator.js +36 -32
- package/dist/commands/simulate/simulator.js.map +1 -1
- 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 +72 -0
- package/dist/config/build-defaults.js.map +1 -0
- package/dist/config/index.d.ts +6 -7
- package/dist/config/index.d.ts.map +1 -1
- package/dist/config/index.js +6 -7
- package/dist/config/index.js.map +1 -1
- package/dist/config/loader.d.ts +34 -27
- package/dist/config/loader.d.ts.map +1 -1
- package/dist/config/loader.js +107 -92
- package/dist/config/loader.js.map +1 -1
- package/dist/config/validators.d.ts +34 -8
- package/dist/config/validators.d.ts.map +1 -1
- package/dist/config/validators.js +59 -21
- package/dist/config/validators.js.map +1 -1
- package/dist/core/asset-resolver.d.ts +8 -15
- package/dist/core/asset-resolver.d.ts.map +1 -1
- package/dist/core/asset-resolver.js +30 -37
- package/dist/core/asset-resolver.js.map +1 -1
- 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 +43 -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/docker.d.ts.map +1 -1
- package/dist/core/docker.js +8 -25
- package/dist/core/docker.js.map +1 -1
- package/dist/core/index.d.ts +1 -0
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +1 -0
- package/dist/core/index.js.map +1 -1
- 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/examples/.npm-cache/content-v2/sha512/0d/2d/7581c288670eaf8538ddd9df145b78756ce3be0791c6e0b9cd33429b3bae894525b9bda287a3cedffbcdd2c7b3107bafc03f2b0367eea489eee1cc042abb +1 -0
- package/dist/examples/.npm-cache/content-v2/sha512/12/20/bc4f5acca143809f7e07da1fdafb38137d93243de4d5b403e6e10b92d0d3a6e51eab24fe9dbc9d3ed1cd72e8f7a406085e99c422bb2c7d1166cf9f1f564e +0 -0
- package/dist/examples/.npm-cache/content-v2/sha512/22/ee/fb2695b01871c1d36946bdcfb49f1b520a57200d0a0b221b1e7d5f047ab38a8b2ab0e5f0e25a00acde1f3f2f9d24430a18f1092d438bc1a9e9891cc45f75 +0 -0
- package/dist/examples/.npm-cache/content-v2/sha512/24/89/da1ce6a61bca6de7e132f241a675c01c83738bf6b78af25b5cce01d3030361332b3fe938571e2b721f1555da9ddf930fdcf8c02f0471556071590e68cc09 +0 -0
- package/dist/examples/.npm-cache/content-v2/sha512/47/fd/c6be997da99228c3e279b95d4a46d6913947078a178f54ac71795a159f3513b1483232f4c2d0a1f403178bf9f96bb19615de32a9e2133e949880c6bc15e2 +0 -0
- package/dist/examples/.npm-cache/content-v2/sha512/4b/1c/c1cb7f8b32102071a89fef97158daa32080ebaedfbbd596880d2213d84e305abc76d2a95a412ded55c1c3d487adcb1ceff87fc2c85d7e2856ebd9d3f16f3 +0 -0
- package/dist/examples/.npm-cache/content-v2/sha512/6e/53/ff864769671f44f39d8a3bf904cd646535b745cc4824a8bb3189193b474678049f43b5178ba15cad7f0289046105e70f1565afc84e907120b35a466690fd +1 -0
- package/dist/examples/.npm-cache/content-v2/sha512/70/4c/4c8837d446965c5551b4ea527e95fa011744fb727581d82cf35bb5599ea0b57d18baa490f7af93ef9a16e8e45e5c0802737da20575f4056a4a5c9a3cd288 +0 -0
- package/dist/examples/.npm-cache/content-v2/sha512/96/ad/05de3bbb12d7de8ea353f962bdaea7d2eb44f707f2973462a6635daf537c67b46cca7764fed7d464fe62152c3f783a07aba1ceb35e09ad446bff05a4b466 +1 -0
- package/dist/examples/.npm-cache/content-v2/sha512/b5/20/52dde94e6cef7170f6089c64a4843e57be18be450d956f4e455905aed047ae6a368451c93035e6ac3ee59576b600f03f815afba0836b3a16e10a9aaca4ba +1 -0
- package/dist/examples/.npm-cache/content-v2/sha512/c7/a9/d166a1c39f97df312c59261319ba1cf9aac178bda0a0cb697d5ddd78bd8dd38ef1bf40017bcc8633c2049896c2d70696d9bff9280851f270792ff38bb3a0 +1 -0
- package/dist/examples/.npm-cache/content-v2/sha512/e0/d0/8c14083b633e6adbd3c6a93da5fc0f6bbd456c5512ef276920bedd8d85d551052adff992de977aff326616a211aaa2d6ddcc801149e9b7f914f566359b6a +1 -0
- package/dist/examples/.npm-cache/content-v2/sha512/e7/c5/06ad3fd79ac4f1031fe0b16ea5e54e232ca397bbcd7592c679021cbfb027276099f8c848f3f7a7691f0102ad53aa64f9141e61d729b037a678bd60440d17 +1 -0
- package/dist/examples/.npm-cache/content-v2/sha512/f3/28/d5d32329604ed7d471a4949105daa2cc98858cf24f45b0b97c41d0eb0d5a9fe7bf1f69c792161cc6693e4fc1b52e886ac41875ebfb8fe47fafe417ca3e6e +0 -0
- package/dist/examples/.npm-cache/index-v5/04/5a/2b5d7a7c407d85d746baa0f5c9388a333e35a717a8a0a81943daa6cb1364 +3 -0
- package/dist/examples/.npm-cache/index-v5/12/9a/eba560cbace295d8ee04cf283015377bd77b379e70968fb6bc407c7fc410 +15 -0
- package/dist/examples/.npm-cache/index-v5/2f/a2/7b047564b0ee21ac835ec609e89153dd6549be554d098584d5bfd19fe043 +15 -0
- package/dist/examples/.npm-cache/index-v5/32/8e/322d58dd8d1e000be248ada51385bf96288e56039de9feec1a4c6a467653 +3 -0
- package/dist/examples/.npm-cache/index-v5/57/93/d1d7cd1402e3e26468db03f2870822bb2c9018a506cdfb3b405f38cd3e1c +3 -0
- package/dist/examples/.npm-cache/index-v5/5d/f8/0a1f4fa7149e4ff33e09eb6aea41ac8d1730c868a5d3ace91f762698acff +3 -0
- package/dist/examples/.npm-cache/index-v5/69/a4/a92c72d838259b051cdf8e0acfb2bc680b6d4cfc642314a7836c3f7b2c50 +15 -0
- package/dist/examples/.npm-cache/index-v5/71/31/6da3423bb203f3de5eb16c942431073f89be2cfcb40058ec91dcb5ce0abc +15 -0
- package/dist/examples/.npm-cache/index-v5/7b/94/72b6bffa050d9ef52a558dd220663695bc606f756be0dfa196ef4f3913ba +3 -0
- package/dist/examples/.npm-cache/index-v5/85/9e/99e97fdd562517e56285337db91d1a8f2f416b8d631cf4d7d754fa671299 +15 -0
- package/dist/examples/.npm-cache/index-v5/92/4c/9416ada81a9b3c679539fd1ab53f8de3d41ff268f35eba7a194389a85b06 +3 -0
- package/dist/examples/.npm-cache/index-v5/c1/5a/13df76b218deed8a6ef12961116af5183db98c53fad1b922fd9edc075247 +3 -0
- package/dist/examples/.npm-cache/index-v5/cb/11/253c55410a8ab7c4a9ea9d6e1bf8ef1450a581da64c478074dfd82c8bff6 +3 -0
- package/dist/examples/.npm-cache/index-v5/d5/ae/b57fad3a62b5ba2dbdf24b042a9e7b70820f3db00e5a630f02e1fea020dc +3 -0
- package/dist/examples/.npm-cache/index-v5/d6/32/2f620f83c7d14451de98de8298c2408e05a16cc0829bd16c891ac19d7a67 +3 -0
- package/dist/examples/.npm-cache/index-v5/dd/b5/01dc7a3cd8b6a03a69aee9af500d51ae19cb0aa12631a4aafd152148b8e5 +15 -0
- package/dist/examples/.npm-cache/index-v5/e0/cf/6b862c15d74630d3871cd813d305210ab741311deb10baf8813014e0bc30 +3 -0
- package/dist/examples/.npm-cache/index-v5/e2/be/e880ccd35950a814d3c1dded34d3938ac61b15a195321dc51357f801aad4 +15 -0
- package/dist/examples/.npm-cache/index-v5/e5/1f/f4affe0b392cd03288f23cc03abcb274ff11a2c8f8965299de681914abb2 +3 -0
- package/dist/examples/.npm-cache/index-v5/f3/5b/9ebe450958ff0d7cc44ab0a00080cb8a3ff1389744b5eab5f97b68a6a6af +3 -0
- package/dist/examples/.npm-cache/index-v5/fb/c1/0de405e902866d53e7c30cf36a97dc2578838622b261816f44dc377c9a80 +3 -0
- package/dist/examples/README.md +343 -0
- package/dist/examples/event.json +53 -0
- package/dist/examples/flow-order-complete.json +68 -0
- package/dist/examples/flow-simple.json +32 -0
- package/dist/examples/flow.json +82 -0
- package/dist/examples/server-collect.json +60 -0
- package/dist/examples/server-collect.mjs +13540 -0
- package/dist/examples/test.html +43 -0
- package/dist/examples/web-serve.js +25503 -0
- package/dist/examples/web-serve.json +74 -0
- package/dist/index.d.ts +84 -201
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +675 -422
- package/dist/index.js.map +1 -1
- 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/templates/server.hbs +29 -0
- package/dist/templates/web.hbs +45 -0
- package/dist/types/bundle.d.ts +68 -190
- package/dist/types/bundle.d.ts.map +1 -1
- package/dist/types/bundle.js +2 -2
- package/dist/walker.js +1 -0
- package/examples/README.md +42 -29
- package/examples/flow-order-complete.json +57 -57
- package/examples/flow-simple.json +25 -25
- package/examples/flow.json +69 -69
- package/examples/server-collect.json +51 -44
- package/examples/server-collect.mjs +1 -1
- package/examples/web-serve.json +62 -63
- package/package.json +2 -2
- package/dist/config/defaults.d.ts +0 -33
- package/dist/config/defaults.d.ts.map +0 -1
- package/dist/config/defaults.js +0 -69
- package/dist/config/defaults.js.map +0 -1
- package/dist/config/parser.d.ts +0 -128
- package/dist/config/parser.d.ts.map +0 -1
- package/dist/config/parser.js +0 -256
- package/dist/config/parser.js.map +0 -1
package/dist/config/loader.js
CHANGED
|
@@ -1,139 +1,154 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Configuration Loader
|
|
3
3
|
*
|
|
4
|
-
* Loads and parses configurations
|
|
5
|
-
*
|
|
6
|
-
* - Multi-environment setups
|
|
7
|
-
* - Environment selection
|
|
4
|
+
* Loads and parses Flow.Setup configurations using core getFlowConfig().
|
|
5
|
+
* Build options are determined by static platform defaults.
|
|
8
6
|
*/
|
|
9
|
-
import
|
|
10
|
-
import
|
|
7
|
+
import path from 'path';
|
|
8
|
+
import fs from 'fs-extra';
|
|
9
|
+
import { getFlowConfig, getPlatform } from '@walkeros/core';
|
|
10
|
+
import { validateFlowSetup, isFlowSetup, getAvailableFlows as getFlowNames, } from './validators.js';
|
|
11
|
+
import { getBuildDefaults, getDefaultOutput } from './build-defaults.js';
|
|
12
|
+
/** Default folder for includes if it exists */
|
|
13
|
+
const DEFAULT_INCLUDE_FOLDER = './shared';
|
|
11
14
|
/**
|
|
12
15
|
* Load and parse bundle configuration.
|
|
13
16
|
*
|
|
14
17
|
* @remarks
|
|
15
|
-
*
|
|
16
|
-
* -
|
|
17
|
-
* -
|
|
18
|
-
* -
|
|
19
|
-
*
|
|
20
|
-
* For multi-environment configs, requires `environment` option.
|
|
18
|
+
* Uses Flow.Setup from @walkeros/core as the only config format.
|
|
19
|
+
* - Validates config structure
|
|
20
|
+
* - Uses core getFlowConfig() for variable/definition resolution
|
|
21
|
+
* - Determines platform from resolved config
|
|
22
|
+
* - Applies static build defaults based on platform
|
|
21
23
|
*
|
|
22
24
|
* @param rawConfig - Raw configuration object from JSON file
|
|
23
25
|
* @param options - Loading options
|
|
24
26
|
* @returns Parsed configuration with flow and build separated
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```typescript
|
|
30
|
+
* const config = loadBundleConfig(rawConfig, {
|
|
31
|
+
* configPath: './walkeros.config.json',
|
|
32
|
+
* flowName: 'production',
|
|
33
|
+
* });
|
|
34
|
+
* ```
|
|
25
35
|
*/
|
|
26
36
|
export function loadBundleConfig(rawConfig, options) {
|
|
27
|
-
//
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
//
|
|
33
|
-
const
|
|
34
|
-
//
|
|
35
|
-
|
|
36
|
-
|
|
37
|
+
// Validate as Flow.Setup
|
|
38
|
+
const setup = validateFlowSetup(rawConfig);
|
|
39
|
+
const availableFlows = getFlowNames(setup);
|
|
40
|
+
// Determine which flow to use
|
|
41
|
+
const flowName = resolveFlow(setup, options.flowName, availableFlows);
|
|
42
|
+
// Use core getFlowConfig() for resolution (variables, $refs, cascading)
|
|
43
|
+
const flowConfig = getFlowConfig(setup, flowName);
|
|
44
|
+
// Detect platform from resolved config
|
|
45
|
+
const platform = getPlatform(flowConfig);
|
|
46
|
+
if (!platform) {
|
|
47
|
+
throw new Error(`Invalid configuration: flow "${flowName}" must have a "web" or "server" key.`);
|
|
37
48
|
}
|
|
38
|
-
//
|
|
39
|
-
|
|
40
|
-
|
|
49
|
+
// Get static build defaults based on platform
|
|
50
|
+
const buildDefaults = getBuildDefaults(platform);
|
|
51
|
+
// Extract packages from flowConfig (if present)
|
|
52
|
+
const packages = flowConfig.packages || {};
|
|
53
|
+
// Resolve output path relative to config directory
|
|
54
|
+
let output = getDefaultOutput(platform);
|
|
55
|
+
if (options.buildOverrides?.output) {
|
|
56
|
+
output = options.buildOverrides.output;
|
|
41
57
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Load multi-environment configuration.
|
|
49
|
-
*
|
|
50
|
-
* @deprecated Kept for backward compatibility. Use loadBundleConfig() instead.
|
|
51
|
-
*/
|
|
52
|
-
function loadMultiEnvironmentConfig(setup, options) {
|
|
53
|
-
const availableEnvironments = Object.keys(setup.environments);
|
|
54
|
-
// Validate environment selection
|
|
55
|
-
if (!options.environment) {
|
|
56
|
-
throw new Error(`Multi-environment configuration detected. Please specify an environment using --env flag.\n` +
|
|
57
|
-
`Available environments: ${availableEnvironments.join(', ')}`);
|
|
58
|
+
// Get config directory for relative path resolution
|
|
59
|
+
const configDir = path.dirname(options.configPath);
|
|
60
|
+
// Make output path absolute relative to config file
|
|
61
|
+
if (!path.isAbsolute(output)) {
|
|
62
|
+
output = path.resolve(configDir, output);
|
|
58
63
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
64
|
+
// Get includes from config or use default if ./shared exists
|
|
65
|
+
let includes = setup.include;
|
|
66
|
+
if (!includes) {
|
|
67
|
+
const defaultIncludePath = path.resolve(configDir, DEFAULT_INCLUDE_FOLDER);
|
|
68
|
+
if (fs.pathExistsSync(defaultIncludePath)) {
|
|
69
|
+
includes = [DEFAULT_INCLUDE_FOLDER];
|
|
70
|
+
}
|
|
63
71
|
}
|
|
64
|
-
//
|
|
65
|
-
const
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
72
|
+
// Merge build options: defaults + CLI overrides
|
|
73
|
+
const buildOptions = {
|
|
74
|
+
...buildDefaults,
|
|
75
|
+
packages,
|
|
76
|
+
output,
|
|
77
|
+
include: includes,
|
|
78
|
+
configDir,
|
|
79
|
+
...options.buildOverrides,
|
|
80
|
+
};
|
|
81
|
+
// Log flow selection
|
|
82
|
+
const isMultiFlow = availableFlows.length > 1;
|
|
83
|
+
if (isMultiFlow && options.logger) {
|
|
84
|
+
options.logger.info(`📦 Using flow: ${flowName} (${availableFlows.length} total)`);
|
|
70
85
|
}
|
|
71
86
|
return {
|
|
72
87
|
flowConfig,
|
|
73
88
|
buildOptions,
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
89
|
+
flowName,
|
|
90
|
+
isMultiFlow,
|
|
91
|
+
availableFlows,
|
|
77
92
|
};
|
|
78
93
|
}
|
|
79
94
|
/**
|
|
80
|
-
*
|
|
95
|
+
* Resolve which flow to use.
|
|
81
96
|
*
|
|
82
|
-
* @
|
|
97
|
+
* @param setup - Flow.Setup configuration
|
|
98
|
+
* @param requestedFlow - Flow name from CLI (optional)
|
|
99
|
+
* @param available - Available flow names
|
|
100
|
+
* @returns Flow name to use
|
|
101
|
+
* @throws Error if flow selection is invalid
|
|
83
102
|
*/
|
|
84
|
-
function
|
|
85
|
-
//
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
options.logger.warn(`--env flag specified but configuration is single-environment. Ignoring flag.`);
|
|
103
|
+
function resolveFlow(setup, requestedFlow, available) {
|
|
104
|
+
// If only one flow, use it automatically
|
|
105
|
+
if (available.length === 1) {
|
|
106
|
+
return available[0];
|
|
89
107
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
108
|
+
// Multiple flows require explicit selection
|
|
109
|
+
if (!requestedFlow) {
|
|
110
|
+
throw new Error(`Multiple flows found. Please specify a flow using --flow flag.\n` +
|
|
111
|
+
`Available flows: ${available.join(', ')}`);
|
|
112
|
+
}
|
|
113
|
+
// Validate the requested flow exists
|
|
114
|
+
if (!available.includes(requestedFlow)) {
|
|
115
|
+
throw new Error(`Flow "${requestedFlow}" not found in configuration.\n` +
|
|
116
|
+
`Available flows: ${available.join(', ')}`);
|
|
117
|
+
}
|
|
118
|
+
return requestedFlow;
|
|
96
119
|
}
|
|
97
|
-
// Legacy format support removed in v0.3.0
|
|
98
|
-
// Migration: Convert old format { platform, sources, destinations, packages, code, output }
|
|
99
|
-
// To new format: { flow: { platform, sources, destinations }, build: { packages, code, output } }
|
|
100
|
-
// See docs/MIGRATION.md for details
|
|
101
120
|
/**
|
|
102
|
-
* Load all
|
|
121
|
+
* Load all flows from a configuration.
|
|
103
122
|
*
|
|
104
123
|
* @remarks
|
|
105
|
-
* Used by the --all flag to build all
|
|
124
|
+
* Used by the --all flag to build all flows.
|
|
106
125
|
*
|
|
107
126
|
* @param rawConfig - Raw configuration object
|
|
108
|
-
* @param options - Loading options
|
|
109
|
-
* @returns Array of loaded configurations for all
|
|
127
|
+
* @param options - Loading options (without flowName)
|
|
128
|
+
* @returns Array of loaded configurations for all flows
|
|
110
129
|
*/
|
|
111
|
-
export function
|
|
112
|
-
//
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
`Your configuration appears to be single-environment.`);
|
|
116
|
-
}
|
|
117
|
-
const setup = rawConfig;
|
|
118
|
-
const environments = Object.keys(setup.environments);
|
|
130
|
+
export function loadAllFlows(rawConfig, options) {
|
|
131
|
+
// Validate as Flow.Setup
|
|
132
|
+
const setup = validateFlowSetup(rawConfig);
|
|
133
|
+
const flows = getFlowNames(setup);
|
|
119
134
|
if (options.logger) {
|
|
120
|
-
options.logger.info(`📦 Loading all ${
|
|
135
|
+
options.logger.info(`📦 Loading all ${flows.length} flows: ${flows.join(', ')}`);
|
|
121
136
|
}
|
|
122
|
-
// Load each
|
|
123
|
-
return
|
|
137
|
+
// Load each flow
|
|
138
|
+
return flows.map((name) => loadBundleConfig(rawConfig, {
|
|
124
139
|
...options,
|
|
125
|
-
|
|
140
|
+
flowName: name,
|
|
126
141
|
}));
|
|
127
142
|
}
|
|
128
143
|
/**
|
|
129
|
-
* Get list of available
|
|
144
|
+
* Get list of available flows from configuration.
|
|
130
145
|
*
|
|
131
146
|
* @param rawConfig - Raw configuration object
|
|
132
|
-
* @returns Array of
|
|
147
|
+
* @returns Array of flow names
|
|
133
148
|
*/
|
|
134
|
-
export function
|
|
135
|
-
if (
|
|
136
|
-
return
|
|
149
|
+
export function getAvailableFlows(rawConfig) {
|
|
150
|
+
if (isFlowSetup(rawConfig)) {
|
|
151
|
+
return getFlowNames(rawConfig);
|
|
137
152
|
}
|
|
138
153
|
return [];
|
|
139
154
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loader.js","sourceRoot":"","sources":["../../src/config/loader.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"loader.js","sourceRoot":"","sources":["../../src/config/loader.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,MAAM,UAAU,CAAC;AAC1B,OAAO,EAAE,aAAa,EAAE,WAAW,EAAa,MAAM,gBAAgB,CAAC;AAEvE,OAAO,EACL,iBAAiB,EACjB,WAA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ACb,kEAAkE;YAChE,oBAAoB,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAC7C,CAAC;IACJ,CAAC;IAED,qCAAqC;IACrC,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,aAAa,CAAC,EAAE,CAAC;QACvC,MAAM,IAAI,KAAK,CACb,SAAS,aAAa,iCAAiC;YACrD,oBAAoB,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAC7C,CAAC;IACJ,CAAC;IAED,OAAO,aAAa,CAAC;AACvB,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,YAAY,CAC1B,SAAkB,EAClB,OAA4C;IAE5C,yBAAyB;IACzB,MAAM,KAAK,GAAG,iBAAiB,CAAC,SAAS,CAAC,CAAC;IAC3C,MAAM,KAAK,GAAG,YAAY,CAAC,KAAK,CAAC,CAAC;IAElC,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;QACnB,OAAO,CAAC,MAAM,CAAC,IAAI,CACjB,kBAAkB,KAAK,CAAC,MAAM,WAAW,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAC5D,CAAC;IACJ,CAAC;IAED,iBAAiB;IACjB,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CACxB,gBAAgB,CAAC,SAAS,EAAE;QAC1B,GAAG,OAAO;QACV,QAAQ,EAAE,IAAI;KACf,CAAC,CACH,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB,CAAC,SAAkB;IAClD,IAAI,WAAW,CAAC,SAAS,CAAC,EAAE,CAAC;QAC3B,OAAO,YAAY,CAAC,SAAS,CAAC,CAAC;IACjC,CAAC;IACD,OAAO,EAAE,CAAC;AACZ,CAAC"}
|
|
@@ -2,25 +2,51 @@
|
|
|
2
2
|
* Configuration Type Guards and Validators
|
|
3
3
|
*
|
|
4
4
|
* Type checking utilities for configuration validation.
|
|
5
|
+
* Uses Zod schemas from @walkeros/core for Flow.Setup validation.
|
|
5
6
|
*/
|
|
6
|
-
import type {
|
|
7
|
+
import type { Flow } from '@walkeros/core';
|
|
7
8
|
/**
|
|
8
9
|
* Type guard: Check if value is a plain object.
|
|
9
10
|
*/
|
|
10
11
|
export declare function isObject(value: unknown): value is Record<string, unknown>;
|
|
11
12
|
/**
|
|
12
|
-
*
|
|
13
|
+
* Detect platform from flow config.
|
|
14
|
+
*
|
|
15
|
+
* Platform is determined by the presence of `web` or `server` key.
|
|
13
16
|
*/
|
|
14
|
-
export declare function
|
|
17
|
+
export declare function detectPlatform(flowConfig: Record<string, unknown>): 'web' | 'server' | undefined;
|
|
15
18
|
/**
|
|
16
|
-
* Type guard: Check if config is
|
|
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
|
+
* ```
|
|
17
31
|
*/
|
|
18
|
-
export declare function
|
|
32
|
+
export declare function isFlowSetup(data: unknown): data is Flow.Setup;
|
|
19
33
|
/**
|
|
20
|
-
*
|
|
34
|
+
* Validate Flow.Setup and throw descriptive error if invalid.
|
|
21
35
|
*
|
|
22
36
|
* @remarks
|
|
23
|
-
*
|
|
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
|
|
24
50
|
*/
|
|
25
|
-
export declare function
|
|
51
|
+
export declare function getAvailableFlows(setup: Flow.Setup): string[];
|
|
26
52
|
//# sourceMappingURL=validators.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validators.d.ts","sourceRoot":"","sources":["../../src/config/validators.ts"],"names":[],"mappings":"AAAA
|
|
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"}
|
|
@@ -2,7 +2,10 @@
|
|
|
2
2
|
* Configuration Type Guards and Validators
|
|
3
3
|
*
|
|
4
4
|
* Type checking utilities for configuration validation.
|
|
5
|
+
* Uses Zod schemas from @walkeros/core for Flow.Setup validation.
|
|
5
6
|
*/
|
|
7
|
+
import { schemas } from '@walkeros/core/dev';
|
|
8
|
+
const { safeParseSetup } = schemas;
|
|
6
9
|
/**
|
|
7
10
|
* Type guard: Check if value is a plain object.
|
|
8
11
|
*/
|
|
@@ -13,35 +16,70 @@ export function isObject(value) {
|
|
|
13
16
|
Object.prototype.toString.call(value) === '[object Object]');
|
|
14
17
|
}
|
|
15
18
|
/**
|
|
16
|
-
*
|
|
19
|
+
* Detect platform from flow config.
|
|
20
|
+
*
|
|
21
|
+
* Platform is determined by the presence of `web` or `server` key.
|
|
17
22
|
*/
|
|
18
|
-
export function
|
|
19
|
-
|
|
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;
|
|
20
31
|
}
|
|
21
32
|
/**
|
|
22
|
-
* Type guard: Check if config is
|
|
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
|
+
* ```
|
|
23
45
|
*/
|
|
24
|
-
export function
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
data.version === 1 &&
|
|
28
|
-
'environments' in data &&
|
|
29
|
-
isObject(data.environments));
|
|
46
|
+
export function isFlowSetup(data) {
|
|
47
|
+
const result = safeParseSetup(data);
|
|
48
|
+
return result.success;
|
|
30
49
|
}
|
|
31
50
|
/**
|
|
32
|
-
*
|
|
51
|
+
* Validate Flow.Setup and throw descriptive error if invalid.
|
|
33
52
|
*
|
|
34
53
|
* @remarks
|
|
35
|
-
*
|
|
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
|
|
36
81
|
*/
|
|
37
|
-
export function
|
|
38
|
-
return (
|
|
39
|
-
'flow' in data &&
|
|
40
|
-
'build' in data &&
|
|
41
|
-
isObject(data.flow) &&
|
|
42
|
-
isObject(data.build) &&
|
|
43
|
-
'platform' in data.flow);
|
|
82
|
+
export function getAvailableFlows(setup) {
|
|
83
|
+
return Object.keys(setup.flows);
|
|
44
84
|
}
|
|
45
|
-
// Legacy format support removed in v0.3.0
|
|
46
|
-
// See docs/MIGRATION.md for migration guide
|
|
47
85
|
//# sourceMappingURL=validators.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validators.js","sourceRoot":"","sources":["../../src/config/validators.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"validators.js","sourceRoot":"","sources":["../../src/config/validators.ts"],"names":[],"mapp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K,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"}
|
|
@@ -1,20 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Asset Resolver
|
|
3
3
|
*
|
|
4
|
-
* Unified path resolution for package assets (templates, examples) and user assets
|
|
5
|
-
*
|
|
4
|
+
* Unified path resolution for package assets (templates, examples) and user assets.
|
|
5
|
+
* Assets are always siblings to the CLI entry point (in dist/ for production).
|
|
6
6
|
*/
|
|
7
7
|
/**
|
|
8
|
-
* Get the
|
|
8
|
+
* Get the directory containing CLI assets (templates, examples).
|
|
9
9
|
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* - Test (src): /path/to/packages/cli/src/core/asset-resolver.ts → /path/to/packages/cli
|
|
13
|
-
* - Docker: /cli
|
|
10
|
+
* In production: assets are in dist/ alongside the bundled CLI
|
|
11
|
+
* In development: assets are at package root
|
|
14
12
|
*
|
|
15
|
-
* @returns Absolute path to
|
|
13
|
+
* @returns Absolute path to assets directory
|
|
16
14
|
*/
|
|
17
|
-
export declare function
|
|
15
|
+
export declare function getAssetDir(): string;
|
|
18
16
|
/**
|
|
19
17
|
* Asset type for resolution strategy
|
|
20
18
|
*/
|
|
@@ -23,13 +21,8 @@ export type AssetType = 'template' | 'config' | 'bundle';
|
|
|
23
21
|
* Resolve asset path using unified strategy
|
|
24
22
|
*
|
|
25
23
|
* Resolution rules:
|
|
26
|
-
* 1. Bare names (no / or \) → Package asset
|
|
27
|
-
* - "web.hbs" → ${packageRoot}/templates/web.hbs
|
|
28
|
-
* - "server-collect.json" → ${packageRoot}/examples/server-collect.json
|
|
29
|
-
*
|
|
24
|
+
* 1. Bare names (no / or \) → Package asset (templates or examples)
|
|
30
25
|
* 2. Relative paths (./ or ../) → User asset relative to base directory
|
|
31
|
-
* - "./my-template.hbs" → ${baseDir}/my-template.hbs
|
|
32
|
-
*
|
|
33
26
|
* 3. Absolute paths → Use as-is
|
|
34
27
|
*
|
|
35
28
|
* @param assetPath - Path to resolve
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"asset-resolver.d.ts","sourceRoot":"","sources":["../../src/core/asset-resolver.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;
|
|
1
|
+
{"version":3,"file":"asset-resolver.d.ts","sourceRoot":"","sources":["../../src/core/asset-resolver.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAWH;;;;;;;GAOG;AACH,wBAAgB,WAAW,IAAI,MAAM,CAkBpC;AAED;;GAEG;AACH,MAAM,MAAM,SAAS,GAAG,UAAU,GAAG,QAAQ,GAAG,QAAQ,CAAC;AAEzD;;;;;;;;;;;;GAYG;AACH,wBAAgB,YAAY,CAC1B,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,SAAS,EACpB,OAAO,CAAC,EAAE,MAAM,GACf,MAAM,CAkBR"}
|
|
@@ -1,53 +1,47 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Asset Resolver
|
|
3
3
|
*
|
|
4
|
-
* Unified path resolution for package assets (templates, examples) and user assets
|
|
5
|
-
*
|
|
4
|
+
* Unified path resolution for package assets (templates, examples) and user assets.
|
|
5
|
+
* Assets are always siblings to the CLI entry point (in dist/ for production).
|
|
6
6
|
*/
|
|
7
7
|
import { fileURLToPath } from 'url';
|
|
8
|
+
import { existsSync } from 'fs';
|
|
8
9
|
import path from 'path';
|
|
9
10
|
/**
|
|
10
|
-
*
|
|
11
|
+
* Cached asset directory to avoid repeated filesystem checks
|
|
12
|
+
*/
|
|
13
|
+
let cachedAssetDir;
|
|
14
|
+
/**
|
|
15
|
+
* Get the directory containing CLI assets (templates, examples).
|
|
11
16
|
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
* - Test (src): /path/to/packages/cli/src/core/asset-resolver.ts → /path/to/packages/cli
|
|
15
|
-
* - Docker: /cli
|
|
17
|
+
* In production: assets are in dist/ alongside the bundled CLI
|
|
18
|
+
* In development: assets are at package root
|
|
16
19
|
*
|
|
17
|
-
* @returns Absolute path to
|
|
20
|
+
* @returns Absolute path to assets directory
|
|
18
21
|
*/
|
|
19
|
-
export function
|
|
22
|
+
export function getAssetDir() {
|
|
23
|
+
if (cachedAssetDir)
|
|
24
|
+
return cachedAssetDir;
|
|
20
25
|
const currentFile = fileURLToPath(import.meta.url);
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
// Files can be at any depth: dist/index.js or dist/core/asset-resolver.js
|
|
30
|
-
// Find the dist/ directory and go one level up
|
|
31
|
-
// e.g., /path/to/packages/cli/dist/core/asset-resolver.js -> /path/to/packages/cli
|
|
32
|
-
// e.g., /cli/dist/core/asset-resolver.js -> /cli (Docker)
|
|
33
|
-
if (currentFile.includes('/dist/')) {
|
|
34
|
-
const distIndex = currentFile.indexOf('/dist/');
|
|
35
|
-
return currentFile.substring(0, distIndex);
|
|
26
|
+
let dir = path.dirname(currentFile);
|
|
27
|
+
// Walk up until we find a directory with templates/ sibling
|
|
28
|
+
while (dir !== path.dirname(dir)) {
|
|
29
|
+
if (existsSync(path.join(dir, 'templates'))) {
|
|
30
|
+
cachedAssetDir = dir;
|
|
31
|
+
return dir;
|
|
32
|
+
}
|
|
33
|
+
dir = path.dirname(dir);
|
|
36
34
|
}
|
|
37
|
-
// Fallback
|
|
38
|
-
|
|
35
|
+
// Fallback to current file's directory (shouldn't happen if build is correct)
|
|
36
|
+
cachedAssetDir = path.dirname(currentFile);
|
|
37
|
+
return cachedAssetDir;
|
|
39
38
|
}
|
|
40
39
|
/**
|
|
41
40
|
* Resolve asset path using unified strategy
|
|
42
41
|
*
|
|
43
42
|
* Resolution rules:
|
|
44
|
-
* 1. Bare names (no / or \) → Package asset
|
|
45
|
-
* - "web.hbs" → ${packageRoot}/templates/web.hbs
|
|
46
|
-
* - "server-collect.json" → ${packageRoot}/examples/server-collect.json
|
|
47
|
-
*
|
|
43
|
+
* 1. Bare names (no / or \) → Package asset (templates or examples)
|
|
48
44
|
* 2. Relative paths (./ or ../) → User asset relative to base directory
|
|
49
|
-
* - "./my-template.hbs" → ${baseDir}/my-template.hbs
|
|
50
|
-
*
|
|
51
45
|
* 3. Absolute paths → Use as-is
|
|
52
46
|
*
|
|
53
47
|
* @param assetPath - Path to resolve
|
|
@@ -56,21 +50,20 @@ export function getPackageRoot() {
|
|
|
56
50
|
* @returns Absolute path to asset
|
|
57
51
|
*/
|
|
58
52
|
export function resolveAsset(assetPath, assetType, baseDir) {
|
|
59
|
-
const packageRoot = getPackageRoot();
|
|
60
53
|
// Bare name → package asset
|
|
61
54
|
if (!assetPath.includes('/') && !assetPath.includes('\\')) {
|
|
55
|
+
const assetDir = getAssetDir();
|
|
62
56
|
if (assetType === 'template') {
|
|
63
|
-
return path.join(
|
|
57
|
+
return path.join(assetDir, 'templates', assetPath);
|
|
64
58
|
}
|
|
65
59
|
// config or bundle → examples directory
|
|
66
|
-
return path.join(
|
|
60
|
+
return path.join(assetDir, 'examples', assetPath);
|
|
67
61
|
}
|
|
68
62
|
// Absolute path → use as-is
|
|
69
63
|
if (path.isAbsolute(assetPath)) {
|
|
70
64
|
return assetPath;
|
|
71
65
|
}
|
|
72
66
|
// Relative path → resolve from base directory
|
|
73
|
-
|
|
74
|
-
return path.resolve(resolveBase, assetPath);
|
|
67
|
+
return path.resolve(baseDir || process.cwd(), assetPath);
|
|
75
68
|
}
|
|
76
69
|
//# sourceMappingURL=asset-resolver.js.map
|
|
@@ -1 +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,IAAI,MAAM,MAAM,CAAC;AAExB
|
|
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;AAExB;;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,4DAA4D;IAC5D,OAAO,GAAG,KAAK,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;QACjC,IAAI,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,WAAW,CAAC,CAAC,EAAE,CAAC;YAC5C,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,CA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