-
Notifications
You must be signed in to change notification settings - Fork 7
/
gulpfile.js
executable file
·105 lines (91 loc) · 2.42 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
'use strict';
var gulp = require('gulp'),
del = require('del'),
fs = require('fs'),
sass = require('gulp-sass'),
zip = require('gulp-zip'),
manifest = require('gulp-chrome-manifest'),
replace = require('gulp-replace'),
bump = require('gulp-bump');
// Config
var SRC_DIR = './src';
var DIST_DIR = './dist';
var PACKAGE_DIR = './package';
var MANIFEST = './manifest.json';
// Compile SASS to CSS
gulp.task('sass', function () {
return gulp
.src([SRC_DIR + '/**/*.scss'])
.pipe(sass({ style: 'expanded' }))
.on('error', sass.logError)
.pipe(gulp.dest(SRC_DIR));
});
// Delete everything from dist directory
gulp.task('clean', function () {
return del([DIST_DIR + '/**/*']);
});
// Copy all files to dist folder
gulp.task('copy', ['clean', 'sass', 'version'], function (cb) {
gulp
.src('./_locales/**/*')
.pipe(gulp.dest(DIST_DIR + '/_locales'));
gulp
.src('./icons/**')
.pipe(gulp.dest(DIST_DIR + '/icons'));
gulp
.src(SRC_DIR + '/**/*')
.pipe(gulp.dest(DIST_DIR));
cb();
});
// VERSION
/**
* Bump version of extension in manifest.json and package.json
* @param type ['patch'|'minor'|'major']
* @returns {*}
*/
function bumpVersion(type) {
return gulp
.src([MANIFEST, './package.json'])
.pipe(bump({ type: type }))
.pipe(gulp.dest('./'))
}
gulp.task('version', function () {
return bumpVersion('patch');
});
gulp.task('version:prerelease', function () {
return bumpVersion('prerelease');
});
gulp.task('version:patch', function () {
return bumpVersion('patch');
});
gulp.task('version:minor', function () {
return bumpVersion('minor');
});
gulp.task('version:major', function () {
return bumpVersion('major');
});
// Copy manifest to dist and update paths
gulp.task('manifest', ['copy'], function () {
return gulp
.src(MANIFEST)
.pipe(replace('src/', ''))
.pipe(gulp.dest(DIST_DIR))
});
// PACKAGE
function packageName() {
var manifest = JSON.parse(fs.readFileSync(MANIFEST));
return (manifest.name.trim().replace(/\s/g, '-').toLowerCase()) + '-' + manifest.version;
}
function createPackage() {
return gulp
.src(DIST_DIR + '/**/*')
.pipe(zip(packageName() + '.zip'))
.pipe(gulp.dest(PACKAGE_DIR));
}
// Watch sass files for change
gulp.task('watch', ['sass'], function () {
return gulp.watch(SRC_DIR + '/**/*.scss', ['sass']);
});
gulp.task('build', ['manifest']);
gulp.task('package', createPackage);
gulp.task('default', ['watch']);