@hypercli/core 0.1.1
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/LICENSE +21 -0
- package/README.md +11 -0
- package/dist/config/config-loader.d.ts +117 -0
- package/dist/config/config-loader.d.ts.map +1 -0
- package/dist/config/config-loader.js +287 -0
- package/dist/config/config-loader.js.map +1 -0
- package/dist/config/index.d.ts +9 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +8 -0
- package/dist/config/index.js.map +1 -0
- package/dist/config/load-helpers.d.ts +13 -0
- package/dist/config/load-helpers.d.ts.map +1 -0
- package/dist/config/load-helpers.js +67 -0
- package/dist/config/load-helpers.js.map +1 -0
- package/dist/constants.d.ts +4 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +4 -0
- package/dist/constants.js.map +1 -0
- package/dist/errors/hypergen-errors.d.ts +162 -0
- package/dist/errors/hypergen-errors.d.ts.map +1 -0
- package/dist/errors/hypergen-errors.js +944 -0
- package/dist/errors/hypergen-errors.js.map +1 -0
- package/dist/errors/index.d.ts +2 -0
- package/dist/errors/index.d.ts.map +1 -0
- package/dist/errors/index.js +2 -0
- package/dist/errors/index.js.map +1 -0
- package/dist/helpers.d.ts +25 -0
- package/dist/helpers.d.ts.map +1 -0
- package/dist/helpers.js +20 -0
- package/dist/helpers.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +13 -0
- package/dist/index.js.map +1 -0
- package/dist/logger/cli-html-types.d.ts +36 -0
- package/dist/logger/cli-html-types.d.ts.map +1 -0
- package/dist/logger/cli-html-types.js +2 -0
- package/dist/logger/cli-html-types.js.map +1 -0
- package/dist/logger/index.d.ts +3 -0
- package/dist/logger/index.d.ts.map +1 -0
- package/dist/logger/index.js +3 -0
- package/dist/logger/index.js.map +1 -0
- package/dist/logger/logger.d.ts +17 -0
- package/dist/logger/logger.d.ts.map +1 -0
- package/dist/logger/logger.js +42 -0
- package/dist/logger/logger.js.map +1 -0
- package/dist/logger/types.d.ts +16 -0
- package/dist/logger/types.d.ts.map +1 -0
- package/dist/logger/types.js +2 -0
- package/dist/logger/types.js.map +1 -0
- package/dist/parsers/cookbook-parser.d.ts +30 -0
- package/dist/parsers/cookbook-parser.d.ts.map +1 -0
- package/dist/parsers/cookbook-parser.js +155 -0
- package/dist/parsers/cookbook-parser.js.map +1 -0
- package/dist/parsers/index.d.ts +10 -0
- package/dist/parsers/index.d.ts.map +1 -0
- package/dist/parsers/index.js +16 -0
- package/dist/parsers/index.js.map +1 -0
- package/dist/parsers/kit-parser.d.ts +44 -0
- package/dist/parsers/kit-parser.d.ts.map +1 -0
- package/dist/parsers/kit-parser.js +195 -0
- package/dist/parsers/kit-parser.js.map +1 -0
- package/dist/parsers/path-resolver.d.ts +72 -0
- package/dist/parsers/path-resolver.d.ts.map +1 -0
- package/dist/parsers/path-resolver.js +281 -0
- package/dist/parsers/path-resolver.js.map +1 -0
- package/dist/parsers/template-parser.d.ts +142 -0
- package/dist/parsers/template-parser.d.ts.map +1 -0
- package/dist/parsers/template-parser.js +896 -0
- package/dist/parsers/template-parser.js.map +1 -0
- package/dist/types/actions.d.ts +109 -0
- package/dist/types/actions.d.ts.map +1 -0
- package/dist/types/actions.js +31 -0
- package/dist/types/actions.js.map +1 -0
- package/dist/types/ai-config.d.ts +170 -0
- package/dist/types/ai-config.d.ts.map +1 -0
- package/dist/types/ai-config.js +10 -0
- package/dist/types/ai-config.js.map +1 -0
- package/dist/types/common.d.ts +24 -0
- package/dist/types/common.d.ts.map +1 -0
- package/dist/types/common.js +10 -0
- package/dist/types/common.js.map +1 -0
- package/dist/types/index.d.ts +19 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +11 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/kit.d.ts +92 -0
- package/dist/types/kit.d.ts.map +1 -0
- package/dist/types/kit.js +17 -0
- package/dist/types/kit.js.map +1 -0
- package/dist/types/recipe.d.ts +953 -0
- package/dist/types/recipe.d.ts.map +1 -0
- package/dist/types/recipe.js +92 -0
- package/dist/types/recipe.js.map +1 -0
- package/dist/types/template.d.ts +49 -0
- package/dist/types/template.d.ts.map +1 -0
- package/dist/types/template.js +7 -0
- package/dist/types/template.js.map +1 -0
- package/dist/ui/index.d.ts +4 -0
- package/dist/ui/index.d.ts.map +1 -0
- package/dist/ui/index.js +4 -0
- package/dist/ui/index.js.map +1 -0
- package/dist/ui/messages.d.ts +16 -0
- package/dist/ui/messages.d.ts.map +1 -0
- package/dist/ui/messages.js +57 -0
- package/dist/ui/messages.js.map +1 -0
- package/dist/ui/styles.d.ts +7 -0
- package/dist/ui/styles.d.ts.map +1 -0
- package/dist/ui/styles.js +8 -0
- package/dist/ui/styles.js.map +1 -0
- package/dist/ui/symbols.d.ts +9 -0
- package/dist/ui/symbols.d.ts.map +1 -0
- package/dist/ui/symbols.js +10 -0
- package/dist/ui/symbols.js.map +1 -0
- package/dist/utils/display-utils.d.ts +65 -0
- package/dist/utils/display-utils.d.ts.map +1 -0
- package/dist/utils/display-utils.js +101 -0
- package/dist/utils/display-utils.js.map +1 -0
- package/dist/utils/find-project-root.d.ts +32 -0
- package/dist/utils/find-project-root.d.ts.map +1 -0
- package/dist/utils/find-project-root.js +133 -0
- package/dist/utils/find-project-root.js.map +1 -0
- package/dist/utils/index.d.ts +4 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +4 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/newline.d.ts +3 -0
- package/dist/utils/newline.d.ts.map +1 -0
- package/dist/utils/newline.js +12 -0
- package/dist/utils/newline.js.map +1 -0
- package/package.json +83 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Saulo Vallory
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hypergen Configuration System
|
|
3
|
+
*
|
|
4
|
+
* Provides configuration loading and management for hypergen projects
|
|
5
|
+
*/
|
|
6
|
+
export interface AiServiceConfig {
|
|
7
|
+
provider?: "anthropic" | "openai" | "custom";
|
|
8
|
+
apiKey?: string;
|
|
9
|
+
model?: string;
|
|
10
|
+
temperature?: number;
|
|
11
|
+
maxTokens?: number;
|
|
12
|
+
}
|
|
13
|
+
export interface HypergenConfig {
|
|
14
|
+
templates?: string[];
|
|
15
|
+
discovery?: {
|
|
16
|
+
sources?: ("local" | "npm" | "workspace" | "github" | "git")[];
|
|
17
|
+
directories?: string[];
|
|
18
|
+
exclude?: string[];
|
|
19
|
+
};
|
|
20
|
+
engine?: {
|
|
21
|
+
/** Enable template caching */
|
|
22
|
+
cache?: boolean;
|
|
23
|
+
};
|
|
24
|
+
output?: {
|
|
25
|
+
conflictStrategy?: "fail" | "overwrite" | "skip" | "merge";
|
|
26
|
+
createDirectories?: boolean;
|
|
27
|
+
preserveTimestamps?: boolean;
|
|
28
|
+
};
|
|
29
|
+
validation?: {
|
|
30
|
+
strict?: boolean;
|
|
31
|
+
validateTemplates?: boolean;
|
|
32
|
+
validateVariables?: boolean;
|
|
33
|
+
};
|
|
34
|
+
plugins?: string[];
|
|
35
|
+
helpers?: string | Record<string, Function>;
|
|
36
|
+
/** AI integration configuration */
|
|
37
|
+
ai?: AiServiceConfig;
|
|
38
|
+
environments?: Record<string, Partial<HypergenConfig>>;
|
|
39
|
+
}
|
|
40
|
+
export interface ResolvedConfig {
|
|
41
|
+
configPath: string;
|
|
42
|
+
projectRoot: string;
|
|
43
|
+
environment: string;
|
|
44
|
+
loadedHelpers: Record<string, Function>;
|
|
45
|
+
templates: string[];
|
|
46
|
+
discovery: {
|
|
47
|
+
sources?: ("local" | "npm" | "workspace" | "github" | "git")[];
|
|
48
|
+
directories?: string[];
|
|
49
|
+
exclude?: string[];
|
|
50
|
+
};
|
|
51
|
+
engine: {
|
|
52
|
+
cache?: boolean;
|
|
53
|
+
};
|
|
54
|
+
output: {
|
|
55
|
+
conflictStrategy?: "fail" | "overwrite" | "skip" | "merge";
|
|
56
|
+
createDirectories?: boolean;
|
|
57
|
+
preserveTimestamps?: boolean;
|
|
58
|
+
};
|
|
59
|
+
validation: {
|
|
60
|
+
strict?: boolean;
|
|
61
|
+
validateTemplates?: boolean;
|
|
62
|
+
validateVariables?: boolean;
|
|
63
|
+
};
|
|
64
|
+
plugins: string[];
|
|
65
|
+
helpers: string | Record<string, Function>;
|
|
66
|
+
ai?: AiServiceConfig;
|
|
67
|
+
environments: Record<string, Partial<HypergenConfig>>;
|
|
68
|
+
}
|
|
69
|
+
export interface ConfigLoaderOptions {
|
|
70
|
+
/**
|
|
71
|
+
* Callback invoked when helpers are loaded from config.
|
|
72
|
+
* Allows consumers to register helpers with their template engine.
|
|
73
|
+
*/
|
|
74
|
+
onHelpersLoaded?: (helpers: Record<string, Function>, source: string) => void;
|
|
75
|
+
}
|
|
76
|
+
export declare class HypergenConfigLoader {
|
|
77
|
+
private static readonly DEFAULT_CONFIG;
|
|
78
|
+
/**
|
|
79
|
+
* Load configuration from various sources using cosmiconfig
|
|
80
|
+
*/
|
|
81
|
+
static loadConfig(configPath?: string, projectRoot?: string, environment?: string, options?: ConfigLoaderOptions): Promise<ResolvedConfig>;
|
|
82
|
+
/**
|
|
83
|
+
* Merge configuration objects
|
|
84
|
+
*/
|
|
85
|
+
private static mergeConfig;
|
|
86
|
+
/**
|
|
87
|
+
* Validate configuration
|
|
88
|
+
*/
|
|
89
|
+
static validateConfig(config: HypergenConfig): {
|
|
90
|
+
valid: boolean;
|
|
91
|
+
errors: string[];
|
|
92
|
+
};
|
|
93
|
+
/**
|
|
94
|
+
* Generate default configuration file
|
|
95
|
+
*/
|
|
96
|
+
static generateDefaultConfig(format?: "js" | "json"): string;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Create a new configuration file
|
|
100
|
+
*/
|
|
101
|
+
export declare function createConfigFile(projectRoot: string, format?: "js" | "json"): Promise<string>;
|
|
102
|
+
/**
|
|
103
|
+
* Search upward from startDir for the nearest hyper config file.
|
|
104
|
+
* Returns the directory containing the config, or null if none found.
|
|
105
|
+
*/
|
|
106
|
+
export declare function findHyperConfigDir(startDir?: string): Promise<string | null>;
|
|
107
|
+
/**
|
|
108
|
+
* Get configuration information
|
|
109
|
+
*/
|
|
110
|
+
export declare function getConfigInfo(config: ResolvedConfig): {
|
|
111
|
+
source: string;
|
|
112
|
+
templates: string[];
|
|
113
|
+
environment: string;
|
|
114
|
+
pluginCount: number;
|
|
115
|
+
helperCount: number;
|
|
116
|
+
};
|
|
117
|
+
//# sourceMappingURL=config-loader.d.ts.map
|
|
@@ -0,0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
|
|
6
|
+
import fs from "node:fs";
|
|
7
|
+
import path from "node:path";
|
|
8
|
+
import { cosmiconfig } from "cosmiconfig";
|
|
9
|
+
import { ErrorCode, ErrorHandler } from "#errors/hypergen-errors";
|
|
10
|
+
import { loadHelpers } from "./load-helpers.js";
|
|
11
|
+
const DEFAULT_TEMPLATE_DIRECTORY = "templates";
|
|
12
|
+
export class HypergenConfigLoader {
|
|
13
|
+
static DEFAULT_CONFIG = {
|
|
14
|
+
templates: [DEFAULT_TEMPLATE_DIRECTORY],
|
|
15
|
+
discovery: {
|
|
16
|
+
sources: ["local", "npm", "workspace"],
|
|
17
|
+
directories: [DEFAULT_TEMPLATE_DIRECTORY, "cookbooks"],
|
|
18
|
+
exclude: ["node_modules", ".git", "dist", "build"],
|
|
19
|
+
},
|
|
20
|
+
engine: {
|
|
21
|
+
cache: false,
|
|
22
|
+
},
|
|
23
|
+
output: {
|
|
24
|
+
conflictStrategy: "fail",
|
|
25
|
+
createDirectories: true,
|
|
26
|
+
preserveTimestamps: false,
|
|
27
|
+
},
|
|
28
|
+
validation: {
|
|
29
|
+
strict: true,
|
|
30
|
+
validateTemplates: true,
|
|
31
|
+
validateVariables: true,
|
|
32
|
+
},
|
|
33
|
+
plugins: [],
|
|
34
|
+
helpers: {},
|
|
35
|
+
environments: {},
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Load configuration from various sources using cosmiconfig
|
|
39
|
+
*/
|
|
40
|
+
static async loadConfig(configPath, projectRoot = process.cwd(), environment = process.env.NODE_ENV || "development", options) {
|
|
41
|
+
let config = {};
|
|
42
|
+
let actualConfigPath = null;
|
|
43
|
+
try {
|
|
44
|
+
const explorer = cosmiconfig("hyper", {
|
|
45
|
+
searchPlaces: [
|
|
46
|
+
"hyper.config.js",
|
|
47
|
+
"hyper.config.mjs",
|
|
48
|
+
"hyper.config.cjs",
|
|
49
|
+
"hyper.config.json",
|
|
50
|
+
".hyperrc",
|
|
51
|
+
".hyperrc.json",
|
|
52
|
+
],
|
|
53
|
+
stopDir: path.dirname(projectRoot), // Stop searching at project root's parent
|
|
54
|
+
});
|
|
55
|
+
let result;
|
|
56
|
+
// 1. Try explicit config path first
|
|
57
|
+
if (configPath) {
|
|
58
|
+
if (fs.existsSync(configPath)) {
|
|
59
|
+
result = await explorer.load(configPath);
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
throw ErrorHandler.createError(ErrorCode.CONFIG_FILE_NOT_FOUND, `Configuration file not found: ${configPath}`, { file: configPath });
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
// 2. Auto-detect using cosmiconfig (searches from projectRoot upwards)
|
|
67
|
+
result = await explorer.search(projectRoot);
|
|
68
|
+
}
|
|
69
|
+
if (result) {
|
|
70
|
+
config = result.config;
|
|
71
|
+
actualConfigPath = result.filepath;
|
|
72
|
+
}
|
|
73
|
+
// Merge with default config
|
|
74
|
+
const mergedConfig = HypergenConfigLoader.mergeConfig(HypergenConfigLoader.DEFAULT_CONFIG, config);
|
|
75
|
+
// Apply environment-specific settings
|
|
76
|
+
if (mergedConfig.environments?.[environment]) {
|
|
77
|
+
const envConfig = mergedConfig.environments[environment];
|
|
78
|
+
Object.assign(mergedConfig, HypergenConfigLoader.mergeConfig(mergedConfig, envConfig));
|
|
79
|
+
}
|
|
80
|
+
// Load helpers and invoke callback if provided
|
|
81
|
+
const loadedHelpers = await loadHelpers(mergedConfig.helpers, projectRoot);
|
|
82
|
+
if (Object.keys(loadedHelpers).length > 0 && options?.onHelpersLoaded) {
|
|
83
|
+
options.onHelpersLoaded(loadedHelpers, "config:hyper.config");
|
|
84
|
+
}
|
|
85
|
+
// Determine the base directory for resolving relative paths
|
|
86
|
+
// If config was found, use its directory; otherwise use projectRoot
|
|
87
|
+
const configDir = actualConfigPath ? path.dirname(actualConfigPath) : projectRoot;
|
|
88
|
+
// Resolve paths
|
|
89
|
+
const resolvedConfig = {
|
|
90
|
+
...mergedConfig,
|
|
91
|
+
configPath: actualConfigPath || "default",
|
|
92
|
+
projectRoot,
|
|
93
|
+
environment,
|
|
94
|
+
loadedHelpers,
|
|
95
|
+
};
|
|
96
|
+
// Resolve template paths relative to config file directory
|
|
97
|
+
resolvedConfig.templates = resolvedConfig.templates.map((templatePath) => {
|
|
98
|
+
if (path.isAbsolute(templatePath)) {
|
|
99
|
+
return templatePath;
|
|
100
|
+
}
|
|
101
|
+
return path.resolve(configDir, templatePath);
|
|
102
|
+
});
|
|
103
|
+
return resolvedConfig;
|
|
104
|
+
}
|
|
105
|
+
catch (error) {
|
|
106
|
+
if (error.code === "ENOENT") {
|
|
107
|
+
throw ErrorHandler.createError(ErrorCode.CONFIG_FILE_NOT_FOUND, `Configuration file not found: ${error.path}`, { file: error.path });
|
|
108
|
+
}
|
|
109
|
+
if (error.name === "SyntaxError" || error.message.includes("JSON Parse error")) {
|
|
110
|
+
throw ErrorHandler.createError(ErrorCode.CONFIG_INVALID_FORMAT, `Invalid configuration file syntax: ${error.message}`, { file: actualConfigPath || "unknown" });
|
|
111
|
+
}
|
|
112
|
+
throw error;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Merge configuration objects
|
|
117
|
+
*/
|
|
118
|
+
static mergeConfig(base, override) {
|
|
119
|
+
const merged = { ...base };
|
|
120
|
+
for (const [key, value] of Object.entries(override)) {
|
|
121
|
+
if (value === undefined)
|
|
122
|
+
continue;
|
|
123
|
+
if (key === "templates" && Array.isArray(value)) {
|
|
124
|
+
// Replace templates instead of merging
|
|
125
|
+
merged.templates = value;
|
|
126
|
+
}
|
|
127
|
+
else if (typeof value === "object" && value !== null && !Array.isArray(value)) {
|
|
128
|
+
merged[key] = {
|
|
129
|
+
...merged[key],
|
|
130
|
+
...value,
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
merged[key] = value;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
return merged;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Validate configuration
|
|
141
|
+
*/
|
|
142
|
+
static validateConfig(config) {
|
|
143
|
+
const errors = [];
|
|
144
|
+
// Validate templates
|
|
145
|
+
if (config.templates && !Array.isArray(config.templates)) {
|
|
146
|
+
errors.push("templates must be an array of strings");
|
|
147
|
+
}
|
|
148
|
+
// Validate discovery sources
|
|
149
|
+
if (config.discovery?.sources) {
|
|
150
|
+
const validSources = ["local", "npm", "workspace", "github", "git"];
|
|
151
|
+
const invalidSources = config.discovery.sources.filter((source) => !validSources.includes(source));
|
|
152
|
+
if (invalidSources.length > 0) {
|
|
153
|
+
errors.push(`Invalid discovery sources: ${invalidSources.join(", ")}`);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
// Validate conflict strategy
|
|
157
|
+
if (config.output?.conflictStrategy) {
|
|
158
|
+
const validStrategies = ["fail", "overwrite", "skip", "merge"];
|
|
159
|
+
if (!validStrategies.includes(config.output.conflictStrategy)) {
|
|
160
|
+
errors.push(`Invalid conflict strategy: ${config.output.conflictStrategy}`);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
return {
|
|
164
|
+
valid: errors.length === 0,
|
|
165
|
+
errors,
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Generate default configuration file
|
|
170
|
+
*/
|
|
171
|
+
static generateDefaultConfig(format = "js") {
|
|
172
|
+
if (format === "json") {
|
|
173
|
+
return JSON.stringify(HypergenConfigLoader.DEFAULT_CONFIG, null, 2);
|
|
174
|
+
}
|
|
175
|
+
return `/**
|
|
176
|
+
* HyperDev Configuration
|
|
177
|
+
*
|
|
178
|
+
* @type {import('@hypercli/core').HypergenConfig}
|
|
179
|
+
*/
|
|
180
|
+
export default {
|
|
181
|
+
// Template directories to search
|
|
182
|
+
templates: ['.hyper/recipes'],
|
|
183
|
+
|
|
184
|
+
// Generator discovery options
|
|
185
|
+
discovery: {
|
|
186
|
+
sources: ['local', 'npm', 'workspace'],
|
|
187
|
+
directories: ['templates', 'cookbooks'],
|
|
188
|
+
exclude: ['node_modules', '.git', 'dist', 'build']
|
|
189
|
+
},
|
|
190
|
+
|
|
191
|
+
// Template engine configuration (Jig)
|
|
192
|
+
engine: {
|
|
193
|
+
cache: false
|
|
194
|
+
},
|
|
195
|
+
|
|
196
|
+
// Output handling
|
|
197
|
+
output: {
|
|
198
|
+
conflictStrategy: 'fail', // fail | overwrite | skip | merge
|
|
199
|
+
createDirectories: true,
|
|
200
|
+
preserveTimestamps: false
|
|
201
|
+
},
|
|
202
|
+
|
|
203
|
+
// Validation options
|
|
204
|
+
validation: {
|
|
205
|
+
strict: true,
|
|
206
|
+
validateTemplates: true,
|
|
207
|
+
validateVariables: true
|
|
208
|
+
},
|
|
209
|
+
|
|
210
|
+
// AI integration
|
|
211
|
+
ai: {
|
|
212
|
+
// stdout: prints prompt to stdout for AI agents (e.g. Claude Code) to resolve
|
|
213
|
+
mode: 'stdout',
|
|
214
|
+
|
|
215
|
+
// api: call LLM directly via Vercel AI SDK
|
|
216
|
+
// mode: 'api',
|
|
217
|
+
// provider: 'anthropic',
|
|
218
|
+
// model: 'claude-sonnet-4-5',
|
|
219
|
+
// apiKeyEnvVar: 'ANTHROPIC_API_KEY',
|
|
220
|
+
|
|
221
|
+
// command: pipe prompt to a CLI command
|
|
222
|
+
// mode: 'command',
|
|
223
|
+
// command: 'claude -p {prompt}',
|
|
224
|
+
},
|
|
225
|
+
|
|
226
|
+
// Plugins to load
|
|
227
|
+
plugins: [],
|
|
228
|
+
|
|
229
|
+
// Custom helper functions
|
|
230
|
+
helpers: {},
|
|
231
|
+
|
|
232
|
+
// Environment-specific configuration
|
|
233
|
+
environments: {
|
|
234
|
+
development: {
|
|
235
|
+
validation: {
|
|
236
|
+
strict: false
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
`;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* Create a new configuration file
|
|
246
|
+
*/
|
|
247
|
+
export async function createConfigFile(projectRoot, format = "js") {
|
|
248
|
+
const fileName = format === "json" ? "hyper.config.json" : "hyper.config.js";
|
|
249
|
+
const configPath = path.join(projectRoot, fileName);
|
|
250
|
+
if (fs.existsSync(configPath)) {
|
|
251
|
+
throw ErrorHandler.createError(ErrorCode.FILE_ALREADY_EXISTS, `Configuration file already exists: ${configPath}`, { file: configPath });
|
|
252
|
+
}
|
|
253
|
+
const content = HypergenConfigLoader.generateDefaultConfig(format);
|
|
254
|
+
fs.writeFileSync(configPath, content, "utf-8");
|
|
255
|
+
return configPath;
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* Search upward from startDir for the nearest hyper config file.
|
|
259
|
+
* Returns the directory containing the config, or null if none found.
|
|
260
|
+
*/
|
|
261
|
+
export async function findHyperConfigDir(startDir = process.cwd()) {
|
|
262
|
+
const explorer = cosmiconfig("hyper", {
|
|
263
|
+
searchPlaces: [
|
|
264
|
+
"hyper.config.js",
|
|
265
|
+
"hyper.config.mjs",
|
|
266
|
+
"hyper.config.cjs",
|
|
267
|
+
"hyper.config.json",
|
|
268
|
+
".hyperrc",
|
|
269
|
+
".hyperrc.json",
|
|
270
|
+
],
|
|
271
|
+
});
|
|
272
|
+
const result = await explorer.search(startDir);
|
|
273
|
+
return result ? path.dirname(result.filepath) : null;
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* Get configuration information
|
|
277
|
+
*/
|
|
278
|
+
export function getConfigInfo(config) {
|
|
279
|
+
return {
|
|
280
|
+
source: config.configPath,
|
|
281
|
+
templates: config.templates,
|
|
282
|
+
environment: config.environment,
|
|
283
|
+
pluginCount: config.plugins.length,
|
|
284
|
+
helperCount: Object.keys(config.loadedHelpers).length,
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
//# sourceMappingURL=config-loader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config-loader.js","sourceRoot":"","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AC;AACtD,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,aAAa,CAAC,MAAsB;IAOnD,OAAO;QACN,MAAM,EAAE,MAAM,CAAC,UAAU;QACzB,SAAS,EAAE,MAAM,CAAC,SAAS;QAC3B,WAAW,EAAE,MAAM,CAAC,WAAW;QAC/B,WAAW,EAAE,MAAM,CAAC,OAAO,CAAC,MAAM;QAClC,WAAW,EAAE,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC,MAAM;KACrD,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration System
|
|
3
|
+
*
|
|
4
|
+
* Provides configuration loading and helper management for hypergen projects
|
|
5
|
+
*/
|
|
6
|
+
export type { HypergenConfig, ResolvedConfig, AiServiceConfig, ConfigLoaderOptions, } from "./config-loader.js";
|
|
7
|
+
export { HypergenConfigLoader, createConfigFile, findHyperConfigDir, getConfigInfo, } from "./config-loader.js";
|
|
8
|
+
export { loadHelpers } from "./load-helpers.js";
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/config/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,YAAY,EACX,cAAc,EACd,cAAc,EACd,eAAe,EACf,mBAAmB,GACnB,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EACN,oBAAoB,EACpB,gBAAgB,EAChB,kBAAkB,EAClB,aAAa,GACb,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration System
|
|
3
|
+
*
|
|
4
|
+
* Provides configuration loading and helper management for hypergen projects
|
|
5
|
+
*/
|
|
6
|
+
export { HypergenConfigLoader, createConfigFile, findHyperConfigDir, getConfigInfo, } from "./config-loader.js";
|
|
7
|
+
export { loadHelpers } from "./load-helpers.js";
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/config/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AASH,OAAO,EACN,oBAAoB,EACpB,gBAAgB,EAChB,kBAAkB,EAClB,aAAa,GACb,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared helper loading utility
|
|
3
|
+
*
|
|
4
|
+
* Loads helper functions from a file path, directory, or plain object.
|
|
5
|
+
* Used by HypergenConfigLoader, kit-parser, and cookbook-parser.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Load helpers from a file path, directory, or object.
|
|
9
|
+
* Resolves relative paths against baseDir.
|
|
10
|
+
* Returns Record<string, Function>.
|
|
11
|
+
*/
|
|
12
|
+
export declare function loadHelpers(helpers: string | Record<string, Function> | undefined, baseDir: string): Promise<Record<string, Function>>;
|
|
13
|
+
//# sourceMappingURL=load-helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"load-helpers.d.ts","sourceRoot":"","sources":["../../src/config/load-helpers.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAMH;;;;GAIG;AACH,wBAAsB,WAAW,CAChC,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,GAAG,SAAS,EACtD,OAAO,EAAE,MAAM,GACb,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,CAqDnC"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared helper loading utility
|
|
3
|
+
*
|
|
4
|
+
* Loads helper functions from a file path, directory, or plain object.
|
|
5
|
+
* Used by HypergenConfigLoader, kit-parser, and cookbook-parser.
|
|
6
|
+
*/
|
|
7
|
+
import fs from "node:fs";
|
|
8
|
+
import path from "node:path";
|
|
9
|
+
import { pathToFileURL } from "node:url";
|
|
10
|
+
/**
|
|
11
|
+
* Load helpers from a file path, directory, or object.
|
|
12
|
+
* Resolves relative paths against baseDir.
|
|
13
|
+
* Returns Record<string, Function>.
|
|
14
|
+
*/
|
|
15
|
+
export async function loadHelpers(helpers, baseDir) {
|
|
16
|
+
if (!helpers)
|
|
17
|
+
return {};
|
|
18
|
+
if (typeof helpers === "string") {
|
|
19
|
+
// Load helpers from file or directory
|
|
20
|
+
let helpersPath = path.isAbsolute(helpers) ? helpers : path.resolve(baseDir, helpers);
|
|
21
|
+
try {
|
|
22
|
+
// Check if path is a directory
|
|
23
|
+
if (fs.existsSync(helpersPath)) {
|
|
24
|
+
const stats = fs.statSync(helpersPath);
|
|
25
|
+
if (stats.isDirectory()) {
|
|
26
|
+
// Try index.ts, index.js, index.mjs, index.cjs
|
|
27
|
+
const indexFiles = ["index.ts", "index.js", "index.mjs", "index.cjs"];
|
|
28
|
+
let found = false;
|
|
29
|
+
for (const indexFile of indexFiles) {
|
|
30
|
+
const indexPath = path.join(helpersPath, indexFile);
|
|
31
|
+
if (fs.existsSync(indexPath)) {
|
|
32
|
+
helpersPath = indexPath;
|
|
33
|
+
found = true;
|
|
34
|
+
break;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
if (!found) {
|
|
38
|
+
console.warn(`Warning: Could not find index file in helpers directory ${helpersPath}`);
|
|
39
|
+
return {};
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
// Check if the resolved file exists
|
|
44
|
+
if (!fs.existsSync(helpersPath)) {
|
|
45
|
+
console.warn(`Warning: Could not load helpers from ${helpersPath} (file not found)`);
|
|
46
|
+
return {};
|
|
47
|
+
}
|
|
48
|
+
const fileUrl = pathToFileURL(helpersPath).href;
|
|
49
|
+
const module = await import(fileUrl);
|
|
50
|
+
const loaded = module.default || module;
|
|
51
|
+
// Ensure we return a plain object with own properties
|
|
52
|
+
// to avoid prototype chain issues when spreading
|
|
53
|
+
return { ...loaded };
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
console.warn(`Warning: Could not load helpers from ${helpersPath}`);
|
|
57
|
+
console.warn(` Error: ${error instanceof Error ? error.message : String(error)}`);
|
|
58
|
+
return {};
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
else if (typeof helpers === "object") {
|
|
62
|
+
// Use provided helpers object
|
|
63
|
+
return helpers;
|
|
64
|
+
}
|
|
65
|
+
return {};
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=load-helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"load-helpers.js","sourceRoot":"","sources":["../../src/config/load-helpers.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAChC,OAAsD,EACtD,OAAe;IAEf,IAAI,CAAC,OAAO;QAAE,OAAO,EAAE,CAAC;IAExB,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;QACjC,sCAAsC;QACtC,IAAI,WAAW,GAAG,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QAEtF,IAAI,CAAC;YACJ,+BAA+B;YAC/B,IAAI,EAAE,CAAC,UAAU,CAAC,WAAW,CAAC,EAAE,CAAC;gBAChC,MAAM,KAAK,GAAG,EAAE,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;gBACvC,IAAI,KAAK,CAAC,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K,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;YACnF,OAAO,EAAE,CAAC;QACX,CAAC;IACF,CAAC;SAAM,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;QACxC,8BAA8B;QAC9B,OAAO,OAAO,CAAC;IAChB,CAAC;IAED,OAAO,EAAE,CAAC;AACX,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,gBAAgB,eAAe,CAAC;AAC7C,eAAO,MAAM,cAAc,aAAa,CAAC;AACzC,eAAO,MAAM,0BAA0B,cAAc,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,gBAAgB,GAAG,YAAY,CAAC;AAC7C,MAAM,CAAC,MAAM,cAAc,GAAG,UAAU,CAAC;AACzC,MAAM,CAAC,MAAM,0BAA0B,GAAG,WAAW,CAAC"}
|