@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.
@@ -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
- for (const group of groups) {
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
- if (isIncluded(matchPath) && !isExcluded(matchPath)) {
59
- return group.name;
60
- }
62
+ if (isNil(matched)) {
63
+ return undefined;
61
64
  }
62
- return undefined;
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
- let excludes: string[] | undefined;
105
- if (options.excludes) {
106
- excludes = [...options.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(frontmatter.name, d.filePath, frontmatter.schema, templateVars);
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
- let excludes: string[] | undefined;
157
- if (options.excludes) {
158
- excludes = [...options.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(frontmatter.name, d.filePath, frontmatter.schema, templateVars),
180
- prompt: {
203
+ lintResult: lintPrompt({
181
204
  name: frontmatter.name,
182
- group,
183
- schema: frontmatter.schema,
184
- template,
185
- sourcePath: d.filePath,
186
- } satisfies ParsedPrompt,
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
- "esModuleInterop": true,
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
- "resolveJsonModule": true,
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": {