Skip to content

Commit

Permalink
feat: walrus-plugin-commitlint 开发完毕
Browse files Browse the repository at this point in the history
  • Loading branch information
wangxingkang committed Oct 19, 2019
1 parent edf604f commit c456985
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 11 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down Expand Up @@ -37,7 +37,7 @@
},
"husky": {
"hooks": {
"commit-msg": "yarn commitlint --env HUSKY_GIT_PARAMS"
"commit-msg": "yarn commitlint"
}
},
"workspaces": [
Expand Down
2 changes: 1 addition & 1 deletion packages/walrus-plugin-commitlint/src/commitlint.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export default {
module.exports = {
rules: {
// Header
'header-max-length': [2, 'always', 200],
Expand Down
24 changes: 17 additions & 7 deletions packages/walrus-plugin-commitlint/src/commitlint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,28 @@ 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[] = [],
config: IPluginCommitLintOptions = {}
) {
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');

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}
11 changes: 10 additions & 1 deletion packages/walrus-plugin-commitlint/src/index.ts
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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;
})
);;
})
}

0 comments on commit c456985

Please sign in to comment.