1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 | 'use strict';
|
26 |
|
27 | var 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 |
|
43 | var TEST = [ 'test/*.coffee' ];
|
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(babel)
|
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('test', [ 'build' ], function () {
|
92 | return gulp.src(TEST)
|
93 | .pipe(mocha({
|
94 | reporter: 'spec',
|
95 | timeout: 100000
|
96 | }));
|
97 | });
|
98 |
|
99 | gulp.task('watch', [ 'build-for-watch' ], function () {
|
100 | gulp.watch(SOURCE, [ 'build-for-watch' ]);
|
101 | });
|
102 |
|
103 |
|
104 | gulp.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 |
|
113 |
|
114 |
|
115 |
|
116 |
|
117 |
|
118 |
|
119 |
|
120 |
|
121 |
|
122 |
|
123 |
|
124 |
|
125 | function inc(importance) {
|
126 |
|
127 | return gulp.src(['./package.json'])
|
128 |
|
129 | .pipe(bump({type: importance}))
|
130 |
|
131 | .pipe(gulp.dest('./'))
|
132 |
|
133 | .pipe(git.commit('Bumps package version'))
|
134 |
|
135 | .pipe(filter('package.json'))
|
136 |
|
137 | .pipe(tagVersion({
|
138 | prefix: ''
|
139 | }));
|
140 | }
|
141 |
|
142 | gulp.task('patch', [ 'build' ], function () { return inc('patch'); })
|
143 | gulp.task('minor', [ 'build' ], function () { return inc('minor'); })
|
144 | gulp.task('major', [ 'build' ], function () { return inc('major'); })
|
145 |
|
146 | gulp.task('travis', [ 'test' ]);
|
147 | gulp.task('default', [ 'travis' ]);
|