1
+ import { Gulpclass , Task , SequenceTask } from "gulpclass/Decorators" ;
2
+
3
+ const gulp = require ( "gulp" ) ;
4
+ const del = require ( "del" ) ;
5
+ const shell = require ( "gulp-shell" ) ;
6
+ const replace = require ( "gulp-replace" ) ;
7
+ const mocha = require ( "gulp-mocha" ) ;
8
+ const chai = require ( "chai" ) ;
9
+ const tslint = require ( "gulp-tslint" ) ;
10
+ const stylish = require ( "tslint-stylish" ) ;
11
+
12
+ @Gulpclass ( )
13
+ export class Gulpfile {
14
+
15
+ // -------------------------------------------------------------------------
16
+ // General tasks
17
+ // -------------------------------------------------------------------------
18
+
19
+ /**
20
+ * Cleans build folder.
21
+ */
22
+ @Task ( )
23
+ clean ( cb : Function ) {
24
+ return del ( [ "./build/**" ] , cb ) ;
25
+ }
26
+
27
+ /**
28
+ * Runs typescript files compilation.
29
+ */
30
+ @Task ( )
31
+ compile ( ) {
32
+ return gulp . src ( "*.js" , { read : false } )
33
+ . pipe ( shell ( [ "tsc" ] ) ) ;
34
+ }
35
+
36
+ // -------------------------------------------------------------------------
37
+ // Packaging and Publishing tasks
38
+ // -------------------------------------------------------------------------
39
+
40
+ /**
41
+ * Publishes a package to npm from ./build/package directory.
42
+ */
43
+ @Task ( )
44
+ npmPublish ( ) {
45
+ return gulp . src ( "*.js" , { read : false } )
46
+ . pipe ( shell ( [
47
+ "cd ./build/package && npm publish"
48
+ ] ) ) ;
49
+ }
50
+
51
+ /**
52
+ * Copies all files that will be in a package.
53
+ */
54
+ @Task ( )
55
+ packageFiles ( ) {
56
+ return gulp . src ( "./build/es5/src/**/*" )
57
+ . pipe ( gulp . dest ( "./build/package" ) ) ;
58
+ }
59
+
60
+ /**
61
+ * Change the "private" state of the packaged package.json file to public.
62
+ */
63
+ @Task ( )
64
+ packagePreparePackageFile ( ) {
65
+ return gulp . src ( "./package.json" )
66
+ . pipe ( replace ( "\"private\": true," , "\"private\": false," ) )
67
+ . pipe ( gulp . dest ( "./build/package" ) ) ;
68
+ }
69
+
70
+ /**
71
+ * This task will replace all typescript code blocks in the README (since npm does not support typescript syntax
72
+ * highlighting) and copy this README file into the package folder.
73
+ */
74
+ @Task ( )
75
+ packageReadmeFile ( ) {
76
+ return gulp . src ( "./README.md" )
77
+ . pipe ( replace ( / ` ` ` t y p e s c r i p t ( [ \s \S ] * ?) ` ` ` / g, "```javascript$1```" ) )
78
+ . pipe ( gulp . dest ( "./build/package" ) ) ;
79
+ }
80
+
81
+ /**
82
+ * This task will copy typings.json file to the build package.
83
+ */
84
+ @Task ( )
85
+ copyTypingsFile ( ) {
86
+ return gulp . src ( "./typings.json" )
87
+ . pipe ( gulp . dest ( "./build/package" ) ) ;
88
+ }
89
+
90
+ /**
91
+ * Creates a package that can be published to npm.
92
+ */
93
+ @SequenceTask ( )
94
+ package ( ) {
95
+ return [
96
+ "clean" ,
97
+ "compile" ,
98
+ [ "packageFiles" , "packagePreparePackageFile" , "packageReadmeFile" , "copyTypingsFile" ]
99
+ ] ;
100
+ }
101
+
102
+ /**
103
+ * Creates a package and publishes it to npm.
104
+ */
105
+ @SequenceTask ( )
106
+ publish ( ) {
107
+ return [ "package" , "npmPublish" ] ;
108
+ }
109
+
110
+ // -------------------------------------------------------------------------
111
+ // Run tests tasks
112
+ // -------------------------------------------------------------------------
113
+
114
+ /**
115
+ * Runs ts linting to validate source code.
116
+ */
117
+ @Task ( )
118
+ tslint ( ) {
119
+ return gulp . src ( [ "./src/**/*.ts" , "./test/**/*.ts" , "./sample/**/*.ts" ] )
120
+ . pipe ( tslint ( ) )
121
+ . pipe ( tslint . report ( stylish , {
122
+ emitError : true ,
123
+ sort : true ,
124
+ bell : true
125
+ } ) ) ;
126
+ }
127
+
128
+ /**
129
+ * Runs unit-tests.
130
+ */
131
+ @Task ( )
132
+ unit ( ) {
133
+ chai . should ( ) ;
134
+ chai . use ( require ( "sinon-chai" ) ) ;
135
+ return gulp . src ( "./build/es5/test/unit/**/*.js" )
136
+ . pipe ( mocha ( ) ) ;
137
+ }
138
+
139
+ /**
140
+ * Compiles the code and runs tests.
141
+ */
142
+ @SequenceTask ( )
143
+ tests ( ) {
144
+ return [ "compile" , "tslint" , "unit" ] ;
145
+ }
146
+
147
+ }
0 commit comments