Skip to content

Commit 7e4dd3d

Browse files
committed
misc(add commitlinting): adds commit linting to the cli
1 parent 4333088 commit 7e4dd3d

File tree

11 files changed

+1645
-70
lines changed

11 files changed

+1645
-70
lines changed

.appveyor.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ test_script:
2424
- yarn appveyor:prepare
2525
- yarn appveyor:lint
2626
- yarn appveyor:test
27+
- yarn bundlesize
2728

2829
cache:
2930
- node_modules -> appveyor.yml,package.json,yarn.lock

.cz-config.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* @license Copyright 2017 Google Inc. All Rights Reserved.
3+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
4+
* use this file except in compliance with the License. You may obtain a copy of
5+
* the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by
6+
* applicable law or agreed to in writing, software distributed under the
7+
* License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
8+
* OF ANY KIND, either express or implied. See the License for the specific
9+
* language governing permissions and limitations under the License.
10+
*/
11+
// Based on https://github.com/GoogleChrome/lighthouse/blob/master/.cz-config.js
12+
13+
'use strict';
14+
15+
module.exports = {
16+
allowBreakingChanges: ['ast'],
17+
allowCustomScopes: true,
18+
scopes: [],
19+
types: [
20+
{value: 'new_feature', name: 'new_feature: A new feature'}, {
21+
value: 'ast',
22+
name: 'ast: init, migrate, add, etc'
23+
},
24+
{value: 'tests', name: 'tests: Tests, jest, binTestCases etc'},
25+
{value: 'docs', name: 'docs: Documentation'},
26+
{value: 'deps', name: 'deps: Dependency bumps only'},
27+
{value: 'cli', name: 'cli: core CLI things'},
28+
{value: 'misc', name: 'misc: Other formats like tweaks and such'}
29+
]
30+
};

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ matrix:
1717
- os: linux
1818
node_js: "6"
1919
env: JOB_PART=integration
20-
2120
sudo: false
2221

2322
notifications:
@@ -33,3 +32,4 @@ before_script:
3332

3433
script:
3534
- npm run travis:$JOB_PART
35+
- commitlint-travis

