-
Notifications
You must be signed in to change notification settings - Fork 24
/
gulpfile.ts
97 lines (85 loc) · 2.29 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
import {Gulpclass, Task, SequenceTask} from "./src/index";
const gulp = require("gulp");
const del = require("del");
const shell = require("gulp-shell");
const replace = require("gulp-replace");
@Gulpclass()
export class Gulpfile {
/**
* Cleans compiled files.
*/
@Task()
cleanCompiled(cb: Function) {
return del(["./build/es5/**"], cb);
}
/**
* Publishes a package to npm from ./build/package directory.
*/
@Task()
npmPublish() {
return gulp.src("*.js", { read: false })
.pipe(shell([
"cd ./build/package && npm publish"
]));
}
/**
* Cleans generated package files.
*/
@Task()
cleanPackage(cb: Function) {
return del(["./build/package/**"], cb);
}
/**
* Runs typescript files compilation.
*/
@Task()
compile() {
return gulp.src("*.js", { read: false })
.pipe(shell(["tsc"]));
}
/**
* 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"));
}
/**
* Creates a package that can be published to npm.
*/
@SequenceTask()
package() {
return [
["cleanCompiled", "cleanPackage"],
"compile",
["packageFiles", "packagePreparePackageFile", "packageReadmeFile"]
];
}
/**
* Creates a package and publishes it to npm.
*/
@SequenceTask()
publish() {
return ["package", "npmPublish"];
}
}