@viberails/context 0.2.0 → 0.2.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/dist/index.cjs +108 -52
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +107 -52
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -20,11 +20,12 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/index.ts
|
|
21
21
|
var index_exports = {};
|
|
22
22
|
__export(index_exports, {
|
|
23
|
+
VERSION: () => VERSION,
|
|
23
24
|
generateContext: () => generateContext
|
|
24
25
|
});
|
|
25
26
|
module.exports = __toCommonJS(index_exports);
|
|
26
27
|
|
|
27
|
-
// src/
|
|
28
|
+
// src/format-helpers.ts
|
|
28
29
|
var NAMING_EXAMPLES = {
|
|
29
30
|
"kebab-case": "`user-profile.ts`, not `UserProfile.ts`",
|
|
30
31
|
camelCase: "`userProfile.ts`, not `user-profile.ts`",
|
|
@@ -34,67 +35,50 @@ var NAMING_EXAMPLES = {
|
|
|
34
35
|
function conventionValue(cv) {
|
|
35
36
|
return typeof cv === "string" ? cv : cv.value;
|
|
36
37
|
}
|
|
37
|
-
function
|
|
38
|
-
const {
|
|
38
|
+
function formatDevelopmentSetup(config) {
|
|
39
|
+
const { linter, formatter } = config.stack;
|
|
40
|
+
if (!linter && !formatter) return [];
|
|
39
41
|
const lines = [];
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
);
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
42
|
+
lines.push("## Development setup\n");
|
|
43
|
+
const toolName = (id) => {
|
|
44
|
+
const name = id.split("@")[0];
|
|
45
|
+
if (name === "biome") return "Biome";
|
|
46
|
+
if (name === "prettier") return "Prettier";
|
|
47
|
+
if (name === "eslint") return "ESLint";
|
|
48
|
+
return name;
|
|
49
|
+
};
|
|
50
|
+
if (formatter && linter) {
|
|
51
|
+
const fmt = toolName(formatter);
|
|
52
|
+
const lint = toolName(linter);
|
|
53
|
+
if (fmt === lint) {
|
|
54
|
+
lines.push(`This project uses **${fmt}** for formatting and linting.
|
|
55
|
+
`);
|
|
56
|
+
} else {
|
|
57
|
+
lines.push(`This project uses **${fmt}** for formatting and **${lint}** for linting.
|
|
58
|
+
`);
|
|
59
|
+
}
|
|
60
|
+
} else if (formatter) {
|
|
61
|
+
lines.push(`This project uses **${toolName(formatter)}** for formatting.
|
|
62
|
+
`);
|
|
63
|
+
} else if (linter) {
|
|
64
|
+
lines.push(`This project uses **${toolName(linter)}** for linting.
|
|
65
|
+
`);
|
|
54
66
|
}
|
|
55
|
-
|
|
56
|
-
|
|
67
|
+
lines.push("- Enable format-on-save in your editor to avoid lint failures on commit.");
|
|
68
|
+
if (formatter) {
|
|
69
|
+
const fmt = toolName(formatter);
|
|
70
|
+
if (fmt === "Biome") {
|
|
57
71
|
lines.push(
|
|
58
|
-
|
|
72
|
+
"- If using VS Code, install the [Biome extension](https://marketplace.visualstudio.com/items?itemName=biomejs.biome) and enable format-on-save."
|
|
59
73
|
);
|
|
60
|
-
} else {
|
|
74
|
+
} else if (fmt === "Prettier") {
|
|
61
75
|
lines.push(
|
|
62
|
-
|
|
76
|
+
"- If using VS Code, install the [Prettier extension](https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode) and enable format-on-save."
|
|
63
77
|
);
|
|
64
78
|
}
|
|
65
79
|
}
|
|
66
80
|
return lines;
|
|
67
81
|
}
|
|
68
|
-
function generateContext(config) {
|
|
69
|
-
const sections = [];
|
|
70
|
-
sections.push("# viberails enforced rules\n");
|
|
71
|
-
if (config.enforcement === "enforce") {
|
|
72
|
-
sections.push("Commits will be rejected if these rules are violated:\n");
|
|
73
|
-
} else {
|
|
74
|
-
sections.push(
|
|
75
|
-
"These rules are checked before commits. Violations will be **warned** but not blocked:\n"
|
|
76
|
-
);
|
|
77
|
-
}
|
|
78
|
-
const ruleLines = formatEnforcedRules(config);
|
|
79
|
-
if (ruleLines.length > 0) {
|
|
80
|
-
sections.push(ruleLines.join("\n"));
|
|
81
|
-
} else {
|
|
82
|
-
sections.push("_(No rules configured. Edit `viberails.config.json` to add rules.)_");
|
|
83
|
-
}
|
|
84
|
-
const packageLines = formatPackageOverrides(config);
|
|
85
|
-
if (packageLines.length > 0) {
|
|
86
|
-
sections.push("");
|
|
87
|
-
sections.push(packageLines.join("\n"));
|
|
88
|
-
}
|
|
89
|
-
const boundaryLines = formatBoundaryRules(config);
|
|
90
|
-
if (boundaryLines.length > 0) {
|
|
91
|
-
sections.push("");
|
|
92
|
-
sections.push(boundaryLines.join("\n"));
|
|
93
|
-
}
|
|
94
|
-
sections.push("");
|
|
95
|
-
sections.push("Run `viberails check` before committing to catch violations early.\n");
|
|
96
|
-
return sections.join("\n");
|
|
97
|
-
}
|
|
98
82
|
function packageHeader(pkg) {
|
|
99
83
|
const framework = pkg.stack?.framework;
|
|
100
84
|
if (framework) {
|
|
@@ -155,8 +139,80 @@ function formatBoundaryRules(config) {
|
|
|
155
139
|
}
|
|
156
140
|
return lines;
|
|
157
141
|
}
|
|
142
|
+
|
|
143
|
+
// src/generate-context.ts
|
|
144
|
+
function formatEnforcedRules(config) {
|
|
145
|
+
const { rules, conventions, structure } = config;
|
|
146
|
+
const lines = [];
|
|
147
|
+
if (rules.maxFileLines > 0) {
|
|
148
|
+
lines.push(
|
|
149
|
+
`- Files must not exceed **${rules.maxFileLines} lines**. Split into focused modules.`
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
if (rules.maxFunctionLines > 0) {
|
|
153
|
+
lines.push(
|
|
154
|
+
`- Functions must not exceed **${rules.maxFunctionLines} lines**. Extract helpers for complex logic.`
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
if (rules.enforceNaming && conventions.fileNaming) {
|
|
158
|
+
const val = conventionValue(conventions.fileNaming);
|
|
159
|
+
const examples = NAMING_EXAMPLES[val] ?? `e.g. \`my-module.ts\``;
|
|
160
|
+
lines.push(`- Source files use **${val}**: ${examples}.`);
|
|
161
|
+
}
|
|
162
|
+
if (rules.requireTests && structure.testPattern) {
|
|
163
|
+
if (structure.srcDir) {
|
|
164
|
+
lines.push(
|
|
165
|
+
`- Every source file in \`${structure.srcDir}/\` must have a corresponding \`${structure.testPattern}\` file.`
|
|
166
|
+
);
|
|
167
|
+
} else {
|
|
168
|
+
lines.push(
|
|
169
|
+
`- Every source file must have a corresponding \`${structure.testPattern}\` file.`
|
|
170
|
+
);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
return lines;
|
|
174
|
+
}
|
|
175
|
+
function generateContext(config) {
|
|
176
|
+
const sections = [];
|
|
177
|
+
sections.push("# viberails enforced rules\n");
|
|
178
|
+
if (config.enforcement === "enforce") {
|
|
179
|
+
sections.push("Commits will be rejected if these rules are violated:\n");
|
|
180
|
+
} else {
|
|
181
|
+
sections.push(
|
|
182
|
+
"These rules are checked before commits. Violations will be **warned** but not blocked:\n"
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
const ruleLines = formatEnforcedRules(config);
|
|
186
|
+
if (ruleLines.length > 0) {
|
|
187
|
+
sections.push(ruleLines.join("\n"));
|
|
188
|
+
} else {
|
|
189
|
+
sections.push("_(No rules configured. Edit `viberails.config.json` to add rules.)_");
|
|
190
|
+
}
|
|
191
|
+
const packageLines = formatPackageOverrides(config);
|
|
192
|
+
if (packageLines.length > 0) {
|
|
193
|
+
sections.push("");
|
|
194
|
+
sections.push(packageLines.join("\n"));
|
|
195
|
+
}
|
|
196
|
+
const boundaryLines = formatBoundaryRules(config);
|
|
197
|
+
if (boundaryLines.length > 0) {
|
|
198
|
+
sections.push("");
|
|
199
|
+
sections.push(boundaryLines.join("\n"));
|
|
200
|
+
}
|
|
201
|
+
const setupLines = formatDevelopmentSetup(config);
|
|
202
|
+
if (setupLines.length > 0) {
|
|
203
|
+
sections.push("");
|
|
204
|
+
sections.push(setupLines.join("\n"));
|
|
205
|
+
}
|
|
206
|
+
sections.push("");
|
|
207
|
+
sections.push("Run `viberails check` before committing to catch violations early.\n");
|
|
208
|
+
return sections.join("\n");
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
// src/index.ts
|
|
212
|
+
var VERSION = "0.2.2";
|
|
158
213
|
// Annotate the CommonJS export names for ESM import in node:
|
|
159
214
|
0 && (module.exports = {
|
|
215
|
+
VERSION,
|
|
160
216
|
generateContext
|
|
161
217
|
});
|
|
162
218
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/generate-context.ts"],"sourcesContent":["export { generateContext } from './generate-context.js';\n","import type { ConventionValue, PackageConfigOverrides, ViberailsConfig } from '@viberails/types';\n\n/** Naming convention examples for directive formatting. */\nconst NAMING_EXAMPLES: Record<string, string> = {\n 'kebab-case': '`user-profile.ts`, not `UserProfile.ts`',\n camelCase: '`userProfile.ts`, not `user-profile.ts`',\n PascalCase: '`UserProfile.ts`, not `user-profile.ts`',\n snake_case: '`user_profile.ts`, not `UserProfile.ts`',\n};\n\n/**\n * Extract the effective value from a ConventionValue (string or object).\n */\nfunction conventionValue(cv: ConventionValue): string {\n return typeof cv === 'string' ? cv : cv.value;\n}\n\n/**\n * Build the list of enforced rules as markdown bullet points.\n */\nfunction formatEnforcedRules(config: ViberailsConfig): string[] {\n const { rules, conventions, structure } = config;\n const lines: string[] = [];\n\n if (rules.maxFileLines > 0) {\n lines.push(\n `- Files must not exceed **${rules.maxFileLines} lines**. Split into focused modules.`,\n );\n }\n\n if (rules.maxFunctionLines > 0) {\n lines.push(\n `- Functions must not exceed **${rules.maxFunctionLines} lines**. Extract helpers for complex logic.`,\n );\n }\n\n if (rules.enforceNaming && conventions.fileNaming) {\n const val = conventionValue(conventions.fileNaming);\n const examples = NAMING_EXAMPLES[val] ?? `e.g. \\`my-module.ts\\``;\n lines.push(`- Source files use **${val}**: ${examples}.`);\n }\n\n if (rules.requireTests && structure.testPattern) {\n if (structure.srcDir) {\n lines.push(\n `- Every source file in \\`${structure.srcDir}/\\` must have a corresponding \\`${structure.testPattern}\\` file.`,\n );\n } else {\n lines.push(\n `- Every source file must have a corresponding \\`${structure.testPattern}\\` file.`,\n );\n }\n }\n\n return lines;\n}\n\n/**\n * Generate a rules-focused context document from a ViberailsConfig.\n *\n * The output tells AI agents what rules are enforced and that commits\n * will fail if they are violated. It does not describe the project's\n * stack, structure, or architecture — that is trivially discoverable.\n *\n * @param config - The viberails configuration\n * @returns Markdown string for `.viberails/context.md`\n */\nexport function generateContext(config: ViberailsConfig): string {\n const sections: string[] = [];\n\n sections.push('# viberails enforced rules\\n');\n\n if (config.enforcement === 'enforce') {\n sections.push('Commits will be rejected if these rules are violated:\\n');\n } else {\n sections.push(\n 'These rules are checked before commits. Violations will be **warned** but not blocked:\\n',\n );\n }\n\n const ruleLines = formatEnforcedRules(config);\n if (ruleLines.length > 0) {\n sections.push(ruleLines.join('\\n'));\n } else {\n sections.push('_(No rules configured. Edit `viberails.config.json` to add rules.)_');\n }\n\n const packageLines = formatPackageOverrides(config);\n if (packageLines.length > 0) {\n sections.push('');\n sections.push(packageLines.join('\\n'));\n }\n\n const boundaryLines = formatBoundaryRules(config);\n if (boundaryLines.length > 0) {\n sections.push('');\n sections.push(boundaryLines.join('\\n'));\n }\n\n sections.push('');\n sections.push('Run `viberails check` before committing to catch violations early.\\n');\n\n return sections.join('\\n');\n}\n\n/**\n * Build the header for a package override section.\n */\nfunction packageHeader(pkg: PackageConfigOverrides): string {\n const framework = pkg.stack?.framework;\n if (framework) {\n const name = typeof framework === 'string' ? framework.split('@')[0] : framework;\n return `### ${pkg.path} (${name})`;\n }\n return `### ${pkg.path}`;\n}\n\n/**\n * Build the per-package overrides section as markdown lines.\n */\nfunction formatPackageOverrides(config: ViberailsConfig): string[] {\n if (!config.packages || config.packages.length === 0) return [];\n\n const lines: string[] = [];\n lines.push('## Per-package rules\\n');\n lines.push('The following packages have rules that differ from the global defaults:\\n');\n\n for (const pkg of config.packages) {\n lines.push(packageHeader(pkg));\n\n if (pkg.conventions?.fileNaming) {\n const val = conventionValue(pkg.conventions.fileNaming);\n const examples = NAMING_EXAMPLES[val] ?? `e.g. \\`my-module.ts\\``;\n lines.push(`- Source files use **${val}**: ${examples}.`);\n }\n\n if (pkg.conventions?.componentNaming) {\n const val = conventionValue(pkg.conventions.componentNaming);\n lines.push(`- Components use **${val}** naming.`);\n }\n\n if (pkg.conventions?.hookNaming) {\n const val = conventionValue(pkg.conventions.hookNaming);\n lines.push(`- Hooks use **${val}** naming.`);\n }\n\n if (pkg.conventions?.importAlias) {\n const val = conventionValue(pkg.conventions.importAlias);\n lines.push(`- Import alias: \\`${val}\\`.`);\n }\n\n if (pkg.rules?.maxFileLines !== undefined && pkg.rules.maxFileLines > 0) {\n lines.push(\n `- Files must not exceed **${pkg.rules.maxFileLines} lines**. Split into focused modules.`,\n );\n }\n\n if (pkg.rules?.maxFunctionLines !== undefined && pkg.rules.maxFunctionLines > 0) {\n lines.push(\n `- Functions must not exceed **${pkg.rules.maxFunctionLines} lines**. Extract helpers for complex logic.`,\n );\n }\n }\n\n return lines;\n}\n\n/**\n * Build the boundary rules section as markdown lines.\n * Only includes deny rules (allow: false).\n */\nfunction formatBoundaryRules(config: ViberailsConfig): string[] {\n if (!config.rules.enforceBoundaries || !config.boundaries || config.boundaries.length === 0) {\n return [];\n }\n\n const denyRules = config.boundaries.filter((r) => !r.allow);\n if (denyRules.length === 0) return [];\n\n const lines: string[] = [];\n lines.push('## Boundary rules\\n');\n lines.push('These import boundaries are enforced:\\n');\n\n for (const rule of denyRules) {\n const reason = rule.reason ? ` (${rule.reason})` : '';\n lines.push(`- \\`${rule.from}\\` must NOT import from \\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declare const __PACKAGE_VERSION__: string;\nexport const VERSION: string = __PACKAGE_VERSION__;\n\nexport { generateContext } from './generate-context.js';\n","import type { ConventionValue, PackageConfigOverrides, ViberailsConfig } from '@viberails/types';\n\n/** Naming convention examples for directive formatting. */\nexport const NAMING_EXAMPLES: Record<string, string> = {\n 'kebab-case': '`user-profile.ts`, not `UserProfile.ts`',\n camelCase: '`userProfile.ts`, not `user-profile.ts`',\n PascalCase: '`UserProfile.ts`, not `user-profile.ts`',\n snake_case: '`user_profile.ts`, not `UserProfile.ts`',\n};\n\n/**\n * Extract the effective value from a ConventionValue (string or object).\n */\nexport function conventionValue(cv: ConventionValue): string {\n return typeof cv === 'string' ? cv : cv.value;\n}\n\n/**\n * Build the \"Development setup\" section describing the project's\n * formatter and linter, with guidance on enabling format-on-save.\n */\nexport function formatDevelopmentSetup(config: ViberailsConfig): string[] {\n const { linter, formatter } = config.stack;\n if (!linter && !formatter) return [];\n\n const lines: string[] = [];\n lines.push('## Development setup\\n');\n\n const toolName = (id: string): string => {\n const name = id.split('@')[0];\n if (name === 'biome') return 'Biome';\n if (name === 'prettier') return 'Prettier';\n if (name === 'eslint') return 'ESLint';\n return name;\n };\n\n if (formatter && linter) {\n const fmt = toolName(formatter);\n const lint = toolName(linter);\n if (fmt === lint) {\n lines.push(`This project uses **${fmt}** for formatting and linting.\\n`);\n } else {\n lines.push(`This project uses **${fmt}** for formatting and **${lint}** for linting.\\n`);\n }\n } else if (formatter) {\n lines.push(`This project uses **${toolName(formatter)}** for formatting.\\n`);\n } else if (linter) {\n lines.push(`This project uses **${toolName(linter)}** for linting.\\n`);\n }\n\n lines.push('- Enable format-on-save in your editor to avoid lint failures on commit.');\n\n if (formatter) {\n const fmt = toolName(formatter);\n if (fmt === 'Biome') {\n lines.push(\n '- If using VS Code, install the [Biome extension](https://marketplace.visualstudio.com/items?itemName=biomejs.biome) and enable format-on-save.',\n );\n } else if (fmt === 'Prettier') {\n lines.push(\n '- If using VS Code, install the [Prettier extension](https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode) and enable format-on-save.',\n );\n }\n }\n\n return lines;\n}\n\n/**\n * Build the header for a package override section.\n */\nexport function packageHeader(pkg: PackageConfigOverrides): string {\n const framework = pkg.stack?.framework;\n if (framework) {\n const name = typeof framework === 'string' ? framework.split('@')[0] : framework;\n return `### ${pkg.path} (${name})`;\n }\n return `### ${pkg.path}`;\n}\n\n/**\n * Build the per-package overrides section as markdown lines.\n */\nexport function formatPackageOverrides(config: ViberailsConfig): string[] {\n if (!config.packages || config.packages.length === 0) return [];\n\n const lines: string[] = [];\n lines.push('## Per-package rules\\n');\n lines.push('The following packages have rules that differ from the global defaults:\\n');\n\n for (const pkg of config.packages) {\n lines.push(packageHeader(pkg));\n\n if (pkg.conventions?.fileNaming) {\n const val = conventionValue(pkg.conventions.fileNaming);\n const examples = NAMING_EXAMPLES[val] ?? `e.g. \\`my-module.ts\\``;\n lines.push(`- Source files use **${val}**: ${examples}.`);\n }\n\n if (pkg.conventions?.componentNaming) {\n const val = conventionValue(pkg.conventions.componentNaming);\n lines.push(`- Components use **${val}** naming.`);\n }\n\n if (pkg.conventions?.hookNaming) {\n const val = conventionValue(pkg.conventions.hookNaming);\n lines.push(`- Hooks use **${val}** naming.`);\n }\n\n if (pkg.conventions?.importAlias) {\n const val = conventionValue(pkg.conventions.importAlias);\n lines.push(`- Import alias: \\`${val}\\`.`);\n }\n\n if (pkg.rules?.maxFileLines !== undefined && pkg.rules.maxFileLines > 0) {\n lines.push(\n `- Files must not exceed **${pkg.rules.maxFileLines} lines**. Split into focused modules.`,\n );\n }\n\n if (pkg.rules?.maxFunctionLines !== undefined && pkg.rules.maxFunctionLines > 0) {\n lines.push(\n `- Functions must not exceed **${pkg.rules.maxFunctionLines} lines**. Extract helpers for complex logic.`,\n );\n }\n }\n\n return lines;\n}\n\n/**\n * Build the boundary rules section as markdown lines.\n * Only includes deny rules (allow: false).\n */\nexport function formatBoundaryRules(config: ViberailsConfig): string[] {\n if (!config.rules.enforceBoundaries || !config.boundaries || config.boundaries.length === 0) {\n return [];\n }\n\n const denyRules = config.boundaries.filter((r) => !r.allow);\n if (denyRules.length === 0) return [];\n\n const lines: string[] = [];\n lines.push('## Boundary rules\\n');\n lines.push('These import boundaries are enforced:\\n');\n\n for (const rule of denyRules) {\n const reason = rule.reason ? ` (${rule.reason})` : '';\n lines.push(`- \\`${rule.from}\\` must NOT import from \\`${rule.to}\\`${reason}`);\n }\n\n return lines;\n}\n","import type { ViberailsConfig } from '@viberails/types';\nimport {\n conventionValue,\n formatBoundaryRules,\n formatDevelopmentSetup,\n formatPackageOverrides,\n NAMING_EXAMPLES,\n} from './format-helpers.js';\n\n/**\n * Build the list of enforced rules as markdown bullet points.\n */\nfunction formatEnforcedRules(config: ViberailsConfig): string[] {\n const { rules, conventions, structure } = config;\n const lines: string[] = [];\n\n if (rules.maxFileLines > 0) {\n lines.push(\n `- Files must not exceed **${rules.maxFileLines} lines**. Split into focused modules.`,\n );\n }\n\n if (rules.maxFunctionLines > 0) {\n lines.push(\n `- Functions must not exceed **${rules.maxFunctionLines} lines**. Extract helpers for complex logic.`,\n );\n }\n\n if (rules.enforceNaming && conventions.fileNaming) {\n const val = conventionValue(conventions.fileNaming);\n const examples = NAMING_EXAMPLES[val] ?? `e.g. \\`my-module.ts\\``;\n lines.push(`- Source files use **${val}**: ${examples}.`);\n }\n\n if (rules.requireTests && structure.testPattern) {\n if (structure.srcDir) {\n lines.push(\n `- Every source file in \\`${structure.srcDir}/\\` must have a corresponding \\`${structure.testPattern}\\` file.`,\n );\n } else {\n lines.push(\n `- Every source file must have a corresponding \\`${structure.testPattern}\\` file.`,\n );\n }\n }\n\n return lines;\n}\n\n/**\n * Generate a rules-focused context document from a ViberailsConfig.\n *\n * The output tells AI agents what rules are enforced and that commits\n * will fail if they are violated. It does not describe the project's\n * stack, structure, or architecture — that is trivially discoverable.\n *\n * @param config - The viberails configuration\n * @returns Markdown string for `.viberails/context.md`\n */\nexport function generateContext(config: ViberailsConfig): string {\n const sections: string[] = [];\n\n sections.push('# viberails enforced rules\\n');\n\n if (config.enforcement === 'enforce') {\n sections.push('Commits will be rejected if these rules are violated:\\n');\n } else {\n sections.push(\n 'These rules are checked before commits. Violations will be **warned** but not blocked:\\n',\n );\n }\n\n const ruleLines = formatEnforcedRules(config);\n if (ruleLines.length > 0) {\n sections.push(ruleLines.join('\\n'));\n } else {\n sections.push('_(No rules configured. Edit `viberails.config.json` to add rules.)_');\n }\n\n const packageLines = formatPackageOverrides(config);\n if (packageLines.length > 0) {\n sections.push('');\n sections.push(packageLines.join('\\n'));\n }\n\n const boundaryLines = formatBoundaryRules(config);\n if (boundaryLines.length > 0) {\n sections.push('');\n sections.push(boundaryLines.join('\\n'));\n }\n\n const setupLines = formatDevelopmentSetup(config);\n if (setupLines.length > 0) {\n sections.push('');\n sections.push(setupLines.join('\\n'));\n }\n\n sections.push('');\n sections.push('Run `viberails check` before committing to catch violations early.\\n');\n\n return sections.join('\\n');\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACGO,IAAM,kBAA0C;AAAA,EACrD,cAAc;AAAA,EACd,WAAW;AAAA,EACX,YAAY;AAAA,EACZ,YAAY;AACd;AAKO,SAAS,gBAAgB,IAA6B;AAC3D,SAAO,OAAO,OAAO,WAAW,KAAK,GAAG;AAC1C;AAMO,SAAS,uBAAuB,QAAmC;AACxE,QAAM,EAAE,QAAQ,UAAU,IAAI,OAAO;AACrC,MAAI,CAAC,UAAU,CAAC,UAAW,QAAO,CAAC;AAEnC,QAAM,QAAkB,CAAC;AACzB,QAAM,KAAK,wBAAwB;AAEnC,QAAM,WAAW,CAAC,OAAuB;AACvC,UAAM,OAAO,GAAG,MAAM,GAAG,EAAE,CAAC;AAC5B,QAAI,SAAS,QAAS,QAAO;AAC7B,QAAI,SAAS,WAAY,QAAO;AAChC,QAAI,SAAS,SAAU,QAAO;AAC9B,WAAO;AAAA,EACT;AA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AS,KAAK,EAAE;AAChB,aAAS,KAAK,aAAa,KAAK,IAAI,CAAC;AAAA,EACvC;AAEA,QAAM,gBAAgB,oBAAoB,MAAM;AAChD,MAAI,cAAc,SAAS,GAAG;AAC5B,aAAS,KAAK,EAAE;AAChB,aAAS,KAAK,cAAc,KAAK,IAAI,CAAC;AAAA,EACxC;AAEA,QAAM,aAAa,uBAAuB,MAAM;AAChD,MAAI,WAAW,SAAS,GAAG;AACzB,aAAS,KAAK,EAAE;AAChB,aAAS,KAAK,WAAW,KAAK,IAAI,CAAC;AAAA,EACrC;AAEA,WAAS,KAAK,EAAE;AAChB,WAAS,KAAK,sEAAsE;AAEpF,SAAO,SAAS,KAAK,IAAI;AAC3B;;;AFpGO,IAAM,UAAkB;","names":[]}
|
package/dist/index.d.cts
CHANGED
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// src/
|
|
1
|
+
// src/format-helpers.ts
|
|
2
2
|
var NAMING_EXAMPLES = {
|
|
3
3
|
"kebab-case": "`user-profile.ts`, not `UserProfile.ts`",
|
|
4
4
|
camelCase: "`userProfile.ts`, not `user-profile.ts`",
|
|
@@ -8,67 +8,50 @@ var NAMING_EXAMPLES = {
|
|
|
8
8
|
function conventionValue(cv) {
|
|
9
9
|
return typeof cv === "string" ? cv : cv.value;
|
|
10
10
|
}
|
|
11
|
-
function
|
|
12
|
-
const {
|
|
11
|
+
function formatDevelopmentSetup(config) {
|
|
12
|
+
const { linter, formatter } = config.stack;
|
|
13
|
+
if (!linter && !formatter) return [];
|
|
13
14
|
const lines = [];
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
);
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
15
|
+
lines.push("## Development setup\n");
|
|
16
|
+
const toolName = (id) => {
|
|
17
|
+
const name = id.split("@")[0];
|
|
18
|
+
if (name === "biome") return "Biome";
|
|
19
|
+
if (name === "prettier") return "Prettier";
|
|
20
|
+
if (name === "eslint") return "ESLint";
|
|
21
|
+
return name;
|
|
22
|
+
};
|
|
23
|
+
if (formatter && linter) {
|
|
24
|
+
const fmt = toolName(formatter);
|
|
25
|
+
const lint = toolName(linter);
|
|
26
|
+
if (fmt === lint) {
|
|
27
|
+
lines.push(`This project uses **${fmt}** for formatting and linting.
|
|
28
|
+
`);
|
|
29
|
+
} else {
|
|
30
|
+
lines.push(`This project uses **${fmt}** for formatting and **${lint}** for linting.
|
|
31
|
+
`);
|
|
32
|
+
}
|
|
33
|
+
} else if (formatter) {
|
|
34
|
+
lines.push(`This project uses **${toolName(formatter)}** for formatting.
|
|
35
|
+
`);
|
|
36
|
+
} else if (linter) {
|
|
37
|
+
lines.push(`This project uses **${toolName(linter)}** for linting.
|
|
38
|
+
`);
|
|
28
39
|
}
|
|
29
|
-
|
|
30
|
-
|
|
40
|
+
lines.push("- Enable format-on-save in your editor to avoid lint failures on commit.");
|
|
41
|
+
if (formatter) {
|
|
42
|
+
const fmt = toolName(formatter);
|
|
43
|
+
if (fmt === "Biome") {
|
|
31
44
|
lines.push(
|
|
32
|
-
|
|
45
|
+
"- If using VS Code, install the [Biome extension](https://marketplace.visualstudio.com/items?itemName=biomejs.biome) and enable format-on-save."
|
|
33
46
|
);
|
|
34
|
-
} else {
|
|
47
|
+
} else if (fmt === "Prettier") {
|
|
35
48
|
lines.push(
|
|
36
|
-
|
|
49
|
+
"- If using VS Code, install the [Prettier extension](https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode) and enable format-on-save."
|
|
37
50
|
);
|
|
38
51
|
}
|
|
39
52
|
}
|
|
40
53
|
return lines;
|
|
41
54
|
}
|
|
42
|
-
function generateContext(config) {
|
|
43
|
-
const sections = [];
|
|
44
|
-
sections.push("# viberails enforced rules\n");
|
|
45
|
-
if (config.enforcement === "enforce") {
|
|
46
|
-
sections.push("Commits will be rejected if these rules are violated:\n");
|
|
47
|
-
} else {
|
|
48
|
-
sections.push(
|
|
49
|
-
"These rules are checked before commits. Violations will be **warned** but not blocked:\n"
|
|
50
|
-
);
|
|
51
|
-
}
|
|
52
|
-
const ruleLines = formatEnforcedRules(config);
|
|
53
|
-
if (ruleLines.length > 0) {
|
|
54
|
-
sections.push(ruleLines.join("\n"));
|
|
55
|
-
} else {
|
|
56
|
-
sections.push("_(No rules configured. Edit `viberails.config.json` to add rules.)_");
|
|
57
|
-
}
|
|
58
|
-
const packageLines = formatPackageOverrides(config);
|
|
59
|
-
if (packageLines.length > 0) {
|
|
60
|
-
sections.push("");
|
|
61
|
-
sections.push(packageLines.join("\n"));
|
|
62
|
-
}
|
|
63
|
-
const boundaryLines = formatBoundaryRules(config);
|
|
64
|
-
if (boundaryLines.length > 0) {
|
|
65
|
-
sections.push("");
|
|
66
|
-
sections.push(boundaryLines.join("\n"));
|
|
67
|
-
}
|
|
68
|
-
sections.push("");
|
|
69
|
-
sections.push("Run `viberails check` before committing to catch violations early.\n");
|
|
70
|
-
return sections.join("\n");
|
|
71
|
-
}
|
|
72
55
|
function packageHeader(pkg) {
|
|
73
56
|
const framework = pkg.stack?.framework;
|
|
74
57
|
if (framework) {
|
|
@@ -129,7 +112,79 @@ function formatBoundaryRules(config) {
|
|
|
129
112
|
}
|
|
130
113
|
return lines;
|
|
131
114
|
}
|
|
115
|
+
|
|
116
|
+
// src/generate-context.ts
|
|
117
|
+
function formatEnforcedRules(config) {
|
|
118
|
+
const { rules, conventions, structure } = config;
|
|
119
|
+
const lines = [];
|
|
120
|
+
if (rules.maxFileLines > 0) {
|
|
121
|
+
lines.push(
|
|
122
|
+
`- Files must not exceed **${rules.maxFileLines} lines**. Split into focused modules.`
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
if (rules.maxFunctionLines > 0) {
|
|
126
|
+
lines.push(
|
|
127
|
+
`- Functions must not exceed **${rules.maxFunctionLines} lines**. Extract helpers for complex logic.`
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
if (rules.enforceNaming && conventions.fileNaming) {
|
|
131
|
+
const val = conventionValue(conventions.fileNaming);
|
|
132
|
+
const examples = NAMING_EXAMPLES[val] ?? `e.g. \`my-module.ts\``;
|
|
133
|
+
lines.push(`- Source files use **${val}**: ${examples}.`);
|
|
134
|
+
}
|
|
135
|
+
if (rules.requireTests && structure.testPattern) {
|
|
136
|
+
if (structure.srcDir) {
|
|
137
|
+
lines.push(
|
|
138
|
+
`- Every source file in \`${structure.srcDir}/\` must have a corresponding \`${structure.testPattern}\` file.`
|
|
139
|
+
);
|
|
140
|
+
} else {
|
|
141
|
+
lines.push(
|
|
142
|
+
`- Every source file must have a corresponding \`${structure.testPattern}\` file.`
|
|
143
|
+
);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
return lines;
|
|
147
|
+
}
|
|
148
|
+
function generateContext(config) {
|
|
149
|
+
const sections = [];
|
|
150
|
+
sections.push("# viberails enforced rules\n");
|
|
151
|
+
if (config.enforcement === "enforce") {
|
|
152
|
+
sections.push("Commits will be rejected if these rules are violated:\n");
|
|
153
|
+
} else {
|
|
154
|
+
sections.push(
|
|
155
|
+
"These rules are checked before commits. Violations will be **warned** but not blocked:\n"
|
|
156
|
+
);
|
|
157
|
+
}
|
|
158
|
+
const ruleLines = formatEnforcedRules(config);
|
|
159
|
+
if (ruleLines.length > 0) {
|
|
160
|
+
sections.push(ruleLines.join("\n"));
|
|
161
|
+
} else {
|
|
162
|
+
sections.push("_(No rules configured. Edit `viberails.config.json` to add rules.)_");
|
|
163
|
+
}
|
|
164
|
+
const packageLines = formatPackageOverrides(config);
|
|
165
|
+
if (packageLines.length > 0) {
|
|
166
|
+
sections.push("");
|
|
167
|
+
sections.push(packageLines.join("\n"));
|
|
168
|
+
}
|
|
169
|
+
const boundaryLines = formatBoundaryRules(config);
|
|
170
|
+
if (boundaryLines.length > 0) {
|
|
171
|
+
sections.push("");
|
|
172
|
+
sections.push(boundaryLines.join("\n"));
|
|
173
|
+
}
|
|
174
|
+
const setupLines = formatDevelopmentSetup(config);
|
|
175
|
+
if (setupLines.length > 0) {
|
|
176
|
+
sections.push("");
|
|
177
|
+
sections.push(setupLines.join("\n"));
|
|
178
|
+
}
|
|
179
|
+
sections.push("");
|
|
180
|
+
sections.push("Run `viberails check` before committing to catch violations early.\n");
|
|
181
|
+
return sections.join("\n");
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
// src/index.ts
|
|
185
|
+
var VERSION = "0.2.2";
|
|
132
186
|
export {
|
|
187
|
+
VERSION,
|
|
133
188
|
generateContext
|
|
134
189
|
};
|
|
135
190
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/generate-context.ts"],"sourcesContent":["import type { ConventionValue, PackageConfigOverrides, ViberailsConfig } from '@viberails/types';\n\n/** Naming convention examples for directive formatting. */\nconst NAMING_EXAMPLES: Record<string, string> = {\n 'kebab-case': '`user-profile.ts`, not `UserProfile.ts`',\n camelCase: '`userProfile.ts`, not `user-profile.ts`',\n PascalCase: '`UserProfile.ts`, not `user-profile.ts`',\n snake_case: '`user_profile.ts`, not `UserProfile.ts`',\n};\n\n/**\n * Extract the effective value from a ConventionValue (string or object).\n */\nfunction conventionValue(cv: ConventionValue): string {\n return typeof cv === 'string' ? cv : cv.value;\n}\n\n/**\n * Build the list of enforced rules as markdown bullet points.\n */\nfunction formatEnforcedRules(config: ViberailsConfig): string[] {\n const { rules, conventions, structure } = config;\n const lines: string[] = [];\n\n if (rules.maxFileLines > 0) {\n lines.push(\n `- Files must not exceed **${rules.maxFileLines} lines**. Split into focused modules.`,\n );\n }\n\n if (rules.maxFunctionLines > 0) {\n lines.push(\n `- Functions must not exceed **${rules.maxFunctionLines} lines**. Extract helpers for complex logic.`,\n );\n }\n\n if (rules.enforceNaming && conventions.fileNaming) {\n const val = conventionValue(conventions.fileNaming);\n const examples = NAMING_EXAMPLES[val] ?? `e.g. \\`my-module.ts\\``;\n lines.push(`- Source files use **${val}**: ${examples}.`);\n }\n\n if (rules.requireTests && structure.testPattern) {\n if (structure.srcDir) {\n lines.push(\n `- Every source file in \\`${structure.srcDir}/\\` must have a corresponding \\`${structure.testPattern}\\` file.`,\n );\n } else {\n lines.push(\n `- Every source file must have a corresponding \\`${structure.testPattern}\\` file.`,\n );\n }\n }\n\n return lines;\n}\n\n/**\n * Generate a rules-focused context document from a ViberailsConfig.\n *\n * The output tells AI agents what rules are enforced and that commits\n * will fail if they are violated. It does not describe the project's\n * stack, structure, or architecture — that is trivially discoverable.\n *\n * @param config - The viberails configuration\n * @returns Markdown string for `.viberails/context.md`\n */\nexport function generateContext(config: ViberailsConfig): string {\n const sections: string[] = [];\n\n sections.push('# viberails enforced rules\\n');\n\n if (config.enforcement === 'enforce') {\n sections.push('Commits will be rejected if these rules are violated:\\n');\n } else {\n sections.push(\n 'These rules are checked before commits. Violations will be **warned** but not blocked:\\n',\n );\n }\n\n const ruleLines = formatEnforcedRules(config);\n if (ruleLines.length > 0) {\n sections.push(ruleLines.join('\\n'));\n } else {\n sections.push('_(No rules configured. Edit `viberails.config.json` to add rules.)_');\n }\n\n const packageLines = formatPackageOverrides(config);\n if (packageLines.length > 0) {\n sections.push('');\n sections.push(packageLines.join('\\n'));\n }\n\n const boundaryLines = formatBoundaryRules(config);\n if (boundaryLines.length > 0) {\n sections.push('');\n sections.push(boundaryLines.join('\\n'));\n }\n\n sections.push('');\n sections.push('Run `viberails check` before committing to catch violations early.\\n');\n\n return sections.join('\\n');\n}\n\n/**\n * Build the header for a package override section.\n */\nfunction packageHeader(pkg: PackageConfigOverrides): string {\n const framework = pkg.stack?.framework;\n if (framework) {\n const name = typeof framework === 'string' ? framework.split('@')[0] : framework;\n return `### ${pkg.path} (${name})`;\n }\n return `### ${pkg.path}`;\n}\n\n/**\n * Build the per-package overrides section as markdown lines.\n */\nfunction formatPackageOverrides(config: ViberailsConfig): string[] {\n if (!config.packages || config.packages.length === 0) return [];\n\n const lines: string[] = [];\n lines.push('## Per-package rules\\n');\n lines.push('The following packages have rules that differ from the global defaults:\\n');\n\n for (const pkg of config.packages) {\n lines.push(packageHeader(pkg));\n\n if (pkg.conventions?.fileNaming) {\n const val = conventionValue(pkg.conventions.fileNaming);\n const examples = NAMING_EXAMPLES[val] ?? `e.g. \\`my-module.ts\\``;\n lines.push(`- Source files use **${val}**: ${examples}.`);\n }\n\n if (pkg.conventions?.componentNaming) {\n const val = conventionValue(pkg.conventions.componentNaming);\n lines.push(`- Components use **${val}** naming.`);\n }\n\n if (pkg.conventions?.hookNaming) {\n const val = conventionValue(pkg.conventions.hookNaming);\n lines.push(`- Hooks use **${val}** naming.`);\n }\n\n if (pkg.conventions?.importAlias) {\n const val = conventionValue(pkg.conventions.importAlias);\n lines.push(`- Import alias: \\`${val}\\`.`);\n }\n\n if (pkg.rules?.maxFileLines !== undefined && pkg.rules.maxFileLines > 0) {\n lines.push(\n `- Files must not exceed **${pkg.rules.maxFileLines} lines**. Split into focused modules.`,\n );\n }\n\n if (pkg.rules?.maxFunctionLines !== undefined && pkg.rules.maxFunctionLines > 0) {\n lines.push(\n `- Functions must not exceed **${pkg.rules.maxFunctionLines} lines**. Extract helpers for complex logic.`,\n );\n }\n }\n\n return lines;\n}\n\n/**\n * Build the boundary rules section as markdown lines.\n * Only includes deny rules (allow: false).\n */\nfunction formatBoundaryRules(config: ViberailsConfig): string[] {\n if (!config.rules.enforceBoundaries || !config.boundaries || config.boundaries.length === 0) {\n return [];\n }\n\n const denyRules = config.boundaries.filter((r) => !r.allow);\n if (denyRules.length === 0) return [];\n\n const lines: string[] = [];\n lines.push('## Boundary rules\\n');\n lines.push('These import boundaries are enforced:\\n');\n\n for (const rule of denyRules) {\n const reason = rule.reason ? ` (${rule.reason})` : '';\n lines.push(`- \\`${rule.from}\\` must NOT import from \\`${rule.to}\\`${reason}`);\n }\n\n return lines;\n}\n"],"mappings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Y;AAC/B,YAAM,MAAM,gBAAgB,IAAI,YAAY,UAAU;AACtD,YAAM,KAAK,iBAAiB,GAAG,YAAY;AAAA,IAC7C;AAEA,QAAI,IAAI,aAAa,aAAa;AAChC,YAAM,MAAM,gBAAgB,IAAI,YAAY,WAAW;AACvD,YAAM,KAAK,qBAAqB,GAAG,KAAK;AAAA,IAC1C;AAEA,QAAI,IAAI,OAAO,iBAAiB,UAAa,IAAI,MAAM,eAAe,GAAG;AACvE,YAAM;AAAA,QACJ,6BAA6B,IAAI,MAAM,YAAY;AAAA,MACrD;AAAA,IACF;AAEA,QAAI,IAAI,OAAO,qBAAqB,UAAa,IAAI,MAAM,mBAAmB,GAAG;AAC/E,YAAM;AAAA,QACJ,iCAAiC,IAAI,MAAM,gBAAgB;AAAA,MAC7D;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AACT;AAMA,SAAS,oBAAoB,QAAmC;AAC9D,MAAI,CAAC,OAAO,MAAM,qBAAqB,CAAC,OAAO,cAAc,OAAO,WAAW,WAAW,GAAG;AAC3F,WAAO,CAAC;AAAA,EACV;AAEA,QAAM,YAAY,OAAO,WAAW,OAAO,CAAC,MAAM,CAAC,EAAE,KAAK;AAC1D,MAAI,UAAU,WAAW,EAAG,QAAO,CAAC;AAEpC,QAAM,QAAkB,CAAC;AACzB,QAAM,KAAK,qBAAqB;AAChC,QAAM,KAAK,yCAAyC;AAEpD,aAAW,QAAQ,WAAW;AAC5B,UAAM,SAAS,KAAK,SAAS,KAAK,KAAK,MAAM,MAAM;AACnD,UAAM,KAAK,OAAO,KAAK,IAAI,6BAA6B,KAAK,EAAE,KAAK,MAAM,EAAE;AAAA,EAC9E;AAEA,SAAO;AACT;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/format-helpers.ts","../src/generate-context.ts","../src/index.ts"],"sourcesContent":["import type { ConventionValue, PackageConfigOverrides, ViberailsConfig } from '@viberails/types';\n\n/** Naming convention examples for directive formatting. */\nexport const NAMING_EXAMPLES: Record<string, string> = {\n 'kebab-case': '`user-profile.ts`, not `UserProfile.ts`',\n camelCase: '`userProfile.ts`, not `user-profile.ts`',\n PascalCase: '`UserProfile.ts`, not `user-profile.ts`',\n snake_case: '`user_profile.ts`, not `UserProfile.ts`',\n};\n\n/**\n * Extract the effective value from a ConventionValue (string or object).\n */\nexport function conventionValue(cv: ConventionValue): string {\n return typeof cv === 'string' ? cv : cv.value;\n}\n\n/**\n * Build the \"Development setup\" section describing the project's\n * formatter and linter, with guidance on enabling format-on-save.\n */\nexport function formatDevelopmentSetup(config: ViberailsConfig): string[] {\n const { linter, formatter } = config.stack;\n if (!linter && !formatter) return [];\n\n const lines: string[] = [];\n lines.push('## Development setup\\n');\n\n const toolName = (id: string): string => {\n const name = id.split('@')[0];\n if (name === 'biome') return 'Biome';\n if (name === 'prettier') return 'Prettier';\n if (name === 'eslint') return 'ESLint';\n return name;\n };\n\n if (formatter && linter) {\n const fmt = toolName(formatter);\n const lint = toolName(linter);\n if (fmt === lint) {\n lines.push(`This project uses **${fmt}** for formatting and linting.\\n`);\n } else {\n lines.push(`This project uses **${fmt}** for formatting and **${lint}** for linting.\\n`);\n }\n } else if (formatter) {\n lines.push(`This project uses **${toolName(formatter)}** for formatting.\\n`);\n } else if (linter) {\n lines.push(`This project uses **${toolName(linter)}** for linting.\\n`);\n }\n\n lines.push('- Enable format-on-save in your editor to avoid lint failures on commit.');\n\n if (formatter) {\n const fmt = toolName(formatter);\n if (fmt === 'Biome') {\n lines.push(\n '- If using VS Code, install the [Biome extension](https://marketplace.visualstudio.com/items?itemName=biomejs.biome) and enable format-on-save.',\n );\n } else if (fmt === 'Prettier') {\n lines.push(\n '- If using VS Code, install the [Prettier extension](https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode) and enable format-on-save.',\n );\n }\n }\n\n return lines;\n}\n\n/**\n * Build the header for a package override section.\n */\nexport function packageHeader(pkg: PackageConfigOverrides): string {\n const framework = pkg.stack?.framework;\n if (framework) {\n const name = typeof framework === 'string' ? framework.split('@')[0] : framework;\n return `### ${pkg.path} (${name})`;\n }\n return `### ${pkg.path}`;\n}\n\n/**\n * Build the per-package overrides section as markdown lines.\n */\nexport function formatPackageOverrides(config: ViberailsConfig): string[] {\n if (!config.packages || config.packages.length === 0) return [];\n\n const lines: string[] = [];\n lines.push('## Per-package rules\\n');\n lines.push('The following packages have rules that differ from the global defaults:\\n');\n\n for (const pkg of config.packages) {\n lines.push(packageHeader(pkg));\n\n if (pkg.conventions?.fileNaming) {\n const val = conventionValue(pkg.conventions.fileNaming);\n const examples = NAMING_EXAMPLES[val] ?? `e.g. \\`my-module.ts\\``;\n lines.push(`- Source files use **${val}**: ${examples}.`);\n }\n\n if (pkg.conventions?.componentNaming) {\n const val = conventionValue(pkg.conventions.componentNaming);\n lines.push(`- Components use **${val}** naming.`);\n }\n\n if (pkg.conventions?.hookNaming) {\n const val = conventionValue(pkg.conventions.hookNaming);\n lines.push(`- Hooks use **${val}** naming.`);\n }\n\n if (pkg.conventions?.importAlias) {\n const val = conventionValue(pkg.conventions.importAlias);\n lines.push(`- Import alias: \\`${val}\\`.`);\n }\n\n if (pkg.rules?.maxFileLines !== undefined && pkg.rules.maxFileLines > 0) {\n lines.push(\n `- Files must not exceed **${pkg.rules.maxFileLines} lines**. Split into focused modules.`,\n );\n }\n\n if (pkg.rules?.maxFunctionLines !== undefined && pkg.rules.maxFunctionLines > 0) {\n lines.push(\n `- Functions must not exceed **${pkg.rules.maxFunctionLines} lines**. Extract helpers for complex logic.`,\n );\n }\n }\n\n return lines;\n}\n\n/**\n * Build the boundary rules section as markdown lines.\n * Only includes deny rules (allow: false).\n */\nexport function formatBoundaryRules(config: ViberailsConfig): string[] {\n if (!config.rules.enforceBoundaries || !config.boundaries || config.boundaries.length === 0) {\n return [];\n }\n\n const denyRules = config.boundaries.filter((r) => !r.allow);\n if (denyRules.length === 0) return [];\n\n const lines: string[] = [];\n lines.push('## Boundary rules\\n');\n lines.push('These import boundaries are enforced:\\n');\n\n for (const rule of denyRules) {\n const reason = rule.reason ? ` (${rule.reason})` : '';\n lines.push(`- \\`${rule.from}\\` must NOT import from \\`${rule.to}\\`${reason}`);\n }\n\n return lines;\n}\n","import type { ViberailsConfig } from '@viberails/types';\nimport {\n conventionValue,\n formatBoundaryRules,\n formatDevelopmentSetup,\n formatPackageOverrides,\n NAMING_EXAMPLES,\n} from './format-helpers.js';\n\n/**\n * Build the list of enforced rules as markdown bullet points.\n */\nfunction formatEnforcedRules(config: ViberailsConfig): string[] {\n const { rules, conventions, structure } = config;\n const lines: string[] = [];\n\n if (rules.maxFileLines > 0) {\n lines.push(\n `- Files must not exceed **${rules.maxFileLines} lines**. Split into focused modules.`,\n );\n }\n\n if (rules.maxFunctionLines > 0) {\n lines.push(\n `- Functions must not exceed **${rules.maxFunctionLines} lines**. Extract helpers for complex logic.`,\n );\n }\n\n if (rules.enforceNaming && conventions.fileNaming) {\n const val = conventionValue(conventions.fileNaming);\n const examples = NAMING_EXAMPLES[val] ?? `e.g. \\`my-module.ts\\``;\n lines.push(`- Source files use **${val}**: ${examples}.`);\n }\n\n if (rules.requireTests && structure.testPattern) {\n if (structure.srcDir) {\n lines.push(\n `- Every source file in \\`${structure.srcDir}/\\` must have a corresponding \\`${structure.testPattern}\\` file.`,\n );\n } else {\n lines.push(\n `- Every source file must have a corresponding \\`${structure.testPattern}\\` file.`,\n );\n }\n }\n\n return lines;\n}\n\n/**\n * Generate a rules-focused context document from a ViberailsConfig.\n *\n * The output tells AI agents what rules are enforced and that commits\n * will fail if they are violated. It does not describe the project's\n * stack, structure, or architecture — that is trivially discoverable.\n *\n * @param config - The viberails configuration\n * @returns Markdown string for `.viberails/context.md`\n */\nexport function generateContext(config: ViberailsConfig): string {\n const sections: string[] = [];\n\n sections.push('# viberails enforced rules\\n');\n\n if (config.enforcement === 'enforce') {\n sections.push('Commits will be rejected if these rules are violated:\\n');\n } else {\n sections.push(\n 'These rules are checked before commits. Violations will be **warned** but not blocked:\\n',\n );\n }\n\n const ruleLines = formatEnforcedRules(config);\n if (ruleLines.length > 0) {\n sections.push(ruleLines.join('\\n'));\n } else {\n sections.push('_(No rules configured. Edit `viberails.config.json` to add rules.)_');\n }\n\n const packageLines = formatPackageOverrides(config);\n if (packageLines.length > 0) {\n sections.push('');\n sections.push(packageLines.join('\\n'));\n }\n\n const boundaryLines = formatBoundaryRules(config);\n if (boundaryLines.length > 0) {\n sections.push('');\n sections.push(boundaryLines.join('\\n'));\n }\n\n const setupLines = formatDevelopmentSetup(config);\n if (setupLines.length > 0) {\n sections.push('');\n sections.push(setupLines.join('\\n'));\n }\n\n sections.push('');\n sections.push('Run `viberails check` before committing to catch violations early.\\n');\n\n return sections.join('\\n');\n}\n","declare const __PACKAGE_VERSION__: string;\nexport const VERSION: string = __PACKAGE_VERSION__;\n\nexport { generateContext } from './generate-context.js';\n"],"mappings":";AAGO,IAAM,kBAA0C;AAAA,EACrD,cAAc;AAAA,EACd,WAAW;AAAA,EACX,YAAY;AAAA,EACZ,YAAY;AACd;AAKO,SAAS,gBAAgB,IAA6B;AAC3D,SAAO,OAAO,OAAO,WAAW,KAAK,GAAG;AAC1C;AAMO,SAAS,uBAAuB,QAAmC;AACxE,QAAM,EAAE,QAAQ,UAAU,IAAI,OAAO;AACrC,MAAI,CAAC,UAAU,CAAC,UAAW,QAAO,CAAC;AAEnC,QAAM,QAAkB,CAAC;AACzB,QAAM,KAAK,wBAAwB;AAEnC,QAAM,WAAW,CAAC,OAAuB;AACvC,UAAM,OAAO,GAAG,MAAM,GAAG,EAAE,CAAC;AAC5B,QAAI,SAAS,QAAS,QAAO;AAC7B,QAAI,SAAS,WAAY,QAAO;AAChC,QAAI,SAAS,SAAU,QAAO;AAC9B,WAAO;AAAA,EACT;AAEA,MAAI,aAAa,QAAQ;AACvB,UAAM,MAAM,SAAS,SAAS;AAC9B,UAAM,OAAO,SAAS,MAAM;AAC5B,QAAI,QAAQ,MAAM;AAChB,YAAM,KAAK,uBAAuB,GAAG;AAAA,CAAkC;AAAA,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ChB,aAAS,KAAK,cAAc,KAAK,IAAI,CAAC;AAAA,EACxC;AAEA,QAAM,aAAa,uBAAuB,MAAM;AAChD,MAAI,WAAW,SAAS,GAAG;AACzB,aAAS,KAAK,EAAE;AAChB,aAAS,KAAK,WAAW,KAAK,IAAI,CAAC;AAAA,EACrC;AAEA,WAAS,KAAK,EAAE;AAChB,WAAS,KAAK,sEAAsE;AAEpF,SAAO,SAAS,KAAK,IAAI;AAC3B;;;ACpGO,IAAM,UAAkB;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@viberails/context",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "AI context file generation for viberails",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -25,8 +25,8 @@
|
|
|
25
25
|
"access": "public"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@viberails/types": "0.2.
|
|
29
|
-
"@viberails/config": "0.2.
|
|
28
|
+
"@viberails/types": "0.2.2",
|
|
29
|
+
"@viberails/config": "0.2.2"
|
|
30
30
|
},
|
|
31
31
|
"scripts": {
|
|
32
32
|
"build": "tsup",
|