forked from Wikiki/bulma-carousel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
239 lines (217 loc) · 6.56 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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
var package = require('./package.json')
var gulp = require('gulp');
// Define variables.
var autoprefixer = require('autoprefixer');
var babel = require('gulp-babel');
var bump = require('gulp-bump');
var camelCase = require('camelcase');
var cleancss = require('gulp-clean-css');
var concat = require('gulp-concat');
var conventionalChangelog = require('gulp-conventional-changelog');
var conventionalGithubReleaser = require('conventional-github-releaser');
var del = require('del');
var fs = require('fs');
var git = require('gulp-git');
var gutil = require('gulp-util');
var postcss = require('gulp-postcss');
var rollup = require('gulp-better-rollup');
var runSequence = require('run-sequence');
var sass = require('gulp-sass');
var spawn = require('child_process').spawn;
var minify = require('gulp-babel-minify');
/**
* ----------------------------------------
* VARIABLES
* ----------------------------------------
*/
var paths = {
src: 'src/',
dest: 'dist/',
bulma: 'node_modules/bulma/sass/utilities/',
jsPattern: '**/*.js'
}
var bulmaSassFile = '_all.sass';
var globalSassFile = package.name + '.sass';
var globalJsFile = package.name + '.js';
var mainSassFile = 'extension.sass';
var mainJsFile = 'extension.js';
var distCssFile = package.name + '.min.css';
var distJsFile = package.name + '.min.js';
/**
* ----------------------------------------
* STYLESHEETS
* ----------------------------------------
*/
// Uses Sass compiler to process styles, adds vendor prefixes, minifies, then
// outputs file to the appropriate location.
gulp.task('build:styles', function() {
runSequence('build:styles:copy',function() {
return gulp.src([paths.bulma + bulmaSassFile, paths.src + mainSassFile])
.pipe(concat(globalSassFile))
.pipe(sass({
style: 'compressed',
includePaths: [paths.bulma]
}))
.pipe(postcss([autoprefixer({browsers: ['last 2 versions']})]))
.pipe(cleancss())
.pipe(concat(distCssFile))
.pipe(gulp.dest(paths.dest));
});
});
// Copy original sass file to dist
gulp.task('build:styles:copy', function() {
return gulp.src(paths.src + mainSassFile)
.pipe(concat(globalSassFile))
.pipe(gulp.dest(paths.dest));
});
gulp.task('clean:styles', function() {
del([
paths.dest + mainSassFile,
paths.dest + distCssFile
]);
});
/**
* ----------------------------------------
* JAVASCRIPT
* ----------------------------------------
*/
// Concatenates and uglifies global JS files and outputs result to the
// appropriate location.
gulp.task('build:scripts', function() {
return gulp
.src([paths.src + mainJsFile])
.pipe(rollup({
plugins: [babel({
babelrc: false,
sourceMaps: false,
exclude: 'node_modules/**',
presets: [
["@babel/preset-env", {
"modules": false,
"targets": {
"browsers": gutil.env.babelTarget ? gutil.env.babelTarget : ['last 2 versions']
}
}]
]
})]
}, {
format: 'umd',
name: camelCase(package.name)
}
).on('error', function(err) {
gutil.log(gutil.colors.red('[Error]'), err.toString())
}))
.pipe(concat(globalJsFile))
.pipe(gulp.dest(paths.dest))
.pipe(concat(distJsFile))
.pipe(minify().on('error', function(err) {
gutil.log(gutil.colors.red('[Error]'), err.toString())
}))
.pipe(gulp.dest(paths.dest));
});
gulp.task('clean:scripts', function() {
del([
paths.dest + mainJsFile,
paths.dest + distJsFile
]);
});
// Deletes the entire dist directory.
gulp.task('clean', function() {
del(paths.dest);
});
/**
* ----------------------------------------
* GLOBAL BUILD
* ----------------------------------------
*/
gulp.task('build', function(callback) {
runSequence('clean',
['build:scripts', 'build:styles'],
callback);
});
/**
* ----------------------------------------
* DEFAULT TASK
* ----------------------------------------
*/
gulp.task('default', ['build']);
/**
* ----------------------------------------
* GENERATE CHANGELOG
* ----------------------------------------
*/
gulp.task('changelog', function () {
return gulp.src('CHANGELOG.md')
.pipe(conventionalChangelog({
preset: 'angular'
}))
.pipe(gulp.dest('./'));
});
/**
* ----------------------------------------
* GENERATE GITHUB RELEASE
* ----------------------------------------
*/
gulp.task('github:release', function(done) {
conventionalGithubReleaser({
type: "oauth",
token: process.env.GITHUB_TOKEN
}, {
preset: 'angular'
}, done);
});
/**
* ----------------------------------------
* UPDATE
* ----------------------------------------
*/
gulp.task('bump-version', function () {
return gulp.src(['./bower.json', './package.json'])
.pipe(bump({type: gutil.env.type ? gutil.env.type : 'patch' })
.on('error', gutil.log))
.pipe(gulp.dest('./'));
});
gulp.task('github:commit', function () {
return gulp.src('.')
.pipe(git.add())
.pipe(git.commit('[Prerelease] Bumped version number'));
});
gulp.task('github:push', function (cb) {
git.push('origin', 'master', cb);
});
gulp.task('github:create-new-tag', function (cb) {
var version = getPackageJsonVersion();
git.tag(version, 'Created Tag for version: ' + version, function (error) {
if (error) {
return cb(error);
}
git.push('origin', 'master', {args: '--tags'}, cb);
});
function getPackageJsonVersion () {
// We parse the json file instead of using require because require caches
// multiple calls so the version number won't be updated
return JSON.parse(fs.readFileSync('./package.json', 'utf8')).version;
};
});
gulp.task('npm:publish', function (done) {
spawn('npm', ['publish'], { stdio: 'inherit' }).on('close', done);
});
gulp.task('release', function (callback) {
runSequence(
'build',
'bump-version',
'changelog',
'github:commit',
'github:push',
'github:create-new-tag',
'github:release',
'npm:publish',
function (error) {
if (error) {
console.log(error.message);
} else {
console.log('RELEASE FINISHED SUCCESSFULLY');
}
callback(error);
});
});