CHANGELOG.md

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,49 @@
1-
# Change Log
1+
<a name="2.0.6"></a>
2+
# 2.0.6 (2018-02-19)
3+
[Full Changelog](https://github.com/webpack/webpack-cli/compare/v2.0.4...v2.0.6)
4+
5+
## Chore
6+
7+
* .gitignore: ignore .vscode ([ab0eacc](https://github.com/webpack/webpack-cli/commit/ab0eacc))
8+
* .gitignore: ignore .vscode ([a322505](https://github.com/webpack/webpack-cli/commit/a322505))
9+
10+
## Feat
11+
12+
* show help when no options given ([a7ee15a](https://github.com/webpack/webpack-cli/commit/a7ee15a))
13+
14+
## Fix
15+
16+
* Resolve webpack dependencies ([#251](https://github.com/webpack/webpack-cli/pull/251))
17+
* change help logic ([d67f4b7](https://github.com/webpack/webpack-cli/commit/d67f4b7))
18+
19+
## Improvement
20+
21+
* add an option to watch messaging. Add .idea to .gitignore ([#200](https://github.com/webpack/webpack-cli/pull/200))
22+
23+
## Refactor
24+
25+
* convert-args: remove unused arguments ([#253](https://github.com/webpack/webpack-cli/pull/253))
26+
27+
## Style
28+
29+
* run formatter ([7be0da7](https://github.com/webpack/webpack-cli/commit/7be0da7))
30+
31+
## Tests
32+
33+
* add test for showing help on no options ([cf43939](https://github.com/webpack/webpack-cli/commit/cf43939))
34+
35+
## Misc
36+
37+
* adds bundlesize and CI's for it ([59b8772](https://github.com/webpack/webpack-cli/commit/59b8772))
38+
* v.2.0.6 ([4333088](https://github.com/webpack/webpack-cli/commit/4333088))
39+
* fix typo.. ([0f1cee6](https://github.com/webpack/webpack-cli/commit/0f1cee6))
40+
* 2.0.5 ([94ac6db](https://github.com/webpack/webpack-cli/commit/94ac6db))
41+
* remove yargs major update due security compromise ([9bd7ed4](https://github.com/webpack/webpack-cli/commit/9bd7ed4))
42+
* Issue 249 fixed and other enums refactored ([#264](https://github.com/webpack/webpack-cli/pull/264))
43+
* Refactor bin directory ([#263](https://github.com/webpack/webpack-cli/pull/263))
44+
* Add jsdoc comments for migrate ([#255](https://github.com/webpack/webpack-cli/pull/255))
45+
* Change from git:// to https:// ([#259](https://github.com/webpack/webpack-cli/pull/259))
46+
* [feature] configuration validation ([#240](https://github.com/webpack/webpack-cli/pull/240))
247

348
<a name="2.0.0"></a>
449
## 2.0.0 (2017-12-21)

build/changelog-generator/index.js

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
/**
2+
* @license Copyright 2017 Google Inc. All Rights Reserved.
3+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
4+
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
5+
* Based on: https://github.com/GoogleChrome/lighthouse/blob/master/build/changelog-generator/
6+
*/
7+
'use strict';
8+
const readFileSync = require('fs').readFileSync;
9+
const resolve = require('path').resolve;
10+
const mainTemplate = readFileSync(resolve(__dirname, 'templates/template.hbs')).toString();
11+
const headerPartial = readFileSync(resolve(__dirname, 'templates/header.hbs')).toString();
12+
const commitPartial = readFileSync(resolve(__dirname, 'templates/commit.hbs')).toString();
13+
14+
const pullRequestRegex = /\(#(\d+)\)$/;
15+
const parserOpts = {
16+
headerPattern: /^(\w*)(?:\((.*)\))?: (.*)$/,
17+
headerCorrespondence: [
18+
'type',
19+
'scope',
20+
'message',
21+
],
22+
};
23+
24+
process.stderr.write(`
25+
> Be sure to have the latest git tags locally:
26+
git fetch --tags
27+
28+
`);
29+
30+
const writerOpts = {
31+
mainTemplate,
32+
headerPartial,
33+
commitPartial,
34+
transform: commit => {
35+
if (typeof commit.hash === 'string') {
36+
commit.hash = commit.hash.substring(0, 7);
37+
}
38+
39+
if (commit.type === 'test') {
40+
commit.type = 'tests';
41+
} else if (commit.type === 'cli') {
42+
commit.type = 'CLI';
43+
} else if (commit.type === 'new_feature') {
44+
commit.type = 'New Features';
45+
}
46+
47+
if (commit.type) {
48+
commit.type = commit.type.replace(/_/g, ' ');
49+
commit.type = commit.type.substring(0, 1).toUpperCase() + commit.type.substring(1);
50+
} else {
51+
commit.type = 'Misc';
52+
}
53+
54+
let pullRequestMatch = commit.header.match(pullRequestRegex);
55+
// if header does not provide a PR we try the message
56+
if (!pullRequestMatch && commit.message) {
57+
pullRequestMatch = commit.message.match(pullRequestRegex);
58+
}
59+
60+
if (pullRequestMatch) {
61+
commit.header = commit.header.replace(pullRequestMatch[0], '').trim();
62+
if (commit.message) {
63+
commit.message = commit.message.replace(pullRequestMatch[0], '').trim();
64+
}
65+
66+
commit.PR = pullRequestMatch[1];
67+
}
68+
69+
return commit;
70+
},
71+
groupBy: 'type',
72+
commitGroupsSort: (a, b) => {
73+
// put new feature on the top
74+
if (a.title === 'New Features') {
75+
return -1;
76+
}
77+
if (b.title === 'New Features') {
78+
return 1;
79+
}
80+
81+
// put misc on the bottom
82+
if (a.title === 'Misc') {
83+
return 1;
84+
}
85+
if (b.title === 'Misc') {
86+
return -1;
87+
}
88+
89+
return a.title.localeCompare(b.title);
90+
},
91+
commitsSort: ['type', 'scope'],
92+
};
93+
94+
module.exports = {
95+
writerOpts,
96+
parserOpts,
97+
};
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{{!--
2+
/**
3+
* @license Copyright 2017 Google Inc. All Rights Reserved.
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
5+
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
6+
*/
7+
From: https://github.com/GoogleChrome/lighthouse/blob/master/build/changelog-generator/
8+
--}}
9+
* {{#if scope}}{{scope}}: {{/if~}}
10+
{{#if message ~}}
11+
{{~message~}}
12+
{{~else~}}
13+
{{~header~}}
14+
{{~/if ~}}
15+
{{~!-- PR number/commit hash --}}
16+
{{~#if @root.linkReferences~}}
17+
{{~#if PR}} ([#{{PR}}](
18+
{{~#if @root.host}}{{~@root.host}}/{{/if~}}
19+
{{~#if @root.owner ~}}{{@root.owner}}/{{/if~}}
20+
{{~@root.repository}}/pull/{{PR}}))
21+
{{~else}} ([{{hash}}](
22+
{{~#if @root.host}}{{~@root.host}}/{{/if~}}
23+
{{~#if @root.owner ~}}{{@root.owner}}/{{/if~}}
24+
{{~@root.repository}}/{{@root.commit}}/{{hash}}))
25+
{{~/if~}}
26+
{{~else~}}
27+
{{~hash~}}
28+
{{~/if~}}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{{!--
2+
/**
3+
* @license Copyright 2017 Google Inc. All Rights Reserved.
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
5+
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
6+
*/
7+
From: https://github.com/GoogleChrome/lighthouse/blob/master/build/changelog-generator/
8+
--}}
9+
<a name="{{version}}"></a>
10+
# {{version}} ({{date}})
11+
{{#if @root.linkCompare~}}
12+
[Full Changelog]({{~@root.repoUrl}}/compare/{{previousTag}}...{{currentTag}})
13+
{{~/if}}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{{!--
2+
/**
3+
* @license Copyright 2017 Google Inc. All Rights Reserved.
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
5+
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
6+
*/
7+
From: https://github.com/GoogleChrome/lighthouse/blob/master/build/changelog-generator/
8+
--}}
9+
{{> header}}
10+
11+
{{#each commitGroups}}
12+
13+
{{#if title~}}
14+
## {{title}}
15+
16+
{{/if}}
17+
{{#each commits}}
18+
{{~> commit root=@root}}
19+
20+
{{/each}}
21+
{{/each}}
22+

commitlint.config.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* @license Copyright 2017 Google Inc. All Rights Reserved.
3+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
4+
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
5+
*/
6+
7+
// Config from https://github.com/GoogleChrome/lighthouse/blob/master/commitlint.config.js
8+
'use strict';
9+
10+
module.exports = {
11+
extends: ['cz'],
12+
rules: {
13+
'body-leading-blank': [1, 'always'],
14+
'body-tense': [1, 'always', ['present-imperative']],
15+
'footer-leading-blank': [1, 'always'],
16+
'footer-tense': [1, 'always', ['present-imperative']],
17+
'header-max-length': [2, 'always', 80],
18+
'lang': [0, 'always', 'eng'],
19+
'scope-case': [2, 'always', 'lowerCase'],
20+
'scope-empty': [0, 'never'],
21+
'subject-case': [1, 'always', 'lowerCase'],
22+
'subject-empty': [0, 'never'],
23+
'subject-full-stop': [2, 'never', '.'],
24+
'subject-tense': [1, 'always', ['present-imperative']],
25+
'type-case': [2, 'always', 'lowerCase'],
26+
'type-empty': [2, 'never'],
27+
// The scope-enum : defined in the cz-config
28+
// The 'type-enum': defined in the cz-config
29+
},
30+
};

package.json

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,16 @@
2929
"appveyor:lint": "yarn lint",
3030
"appveyor:test": "nyc jest && yarn reportCoverage",
3131
"travis:integration": "yarn prepare && nyc jest && yarn reportCoverage",
32-
"travis:lint": "yarn lint"
32+
"travis:lint": "yarn lint && yarn bundlesize",
33+
"bundlesize": "bundlesize",
34+
"commitmsg": "commitlint -e $GIT_PARAMS",
35+
"commit": "commit",
36+
"changelog": "conventional-changelog --config ./build/changelog-generator/index.js --infile changelog.md --same-file"
3337
},
3438
"lint-staged": {
3539
"{lib,bin}/**/!(__testfixtures__)/**.js": [
3640
"eslint --fix",
41+
"npm run commitmsg",
3742
"git add"
3843
]
3944
},
@@ -57,6 +62,28 @@
5762
],
5863
"all": true
5964
},
65+
"bundlesize": [
66+
{
67+
"path": "./lib/migrate/**.js",
68+
"maxSize": "1 kB"
69+
},
70+
{
71+
"path": "./lib/init/**/**.js",
72+
"maxSize": "1.5 kB"
73+
},
74+
{
75+
"path": "./lib/utils/**.js",
76+
"maxSize": "5 kB"
77+
}
78+
],
79+
"config": {
80+
"commitizen": {
81+
"path": "./node_modules/cz-customizable"
82+
},
83+
"cz-customizable": {
84+
"config": "./.cz-config.js"
85+
}
86+
},
6087
"dependencies": {
6188
"chalk": "^2.0.1",
6289
"codecov": "^3.0.0",
@@ -88,6 +115,14 @@
88115
"yeoman-generator": "https://github.com/ev1stensberg/generator.git#Feature-getArgument"
89116
},
90117
"devDependencies": {
118+
"@commitlint/cli": "^6.1.0",
119+
"@commitlint/prompt-cli": "^6.1.0",
120+
"@commitlint/travis-cli": "^6.1.0",
121+
"bundlesize": "^0.16.0",
122+
"commitizen": "^2.9.6",
123+
"conventional-changelog-cli": "^1.3.13",
124+
"conventional-changelog-lint-config-cz": "^0.3.0",
125+
"cz-customizable": "^5.2.0",
91126
"eslint": "^4.2.0",
92127
"eslint-plugin-node": "^5.1.0",
93128
"flow-bin": "^0.49.1",

0 commit comments

Comments
 (0)