Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(cli): port cli to typescript #978

Closed
wants to merge 23 commits into from
Closed
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
8142287
refactor(cli): port cli to typescript
armano2 Feb 8, 2020
8670c15
chore(cli): cleanup code
armano2 Feb 8, 2020
b58696a
fix(cli): cleanup code and add missing dependencies
armano2 Feb 8, 2020
50afa34
fix(cli): restore original options array
armano2 Feb 8, 2020
f819a4c
fix(cli): set cli as executable
armano2 Feb 8, 2020
bb12a02
fix(cli): attempt to fix permissions on linux
armano2 Feb 8, 2020
27b1ccd
fix(cli): improve help format and setup version command
armano2 Feb 8, 2020
3d889a0
fix(cli): restore condition after refactoring
armano2 Feb 8, 2020
93f1e63
chore(cli): add missing todo
armano2 Feb 8, 2020
63123de
chore(cli): add missing type
armano2 Feb 8, 2020
e4efb34
chore: add missing new line in help and update CI doc
armano2 Feb 8, 2020
3a17ad8
docs: update default of cwd
armano2 Feb 8, 2020
8b57a0c
fix(cli): update published files
armano2 Feb 8, 2020
422b833
refactor(cli): rename cli-bin to cli
armano2 Feb 8, 2020
3f3d2e0
refactor(cli): add custom CliError and fix printing help
armano2 Feb 8, 2020
1f1e6a1
chore(cli): fix package.json
armano2 Feb 8, 2020
a0c4bb3
refactor(cli): use camelCase cli flag names
armano2 Feb 9, 2020
6fea4cf
fix: unify rule config types
marionebl Feb 9, 2020
4e12277
chore: drop no longer used package (issue after rebase)
armano2 Feb 9, 2020
17504f2
chore: remove todo comment as its already resolved
armano2 Feb 9, 2020
db186dd
fix: enable strict mode to reproduce previous behavior
armano2 Feb 9, 2020
4246081
chore: rollback some unnecessary changes
armano2 Feb 11, 2020
712f4cd
test(cli): add unit test for help and version commands
armano2 Feb 11, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions @commitlint/cli/cli.js
@@ -0,0 +1,2 @@
#!/usr/bin/env node
require('./lib/cli.js');
2 changes: 1 addition & 1 deletion @commitlint/cli/index.js
@@ -1,3 +1,3 @@
const path = require('path');

module.exports = path.join(__dirname, 'lib/cli.js');
module.exports = path.join(__dirname, 'cli.js');
30 changes: 7 additions & 23 deletions @commitlint/cli/package.json
Expand Up @@ -4,26 +4,15 @@
"description": "Lint your commit messages",
"files": [
"index.js",
"lib",
"!*.test.js*"
"cli.js",
"lib"
],
"bin": {
"commitlint": "./lib/cli.js"
"commitlint": "./cli.js"
},
"scripts": {
"build": "cross-env NODE_ENV=production babel src --out-dir lib --source-maps",
"deps": "dep-check",
"pkg": "pkg-check",
"start": "yarn run watch",
"watch": "babel src --out-dir lib --watch --source-maps"
},
"babel": {
"presets": [
"babel-preset-commitlint"
],
"ignore": [
"**/*.test.js"
]
"pkg": "pkg-check"
},
"engines": {
"node": ">=8"
Expand All @@ -47,12 +36,9 @@
},
"license": "MIT",
"devDependencies": {
"@babel/cli": "^7.7.7",
"@babel/core": "^7.7.7",
"@types/yargs": "^15.0.3",
"@commitlint/test": "8.2.0",
"@commitlint/utils": "^8.3.4",
"babel-preset-commitlint": "^8.2.0",
"cross-env": "7.0.0",
"execa": "^3.4.0",
"fs-extra": "^8.1.0"
},
Expand All @@ -62,12 +48,10 @@
"@commitlint/load": "^8.3.5",
"@commitlint/read": "^8.3.4",
"chalk": "3.0.0",
"core-js": "^3.6.1",
"get-stdin": "7.0.0",
"lodash": "^4.17.15",
"meow": "5.0.0",
"regenerator-runtime": "0.13.3",
"resolve-from": "5.0.0",
"resolve-global": "1.0.0"
"resolve-global": "1.0.0",
escapedcat marked this conversation as resolved.
Show resolved Hide resolved
"yargs": "^15.1.0"
}
}
13 changes: 13 additions & 0 deletions @commitlint/cli/src/cli-error.ts
@@ -0,0 +1,13 @@
export class CliError extends Error {
__proto__ = Error;

public type: string;

constructor(message: string, type: string) {
super(message);

this.type = type;

Object.setPrototypeOf(this, CliError.prototype);
}
}
Expand Up @@ -4,9 +4,14 @@ import execa from 'execa';
import merge from 'lodash/merge';
import fs from 'fs-extra';

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

const cli = (args, options) => {
interface TestOptions {
cwd: string;
env?: Record<string, string>;
}

const cli = (args: string[], options: TestOptions) => {
return (input = '') => {
return execa(bin, args, {
cwd: options.cwd,
Expand All @@ -17,8 +22,8 @@ const cli = (args, options) => {
};
};

const gitBootstrap = fixture => git.bootstrap(fixture, __dirname);
const fixBootstrap = fixture => fix.bootstrap(fixture, __dirname);
const gitBootstrap = (fixture: string) => git.bootstrap(fixture, __dirname);
const fixBootstrap = (fixture: string) => fix.bootstrap(fixture, __dirname);

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

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