forked from assemblee-virtuelle/grands-voisins-v2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
193 lines (178 loc) · 6.3 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
var gulp = require('gulp');
var babel = require('gulp-babel');
var sourcemaps = require('gulp-sourcemaps');
var uglify = require('gulp-uglify');
var concat = require('gulp-concat');
var git = require('gulp-git');
var sync = require('gulp-sync')(gulp);
var sass = require('gulp-sass');
var fs = require('fs');
// For each file (with no extension),
// if value is "true", use the .js version to build .min.js version,
// if value is an array, aggregate the files to the .min.js version.
var filesJs = {
'web/front/src/main': true,
// Main admin script.
'web/admin/js/dist/script': [
'web/admin/js/src/class/lgvAdmin.js',
'web/admin/js/src/class/lgvAdminPage.js',
// Page specific scripts.
'web/admin/js/src/class/lgvAdminPageTeam.js',
'web/admin/js/src/class/lgvAdminPageUser.js',
'web/admin/js/src/class/lgvAdminPageProfile.js',
'web/admin/js/src/class/lgvAdminPageOrga.js',
'web/admin/js/src/class/lgvAdminPageComponent.js',
// Fields.
'vendor/VirtualAssembly/SemanticFormsBundle/VirtualAssembly/SemanticFormsBundle/Resources/js/field.uri.js',
'vendor/VirtualAssembly/SemanticFormsBundle/VirtualAssembly/SemanticFormsBundle/Resources/js/field.dbPedia.js',
'vendor/VirtualAssembly/SemanticFormsBundle/VirtualAssembly/SemanticFormsBundle/Resources/js/semanticForms.js',
// Launcher
'web/admin/js/src/main.js'
],
// Front
'web/front/src/gv-avatar/gv-avatar': true,
'web/front/src/gv-carto/gv-carto': true,
'web/front/src/gv-header/gv-header': true,
'web/front/src/gv-results/gv-results': true,
'web/front/src/gv-results-tab/gv-results-tab': true,
'web/front/src/gv-results-item/gv-results-item': true,
'web/front/src/gv-logo-animated/gv-logo-animated': true,
'web/front/src/gv-detail/gv-detail': true,
'web/front/src/gv-ressource/gv-ressource': true,
'web/front/src/gv-detail-organization/gv-detail-organization': true,
'web/front/src/gv-detail-person/gv-detail-person': true,
'web/front/src/gv-detail-projet/gv-detail-projet': true,
'web/front/src/gv-detail-event/gv-detail-event': true,
'web/front/src/gv-detail-proposition/gv-detail-proposition': true,
'web/front/src/gv-map/gv-map': true,
'web/front/src/gv-map-pin/gv-map-pin': true
};
var filesScss = {
// Semantic Forms.
//'src/VirtualAssembly/SemanticFormsBundle/Resources/css/semanticForms': true,
// Admin
'web/admin/css/menu': true,
'web/admin/css/style': true,
// Front
'web/front/css/style': true,
'web/front/src/gv-avatar/gv-avatar': true,
'web/front/src/gv-carto/gv-carto': true,
'web/front/src/gv-spinner/gv-spinner': true,
'web/front/src/gv-results/gv-results': true,
'web/front/src/gv-results-tab/gv-results-tab': true,
'web/front/src/gv-results-item/gv-results-item': true,
'web/front/src/gv-header/gv-header': true,
'web/front/src/gv-detail/gv-detail': true,
'web/front/src/gv-ressource/gv-ressource': true,
'web/front/src/gv-detail/gv-detail-inner': true,
'web/front/src/gv-detail-organization/gv-detail-organization': true,
'web/front/src/gv-detail-person/gv-detail-person': true,
'web/front/src/gv-detail-projet/gv-detail-projet': true,
'web/front/src/gv-detail-event/gv-detail-event': true,
'web/front/src/gv-detail-proposition/gv-detail-proposition': true,
'web/front/src/gv-logo-animated/gv-logo-animated': true,
'web/front/src/gv-map/gv-map': true,
'web/front/src/gv-map-pin/gv-map-pin': true
};
function getFilesOptions(destFile, sourceFiles, sourceExt, destExt) {
"use strict";
// Get source from dest if not defined.
if (sourceFiles === true) {
sourceFiles = [destFile + '.' + sourceExt];
}
else if (typeof sourceFiles === 'string') {
sourceFiles = [sourceFiles];
}
sourceFiles.map((file) => {
if (!fs.existsSync(file)) {
console.error('Missing ' + file);
}
});
var split = destFile.split('/');
var destFileName = split.pop();
var destFilePath = split.join('/') + '/';
return {
sourceFiles: sourceFiles,
destFileName: destFileName,
destFilePath: destFilePath
};
}
function buildFiles(files, action, sourceExt, destExt) {
// One task for each file separately.
Object.keys(files).map((destFile) => {
var fileData = getFilesOptions(destFile, files[destFile], sourceExt);
console.log('Building ' + fileData.destFilePath + fileData.destFileName + '.' + destExt + ' ...');
action(destFile, fileData, sourceExt, destExt);
});
}
var tasksCounter = 0;
var allTasks = [];
buildFiles(filesJs, (destFile, fileData, sourceExt, destExt) => {
"use strict";
let key = 'buildFileJs' + tasksCounter++;
allTasks.push(key);
gulp.task(key, () => {
// Create task.
gulp.src(fileData.sourceFiles, {base: "./"})
// Create ap file.
.pipe(sourcemaps.init())
// Transpile.
.pipe(babel({
presets: ['latest']
}))
// Set dest name.
.pipe(concat(fileData.destFileName + '.' + destExt))
// Compress.
.pipe(uglify())
// Write map file.
.pipe(sourcemaps.write('.'))
// Write.
.pipe(gulp.dest(fileData.destFilePath));
});
}, 'js', 'min.js');
buildFiles(filesScss, (destFile, fileData, sourceExt, destExt) => {
"use strict";
let key = 'buildFileCss' + tasksCounter++;
allTasks.push(key);
gulp.task(key, () => {
gulp.src(fileData.sourceFiles, {base: "./"})
// Set dest name.
.pipe(concat(fileData.destFileName + '.' + destExt))
.pipe(sass({
includePaths: [fileData.destFilePath]
}).on('error', sass.logError))
.pipe(gulp.dest(fileData.destFilePath));
});
}, 'scss', 'css');
function getFiles(registery, ext, sourceFiles) {
"use strict";
Object.keys(registery).map((destFiles) => {
"use strict";
let source = registery[destFiles];
if (source === true) {
sourceFiles.push(destFiles + '.' + ext);
}
else if (typeof source === 'string') {
sourceFiles.push(source);
}
else {
for (let i = 0; i < source.length; i++) {
sourceFiles.push(source[i]);
}
}
});
}
// Define files to watch.
gulp.task('watch', () => {
var sourceFiles = [];
getFiles(filesJs, 'js', sourceFiles);
getFiles(filesScss, 'scss', sourceFiles);
// Check
sourceFiles.map((file) => {
if (!fs.existsSync(file)) {
console.error('Missing watched file : ' + file);
}
});
gulp.watch(sourceFiles, [allTasks]);
});
gulp.task('default', allTasks.concat('watch'));