Skip to content

Commit 2ce521b

Browse files
committed
refactor(cli): port cli to typescript
1 parent c9c968d commit 2ce521b

File tree

11 files changed

+224
-197
lines changed

11 files changed

+224
-197
lines changed

@commitlint/cli/package.json

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,8 @@
1111
"commitlint": "./lib/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": ">=8"
@@ -47,12 +36,7 @@
4736
},
4837
"license": "MIT",
4938
"devDependencies": {
50-
"@babel/cli": "^7.7.7",
51-
"@babel/core": "^7.7.7",
52-
"@commitlint/test": "8.2.0",
53-
"@commitlint/utils": "^8.3.4",
54-
"babel-preset-commitlint": "^8.2.0",
55-
"cross-env": "7.0.0",
39+
"@types/yargs": "^15.0.3",
5640
"execa": "0.11.0",
5741
"fs-extra": "^8.1.0"
5842
},
@@ -62,12 +46,10 @@
6246
"@commitlint/load": "^8.3.5",
6347
"@commitlint/read": "^8.3.4",
6448
"chalk": "3.0.0",
65-
"core-js": "^3.6.1",
6649
"get-stdin": "7.0.0",
6750
"lodash": "^4.17.15",
68-
"meow": "5.0.0",
69-
"regenerator-runtime": "0.13.3",
7051
"resolve-from": "5.0.0",
71-
"resolve-global": "1.0.0"
52+
"resolve-global": "1.0.0",
53+
"yargs": "^15.1.0"
7254
}
7355
}

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@ import fs from 'fs-extra';
66

77
const bin = require.resolve('../lib/cli.js');
88

9-
const cli = (args, options) => {
9+
interface TestOptions {
10+
cwd: string;
11+
env?: Record<string, string>;
12+
}
13+
14+
function cli(args: string[], options: TestOptions) {
1015
return (input = '') => {
1116
const c = execa(bin, args, {
1217
cwd: options.cwd,
@@ -15,10 +20,10 @@ const cli = (args, options) => {
1520
});
1621
return c.catch(err => err);
1722
};
18-
};
23+
}
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,7 @@ test('should work with relative formatter path', async () => {
423428
expect(actual.code).toBe(0);
424429
});
425430

426-
async function writePkg(payload, options) {
431+
async function writePkg(payload: unknown, options: TestOptions) {
427432
const pkgPath = path.join(options.cwd, 'package.json');
428433
const pkg = JSON.parse(await fs.readFile(pkgPath, 'utf-8'));
429434
const result = merge(pkg, payload);

0 commit comments

Comments
 (0)