Skip to content

Commit

Permalink
Refactor/armano cli (#1998)
Browse files Browse the repository at this point in the history
* chore: merge armanos branch

* refactor: merge cli typescript refactor with conflicts

Fixes #1691

Co-authored-by: escapedcat <github@htmlcss.de>
  • Loading branch information
byCedric and escapedcat committed Jul 13, 2020
1 parent d4f064c commit dabdfc9
Show file tree
Hide file tree
Showing 28 changed files with 503 additions and 404 deletions.
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: 9 additions & 21 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": ">=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
@@ -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,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/cli@9.1.1 - 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

0 comments on commit dabdfc9

Please sign in to comment.