Skip to content

Commit b05a3ef

Browse files
committed
style: Use prettier, standard-version, commitizen, husky
This updates to the modern dev stack, similar to documentation.js. Ideally this will make it easier if / when we merge this with documentation.js.
1 parent 13ae4a7 commit b05a3ef

File tree

3 files changed

+202
-166
lines changed

3 files changed

+202
-166
lines changed

Gruntfile.js

Lines changed: 30 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,30 @@
1-
/*
2-
* grunt-documentation
3-
* https://github.com/SunboX/grunt-documentation
4-
*
5-
* Copyright (c) 2015 André Fiedler
6-
* Licensed under the MIT license.
7-
*/
8-
9-
'use strict';
10-
11-
module.exports = function(grunt) {
12-
13-
// Project configuration.
14-
grunt.initConfig({
15-
jshint: {
16-
all: [
17-
'Gruntfile.js',
18-
'tasks/*.js'
19-
],
20-
options: {
21-
jshintrc: '.jshintrc'
22-
}
23-
}
24-
25-
});
26-
27-
// Actually load this plugin's task(s).
28-
grunt.loadTasks('tasks');
29-
30-
// These plugins provide necessary tasks.
31-
grunt.loadNpmTasks('grunt-contrib-jshint');
32-
33-
// By default, lint and run all tests.
34-
grunt.registerTask('default', ['jshint']);
35-
36-
};
1+
/*
2+
* grunt-documentation
3+
* https://github.com/SunboX/grunt-documentation
4+
*
5+
* Copyright (c) 2015 André Fiedler
6+
* Licensed under the MIT license.
7+
*/
8+
9+
'use strict';
10+
11+
module.exports = function(grunt) {
12+
// Project configuration.
13+
grunt.initConfig({
14+
jshint: {
15+
all: ['Gruntfile.js', 'tasks/*.js'],
16+
options: {
17+
jshintrc: '.jshintrc'
18+
}
19+
}
20+
});
21+
22+
// Actually load this plugin's task(s).
23+
grunt.loadTasks('tasks');
24+
25+
// These plugins provide necessary tasks.
26+
grunt.loadNpmTasks('grunt-contrib-jshint');
27+
28+
// By default, lint and run all tests.
29+
grunt.registerTask('default', ['jshint']);
30+
};

package.json

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
"email": "[email protected]"
99
},
1010
"scripts": {
11-
"test": "grunt"
11+
"test": "grunt",
12+
"precommit": "lint-staged --verbose",
13+
"release": "standard-version"
1214
},
1315
"repository": {
1416
"type": "git",
@@ -22,8 +24,13 @@
2224
"node": ">= 0.8.0"
2325
},
2426
"devDependencies": {
27+
"cz-conventional-changelog": "^2.0.0",
28+
"grunt": "latest",
2529
"grunt-contrib-jshint": "latest",
26-
"grunt": "latest"
30+
"husky": "^0.13.3",
31+
"lint-staged": "^3.4.0",
32+
"prettier": "^1.2.2",
33+
"standard-version": "^4.0.0"
2734
},
2835
"peerDependencies": {
2936
"grunt": ">=0.4.0"
@@ -35,9 +42,19 @@
3542
"gruntplugin"
3643
],
3744
"dependencies": {
38-
"chalk": "latest",
39-
"documentation": "4.0.0-beta.18",
40-
"module-deps": "latest",
41-
"escape-string-regexp": "latest"
45+
"chalk": "^1.0.0",
46+
"documentation": "4.0.0-rc.0",
47+
"escape-string-regexp": "^1.0.5"
48+
},
49+
"lint-staged": {
50+
"*.js": [
51+
"prettier --write --single-quote",
52+
"git add"
53+
]
54+
},
55+
"config": {
56+
"commitizen": {
57+
"path": "./node_modules/cz-conventional-changelog"
58+
}
4259
}
4360
}

tasks/documentation.js

