1
1
/* eslint-disable */
2
2
var gulp = require ( 'gulp' ) ,
3
- path = require ( 'path' ) ,
4
- ngc = require ( '@angular/compiler-cli/src/main' ) . main ,
5
- rollup = require ( 'gulp-rollup' ) ,
6
- rename = require ( 'gulp-rename' ) ,
7
- del = require ( 'del' ) ,
8
- runSequence = require ( 'run-sequence' ) ,
9
- inlineResources = require ( './tools/gulp/inline-resources' ) ;
3
+ path = require ( 'path' ) ,
4
+ ngc = require ( '@angular/compiler-cli/src/main' ) . main ,
5
+ rollup = require ( 'gulp-rollup' ) ,
6
+ rename = require ( 'gulp-rename' ) ,
7
+ del = require ( 'del' ) ,
8
+ runSequence = require ( 'run-sequence' ) ,
9
+ inlineResources = require ( './tools/gulp/inline-resources' ) ;
10
10
11
11
const rootFolder = path . join ( __dirname ) ;
12
12
const srcFolder = path . join ( rootFolder , 'src' ) ;
13
13
const tmpFolder = path . join ( rootFolder , '.tmp' ) ;
14
14
const buildFolder = path . join ( rootFolder , 'build' ) ;
15
15
const distFolder = path . join ( rootFolder , 'dist' ) ;
16
+ const bundlesFolder = path . join ( distFolder , 'bundles' ) ;
16
17
17
18
/**
18
19
* 1. Delete /dist folder
19
20
*/
20
21
gulp . task ( 'clean:dist' , function ( ) {
21
22
22
- // Delete contents but not dist folder to avoid broken npm links
23
- // when dist directory is removed while npm link references it.
24
- return deleteFolders ( [ distFolder + '/**' , '!' + distFolder ] ) ;
23
+ // Delete contents but not dist folder to avoid broken npm links
24
+ // when dist directory is removed while npm link references it.
25
+ return deleteFolders ( [ distFolder + '/**' , '!' + distFolder ] ) ;
25
26
} ) ;
26
27
27
28
/**
@@ -30,17 +31,17 @@ return deleteFolders([distFolder + '/**', '!' + distFolder]);
30
31
* when copying to /.tmp.
31
32
*/
32
33
gulp . task ( 'copy:source' , function ( ) {
33
- return gulp . src ( [ `${ srcFolder } /**/*` , `!${ srcFolder } /node_modules` ] )
34
- . pipe ( gulp . dest ( tmpFolder ) ) ;
34
+ return gulp . src ( [ `${ srcFolder } /**/*` , `!${ srcFolder } /node_modules` ] )
35
+ . pipe ( gulp . dest ( tmpFolder ) ) ;
35
36
} ) ;
36
37
37
38
/**
38
39
* 3. Inline template (.html) and style (.css) files into the the component .ts files.
39
40
* We do this on the /.tmp folder to avoid editing the original /src files
40
41
*/
41
42
gulp . task ( 'inline-resources' , function ( ) {
42
- return Promise . resolve ( )
43
- . then ( ( ) => inlineResources ( tmpFolder ) ) ;
43
+ return Promise . resolve ( )
44
+ . then ( ( ) => inlineResources ( tmpFolder ) ) ;
44
45
} ) ;
45
46
46
47
@@ -49,168 +50,112 @@ return Promise.resolve()
49
50
* compiled modules to the /build folder.
50
51
*/
51
52
gulp . task ( 'ngc' , function ( ) {
52
- return ngc ( {
53
- project : `${ tmpFolder } /tsconfig.es5.json`
54
- } )
55
- . then ( ( exitCode ) => {
56
- if ( exitCode === 1 ) {
57
- // This error is caught in the 'compile' task by the runSequence method callback
58
- // so that when ngc fails to compile, the whole compile process stops running
59
- throw new Error ( 'ngc compilation failed' ) ;
60
- }
61
- } ) ;
53
+ return ngc ( [ ] , function ( s ) {
54
+ throw new Error ( s ) ;
55
+ } )
62
56
} ) ;
63
57
64
58
/**
65
59
* 5. Run rollup inside the /build folder to generate our Flat ES module and place the
66
60
* generated file into the /dist folder
67
61
*/
68
- gulp . task ( 'rollup:fesm' , function ( ) {
69
- return gulp . src ( `${ buildFolder } /**/*.js` )
70
- // transform the files here.
71
- . pipe ( rollup ( {
72
-
73
- // Bundle's entry point
74
- // See "input" in https://rollupjs.org/#core-functionality
75
- input : `${ buildFolder } /index.js` ,
76
-
77
- // Allow mixing of hypothetical and actual files. "Actual" files can be files
78
- // accessed by Rollup or produced by plugins further down the chain.
79
- // This prevents errors like: 'path/file' does not exist in the hypothetical file system
80
- // when subdirectories are used in the `src` directory.
81
- allowRealFiles : true ,
82
-
83
- // A list of IDs of modules that should remain external to the bundle
84
- // See "external" in https://rollupjs.org/#core-functionality
85
- external : [
86
- '@angular/core' ,
87
- '@angular/common'
88
- ] ,
89
-
90
- // Format of generated bundle
91
- // See "format" in https://rollupjs.org/#core-functionality
92
- format : 'es'
93
- } ) )
94
- . pipe ( gulp . dest ( distFolder ) ) ;
95
- } ) ;
96
-
97
- /**
98
- * 6. Run rollup inside the /build folder to generate our UMD module and place the
99
- * generated file into the /dist folder
100
- */
101
62
gulp . task ( 'rollup:umd' , function ( ) {
102
- return gulp . src ( `${ buildFolder } /**/*.js` )
103
- // transform the files here.
104
- . pipe ( rollup ( {
105
-
106
- // Bundle's entry point
107
- // See "input" in https://rollupjs.org/#core-functionality
108
- input : `${ buildFolder } /index.js` ,
109
-
110
- // Allow mixing of hypothetical and actual files. "Actual" files can be files
111
- // accessed by Rollup or produced by plugins further down the chain.
112
- // This prevents errors like: 'path/file' does not exist in the hypothetical file system
113
- // when subdirectories are used in the `src` directory.
114
- allowRealFiles : true ,
115
-
116
- // A list of IDs of modules that should remain external to the bundle
117
- // See "external" in https://rollupjs.org/#core-functionality
118
- external : [
119
- '@angular/core' ,
120
- '@angular/common'
121
- ] ,
122
-
123
- // Format of generated bundle
124
- // See "format" in https://rollupjs.org/#core-functionality
125
- format : 'umd' ,
126
-
127
- // Export mode to use
128
- // See "exports" in https://rollupjs.org/#danger-zone
129
- exports : 'named' ,
130
-
131
- // The name to use for the module for UMD/IIFE bundles
132
- // (required for bundles with exports)
133
- // See "name" in https://rollupjs.org/#core-functionality
134
- name : 'angular-oauth2-oidc' ,
135
-
136
- // See "globals" in https://rollupjs.org/#core-functionality
137
- globals : {
138
- typescript : 'ts'
139
- }
140
-
141
- } ) )
142
- . pipe ( rename ( 'angular-oauth2-oidc.umd.js' ) )
143
- . pipe ( gulp . dest ( distFolder ) ) ;
63
+ return gulp . src ( `${ buildFolder } /**/*.js` )
64
+ // transform the files here.
65
+ . pipe ( rollup ( {
66
+
67
+ // Bundle's entry point
68
+ // See "input" in https://rollupjs.org/#core-functionality
69
+ entry : `${ buildFolder } /index.js` ,
70
+ // A list of IDs of modules that should remain external to the bundle
71
+ // See "external" in https://rollupjs.org/#core-functionality
72
+ external : [
73
+ '@angular/core' ,
74
+ '@angular/common'
75
+ ] ,
76
+ // Format of generated bundle
77
+ // See "format" in https://rollupjs.org/#core-functionality
78
+ output : {
79
+ name : 'UMD' ,
80
+ format : 'umd' ,
81
+ globals : {
82
+ typescript : 'ts'
83
+ }
84
+ } ,
85
+ } ) )
86
+ . pipe ( rename ( 'angular-oauth2-oidc.umd.js' ) )
87
+ . pipe ( gulp . dest ( bundlesFolder ) )
88
+ ;
144
89
} ) ;
145
90
91
+
146
92
/**
147
93
* 7. Copy all the files from /build to /dist, except .js files. We ignore all .js from /build
148
94
* because with don't need individual modules anymore, just the Flat ES module generated
149
95
* on step 5.
150
96
*/
151
97
gulp . task ( 'copy:build' , function ( ) {
152
- return gulp . src ( [ `${ buildFolder } /**/*` , `! ${ buildFolder } /**/*.js `] )
153
- . pipe ( gulp . dest ( distFolder ) ) ;
98
+ return gulp . src ( [ `${ buildFolder } /**/*` ] )
99
+ . pipe ( gulp . dest ( distFolder ) ) ;
154
100
} ) ;
155
101
156
102
/**
157
103
* 8. Copy package.json from /src to /dist
158
104
*/
159
105
gulp . task ( 'copy:manifest' , function ( ) {
160
- return gulp . src ( [ `${ srcFolder } /package.json` ] )
161
- . pipe ( gulp . dest ( distFolder ) ) ;
106
+ return gulp . src ( [ `${ srcFolder } /package.json` ] )
107
+ . pipe ( gulp . dest ( distFolder ) ) ;
162
108
} ) ;
163
109
164
110
/**
165
111
* 9. Copy README.md from / to /dist
166
112
*/
167
113
gulp . task ( 'copy:readme' , function ( ) {
168
- return gulp . src ( [ path . join ( rootFolder , 'README.MD' ) ] )
169
- . pipe ( gulp . dest ( distFolder ) ) ;
114
+ return gulp . src ( [ path . join ( rootFolder , 'README.MD' ) ] )
115
+ . pipe ( gulp . dest ( distFolder ) ) ;
170
116
} ) ;
171
117
172
118
/**
173
119
* 10. Delete /.tmp folder
174
120
*/
175
121
gulp . task ( 'clean:tmp' , function ( ) {
176
- return deleteFolders ( [ tmpFolder ] ) ;
122
+ return deleteFolders ( [ tmpFolder ] ) ;
177
123
} ) ;
178
124
179
125
/**
180
126
* 11. Delete /build folder
181
127
*/
182
128
gulp . task ( 'clean:build' , function ( ) {
183
- return deleteFolders ( [ buildFolder ] ) ;
129
+ return deleteFolders ( [ buildFolder ] ) ;
184
130
} ) ;
185
131
186
132
gulp . task ( 'compile' , function ( ) {
187
- runSequence (
188
- 'clean:dist' ,
189
- 'copy:source' ,
190
- 'inline-resources' ,
191
- 'ngc' ,
192
- 'rollup:fesm' ,
193
- 'rollup:umd' ,
194
- 'copy:build' ,
195
- 'copy:manifest' ,
196
- 'copy:readme' ,
197
- 'clean:build' ,
198
- 'clean:tmp' ,
199
- function ( err ) {
200
- if ( err ) {
201
- console . log ( 'ERROR:' , err . message ) ;
202
- deleteFolders ( [ distFolder , tmpFolder , buildFolder ] ) ;
203
- } else {
204
- console . log ( 'Compilation finished succesfully' ) ;
205
- }
206
- } ) ;
133
+ runSequence (
134
+ 'clean:dist' ,
135
+ 'copy:source' ,
136
+ 'inline-resources' ,
137
+ 'ngc' ,
138
+ 'rollup:umd' ,
139
+ 'copy:build' ,
140
+ 'copy:manifest' ,
141
+ 'copy:readme' ,
142
+ 'clean:build' ,
143
+ 'clean:tmp' ,
144
+ function ( err ) {
145
+ if ( err ) {
146
+ console . log ( 'ERROR:' , err . message ) ;
147
+ deleteFolders ( [ distFolder , tmpFolder , buildFolder ] ) ;
148
+ } else {
149
+ console . log ( 'Compilation finished succesfully' ) ;
150
+ }
151
+ } ) ;
207
152
} ) ;
208
153
209
154
/**
210
155
* Watch for any change in the /src folder and compile files
211
156
*/
212
157
gulp . task ( 'watch' , function ( ) {
213
- gulp . watch ( `${ srcFolder } /**/*` , [ 'compile' ] ) ;
158
+ gulp . watch ( `${ srcFolder } /**/*` , [ 'compile' ] ) ;
214
159
} ) ;
215
160
216
161
gulp . task ( 'clean' , [ 'clean:dist' , 'clean:tmp' , 'clean:build' ] ) ;
@@ -223,5 +168,5 @@ gulp.task('default', ['build:watch']);
223
168
* Deletes the specified folder
224
169
*/
225
170
function deleteFolders ( folders ) {
226
- return del ( folders ) ;
171
+ return del ( folders ) ;
227
172
}
0 commit comments