pr-checkmate 1.0.1 → 1.0.3

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/cli.js ADDED
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env node
2
+ import { runJob } from './scripts/index.js';
3
+ import { init } from './init.js';
4
+ const cmd = process.argv[2];
5
+ (async () => {
6
+ try {
7
+ if (cmd === 'init') {
8
+ await init();
9
+ process.exit(0);
10
+ }
11
+ await runJob(cmd || 'all');
12
+ }
13
+ catch (err) {
14
+ console.error('❌ CLI failed:', err);
15
+ process.exit(1);
16
+ }
17
+ })();
package/dist/config.js ADDED
@@ -0,0 +1,7 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ export const CONFIG_FILE = path.resolve(process.cwd(), 'pr-checkmate.json');
4
+ export const config = fs.existsSync(CONFIG_FILE)
5
+ ? JSON.parse(fs.readFileSync(CONFIG_FILE, 'utf-8'))
6
+ : { sourcePath: 'src' };
7
+ export const SOURCE_PATH = config.sourcePath;
package/dist/index.js CHANGED
@@ -1,65 +1,22 @@
1
- "use strict";
2
1
  /**
3
2
  * PR CheckMate - Automated PR quality checks
4
3
  *
5
4
  * @module pr-checkmate
6
5
  */
7
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
8
- if (k2 === undefined) k2 = k;
9
- var desc = Object.getOwnPropertyDescriptor(m, k);
10
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
11
- desc = { enumerable: true, get: function() { return m[k]; } };
12
- }
13
- Object.defineProperty(o, k2, desc);
14
- }) : (function(o, m, k, k2) {
15
- if (k2 === undefined) k2 = k;
16
- o[k2] = m[k];
17
- }));
18
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
19
- Object.defineProperty(o, "default", { enumerable: true, value: v });
20
- }) : function(o, v) {
21
- o["default"] = v;
22
- });
23
- var __importStar = (this && this.__importStar) || (function () {
24
- var ownKeys = function(o) {
25
- ownKeys = Object.getOwnPropertyNames || function (o) {
26
- var ar = [];
27
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
28
- return ar;
29
- };
30
- return ownKeys(o);
31
- };
32
- return function (mod) {
33
- if (mod && mod.__esModule) return mod;
34
- var result = {};
35
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
36
- __setModuleDefault(result, mod);
37
- return result;
38
- };
39
- })();
40
- Object.defineProperty(exports, "__esModule", { value: true });
41
- exports.logger = exports.runSpellcheck = exports.runPrettier = exports.runDependencyCheck = exports.runLint = void 0;
42
- exports.runAllChecks = runAllChecks;
43
- exports.runChecks = runChecks;
44
- var lint_1 = require("./scripts/lint");
45
- Object.defineProperty(exports, "runLint", { enumerable: true, get: function () { return lint_1.runLint; } });
46
- var dependency_check_1 = require("./scripts/dependency-check");
47
- Object.defineProperty(exports, "runDependencyCheck", { enumerable: true, get: function () { return dependency_check_1.runDependencyCheck; } });
48
- var prettier_autoformat_1 = require("./scripts/prettier-autoformat");
49
- Object.defineProperty(exports, "runPrettier", { enumerable: true, get: function () { return prettier_autoformat_1.runPrettier; } });
50
- var spellcheck_1 = require("./scripts/spellcheck");
51
- Object.defineProperty(exports, "runSpellcheck", { enumerable: true, get: function () { return spellcheck_1.runSpellcheck; } });
52
- var utils_1 = require("./utils");
53
- Object.defineProperty(exports, "logger", { enumerable: true, get: function () { return utils_1.logger; } });
6
+ export { runLint } from './scripts/lint';
7
+ export { runDependencyCheck } from './scripts/dependency-check';
8
+ export { runPrettier } from './scripts/prettier-autoformat';
9
+ export { runSpellcheck } from './scripts/spellcheck';
10
+ export { logger } from './utils';
54
11
  /**
55
12
  * Run all checks sequentially
56
13
  * @returns Promise that resolves when all checks complete
57
14
  */
