From c4569854d073e82ef3926b86fca488d59b1b310e Mon Sep 17 00:00:00 2001 From: wangxingkang Date: Sun, 20 Oct 2019 04:32:33 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20walrus-plugin-commitlint=20=E5=BC=80?= =?UTF-8?q?=E5=8F=91=E5=AE=8C=E6=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 4 ++-- .../src/commitlint.config.js | 2 +- .../src/commitlint.ts | 24 +++++++++++++------ .../walrus-plugin-commitlint/src/index.ts | 11 ++++++++- 4 files changed, 30 insertions(+), 11 deletions(-) diff --git a/package.json b/package.json index 5ab9924..fd96f68 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "build": "father-build --watch", "clean": "lerna clean", "prerelease": "father-build", - "commitlint": "node ./packages/walrus-cli/lib/cli.js commitlint", + "commitlint": "node ./packages/walrus-cli/lib/cli.js commitlint --env HUSKY_GIT_PARAMS", "release": "yarn --pure-lockfile && node scripts/release.js" }, "devDependencies": { @@ -37,7 +37,7 @@ }, "husky": { "hooks": { - "commit-msg": "yarn commitlint --env HUSKY_GIT_PARAMS" + "commit-msg": "yarn commitlint" } }, "workspaces": [ diff --git a/packages/walrus-plugin-commitlint/src/commitlint.config.js b/packages/walrus-plugin-commitlint/src/commitlint.config.js index 12c46fe..390508e 100644 --- a/packages/walrus-plugin-commitlint/src/commitlint.config.js +++ b/packages/walrus-plugin-commitlint/src/commitlint.config.js @@ -1,4 +1,4 @@ -export default { +module.exports = { rules: { // Header 'header-max-length': [2, 'always', 200], diff --git a/packages/walrus-plugin-commitlint/src/commitlint.ts b/packages/walrus-plugin-commitlint/src/commitlint.ts index 5898fc8..e653b9e 100644 --- a/packages/walrus-plugin-commitlint/src/commitlint.ts +++ b/packages/walrus-plugin-commitlint/src/commitlint.ts @@ -13,6 +13,7 @@ const load = require('@commitlint/load'); const read = require('@commitlint/read'); const lint = require('@commitlint/lint'); const stdin = require('get-stdin'); +const pkg = require('../package.json'); export default async function commitLint( raw: string[] = [], @@ -20,11 +21,20 @@ export default async function commitLint( ) { const options = Object.assign({}, defaultOptions, config); - const fromStdin = checkFromStdin(raw, options); - - console.log(fromStdin); + if (options.env) { + if (!(options.env in process.env)) { + throw new Error( + `Recieved '${ + options.env + }' as value for --env, but environment variable '${ + options.env + }' is not available globally` + ); + } + options.edit = process.env[options.env]; + } - process.exit(1); + const fromStdin = checkFromStdin(raw, options); const range = lodash.pick(options, 'edit', 'from', 'to'); @@ -87,8 +97,6 @@ export default async function commitLint( // @ts-ignore const results = await Promise.all(lints); - console.log(results); - const report = results.reduce( (info, result) => { info.valid = result.valid ? info.valid : false; @@ -119,6 +127,8 @@ export default async function commitLint( } if (!report.valid) { - throw new Error(output); + const err = new Error(output); + err['type'] = pkg.name; + throw err; } } diff --git a/packages/walrus-plugin-commitlint/src/index.ts b/packages/walrus-plugin-commitlint/src/index.ts index dbe11d7..f1362f0 100644 --- a/packages/walrus-plugin-commitlint/src/index.ts +++ b/packages/walrus-plugin-commitlint/src/index.ts @@ -1,6 +1,8 @@ import { IApi, IConfig } from '@walrus/types'; import commitLint from './commitlint'; +const pkg = require('../package.json'); + export default function( api: IApi, config: IConfig @@ -13,6 +15,13 @@ export default function( '--config [file]': 'path to the config file' } }, (args) => { - commitLint(args._, Object.assign({}, config.pluginCommitLint, args)).then(); + commitLint(args._, Object.assign({}, config.pluginCommitLint, args)).catch(err => + setTimeout(() => { + if (err.type === pkg.name) { + process.exit(1); + } + throw err; + }) + );; }) }