forked from RevillWeb/angular-preload-image
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgulpfile.js
More file actions
122 lines (95 loc) · 3.14 KB
/
Copy pathgulpfile.js
File metadata and controls
122 lines (95 loc) · 3.14 KB
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
'use strict';
var gulp = require('gulp');
var plugins = require('gulp-load-plugins')();
var pkg = require('./package.json');
var path = require('path');
var sh = require('shelljs');
var semver = require('semver');
plugins.minimist = require('minimist')(process.argv.slice(2));
var PATH = {
bower_components: 'bower_components',
build: '.',
dist: './',
};
var BRANCH = {
master: 'master',
develop: 'develop'
};
var CONFIG_FILES = ['./bower.json', './package.json'];
var MAIN = 'angular-preload-image.js';
var FILES = [ './angular-preload-image.css',
'./angular-preload-image.js',
'./angular-preload-image.js.map',
'./angular-preload-image.min.js'
];
gulp.task('minify', ['lint'], function() {
return gulp.src(path.join(PATH.build, MAIN))
.pipe(plugins.sourcemaps.init({loadMaps: true}))
.pipe(plugins.uglify({
preserveComments: 'all'
}))
.pipe(plugins.rename({extname: '.min.js'}))
.pipe(plugins.sourcemaps.write(PATH.build))
.pipe(gulp.dest(PATH.build));
});
gulp.task('publish', ['publish::copy'], function() {
gulp.watch(FILES, ['publish::copy']);
});
gulp.task('publish::copy', ['minify'], function() {
return gulp.src(FILES)
.pipe(gulp.dest(plugins.minimist.path));
});
gulp.task('lint', function() {
return gulp.src(PATH.dist + MAIN)
.pipe(plugins.jshint())
.pipe(plugins.jshint.reporter('jshint-stylish'))
.pipe(plugins.jshint.reporter('fail'));
});
gulp.task('jscs', function() {
return gulp.src(PATH.dist + MAIN)
.pipe(plugins.jscs());
});
gulp.task('develop', ['minify'], function() {
gulp.watch(MAIN, ['lint']);
});
gulp.task('release::dist::version', ['minify'], function() {
pkg.version = semver.inc(pkg.version, 'patch');
return gulp.src(CONFIG_FILES)
.pipe(plugins.bump({
version: pkg.version
}))
.pipe(gulp.dest(PATH.build));
});
gulp.task('release::dist::commit', ['release::dist::version'], function() {
return gulp.src(['./bower.json', './package.json'])
.pipe(plugins.git.add())
.pipe(plugins.git.commit('chore(release): Bump version.'));
});
gulp.task('release::dist::merge', ['release::dist::commit'], function() {
return plugins.git.checkout(BRANCH.master, function() {
plugins.git.merge(BRANCH.develop);
});
});
gulp.task('release::dist::push', ['release::dist::merge'], function(done) {
return plugins.git.push('origin', BRANCH.develop, {cwd: PATH.dist}, function(err) {
if (err) {
plugins.git.checkout(BRANCH.master);
plugins.git.reset('HEAD~1', { args: '--hard' });
plugins.git.checkout(BRANCH.develop);
plugins.git.reset('HEAD~1', { args: '--hard' });
throw err;
}
plugins.git.push('origin', BRANCH.master, {cwd: PATH.dist}, done);
});
});
gulp.task('release::dist::tag', ['release::dist::push'], function(done) {
return plugins.git.tag('v' + pkg.version, 'v' + pkg.version, {cwd: PATH.dist}, function(err) {
if (err) {
throw err;
}
plugins.git.push('origin', 'refs/tags/v' + pkg.version, {cwd: PATH.dist}, done);
});
});
gulp.task('release', ['release::dist::tag'], function() {
plugins.git.checkout(BRANCH.develop);
});