forked from OctopusDeploy/Library
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.babel.js
422 lines (385 loc) · 12.2 KB
/
gulpfile.babel.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
"use strict";
import gulp from "gulp";
import log from "fancy-log";
import gulpLoadPlugins from "gulp-load-plugins";
import browserSync from "browser-sync";
import LiveServer from "gulp-live-server";
import gulpSass from "gulp-sass";
import dartSass from "sass";
import concat from "gulp-concat";
import insert from "gulp-insert";
import del from "del";
import source from "vinyl-source-stream";
import buffer from "vinyl-buffer";
import babelify from "babelify";
import reactify from "reactify";
import browserify from "browserify";
import uglify from "gulp-uglify-es";
import postcss from "gulp-postcss";
import cssnano from "cssnano";
import rename from "gulp-rename";
import sourcemaps from "gulp-sourcemaps";
import inject from "gulp-inject";
import yargs from "yargs";
import rev from "gulp-rev";
import glob from "glob";
import envify from "envify/custom";
import jasmine from "gulp-jasmine";
import jasmineReporters from "jasmine-reporters";
import jasmineTerminalReporter from "jasmine-terminal-reporter";
import eventStream from "event-stream";
import fs from "fs";
import jsonlint from "gulp-jsonlint";
const sass = gulpSass(dartSass);
const clientDir = "app";
const serverDir = "server";
const buildDir = "build";
const publishDir = "dist";
const $ = gulpLoadPlugins({
rename: {
"gulp-expect-file": "expect",
},
});
const reload = browserSync.reload;
const argv = yargs.argv;
const vendorStyles = [
"node_modules/font-awesome/css/font-awesome.min.css",
"node_modules/font-awesome/css/font-awesome.css.map",
"node_modules/font-awesome/fonts/fontawesome*{.eot,.svg,.ttf,.woff,.woff2,.otf}",
"node_modules/normalize.css/normalize.css",
];
gulp.task("clean", () => {
return del([`${publishDir}`, `${buildDir}`, `${clientDir}/data/*.json`]);
});
function lint(files, options = {}) {
return () => {
return gulp
.src(files)
.pipe(reload({ stream: true, once: true }))
.pipe($.eslint(options))
.pipe($.eslint.format("compact"))
.pipe($.if(!browserSync.active, $.eslint.failOnError()));
};
}
gulp.task("lint:client", lint(`${clientDir}/**/*.jsx`));
gulp.task("lint:server", lint(`./${serverDir}/server.js`));
gulp.task("lint:step-templates", () => {
return gulp
.src("./step-templates/*.json")
.pipe($.expect({ errorOnFailure: true, silent: true }, glob.sync("step-templates/*.json")))
.pipe(jsonlint())
.pipe(jsonlint.failOnError())
.pipe(jsonlint.reporter());
});
gulp.task(
"tests",
gulp.series("lint:step-templates", () => {
return (
gulp
.src("./spec/*-tests.js")
// gulp-jasmine works on filepaths so you can't have any plugins before it
.pipe(
jasmine({
includeStackTrace: false,
reporter: [new jasmineReporters.JUnitXmlReporter(), process.env.TEAMCITY_VERSION ? new jasmineReporters.TeamCityReporter() : new jasmineTerminalReporter()],
})
)
.on("error", function () {
process.exit(1);
})
);
})
);
function humanize(categoryId) {
switch (categoryId) {
case "amazon-chime":
return "Amazon Chime";
case "ansible":
return "Ansible";
case "apexsql":
return "ApexSQL";
case "aspnet":
return "ASP.NET";
case "aws":
return "AWS";
case "azure-devops":
return "Azure DevOps";
case "azure-keyvault":
return "Azure Key Vault";
case "azure-site-extensions":
return "Azure Site Extensions";
case "azureFunctions":
return "Azure Functions";
case "cassandra":
return "Cassandra";
case "chef":
return "Chef";
case "clickonce":
return "ClickOnce";
case "cyberark":
return "CyberArk";
case "dll":
return "dll";
case "dlm":
return "dlm";
case "dotnetcore":
return ".NET Core";
case "edgecast":
return "EdgeCast";
case "elmah":
return "ELMAH";
case "entityframework":
return "Entity Framework";
case "event-tracing":
return "Event Tracing for Windows";
case "filesystem":
return "File System";
case "firebase":
return "Firebase";
case "flyway":
return "Flyway";
case "ghostinspector":
return "Ghost Inspector";
case "github":
return "GitHub";
case "gitlab":
return "GitLab";
case "google-cloud":
return "Google Cloud";
case "grate":
return "Grate";
case "hashicorp-vault":
return "HashiCorp Vault";
case "hipchat":
return "HipChat";
case "hockeyapp":
return "HockeyApp";
case "hosts-file":
return " Hosts File";
case "http":
return "HTTP";
case "iis":
return "IIS";
case "jira":
return "JIRA";
case "json":
return "JSON";
case "jwt":
return "JWT";
case "k8s":
return "Kubernetes";
case "keeper-secretsmanager":
return "Keeper Secrets Manager";
case "launchdarkly":
return "LaunchDarkly";
case "lets-encrypt":
return "Lets Encrypt";
case "linux":
return "Linux";
case "liquibase":
return "Liquibase";
case "mabl":
return "mabl";
case "mariadb":
return "MariaDB";
case "microsoft-teams":
return "Microsoft Teams";
case "mongodb":
return "MongoDB";
case "mysql":
return "MySQL";
case "netscaler":
return "NetScaler";
case "newrelic":
return "New Relic";
case "nunit":
return "NUnit";
case "opslevel":
return "OpsLevel";
case "pagerduty":
return "PagerDuty";
case "postgresql":
return "PostgreSQL";
case "pulumi":
return "Pulumi";
case "rabbitmq":
return "RabbitMQ";
case "ravendb":
return "RavenDB";
case "readyroll":
return "ReadyRoll";
case "redgate":
return "Redgate";
case "roundhouse":
return "RoundhousE";
case "sharepoint":
return "SharePoint";
case "snowflake":
return "Snowflake";
case "solarwinds":
return "SolarWinds";
case "sql":
return "SQL Server";
case "ssl":
return "SSL";
case "statuspage":
return "StatusPage";
case "swaggerhub":
return "SwaggerHub";
case "statuscake":
return "StatusCake";
case "teamcity":
return "TeamCity";
case "terraform":
return "Terraform";
case "testery":
return "Testery";
case "tomcat":
return "Tomcat";
case "twilio":
return "Twilio";
case "victorops":
return "VictorOps";
case "webdeploy":
return "Web Deploy";
case "xml":
return "XML";
case "xunit":
return "xUnit";
case "databricks":
return "Databricks";
case "rnhub":
return "RnHub";
case "venafi":
return "Venafi";
case "proxmox":
return "Proxmox";
default:
return categoryId[0].toUpperCase() + categoryId.substr(1).toLowerCase();
}
}
function provideMissingData() {
return eventStream.map(function (file, cb) {
var fileContent = file.contents.toString();
var template = JSON.parse(fileContent);
var pathParts = file.path.split("\\");
var fileName = pathParts[pathParts.length - 1];
if (!template.HistoryUrl) {
template.HistoryUrl = "https://github.com/OctopusDeploy/Library/commits/master/step-templates/" + fileName;
}
if (!template.Website) {
template.Website = "/step-templates/" + template.Id;
}
var categoryId = template.Category;
if (!categoryId) {
categoryId = "other";
}
categoryId = categoryId.toLowerCase();
template.Category = humanize(categoryId);
if (!template.Logo) {
var logo = fs.readFileSync("./step-templates/logos/" + categoryId + ".png");
template.Logo = Buffer.from(logo).toString("base64");
}
file.contents = Buffer.from(JSON.stringify(template));
cb(null, file);
});
}
gulp.task(
"step-templates",
gulp.series("tests", () => {
return gulp
.src("./step-templates/*.json")
.pipe(provideMissingData())
.pipe(concat("step-templates.json", { newLine: "," }))
.pipe(insert.wrap('{"items": [', "]}"))
.pipe(argv.production ? gulp.dest(`${publishDir}/app/services`) : gulp.dest(`${buildDir}/app/services`));
})
);
gulp.task("styles:vendor", () => {
return gulp.src(vendorStyles, { base: "node_modules/" }).pipe(argv.production ? gulp.dest(`${publishDir}/public/styles/vendor`) : gulp.dest(`${buildDir}/public/styles/vendor`));
});
gulp.task("styles:client", () => {
let postCssPlugins = [cssnano];
return gulp
.src(`${clientDir}/content/styles/main.scss`)
.pipe(sass().on("error", sass.logError))
.pipe($.if(argv.production, sourcemaps.init({ loadMaps: true })))
.pipe($.if(argv.production, postcss(postCssPlugins)))
.on("error", log.error)
.pipe($.if(argv.production, rename({ suffix: ".min" })))
.pipe($.if(argv.production, rev()))
.pipe($.if(argv.production, sourcemaps.write(".")))
.pipe(argv.production ? gulp.dest(`${publishDir}/public/styles`) : gulp.dest(`${buildDir}/public/styles`));
});
gulp.task("images", () => {
return gulp.src(`${clientDir}/content/images/**/*{.png,.gif,.jpeg,.jpg,.bmp}`).pipe(argv.production ? gulp.dest(`${publishDir}/public/images`) : gulp.dest(`${buildDir}/public/images`));
});
gulp.task("copy:app", () => {
return gulp.src(`${clientDir}/**/*{.jsx,.js}`).pipe(argv.production ? gulp.dest(`${publishDir}/app`) : gulp.dest(`${buildDir}/app`));
});
gulp.task("copy:configs", () => {
return gulp.src(["./package.json", "./package-lock.json", "./web.config", "./IISNode.yml"]).pipe(argv.production ? gulp.dest(`${publishDir}`) : gulp.dest(`${buildDir}`));
});
gulp.task(
"scripts",
gulp.series("lint:client", () => {
return browserify({
entries: `./${clientDir}/Browser.jsx`,
extensions: [".jsx", ".js"],
debug: true,
})
.transform(babelify)
.transform(reactify)
.transform(envify({ _: "purge", NODE_ENV: argv.production ? "production" : "development" }), { global: true })
.bundle()
.pipe(source("app.js"))
.pipe(buffer())
.pipe($.if(argv.production, sourcemaps.init({ loadMaps: true })))
.pipe($.if(argv.production, uglify()))
.on("error", log.error)
.pipe($.if(argv.production, rename({ suffix: ".min" })))
.pipe($.if(argv.production, rev()))
.pipe($.if(argv.production, sourcemaps.write(".")))
.pipe(argv.production ? gulp.dest(`${publishDir}/public/scripts`) : gulp.dest(`${buildDir}/public/scripts`));
})
);
gulp.task(
"build:client",
gulp.series("step-templates", "copy:app", "scripts", "styles:client", "styles:vendor", "images", () => {
let vendorSources = gulp.src(vendorStyles, { base: "node_modules/" });
let sources = argv.production
? gulp.src([`${publishDir}/public/**/*.js`, `${publishDir}/public/**/*.css*`, `!${publishDir}/public/**/vendor{,/**}`], { read: false })
: gulp.src([`${buildDir}/public/**/*.js`, `${buildDir}/public/**/*.css*`, `!${buildDir}/public/**/vendor{,/**}`], { read: false });
return gulp
.src(`${serverDir}/views/index.pug`)
.pipe(inject(vendorSources, { relative: false, name: "vendor", ignorePath: "node_modules", addPrefix: "styles/vendor" }))
.pipe(inject(sources, { relative: false, ignorePath: `${argv.production ? `${publishDir}` : `${buildDir}`}/public` }))
.pipe(argv.production ? gulp.dest(`${publishDir}/views`) : gulp.dest(`${buildDir}/views`));
})
);
gulp.task(
"build:server",
gulp.series("lint:server", () => {
return gulp
.src([`./${serverDir}/server.js`])
.pipe($.babel())
.pipe(argv.production ? gulp.dest(`${publishDir}`) : gulp.dest(`${buildDir}`));
})
);
gulp.task("build", gulp.parallel("build:server", "build:client", "copy:configs"));
gulp.task(
"watch",
gulp.series("clean", "build", () => {
let server = LiveServer(`${buildDir}/server.js`);
server.start();
browserSync.init(null, {
proxy: "http://localhost:9000",
});
gulp.watch(`${clientDir}/**/*.jade`, gulp.series("build:client"));
gulp.watch(`${clientDir}/**/*.jsx`, gulp.series("scripts", "copy:app"));
gulp.watch(`${clientDir}/content/styles/**/*.scss`, gulp.series("styles:client"));
gulp.watch("step-templates/*.json", gulp.series("step-templates"));
gulp.watch(`${buildDir}/**/*.*`).on("change", reload);
})
);
gulp.task("default", gulp.series("clean", "build"));