@clipboard-health/ai-rules 2.4.2 → 2.4.4

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/scripts/sync.js +53 -7
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@clipboard-health/ai-rules",
3
3
  "description": "Pre-built AI agent rules for consistent coding standards.",
4
- "version": "2.4.2",
4
+ "version": "2.4.4",
5
5
  "bugs": "https://github.com/ClipboardHealth/core-utils/issues",
6
6
  "keywords": [
7
7
  "ai",
package/scripts/sync.js CHANGED
@@ -153,15 +153,61 @@ async function appendOverlay(projectRoot) {
153
153
  await (0, promises_1.writeFile)(agentsPath, updatedContent, "utf8");
154
154
  console.log(`📎 Appended OVERLAY.md to ${constants_1.FILES.agents}`);
155
155
  }
156
+ const PRETTIER_CONFIG_FILES = [
157
+ ".prettierrc",
158
+ ".prettierrc.json",
159
+ ".prettierrc.js",
160
+ ".prettierrc.cjs",
161
+ ".prettierrc.yaml",
162
+ ".prettierrc.yml",
163
+ "prettier.config.js",
164
+ "prettier.config.cjs",
165
+ "prettier.config.mjs",
166
+ ];
167
+ async function fileExists(filePath) {
168
+ try {
169
+ await (0, promises_1.access)(filePath);
170
+ return true;
171
+ }
172
+ catch {
173
+ return false;
174
+ }
175
+ }
176
+ async function detectFormatter(projectRoot) {
177
+ if (await fileExists(node_path_1.default.join(projectRoot, ".oxfmtrc.json"))) {
178
+ return "oxfmt";
179
+ }
180
+ const prettierChecks = await Promise.all(PRETTIER_CONFIG_FILES.map(async (configFile) => await fileExists(node_path_1.default.join(projectRoot, configFile))));
181
+ if (prettierChecks.some(Boolean)) {
182
+ return "prettier";
183
+ }
184
+ try {
185
+ const packageJson = JSON.parse(await (0, promises_1.readFile)(node_path_1.default.join(projectRoot, "package.json"), "utf8"));
186
+ const devDependencies = packageJson.devDependencies ?? {};
187
+ if ("oxfmt" in devDependencies) {
188
+ return "oxfmt";
189
+ }
190
+ if ("prettier" in devDependencies) {
191
+ return "prettier";
192
+ }
193
+ }
194
+ catch {
195
+ // package.json not found or unreadable
196
+ }
197
+ return undefined;
198
+ }
156
199
  async function formatOutputFiles(projectRoot) {
200
+ const formatter = await detectFormatter(projectRoot);
201
+ if (!formatter) {
202
+ console.warn("⚠️ No formatter detected (oxfmt or prettier). Skipping formatting.");
203
+ return;
204
+ }
205
+ const filesToFormat = [node_path_1.default.join(projectRoot, constants_1.FILES.agents), node_path_1.default.join(projectRoot, ".rules")];
206
+ const command = formatter === "oxfmt"
207
+ ? ["npx", "oxfmt", ...filesToFormat]
208
+ : ["npx", "prettier", "--write", ...filesToFormat];
157
209
  await (0, execAndLog_1.execAndLog)({
158
- command: [
159
- "npx",
160
- "prettier",
161
- "--write",
162
- node_path_1.default.join(projectRoot, constants_1.FILES.agents),
163
- node_path_1.default.join(projectRoot, ".rules"),
164
- ],
210
+ command,
165
211
  timeout: 60_000,
166
212
  verbose: false,
167
213
  });