-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathgulpfile.js
162 lines (148 loc) · 4.92 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
// GULPFILE
// - - - - - - - - - - - - - - -
// This file processes all of the assets in the "src" folder
// and outputs the finished files in the "dist" folder.
// 1. LIBRARIES
// - - - - - - - - - - - - - - -
const { src, pipe, dest, series, parallel, watch } = require("gulp");
const plugins = {};
plugins.addSrc = require("gulp-add-src");
plugins.babel = require("gulp-babel");
plugins.base64 = require("gulp-base64-inline");
plugins.concat = require("gulp-concat");
plugins.faMinify = require("gulp-fa-minify");
plugins.jshint = require("gulp-jshint");
plugins.prettyerror = require("gulp-prettyerror");
plugins.rename = require("gulp-rename");
//plugins.uglify = require("gulp-uglify");
// 2. CONFIGURATION
// - - - - - - - - - - - - - - -
const paths = {
src: "app/assets/",
dist: "app/static/",
templates: "app/templates/",
npm: "node_modules/",
toolkit: "node_modules/govuk_frontend_toolkit/",
};
// 3. TASKS
// - - - - - - - - - - - - - - -
// Move GOV.UK template resources
const javascripts = () => {
return src([
paths.toolkit + "javascripts/govuk/modules.js",
paths.toolkit + "javascripts/govuk/show-hide-content.js",
paths.src + "javascripts/utils.js",
paths.src + "javascripts/webpackLoader.js",
paths.src + "javascripts/stick-to-window-when-scrolling.js",
paths.src + "javascripts/detailsPolyfill.js",
paths.src + "javascripts/apiKey.js",
paths.src + "javascripts/cbor.js",
paths.src + "javascripts/fido2.js",
paths.src + "javascripts/autocomplete.js",
paths.src + "javascripts/autofocus.js",
paths.src + "javascripts/highlightTags.js",
paths.src + "javascripts/fileUpload.js",
paths.src + "javascripts/button.js",
paths.src + "javascripts/updateContent.js",
paths.src + "javascripts/listEntry.js",
paths.src + "javascripts/liveSearch.js",
paths.src + "javascripts/preventDuplicateFormSubmissions.js",
paths.src + "javascripts/fullscreenTable.js",
paths.src + "javascripts/previewPane.js",
paths.src + "javascripts/colourPreview.js",
paths.src + "javascripts/templateFolderForm.js",
paths.src + "javascripts/collapsibleCheckboxes.js",
paths.src + "javascripts/moreMenu.js",
paths.src + "javascripts/menu.js",
paths.src + "javascripts/scopeTabNavigation.js",
paths.src + "javascripts/url-typer.js",
paths.src + "javascripts/notificationsReports.js",
paths.src + "javascripts/main.js",
paths.src + "javascripts/templateCategories.js",
paths.src + "javascripts/templateContent.js",
])
.pipe(plugins.prettyerror())
.pipe(
plugins.babel({
presets: ["@babel/preset-env"],
})
)
.pipe(
plugins.addSrc.prepend([
//paths.src + 'javascripts/main.min.js',
paths.npm + "hogan.js/dist/hogan-3.0.2.js",
paths.npm + "jquery/dist/jquery.min.js",
paths.npm + "jquery-migrate/dist/jquery-migrate.min.js",
paths.npm + "query-command-supported/dist/queryCommandSupported.min.js",
//paths.npm + "diff-dom/diffDOM.js",
paths.npm + "textarea-caret/index.js",
paths.npm +
"accessible-autocomplete/dist/accessible-autocomplete.min.js",
])
)
//.pipe(plugins.uglify())
.pipe(plugins.concat("all.min.js"))
.pipe(
plugins.addSrc.prepend([
paths.src + "javascripts/main.min.js",
paths.src + "javascripts/scheduler.min.js",
paths.src + "javascripts/branding_request.min.js",
paths.src + "javascripts/formValidateRequired.min.js",
paths.src + "javascripts/sessionRedirect.min.js",
paths.src + "javascripts/touDialog.min.js",
paths.src + "javascripts/templateFilters.min.js",
])
)
.pipe(dest(paths.dist + "javascripts/"));
};
// copy static css
const static_css = () => {
return src(paths.src + "/stylesheets/index.css")
.pipe(
plugins.addSrc.prepend([
paths.npm + "accessible-autocomplete/dist/accessible-autocomplete.min.css",
paths.src + "stylesheets/fa-svg-with-js.css",
])
)
.pipe(plugins.concat("index.css"))
.pipe(
dest(paths.dist + "stylesheets/")
);
};
// Copy images
const images = () => {
return src([
paths.toolkit + "images/**/*",
paths.template + "assets/images/**/*",
paths.src + "images/**/*",
]).pipe(dest(paths.dist + "images/"));
};
const watchFiles = {
javascripts: (cb) => {
watch([paths.src + "javascripts/**/*"], javascripts);
cb();
},
images: (cb) => {
watch([paths.src + "images/**/*"], images);
cb();
},
self: (cb) => {
watch(["gulpfile.js"], defaultTask);
cb();
},
};
// Default: compile everything
const defaultTask = parallel(
series(javascripts),
series(images),
series(static_css),
);
// Watch for changes and re-run tasks
const watchForChanges = parallel(
watchFiles.javascripts,
watchFiles.images,
watchFiles.self
);
exports.default = defaultTask;
// Optional: recompile on changes
exports.watch = series(defaultTask, watchForChanges);