@acidgreen-au/ag-cicd-cli 0.2.0 → 0.2.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.
Files changed (2) hide show
  1. package/dist/cli.mjs +102 -6
  2. package/package.json +1 -1
package/dist/cli.mjs CHANGED
@@ -216,6 +216,73 @@ function checkTagCommand(options) {
216
216
 
217
217
  //#endregion
218
218
  //#region src/utils/codequality.ts
219
+ /**
220
+ * Check if Biome is configured in the project
221
+ */
222
+ function isBiomeConfigured(cwd = ".") {
223
+ return ["biome.json", "biome.jsonc"].some((file) => existsSync(join(cwd, file)));
224
+ }
225
+ /**
226
+ * Check if Prettier is configured in the project
227
+ */
228
+ function isPrettierConfigured(cwd = ".") {
229
+ if ([
230
+ ".prettierrc",
231
+ ".prettierrc.json",
232
+ ".prettierrc.yml",
233
+ ".prettierrc.yaml",
234
+ ".prettierrc.js",
235
+ ".prettierrc.cjs",
236
+ ".prettierrc.mjs",
237
+ "prettier.config.js",
238
+ "prettier.config.cjs",
239
+ "prettier.config.mjs"
240
+ ].some((file) => existsSync(join(cwd, file)))) return true;
241
+ const packageJsonPath = join(cwd, "package.json");
242
+ if (existsSync(packageJsonPath)) try {
243
+ if (JSON.parse(readFileSync(packageJsonPath, "utf-8")).prettier) return true;
244
+ } catch {}
245
+ return false;
246
+ }
247
+ /**
248
+ * Check if the path is a Shopify theme directory
249
+ */
250
+ function isShopifyTheme(themePath) {
251
+ if (!existsSync(themePath)) return false;
252
+ if (existsSync(join(themePath, ".theme-check.yml"))) return true;
253
+ const themeDirectories = [
254
+ "layout",
255
+ "templates",
256
+ "sections",
257
+ "snippets",
258
+ "assets"
259
+ ];
260
+ try {
261
+ const contents = readdirSync(themePath);
262
+ const hasThemeDirs = themeDirectories.some((dir) => contents.includes(dir));
263
+ if (hasThemeDirs && existsSync(join(themePath, "layout"))) return readdirSync(join(themePath, "layout")).some((file) => file.endsWith(".liquid"));
264
+ return hasThemeDirs;
265
+ } catch {
266
+ return false;
267
+ }
268
+ }
269
+ /**
270
+ * Check if TypeScript is configured in the project
271
+ */
272
+ function isTscConfigured(cwd = ".") {
273
+ return existsSync(join(cwd, "tsconfig.json"));
274
+ }
275
+ /**
276
+ * Check which code quality tools are available/configured
277
+ */
278
+ function getAvailableTools(cwd = ".", themePath = "theme") {
279
+ return {
280
+ biome: isBiomeConfigured(cwd),
281
+ prettier: isPrettierConfigured(cwd),
282
+ "theme-check": isShopifyTheme(join(cwd, themePath)),
283
+ tsc: isTscConfigured(cwd)
284
+ };
285
+ }
219
286
  function runBiome() {
220
287
  try {
221
288
  const result = execSync("pnpm exec biome ci --reporter=gitlab --colors=off", {
@@ -385,27 +452,48 @@ function register$9(program$1) {
385
452
  function codequality(options) {
386
453
  const { output, path, checks = ALL_CHECKS } = options;
387
454
  const allIssues = [];
388
- const enabledChecks = new Set(checks);
389
- console.log(`Running code quality checks: ${checks.join(", ")}\n`);
390
- if (enabledChecks.has("biome")) {
455
+ const requestedChecks = new Set(checks);
456
+ const availableTools = getAvailableTools(".", path);
457
+ const enabledChecks = [];
458
+ const skippedChecks = [];
459
+ for (const check of checks) if (!availableTools[check]) skippedChecks.push({
460
+ name: check,
461
+ reason: getSkipReason(check)
462
+ });
463
+ else enabledChecks.push(check);
464
+ if (enabledChecks.length === 0) {
465
+ console.log("No code quality tools are configured for this project.\n");
466
+ console.log("Skipped checks:");
467
+ for (const { name, reason } of skippedChecks) console.log(` - ${name}: ${reason}`);
468
+ writeFileSync(output, JSON.stringify([], null, 2));
469
+ console.log(`\nWrote 0 issues to ${output}`);
470
+ return;
471
+ }
472
+ console.log(`Running code quality checks: ${enabledChecks.join(", ")}\n`);
473
+ if (skippedChecks.length > 0) {
474
+ console.log("Skipped (not configured):");
475
+ for (const { name, reason } of skippedChecks) console.log(` - ${name}: ${reason}`);
476
+ console.log("");
477
+ }
478
+ if (requestedChecks.has("biome") && availableTools.biome) {
391
479
  console.log("Running Biome...");
392
480
  const biomeIssues = runBiome();
393
481
  allIssues.push(...biomeIssues);
394
482
  console.log(` Found ${biomeIssues.length} issues\n`);
395
483
  }
396
- if (enabledChecks.has("prettier")) {
484
+ if (requestedChecks.has("prettier") && availableTools.prettier) {
397
485
  console.log("Running Prettier...");
398
486
  const prettierIssues = runPrettier();
399
487
  allIssues.push(...prettierIssues);
400
488
  console.log(` Found ${prettierIssues.length} issues\n`);
401
489
  }
402
- if (enabledChecks.has("theme-check")) {
490
+ if (requestedChecks.has("theme-check") && availableTools["theme-check"]) {
403
491
  console.log("Running Theme Check...");
404
492
  const themeIssues = runThemeCheck(path);
405
493
  allIssues.push(...themeIssues);
406
494
  console.log(` Found ${themeIssues.length} issues\n`);
407
495
  }
408
- if (enabledChecks.has("tsc")) {
496
+ if (requestedChecks.has("tsc") && availableTools.tsc) {
409
497
  console.log("Running TypeScript...");
410
498
  const tscIssues = runTsc();
411
499
  allIssues.push(...tscIssues);
@@ -414,6 +502,14 @@ function codequality(options) {
414
502
  writeFileSync(output, JSON.stringify(allIssues, null, 2));
415
503
  console.log(`Wrote ${allIssues.length} total issues to ${output}`);
416
504
  }
505
+ function getSkipReason(check) {
506
+ switch (check) {
507
+ case "biome": return "no biome.json found";
508
+ case "prettier": return "no prettier config found";
509
+ case "theme-check": return "not a Shopify theme directory";
510
+ case "tsc": return "no tsconfig.json found";
511
+ }
512
+ }
417
513
 
418
514
  //#endregion
419
515
  //#region src/commands/commit-msg.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@acidgreen-au/ag-cicd-cli",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "Acidgreen CI/CD CLI tools",
5
5
  "type": "module",
6
6
  "bin": {