Skip to content

Commit dabdfc9

Browse files
byCedricescapedcat
andauthored
Refactor/armano cli (#1998)
* chore: merge armanos branch * refactor: merge cli typescript refactor with conflicts Fixes #1691 Co-authored-by: escapedcat <[email protected]>
1 parent d4f064c commit dabdfc9

28 files changed

+503
-404
lines changed

@commitlint/cli/cli.js

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/usr/bin/env node
2+
require('./lib/cli.js');

@commitlint/cli/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
const path = require('path');
22

3-
module.exports = path.join(__dirname, 'lib/cli.js');
3+
module.exports = path.join(__dirname, 'cli.js');

@commitlint/cli/package.json

+9-21
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,15 @@
44
"description": "Lint your commit messages",
55
"files": [
66
"index.js",
7-
"lib",
8-
"!*.test.js*"
7+
"cli.js",
8+
"lib"
99
],
1010
"bin": {
11-
"commitlint": "./lib/cli.js"
11+
"commitlint": "./cli.js"
1212
},
1313
"scripts": {
14-
"build": "cross-env NODE_ENV=production babel src --out-dir lib --source-maps",
1514
"deps": "dep-check",
16-
"pkg": "pkg-check",
17-
"start": "yarn run watch",
18-
"watch": "babel src --out-dir lib --watch --source-maps"
19-
},
20-
"babel": {
21-
"presets": [
22-
"babel-preset-commitlint"
23-
],
24-
"ignore": [
25-
"**/*.test.js"
26-
]
15+
"pkg": "pkg-check"
2716
},
2817
"engines": {
2918
"node": ">=v8.17.0"
@@ -51,6 +40,7 @@
5140
"@babel/core": "^7.7.7",
5241
"@commitlint/test": "^9.1.1",
5342
"@commitlint/utils": "^9.1.1",
43+
"@types/yargs": "^15.0.3",
5444
"babel-preset-commitlint": "^9.1.1",
5545
"cross-env": "7.0.2",
5646
"execa": "^3.4.0",
@@ -65,11 +55,9 @@
6555
"chalk": "4.1.0",
6656
"core-js": "^3.6.1",
6757
"get-stdin": "7.0.0",
68-
"lodash": "^4.17.15",
69-
"meow": "5.0.0",
70-
"regenerator-runtime": "0.13.5",
58+
"lodash": "^4.17.19",
7159
"resolve-from": "5.0.0",
72-
"resolve-global": "1.0.0"
73-
},
74-
"gitHead": "cb565dfcca3128380b9b3dc274aedbcae34ce5ca"
60+
"resolve-global": "1.0.0",
61+
"yargs": "^15.1.0"
62+
}
7563
}

@commitlint/cli/src/cli-error.ts

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
export class CliError extends Error {
2+
__proto__ = Error;
3+
4+
public type: string;
5+
6+
constructor(message: string, type: string) {
7+
super(message);
8+
9+
this.type = type;
10+
11+
Object.setPrototypeOf(this, CliError.prototype);
12+
}
13+
}

@commitlint/cli/src/cli.test.js @commitlint/cli/src/cli.test.ts

+51-5
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,14 @@ import execa from 'execa';
44
import merge from 'lodash/merge';
55
import fs from 'fs-extra';
66

7-
const bin = require.resolve('../lib/cli.js');
7+
const bin = require.resolve('../cli.js');
88

9-
const cli = (args, options) => {
9+
interface TestOptions {
10+
cwd: string;
11+
env?: Record<string, string>;
12+
}
13+
14+
const cli = (args: string[], options: TestOptions) => {
1015
return (input = '') => {
1116
return execa(bin, args, {
1217
cwd: options.cwd,
@@ -17,8 +22,8 @@ const cli = (args, options) => {
1722
};
1823
};
1924

20-
const gitBootstrap = fixture => git.bootstrap(fixture, __dirname);
21-
const fixBootstrap = fixture => fix.bootstrap(fixture, __dirname);
25+
const gitBootstrap = (fixture: string) => git.bootstrap(fixture, __dirname);
26+
const fixBootstrap = (fixture: string) => fix.bootstrap(fixture, __dirname);
2227

2328
test('should throw when called without [input]', async () => {
2429
const cwd = await gitBootstrap('fixtures/default');
@@ -423,7 +428,48 @@ test('should work with relative formatter path', async () => {
423428
expect(actual.exitCode).toBe(0);
424429
});
425430

426-
async function writePkg(payload, options) {
431+
test('should print help', async () => {
432+
const cwd = await gitBootstrap('fixtures/default');
433+
const actual = await cli(['--help'], {cwd})();
434+
expect(actual.stdout).toMatchInlineSnapshot(`
435+
"@commitlint/[email protected] - Lint your commit messages
436+
437+
[input] reads from stdin if --edit, --env, --from and --to are omitted
438+
439+
Options:
440+
--color, -c toggle colored output [boolean] [default: true]
441+
--config, -g path to the config file [string]
442+
--cwd, -d directory to execute in
443+
[string] [default: (Working Directory)]
444+
--edit, -e read last commit message from the specified file or
445+
fallbacks to ./.git/COMMIT_EDITMSG
446+
[string] [default: false]
447+
--env, -E check message in the file at path given by environment
448+
variable value [string]
449+
--extends, -x array of shareable configurations to extend [array]
450+
--help-url, -H help url in error message [string]
451+
--from, -f lower end of the commit range to lint; applies if
452+
edit=false [string]
453+
--format, -o output format of the results [string]
454+
--parser-preset, -p configuration preset to use for
455+
conventional-commits-parser [string]
456+
--quiet, -q toggle console output [boolean] [default: false]
457+
--to, -t upper end of the commit range to lint; applies if
458+
edit=false [string]
459+
--verbose, -V enable verbose output for reports without problems
460+
[boolean]
461+
-v, --version display version information [boolean]
462+
-h, --help Show help [boolean]"
463+
`);
464+
});
465+
466+
test('should print version', async () => {
467+
const cwd = await gitBootstrap('fixtures/default');
468+
const actual = await cli(['--version'], {cwd})();
469+
expect(actual.stdout).toMatch('@commitlint/cli@');
470+
});
471+
472+
async function writePkg(payload: unknown, options: TestOptions) {
427473
const pkgPath = path.join(options.cwd, 'package.json');
428474
const pkg = JSON.parse(await fs.readFile(pkgPath, 'utf-8'));
429475
const result = merge(pkg, payload);

0 commit comments

Comments
 (0)