UNPKG

4.71 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'),
28 mocha = require('gulp-mocha'),
29 babel = require('gulp-babel'),
30 git = require('gulp-git'),
31 bump = require('gulp-bump'),
32 filter = require('gulp-filter'),
33 tagVersion = require('gulp-tag-version'),
34 sourcemaps = require('gulp-sourcemaps'),
35 coffee = require('gulp-coffee'),
36 plumber = require('gulp-plumber'),
37 source = require('vinyl-source-stream'),
38 browserify = require('browserify'),
39 lazypipe = require('lazypipe'),
40 eslint = require('gulp-eslint'),
41 coffee = require('coffee-script/register');
42
43var TEST = [ 'test/*.coffee' ];
44var SOURCE = [ 'src/**/*.js' ];
45
46var ESLINT_OPTION = {
47 rules: {
48 'quotes': 0,
49 'eqeqeq': 0,
50 'no-use-before-define': 0,
51 'no-shadow': 0,
52 'no-new': 0,
53 'no-underscore-dangle': 0,
54 'no-multi-spaces': false,
55 'no-native-reassign': 0,
56 'no-loop-func': 0,
57 'no-lone-blocks': 0
58 },
59 settings: {
60 "ecmascript": 6,
61 "jsx": false
62 },
63 env: {
64 'node': true
65 }
66};
67
68var build = lazypipe()
69 .pipe(sourcemaps.init)
70 .pipe(babel)
71 .pipe(sourcemaps.write)
72 .pipe(gulp.dest, 'lib');
73
74gulp.task('build-for-watch', function () {
75 return gulp.src(SOURCE).pipe(plumber()).pipe(build());
76});
77
78gulp.task('build', function () {
79 return gulp.src(SOURCE).pipe(build());
80});
81
82gulp.task('browserify', [ 'build' ], function () {
83 return browserify({
84 entries: [ './lib/index.js' ]
85 })
86 .bundle()
87 .pipe(source('bundle.js'))
88 .pipe(gulp.dest('build'))
89});
90
91gulp.task('test', [ 'build' ], function () {
92 return gulp.src(TEST)
93 .pipe(mocha({
94 reporter: 'spec',
95 timeout: 100000 // 100s
96 }));
97});
98
99gulp.task('watch', [ 'build-for-watch' ], function () {
100 gulp.watch(SOURCE, [ 'build-for-watch' ]);
101});
102
103// Currently, not works for ES6.
104gulp.task('lint', function () {
105 return gulp.src(SOURCE)
106 .pipe(eslint(ESLINT_OPTION))
107 .pipe(eslint.formatEach('stylish', process.stderr))
108 .pipe(eslint.failOnError());
109});
110
111/**
112 * Bumping version number and tagging the repository with it.
113 * Please read http://semver.org/
114 *
115 * You can use the commands
116 *
117 * gulp patch # makes v0.1.0 -> v0.1.1
118 * gulp feature # makes v0.1.1 -> v0.2.0
119 * gulp release # makes v0.2.1 -> v1.0.0
120 *
121 * To bump the version numbers accordingly after you did a patch,
122 * introduced a feature or made a backwards-incompatible release.
123 */
124
125function inc(importance) {
126 // get all the files to bump version in
127 return gulp.src(['./package.json'])
128 // bump the version number in those files
129 .pipe(bump({type: importance}))
130 // save it back to filesystem
131 .pipe(gulp.dest('./'))
132 // commit the changed version number
133 .pipe(git.commit('Bumps package version'))
134 // read only one file to get the version number
135 .pipe(filter('package.json'))
136 // **tag it in the repository**
137 .pipe(tagVersion({
138 prefix: ''
139 }));
140}
141
142gulp.task('patch', [ 'build' ], function () { return inc('patch'); })
143gulp.task('minor', [ 'build' ], function () { return inc('minor'); })
144gulp.task('major', [ 'build' ], function () { return inc('major'); })
145
146gulp.task('travis', [ 'test' ]);
147gulp.task('default', [ 'travis' ]);