-
Notifications
You must be signed in to change notification settings - Fork 82
Expand file tree
/
Copy pathgulpfile.cjs
More file actions
231 lines (198 loc) · 5.43 KB
/
gulpfile.cjs
File metadata and controls
231 lines (198 loc) · 5.43 KB
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
'use strict';
var gulp = require('gulp');
var del = require('del');
var rename = require('gulp-rename');
var Server = require('karma').Server;
var parseConfig = require('karma').config.parseConfig;
var typeScriptCompiler = require('gulp-typescript');
var uglify = require('gulp-uglify');
var replace = require('gulp-replace');
var pump = require('pump');
var browserSources = [
'src/client/js/controller/*.ts',
'src/client/js/directives/*.ts',
'src/client/js/filters/*.ts',
'src/client/js/services/*.ts',
'src/client/js/*.ts'
];
var rootDir = process.cwd();
var distDirectory = 'dist';
gulp.task('watch', function () {
gulp.watch(['js/**/*.ts', 'server/data_form.ts'], ['build']);
});
gulp.task('compileClientSide', function () {
return gulp
.src(browserSources)
.pipe(typeScriptCompiler({
module: 'amd',
lib: [
"ES5",
"ES2015",
"DOM"
],
out: 'forms-angular.js',
target: 'ES5'
}))
.pipe(gulp.dest(distDirectory + '/client'));
});
gulp.task('compileServerSide', function () {
return gulp
.src('src/server/*.ts')
.pipe(typeScriptCompiler({
target: 'ES2020',
rootDir: '.',
moduleResolution: "node",
module: "es2020",
esModuleInterop: true,
}))
.pipe(gulp.dest(distDirectory + '/server'));
});
gulp.task('clean', function () {
return del(distDirectory, function (err, paths) { console.log('Cleared ' + paths.join(' ')); });
});
gulp.task('cleanMin', function () {
return del(distDirectory + '/client/min', function (err, paths) { console.log('Cleared ' + paths.join(' ')); });
});
gulp.task('annotate', function () {
var ngAnnotate = require('gulp-ng-annotate');
return gulp.src(distDirectory + '/client/forms-angular.js')
.pipe(ngAnnotate())
.pipe(gulp.dest(distDirectory + '/client'));
});
gulp.task('concatTemplates', function () {
var concat = require('gulp-concat');
return gulp.src(distDirectory + '/client/*.js')
.pipe(concat('forms-angular.js'))
.pipe(gulp.dest('./dist/client'));
});
gulp.task('tidy', function () {
return del([distDirectory + '/client/templates.js'], function (err, paths) { console.log('Cleared ' + paths.join(' ')); });
});
gulp.task('karmaTest', function (done) {
parseConfig(
rootDir + '/test/karma.conf.cjs',
{ singleRun: true },
{ promiseConfig: true, throwErrors: true }
).then(function (config) {
var server = new Server(config, done);
server.start();
});
});
gulp.task('midwayTest', function (done) {
parseConfig(
rootDir + '/test/karma.midway.conf.cjs',
{ singleRun: true },
{ promiseConfig: true, throwErrors: true }
).then(function (config) {
var server = new Server(config, done);
server.start();
});
});
gulp.task('apiTest', function () {
return gulp.src('test/api/API-Spec.js', { read: false })
// gulp-mocha needs filepaths so you can't have any plugins before it
.pipe(require('gulp-mocha')({ reporter: 'dot', 'forbid-only': true }));
});
gulp.task('saveDebug', function () {
return gulp.src(distDirectory + '/client/min/forms-angular.js')
.pipe(rename('forms-angular.min.js'))
.pipe(gulp.dest(distDirectory + '/client'));
});
gulp.task('uglify', function (cb) {
return pump([
gulp.src(distDirectory + '/client/forms-angular.js'),
uglify(),
gulp.dest(distDirectory + '/client/min')
],
cb
);
});
gulp.task('copyTypes', function () {
var files = [
'./src/client/index.d.ts',
'./src/server/index.d.ts'
];
return gulp.src(files, { base: './src/' })
.pipe(gulp.dest(distDirectory));
});
gulp.task('copyLess', function () {
return gulp.src(['./src/client/less/*.less'])
.pipe(gulp.dest(distDirectory + '/client'));
});
gulp.task('copyJs', function () {
return gulp.src([distDirectory + '/server/*.js'])
.pipe(gulp.dest('./src/server'));
});
gulp.task('templates', function () {
var templateCache = require('gulp-angular-templatecache');
return gulp
.src('src/client/template/**/*.html')
.pipe(templateCache({ standalone: false, module: 'formsAngular' }))
.pipe(replace(/templateCache.put\('\//g, "templateCache.put('"))
.pipe(gulp.dest(distDirectory + '/client'));
});
gulp.task('less', function () {
var less = require('gulp-less');
var minifyCSS = require('gulp-clean-css');
var path = require('path');
return gulp.src('src/client/less/forms-angular-with-*.less')
.pipe(less({ math: 'always' }))
.pipe(minifyCSS())
.pipe(gulp.dest(distDirectory + '/client'));
});
/**
* Main task: cleans, builds, run tests, and bundles up for distribution.
*/
gulp.task('compile', gulp.series(
'compileServerSide',
'compileClientSide',
function (done) { done(); })
);
gulp.task('test', gulp.series(
'karmaTest',
'midwayTest',
'apiTest',
function (done) { done(); })
);
gulp.task('build', gulp.series(
'clean',
'compile',
'templates',
'concatTemplates',
'annotate',
'tidy',
'uglify',
'saveDebug',
'copyTypes',
'copyLess',
'copyJs',
'cleanMin',
'less',
function (done) { done(); })
);
gulp.task('debugBuild', gulp.series(
'compile',
'templates',
'concatTemplates',
'annotate',
'tidy',
'less',
function (done) { done(); })
);
gulp.task('all', gulp.series(
'build',
'test',
function (done) { done(); })
);
gulp.task('default', gulp.series(
'clean',
'build',
'test',
function (done) { done(); })
);
gulp.task('allServer', gulp.series(
'clean',
'compileServerSide',
'apiTest',
function (done) { done(); })
);