-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
291 lines (251 loc) · 8.52 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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
'use strict';
var gulp = require('gulp');
var babel = require("gulp-babel");
var eslint = require('gulp-eslint');
var plugins = require('gulp-load-plugins')();
var fs = require('fs');
var path = require('path');
var es = require('event-stream');
var rename = require('gulp-rename');
var moduleName = (function() {
var args = process.argv;
var length = args.length;
var i = 0;
var name;
var subName;
var useSubName;
while (i++ < length) {
if ((/^--+(\w+)/i).test(args[i])) {
name = args[i].split('--')[1];
subName = args[i].split('--')[2];
useSubName = args[i].split('--')[3];
break;
}
}
return {
'name': name,
'subName': subName,
'useSubName': useSubName
};
})();
// Admin Module
// Command: gulp [task]
// Admin is default task
// Watch Admin module: gulp
// -----------------------------------------------------------------------------
function adminTasks() {
var pathto = function(file) {
return ('../admin/views/assets/' + file);
};
var scripts = {
src: pathto('javascripts/app/*.js'),
dest: pathto('javascripts'),
qor: pathto('javascripts/qor/*.js'),
qorInit: pathto('javascripts/qor/qor-config.js'),
qorCommon: pathto('javascripts/qor/qor-common.js'),
all: [
'gulpfile.js',
pathto('javascripts/qor/*.js')
]
};
var styles = {
src: pathto('stylesheets/scss/{app,qor}.scss'),
dest: pathto('stylesheets'),
vendors: pathto('stylesheets/vendors'),
main: pathto('stylesheets/{qor,app}.css'),
scss: pathto('stylesheets/scss/**/*.scss')
};
gulp.task('qor', function() {
return gulp.src([scripts.qorInit, scripts.qorCommon, scripts.qor])
.pipe(plugins.concat('qor.js'))
.pipe(plugins.uglify())
.pipe(gulp.dest(scripts.dest));
});
gulp.task('js', ['qor'], function() {
return gulp.src(scripts.src)
.pipe(eslint({
configFile: '.eslintrc'
}))
.pipe(plugins.concat('app.js'))
.pipe(plugins.uglify())
.pipe(gulp.dest(scripts.dest));
});
gulp.task('qor+', function() {
return gulp.src([scripts.qorInit, scripts.qorCommon, scripts.qor])
.pipe(eslint({
configFile: '.eslintrc'
}))
.pipe(babel({
presets: ['es2015']
}))
.pipe(eslint.format())
.pipe(plugins.concat('qor.js'))
.pipe(plugins.uglify())
.pipe(gulp.dest(scripts.dest));
});
gulp.task('js+', function() {
return gulp.src(scripts.src)
.pipe(babel({
presets: ['es2015']
}))
.pipe(eslint.format())
.pipe(plugins.concat('app.js'))
.pipe(plugins.uglify())
.pipe(gulp.dest(scripts.dest));
});
gulp.task('sass', function() {
return gulp.src(styles.src)
.pipe(plugins.sass())
.pipe(gulp.dest(styles.dest));
});
gulp.task('css', ['sass'], function() {
return gulp.src(styles.main)
.pipe(plugins.autoprefixer())
.pipe(plugins.csscomb())
.pipe(plugins.minifyCss())
.pipe(gulp.dest(styles.dest));
});
gulp.task('watch', function() {
gulp.watch(scripts.qor, ['qor+']);
gulp.watch(scripts.src, ['js+']);
gulp.watch(styles.scss, ['css']);
});
gulp.task('release', ['qor+', 'js+', 'css']);
gulp.task('default', ['watch']);
}
// -----------------------------------------------------------------------------
// Other Modules
// Command: gulp [task] --moduleName--subModuleName
//
// example:
// Watch Worker module: gulp --worker
//
// if module's assets just as normal path:
// moduleName/views/themes/moduleName/assets/javascripts(stylesheets)
// just use gulp --worker
//
// if module's assets in enterprise as normal path:
// moduleName/views/themes/moduleName/assets/javascripts(stylesheets)
// just use gulp --microsite--enterprise
//
// if module's assets path as Admin module:
// moduleName/views/assets/javascripts(stylesheets)
// you need set subModuleName as admin
// gulp --worker--admin
//
// if you need run task for subModule in modules
// example: worker module inline_edit subModule:
// gulp --worker--inline_edit
//
// gulp --media--media_library--true
//
// -----------------------------------------------------------------------------
function moduleTasks(moduleNames) {
var moduleName = moduleNames.name;
var subModuleName = moduleNames.subName;
var useSubName = moduleNames.useSubName;
var pathto = function(file) {
if (moduleName && subModuleName) {
if (subModuleName == 'admin') {
return '../' + moduleName + '/views/assets/' + file;
} else if (subModuleName == 'enterprise') {
return '../../../enterprise.getqor.com/' + moduleName + '/views/themes/' + moduleName + '/assets/' + file;
} else if (useSubName) {
return '../' + moduleName + '/' + subModuleName + '/views/themes/' + subModuleName + '/assets/' + file;
} else {
return '../' + moduleName + '/' + subModuleName + '/views/themes/' + moduleName + '/assets/' + file;
}
}
return '../' + moduleName + '/views/themes/' + moduleName + '/assets/' + file;
};
var scripts = {
src: pathto('javascripts/'),
watch: pathto('javascripts/**/*.js')
};
var styles = {
src: pathto('stylesheets/'),
watch: pathto('stylesheets/**/*.scss')
};
function getFolders(dir) {
return fs.readdirSync(dir).filter(function(file) {
return fs.statSync(path.join(dir, file)).isDirectory();
})
}
gulp.task('js', function() {
var scriptPath = scripts.src;
var folders = getFolders(scriptPath);
var task = folders.map(function(folder) {
return gulp.src(path.join(scriptPath, folder, '/*.js'))
.pipe(eslint({
configFile: '.eslintrc'
}))
.pipe(babel({
presets: ['es2015']
}))
.pipe(eslint.format())
.pipe(plugins.concat(folder + '.js'))
.pipe(plugins.uglify({
drop_debugger: false
}))
.pipe(gulp.dest(scriptPath));
});
return es.concat.apply(null, task);
});
gulp.task('css', function() {
var stylePath = styles.src;
var folders = getFolders(stylePath);
var task = folders.map(function(folder) {
return gulp.src(path.join(stylePath, folder, '/*.scss'))
.pipe(plugins.sass({
outputStyle: 'compressed'
}))
.pipe(plugins.minifyCss())
.pipe(rename(folder + '.css'))
.pipe(gulp.dest(stylePath))
});
return es.concat.apply(null, task);
});
gulp.task('watch', function() {
gulp.watch(scripts.watch, ['js']);
gulp.watch(styles.watch, ['css']);
});
gulp.task('default', ['watch']);
gulp.task('release', ['js', 'css']);
}
// Init
// -----------------------------------------------------------------------------
if (moduleName.name) {
var taskPath = moduleName.name + '/views/themes/' + moduleName.name + '/assets/';
var runModuleName = 'Running "' + moduleName.name + '" module task in "' + taskPath + '"...';
if (moduleName.subName) {
if (moduleName.subName == 'admin') {
taskPath = moduleName.name + '/views/assets/';
runModuleName = 'Running "' + moduleName.name + '" module task in "' + taskPath + '"...';
} else if (moduleName.subName == 'enterprise') {
taskPath = '../../../enterprise.getqor.com/' + moduleName.name + '/views/themes/' + moduleName.name + '/assets/';
runModuleName = 'Running "' + moduleName.name + '" module task in "' + taskPath + '"...';
} else if (moduleName.useSubName) {
taskPath = moduleName.name + '/' + moduleName.subName + '/views/themes/' + moduleName.subName + '/assets/';
runModuleName = 'Running "' + moduleName.name + ' > ' + moduleName.subName + '" module task in "' + taskPath + '"...';
} else {
taskPath = moduleName.name + '/' + moduleName.subName + '/views/themes/' + moduleName.name + '/assets/';
runModuleName = 'Running "' + moduleName.name + ' > ' + moduleName.subName + '" module task in "' + taskPath + '"...';
}
}
console.log(runModuleName);
moduleTasks(moduleName);
} else {
console.log('Running "admin" module task in "admin/views/assets/"...');
adminTasks();
}
// Task for compress js and css vendor assets
gulp.task('combineJavaScriptVendor', function() {
return gulp.src(['!../admin/views/assets/javascripts/vendors/jquery.min.js', '../admin/views/assets/javascripts/vendors/*.js'])
.pipe(plugins.concat('vendors.js'))
.pipe(gulp.dest('../admin/views/assets/javascripts'));
});
gulp.task('compressCSSVendor', function() {
return gulp.src('../admin/views/assets/stylesheets/vendors/*.css')
.pipe(plugins.concat('vendors.css'))
.pipe(gulp.dest('../admin/views/assets/stylesheets'));
});