Lines changed: 149 additions & 124 deletions
Original file line numberDiff line numberDiff line change
@@ -1,124 +1,149 @@
1-
/*
2-
* grunt-documentation
3-
* https://github.com/documentationjs/grunt-documentation
4-
*
5-
* Copyright (c) 2015 André Fiedler
6-
* Licensed under the MIT license.
7-
*/
8-
'use strict';
9-
10-
module.exports = function(grunt) {
11-
12-
var path = require('path'),
13-
chalk = require('chalk'),
14-
documentation = require('documentation').build || require('documentation'),
15-
formats = require('documentation').formats;
16-
17-
grunt.registerMultiTask('documentation', 'Use Grunt with documentation to generate great documentation for your JavaScript projects.', function() {
18-
var options = this.options({
19-
format: 'html',
20-
shallow: false,
21-
github: false,
22-
access: ['public', 'protected', 'undefined'],
23-
order: []
24-
});
25-
26-
var formatter = formats[options.format];
27-
if (!formatter) {
28-
throw new Error('invalid format given: valid options are ' + Object.keys(formats).join(', '));
29-
}
30-
31-
var docOptions = {
32-
github: options.github,
33-
shallow: options.shallow,
34-
access: options.access,
35-
toc: options.toc || options.order,
36-
theme: options.theme,
37-
name: options.name,
38-
version: options.version
39-
};
40-
41-
var done = this.async(),
42-
waiting = 0;
43-
44-
function await (c) {
45-
c = c || 1;
46-
waiting += c;
47-
}
48-
49-
function release() {
50-
waiting--;
51-
if (waiting <= 0) {
52-
done();
53-
grunt.log.writeln(chalk.green('Done, created documentation at ') + path.join(process.cwd(), options.destination));
54-
}
55-
}
56-
57-
function generateDocs(files) {
58-
await ();
59-
documentation(files, docOptions, function(err, comments) {
60-
if (err) {
61-
grunt.log.error(err.toString());
62-
if (err.codeFrame) {
63-
grunt.log.error(err.codeFrame);
64-
}
65-
done(false);
66-
} else {
67-
await ();
68-
formatter(comments, docOptions, function(err, output) {
69-
if (err) {
70-
grunt.log.error(err.toString());
71-
if (err.codeFrame) {
72-
grunt.log.error(err.codeFrame);
73-
}
74-
done(false);
75-
} else {
76-
if (options.format === 'json' || options.format === 'md') {
77-
var dest = path.join(process.cwd(), options.destination, (options.filename || 'API.' + options.format));
78-
grunt.file.write(dest, output);
79-
grunt.log.writeln('File ' + chalk.cyan(options.filename || 'API.' + options.format) + ' created.');
80-
} else if (options.format === 'html') {
81-
await (output.length);
82-
output.forEach(function(file) {
83-
var dest = path.join(process.cwd(), options.destination, file.relative);
84-
if (file.isDirectory() || grunt.file.isDir(file.path)) {
85-
grunt.file.mkdir(dest);
86-
grunt.verbose.writeln('Directory ' + chalk.cyan(file.relative) + ' created.');
87-
} else {
88-
grunt.file.write(dest, file.contents);
89-
grunt.verbose.writeln('File ' + chalk.cyan(file.relative) + ' created.');
90-
}
91-
release();
92-
});
93-
}
94-
}
95-
release();
96-
});
97-
}
98-
release();
99-
});
100-
}
101-
102-
var files = [];
103-
104-
var filesToProcess = this.files.length;
105-
106-
this.files.forEach(function(f) {
107-
var src = f.src.filter(function(filepath) {
108-
// Warn on and remove invalid source files (if nonull was set).
109-
if (!grunt.file.exists(filepath)) {
110-
grunt.log.warn('Source file "' + filepath + '" not found.');
111-
return false;
112-
} else {
113-
return true;
114-
}
115-
});
116-
files = files.concat(src);
117-
filesToProcess--;
118-
if (filesToProcess <= 0) {
119-
generateDocs(files);
120-
}
121-
}.bind(this));
122-
});
123-
124-
};
1+
/*
2+
* grunt-documentation
3+
* https://github.com/documentationjs/grunt-documentation
4+
*
5+
* Copyright (c) 2015 André Fiedler
6+
* Licensed under the MIT license.
7+
*/
8+
'use strict';
9+
10+
module.exports = function(grunt) {
11+
var path = require('path'),
12+
chalk = require('chalk'),
13+
documentation = require('documentation').build || require('documentation'),
14+
formats = require('documentation').formats;
15+
16+
grunt.registerMultiTask(
17+
'documentation',
18+
'Use Grunt with documentation to generate great documentation for your JavaScript projects.',
19+
function() {
20+
var options = this.options({
21+
format: 'html',
22+
shallow: false,
23+
github: false,
24+
access: ['public', 'protected', 'undefined'],
25+
order: []
26+
});
27+
28+
var formatter = formats[options.format];
29+
if (!formatter) {
30+
throw new Error(
31+
'invalid format given: valid options are ' +
32+
Object.keys(formats).join(', ')
33+
);
34+
}
35+
36+
var docOptions = {
37+
github: options.github,
38+
shallow: options.shallow,
39+
access: options.access,
40+
toc: options.toc || options.order,
41+
theme: options.theme,
42+
name: options.name,
43+
version: options.version
44+
};
45+
46+
var done = this.async(), waiting = 0;
47+
48+
function wait(c) {
49+
c = c || 1;
50+
waiting += c;
51+
}
52+
53+
function release() {
54+
waiting--;
55+
if (waiting <= 0) {
56+
done();
57+
grunt.log.writeln(
58+
chalk.green('Done, created documentation at ') +
59+
path.join(process.cwd(), options.destination)
60+
);
61+
}
62+
}
63+
64+
function generateDocs(files) {
65+
wait();
66+
documentation(files, docOptions, function(err, comments) {
67+
if (err) {
68+
grunt.log.error(err.toString());
69+
if (err.codeFrame) {
70+
grunt.log.error(err.codeFrame);
71+
}
72+
done(false);
73+
} else {
74+
wait();
75+
formatter(comments, docOptions, function(err, output) {
76+
if (err) {
77+
grunt.log.error(err.toString());
78+
if (err.codeFrame) {
79+
grunt.log.error(err.codeFrame);
80+
}
81+
done(false);
82+
} else {
83+
if (options.format === 'json' || options.format === 'md') {
84+
var dest = path.join(
85+
process.cwd(),
86+
options.destination,
87+
options.filename || 'API.' + options.format
88+
);
89+
grunt.file.write(dest, output);
90+
grunt.log.writeln(
91+
'File ' +
92+
chalk.cyan(options.filename || 'API.' + options.format) +
93+
' created.'
94+
);
95+
} else if (options.format === 'html') {
96+
wait(output.length);
97+
output.forEach(function(file) {
98+
var dest = path.join(
99+
process.cwd(),
100+
options.destination,
101+
file.relative
102+
);
103+
if (file.isDirectory() || grunt.file.isDir(file.path)) {
104+
grunt.file.mkdir(dest);
105+
grunt.verbose.writeln(
106+
'Directory ' + chalk.cyan(file.relative) + ' created.'
107+
);
108+
} else {
109+
grunt.file.write(dest, file.contents);
110+
grunt.verbose.writeln(
111+
'File ' + chalk.cyan(file.relative) + ' created.'
112+
);
113+
}
114+
release();
115+
});
116+
}
117+
}
118+
release();
119+
});
120+
}
121+
release();
122+
});
123+
}
124+
125+
var files = [];
126+
127+
var filesToProcess = this.files.length;
128+
129+
this.files.forEach(
130+
function(f) {
131+
var src = f.src.filter(function(filepath) {
132+
// Warn on and remove invalid source files (if nonull was set).
133+
if (!grunt.file.exists(filepath)) {
134+
grunt.log.warn('Source file "' + filepath + '" not found.');
135+
return false;
136+
} else {
137+
return true;
138+
}
139+
});
140+
files = files.concat(src);
141+
filesToProcess--;
142+
if (filesToProcess <= 0) {
143+
generateDocs(files);
144+
}
145+
}.bind(this)
146+
);
147+
}
148+
);
149+
};

0 commit comments

Comments
 (0)