This repository has been archived by the owner on Dec 10, 2024. It is now read-only.
forked from dmarc-viewer/dmarc-viewer
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathGulpfile.js
203 lines (174 loc) · 6.46 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
/*****************************************************************
<File Name>
Gulpfile.js
<Author>
Lukas Puehringer <[email protected]>
<Started>
July 22, 2015
<Copyright>
See LICENSE for licensing information.
<Purpose>
Frontend dependency task runners to
- Compile SCSS to CSS (website/static/sass)
- Vendorize fonts (node_modules)
- Create dist files
- 3rd party CSS (node_modules)
- 3rd party JS (node_modules)
- local CSS (website/static/css)
- local JS (website/static/js)
3rd party dependencies are defined in `package.json` and can be installed
using npm like so:
npm install
3rd party dependencies are always served from `dist` (the latest minified
concatenated version should be checked into vcs).
Creating new `dist` files is only necessary when dependencies are
updated/added/removed.
3rd party fonts are served from `website/static/fonts` and are also
checked into vcs. (AFAIK there is no obvious way to create a `dist` version
from fonts).
Local frontend code is served either from `dist` (the latest minified
concatenated version should be checked into vcs) or non-minified from
`website/static/js` and `website/static/css` when the Django setting
`settings.TEMPLATE_SETTINGS.use_dist` is `False`
Change local frontend code in `website/static/js` and
`website/static/sass` only (sass code is compiled to css code with an extra
task runner).
<Usage>
Task runners can be invoked from the command line, e.g.:
```
gulp create-dist
gulp create-dist-js
gulp create-dist-css
gulp create-dist-js-node-modules
gulp create-dist-css-node-modules
gulp copy-fonts
gulp compile-scss
```
*****************************************************************/
var gulp = require('gulp');
var gulpSass = require('gulp-sass');
var gulpConcat = require('gulp-concat');
var gulpUglifyJs = require('gulp-uglify');
var gulpCleanCss = require('gulp-clean-css');
var gulpSourceMaps = require('gulp-sourcemaps');
/*
* List of all 3rd party and non-3rd party frontend dependencies, i.e.
* CSS/SCSS, JavaScript and fonts.
* Note: Requires dependencies installed in `node_modules`.
*/
var paths = {
css: [
'website/static/css/dmarc_viewer.css'
],
js: [
'website/static/js/main.js',
'website/static/js/editor.js',
'website/static/js/analysis.js',
'website/static/js/d3.legend.js'
],
scss: [
'website/static/sass/dmarc_viewer.scss'
],
scss_node_modules: [
'node_modules/bootstrap-sass/assets/stylesheets',
'node_modules/bootstrap-colorpicker/src/sass',
],
css_node_modules: [
'node_modules/selectize/dist/css/selectize.bootstrap3.css',
'node_modules/bootstrap-datepicker/dist/css/bootstrap-datepicker3.css',
'node_modules/bootstrap-colorpicker/dist/css/bootstrap-colorpicker.css',
'node_modules/datatables.net-bs/css/dataTables.bootstrap.css',
'node_modules/datatables.net-responsive-bs/css/responsive.bootstrap.css'
],
js_node_modules: [
'node_modules/jquery/dist/jquery.js',
'node_modules/bootstrap-sass/assets/javascripts/bootstrap.js',
'node_modules/sortablejs/Sortable.js',
'node_modules/selectize/dist/js/standalone/selectize.js',
'node_modules/bootstrap-colorpicker/dist/js/bootstrap-colorpicker.js',
'node_modules/bootstrap-datepicker/js/bootstrap-datepicker.js',
'node_modules/datatables.net/js/jquery.dataTables.js',
'node_modules/datatables.net-bs/js/dataTables.bootstrap.js',
'node_modules/datatables.net-responsive/js/dataTables.responsive.js',
'node_modules/d3/d3.js',
'node_modules/topojson/dist/topojson.js',
'node_modules/datamaps/dist/datamaps.all.js',
],
fonts_node_modules: [
'node_modules/bootstrap-sass/assets/fonts/**/*'
]
}
/*
* Helper function to minify and concatenate the files in the passed list of
*`src_paths` using the passed `minifier` (e.g. `gulpClassCss` for CSS,
* or `gulpUglify` for JS) and writes the resulting file to
* "website/static/dist/dmarc_viewer.dist" + `suffix`.
*/
function _create_dist(src_paths, minifier, suffix) {
return gulp.src(src_paths)
.pipe(minifier())
.pipe(gulpConcat('dmarc_viewer.dist' + suffix))
.pipe(gulp.dest('website/static/dist'));
}
/*
* Tasks to minify and concatenate third party and non-third party
* CSS and JS, copying them to `static/dist`.
* Note: Requires dependencies installed in `node_modules`.
*/
gulp.task('create-dist-js', function(){
return _create_dist(paths.js, gulpUglifyJs,'.js')
});
gulp.task('create-dist-css', function(){
return _create_dist(paths.css, gulpCleanCss, '.css')
});
// TODO: Do we need source maps for third party code? Might be nice
// for debugging
gulp.task('create-dist-js-node-modules', function(){
return _create_dist(paths.js_node_modules, gulpUglifyJs, '.npm.js')
});
gulp.task('create-dist-css-node-modules', function(){
return _create_dist(paths.css_node_modules, gulpCleanCss, '.npm.css')
});
/*
* Task to copy Bootstraps fonts from `node_modules` to `static/fonts`
*/
gulp.task('copy-fonts', function() {
return gulp.src(paths.fonts_node_modules)
.pipe(gulp.dest('website/static/fonts/'));
});
/*
* Copies 3rd party and non-3rd party css, js and fonts to dist.
* Note: This does not compile scss, so make sure to run the `compile-scss`
* task first if you have changed any scss files and want them in the minified
* dist.
*/
gulp.task('create-dist', [
'copy-fonts',
'create-dist-js-node-modules',
'create-dist-css-node-modules',
'create-dist-js',
'create-dist-css'
]
);
/*
* Task to compile SCSS files and copy it to `static/css` (with sourcemap).
* Note: `includePaths` define 3rd party SCSS files that are included (by name)
* in the main scss file that gets compiled.
*/
gulp.task('compile-scss', function() {
return gulp.src(paths.scss)
.pipe(gulpSourceMaps.init())
.pipe(gulpSass({
errLogToConsole: true,
outputStyle: 'expanded',
includePaths: paths.scss_node_modules,
}).on('error', gulpSass.logError))
.pipe(gulpSourceMaps.write('.'))
.pipe(gulp.dest('website/static/css'))
});
/*
* Watcher task to compile to SCSS to CSS if the main SCSS file changes
*/
gulp.task('watch-scss', function() {
return gulp.watch(paths.scss, ['compile-scss'])
});