This repository was archived by the owner on Mar 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.js
More file actions
258 lines (213 loc) · 6.32 KB
/
gulpfile.js
File metadata and controls
258 lines (213 loc) · 6.32 KB
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
const babel = require('gulp-babel');
const del = require('del');
const { src, dest, watch, series, parallel } = require('gulp');
const minifyCSS = require('gulp-clean-css');
const eslint = require('gulp-eslint');
const ghPages = require('gulp-gh-pages');
const postcss = require('gulp-postcss');
const rename = require("gulp-rename");
const sass = require('gulp-sass')(require('sass'));
const sitemap = require('gulp-sitemap');
const stylelint = require('gulp-stylelint');
const fractal = require('./fractal.js');
const { spawn } = require('child_process');
// Public Tasks:
exports.default = parallel(series(copyfonts, copyimages, sasswatch, fractalstart, watcher), jswatch);
exports.build = series(clean, copyfonts, copyimages, sassbuild, scsslint, jslint, jsbuild, fractalbuild, copyassets);
exports.deploy = series(clean, copyfonts, copyimages, sassbuild, scsslint, jslint, jsbuild, fractalbuild, copyassets, githubpages);
exports.test = series(settestenvironment, clean, copyfonts, copyimages, sassbuild, scsslint, jslint, jsbuild, fractalbuild, copyassets, makesitemap, startserver, runa11y, runpercy, stopserver, setdevenvironment);
exports.updatelocal = series(pushassetslocal);
exports.updatedev = series(pushassetsdev, gitpulldev);
exports.updatestage = series(pushassetsstage, gitpullstage);
exports.updateprod = series(pushassetsprod, gitpullprod);
// Fractal to Gulp Integration:
const logger = fractal.cli.console; // keep a reference to the fractal CLI console utility
function fractalstart() {
const server = fractal.web.server({
sync: true
});
server.on('error', err => logger.error(err.message));
return server.start().then(() => {
logger.success(`Fractal now running`);
});
}
function fractalbuild(cb) {
const builder = fractal.web.builder();
builder.on('progress', (completed, total) => logger.update(`Exported ${completed} of ${total} items`, 'info'));
builder.on('error', err => logger.error(err.message));
return builder.build().then(() => {
logger.success('Fractal build completed');
})
cb();
}
// General Tasks:
async function startserver() {
return spawn('npm run starttestserver', {
stdio: 'inherit',
shell: true
});
}
async function stopserver() {
return spawn('npm run stoptestserver', {
stdio: 'inherit',
shell: true
});
}
async function setdevenvironment() {
return process.env.NODE_ENV = 'development';
}
async function settestenvironment() {
return process.env.NODE_ENV = 'testing';
}
function clean(cb) {
return del(['./dist/**', './ui-assets/**'])
cb();
}
function copyfonts() {
return spawn('npm run copy-fonts', {
stdio: 'inherit',
shell: true
});
}
function watcher(cb) {
watch('./scss/*.scss', parallel(series(sasswatch), scsslint));
watch('./js/*.js', series(jslint));
cb();
}
function sasswatch(cb) {
return src('./scss/*.scss', { sourcemaps: true })
.pipe(sass().on('error', sass.logError))
.pipe(postcss())
.pipe(dest('./ui-assets/css', { sourcemaps: 'sourcemaps' }))
cb();
}
function sassbuild(cb) {
return src('./scss/*.scss')
.pipe(sass().on('error', sass.logError))
.pipe(postcss())
.pipe(minifyCSS())
.pipe(dest('./ui-assets/css'))
cb();
}
function criticalcss(cb) {
return src('./ui-assets/css/critical.css')
.pipe(rename('_criticalcss.hbs'))
.pipe(dest('./elements/'))
cb();
}
function scsslint(cb) {
return src('./scss/*.scss')
.pipe(stylelint({
reporters: [
{formatter: 'string', console: true}
]
}));
cb();
}
function jslint(cb) {
return src(['./js/*.js'])
.pipe(eslint())
.pipe(eslint.format())
cb();
}
async function jswatch(cb) {
return spawn('npm run parcel-watch --silent', {
stdio: 'inherit',
shell: true
});
}
async function jsbuild(cb) {
return spawn('npm run parcel-build --silent', {
stdio: 'inherit',
shell: true
});
}
async function copyimages(cb) {
return spawn('npm run copy-images', {
stdio: 'inherit',
shell: true
});
}
// Fractal build process should copy everything in /ui-assets to /dist/ui-assets, but some things are getting left out, so we do it again as a separate task:
async function copyassets(cb) {
return spawn('npm run copy-assets', {
stdio: 'inherit',
shell: true
});
}
function githubpages(cb) {
return src('./dist/**/*')
.pipe(ghPages())
cb();
}
function runpercy(cb) {
return spawn('npm run percy', {
stdio: 'inherit',
shell: true
});
cb();
}
function runa11y() {
return spawn('npm run a11y', {
stdio: 'inherit',
shell: true
});
}
function makesitemap() {
return src('./dist/components/preview/*.html')
.pipe(sitemap({
siteUrl: 'http://localhost:8080/components/preview',
noindex: true
}))
.pipe(dest('./dist'))
}
// Rsync Tasks:
function pullassetsdev() {
return spawn('rsync -rvu cdlib@web-cdlib2x2-dev.cdlib.org:/apps/cdlib/apache/htdocs/wp-content/themes/cdlib/ui-assets ./', {
stdio: 'inherit',
shell: true
});
}
function pushassetslocal() {
return spawn("rsync -rvu --delete --exclude \'.DS_Store\' ./dist/ui-assets ~/'Local Sites'/cdlib/app/public/wp-content/themes/cdlib", {
stdio: 'inherit',
shell: true
});
}
function pushassetsdev() {
return spawn('rsync -rvu --delete --exclude \'.DS_Store\' ./dist/ui-assets cdlib@web-cdlib2x2-dev.cdlib.org:/apps/cdlib/apache/htdocs/wp-content/themes/cdlib', {
stdio: 'inherit',
shell: true
});
}
function pushassetsstage() {
return spawn('rsync -rvu --delete --exclude \'.DS_Store\' ./dist/ui-assets cdlib@web-cdlib2x2-stg-2a.cdlib.org:/apps/cdlib/apache/htdocs/wp-content/themes/cdlib', {
stdio: 'inherit',
shell: true
});
}
function pushassetsprod() {
return spawn('rsync -rvu --delete --exclude \'.DS_Store\' ./dist/ui-assets cdlib@web-cdlib2x2-prd-2a.cdlib.org:/apps/cdlib/apache/htdocs/wp-content/themes/cdlib', {
stdio: 'inherit',
shell: true
});
}
// // Server Git Pull Shell Tasks
function gitpulldev() {
return spawn('ssh cdlib@web-cdlib2x2-dev.cdlib.org /apps/cdlib/bin/remote_git_pull_dev.sh', {
stdio: 'inherit',
shell: true
});
}
function gitpullstage() {
return spawn('ssh cdlib@web-cdlib2x2-stg-2a.cdlib.org /apps/cdlib/bin/remote_git_pull_stg.sh', {
stdio: 'inherit',
shell: true
});
}
function gitpullprod() {
return spawn('ssh cdlib@web-cdlib2x2-prd-2a.cdlib.org /apps/cdlib/bin/remote_git_pull_prd.sh', {
stdio: 'inherit',
shell: true
});
}