-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
96 lines (80 loc) · 2.2 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
var gulp = require('gulp');
var del = require('del');
var ts = require('gulp-typescript');
var jshint = require('gulp-jshint');
var wrap = require('gulp-wrap');
var concat = require('gulp-concat');
var rename = require('gulp-rename');
var uglify = require('gulp-uglify');
var serve = require('gulp-serve');
var minimist = require('minimist');
var knownOptions = {
string: 'env',
default: { env: process.env.NODE_ENV || 'local' }
};
var options = minimist(process.argv.slice(2), knownOptions);
var paths = {
clean: './dist',
scripts: {
source: './dist/.tmp/js/src/**/*.js',
dest: './dist/serve/js/'
},
typescript: {
config: './tsconfig.js',
source: './src/*.ts',
dest: './dist/.tmp/js'
},
libraries: {
source: './libs/**/*',
dest: './dist/serve/libs/'
},
tests: {
source: './tests/spec/**/*.js'
}
};
gulp.task('typescript', compileTypeScript);
gulp.task('scripts', scriptsTask);
gulp.task('serve', serve({
root: paths.wwwroot,
port: 3001
}));
gulp.task('clean', function () {
return del([paths.clean]);
});
gulp.task('copy:libs', copyLibraries);
gulp.task('copy:all', gulp.parallel('copy:libs'));
gulp.task('watch:typescript', function () {
gulp.watch(paths.typescript.source, gulp.series('typescript','scripts'/*, 'karma'*/));
});
gulp.task('watch', gulp.parallel('watch:typescript' /*, 'watch:tests'*/));
gulp.task('build', gulp
.series(
'clean',
'typescript',
'scripts',
'copy:all'
)
);
gulp.task('default', gulp.series('build', gulp.parallel('serve', 'watch')));
function compileTypeScript() {
var tsProject = ts.createProject('tsconfig.json');
var tsResult = tsProject.src() // instead of gulp.src(...)
.pipe(ts(tsProject));
return tsResult.js.pipe(gulp.dest(paths.typescript.dest));
}
function copyLibraries() {
return gulp
.src(paths.libraries.source)
.pipe(gulp.dest(paths.libraries.dest));
}
function scriptsTask() {
return gulp.src(paths.scripts.source)
.pipe(jshint({sub:true}))
.pipe(jshint.reporter('jshint-stylish'))
.pipe(concat('app.js'))
.pipe(wrap('(function(angular){"use strict";\n<%= contents %>\n})(angular);'))
.pipe(gulp.dest(paths.scripts.dest))
.pipe(rename({ suffix: '.min' }))
.pipe(uglify())
.pipe(gulp.dest(paths.scripts.dest));
}