58
- async function runAllChecks() {
59
- const { runLint } = await Promise.resolve().then(() => __importStar(require('./scripts/lint')));
60
- const { runDependencyCheck } = await Promise.resolve().then(() => __importStar(require('./scripts/dependency-check')));
61
- const { runPrettier } = await Promise.resolve().then(() => __importStar(require('./scripts/prettier-autoformat')));
62
- const { runSpellcheck } = await Promise.resolve().then(() => __importStar(require('./scripts/spellcheck')));
15
+ export async function runAllChecks() {
16
+ const { runLint } = await import('./scripts/lint');
17
+ const { runDependencyCheck } = await import('./scripts/dependency-check');
18
+ const { runPrettier } = await import('./scripts/prettier-autoformat');
19
+ const { runSpellcheck } = await import('./scripts/spellcheck');
63
20
  await runLint();
64
21
  await runDependencyCheck();
65
22
  await runSpellcheck();
@@ -68,11 +25,11 @@ async function runAllChecks() {
68
25
  /**
69
26
  * Run checks based on configuration
70
27
  */
71
- async function runChecks(config = {}) {
72
- const { runLint } = await Promise.resolve().then(() => __importStar(require('./scripts/lint')));
73
- const { runDependencyCheck } = await Promise.resolve().then(() => __importStar(require('./scripts/dependency-check')));
74
- const { runPrettier } = await Promise.resolve().then(() => __importStar(require('./scripts/prettier-autoformat')));
75
- const { runSpellcheck } = await Promise.resolve().then(() => __importStar(require('./scripts/spellcheck')));
28
+ export async function runChecks(config = {}) {
29
+ const { runLint } = await import('./scripts/lint');
30
+ const { runDependencyCheck } = await import('./scripts/dependency-check');
31
+ const { runPrettier } = await import('./scripts/prettier-autoformat');
32
+ const { runSpellcheck } = await import('./scripts/spellcheck');
76
33
  if (!config.skipLint)
77
34
  await runLint();
78
35
  if (!config.skipDeps)
package/dist/init.js ADDED
@@ -0,0 +1,31 @@
1
+ import fs from 'fs';
2
+ import path from 'path';
3
+ import inquirer from 'inquirer';
4
+ import { logger } from './utils';
5
+ export const CONFIG_FILE = path.resolve(process.cwd(), 'pr-checkmate.json');
6
+ export async function init() {
7
+ if (fs.existsSync(CONFIG_FILE)) {
8
+ logger.info('⚡ pr-checkmate.json already exists.');
9
+ return;
10
+ }
11
+ const answers = await inquirer.prompt([
12
+ {
13
+ type: 'list',
14
+ name: 'sourcePath',
15
+ message: 'Where is your project source code?',
16
+ choices: ['src', 'app', 'Enter manually'],
17
+ },
18
+ {
19
+ type: 'input',
20
+ name: 'manualPath',
21
+ message: 'Enter path:',
22
+ when: a => a.sourcePath === 'Enter manually',
23
+ validate: input => input.trim().length > 0 || 'Cannot be empty',
24
+ },
25
+ ]);
26
+ const config = {
27
+ sourcePath: answers.sourcePath === 'Enter manually' ? answers.manualPath : answers.sourcePath,
28
+ };
29
+ fs.writeFileSync(CONFIG_FILE, JSON.stringify(config, null, 2));
30
+ logger.info('✅ Created checkmatec.json');
31
+ }
@@ -1,33 +1,24 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.runDependencyCheck = runDependencyCheck;
7
- const utils_1 = require("../utils");
8
- const node_fs_1 = __importDefault(require("node:fs"));
1
+ import { logger } from '../utils';
2
+ import fs from 'node:fs';
3
+ import path from 'node:path';
4
+ import { SOURCE_PATH } from '../config';
9
5
  /**
10
- * Check for changes in dependency files using CHANGED_FILES env variable.
6
+ * Check for the presence of package.json and source folder.
7
+ * Currently, only validates existence; can be extended for dependency checks.
8
+ *
9
+ * @throws Will throw an error if deeper checks are added and fail.
11
10
  */
12
- // export async function runDependencyCheck(): Promise<void> {
13
- // try {
14
- // const changedFiles = process.env.CHANGED_FILES ?? '';
15
- // if (/package.*\.json/.test(changedFiles)) {
16
- // logger.warn('[runDependencyCheck]: ⚠️ Dependencies changed!');
17
- // } else {
18
- // logger.log('[runDependencyCheck]: ✅ No dependency changes detected.');
19
- // }
20
- // } catch (err: unknown) {
21
- // const errorMessage = err instanceof Error ? err.message : String(err);
22
- // logger.error('[runDependencyCheck]: ❌ Dependency check failed:', errorMessage);
23
- // throw err;
24
- // }
25
- // }
26
- async function runDependencyCheck() {
27
- utils_1.logger.info('Checking dependencies...');
28
- if (!node_fs_1.default.existsSync('package.json')) {
29
- utils_1.logger.warn('No package.json — skipping');
11
+ export async function runDependencyCheck() {
12
+ logger.info('Checking dependencies...');
13
+ const packageJsonPath = path.resolve(process.cwd(), 'package.json');
14
+ if (!fs.existsSync(packageJsonPath)) {
15
+ logger.warn('No package.json skipping dependency check');
30
16
  return;
31
17
  }
32
- utils_1.logger.info('Dependencies OK');
18
+ const sourceFolder = path.resolve(process.cwd(), SOURCE_PATH);
19
+ if (!fs.existsSync(sourceFolder)) {
20
+ logger.warn(`Source folder "${SOURCE_PATH}" not found — skipping deeper checks`);
21
+ return;
22
+ }
23
+ logger.info('Dependencies OK');
33
24
  }
@@ -1,10 +1,8 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const lint_1 = require("./lint");
4
- const dependency_check_1 = require("./dependency-check");
5
- const prettier_autoformat_1 = require("./prettier-autoformat");
6
- const spellcheck_1 = require("./spellcheck");
7
- const utils_1 = require("../utils");
1
+ import { runLint } from './lint';
2
+ import { runDependencyCheck } from './dependency-check';
3
+ import { runPrettier } from './prettier-autoformat';
4
+ import { runSpellcheck } from './spellcheck';
5
+ import { logger } from '../utils';
8
6
  /**
9
7
  * CLI entry point for PR CheckMate.
10
8
  *
@@ -19,28 +17,28 @@ const utils_1 = require("../utils");
19
17
  * spellcheck - Run cspell spellcheck
20
18
  */
21
19
  const job = process.argv[2];
22
- async function runJob(jobName) {
20
+ export async function runJob(jobName) {
23
21
  switch (jobName) {
24
22
  case 'all':
25
- await (0, lint_1.runLint)();
26
- await (0, dependency_check_1.runDependencyCheck)();
27
- await (0, prettier_autoformat_1.runPrettier)();
28
- await (0, spellcheck_1.runSpellcheck)();
23
+ await runLint();
24
+ await runDependencyCheck();
25
+ await runPrettier();
26
+ await runSpellcheck();
29
27
  break;
30
28
  case 'lint':
31
- await (0, lint_1.runLint)();
29
+ await runLint();
32
30
  break;
33
31
  case 'deps':
34
- await (0, dependency_check_1.runDependencyCheck)();
32
+ await runDependencyCheck();
35
33
  break;
36
34
  case 'prettier':
37
- await (0, prettier_autoformat_1.runPrettier)();
35
+ await runPrettier();
38
36
  break;
39
37
  case 'spellcheck':
40
- await (0, spellcheck_1.runSpellcheck)();
38
+ await runSpellcheck();
41
39
  break;
42
40
  default:
43
- utils_1.logger.log('[runJob]: Available jobs: lint, deps, prettier, spellcheck');
41
+ logger.log('[runJob]: Available jobs: lint, deps, prettier, spellcheck');
44
42
  }
45
43
  }
46
44
  runJob(job).catch(err => {
@@ -1,41 +1,27 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.runLint = runLint;
7
- const execa_1 = require("execa");
8
- const utils_1 = require("../utils");
9
- const node_fs_1 = __importDefault(require("node:fs"));
10
- // /**
11
- // * Run ESLint on the project.
12
- // */
13
- // export async function runLint(): Promise<void> {
14
- // try {
15
- // logger.info('[runLint]: Running ESLint...');
16
- // // Run ESLint
17
- // await execa('npm', ['run', 'lint'], { stdio: 'inherit' });
18
- // logger.log('[runLint]: ✅ ESLint passed successfully.');
19
- // } catch (err: unknown) {
20
- // const errorMessage = err instanceof Error ? err.message : String(err);
21
- // logger.warn(`[runLint]: ⚠️ ESLint found issues: ${errorMessage}`);
22
- // // Don't throw - allow process to continue
23
- // }
24
- // }
25
- async function runLint() {
26
- utils_1.logger.info('Running ESLint...');
27
- const hasLocalConfig = node_fs_1.default.existsSync('eslint.config.mjs') ||
28
- node_fs_1.default.existsSync('.eslintrc.js') ||
29
- node_fs_1.default.existsSync('.eslintrc.json');
1
+ import { execa } from 'execa';
2
+ import { logger } from '../utils';
3
+ import { SOURCE_PATH } from '../config';
4
+ import fs from 'node:fs';
5
+ /**
6
+ * Run ESLint on the project.
7
+ * Uses local ESLint configuration if available; otherwise defaults to SOURCE_PATH.
8
+ *
9
+ * @throws Will throw an error if ESLint detects issues that cannot be fixed automatically.
10
+ */
11
+ export async function runLint() {
12
+ logger.info('Running ESLint...');
13
+ const hasLocalConfig = fs.existsSync('eslint.config.mjs') ||
14
+ fs.existsSync('.eslintrc.js') ||
15
+ fs.existsSync('.eslintrc.json');
30
16
  const args = hasLocalConfig
31
17
  ? ['eslint', '.', '--ext', '.ts,.tsx', '--fix']
32
- : ['eslint', 'src', '--ext', '.ts', '--fix'];
18
+ : ['eslint', SOURCE_PATH, '--ext', '.ts,.tsx', '--fix'];
33
19
  try {
34
- await (0, execa_1.execa)('npx', args, { stdio: 'inherit' });
35
- utils_1.logger.info('ESLint passed');
20
+ await execa('npx', args, { stdio: 'inherit' });
21
+ logger.info('ESLint passed');
36
22
  }
37
23
  catch (err) {
38
- utils_1.logger.warn('ESLint issues found');
24
+ logger.warn('ESLint issues found');
39
25
  throw err;
40
26
  }
41
27
  }
@@ -1,43 +1,27 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.runPrettier = runPrettier;
7
- const execa_1 = require("execa");
8
- const utils_1 = require("../utils");
9
- const node_fs_1 = __importDefault(require("node:fs"));
1
+ import { execa } from 'execa';
2
+ import { logger } from '../utils';
3
+ import fs from 'node:fs';
4
+ import { SOURCE_PATH } from '../config';
10
5
  /**
11
- * Run Prettier formatting inside container.
12
- * Git commit/push is done on the runner, not in Docker.
6
+ * Run Prettier to auto-format project files.
7
+ * If a Prettier config file exists, it runs on the whole project; otherwise on SOURCE_PATH.
8
+ *
9
+ * @throws Will throw an error if Prettier fails.
13
10
  */
14
- // export async function runPrettier(): Promise<void> {
15
- // try {
16
- // logger.info('[runPrettier]: Running Prettier auto-format...');
17
- // await execa('npm', ['run', 'prettier'], { stdio: 'inherit' });
18
- // logger.log(
19
- // '[runPrettier]: Prettier formatting completed (no git operations inside container)',
20
- // );
21
- // } catch (err: unknown) {
22
- // const errorMessage = err instanceof Error ? err.message : String(err);
23
- // logger.error('[runPrettier]: ❌ Prettier failed:', errorMessage);
24
- // throw err;
25
- // }
26
- // }
27
- async function runPrettier() {
28
- utils_1.logger.info('Running Prettier...');
29
- const hasConfig = node_fs_1.default.existsSync('.prettierrc') ||
30
- node_fs_1.default.existsSync('.prettierrc.json') ||
31
- node_fs_1.default.existsSync('prettier.config.js');
32
- const pattern = hasConfig ? '.' : 'src';
11
+ export async function runPrettier() {
12
+ logger.info('Running Prettier...');
13
+ const hasConfig = fs.existsSync('.prettierrc') ||
14
+ fs.existsSync('.prettierrc.json') ||
15
+ fs.existsSync('prettier.config.js');
16
+ const pattern = hasConfig ? '.' : SOURCE_PATH;
33
17
  try {
34
- await (0, execa_1.execa)('npx', ['prettier', '--write', `${pattern}/**/*`], {
18
+ await execa('npx', ['prettier', '--write', `${pattern}/**/*`], {
35
19
  stdio: 'inherit',
36
20
  });
37
- utils_1.logger.info('Prettier completed');
21
+ logger.info('Prettier completed');
38
22
  }
39
23
  catch (err) {
40
- utils_1.logger.error('Prettier failed');
24
+ logger.error('Prettier failed');
41
25
  throw err;
42
26
  }
43
27
  }
@@ -1,32 +1,21 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.runSpellcheck = runSpellcheck;
4
- const execa_1 = require("execa");
5
- const utils_1 = require("../utils");
1
+ import { execa } from 'execa';
2
+ import { logger } from '../utils';
3
+ import { SOURCE_PATH } from '../config';
6
4
  /**
7
- * Run spellcheck on the project using cspell.
5
+ * Run spellcheck using cspell on the project source files.
6
+ * Only runs on SOURCE_PATH.
7
+ *
8
+ * @throws Will throw an error if cspell detects spelling issues.
8
9
  */
9
- // export async function runSpellcheck(): Promise<void> {
10
- // try {
11
- // logger.info('[runSpellcheck]: Running spellcheck...');
12
- // await execa('npx', ['cspell', '**/*.{ts,tsx,js,jsx,md,json}', '--no-progress'], {
13
- // stdio: 'inherit',
14
- // });
15
- // logger.log('[runSpellcheck]: ✅ Spellcheck passed successfully.');
16
- // } catch (err: unknown) {
17
- // const errorMessage = err instanceof Error ? err.message : String(err);
18
- // logger.warn(`[runSpellcheck]: ⚠️ Spellcheck found errors: ${errorMessage}`);
19
- // // Don't throw - allow process to continue
20
- // }
21
- // }
22
- async function runSpellcheck() {
23
- utils_1.logger.info('Running spellcheck...');
10
+ export async function runSpellcheck() {
11
+ logger.info('Running spellcheck...');
12
+ const pattern = `${SOURCE_PATH}/**/*`;
24
13
  try {
25
- await (0, execa_1.execa)('npx', ['cspell', '**/*'], { stdio: 'inherit' });
26
- utils_1.logger.info('Spellcheck passed');
14
+ await execa('npx', ['cspell', pattern], { stdio: 'inherit' });
15
+ logger.info('Spellcheck passed');
27
16
  }
28
17
  catch (err) {
29
- utils_1.logger.warn('Spellcheck found issues');
18
+ logger.warn('Spellcheck found issues');
30
19
  throw err;
31
20
  }
32
21
  }
@@ -1,17 +1 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./logger"), exports);
1
+ export * from './logger';
@@ -1,6 +1,3 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.logger = void 0;
4
1
  class Logger {
5
2
  constructor() {
6
3
  this.logs = [];
@@ -62,4 +59,4 @@ class Logger {
62
59
  this.logs = [];
63
60
  }
64
61
  }
65
- exports.logger = new Logger();
62
+ export const logger = new Logger();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pr-checkmate",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "Automated PR quality checks: linting, formatting, dependency analysis, and spellcheck",
5
5
  "keywords": [
6
6
  "github-actions",
@@ -11,10 +11,10 @@
11
11
  "code-quality",
12
12
  "automation"
13
13
  ],
14
- "main": "dist/index.js",
14
+ "main": "./dist/cli.js",
15
15
  "types": "dist/index.d.ts",
16
16
  "bin": {
17
- "pr-checkmate": "./dist/scripts/index.js"
17
+ "pr-checkmate": "./dist/cli.js"
18
18
  },
19
19
  "files": [
20
20
  "dist",
@@ -46,15 +46,17 @@
46
46
  "author": "Your Name <your.email@example.com>",
47
47
  "license": "LicenseRef-Proprietary",
48
48
  "dependencies": {
49
- "execa": "^7.1.0",
50
- "eslint": "^9.39.1",
51
- "prettier": "^3.6.2",
52
- "cspell": "^6.30.0",
53
- "typescript": "^5.2.0",
49
+ "cspell": "^9.3.2",
50
+ "dotenv": "^17.2.3",
51
+ "eslint": ">=8.0.0",
52
+ "execa": "^9.6.0",
53
+ "inquirer": "^13.0.1",
54
+ "prettier": ">=3.0.0",
54
55
  "ts-node": "^10.9.1",
55
- "dotenv": "^17.2.3"
56
+ "typescript": "^5.9.3"
56
57
  },
57
58
  "devDependencies": {
59
+ "@types/inquirer": "^9.0.9",
58
60
  "@typescript-eslint/eslint-plugin": "^8.47.0",
59
61
  "@typescript-eslint/parser": "^8.47.0",
60
62
  "eslint-config-prettier": "^9.1.2",