forked from DevExpress/devextreme-angular
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
273 lines (215 loc) · 8.55 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
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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
var gulp = require('gulp');
var path = require('path');
var typescript = require('gulp-typescript');
var tslint = require('gulp-tslint');
var replace = require('gulp-replace');
var shell = require('gulp-shell');
var sourcemaps = require('gulp-sourcemaps');
var jasmine = require('gulp-jasmine');
var jasmineReporters = require('jasmine-reporters');
var del = require('del');
var karmaServer = require('karma').Server;
var karmaConfig = require('karma').config;
var buildConfig = require('./build.config');
var header = require('gulp-header');
var ngPackagr = require('ng-packagr');
//------------Tools------------
gulp.task('build.tools', function() {
var config = buildConfig.tools;
return gulp.src(config.srcFilesPattern)
.pipe(sourcemaps.init())
.pipe(typescript(config.tsConfigPath))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(config.distPath));
});
//------------Components------------
gulp.task('clean.metadata', gulp.series('build.tools', function() {
var outputFolderPath = buildConfig.tools.metadataGenerator.outputFolderPath;
return del([outputFolderPath]);
}));
gulp.task('generate.metadata', gulp.series('build.tools', 'clean.metadata', function(done) {
var MetadataGenerator = require(buildConfig.tools.metadataGenerator.importFrom).default,
generator = new MetadataGenerator();
generator.generate(buildConfig.tools.metadataGenerator);
done();
}));
gulp.task('clean.generatedComponents', function(done) {
var { outputFolderPath } = buildConfig.tools.componentGenerator;
del.sync([outputFolderPath + "/**"]);
done();
});
gulp.task('generate.components', gulp.series('generate.metadata', 'clean.generatedComponents', function(done) {
var DoTGenerator = require(buildConfig.tools.componentGenerator.importFrom).default,
generator = new DoTGenerator();
generator.generate(buildConfig.tools.componentGenerator);
done();
}));
gulp.task('generate.moduleFacades', gulp.series('generate.components', function(done) {
var ModuleFacadeGenerator = require(buildConfig.tools.moduleFacadeGenerator.importFrom).default,
moduleFacadeGenerator = new ModuleFacadeGenerator();
moduleFacadeGenerator.generate(buildConfig.tools.moduleFacadeGenerator);
done();
}));
gulp.task('generate.facades', gulp.series('generate.moduleFacades', function(done) {
var FacadeGenerator = require(buildConfig.tools.facadeGenerator.importFrom).default,
facadeGenerator = new FacadeGenerator();
facadeGenerator.generate(buildConfig.tools.facadeGenerator);
done();
}));
gulp.task('build.license-headers', function() {
var config = buildConfig.components,
pkg = require('./package.json'),
now = new Date(),
data = {
pkg: pkg,
date: now.toDateString(),
year: now.getFullYear()
};
var banner = [
'/*!',
' * <%= pkg.name %>',
' * Version: <%= pkg.version %>',
' * Build date: <%= date %>',
' *',
' * Copyright (c) 2012 - <%= year %> Developer Express Inc. ALL RIGHTS RESERVED',
' *',
' * This software may be modified and distributed under the terms',
' * of the MIT license. See the LICENSE file in the root of the project for details.',
' *',
' * https://github.com/DevExpress/devextreme-angular',
' */',
'\n' // This new line is necessary to keep the header after TS compilation
].join('\n');
return gulp.src(`${config.outputPath}/${config.srcFilesPattern}`)
.pipe(header(banner, data))
.pipe(gulp.dest(config.outputPath));
});
gulp.task('clean.dist', function() {
del.sync([buildConfig.components.outputPath + "/*.*"]);
return del([buildConfig.components.outputPath]);
});
gulp.task('build.ngc', function() {
var config = buildConfig.components;
return ngPackagr.build({
project: path.join(config.outputPath, 'package.json')
});
});
gulp.task('build.copy-sources', gulp.series('clean.dist', function() {
var config = buildConfig.components;
return gulp.src(config.sourcesGlobs)
.pipe(gulp.dest(config.outputPath));
}));
// Note: workaround for https://github.com/angular/angular-cli/issues/4874
gulp.task('build.remove-unusable-variable', function() {
var config = buildConfig.npm;
return gulp.src(config.distPath + '/**/*.js')
.pipe(replace(/DevExpress\.[\w\.]+/g, 'Object'))
.pipe(gulp.dest(config.distPath));
});
gulp.task('build.components', gulp.series('generate.facades',
'build.copy-sources',
'build.license-headers',
'build.ngc',
'build.remove-unusable-variable'
));
//------------npm------------
gulp.task('npm.content', gulp.series('build.components', function() {
var npmConfig = buildConfig.npm,
cmpConfig = buildConfig.components;
return gulp.src([cmpConfig.outputPath + '/**/collection.json', ...npmConfig.content])
.pipe(gulp.dest(npmConfig.distPath));
}));
gulp.task('npm.pack', gulp.series('npm.content', shell.task(['npm pack'], { cwd: buildConfig.npm.distPath })));
//------------TSLint------------
gulp.task('lint', function() {
return gulp.src([buildConfig.components.tsSourcesGlob]
.concat(buildConfig.components.tsTestSrc)
.concat(buildConfig.examples.srcFilesPattern)
.concat(buildConfig.tools.srcFilesPattern)
)
.pipe(tslint({
formatter: 'prose',
tslint: require('tslint').default,
rulesDirectory: null,
configuration: 'tslint.json'
}))
.pipe(tslint.report());
});
//------------Main------------
var buildTask = gulp.series(
'build.tools',
'build.components'
);
gulp.task('build', buildTask);
gulp.task('default', buildTask);
//------------Testing------------
gulp.task('clean.tests', function() {
var outputFolderPath = buildConfig.components.testsPath;
return del([outputFolderPath]);
});
gulp.task('generate-component-names', gulp.series('build.tools', function(done) {
var ComponentNamesGenerator = require(buildConfig.tools.componentNamesGenerator.importFrom).default;
var generator = new ComponentNamesGenerator(buildConfig.tools.componentNamesGenerator);
generator.generate();
done();
}));
gulp.task('build.tests', gulp.series('clean.tests', 'generate-component-names', function() {
var config = buildConfig.components,
testConfig = buildConfig.tests;
return gulp.src(config.tsTestSrc)
.pipe(sourcemaps.init())
.pipe(typescript(testConfig.tsConfigPath))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(config.testsPath));
}));
gulp.task('watch.spec', function() {
gulp.watch(buildConfig.components.tsTestSrc, ['build.tests']);
});
var getKarmaConfig = function(testsPath) {
const preprocessors = {};
preprocessors[testsPath] = [ 'webpack' ];
return karmaConfig.parseConfig(path.resolve('./karma.conf.js'), {
files: [{ pattern: testsPath, watched: false }],
preprocessors: preprocessors
});
};
gulp.task('test.components.client', gulp.series('build.tests', function(done) {
new karmaServer(getKarmaConfig('./karma.test.shim.js'), done).start();
}));
gulp.task('test.components.server', gulp.series('build.tests', function(done) {
new karmaServer(getKarmaConfig('./karma.server.test.shim.js'), done).start();
}));
gulp.task('test.components', gulp.series('test.components.server', 'test.components.client'));
gulp.task('test.components.client.debug', function(done) {
var config = getKarmaConfig('./karma.test.shim.js');
config.browsers = [ 'Chrome' ];
config.singleRun = false;
new karmaServer(config, done).start();
});
gulp.task('test.components.server.debug', function(done) {
var config = getKarmaConfig('./karma.server.test.shim.js');
config.browsers = [ 'Chrome' ];
config.singleRun = false;
new karmaServer(config, done).start();
});
gulp.task('test.tools', function(done) {
var config = buildConfig.tools.tests;
return gulp.src(config.srcFilesPattern)
.pipe(jasmine({
errorOnFail: false,
reporter: [
new jasmineReporters.TerminalReporter({
verbosity: 1,
color: true,
showStack: true
})
]
}));
});
gulp.task('run.tests', gulp.series(gulp.parallel('test.tools', 'test.components')));
gulp.task('test', gulp.series('build', 'build.tests', 'run.tests'));
gulp.task('watch.test', function(done) {
new karmaServer({
configFile: __dirname + '/karma.conf.js'
}, done).start();
});