-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathbower2src.js
107 lines (89 loc) · 3.59 KB
/
bower2src.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
/*!
* Project: roulette-predictor
* File: ./gulp-tasks/sync/bower2src.js
* Copyright(c) [2018-present] <tbaltrushaitis@gmail.com>
* License: MIT
*/
'use strict';
// ------------------------------------------------------------------------ //
// ----------------------------- DEPENDENCIES --------------------------- //
// ------------------------------------------------------------------------ //
const fs = require('fs');
const path = require('path');
const util = require('util');
const utin = util.inspect;
const gulpif = require('gulp-if');
const cleanCSS = require('gulp-clean-css');
const changed = require('gulp-changed');
const filter = require('gulp-filter');
const uglify = require('gulp-uglify');
const rename = require('gulp-rename');
const mainBower = require('main-bower-files');
const merge = require('merge-stream');
// ------------------------------------------------------------------------ //
// ---------------------------- CONFIGURATION --------------------------- //
// ------------------------------------------------------------------------ //
let ME = global.ME || {};
const modName = path.basename(module.filename, '.js');
const modPath = path.relative(ME.WD, path.dirname(module.filename));
const modConfigFile = `config/${path.join(modPath, modName)}.json`;
const modConfig = require('read-config')(modConfigFile);
// ------------------------------------------------------------------------ //
// ------------------------------- EXPORTS ------------------------------ //
// ------------------------------------------------------------------------ //
module.exports = function (gulp) {
console.log(`[${new Date().toISOString()}][${modPath}/${modName}] ACTIVATED with modConfig = [${utin(modConfig)}]`);
let mBower = mainBower(ME.pkg.options.bower, {
base: ME.BOWER
, group: ['front']
});
let DEST = path.join(ME.BUILD, 'assets');
let KEEP = path.join(ME.BUILD, 'resources/assets');
let JS = path.join('js/lib');
let CSS = path.join('css');
let FONT = path.join('fonts');
let IMG = path.join('img');
let bowerJS = gulp.src(mBower)
.pipe(filter([
'**/*.js'
, '!**/*.min.js'
, '!**/npm.js'
]))
.pipe(gulp.dest(path.resolve(KEEP, JS)))
.pipe(gulpif('production' === ME.NODE_ENV, uglify(), false))
.pipe(gulpif('production' === ME.NODE_ENV, rename({suffix: ME.pkg.options.minify.suffix})))
.pipe(gulp.dest(path.resolve(DEST, JS)));
let bowerCSS = gulp.src(mBower)
.pipe(filter([
'**/*.css'
, "!**/*.css.map"
, '!**/*.min.css'
]))
.pipe(gulp.dest(path.resolve(KEEP, CSS)))
.pipe(gulpif('production' === ME.NODE_ENV, cleanCSS(ME.pkg.options.clean, function (d) {
console.info(d.name + ':\t' + d.stats.originalSize + '\t->\t' + d.stats.minifiedSize + '\t[' + d.stats.timeSpent + 'ms]\t[' + 100 * d.stats.efficiency.toFixed(2) + '%]');
}), false))
.pipe(gulp.dest(path.resolve(DEST, CSS)));
let bowerFonts = gulp.src(mBower)
.pipe(filter(['**/fonts/*.*']))
.pipe(changed(path.resolve(KEEP, FONT)))
.pipe(gulp.dest(path.resolve(KEEP, FONT)))
.pipe(gulp.dest(path.resolve(DEST, FONT)));
let bowerImg = gulp.src(mBower)
.pipe(filter([
'**/img/*.*'
, '**/image/*.*'
, '**/images/*.*'
]))
.pipe(filter([
'**/*.png'
, '**/*.jpg'
, '**/*.jpeg'
, '**/*.gif'
, '**/*.ico'
]))
.pipe(changed(path.join(KEEP, IMG)))
.pipe(gulp.dest(path.join(KEEP, IMG)))
.pipe(gulp.dest(path.join(DEST, IMG)));
return merge(bowerJS, bowerCSS, bowerFonts, bowerImg);
};