This repository has been archived by the owner on Feb 20, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
138 lines (117 loc) · 3.91 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
'use strict';
var gulp = require('gulp');
var onejsCompiler = require('gulp-onejs-compiler');
var tsc = require('gulp-typescript');
var clean = require('gulp-rimraf');
var uglify = require('gulp-uglifyjs');
var add = require('gulp-add-src');
var less = require('gulp-less');
var cssMinify = require('gulp-minify-css');
var csstojs = require('gulp-csstojs');
var filter = require('gulp-filter');
var size = require('gulp-size');
var mergeStream = require('merge-stream');
var karma = require('karma').server;
var paths = {
tempPath: 'tmp',
appPath: 'app',
appMinPath: 'app-min',
examplePath: 'examples-compiled',
staticFiles: ['node_modules/requirejs/require.js']
};
var amdDependencies = [
'onejs'
];
gulp.task('clean', function() {
return gulp.src([paths.tempPath, paths.appPath, paths.appMinPath, paths.examplePath])
.pipe(clean());
});
gulp.task('copy-deps', ['clean'], function() {
var stream = mergeStream();
for (var i = 0; i < amdDependencies.length; i++) {
var dep = amdDependencies[i];
stream.add(
gulp.src('node_modules/' + dep + '/dist/amd/*')
.pipe(gulp.dest(paths.tempPath + '/ts/' + dep))
.pipe(gulp.dest(paths.tempPath + '/example/' + dep))
.pipe(gulp.dest(paths.examplePath + '/' + dep))
.pipe(gulp.dest(paths.appPath + '/' + dep))
);
}
return stream;
});
gulp.task('tsc-preprocess', ['copy-deps'], function() {
var lessFilter = filter('**/*.less');
return gulp.src(['node_modules/onejs-compiler/src/**/*', 'node_modules/onejs/src/**/*', 'src/**/*'])
.pipe(lessFilter)
.pipe(less())
.pipe(cssMinify())
.pipe(csstojs({
typeScript: true
}))
.pipe(lessFilter.restore())
.pipe(onejsCompiler())
.pipe(gulp.dest(paths.tempPath + '/ts'));
});
gulp.task('test-preprocess', ['copy-deps'], function() {
return gulp.src(['test/**/*']).pipe(gulp.dest(paths.tempPath + '/ts/test'));
});
gulp.task('tsc', ['tsc-preprocess', 'test-preprocess'], function() {
return gulp.src(paths.tempPath + '/ts/**/*.ts')
.pipe(tsc({
target: 'ES5',
module: 'amd'
}))
.pipe(gulp.dest(paths.appPath));
});
gulp.task('example-preprocess', ['copy-deps'], function() {
var lessFilter = filter('**/*.less');
return gulp.src(['node_modules/onejs-compiler/src/**/*', 'node_modules/onejs/src/**/*', 'src/**/*', 'examples/**/*'])
.pipe(lessFilter)
.pipe(less())
.pipe(cssMinify())
.pipe(csstojs({
typeScript: true
}))
.pipe(lessFilter.restore())
.pipe(onejsCompiler())
.pipe(gulp.dest(paths.tempPath + '/example'));
});
gulp.task('example-compile', ['example-preprocess'], function() {
return gulp.src(paths.tempPath + '/example/**/*.ts')
.pipe(tsc({
target: 'ES5',
module: 'amd'
}))
.pipe(gulp.dest(paths.examplePath));
});
gulp.task('copy-examples-static-files', ['clean'], function() {
return gulp.src(paths.staticFiles)
.pipe(gulp.dest(paths.examplePath));
});
gulp.task('minify', ['tsc'], function() {
return gulp.src([paths.appPath + '/*.js'])
.pipe(uglify())
.pipe(size({
gzip: true
}))
.pipe(gulp.dest(paths.appMinPath));
});
gulp.task('copy-static-files', ['clean', 'tsc'], function() {
return gulp.src(paths.staticFiles)
.pipe(gulp.dest(paths.appPath))
.pipe(uglify())
.pipe(gulp.dest(paths.appMinPath));
});
gulp.task('build', ['example-compile',
'tsc',
'minify',
'copy-static-files',
'copy-examples-static-files']);
gulp.task('test', ['build'], function (done) {
karma.start({
configFile: __dirname + '/karma.conf.js',
singleRun: true
}, done);
});
gulp.task('default', ['build', 'test']);