-
Notifications
You must be signed in to change notification settings - Fork 41
/
gulpfile.js
115 lines (94 loc) · 2.59 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
// Search & Filter
/* ==========
* REQUIRE
* ========== */
var gulp = require('gulp');
var plugins = require('gulp-load-plugins')(); //auto load `gulp
var rename = require('gulp-rename'); //change filename before saving
var del = require('del'); //for cleaning up the folder on rebuild
var fs = require('fs'); //for cleaning up the folder on rebuild
var path = require('path');
var handleErrors = require('./gulp/handleErrors');
/* ==========
* CONFIG
* ========== */
var projectDefaults = {
name: 'search-filter-free',
build: './build',
publicApp: {},
src: 'src/',
dev: 'dist/',
dist: 'dist/'
};
let project = projectDefaults;
const localBuildConfigPath = './local/config.js';
if ( fs.existsSync( localBuildConfigPath ) ) {
// We have a local config we want to merge
const localBuildConfig = require( localBuildConfigPath );
project = { ...projectDefaults, ...localBuildConfig };
}
project.publicApp = {
src: './'+project.src+'/public/assets/js/',
cssSrc: './'+project.src+'/public/assets/css/',
build: project.build+'/public/assets/js/',
cssBuild: project.build+'/public/assets/css/',
dist: './'+project.dev+'/public/assets/js/'
}
var appTasks = new Array(); //contain references to dynamically generated app tasks - app tasks are tasks which are specific to a particular game
appTasks['scripts'] = new Array();
appTasks['templates'] = new Array();
// config for tasks & modules
var options = {
uglify: {
compress: {
drop_console: true //always remove console.logs - dist should never have console.logs
},
mangle: true
},
minifyCss: {
//keepBreaks: true,
compatibility: 'ie8',
keepSpecialCommentsBreaks: true
},
}
/* ==========
* TASKS
* ========== */
gulp.task('copy-plugin', function ( done ) {
gulp.src([
project.src+'**/*',
'!'+project.publicApp.src+"**/*",
'!'+project.publicApp.cssSrc+"**/*"
]).pipe(plugins.newer(project.build)).pipe(gulp.dest(project.build));
done();
});
function ensureDirectoryExistence(filePath) {
var dirname = path.dirname(filePath);
if (fs.existsSync(dirname)) {
return true;
}
ensureDirectoryExistence(dirname);
fs.mkdirSync(dirname);
}
/*
* Utility functions
*/
gulp.task('clean', function (cb) {
del([
project.build+'**/*.*',
project.dev+'**/*.*',
project.build+'**',
project.dev+'**'
], cb);
});
gulp.task('watch', function( done ) {
//wait for changes and run tasks accordingly
gulp.watch([
project.src+'**/*',
], gulp.series('copy-plugin') );
done();
});
gulp.task('default', gulp.series( 'copy-plugin', 'watch', function( done ) {
console.log("Init main tasks");
done();
} ) );