-
Notifications
You must be signed in to change notification settings - Fork 2
/
gulpfile.js
119 lines (102 loc) · 3.36 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
const gulp = require('gulp')
const del = require('del')
const fs = require('fs')
const request = require('request')
const concat = require('gulp-concat')
const cleanCSS = require('gulp-clean-css')
const zip = require('gulp-zip')
const gutil = require('gulp-util')
const uglifyes = require('uglify-es')
const composer = require('gulp-uglify/composer')
var minify = composer(uglifyes, console)
const outPath = gutil.env.env === 'prod' ? './docs/demo' : './dev'
const jsFiles = [
'./node_modules/jquery/dist/jquery.js',
'./node_modules/bootstrap/js/tooltip.js',
'./node_modules/d3/dist/d3.js',
'./node_modules/c3/c3.js',
'./node_modules/underscore/underscore.js',
'./node_modules/xlsx/dist/xlsx.full.min.js',
'./src/js/helpers.js',
'./src/js/TimeGraph.js',
'./src/js/graphSetup.js',
'./src/js/documents.js',
'./src/js/summary.js',
'./src/js/action.js'
]
const cssFiles = [
'./node_modules/bootstrap/dist/css/bootstrap.css',
'./node_modules/@fortawesome/fontawesome-free/css/solid.css',
'./node_modules/@fortawesome/fontawesome-free/css/brands.css',
'./node_modules/@fortawesome/fontawesome-free/css/fontawesome.css',
'./node_modules/c3/c3.css',
'./src/css/**'
]
const codelists = [
'Country',
'Region',
'Language',
'DocumentCategory'
]
gulp.task('clean', () => {
return del(outPath + '/*')
})
gulp.task('zip', (done) => {
if (gutil.env.env === 'prod') {
return gulp.src(outPath + '/**')
.pipe(zip('extension.zip'))
.pipe(gulp.dest('.'))
}
return done()
})
gulp.task('build:codelists', (done) => {
if (gutil.env.env === 'prod') {
var baseUrl = 'http://reference.iatistandard.org/203/codelists/downloads/clv2/json/en/'
codelists.map(function (codelist) {
return request(baseUrl + codelist + '.json')
.pipe(fs.createWriteStream('./src/static/json/' + codelist + '.json'))
})
}
return done()
})
gulp.task('build:_core_js', () => {
return gulp.src(jsFiles)
.pipe(concat('js.js'))
.pipe(gutil.env.env === 'prod' ? minify() : gutil.noop())
.pipe(gulp.dest(outPath + '/js'))
})
gulp.task('build:_bg_js', () => {
return gulp.src('./src/js/background.js')
.pipe(gutil.env.env === 'prod' ? minify() : gutil.noop())
.pipe(gulp.dest(outPath + '/js'))
})
gulp.task('build:_individual_js', () => {
return gulp.src(['./src/js/demo.js', './src/js/helpers.js', './src/js/popup.js', './node_modules/jquery/dist/jquery.js'])
.pipe(gutil.env.env === 'prod' ? minify() : gutil.noop())
.pipe(gulp.dest(outPath + '/js'))
})
gulp.task('build:js', gulp.parallel('build:_core_js', 'build:_bg_js', 'build:_individual_js'))
gulp.task('build:css', () => {
return gulp.src(cssFiles)
.pipe(concat('css.css'))
.pipe(gutil.env.env === 'prod' ? cleanCSS() : gutil.noop())
.pipe(gulp.dest(outPath + '/css'))
})
gulp.task('build:assets', () => {
return gulp.src([
'./src/static/**',
'./node_modules/bootstrap/dist/fonts*/*',
'./node_modules/@fortawesome/fontawesome-free/webfonts*/fa-solid-*',
'./node_modules/@fortawesome/fontawesome-free/webfonts*/fa-brands-*'
])
.pipe(gulp.dest(outPath))
})
gulp.task('build',
gulp.series(
gulp.parallel('clean', 'build:codelists'),
gulp.parallel('build:css', 'build:js', 'build:assets'),
'zip'))
gulp.task('watch', gulp.series(['build'], () => {
gulp.watch('./src/**', gulp.parallel('build'))
}))
gulp.task('default', gulp.parallel('build'))