forked from lindell/JsBarcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
180 lines (152 loc) · 3.75 KB
/
gulpfile.js
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
var gulp = require('gulp');
var concat = require('gulp-concat');
var babel = require("gulp-babel");
var uglify = require('gulp-uglify');
var rename = require('gulp-rename');
var bump = require('gulp-bump');
var git = require('gulp-git');
var runSequence = require('run-sequence');
var publishRelease = require('publish-release');
var header = require('gulp-header');
var clean = require('gulp-clean');
var gulpWebpack = require('webpack-stream');
var webpack = require('webpack');
gulp.task("clean", function(){
return gulp.src("bin/", {read: false})
.pipe(clean());
});
gulp.task("babel", function () {
return gulp.src("src/**/*")
.pipe(babel({
presets: ['es2015'],
plugins: [["transform-es2015-classes", {loose: true}]]
}))
.pipe(gulp.dest("bin/node/"));
});
gulp.task("webpack", ["babel"], function () {
return gulp.src('bin/node/JsBarcode.js')
.pipe(gulpWebpack(
{
output: {
filename: 'JsBarcode.js',
}
}
, webpack))
.pipe(gulp.dest("bin/browser/"));
});
gulp.task("webpack-min", ["babel"], function () {
return gulp.src('bin/node/JsBarcode.js')
.pipe(gulpWebpack(
{
output: {
filename: 'JsBarcode.min.js',
},
plugins: [new webpack.optimize.UglifyJsPlugin()],
}
, webpack))
.pipe(gulp.dest("bin/browser/"));
});
gulp.task('watch', ['compile'], function() {
gulp.watch("src/**/*", ['compile']);
});
gulp.task('compress', ["webpack", "webpack-min"], function() {
var pkg = require('./package.json');
});
gulp.task('git-release', ['compress'], function(cb){
var pkg = require('./package.json');
var v = 'v' + pkg.version;
var message = 'Release ' + v;
gulp.src(['./package.json', './bower.json', './bin/'])
.pipe(git.add({args: '--all'}))
.pipe(git.commit(message));
git.tag(v, message, function(error){
if(error){
console.error(error);
}
git.push('origin', 'master', function(){
git.push('origin', 'master', {args: '--tags'}, cb);
});
});
});
// Bump (increase) the version number
gulp.task('bump-patch', function(){
return gulp.src(['./package.json', './bower.json'])
.pipe(bump({type:'patch'}))
.pipe(gulp.dest('./'));
});
gulp.task('bump-minor', function(){
return gulp.src(['./package.json', './bower.json'])
.pipe(bump({type:'minor'}))
.pipe(gulp.dest('./'));
});
gulp.task('bump-major', function(){
return gulp.src(['./package.json', './bower.json'])
.pipe(bump({type:'major'}))
.pipe(gulp.dest('./'));
});
gulp.task('npm', function (done) {
require('child_process').spawn('npm', ['publish'], { stdio: 'inherit' })
.on('close', done);
});
gulp.task('github-release', function(done) {
var pkg = require('./package.json');
var v = 'v' + pkg.version;
var name = "JsBarcode " + v;
publishRelease({
token: process.env.GITHUB_TOKEN,
owner: "lindell",
repo: "JsBarcode",
tag: v,
name: name,
assets: [__dirname + "/bin/browser/JsBarcode.js"],
}, done);
});
// Needed so that github can register the push before new release
gulp.task('wait', function(done) {
setTimeout(done, 5000);
});
var done = function (error) {
if (error) {
console.log(error.message);
}
else {
console.log('Successful!');
}
};
gulp.task('compile', function(done){
runSequence(
'babel',
'webpack',
done
);
});
gulp.task('release', function(callback){
runSequence(
'git-release',
'wait',
'github-release',
'npm',
callback
);
});
gulp.task('patch', function(){
runSequence(
'bump-patch',
'release',
done
);
});
gulp.task('minor', function(){
runSequence(
'bump-minor',
'release',
done
);
});
gulp.task('major', function(){
runSequence(
'bump-major',
'release',
done
);
});