-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
153 lines (123 loc) · 4.18 KB
/
gulpfile.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
const gulp = require('gulp');
const runSequence = require('run-sequence');
const del = require('del');
const rename = require('gulp-rename');
const nodemon = require('gulp-nodemon');
const sourcemaps = require('gulp-sourcemaps');
const run = require('child_process').exec;
const spawn = require('win-spawn');
const exec = require('gulp-exec');
const sass = require('gulp-sass');
const browserSync = require('browser-sync').create();
// SCRIPT START
const sassInput = './client/**/*.scss';
const sassOutput = './bin/client/';
const args = [];
(function initParams() {
process.argv.forEach(arg => {
const getParamsInfo = /-([a-zA-Z\-]+):([a-zA-Z0-9]+)/g;
const result = getParamsInfo.exec(arg);
if (result) {
args.push(`-${result[1]}:${result[2]}`)
}
});
})();
function buildTypescript(tsConfigPath, binPath, cb) {
return gulp.src('').pipe(exec('tsc -p ' + tsConfigPath));
}
let deleteReleaseBinFolder = true;
gulp.task('copyHtml', () => {
return gulp.src('client/**/*.html')
.pipe(gulp.dest('bin/client/'));
});
// ************** DEV ****************/
gulp.task('build:dev', ['copyHtml', 'sass:dev'], (cb) => {
return buildTypescript('tsconfig.dev.json', 'bin');
});
gulp.task('sass:dev', function () {
const sassOptions = {
errLogToConsole: true,
outputStyle: 'expanded'
};
return gulp
// Find all `.scss` files from the `input` folder
.src(sassInput)
// Run Sass on those files
.pipe(sourcemaps.init())
.pipe(sass(sassOptions).on('error', sass.logError))
.pipe(sourcemaps.write('./'))
// Write the resulting CSS in the output folder
.pipe(gulp.dest(sassOutput));
});
gulp.task('watch:dev', function () {
browserSync.init({
files: ['bin/client/app/**/*.css'],
socket: {
domain: "localhost:3042"
},
ui: {
port: 3043,
},
port: 3042,
server: false,
notify: false
});
const tscWatch = spawn('tsc --watch -p tsconfig.dev.json');
tscWatch.stdout.on('data', function (data) {
const toDisplay = data.toString().replace(/[\n\r]+/g, '');
console.log(toDisplay);
});
gulp.watch(["client/**/*.html", "client/**/*.scss"], ['copyHtml', 'sass']).on('change', function (e) {
console.log('Resource file ' + e.path + ' has been changed. Updating.');
});
});
gulp.task('serve:dev', ['build:dev'], function () {
return nodemon({ script: 'bin/server/server.js', watch: ['bin/server'], delay: "50", ext: 'js' })
.on('restart', function () { });
});
gulp.task('start:dev', function () {
deleteReleaseBinFolder = false;
runSequence('clean', 'watch:dev', 'serve:dev');
});
// ************** RELEASE ****************/
gulp.task('build:release', () => {
const build = () => {
runSequence('copyHtml', 'sass:dev');
buildTypescript('tsconfig.release.json', '');
buildTypescript('tsconfig.release.client.json', '');
return gulp.src('./app.amd.js')
.pipe(rename('app.js'))
.pipe(gulp.dest("./bin"));
};
if (deleteReleaseBinFolder) {
return del('bin').then(build);
} else {
return build();
}
});
gulp.task('watch:release', function () {
return gulp.watch(["server/**/*.ts"], ['build:release']).on('change', function (e) {
console.log('REST : TypeScript file ' + e.path + ' has been changed. Compiling.');
});
});
gulp.task('serve:release', ['build:release'], function () {
return nodemon({ script: 'bin/app.js', args, ext: 'js' })
.on('restart', function () { });
});
gulp.task('start:release', ['clean'], function () {
deleteReleaseBinFolder = false;
return runSequence('watch:release', 'serve:release');
});
// ************** HELPERS ****************/
gulp.task('clean', () => {
return del('bin');
});
gulp.task('start', ['start:dev']);
gulp.task('serve', ['serve:dev']);
gulp.task('build', ['build:dev']);
gulp.task('watch', ['watch:dev']);
gulp.task('bwatch', ['build:dev'], function () { gulp.start('watch:dev'); });
gulp.task('sass', ['sass:dev']);
gulp.task('default', () => {
return runSequence('start:dev');
});