-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
executable file
·297 lines (222 loc) · 7.51 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
var gulp = require('gulp');
var fs = require('fs');
var uglify = require('gulp-uglify');
var jshint = require('gulp-jshint');
var minifyCss = require('gulp-minify-css');
var concat = require('gulp-concat');
var imagemin = require('gulp-imagemin');
var cache = require('gulp-cache');
var jsdoc = require('gulp-jsdoc3');
var rename = require('gulp-rename');
var del = require('del');
var es6transpiler = require('gulp-es6-transpiler');
var browserSync = require('browser-sync').create();
var sass = require('gulp-sass');
// Configuration autoloader
var config = [];
fs.readdirSync("./config").forEach(function(file) {
if (file.match(/\.json$/) !== null) {
var name = file.replace('.json', '');
config[name] = require('./config/' + file);
}
});
//------------------------------------
var _tmp=[];
for(i=0,l=config.includes.js.length;i<l;i++){
if(typeof config.includes.js[i] != 'string'){
for(var key in config.includes.js[i]){
if(key==/*config.app.environment*/'production'){
_tmp.push(config.includes.js[i][key]);
}
}
}else{
_tmp.push(config.includes.js[i]);
}
}
config.includes.js =_tmp;
config.includes.js_no_modules = config.includes.js.filter(function(file){
return(file.search('node_modules')==-1);
});
//======================================================================================================================Test
// Lint - testovanie
gulp.task("test", function() {
gulp.src(config.includes.js_no_modules)
.pipe(jshint({esversion:6,laxcomma:true}))
.pipe(jshint.reporter("default"));
});
//======================================================================================================================Documentation
deleteFolderRecursive = function(path) {
var files = [];
if( fs.existsSync(path) ) {
files = fs.readdirSync(path);
files.forEach(function(file,index){
var curPath = path + "/" + file;
if(fs.lstatSync(curPath).isDirectory()) { // recurse
deleteFolderRecursive(curPath);
} else { // delete file
fs.unlinkSync(curPath);
}
});
fs.rmdirSync(path);
}
};
//-------------------
gulp.task('documentation', function (callback) {
var documentation_config = {
"tags": {
"allowUnknownTags": true
},
"source": {
"excludePattern": "(^|\\/|\\\\)_"
},
"opts": {
"destination": "./documentation"
},
"plugins": [
"plugins/markdown"
],
"templates": {
"cleverLinks": false,
"monospaceLinks": false,
"default": {
"outputSourceFiles": true
},
"path": "ink-docstrap",
"theme": "cerulean",
"navType": "vertical",
"linenums": true,
"dateFormat": "MMMM Do YYYY, h:mm:ss a"
}
};
deleteFolderRecursive('./documentation');
gulp.src(config.includes.js_no_modules/*, {read: false}*/)
.pipe(jsdoc(documentation_config,callback));
});
//======================================================================================================================Default
// Starter Buildu
gulp.task('default', function() {
// Nacita sa hodnota environment z konfiguracneho suboru a spusti sa spravny build
if(config.app.environment == "develop") {
gulp.start("develop");
} else {
if (config.app.environment == "test") {
gulp.start("test")
} else {
gulp.start("production")
}
}
});
//======================================================================================================================Develop
gulp.task('develop', function() {
browserSync.init({
proxy: "towns.local"
});
gulp.src("app/scss/**/*.scss")
.pipe(sass())
.pipe(gulp.dest("app/css"));
gulp.watch("app/scss/**/*.scss", ['develop-sass']);
//gulp.watch('app/**/*.{js,php,phtml}').on('change', browserSync.reload);
});
// Compile sass into CSS & auto-inject into browsers
gulp.task('develop-sass', function() {
try {
del(['app/css/*']);
return gulp.src("app/scss/**/*.scss")
.pipe(sass())
.pipe(gulp.dest("app/css"))
.pipe(browserSync.stream());
}catch(e){
console.log(e);
}
});
//======================================================================================================================Build
gulp.task('build', ['production']);//alias
// Vycisti production adresar a zacni Produkcny Build
gulp.task('production', ['production-clean'], function() {
gulp.start('production-build');
});
// Vymazanie production suborov pred buildom
gulp.task('production-clean', function() {
del([
'app-build/index.php',
'app-build/scss/*',
//'app-build/media/image',
//'app-build/media/sound',
'app-build/js/*',
'app-build/fonts/*'
])
});
// Produkcny Build
gulp.task('production-build', [
'production-index',
'production-locale',
'production-scripts',
'production-images',
//'production-sound',
'production-styles',
'production-fonts',
'production-php'
], function () {
console.log(' ¯\\_(ツ)_/¯ Produkčný build je hotový ');
});
// Index.php pre produkcny build
gulp.task('production-index', function () {
gulp.src('app/*.php')
.pipe(gulp.dest('app-build/'));
gulp.src('app/php/neon/*.php')//todo better solution for php subdirs
.pipe(gulp.dest('app-build/php/neon/'));
gulp.src('app/php/neon/Neon/*.php')
.pipe(gulp.dest('app-build/php/neon/Neon/'));
});
// Index.php pre produkcny build
gulp.task('production-locale', function () {
gulp.src('app/locale/*.neon')
.pipe(gulp.dest('app-build/locale/'));
});
// Scripts
gulp.task('production-scripts', function() {
gulp.src(config.includes.js)
.pipe(concat('towns.js'))
//.pipe(gulp.dest('app-build'))
.pipe(rename({suffix: '.min'}))
.pipe(es6transpiler({
"disallowUnknownReferences": false,
"disallowDuplicated": false
}))
//.pipe(uglify())
.pipe(gulp.dest('app-build/js'));
});
// Styly
gulp.task('production-styles', function () {
gulp.src(config.includes.css)
.pipe(sass())
.pipe(concat('towns.css'))
.pipe(rename({suffix: '.min'}))
.pipe(minifyCss({compatibility: 'ie8',keepSpecialComments : false}))
.pipe(gulp.dest('app-build/css'));
});
// Obrazky - nateraz neaktivne //todo use in app
gulp.task('production-images', function () {
gulp.src('media/image/**/*')
.pipe(cache(imagemin({ optimizationLevel: 5, progressive: true, interlaced: true, multipass: true })))
//.pipe(imagemin({ optimizationLevel: 3, progressive: true, interlaced: true, multipass: true }))
.pipe(gulp.dest('app-build/media/image'));
});
// Zvuky - nateraz neaktivne
gulp.task('production-sound', function () {
gulp.src('media/sound/*')
.pipe(gulp.dest('app-build/media/sound'));
});
// Priprav fonty pre produkčný build
gulp.task('production-fonts', function () {
gulp.src([
'node_modules/roboto-fontface/fonts/*',
'node_modules/font-awesome/fonts/*'])
.pipe(gulp.dest('app-build/fonts/'));
});
// Priprav php pre produkčný build
gulp.task('production-php', function () {
gulp.src([
'app/php/*'])
.pipe(gulp.dest('app-build/php/'));
});