-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.ts
49 lines (42 loc) · 1.5 KB
/
gulpfile.ts
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
import * as gulp from 'gulp';
import * as ts from 'gulp-typescript';
import * as typescript from 'typescript';
import uglify from 'gulp-uglify-es';
import * as gzip from 'gulp-gzip';
import * as ejs from 'gulp-ejs';
import * as rename from 'gulp-rename';
import * as fs from 'fs';
let tsProject = (declaration: boolean = false) => ts.createProject('tsconfig.json', {
typescript,
declaration,
emitDeclarationOnly: declaration
})();
gulp.task('build-types', () => gulp.src('./src/index.ts')
.pipe(tsProject(true))
.pipe(gulp.dest('./dist' ))
);
gulp.task('build-app', () => gulp.src('./src/index.ts')
.pipe(tsProject())
.pipe(uglify())
.pipe(gulp.dest('./dist'))
);
gulp.task('gzip-app', () => gulp.src('./dist/index.js')
.pipe(gzip())
.pipe(gulp.dest('./dist'))
);
gulp.task('build-docs', () => gulp.src('./docs/readme-template.ejs.md')
.pipe<NodeJS.ReadWriteStream>(ejs({
sizes: {
min: () => (fs.statSync('./dist/index.js').size / 1000).toFixed(2),
gzip: () => (fs.statSync('./dist/index.js.gz').size / 1000).toFixed(2)
},
example: (name: string) => {
let file = fs.readFileSync(`./docs/examples/${name}.ts`).toString();
let start = '//START';
return file.substring(file.indexOf(start) + start.length).trim();
}
}))
.pipe<NodeJS.ReadWriteStream>(rename('readme.md'))
.pipe(gulp.dest('./'))
);
gulp.task('build', gulp.series('build-app', 'gzip-app', 'build-docs', 'build-types'));