summaryrefslogtreecommitdiff
path: root/gulpfile.js
blob: 612decf66756f296c235ce394121a7c0196088ba (plain)
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
'use strict';

const gulp = require('gulp');
const notify = require('gulp-notify');
const source = require('vinyl-source-stream');
const es = require('event-stream');
const less = require('gulp-less');
const browserify = require('browserify');
const tsify = require('tsify');
const gulpTypings = require("gulp-typings");
const rename = require('gulp-rename');
const processHTML = require('gulp-processhtml');
const del = require('del');
const bower = require('gulp-bower');


/**
 * STYLES
 */
const stylesRootDir = './src/styles/';
const stylesDestDir = './build/styles/';

const styleFileNames = ['main', 'splash', 'projects', 'profile', 'navbar', '404'];
const styleFilePaths = styleFileNames.map(function (fileName) {
    return stylesRootDir + fileName + '.less';
});

gulp.task('styles', function () {
    return gulp.src(styleFilePaths)
        .pipe(less())
        .pipe(gulp.dest(stylesDestDir))
        .pipe(notify({message: 'Styles task complete', onLast: true}));
});


/**
 * SCRIPTS
 */
const scriptsRootDir = './src/scripts/';
const scriptsDestDir = './build/scripts/';

const postfix = '.entry';
const scriptsFileNames = ['splash', 'main', 'projects', 'profile', 'error404'];
const scriptsFilePaths = scriptsFileNames.map(function (fileName) {
    return scriptsRootDir + fileName + postfix + '.ts';
});

gulp.task('scripts', function () {
    var tasks = scriptsFilePaths.map(function (entry, index) {
        return browserify({entries: [entry]})
            .plugin(tsify, {insertGlobals: true})
            .bundle()
            .pipe(source(scriptsFileNames[index] + postfix + '.js'))
            .pipe(gulp.dest(scriptsDestDir));
    });
    return es.merge.apply(null, tasks)
        .pipe(notify({message: 'Scripts task complete', onLast: true}));
});


/**
 * TYPESCRIPT DEFINITIONS
 */
gulp.task("typings", function () {
    return gulp.src("./typings.json")
        .pipe(gulpTypings())
        .pipe(notify({message: 'Typings task complete'}));
});


/**
 * HTML
 */
const htmlRootDir = './src/';
const htmlDestDir = './build/';

const htmlFileNames = ['index', 'app', 'projects', 'profile', '404'];
const htmlFilePaths = htmlFileNames.map(function (fileName) {
    return htmlRootDir + fileName + '.html';
});

gulp.task('html', function () {
    return gulp.src(htmlFilePaths)
        .pipe(processHTML())
        .pipe(gulp.dest(htmlDestDir))
        .pipe(notify({message: 'HTML task complete', onLast: true}));
});


/**
 * IMAGES
 */
const imagesRootDir = './src/img/';
const imagesDestDir = './build/img/';

const imagesFilePaths = [imagesRootDir + '**/*.png', imagesRootDir + '**/*.gif'];

gulp.task('images', function () {
    return gulp.src(imagesFilePaths)
        .pipe(gulp.dest(imagesDestDir))
        .pipe(notify({message: 'Images task complete', onLast: true}));
});


/**
 * CLEAN
 */
gulp.task('clean', function () {
    return del(['./build']);
});


/**
 * BOWER
 */
gulp.task('bower', function () {
    return bower({cmd: 'install'}, ['--allow-root'])
        .pipe(notify({message: 'Bower task complete', onLast: true}));
});


/**
 * DEFAULT TASK
 */
gulp.task('default', ['clean', 'typings'], function () {
    gulp.start('styles', 'bower', 'scripts', 'html', 'images');
});


/**
 * WATCH
 */
gulp.task('watch', ['default'], function () {
    gulp.watch(stylesRootDir + '**/*.less', ['styles']);
    gulp.watch(scriptsRootDir + '**/*.ts', ['scripts']);
    gulp.watch(htmlRootDir + '**/*.html', ['html']);
    gulp.watch(imagesRootDir + '**/*.png', ['images']);
});