@funkai/cli 0.3.0 → 0.3.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/.turbo/turbo-build.log +2 -2
- package/CHANGELOG.md +7 -0
- package/README.md +11 -11
- package/dist/index.mjs +153 -96
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
- package/src/commands/generate.ts +16 -1
- package/src/commands/prompts/create.ts +3 -0
- package/src/commands/prompts/generate.ts +48 -10
- package/src/commands/prompts/lint.ts +31 -3
- package/src/commands/prompts/setup.ts +3 -3
- package/src/commands/setup.ts +39 -17
- package/src/commands/validate.ts +13 -2
- package/src/lib/prompts/__tests__/lint.test.ts +36 -24
- package/src/lib/prompts/codegen.ts +3 -4
- package/src/lib/prompts/flatten.ts +10 -5
- package/src/lib/prompts/frontmatter.ts +24 -8
- package/src/lib/prompts/lint.ts +31 -10
- package/src/lib/prompts/paths.ts +12 -11
- package/src/lib/prompts/pipeline.ts +50 -27
- package/tsconfig.json +11 -3
|
@@ -3,6 +3,7 @@ import { relative, resolve } from "node:path";
|
|
|
3
3
|
|
|
4
4
|
import type { PromptGroup } from "@funkai/config";
|
|
5
5
|
import { clean, PARTIALS_DIR } from "@funkai/prompts/cli";
|
|
6
|
+
import { isNil } from "es-toolkit";
|
|
6
7
|
import picomatch from "picomatch";
|
|
7
8
|
|
|
8
9
|
import { toFileSlug } from "./codegen.js";
|
|
@@ -10,6 +11,7 @@ import type { ParsedPrompt } from "./codegen.js";
|
|
|
10
11
|
import { extractVariables } from "./extract-variables.js";
|
|
11
12
|
import { flattenPartials } from "./flatten.js";
|
|
12
13
|
import { parseFrontmatter } from "./frontmatter.js";
|
|
14
|
+
import type { SchemaVariable } from "./frontmatter.js";
|
|
13
15
|
import { lintPrompt } from "./lint.js";
|
|
14
16
|
import type { LintResult } from "./lint.js";
|
|
15
17
|
import { discoverPrompts } from "./paths.js";
|
|
@@ -51,15 +53,17 @@ function resolveGroupFromConfig(
|
|
|
51
53
|
): string | undefined {
|
|
52
54
|
const matchPath = relative(process.cwd(), filePath).replaceAll("\\", "/");
|
|
53
55
|
|
|
54
|
-
|
|
56
|
+
const matched = groups.find((group) => {
|
|
55
57
|
const isIncluded = picomatch(group.includes as string[]);
|
|
56
58
|
const isExcluded = picomatch((group.excludes ?? []) as string[]);
|
|
59
|
+
return isIncluded(matchPath) && !isExcluded(matchPath);
|
|
60
|
+
});
|
|
57
61
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}
|
|
62
|
+
if (isNil(matched)) {
|
|
63
|
+
return undefined;
|
|
61
64
|
}
|
|
62
|
-
|
|
65
|
+
|
|
66
|
+
return matched.name;
|
|
63
67
|
}
|
|
64
68
|
|
|
65
69
|
/**
|
|
@@ -101,14 +105,14 @@ export interface LintPipelineResult {
|
|
|
101
105
|
* @returns Lint results for all discovered prompts.
|
|
102
106
|
*/
|
|
103
107
|
export function runLintPipeline(options: LintPipelineOptions): LintPipelineResult {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
excludes
|
|
108
|
+
const discoverLintOptions: {
|
|
109
|
+
includes: string[];
|
|
110
|
+
excludes?: string[];
|
|
111
|
+
} = { includes: [...options.includes] };
|
|
112
|
+
if (options.excludes !== undefined) {
|
|
113
|
+
discoverLintOptions.excludes = [...options.excludes];
|
|
107
114
|
}
|
|
108
|
-
const discovered = discoverPrompts(
|
|
109
|
-
includes: [...options.includes],
|
|
110
|
-
excludes,
|
|
111
|
-
});
|
|
115
|
+
const discovered = discoverPrompts(discoverLintOptions);
|
|
112
116
|
const customPartialsDir = resolve(options.partials ?? ".prompts/partials");
|
|
113
117
|
const partialsDirs = resolvePartialsDirs(customPartialsDir);
|
|
114
118
|
|
|
@@ -118,7 +122,12 @@ export function runLintPipeline(options: LintPipelineOptions): LintPipelineResul
|
|
|
118
122
|
const frontmatter = parseFrontmatter({ content: raw, filePath: d.filePath });
|
|
119
123
|
const template = flattenPartials({ template: clean(raw), partialsDirs });
|
|
120
124
|
const templateVars = extractVariables(template);
|
|
121
|
-
return lintPrompt(
|
|
125
|
+
return lintPrompt({
|
|
126
|
+
name: frontmatter.name,
|
|
127
|
+
filePath: d.filePath,
|
|
128
|
+
schemaVars: frontmatter.schema,
|
|
129
|
+
templateVars,
|
|
130
|
+
});
|
|
122
131
|
});
|
|
123
132
|
|
|
124
133
|
return { discovered: discovered.length, results };
|
|
@@ -153,14 +162,14 @@ export interface GeneratePipelineResult {
|
|
|
153
162
|
* @returns Parsed prompts ready for code generation, along with lint results.
|
|
154
163
|
*/
|
|
155
164
|
export function runGeneratePipeline(options: GeneratePipelineOptions): GeneratePipelineResult {
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
excludes
|
|
165
|
+
const discoverGenerateOptions: {
|
|
166
|
+
includes: string[];
|
|
167
|
+
excludes?: string[];
|
|
168
|
+
} = { includes: [...options.includes] };
|
|
169
|
+
if (options.excludes !== undefined) {
|
|
170
|
+
discoverGenerateOptions.excludes = [...options.excludes];
|
|
159
171
|
}
|
|
160
|
-
const discovered = discoverPrompts(
|
|
161
|
-
includes: [...options.includes],
|
|
162
|
-
excludes,
|
|
163
|
-
});
|
|
172
|
+
const discovered = discoverPrompts(discoverGenerateOptions);
|
|
164
173
|
const customPartialsDir = resolve(options.partials ?? resolve(options.out, "../partials"));
|
|
165
174
|
const partialsDirs = resolvePartialsDirs(customPartialsDir);
|
|
166
175
|
const configGroups = options.groups ?? [];
|
|
@@ -175,15 +184,29 @@ export function runGeneratePipeline(options: GeneratePipelineOptions): GenerateP
|
|
|
175
184
|
// Frontmatter group wins; fall back to config-defined group patterns
|
|
176
185
|
const group = frontmatter.group ?? resolveGroupFromConfig(d.filePath, configGroups);
|
|
177
186
|
|
|
187
|
+
const promptObj: {
|
|
188
|
+
name: string;
|
|
189
|
+
schema: readonly SchemaVariable[];
|
|
190
|
+
template: string;
|
|
191
|
+
sourcePath: string;
|
|
192
|
+
group?: string;
|
|
193
|
+
} = {
|
|
194
|
+
name: frontmatter.name,
|
|
195
|
+
schema: frontmatter.schema,
|
|
196
|
+
template,
|
|
197
|
+
sourcePath: d.filePath,
|
|
198
|
+
};
|
|
199
|
+
if (group !== undefined) {
|
|
200
|
+
promptObj.group = group;
|
|
201
|
+
}
|
|
178
202
|
return {
|
|
179
|
-
lintResult: lintPrompt(
|
|
180
|
-
prompt: {
|
|
203
|
+
lintResult: lintPrompt({
|
|
181
204
|
name: frontmatter.name,
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
205
|
+
filePath: d.filePath,
|
|
206
|
+
schemaVars: frontmatter.schema,
|
|
207
|
+
templateVars,
|
|
208
|
+
}),
|
|
209
|
+
prompt: promptObj satisfies ParsedPrompt,
|
|
187
210
|
};
|
|
188
211
|
});
|
|
189
212
|
|
package/tsconfig.json
CHANGED
|
@@ -5,15 +5,23 @@
|
|
|
5
5
|
"module": "NodeNext",
|
|
6
6
|
"moduleResolution": "NodeNext",
|
|
7
7
|
"lib": ["ES2024"],
|
|
8
|
+
"types": ["node"],
|
|
9
|
+
|
|
8
10
|
"strict": true,
|
|
9
|
-
"
|
|
11
|
+
"noUncheckedIndexedAccess": true,
|
|
12
|
+
"exactOptionalPropertyTypes": true,
|
|
13
|
+
"noFallthroughCasesInSwitch": true,
|
|
14
|
+
"noPropertyAccessFromIndexSignature": true,
|
|
15
|
+
|
|
16
|
+
"verbatimModuleSyntax": true,
|
|
17
|
+
"resolveJsonModule": true,
|
|
10
18
|
"skipLibCheck": true,
|
|
11
19
|
"forceConsistentCasingInFileNames": true,
|
|
12
|
-
|
|
13
|
-
"isolatedModules": true,
|
|
20
|
+
|
|
14
21
|
"declaration": true,
|
|
15
22
|
"declarationMap": true,
|
|
16
23
|
"sourceMap": true,
|
|
24
|
+
|
|
17
25
|
"outDir": "./dist",
|
|
18
26
|
"rootDir": ".",
|
|
19
27
|
"paths": {
|