2 //FIXME in VSC/eslint or add to typings declare function require(v: string): any;
4 // FIXME: Rework based on
5 // https://github.com/iotbzh/app-framework-templates/blob/master/templates/hybrid-html5/gulpfile.js
7 // https://github.com/antonybudianto/angular-starter
9 // https://github.com/smmorneau/tour-of-heroes/blob/master/gulpfile.js
11 const gulp = require("gulp"),
12 gulpif = require('gulp-if'),
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');
23 var tslintJsonFile = "./tslint.json"
25 tslintJsonFile = "./tslint.prod.json"
30 * Remove output directory.
32 gulp.task('clean', (cb) => {
33 return del([conf.outDir], cb);
37 * Lint all custom TypeScript files.
39 gulp.task('tslint', function() {
40 return gulp.src(conf.paths.tsSources)
43 configuration: tslintJsonFile
45 .pipe(tslint.report());
49 * Compile TypeScript sources and create sourcemaps in build directory.
51 gulp.task("compile", ["tslint"], function() {
52 var tsResult = gulp.src(conf.paths.tsSources)
53 .pipe(sourcemaps.init())
56 .pipe(sourcemaps.write(".", { sourceRoot: '/src' }))
57 .pipe(gulp.dest(conf.outDir));
61 * Copy all resources that are not TypeScript files into build directory.
63 gulp.task("resources", function() {
64 return gulp.src(["src/**/*", "!**/*.ts"])
65 .pipe(gulp.dest(conf.outDir));
69 * Copy all assets into build directory.
71 gulp.task("assets", function() {
72 return gulp.src(conf.paths.assets)
73 .pipe(gulp.dest(conf.outDir + "/assets"));
77 * Copy all required libraries into build directory.
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"));
86 * Watch for changes in TypeScript, HTML and CSS files.
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.');
92 gulp.watch(["src/**/*.html", "src/**/*.css"], ['resources']).on('change', function (e) {
93 console.log('Resource file ' + e.path + ' has been changed. Updating.');
100 gulp.task("build", ['compile', 'resources', 'libs', 'assets'], function() {
101 console.log("Building the project ...");
105 * Deploy the project on another machine/container
107 gulp.task('rsync', function () {
108 return gulp.src(conf.outDir)
111 username: conf.deploy.username,
112 hostname: conf.deploy.target_ip,
113 port: conf.deploy.port || null,
119 destination: conf.deploy.dir
123 gulp.task('deploy', gulpSequence('build', 'rsync'));