Skip to content

Commit accbbbf

Browse files
authored
Massive Refactor 🤠 (#82)
* Swap Grunt to Gulp * Add binary files generated via gulp * Convert the project to ES2015, add Commander and change the structure
1 parent 68036bf commit accbbbf

23 files changed

+10650
-1196
lines changed

.eslintrc

Lines changed: 56 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,56 @@
1-
{
2-
"env": {
3-
"node": true
4-
},
5-
"parserOptions": {
6-
"ecmaVersion": 5,
7-
"sourceType": "module",
8-
"ecmaFeatures": {
9-
"impliedStrict": true
10-
},
11-
"allowImportExportEverywhere": false
12-
},
13-
14-
"extends": [
15-
"standard"
16-
],
17-
18-
"rules": {
19-
"semi": [2, "always"],
20-
"no-empty": 2,
21-
"array-callback-return": 2,
22-
"indent": [2, 4, { "SwitchCase": 1 }],
23-
"space-before-function-paren": [2, "never"],
24-
"no-debugger": 0
25-
}
26-
}
1+
parser: babel-eslint
2+
env:
3+
es6: true
4+
parserOptions:
5+
ecmaVersion: 6
6+
sourceType: module
7+
ecmaFeatures:
8+
impliedStrict: true
9+
allowImportExportEverywhere: false
10+
plugins:
11+
- babel
12+
extends:
13+
- semistandard
14+
rules:
15+
no-undef: 1
16+
no-unreachable: 1
17+
no-empty: error
18+
array-callback-return: error
19+
no-var: error
20+
indent:
21+
- error
22+
- 4
23+
-
24+
SwitchCase: 1
25+
space-before-function-paren:
26+
- error
27+
- never
28+
no-debugger: 0
29+
prefer-const: error
30+
strict: error
31+
no-template-curly-in-string: error
32+
consistent-return: error
33+
no-multiple-empty-lines:
34+
- error
35+
-
36+
max: 1
37+
maxBOF: 0
38+
no-lonely-if: error
39+
new-parens: error
40+
eol-last: error
41+
no-array-constructor: error
42+
arrow-body-style:
43+
- error
44+
- as-needed
45+
prefer-arrow-callback:
46+
- error
47+
-
48+
allowNamedFunctions: true
49+
prefer-destructuring:
50+
- error
51+
-
52+
object: true
53+
array: false
54+
prefer-spread: error
55+
prefer-rest-params: error
56+
valid-typeof: 0

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@ node_modules/
33
npm-debug.log
44
docs/_site
55
docs/.sass-cache
6+
dist
7+
bin

.npmignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
lib/
12
docs/
23
node_modules/
3-
Gruntfile.js
4+
gulpfile.js
45
.grenrc
56
.grenrc.*
67
.jsdoc.conf.json

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ cache:
99
- node_modules
1010

1111
before_install:
12-
- npm install -g grunt-cli
12+
- npm install -g gulp-cli
1313

1414
script:
15-
- grunt test
15+
- gulp test

Gruntfile.js

Lines changed: 0 additions & 23 deletions
This file was deleted.

bin/gren.js

100644100755
Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,31 @@
11
#!/usr/bin/env node
2+
'use strict';
23

3-
require('../github-release-notes');
4+
var _commander = require('commander');
5+
6+
var _commander2 = _interopRequireDefault(_commander);
7+
8+
var _package = require('../package.json');
9+
10+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11+
12+
var argvWithVersion = function argvWithVersion(argvs) {
13+
var vPos = argvs.indexOf('-v');
14+
15+
if (vPos > -1) {
16+
argvs[vPos] = '-V';
17+
}
18+
19+
return argvs;
20+
};
21+
22+
_commander2.default.version(_package.version).description(_package.description).usage('[command] [options]').command('release', 'Release into chunk').alias('r').command('changelog', 'Write a motherfucking changelog').alias('c').on('--help', function () {
23+
// Get help from markdown or json instead.
24+
console.log('');
25+
console.log(' Examples:');
26+
console.log('');
27+
console.log(' $ gren release');
28+
console.log('');
29+
console.log(' $ gren help release');
30+
console.log('');
31+
}).parse(argvWithVersion(process.argv));

gulpfile.js

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
const gulp = require('gulp');
2+
const mocha = require('gulp-mocha');
3+
const eslint = require('gulp-eslint');
4+
const watch = require('gulp-watch');
5+
const sass = require('gulp-sass');
6+
const gulpIf = require('gulp-if');
7+
const ghPages = require('gulp-gh-pages');
8+
const babel = require('gulp-babel');
9+
const chmod = require('gulp-chmod');
10+
const nodeunit = require('gulp-nodeunit');
11+
12+
gulp.task('deploy', ['build'], function() {
13+
return gulp.src('./docs/**/*')
14+
.pipe(ghPages());
15+
});
16+
17+
gulp.task('scripts', () => {
18+
gulp.src('./lib/src/**/*.js')
19+
.pipe(babel({
20+
presets: ['es2015']
21+
}))
22+
.pipe(gulp.dest('dist'));
23+
24+
gulp.src('./lib/src/**/*.json')
25+
.pipe(gulp.dest('dist'));
26+
27+
gulp.src('./lib/*.js')
28+
.pipe(babel({
29+
presets: ['es2015']
30+
}))
31+
.pipe(chmod(0o755))
32+
.pipe(gulp.dest('bin'));
33+
34+
});
35+
36+
gulp.task('lint', () => {
37+
const isFixed = file => file.eslint != null && file.eslint.fixed;
38+
39+
return gulp.src('./lib/**/*.js')
40+
.pipe(
41+
eslint({
42+
fix: true,
43+
envs: [
44+
'node'
45+
]
46+
})
47+
)
48+
.pipe(eslint.format())
49+
.pipe(gulpIf(isFixed, gulp.dest('./lib/')));
50+
});
51+
52+
gulp.task('watch', () => {
53+
return gulp.watch('./lib/**/*.js', ['lint', 'scripts']);
54+
});
55+
56+
gulp.task('test', () => {
57+
gulp.src('test/**/*.js')
58+
.pipe(nodeunit({
59+
reporter: 'junit',
60+
reporterOptions: {
61+
output: 'test'
62+
}
63+
}));
64+
});
65+
66+
gulp.task('build', ['lint', 'scripts', 'test']);
67+
gulp.task('default', ['build', 'watch']);

lib/_release-options.js

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
// TODO: write test to check whether there are any duplicates (short or name)
2+
export const options = [
3+
{
4+
short: '-u',
5+
name: 'username',
6+
valueType: '<repo owner>',
7+
description: 'The username of the repo e.g. github-tools'
8+
},
9+
{
10+
short: '-r',
11+
name: 'repo',
12+
valueType: '<repository name>',
13+
description: 'The repository name e.g. github-release-notes'
14+
},
15+
{
16+
short: '-T',
17+
name: 'token',
18+
valueType: '<github token>',
19+
description: 'The token generated with repo access'
20+
},
21+
{
22+
short: '-au',
23+
name: 'api-url',
24+
valueType: '<url>',
25+
description: 'Override the GitHub API URL, allows gren to connect to a private GHE installation'
26+
},
27+
{
28+
short: '-o',
29+
name: 'override',
30+
description: 'Override the release notes if exist.'
31+
},
32+
{
33+
short: '-t',
34+
name: 'tags',
35+
valueType: '<old-tag>..<new-tag>',
36+
description: 'Write release notes for a range of tags, a specific tag or all. e.g. 0.2.0..0.1.0 or 0.2.0.. or ..0.1.0 or 0.2.0 or *', // needs to be documented better,
37+
action: value => value.split('..')
38+
},
39+
{
40+
short: '-D',
41+
name: 'data-source',
42+
valueType: '<source>',
43+
description: 'The informations you want to use to build release notes.',
44+
action: /^(issues|commits|milestones)$/i,
45+
defaultValue: 'issues'
46+
},
47+
{
48+
short: '-im',
49+
name: 'include-messages',
50+
valueType: '<merge|commits|all>',
51+
description: 'Filter the messages added to the release notes. Only used when --data-source used is commits',
52+
action: /^(merge|commits|all)$/i,
53+
defaultValue: 'commits'
54+
},
55+
{
56+
short: '-p',
57+
name: 'prefix',
58+
valueType: '<name prefix>',
59+
description: 'Add a prefix to the tag version. e.g. \'v\''
60+
},
61+
{
62+
short: '-d',
63+
name: 'draft',
64+
description: 'Set the release as a draft.'
65+
},
66+
{
67+
short: '-pr',
68+
name: 'prerelease',
69+
description: 'Set the release as a prerelease.'
70+
},
71+
{
72+
short: '-g',
73+
name: 'group-by',
74+
valueType: '<"label"|Object>',
75+
description: 'Group the issues using the labels as group headings. You can set custom headings for groups of labels from a configuration file.'
76+
},
77+
{
78+
short: '-L',
79+
name: 'ignore-labels',
80+
valueType: '<label1>,<label2>,<label3>',
81+
description: 'Ignore the specified labels.',
82+
action: value => value.split(',')
83+
},
84+
{
85+
short: '-I',
86+
name: 'ignore-issues-with',
87+
valueType: '<label1>,<label2>,<label3>',
88+
description: 'Ignore issues that contains one of the specified labels.',
89+
action: value => value.split(',')
90+
},
91+
{
92+
short: '-mm',
93+
name: 'milestone-match',
94+
valueType: '<prefix>',
95+
description: 'The title that the script needs to match to link the release to the milestone. e.g. v will match v0.1.0'
96+
},
97+
{
98+
short: '-M',
99+
name: 'only-milestones',
100+
description: 'Add to the release bodies only the issues that have a milestone'
101+
}
102+
];

lib/gren-changelog.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/bin/env node
2+
3+
console.log('changelog');

lib/gren-release.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/usr/bin/env node
2+
3+
import Program from '../dist/Program';
4+
import GitHubInfo from '../dist/GitHubInfo';
5+
import Release from '../dist/Release';
6+
import { options } from './_release-options';
7+
8+
const githubInfo = new GitHubInfo();
9+
10+
githubInfo.options.then(githubOptions => Promise.resolve(new Program({
11+
name: 'gren release',
12+
description: 'Generate release notes and attach them to a tag',
13+
argv: process.argv,
14+
cwd: process.cwd(),
15+
bashOptions: Object.assign({}, ...githubOptions),
16+
options,
17+
events: {
18+
'--help': () => {
19+
console.log('');
20+
console.log(' Basic Examples:');
21+
console.log('');
22+
console.log(' $ gren release');
23+
console.log('');
24+
console.log(' $ gren release --tags 2.1.3..4.0.0');
25+
console.log('');
26+
}
27+
}
28+
})))
29+
.then(({ options }) => {
30+
const releaseAction = new Release(options);
31+
return releaseAction.release();
32+
})
33+
.catch(error => {
34+
console.error(error);
35+
});

0 commit comments

Comments
 (0)