This repository has been archived by the owner on Dec 21, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
61 lines (55 loc) · 1.52 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
var gulp = require('gulp'),
gulp_copy = require('gulp-copy'),
gulp_typescript = require('gulp-typescript'),
gulp_sourceMaps = require('gulp-sourcemaps'),
gulp_clean = require('gulp-clean'),
fs = require('fs');
gulp.task('clean', function() {
return gulp.src('./dist').pipe(gulp_clean({ force: true }));
});
gulp.task('create-index', function(done) {
function createIndex(path) {
var files = fs.readdirSync(path);
var index = '';
files.forEach(file => {
var stats = fs.statSync(path + '/' + file);
var name = file;
if (stats.isDirectory()) {
createIndex(path + '/' + file);
} else {
if (
!/\.ts$/gi.test(name) ||
/\.spec\.ts$/gi.test(name) ||
/test.ts$/gi.test(name)
) {
return;
}
name = name.replace(/\.ts$/g, '');
if (name === 'index') return;
}
index += `export * from \'./${name}\';\r\n`;
});
fs.writeFileSync(path + '/index.ts', index);
}
createIndex('./src');
done();
});
gulp.task('build', ['clean', 'create-index'], function() {
//loading typings file
var tsProject = gulp_typescript.createProject('./tsconfig.json');
return gulp
.src('./src/**/*.ts')
.pipe(tsProject())
.pipe(gulp_sourceMaps.init())
.pipe(gulp_sourceMaps.write('./'))
.pipe(gulp.dest('dist'))
.pipe(
gulp
.src([
'package.json',
'{README,readme}?(.md)',
'{LICENSE|license}?(.md)'
])
.pipe(gulp_copy('./dist/'))
);
});