-
Notifications
You must be signed in to change notification settings - Fork 100
/
Copy pathgulpfile.js
330 lines (291 loc) · 8.82 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
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
// var gulp = require('gulp');
const { series, src, dest, watch } = require('gulp');
const fs = require('fs');
const del = require('del');
const path = require('path');
const merge = require('merge-stream');
const run = require('gulp-run-command').default
const less = require('gulp-less');
const mainBowerFiles = require('main-bower-files');
const gulpFilter = require('gulp-filter');
const cleanCSS = require('gulp-clean-css');
const uglify = require('gulp-uglify');
const rename = require('gulp-rename');
const wpPot = require('gulp-wp-pot');
const gulpZip = require('gulp-zip');
const shell = require('gulp-shell');
const ROOT_PATH = path.resolve(__dirname);
const assetsPath = './assets';
const source = './engine';
const svnDir = "~/Documents/wordpress.org/tx-onepager";
const config = {
less: {
src: source + '/lithium/*.less',
dest: assetsPath + '/css',
settings: {
javascriptEnabled: true,
indentedSyntax: false, // Enable .less syntax?
imagePath: '/images' // Used by the image-url helper
}
},
js: {
src: [source + '/*.js', source + '/lithium/*.js'],
dest: assetsPath + '/'
},
images: {
src: source + '/lithium/images/**/*',
dest: assetsPath + '/images'
},
fonts: {
src: source + '/fonts/**/*',
dest: assetsPath + '/fonts'
},
bower: {
js: assetsPath + '/js',
css: assetsPath + '/css',
images: assetsPath + '/images',
fonts: assetsPath + '/fonts'
},
uikit: {
js: assetsPath + '/js',
css: assetsPath + '/css'
},
'bootstrap-datepicker': {
js: assetsPath + '/js',
css: assetsPath + '/css'
},
'bootstrap-timepicker': {
js: assetsPath + '/js',
css: assetsPath + '/css'
},
watch: {
src: source + '/**/*.*',
less: source + '/lithium/**/*.less',
js: source + '/**/*.js',
// js: [source + '/*.js', source + '/lithium/*.js'],
tasks: ['build']
}
};
function assets(){
var lessPath = src(config.less.src)
.pipe(less(config.less.settings))
.pipe(cleanCSS())
.pipe(dest(config.less.dest))
var jsPath = src(config.js.src)
.pipe(uglify())
.pipe(dest(config.js.dest))
var fontsPath = src(config.fonts.src)
.pipe(dest(config.fonts.dest))
var imagesPath = src(config.images.src)
.pipe(dest(config.images.dest))
// UiKit
const uikitPath = './node_modules/uikit/dist';
var uikitCss = src(uikitPath + '/css/uikit.css')
.pipe(cleanCSS())
.pipe(dest(config.uikit.css))
var uikitJs = src([uikitPath + '/js/uikit.js', uikitPath + '/js/uikit-icons.js'])
.pipe(uglify())
.pipe(dest(config.uikit.js))
//Bootstrap datepicker
const bsDatePickerPath = './node_modules/bootstrap-datepicker/dist'
var bsDatePickerJs = src([bsDatePickerPath + '/js/bootstrap-datepicker.js'])
.pipe(uglify())
.pipe(dest(config['bootstrap-datepicker'].js))
var bsDatePickerCss = src([bsDatePickerPath + '/css/bootstrap-datepicker.css'])
.pipe(cleanCSS())
.pipe(dest(config['bootstrap-datepicker'].css))
// BS timepicker
const bsTimepickerPath = './node_modules/bootstrap-timepicker'
var bsTimepickerJs = src([bsTimepickerPath + '/js/bootstrap-timepicker.js'])
.pipe(uglify())
.pipe(dest(config['bootstrap-timepicker'].js))
var bsTimepickerCss = src([bsTimepickerPath + '/css/bootstrap-timepicker.css'])
.pipe(cleanCSS())
.pipe(dest(config['bootstrap-timepicker'].css))
return merge(lessPath, jsPath, fontsPath, imagesPath, uikitCss, uikitJs, bsDatePickerCss, bsDatePickerJs, bsTimepickerCss, bsTimepickerJs)
}
/*** Filters for bower main files **/
var jsFilter = gulpFilter('**/*.js', { restore: true }),
cssFilter = gulpFilter('**/*.css', { restore: true }),
lessFilter = gulpFilter('**/*.less', { restore: true }),
fontFilter = gulpFilter(['**/*.svg', '**/*.eot', '**/*.woff', '**/*.woff2', '**/*.ttf'], { restore: true }),
imgFilter = gulpFilter(['**/*.png', '**/*.gif', '**/*.jpg'], { restore: true });
function bower(){
return src(mainBowerFiles())
.pipe(jsFilter)
.pipe(uglify())
.pipe(dest(config.bower.js))
.pipe(jsFilter.restore)
.pipe(lessFilter)
.pipe(less())
.pipe(dest(config.bower.css))
.pipe(rename({extname: 'css'}))
.pipe(lessFilter.restore)
.pipe(cssFilter)
// .pipe(cleanCSS())
.pipe(dest(config.bower.css))
.pipe(cssFilter.restore)
.pipe(imgFilter)
.pipe(dest(config.bower.images))
.pipe(imgFilter.restore)
.pipe(fontFilter)
.pipe(dest(config.bower.fonts))
.pipe(fontFilter.restore);
}
// function watch(){
// gulp.watch(config.watch.less, ['less']);
// gulp.watch(config.watch.js, ['js']);
// }
// gulp.task('watch', function () {
// gulp.watch(config.watch.less, ['less']);
// gulp.watch(config.watch.js, ['js']);
// });
function watcher(){
var listenLessPath = src(config.less.src)
.pipe(less(config.less.settings))
.pipe(cleanCSS())
.pipe(dest(config.less.dest));
var listenJSPath = src(config.js.src)
.pipe(uglify())
.pipe(dest(config.js.dest));
return merge(listenLessPath, listenJSPath)
}
function listen(){
watch([config.watch.less, config.watch.js], series([watcher]));
}
function webpackProd(){
return shell(['webpack -p --color --progress'])
}
function webpackDev(){
return shell(['webpack --color --progress'])
}
function webpackWatch(){
return shell(['webpack --watch --color --progress'])
}
/**
* Clean everything
*/
function clean(){
return del([assetsPath, './temp']);
}
/**
* Package build section
*/
function webpackBuild(cb){
// return gulpRun('npm run build')
async () => gulpRun('npm run build')()
// return process.argv.indexOf('-dev') !== -1 ? webpackDev() : webpackProd();
// var task = process.argv.indexOf('-dev') !== -1 ? 'webpackDev':'webpackProd';
// return series(task, cb);
// return webpackProd();
}
/**
* Default tasks
*/
// gulp.task('default', function () {
// runSequence('build', ['webpack-watch', 'watch']);
// });
// Copy files to /temp dir
function copy(cb){
return src([
'./**',
'./*/**',
'!./node_modules/**',
'!./bower_components/**',
'!./engine/**',
'!./temp/**',
'!gulpfile.js',
'!package.json',
'!*.json',
'!*.yml',
'!*.xml',
'!*.zip',
'!*.config.js',
'!*.lock',
'!*.gitignore',
]).pipe(dest('temp/tx-onepager'));
cb();
}
function package(){
var version = getOnepagerVersion();
var archiveName = `tx-onepager-${version}.zip`;
// Replace version num
replaceVersion('./temp/tx-onepager/readme.txt', version);
// create zip
return src(['./temp/**', './temp/*/**',])
.pipe(gulpZip(archiveName))
.pipe(dest('./temp'))
}
exports.clean = clean
exports.assets = series(assets, bower)
/**
* for windows release
* 1. gulp ready
* 2. npm run buildwin
* 3. gulp releasewin
* for windows dev
* 1. gulp defaultwin
* 2. npm run devwin
*/
exports.ready = series( clean, assets, bower)
exports.releasewin = series( copy, package)
exports.defaultwin = series( clean, assets, bower, listen)
/**
* for MacOs
*/
exports.default = series( clean, assets, bower, run('npm run build'), listen)
exports.release = series( clean, assets, bower, run('npm run build'), copy, package)
/**
* from gulp file command - gulp generatePot
* with gulp command string inside js file can not convert to i18n
* from cli command - wp i18n make-pot . languages/tx-onepager.pot
* but with cli command string inside js file easily convert to i18n function
* command must be run from onepager plugin directory.
*/
function generatePot(){
return src([
'./*.php',
'./*/**.php',
'./*/*/**.php',
'./*/*/*/**.php',
'./assets/*.js',
'./assets/**.js',
'!./node_modules',
'!./node_modules/**',
'!./bower_components',
'!./bower_components/**',
'!./vendor',
'!./vendor/**',
])
.pipe(wpPot( {
domain: 'tx-onepager',
package: 'WPOnepager',
} ))
.pipe(dest('./languages/tx-onepager.pot'));
}
exports.generatePot = series( generatePot)
// gulp.task('svn', function(){
// var version = getOnepagerVersion().replace("v", "");
// var init = [
// `cp tx-onepager.zip ${svnDir}`,
// `cd ${svnDir}`,
// `unzip tx-onepager.zip`,
// `rm -rf trunk/*`,
// `mv tx-onepager/* trunk`,
// `rm -rf tx-onepager.zip tx-onepager`,
// `svn add * --force`,
// `svn rm $( svn status | sed -e '/^!/!d' -e 's/^!//' )`
// ];
// var tag = [ `cd ${svnDir}`, `svn cp trunk tags/${version}`, `svn ci -m '${version} released'` ];
// shell.exec(init.join(" && "));
// shell.exec(tag.join(" && "));
// });
function getOnepagerVersion(){
var p = fs.readFileSync('tx-onepager.php', 'utf-8');
return p.split("\n")[5].split(":")[1].trim();
}
function replaceVersion(file, version){
var readme = fs.readFileSync(file, `utf-8`);
readme = readme.replace("%version%", version);
fs.writeFileSync(file, readme);
}