-
Notifications
You must be signed in to change notification settings - Fork 274
/
gulpfile.js
executable file
·183 lines (157 loc) · 3.63 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
var gulp = require('gulp');
var sass = require('gulp-sass')(require('sass'));
var cleanCSS = require('gulp-clean-css');
var concat = require('gulp-concat');
var rename = require('gulp-rename');
var uglify = require('gulp-uglify');
var sourcemaps = require('gulp-sourcemaps');
// Plugins
var plugins = [
'Confirm',
'Image',
'Notice'
];
// Themes
var themes = [
'NoticeFancy',
'TooltipBorder',
'TooltipBorderThick',
'TooltipDark',
'TooltipError',
'TooltipSmall',
'TooltipSmallGray'
];
// CSS
var styles = [{
name: 'jBox',
src: ['./src/scss/jBox.scss'],
dest: './dist/'
}, {
name: 'jBox.all',
src: [
'./src/scss/jBox.scss',
'./src/scss/plugins/*.scss',
'./src/scss/themes/*.scss'
],
dest: './dist/'
}];
for (let plugin of plugins) {
styles.push({
name: 'jBox.' + plugin,
src: ['./src/scss/plugins/jBox.' + plugin + '.scss'],
dest: './dist/plugins/'
});
}
for (let theme of themes) {
styles.push({
name: 'jBox.' + theme,
src: ['./src/scss/themes/jBox.' + theme + '.scss'],
dest: './dist/themes/'
});
}
// JavaScript
var scripts = [{
name: 'jBox',
src: [
'./src/js/jBox.js',
'./src/js/umd.js'
],
dest: './dist/'
}, {
name: 'jBox.all',
src: [
'./src/js/jBox.js',
'./src/js/plugins/*.js',
'./src/js/umd.js'
],
dest: './dist/'
}];
for (let plugin of plugins) {
scripts.push({
name: 'jBox.' + plugin,
src: ['./src/js/plugins/jBox.' + plugin + '.js'],
dest: './dist/plugins/'
});
}
// Config tasks
let defaultTasks = [];
let buildTasks = [];
let watchTasks = [];
// Config CSS tasks
for (const item of styles) {
// Concat CSS
const cssConcat = function () {
return gulp
.src(item.src)
.pipe(sourcemaps.init())
.pipe(sass({
outputStyle: 'expanded'
}).on('error', sass.logError))
.pipe(concat(item.name + '.css'))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest(item.dest));
};
// Store as a task
gulp.task('cssConcat-' + item.name, cssConcat);
// Add to default tasks
defaultTasks.push('cssConcat-' + item.name);
// Add to watch tasks
watchTasks.push({
src: item.src,
task: cssConcat
});
// Build CSS
const cssBuild = function () {
return gulp
.src(item.dest + item.name + '.css')
.pipe(rename(item.name + '.min.css'))
.pipe(cleanCSS())
.pipe(gulp.dest(item.dest));
};
// Store as a task
gulp.task('cssBuild-' + item.name, cssBuild);
// Add to build tasks
buildTasks.push('cssBuild-' + item.name);
}
// Config JavaScript tasks
for (let item of scripts) {
// Concat JavaScript
const jsConcat = function () {
return gulp
.src(item.src)
.pipe(sourcemaps.init())
.pipe(concat(item.name + '.js'))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest(item.dest));
};
// Store as a task
gulp.task('jsConcat-' + item.name, jsConcat);
// Add to default tasks
defaultTasks.push('jsConcat-' + item.name);
// Add to watch tasks
watchTasks.push({
src: item.src,
task: jsConcat
});
// Build JavaScript
const jsBuild = function () {
return gulp
.src(item.dest + item.name + '.js')
.pipe(rename(item.name + '.min.js'))
.pipe(uglify())
.pipe(gulp.dest(item.dest));
};
// Store as a task
gulp.task('jsBuild-' + item.name, jsBuild);
// Add to build tasks
buildTasks.push('jsBuild-' + item.name);
}
// Watch tasks
function watch() {
for (const watchTask of watchTasks) {
gulp.watch(watchTask.src, watchTask.task);
}
}
exports.default = gulp.series(defaultTasks);
exports.watch = gulp.series(defaultTasks, watch);
exports.build = gulp.series(defaultTasks, buildTasks);