UNPKG

4.14 kBJavaScriptView Raw
1/*
2 Copyright (C) 2014 Yusuke Suzuki <utatane.tea@gmail.com>
3
4 Redistribution and use in source and binary forms, with or without
5 modification, are permitted provided that the following conditions are met:
6
7 * Redistributions of source code must retain the above copyright
8 notice, this list of conditions and the following disclaimer.
9 * Redistributions in binary form must reproduce the above copyright
10 notice, this list of conditions and the following disclaimer in the
11 documentation and/or other materials provided with the distribution.
12
13 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS'
14 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
17 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
19 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
20 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
22 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23*/
24
25'use strict';
26
27var gulp = require('gulp');
28var mocha = require('gulp-mocha');
29var jshint = require('gulp-jshint');
30var eslint = require('gulp-eslint');
31var istanbul = require('gulp-istanbul');
32var bump = require('gulp-bump');
33var filter = require('gulp-filter');
34var git = require('gulp-git');
35var tagVersion = require('gulp-tag-version');
36
37var SRC = [ 'lib/*.js' ];
38
39var TEST = [ 'test/*.js' ];
40
41var LINT = [
42 'gulpfile.js'
43].concat(SRC);
44
45var ESLINT_OPTION = {
46 'rules': {
47 'quotes': 0,
48 'eqeqeq': 0,
49 'no-use-before-define': 0,
50 'no-underscore-dangle': 0,
51 'no-shadow': 0,
52 'no-constant-condition': 0,
53 'no-multi-spaces': 0,
54 'dot-notation': [2, {'allowKeywords': false}]
55 },
56 'env': {
57 'node': true
58 }
59};
60
61gulp.task('test', function (cb) {
62 gulp.src(SRC)
63 .pipe(istanbul()) // Covering files
64 .on('finish', function () {
65 gulp.src(TEST)
66 .pipe(mocha({
67 reporter: 'spec',
68 timeout: 100000 // 100s
69 }))
70 .pipe(istanbul.writeReports()) // Creating the reports after tests runned
71 .on('end', cb);
72 });
73});
74
75gulp.task('lint', function () {
76 return gulp.src(LINT)
77 .pipe(jshint('.jshintrc'))
78 .pipe(jshint.reporter(require('jshint-stylish')))
79 .pipe(jshint.reporter('fail'))
80 .pipe(eslint(ESLINT_OPTION))
81 .pipe(eslint.formatEach('compact', process.stderr))
82 .pipe(eslint.failOnError());
83});
84
85
86/**
87 * Bumping version number and tagging the repository with it.
88 * Please read http://semver.org/
89 *
90 * You can use the commands
91 *
92 * gulp patch # makes v0.1.0 -> v0.1.1
93 * gulp feature # makes v0.1.1 -> v0.2.0
94 * gulp release # makes v0.2.1 -> v1.0.0
95 *
96 * To bump the version numbers accordingly after you did a patch,
97 * introduced a feature or made a backwards-incompatible release.
98 */
99
100function inc(importance) {
101 // get all the files to bump version in
102 return gulp.src(['./package.json'])
103 // bump the version number in those files
104 .pipe(bump({type: importance}))
105 // save it back to filesystem
106 .pipe(gulp.dest('./'))
107 // commit the changed version number
108 .pipe(git.commit('Bumps package version'))
109 // read only one file to get the version number
110 .pipe(filter('package.json'))
111 // **tag it in the repository**
112 .pipe(tagVersion({ prefix: '' }));
113}
114
115gulp.task('patch', [ 'travis' ], function () { return inc('patch'); });
116gulp.task('minor', [ 'travis' ], function () { return inc('minor'); });
117gulp.task('major', [ 'travis' ], function () { return inc('major'); });
118
119gulp.task('travis', [ 'lint', 'test' ]);
120gulp.task('default', [ 'travis' ]);