forked from typestack/typedi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.ts
108 lines (96 loc) · 2.75 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
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
import {Gulpclass, Task, SequenceTask} from "gulpclass/Decorators";
const gulp: any = require('gulp');
const del: any = require('del');
const shell: any = require('gulp-shell');
const dtsGenerator: any = require('dts-generator').default;
const replace: any = require('gulp-replace');
const glob: any = require('glob');
@Gulpclass()
export class Gulpfile {
/**
* Cleans build folder.
*/
@Task()
clean(cb: Function) {
return del(['./build/**'], cb);
}
/**
* Runs typescript files compilation.
*/
@Task()
compile() {
return gulp.src('*.js', { read: false })
.pipe(shell(['tsc']));
}
/**
* Publishes a package to npm from ./build/package directory.
*/
@Task()
npmPublish() {
return gulp.src('*.js', { read: false })
.pipe(shell([
'cd ./build/package && npm publish'
]));
}
/**
* Copies all files that will be in a package.
*/
@Task()
packageFiles() {
return gulp.src('./build/es5/src/**/*')
.pipe(gulp.dest('./build/package'));
}
/**
* Change the "private" state of the packaged package.json file to public.
*/
@Task()
packagePreparePackageFile() {
return gulp.src('./package.json')
.pipe(replace('"private": true,', '"private": false,'))
.pipe(gulp.dest('./build/package'));
}
/**
* This task will replace all typescript code blocks in the README (since npm does not support typescript syntax
* highlighting) and copy this README file into the package folder.
*/
@Task()
packageReadmeFile() {
return gulp.src('./README.md')
.pipe(replace(/```typescript([\s\S]*?)```/g, '```javascript$1```'))
.pipe(gulp.dest('./build/package'));
}
/**
* Generates a .d.ts file that is needed for the npm package and will be imported by others.
*/
@Task()
packageGenerateDts(cb: Function) {
glob('./src/**/*.ts', (err: any, files: string[]) => {
const name = require(__dirname + '/../../package.json').name;
dtsGenerator({
name: name,
baseDir: './src',
files: files,
out: './build/package/index.d.ts'
});
cb();
});
}
/**
* Creates a package that can be published to npm.
*/
@SequenceTask()
package() {
return [
'clean',
'compile',
['packageFiles', 'packagePreparePackageFile', 'packageReadmeFile', 'packageGenerateDts']
];
}
/**
* Creates a package and publishes it to npm.
*/
@SequenceTask()
publish() {
return ['package', 'npmPublish'];
}
}