This repository has been archived by the owner on Dec 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
177 lines (155 loc) · 4.88 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
"use strict";
const fs = require('fs');
const path = require('path');
const dirSource = './source';
const dirOutput = './app/assets';
/*
* INCLUDE
*/
// Include gulp
const gulp = require('gulp');
// Include Plugins
const concat = require('gulp-concat');
// const uglify = require('gulp-uglify');
const less = require('gulp-less');
const nano = require('gulp-cssnano');
//const postcss = require('gulp-postcss');
//const autoprefixer = require('autoprefixer');
// const babel = require('gulp-babel');
const rename = require('gulp-rename');
const watchLess = require('gulp-watch-less2');
// const notify = require("gulp-notify");
const ngAnnotate = require('gulp-ng-annotate');
const babel = require('gulp-babel');
// Defaults ===================================================================
const terserOptions = {
mangle: false,
keep_classnames: true,
keep_fnames: true,
}
// Tasks ======================================================================
const scripts = {
base: () =>
gulp.src(parseKoalaJS(dirSource, 'js-base.js'))
// .pipe(babel())
.pipe(concat('js-base.js'))
/*
.pipe(babel({
'highlightCode': false,
'comments': false,
'compact': false,
'ast': false
}))
*/
// .pipe(uglify())
.pipe(gulp.dest(dirOutput)),
appMain: () =>
gulp.src(parseKoalaJS(dirSource, 'js-app-main.js'))
// .pipe(babel())
.pipe(concat('js-app-main.js'))
//.pipe(uglify())
.pipe(gulp.dest(dirOutput)),
appAngular: () =>
gulp.src(parseKoalaJS(dirSource, 'js-app-angular.js'))
.pipe(concat('js-app-angular.js'))
.pipe(ngAnnotate())
// .pipe(babel())
.pipe(gulp.dest(dirOutput))
}
const styles = {
app: () => {
let f = path.join(dirSource, '*.less');
return gulp.src(f)
.pipe(watchLess(f, { verbose: true }, function (File) {
lessCompile(File.history[0], dirOutput, {
nano: {
autoprefixer: {
'browsers': [
'Android >= 2',
'Chrome >= 20',
'Firefox >= 20',
'ie >= 11',
'Edge >= 12',
'iOS >= 5',
'ChromeAndroid >= 20',
'ExplorerMobile >= 11'
],
add: true
}
}
})
}))
/*
return gulp.src( path.join( rootSource, 'css-app.less' ) )
.pipe(less())
//.pipe(less({
// 'plugins': [cleanCSSPlugin]
//}))
.pipe(postcss([
autoprefixer({browsers: ['Chrome >= 41']})
]))
.pipe(nano({
//safe: true
}))
.pipe(gulp.dest( path.join( root, 'app', 'assets' ) ));
*/
},
}
const allTasks = {
scripts: Object.values(scripts),
styles: Object.values(styles)
}
const build = gulp.parallel(
...Object.values(allTasks).map(tasks => gulp.parallel(...tasks))
)
exports.build = build
exports.watch = function () {
gulp.watch(
path.join(dirSource, '*js-!(angular)/**/*.js'),
[scripts.base, scripts.appMain]
);
gulp.watch(
path.join(dirSource, 'js-angular/**/*.js'),
[scripts.appAngular]
);
}
// Commons ====================================================================
function parseKoalaJS() {
let filename = Array.prototype.pop.call(arguments);
let dir = Array.prototype.join.call(arguments, '/');
const r = fs.readFileSync(path.join(dir, filename), 'utf-8')
.replace(/\r?\n|\r/g, '')
.split('// @koala-prepend ')
.filter(function (value) {
return value
})
.map(function (value) {
if (value)
return path.join(dir, value.replace(/^"(.+)"$/g, '$1'))
});
return r
}
function lessCompile(file, outputPath, options) {
options = options || {}
function log() {
console.log(`Compiled LESS ${file}`)
}
if (options.onlyMinify) {
return gulp.src(file)
.pipe(less())
.pipe(nano(options.nano))
.pipe(gulp.dest(outputPath))
.on('end', log)
.on('error', log);
} else {
return gulp.src(file)
.pipe(less())
.pipe(gulp.dest(outputPath))
.pipe(nano(options.nano))
.pipe(rename({ extname: '.min.css' }))
.pipe(gulp.dest(outputPath))
.on('end', log)
.on('error', log);
}
}
exports.default = build