|
| 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 | + |
| 27 | +var gulp = require('gulp'), |
| 28 | + mocha = require('gulp-mocha'), |
| 29 | + to5 = require('gulp-6to5'), |
| 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 | + |
| 42 | +var TEST = [ 'test/*.coffee' ]; |
| 43 | +var POWERED = [ 'powered-test/*.js' ]; |
| 44 | +var SOURCE = [ 'src/**/*.js' ]; |
| 45 | + |
| 46 | +var 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 | + |
| 68 | +var build = lazypipe() |
| 69 | + .pipe(sourcemaps.init) |
| 70 | + .pipe(to5) |
| 71 | + .pipe(sourcemaps.write) |
| 72 | + .pipe(gulp.dest, 'lib'); |
| 73 | + |
| 74 | +gulp.task('build-for-watch', function () { |
| 75 | + return gulp.src(SOURCE).pipe(plumber()).pipe(build()); |
| 76 | +}); |
| 77 | + |
| 78 | +gulp.task('build', function () { |
| 79 | + return gulp.src(SOURCE).pipe(build()); |
| 80 | +}); |
| 81 | + |
| 82 | +gulp.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 | + |
| 91 | +gulp.task('powered-test', function () { |
| 92 | + return gulp.src(TEST) |
| 93 | + .pipe(sourcemaps.init()) |
| 94 | + .pipe(coffee()) |
| 95 | + .pipe(sourcemaps.write()) |
| 96 | + .pipe(gulp.dest('./powered-test/')); |
| 97 | +}); |
| 98 | + |
| 99 | +gulp.task('test', [ 'build', 'powered-test' ], function () { |
| 100 | + return gulp.src(POWERED) |
| 101 | + .pipe(mocha({ |
| 102 | + reporter: 'spec', |
| 103 | + timeout: 100000 // 100s |
| 104 | + })); |
| 105 | +}); |
| 106 | + |
| 107 | +gulp.task('watch', [ 'build-for-watch' ], function () { |
| 108 | + gulp.watch(SOURCE, [ 'build-for-watch' ]); |
| 109 | +}); |
| 110 | + |
| 111 | +// Currently, not works for ES6. |
| 112 | +gulp.task('lint', function () { |
| 113 | + return gulp.src(SOURCE) |
| 114 | + .pipe(eslint(ESLINT_OPTION)) |
| 115 | + .pipe(eslint.formatEach('stylish', process.stderr)) |
| 116 | + .pipe(eslint.failOnError()); |
| 117 | +}); |
| 118 | + |
| 119 | +/** |
| 120 | + * Bumping version number and tagging the repository with it. |
| 121 | + * Please read http://semver.org/ |
| 122 | + * |
| 123 | + * You can use the commands |
| 124 | + * |
| 125 | + * gulp patch # makes v0.1.0 -> v0.1.1 |
| 126 | + * gulp feature # makes v0.1.1 -> v0.2.0 |
| 127 | + * gulp release # makes v0.2.1 -> v1.0.0 |
| 128 | + * |
| 129 | + * To bump the version numbers accordingly after you did a patch, |
| 130 | + * introduced a feature or made a backwards-incompatible release. |
| 131 | + */ |
| 132 | + |
| 133 | +function inc(importance) { |
| 134 | + // get all the files to bump version in |
| 135 | + return gulp.src(['./package.json']) |
| 136 | + // bump the version number in those files |
| 137 | + .pipe(bump({type: importance})) |
| 138 | + // save it back to filesystem |
| 139 | + .pipe(gulp.dest('./')) |
| 140 | + // commit the changed version number |
| 141 | + .pipe(git.commit('Bumps package version')) |
| 142 | + // read only one file to get the version number |
| 143 | + .pipe(filter('package.json')) |
| 144 | + // **tag it in the repository** |
| 145 | + .pipe(tagVersion()); |
| 146 | +} |
| 147 | + |
| 148 | +gulp.task('patch', [ 'build' ], function () { return inc('patch'); }) |
| 149 | +gulp.task('minor', [ 'build' ], function () { return inc('minor'); }) |
| 150 | +gulp.task('major', [ 'build' ], function () { return inc('major'); }) |
| 151 | + |
| 152 | +gulp.task('travis', [ 'test' ]); |
| 153 | +gulp.task('default', [ 'travis' ]); |
0 commit comments