-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathgulpfile.js
427 lines (381 loc) · 14.8 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
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
'use strict';
const { src, dest, watch, series, parallel } = require('gulp');
const path = require('path');
const less = require('gulp-less');
const sass = require('gulp-sass')(require('sass'));
const cleanCSS = require('gulp-clean-css');
const uglify = require('gulp-uglify');
const sourceMaps = require('gulp-sourcemaps');
const connect = require('gulp-connect');
const gutil = require('gulp-util');
const rename = require('gulp-rename');
const concat = require('gulp-concat');
const minifyCSS = require('gulp-minify-css');
const stripDebug = require('gulp-strip-debug');
const include = require('gulp-include');
let node_folder_path_bootstrap = path.join(__dirname, 'node_modules/bootstrap');
// caminho da pasta 'node_modules/bootstrap'
let node_folder_path = path.join(__dirname, 'node_modules/');
console.info('[INFO] [gulpfile.js] path da pasta node_modules:\t', node_folder_path);
// caminho da pasta 'node_modules/scielo-design-system/src/bootstrap/scss'
let node_folder_path_scielo_ds = path.join(__dirname, 'node_modules/scielo-design-system/src/bootstrap/scss/');
console.info('[INFO] [gulpfile.js] path da pasta node_modules/scielo-design-system/src/bootstrap/scss:\t', node_folder_path_scielo_ds);
// caminho da pasta 'node_modules/scielo-design-system/dist/img'
let node_folder_path_scielo_ds_img = path.join(__dirname, 'node_modules/scielo-design-system/dist/img/');
console.info('[INFO] [gulpfile.js] path da pasta node_modules/scielo-design-system/dist/img:\t', node_folder_path_scielo_ds_img);
// caminho da pasta 'opac/webapp/static/'
let static_folder_path = path.join(__dirname, 'opac/webapp/static/');
console.info('[INFO] [gulpfile.js] path da pasta static:\t', static_folder_path);
let paths = {
// caminho relativo da pasta 'bootstrap/js/ dentro do node_modules, fora do projeto'
'bootstrap_js': path.join(node_folder_path, 'bootstrap/dist/js/'),
// caminho relativo da pasta 'scielo-design-system/dist/js/bootstrap.min.js dentro do node_modules, fora do projeto'
'scielo_design_system_bootstrap_js': path.join(node_folder_path, 'scielo-design-system/dist/js/'),
// caminho relativo da pasta 'jquery/dist/ dentro do node_modules, fora do projeto'
'jquery_js': path.join(node_folder_path, 'jquery/dist/'),
// caminho relativo da pasta 'jquery-typeahead/dist/ dentro do node_modules, fora do projeto'
'jquery-typeahead_js': path.join(node_folder_path, 'jquery-typeahead/dist/'),
// caminho relativo da pasta 'static/js/'
'static_js': path.join(static_folder_path, 'js/'),
// caminho relativo da pasta 'static/less/'
'static_less': path.join(static_folder_path, 'less/'),
// caminho relativo da pasta 'static/sass/'
'static_sass': path.join(static_folder_path, 'sass/'),
// caminho relativo da pasta 'static/css/'
'static_css': path.join(static_folder_path, 'css/'),
// caminho relativo da pasta 'static/img/'
'static_img': path.join(static_folder_path, 'img/'),
};
console.info('[INFO] [gulpfile.js] path da pasta bootstrap/js:\t', paths['bootstrap_js']);
//console.info('[INFO] [gulpfile.js] path da pasta bootstrap/less:\t', paths['bootstrap_less']);
//console.info('[INFO] [gulpfile.js] path da pasta bootstrap/css:\t', paths['bootstrap_css']);
console.info('[INFO] [gulpfile.js] path da pasta static/js:\t', paths['static_js']);
console.info('[INFO] [gulpfile.js] path da pasta static/less:\t', paths['static_less']);
console.info('[INFO] [gulpfile.js] path da pasta static/css:\t', paths['static_css']);
let target_src = {
'js': {
'scielo-bundle': [
// instruções JS (designer)
path.join(paths['jquery_js'], 'jquery.js'), // foi setado para carregar separadamente
path.join(paths['scielo_design_system_bootstrap_js'], 'bootstrap.bundle.js'), // foi setado para carregar separadamente
path.join(paths['jquery-typeahead_js'], 'jquery.typeahead.min.js'),
path.join(paths['static_js'], 'plugins.js'),
path.join(paths['static_js'], 'slick.min.js'),
path.join(paths['static_js'], 'main.js'),
path.join(paths['static_js'], 'cookieMsg.js'),
// instruções JS (equipe scielo)
path.join(paths['static_js'], 'common.js'),
path.join(paths['static_js'], 'moment.js'),
path.join(paths['static_js'], 'moment_locale_pt_br.js'),
path.join(paths['static_js'], 'moment_locale_es.js'),
path.join(paths['static_js'], 'modal_forms.js'),
],
'scielo-article': [
path.join(paths['static_js'], 'scielo-article.js')
],
'scielo-article-standalone': [
path.join(paths['jquery_js'], 'jquery.js'),
path.join(paths['scielo_design_system_bootstrap_js'], 'bootstrap.bundle.js'),
path.join(paths['static_js'], 'plugins.js'),
path.join(paths['static_js'], 'scielo-article.js'),
],
},
'less': {
'scielo-bundle': [
//path.join(node_folder_path, 'scielo-design-system/dist/css/bootstrap.css'),
//path.join(paths['static_less'], 'scielo-bundle.less'),
path.join(paths['static_less'], 'bootstrap.less'),
path.join(paths['static_less'], 'scielo-portal.less'),
path.join(paths['static_less'], 'collection.less'),
path.join(paths['static_less'], 'journal-menu.less'),
path.join(paths['static_less'], 'journal.less'),
path.join(paths['static_less'], 'portal.less'),
path.join(paths['static_less'], 'search.less'),
path.join(paths['static_less'], 'style.less'),
path.join(paths['static_less'], 'jquery.typeahead.less')
],
'scielo-article': [
path.join(paths['static_less'], 'scielo-article.less')
],
'bootstrap': [
path.join(paths['static_less'], 'bootstrap.less')
//path.join(node_folder_path, 'scielo-design-system/css/bootstrap.css')
//'bootstrap_js': path.join(node_folder_path, 'bootstrap/dist/js/'),
],
'scielo-article-standalone': [
path.join(paths['static_less'], 'scielo-article-standalone.less')
],
'scielo-bundle-print': [
path.join(paths['static_less'], 'scielo-bundle-print.less')
],
},
'sass': {
'scielo-bundle': [
path.join(paths['static_sass'], 'bootstrap.scss'),
path.join(paths['static_sass'], 'scielo-portal.scss'),
path.join(paths['static_sass'], 'collection.scss'),
path.join(paths['static_sass'], 'journal-menu.scss'),
path.join(paths['static_sass'], 'journal.scss'),
path.join(paths['static_sass'], 'portal.scss'),
path.join(paths['static_sass'], 'search.scss'),
path.join(paths['static_sass'], 'style.scss'),
path.join(paths['static_sass'], 'jquery.typeahead.scss')
],
'scielo-article': [
path.join(paths['static_sass'], 'scielo-article.scss')
],
'bootstrap': [
path.join(paths['static_sass'], 'bootstrap.scss')
],
'scielo-article-standalone': [
path.join(paths['static_sass'], 'scielo-article-standalone.scss')
],
'scielo-bundle-print': [
path.join(paths['static_sass'], 'scielo-bundle-print.scss')
],
},
'img': {
'logos': [
path.join(node_folder_path_scielo_ds_img, 'logo-scielo-no-label.svg'),
path.join(node_folder_path_scielo_ds_img, 'logo-scielo-no-label-negative.svg'),
path.join(node_folder_path_scielo_ds_img, 'logo-open-access.svg'),
path.join(node_folder_path_scielo_ds_img, 'logo-footer-fapesp.svg'),
path.join(node_folder_path_scielo_ds_img, 'logo-footer-fap.svg'),
path.join(node_folder_path_scielo_ds_img, 'logo-footer-cnpq.svg'),
path.join(node_folder_path_scielo_ds_img, 'logo-footer-capes.svg'),
path.join(node_folder_path_scielo_ds_img, 'logo-footer-bvs.svg'),
path.join(node_folder_path_scielo_ds_img, 'logo-footer-bireme.svg'),
]
}
};
let output = {
'js': {
'folder': paths['static_js'],
// caminho dos arquivos JS para salvar os resultados
'scielo-bundle': 'scielo-bundle-min.js',
'scielo-article': 'scielo-article-min.js',
'scielo-article-standalone': 'scielo-article-standalone-min.js',
},
'css': { // caminho dos arquivos CSS para salvar os resultados
'folder': paths['static_css'],
'scielo-bundle': 'scielo-bundle.css',
'scielo-article': 'scielo-article.css',
'scielo-article-standalone': 'scielo-article-standalone.css',
'scielo-bundle-print': 'scielo-bundle-print.css',
},
'img': { // caminho dos arquivos IMG SVG para salvar os resultados
'folder': paths['static_img'],
'logo-scielo-no-label': 'logo-scielo-no-label.svg',
'logo-scielo-no-label-negative': 'logo-scielo-no-label-negative.svg',
'logo-open-access': 'logo-open-access.svg',
'logo-footer-fapesp': 'logo-footer-fapesp.svg',
'logo-footer-fap': 'logo-footer-fap.svg',
'logo-footer-cnpq': 'logo-footer-cnpq.svg',
'logo-footer-capes': 'logo-footer-capes.svg',
'logo-footer-bvs': 'logo-footer-bvs.svg',
'logo-footer-bireme': 'logo-footer-bireme.svg'
}
};
// Task para gerar o scielo-article-standalone.js
function processScieloArticleStandaloneJs(){
return src(target_src['js']['scielo-article-standalone'])
.pipe(concat(output['js']['scielo-article-standalone']))
.pipe(sourceMaps.init())
.pipe(stripDebug())
.pipe(uglify())
.pipe(sourceMaps.write('../maps'))
.pipe(dest(output['js']['folder']));
}
// Task para gerar o scielo-article.js
function processScieloArticleJs(){
return src(target_src['js']['scielo-article'])
.pipe(concat(output['js']['scielo-article']))
.pipe(sourceMaps.init())
.pipe(stripDebug())
.pipe(uglify())
.pipe(sourceMaps.write('../maps'))
.pipe(dest(output['js']['folder']));
}
// Task para gerar o scielo-bundle.js
function processScieloBundleJs(){
return src(target_src['js']['scielo-bundle'])
.pipe(concat(output['js']['scielo-bundle']))
.pipe(sourceMaps.init())
//.pipe(stripDebug())
.pipe(uglify())
.pipe(sourceMaps.write('../maps'))
.pipe(dest(output['js']['folder']));
}
// Task para gerar o scielo-bundle-print.less
function processScieloBundlePrintLess(){
return src(target_src['less']['scielo-bundle-print'])
.pipe(sourceMaps.init({loadMaps: true}))
.pipe(concat(output['css']['scielo-bundle-print']))
.pipe(less(output['css']['scielo-bundle-print']))
.pipe(minifyCSS())
.pipe(sourceMaps.write('./'))
.pipe(dest(output['css']['folder']));
}
// Task para gerar o scielo-article-standalone.less
function processScieloArticleStandaloneLess(){
return src(target_src['less']['scielo-article-standalone'])
.pipe(sourceMaps.init({loadMaps: true}))
.pipe(concat(output['css']['scielo-article-standalone']))
.pipe(less(output['css']['scielo-article-standalone']))
.pipe(minifyCSS())
.pipe(sourceMaps.write('./'))
.pipe(dest(output['css']['folder']));
}
function processScieloBundleLess(){
return src(target_src['less']['scielo-bundle'])
.pipe(sourceMaps.init({loadMaps: true}))
.pipe(concat(output['css']['scielo-bundle']))
.pipe(
less().on('error', function(err) {
gutil.log(err);
this.emit('end');
}))
.pipe(
cleanCSS()
)
.pipe(
minifyCSS()
)
.pipe(sourceMaps.write('./'))
.pipe(
dest(output['css']['folder'])
)
.pipe(
connect.reload()
);
}
function processScieloArticleLess(){
return src(target_src['less']['scielo-article'])
.pipe(sourceMaps.init({loadMaps: true}))
.pipe(
less().on('error', function(err) {
gutil.log(err);
this.emit('end');
}))
.pipe(
cleanCSS()
)
.pipe(
minifyCSS()
)
.pipe(sourceMaps.write('./'))
.pipe(
dest(output['css']['folder'])
)
.pipe(
connect.reload()
);
}
function watchProcessScieloBundleLess() {
return watch(paths['static_less'], processScieloBundleLess);
}
function watchProcessScieloArticleLess() {
return watch(paths['static_less'], processScieloArticleLess);
}
/*
Criando Bundle sass
*/
function processScieloBundleSass(){
return src(target_src['sass']['scielo-bundle'])
.pipe(sourceMaps.init())
.pipe(concat(output['css']['scielo-bundle']))
.pipe(
sass({
//outputStyle: 'nested',
includePaths: ['./node_modules/bootstrap/']
})
)
.pipe(include())
.pipe(cleanCSS())
.pipe(sourceMaps.write('./'))
.pipe(dest(output['css']['folder']));
}
/*
Criando Bootstrap Sass
*/
function processBootstrapSass(){
return src(target_src['sass']['bootstrap'])
.pipe(sourceMaps.init())
.pipe(
sass({
//outputStyle: 'nested',
includePaths: ['./node_modules/bootstrap/']
})
)
.pipe(include())
.pipe(cleanCSS())
.pipe(sourceMaps.write('./'))
.pipe(dest(output['css']['folder']));
}
/*
Criando Article Sass
*/
function processScieloArticleSass(){
return src(target_src['sass']['scielo-article'])
.pipe(sourceMaps.init({loadMaps: true}))
.pipe(
sass().on('error', function(err) {
gutil.log(err);
this.emit('end');
}))
.pipe(
cleanCSS()
)
.pipe(
minifyCSS()
)
.pipe(sourceMaps.write('./'))
.pipe(
dest(output['css']['folder'])
)
.pipe(
connect.reload()
);
}
/*
Copiando imagens do design system
*/
function processDesignSystemImg(){
return src(target_src['img']['logos'])
.pipe(dest(output['img']['folder']));
}
/*
Copiando bundle bootstrap para dentro do projeto
*/
function processBootstrapBundle(){
return src('node_modules/bootstrap/dist/js/bootstrap.bundle.js')
.pipe(dest(output['js']['folder']));
}
exports.watch = series(
processScieloBundleLess,
processScieloArticleLess,
parallel(
watchProcessScieloBundleLess,
watchProcessScieloArticleLess
)
)
exports.default = series(
processScieloBundleLess,
processScieloArticleLess,
processScieloArticleStandaloneLess,
processScieloBundlePrintLess,
processScieloBundleJs,
processScieloArticleJs,
processScieloArticleStandaloneJs
);
/*
Tasks para copiar e gerar arquivos baseados no
Design System direto do node_modules.
Arquivos Sass
*/
exports.bundleSass = processScieloBundleSass;
exports.bootstrapSass = processBootstrapSass;
exports.processImages = processDesignSystemImg;
exports.articleSass = processScieloArticleSass;
exports.bootstrapBundleJs = processBootstrapBundle;
exports.scieloBundleJs = processScieloBundleJs;