@dcyfr/ai-code-gen 0.1.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/LICENSE +21 -0
- package/README.md +469 -0
- package/dist/ai/code-gen.d.ts +60 -0
- package/dist/ai/code-gen.d.ts.map +1 -0
- package/dist/ai/code-gen.js +164 -0
- package/dist/ai/code-gen.js.map +1 -0
- package/dist/ai/index.d.ts +8 -0
- package/dist/ai/index.d.ts.map +1 -0
- package/dist/ai/index.js +7 -0
- package/dist/ai/index.js.map +1 -0
- package/dist/ai/prompts.d.ts +32 -0
- package/dist/ai/prompts.d.ts.map +1 -0
- package/dist/ai/prompts.js +96 -0
- package/dist/ai/prompts.js.map +1 -0
- package/dist/ai/provider.d.ts +34 -0
- package/dist/ai/provider.d.ts.map +1 -0
- package/dist/ai/provider.js +76 -0
- package/dist/ai/provider.js.map +1 -0
- package/dist/ast/analyzer.d.ts +34 -0
- package/dist/ast/analyzer.d.ts.map +1 -0
- package/dist/ast/analyzer.js +159 -0
- package/dist/ast/analyzer.js.map +1 -0
- package/dist/ast/index.d.ts +9 -0
- package/dist/ast/index.d.ts.map +1 -0
- package/dist/ast/index.js +8 -0
- package/dist/ast/index.js.map +1 -0
- package/dist/ast/parser.d.ts +16 -0
- package/dist/ast/parser.d.ts.map +1 -0
- package/dist/ast/parser.js +280 -0
- package/dist/ast/parser.js.map +1 -0
- package/dist/ast/printer.d.ts +51 -0
- package/dist/ast/printer.d.ts.map +1 -0
- package/dist/ast/printer.js +126 -0
- package/dist/ast/printer.js.map +1 -0
- package/dist/ast/transformer.d.ts +11 -0
- package/dist/ast/transformer.d.ts.map +1 -0
- package/dist/ast/transformer.js +194 -0
- package/dist/ast/transformer.js.map +1 -0
- package/dist/cli.d.ts +15 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +284 -0
- package/dist/cli.js.map +1 -0
- package/dist/generators/api-route.d.ts +14 -0
- package/dist/generators/api-route.d.ts.map +1 -0
- package/dist/generators/api-route.js +82 -0
- package/dist/generators/api-route.js.map +1 -0
- package/dist/generators/base.d.ts +29 -0
- package/dist/generators/base.d.ts.map +1 -0
- package/dist/generators/base.js +89 -0
- package/dist/generators/base.js.map +1 -0
- package/dist/generators/component.d.ts +14 -0
- package/dist/generators/component.d.ts.map +1 -0
- package/dist/generators/component.js +77 -0
- package/dist/generators/component.js.map +1 -0
- package/dist/generators/index.d.ts +10 -0
- package/dist/generators/index.d.ts.map +1 -0
- package/dist/generators/index.js +10 -0
- package/dist/generators/index.js.map +1 -0
- package/dist/generators/model.d.ts +14 -0
- package/dist/generators/model.d.ts.map +1 -0
- package/dist/generators/model.js +89 -0
- package/dist/generators/model.js.map +1 -0
- package/dist/generators/registry.d.ts +42 -0
- package/dist/generators/registry.d.ts.map +1 -0
- package/dist/generators/registry.js +84 -0
- package/dist/generators/registry.js.map +1 -0
- package/dist/generators/test.d.ts +13 -0
- package/dist/generators/test.d.ts.map +1 -0
- package/dist/generators/test.js +39 -0
- package/dist/generators/test.js.map +1 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +20 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/config.d.ts +16 -0
- package/dist/lib/config.d.ts.map +1 -0
- package/dist/lib/config.js +52 -0
- package/dist/lib/config.js.map +1 -0
- package/dist/lib/file-system.d.ts +30 -0
- package/dist/lib/file-system.d.ts.map +1 -0
- package/dist/lib/file-system.js +71 -0
- package/dist/lib/file-system.js.map +1 -0
- package/dist/lib/logger.d.ts +17 -0
- package/dist/lib/logger.d.ts.map +1 -0
- package/dist/lib/logger.js +43 -0
- package/dist/lib/logger.js.map +1 -0
- package/dist/lib/strings.d.ts +41 -0
- package/dist/lib/strings.d.ts.map +1 -0
- package/dist/lib/strings.js +92 -0
- package/dist/lib/strings.js.map +1 -0
- package/dist/templates/builtins.d.ts +13 -0
- package/dist/templates/builtins.d.ts.map +1 -0
- package/dist/templates/builtins.js +275 -0
- package/dist/templates/builtins.js.map +1 -0
- package/dist/templates/engine.d.ts +69 -0
- package/dist/templates/engine.d.ts.map +1 -0
- package/dist/templates/engine.js +154 -0
- package/dist/templates/engine.js.map +1 -0
- package/dist/templates/index.d.ts +6 -0
- package/dist/templates/index.d.ts.map +1 -0
- package/dist/templates/index.js +6 -0
- package/dist/templates/index.js.map +1 -0
- package/dist/types/index.d.ts +401 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +7 -0
- package/dist/types/index.js.map +1 -0
- package/package.json +80 -0
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @dcyfr/ai-code-gen - Configuration management
|
|
3
|
+
*/
|
|
4
|
+
/** Default configuration */
|
|
5
|
+
const DEFAULT_CONFIG = {
|
|
6
|
+
outputDir: './generated',
|
|
7
|
+
templatePaths: ['./templates'],
|
|
8
|
+
formatOutput: true,
|
|
9
|
+
addJsdoc: true,
|
|
10
|
+
generators: {},
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Load configuration from a partial config object, merging with defaults.
|
|
14
|
+
*/
|
|
15
|
+
export function loadConfig(partial = {}) {
|
|
16
|
+
return {
|
|
17
|
+
...DEFAULT_CONFIG,
|
|
18
|
+
...partial,
|
|
19
|
+
templatePaths: partial.templatePaths ?? DEFAULT_CONFIG.templatePaths,
|
|
20
|
+
generators: {
|
|
21
|
+
...DEFAULT_CONFIG.generators,
|
|
22
|
+
...partial.generators,
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Validate configuration.
|
|
28
|
+
*/
|
|
29
|
+
export function validateConfig(config) {
|
|
30
|
+
const errors = [];
|
|
31
|
+
if (!config.outputDir) {
|
|
32
|
+
errors.push('outputDir is required');
|
|
33
|
+
}
|
|
34
|
+
if (!config.templatePaths || config.templatePaths.length === 0) {
|
|
35
|
+
errors.push('At least one templatePath is required');
|
|
36
|
+
}
|
|
37
|
+
if (config.ai) {
|
|
38
|
+
if (!config.ai.provider) {
|
|
39
|
+
errors.push('AI provider is required when ai config is provided');
|
|
40
|
+
}
|
|
41
|
+
if (!config.ai.model) {
|
|
42
|
+
errors.push('AI model is required when ai config is provided');
|
|
43
|
+
}
|
|
44
|
+
if (config.ai.temperature !== undefined) {
|
|
45
|
+
if (config.ai.temperature < 0 || config.ai.temperature > 1) {
|
|
46
|
+
errors.push('AI temperature must be between 0 and 1');
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return { valid: errors.length === 0, errors };
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/lib/config.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,4BAA4B;AAC5B,MAAM,cAAc,GAAkB;IACpC,SAAS,EAAE,aAAa;IACxB,aAAa,EAAE,CAAC,aAAa,CAAC;IAC9B,YAAY,EAAE,IAAI;IAClB,QAAQ,EAAE,IAAI;IACd,UAAU,EAAE,EAAE;CACf,CAAC;AAEF;;GAEG;AACH,MAAM,UAAU,UAAU,CAAC,UAAkC,EAAE;IAC7D,OAAO;QACL,GAAG,cAAc;QACjB,GAAG,OAAO;QACV,aAAa,EAAE,OAAO,CAAC,aAAa,IAAI,cAAc,CAAC,aAAa;QACpE,UAAU,EAAE;YACV,GAAG,cAAc,CAAC,UAAU;YAC5B,GAAG,OAAO,CAAC,UAAU;SACtB;KACF,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,cAAc,CAAC,MAAqB;IAClD,MAAM,MAAM,GAAa,EAAE,CAAC;IAE5B,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE,CAAC;QACtB,MAAM,CAAC,IAAI,CAAC,uBAAuB,CAAC,CAAC;IACvC,CAAC;IAED,IAAI,CAAC,MAAM,CAAC,aAAa,IAAI,MAAM,CAAC,aAAa,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC/D,MAAM,CAAC,IAAI,CAAC,uCAAuC,CAAC,CAAC;IACvD,CAAC;IAED,IAAI,MAAM,CAAC,EAAE,EAAE,CAAC;QACd,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,QAAQ,EAAE,CAAC;YACxB,MAAM,CAAC,IAAI,CAAC,oDAAoD,CAAC,CAAC;QACpE,CAAC;QACD,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC;YACrB,MAAM,CAAC,IAAI,CAAC,iDAAiD,CAAC,CAAC;QACjE,CAAC;QACD,IAAI,MAAM,CAAC,EAAE,CAAC,WAAW,KAAK,SAAS,EAAE,CAAC;YACxC,IAAI,MAAM,CAAC,EAAE,CAAC,WAAW,GAAG,CAAC,IAAI,MAAM,CAAC,EAAE,CAAC,WAAW,GAAG,CAAC,EAAE,CAAC;gBAC3D,MAAM,CAAC,IAAI,CAAC,wCAAwC,CAAC,CAAC;YACxD,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;AAChD,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @dcyfr/ai-code-gen - File system utilities
|
|
3
|
+
*/
|
|
4
|
+
import type { GeneratedFile } from '../types/index.js';
|
|
5
|
+
/**
|
|
6
|
+
* Ensure a directory exists, creating parent directories as needed.
|
|
7
|
+
*/
|
|
8
|
+
export declare function ensureDir(dirPath: string): void;
|
|
9
|
+
/**
|
|
10
|
+
* Write a generated file, creating directories as needed.
|
|
11
|
+
* Returns true if the file was written, false if skipped.
|
|
12
|
+
*/
|
|
13
|
+
export declare function writeGeneratedFile(baseDir: string, file: GeneratedFile, force?: boolean): boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Read file contents from disk.
|
|
16
|
+
*/
|
|
17
|
+
export declare function readFileContents(filePath: string): string;
|
|
18
|
+
/**
|
|
19
|
+
* Check if a file exists.
|
|
20
|
+
*/
|
|
21
|
+
export declare function fileExists(filePath: string): boolean;
|
|
22
|
+
/**
|
|
23
|
+
* List all TypeScript files in a directory recursively.
|
|
24
|
+
*/
|
|
25
|
+
export declare function listTypeScriptFiles(dirPath: string): string[];
|
|
26
|
+
/**
|
|
27
|
+
* Get the relative path from base to target.
|
|
28
|
+
*/
|
|
29
|
+
export declare function getRelativePath(basePath: string, targetPath: string): string;
|
|
30
|
+
//# sourceMappingURL=file-system.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file-system.d.ts","sourceRoot":"","sources":["../../src/lib/file-system.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAEvD;;GAEG;AACH,wBAAgB,SAAS,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAI/C;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,aAAa,EACnB,KAAK,UAAQ,GACZ,OAAO,CAYT;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAEzD;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAEpD;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE,CAwB7D;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,CAE5E"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @dcyfr/ai-code-gen - File system utilities
|
|
3
|
+
*/
|
|
4
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync, readdirSync, statSync } from 'node:fs';
|
|
5
|
+
import { dirname, join, relative, resolve } from 'node:path';
|
|
6
|
+
/**
|
|
7
|
+
* Ensure a directory exists, creating parent directories as needed.
|
|
8
|
+
*/
|
|
9
|
+
export function ensureDir(dirPath) {
|
|
10
|
+
if (!existsSync(dirPath)) {
|
|
11
|
+
mkdirSync(dirPath, { recursive: true });
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Write a generated file, creating directories as needed.
|
|
16
|
+
* Returns true if the file was written, false if skipped.
|
|
17
|
+
*/
|
|
18
|
+
export function writeGeneratedFile(baseDir, file, force = false) {
|
|
19
|
+
const fullPath = resolve(baseDir, file.path);
|
|
20
|
+
const dir = dirname(fullPath);
|
|
21
|
+
ensureDir(dir);
|
|
22
|
+
if (existsSync(fullPath) && !file.overwrite && !force) {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
writeFileSync(fullPath, file.content, 'utf-8');
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Read file contents from disk.
|
|
30
|
+
*/
|
|
31
|
+
export function readFileContents(filePath) {
|
|
32
|
+
return readFileSync(filePath, 'utf-8');
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Check if a file exists.
|
|
36
|
+
*/
|
|
37
|
+
export function fileExists(filePath) {
|
|
38
|
+
return existsSync(filePath);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* List all TypeScript files in a directory recursively.
|
|
42
|
+
*/
|
|
43
|
+
export function listTypeScriptFiles(dirPath) {
|
|
44
|
+
const results = [];
|
|
45
|
+
function walk(dir) {
|
|
46
|
+
if (!existsSync(dir))
|
|
47
|
+
return;
|
|
48
|
+
const entries = readdirSync(dir);
|
|
49
|
+
for (const entry of entries) {
|
|
50
|
+
const fullPath = join(dir, entry);
|
|
51
|
+
const stat = statSync(fullPath);
|
|
52
|
+
if (stat.isDirectory()) {
|
|
53
|
+
if (entry !== 'node_modules' && entry !== 'dist' && entry !== '.git') {
|
|
54
|
+
walk(fullPath);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
else if (entry.endsWith('.ts') || entry.endsWith('.tsx')) {
|
|
58
|
+
results.push(fullPath);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
walk(dirPath);
|
|
63
|
+
return results;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Get the relative path from base to target.
|
|
67
|
+
*/
|
|
68
|
+
export function getRelativePath(basePath, targetPath) {
|
|
69
|
+
return relative(basePath, targetPath);
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=file-system.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file-system.js","sourceRoot":"","sources":["../../src/lib/file-system.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,aAAa,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACpG,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAG7D;;GAEG;AACH,MAAM,UAAU,SAAS,CAAC,OAAe;IACvC,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC;QACzB,SAAS,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAC1C,CAAC;AACH,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,kBAAkB,CAChC,OAAe,EACf,IAAmB,EACnB,KAAK,GAAG,KAAK;IAEb,MAAM,QAAQ,GAAG,OAAO,CAAC,OAAO,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;IAC7C,MAAM,GAAG,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;IAE9B,SAAS,CAAC,GAAG,CAAC,CAAC;IAEf,IAAI,UAAU,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS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,OAAO,OAAO,CAAC;AACjB,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,eAAe,CAAC,QAAgB,EAAE,UAAkB;IAClE,OAAO,QAAQ,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;AACxC,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @dcyfr/ai-code-gen - Structured logger
|
|
3
|
+
*/
|
|
4
|
+
export type LogLevel = 'debug' | 'info' | 'warn' | 'error';
|
|
5
|
+
export interface Logger {
|
|
6
|
+
debug(message: string, data?: Record<string, unknown>): void;
|
|
7
|
+
info(message: string, data?: Record<string, unknown>): void;
|
|
8
|
+
warn(message: string, data?: Record<string, unknown>): void;
|
|
9
|
+
error(message: string, data?: Record<string, unknown>): void;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Create a structured logger with a given level threshold.
|
|
13
|
+
*/
|
|
14
|
+
export declare function createLogger(minLevel?: LogLevel, prefix?: string): Logger;
|
|
15
|
+
/** Silent logger for testing */
|
|
16
|
+
export declare function createSilentLogger(): Logger;
|
|
17
|
+
//# sourceMappingURL=logger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/lib/logger.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,MAAM,QAAQ,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;AAS3D,MAAM,WAAW,MAAM;IACrB,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;IAC7D,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;IAC5D,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;IAC5D,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;CAC9D;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,QAAQ,GAAE,QAAiB,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAyBjF;AAED,gCAAgC;AAChC,wBAAgB,kBAAkB,IAAI,MAAM,CAG3C"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @dcyfr/ai-code-gen - Structured logger
|
|
3
|
+
*/
|
|
4
|
+
const LOG_LEVELS = {
|
|
5
|
+
debug: 0,
|
|
6
|
+
info: 1,
|
|
7
|
+
warn: 2,
|
|
8
|
+
error: 3,
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Create a structured logger with a given level threshold.
|
|
12
|
+
*/
|
|
13
|
+
export function createLogger(minLevel = 'info', prefix) {
|
|
14
|
+
const threshold = LOG_LEVELS[minLevel];
|
|
15
|
+
const tag = prefix ? `[${prefix}]` : '';
|
|
16
|
+
function log(level, message, data) {
|
|
17
|
+
if (LOG_LEVELS[level] < threshold)
|
|
18
|
+
return;
|
|
19
|
+
const timestamp = new Date().toISOString();
|
|
20
|
+
const entry = `${timestamp} ${level.toUpperCase().padEnd(5)} ${tag} ${message}`;
|
|
21
|
+
if (level === 'error') {
|
|
22
|
+
console.error(entry, data ? JSON.stringify(data) : '');
|
|
23
|
+
}
|
|
24
|
+
else if (level === 'warn') {
|
|
25
|
+
console.warn(entry, data ? JSON.stringify(data) : '');
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
console.log(entry, data ? JSON.stringify(data) : '');
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return {
|
|
32
|
+
debug: (msg, data) => log('debug', msg, data),
|
|
33
|
+
info: (msg, data) => log('info', msg, data),
|
|
34
|
+
warn: (msg, data) => log('warn', msg, data),
|
|
35
|
+
error: (msg, data) => log('error', msg, data),
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
/** Silent logger for testing */
|
|
39
|
+
export function createSilentLogger() {
|
|
40
|
+
const noop = () => { };
|
|
41
|
+
return { debug: noop, info: noop, warn: noop, error: noop };
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/lib/logger.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,MAAM,UAAU,GAA6B;IAC3C,KAAK,EAAE,CAAC;IACR,IAAI,EAAE,CAAC;IACP,IAAI,EAAE,CAAC;IACP,KAAK,EAAE,CAAC;CACT,CAAC;AASF;;GAEG;AACH,MAAM,UAAU,YAAY,CAAC,WAAqB,MAAM,EAAE,MAAe;IACvE,MAAM,SAAS,GAAG,UAAU,CAAC,QAAQ,CAAC,CAAC;IACvC,MAAM,GAAG,GAAG,MAAM,CAAC,CAAC,CAAC,IAAI,MAAM,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;IAExC,SAAS,GAAG,CAAC,KAAe,EAAE,OAAe,EAAE,IAA8B;QAC3E,IAAI,UAAU,CAAC,KAAK,CAAC,GAAG,SAAS;YAAE,OAAO;QAE1C,MAAM,SAAS,GAAG,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;QAC3C,MAAM,KAAK,GAAG,GAAG,SAAS,IAAI,KAAK,CAAC,WAAW,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,GAAG,IAAI,OAAO,EAAE,CAAC;QAEhF,IAAI,KAAK,KAAK,OAAO,EAAE,CAAC;YACtB,OAAO,CAAC,KAAK,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAA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
|
+
* @example toPascalCase('user-profile') → 'UserProfile'
|
|
7
|
+
*/
|
|
8
|
+
export declare function toPascalCase(str: string): string;
|
|
9
|
+
/**
|
|
10
|
+
* Convert a string to camelCase.
|
|
11
|
+
* @example toCamelCase('user-profile') → 'userProfile'
|
|
12
|
+
*/
|
|
13
|
+
export declare function toCamelCase(str: string): string;
|
|
14
|
+
/**
|
|
15
|
+
* Convert a string to kebab-case.
|
|
16
|
+
* @example toKebabCase('UserProfile') → 'user-profile'
|
|
17
|
+
*/
|
|
18
|
+
export declare function toKebabCase(str: string): string;
|
|
19
|
+
/**
|
|
20
|
+
* Convert a string to snake_case.
|
|
21
|
+
* @example toSnakeCase('UserProfile') → 'user_profile'
|
|
22
|
+
*/
|
|
23
|
+
export declare function toSnakeCase(str: string): string;
|
|
24
|
+
/**
|
|
25
|
+
* Convert a string to CONSTANT_CASE.
|
|
26
|
+
* @example toConstantCase('UserProfile') → 'USER_PROFILE'
|
|
27
|
+
*/
|
|
28
|
+
export declare function toConstantCase(str: string): string;
|
|
29
|
+
/**
|
|
30
|
+
* Pluralize a simple English word (basic rules).
|
|
31
|
+
*/
|
|
32
|
+
export declare function pluralize(word: string): string;
|
|
33
|
+
/**
|
|
34
|
+
* Indent each line of a string by the given number of spaces.
|
|
35
|
+
*/
|
|
36
|
+
export declare function indent(str: string, spaces: number): string;
|
|
37
|
+
/**
|
|
38
|
+
* Strip leading whitespace from a template literal while preserving relative indentation.
|
|
39
|
+
*/
|
|
40
|
+
export declare function dedent(str: string): string;
|
|
41
|
+
//# sourceMappingURL=strings.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"strings.d.ts","sourceRoot":"","sources":["../../src/lib/strings.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;GAGG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAIhD;AAED;;;GAGG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAG/C;AAED;;;GAGG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAK/C;AAED;;;GAGG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAK/C;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAElD;AAED;;GAEG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAS9C;AAED;;GAEG;AACH,wBAAgB,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAM1D;AAED;;GAEG;AACH,wBAAgB,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAkB1C"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @dcyfr/ai-code-gen - String utilities for code generation
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Convert a string to PascalCase.
|
|
6
|
+
* @example toPascalCase('user-profile') → 'UserProfile'
|
|
7
|
+
*/
|
|
8
|
+
export function toPascalCase(str) {
|
|
9
|
+
return str
|
|
10
|
+
.replace(/[-_\s]+(.)?/g, (_, c) => (c ? c.toUpperCase() : ''))
|
|
11
|
+
.replace(/^(.)/, (_, c) => c.toUpperCase());
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Convert a string to camelCase.
|
|
15
|
+
* @example toCamelCase('user-profile') → 'userProfile'
|
|
16
|
+
*/
|
|
17
|
+
export function toCamelCase(str) {
|
|
18
|
+
const pascal = toPascalCase(str);
|
|
19
|
+
return pascal.charAt(0).toLowerCase() + pascal.slice(1);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Convert a string to kebab-case.
|
|
23
|
+
* @example toKebabCase('UserProfile') → 'user-profile'
|
|
24
|
+
*/
|
|
25
|
+
export function toKebabCase(str) {
|
|
26
|
+
return str
|
|
27
|
+
.replace(/([a-z])([A-Z])/g, '$1-$2')
|
|
28
|
+
.replace(/[\s_]+/g, '-')
|
|
29
|
+
.toLowerCase();
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Convert a string to snake_case.
|
|
33
|
+
* @example toSnakeCase('UserProfile') → 'user_profile'
|
|
34
|
+
*/
|
|
35
|
+
export function toSnakeCase(str) {
|
|
36
|
+
return str
|
|
37
|
+
.replace(/([a-z])([A-Z])/g, '$1_$2')
|
|
38
|
+
.replace(/[\s-]+/g, '_')
|
|
39
|
+
.toLowerCase();
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Convert a string to CONSTANT_CASE.
|
|
43
|
+
* @example toConstantCase('UserProfile') → 'USER_PROFILE'
|
|
44
|
+
*/
|
|
45
|
+
export function toConstantCase(str) {
|
|
46
|
+
return toSnakeCase(str).toUpperCase();
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Pluralize a simple English word (basic rules).
|
|
50
|
+
*/
|
|
51
|
+
export function pluralize(word) {
|
|
52
|
+
if (word.endsWith('s') || word.endsWith('x') || word.endsWith('z') ||
|
|
53
|
+
word.endsWith('sh') || word.endsWith('ch')) {
|
|
54
|
+
return word + 'es';
|
|
55
|
+
}
|
|
56
|
+
if (word.endsWith('y') && !/[aeiou]y$/i.test(word)) {
|
|
57
|
+
return word.slice(0, -1) + 'ies';
|
|
58
|
+
}
|
|
59
|
+
return word + 's';
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Indent each line of a string by the given number of spaces.
|
|
63
|
+
*/
|
|
64
|
+
export function indent(str, spaces) {
|
|
65
|
+
const pad = ' '.repeat(spaces);
|
|
66
|
+
return str
|
|
67
|
+
.split('\n')
|
|
68
|
+
.map((line) => (line.trim() === '' ? '' : pad + line))
|
|
69
|
+
.join('\n');
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Strip leading whitespace from a template literal while preserving relative indentation.
|
|
73
|
+
*/
|
|
74
|
+
export function dedent(str) {
|
|
75
|
+
const lines = str.split('\n');
|
|
76
|
+
// Remove leading empty line
|
|
77
|
+
if (lines[0]?.trim() === '')
|
|
78
|
+
lines.shift();
|
|
79
|
+
// Remove trailing empty line
|
|
80
|
+
if (lines[lines.length - 1]?.trim() === '')
|
|
81
|
+
lines.pop();
|
|
82
|
+
const minIndent = lines
|
|
83
|
+
.filter((l) => l.trim().length > 0)
|
|
84
|
+
.reduce((min, line) => {
|
|
85
|
+
const match = line.match(/^(\s*)/);
|
|
86
|
+
return Math.min(min, match ? match[1].length : 0);
|
|
87
|
+
}, Infinity);
|
|
88
|
+
if (minIndent === Infinity)
|
|
89
|
+
return str;
|
|
90
|
+
return lines.map((line) => line.slice(minIndent)).join('\n');
|
|
91
|
+
}
|
|
92
|
+
//# sourceMappingURL=strings.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"strings.js","sourceRoot":"","sources":["../../src/lib/strings.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;GAGG;AACH,MAAM,UAAU,YAAY,CAAC,GAAW;IACtC,OAAO,GAAG;SACP,OAAO,CAAC,cAAc,EAAE,CAAC,CAAC,EAAE,CAAqB,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;SACjF,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC,EAAE,CAAS,EAAE,EAAE,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC;AACxD,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,WAAW,CAAC,GAAW;IACrC,MAAM,MAAM,GAAG,YAAY,CAAC,GAAG,CAAC,CAAC;IACjC,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AAC1D,CAAC;AAED;;;GAGG;AACH,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AAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @dcyfr/ai-code-gen - Built-in template definitions
|
|
3
|
+
*
|
|
4
|
+
* Pre-configured templates for common code generation patterns.
|
|
5
|
+
*/
|
|
6
|
+
import type { TemplateDefinition } from '../types/index.js';
|
|
7
|
+
export declare const REACT_COMPONENT_TEMPLATE: TemplateDefinition;
|
|
8
|
+
export declare const API_ROUTE_TEMPLATE: TemplateDefinition;
|
|
9
|
+
export declare const DATA_MODEL_TEMPLATE: TemplateDefinition;
|
|
10
|
+
export declare const TEST_FILE_TEMPLATE: TemplateDefinition;
|
|
11
|
+
export declare const BARREL_EXPORT_TEMPLATE: TemplateDefinition;
|
|
12
|
+
export declare const BUILTIN_TEMPLATES: TemplateDefinition[];
|
|
13
|
+
//# sourceMappingURL=builtins.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"builtins.d.ts","sourceRoot":"","sources":["../../src/templates/builtins.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAI5D,eAAO,MAAM,wBAAwB,EAAE,kBAqCtC,CAAC;AAIF,eAAO,MAAM,kBAAkB,EAAE,kBAuGhC,CAAC;AAIF,eAAO,MAAM,mBAAmB,EAAE,kBAuDjC,CAAC;AAIF,eAAO,MAAM,kBAAkB,EAAE,kBAwChC,CAAC;AAIF,eAAO,MAAM,sBAAsB,EAAE,kBAgBpC,CAAC;AAIF,eAAO,MAAM,iBAAiB,EAAE,kBAAkB,EAMjD,CAAC"}
|