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/armano cli #1998

Merged
merged 2 commits into from
Jul 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions @commitlint/cli/cli.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/usr/bin/env node
require('./lib/cli.js');
2 changes: 1 addition & 1 deletion @commitlint/cli/index.js
Original file line number Diff line number Diff line change
@@ -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: 9 additions & 21 deletions @commitlint/cli/package.json
Original file line number Diff line number Diff line change
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": ">=v8.17.0"
Expand Down Expand Up @@ -51,6 +40,7 @@
"@babel/core": "^7.7.7",
"@commitlint/test": "^9.1.1",
"@commitlint/utils": "^9.1.1",
"@types/yargs": "^15.0.3",
"babel-preset-commitlint": "^9.1.1",
"cross-env": "7.0.2",
"execa": "^3.4.0",
Expand All @@ -65,11 +55,9 @@
"chalk": "4.1.0",
"core-js": "^3.6.1",
"get-stdin": "7.0.0",
"lodash": "^4.17.15",
"meow": "5.0.0",
"regenerator-runtime": "0.13.5",
"lodash": "^4.17.19",
"resolve-from": "5.0.0",
"resolve-global": "1.0.0"
},
"gitHead": "cb565dfcca3128380b9b3dc274aedbcae34ce5ca"
"resolve-global": "1.0.0",
"yargs": "^15.1.0"
}
}
13 changes: 13 additions & 0 deletions @commitlint/cli/src/cli-error.ts
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
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,48 @@ test('should work with relative formatter path', async () => {
expect(actual.exitCode).toBe(0);
});

async function writePkg(payload, options) {
test('should print help', async () => {
const cwd = await gitBootstrap('fixtures/default');
const actual = await cli(['--help'], {cwd})();
expect(actual.stdout).toMatchInlineSnapshot(`
"@commitlint/[email protected] - Lint your commit messages

[input] reads from stdin if --edit, --env, --from and --to are omitted

Options:
--color, -c toggle colored output [boolean] [default: true]
--config, -g path to the config file [string]
--cwd, -d directory to execute in
[string] [default: (Working Directory)]
--edit, -e read last commit message from the specified file or
fallbacks to ./.git/COMMIT_EDITMSG
[string] [default: false]
--env, -E check message in the file at path given by environment
variable value [string]
--extends, -x array of shareable configurations to extend [array]
--help-url, -H help url in error message [string]
--from, -f lower end of the commit range to lint; applies if
edit=false [string]
--format, -o output format of the results [string]
--parser-preset, -p configuration preset to use for
conventional-commits-parser [string]
--quiet, -q toggle console output [boolean] [default: false]
--to, -t upper end of the commit range to lint; applies if
edit=false [string]
--verbose, -V enable verbose output for reports without problems
[boolean]
-v, --version display version information [boolean]
-h, --help Show help [boolean]"
`);
});

test('should print version', async () => {
const cwd = await gitBootstrap('fixtures/default');
const actual = await cli(['--version'], {cwd})();
expect(actual.stdout).toMatch('@commitlint/cli@');
});

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
Loading