Skip to content

Commit de07606

Browse files
committed
release: release version
1 parent e9bd122 commit de07606

File tree

3 files changed

+119
-1
lines changed

3 files changed

+119
-1
lines changed

dist/index.js

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/**
2+
* The MIT License (MIT)
3+
*
4+
* Copyright (c) 2017 Mickael Jeanroy
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
* THE SOFTWARE.
23+
*/
24+
25+
'use strict';
26+
27+
var fs = require('fs');
28+
var path = require('path');
29+
var _ = require('lodash');
30+
var moment = require('moment');
31+
var commenting = require('commenting');
32+
var through = require('through2');
33+
var gutil = require('gulp-util');
34+
var read = require('./read');
35+
36+
module.exports = function gulpHeaderComment() {
37+
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
38+
39+
var separator = _.isObject(options) && _.isString(options.separator) ? options.separator : '\n';
40+
var pkgPath = path.join(process.cwd(), 'package.json');
41+
var pkg = fs.existsSync(pkgPath) ? require(pkgPath) : {};
42+
43+
return through.obj(function (file, encoding, cb) {
44+
if (file.isNull() || file.isDirectory()) {
45+
return cb(null, file);
46+
}
47+
48+
read(options).then(function (content) {
49+
var templateFn = _.template(content);
50+
var template = templateFn({ _: _, moment: moment, pkg: pkg });
51+
var extension = path.extname(file.path);
52+
var header = commenting(template.trim(), { extension: extension }) + separator;
53+
54+
if (file.isBuffer()) {
55+
// Just prepend content.
56+
file.contents = new Buffer(header + file.contents);
57+
} else if (file.isStream()) {
58+
// Pipe to a new stream.
59+
var stream = through();
60+
stream.write(new Buffer(header));
61+
file.contents = file.contents.pipe(stream);
62+
}
63+
64+
cb(null, file);
65+
}).catch(function (err) {
66+
// Log error.
67+
gutil.log(gutil.colors.red('gulp-header-comment: ' + err));
68+
69+
// Wrap error.
70+
cb(new gutil.PluginError('gulp-header-comment', err));
71+
});
72+
});
73+
};

dist/read.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/**
2+
* The MIT License (MIT)
3+
*
4+
* Copyright (c) 2017 Mickael Jeanroy
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
* THE SOFTWARE.
23+
*/
24+
25+
'use strict';
26+
27+
var fs = require('fs');
28+
var _ = require('lodash');
29+
var Q = require('q');
30+
31+
module.exports = function read(options) {
32+
if (_.isString(options)) {
33+
return Q.when(options);
34+
}
35+
36+
var file = options.file;
37+
var encoding = options.encoding || 'utf-8';
38+
var deferred = Q.defer();
39+
40+
fs.readFile(file, { encoding: encoding }, function (err, data) {
41+
return err ? deferred.reject(err) : deferred.resolve(data);
42+
});
43+
44+
return deferred.promise;
45+
};

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "gulp-header-comment",
3-
"version": "0.1.0",
3+
"version": "0.2.0",
44
"description": "Gulp plugin to add header comments to files",
55
"main": "dist/index.js",
66
"scripts": {

0 commit comments

Comments
 (0)