Added events decoder helpers.
[src/xds/xds-agent.git] / webapp / gulpfile.js
1 "use strict";
2 //FIXME in VSC/eslint or add to typings declare function require(v: string): any;
3
4 // FIXME: Rework based on
5 //   https://github.com/iotbzh/app-framework-templates/blob/master/templates/hybrid-html5/gulpfile.js
6 // AND
7 //   https://github.com/antonybudianto/angular-starter
8 // and/or
9 //   https://github.com/smmorneau/tour-of-heroes/blob/master/gulpfile.js
10
11 const gulp = require("gulp"),
12     gulpif = require('gulp-if'),
13     del = require("del"),
14     sourcemaps = require('gulp-sourcemaps'),
15     tsc = require("gulp-typescript"),
16     tsProject = tsc.createProject("tsconfig.json"),
17     tslint = require('gulp-tslint'),
18     gulpSequence = require('gulp-sequence'),
19     rsync = require('gulp-rsync'),
20     conf = require('./gulp.conf');
21
22
23 var tslintJsonFile = "./tslint.json"
24 if (conf.prodMode) {
25     tslintJsonFile = "./tslint.prod.json"
26 }
27
28
29 /**
30  * Remove output directory.
31  */
32 gulp.task('clean', (cb) => {
33     return del([conf.outDir], cb);
34 });
35
36 /**
37  * Lint all custom TypeScript files.
38  */
39 gulp.task('tslint', function() {
40     return gulp.src(conf.paths.tsSources)
41         .pipe(tslint({
42             formatter: 'verbose',
43             configuration: tslintJsonFile
44         }))
45         .pipe(tslint.report());
46 });
47
48 /**
49  * Compile TypeScript sources and create sourcemaps in build directory.
50  */
51 gulp.task("compile", ["tslint"], function() {
52     var tsResult = gulp.src(conf.paths.tsSources)
53         .pipe(sourcemaps.init())
54         .pipe(tsProject());
55     return tsResult.js
56         .pipe(sourcemaps.write(".", { sourceRoot: '/src' }))
57         .pipe(gulp.dest(conf.outDir));
58 });
59
60 /**
61  * Copy all resources that are not TypeScript files into build directory.
62  */
63 gulp.task("resources", function() {
64     return gulp.src(["src/**/*", "!**/*.ts"])
65         .pipe(gulp.dest(conf.outDir));
66 });
67
68 /**
69  * Copy all assets into build directory.
70  */
71 gulp.task("assets", function() {
72     return gulp.src(conf.paths.assets)
73         .pipe(gulp.dest(conf.outDir + "/assets"));
74 });
75
76 /**
77  * Copy all required libraries into build directory.
78  */
79 gulp.task("libs", function() {
80     return gulp.src(conf.paths.node_modules_libs,
81         { cwd: "node_modules/**" })    /* Glob required here. */
82         .pipe(gulp.dest(conf.outDir + "/lib"));
83 });
84
85 /**
86  * Watch for changes in TypeScript, HTML and CSS files.
87  */
88 gulp.task('watch', function () {
89     gulp.watch([conf.paths.tsSources], ['compile']).on('change', function (e) {
90         console.log('TypeScript file ' + e.path + ' has been changed. Compiling.');
91     });
92     gulp.watch(["src/**/*.html", "src/**/*.css"], ['resources']).on('change', function (e) {
93         console.log('Resource file ' + e.path + ' has been changed. Updating.');
94     });
95 });
96
97 /**
98  * Build the project.
99  */
100 gulp.task("build", ['compile', 'resources', 'libs', 'assets'], function() {
101     console.log("Building the project ...");
102 });
103
104 /**
105  * Deploy the project on another machine/container
106  */
107 gulp.task('rsync', function () {
108     return gulp.src(conf.outDir)
109         .pipe(rsync({
110             root: conf.outDir,
111             username: conf.deploy.username,
112             hostname: conf.deploy.target_ip,
113             port: conf.deploy.port || null,
114             archive: true,
115             recursive: true,
116             compress: true,
117             progress: false,
118             incremental: true,
119             destination: conf.deploy.dir
120         }));
121 });
122
123 gulp.task('deploy', gulpSequence('build', 'rsync'));