@@ -30,6 +30,7 @@ var ts = require('gulp-typescript');
30
30
var del = require ( 'del' ) ;
31
31
var header = require ( 'gulp-header' ) ;
32
32
var replace = require ( 'gulp-replace' ) ;
33
+ var filter = require ( 'gulp-filter' ) ;
33
34
34
35
35
36
/****************/
@@ -50,12 +51,35 @@ var paths = {
50
51
] ,
51
52
52
53
build : 'lib/' ,
54
+
55
+ curatedTypings : [ 'src/*.d.ts' ] ,
53
56
} ;
54
57
55
- // Create a separate project for buildProject that overrides the rootDir
58
+ const TEMPORARY_TYPING_EXCLUDES = [
59
+ '!lib/default-namespace.d.ts' ,
60
+ '!lib/firebase-namespace.d.ts' ,
61
+ '!lib/firebase-app.d.ts' ,
62
+ '!lib/firebase-service.d.ts' ,
63
+ '!lib/auth/*.d.ts' ,
64
+ '!lib/database/*.d.ts' ,
65
+ '!lib/firestore/*.d.ts' ,
66
+ '!lib/instance-id/*.d.ts' ,
67
+ '!lib/machine-learning/*.d.ts' ,
68
+ '!lib/messaging/*.d.ts' ,
69
+ '!lib/project-management/*.d.ts' ,
70
+ '!lib/remote-config/*.d.ts' ,
71
+ '!lib/security-rules/*.d.ts' ,
72
+ '!lib/storage/*.d.ts' ,
73
+ '!lib/utils/*.d.ts'
74
+ ] ;
75
+
76
+ // Create a separate project for buildProject that overrides the rootDir.
56
77
// This ensures that the generated production files are in their own root
57
- // rather than including both src and test in the lib dir.
58
- var buildProject = ts . createProject ( 'tsconfig.json' , { rootDir : 'src' } ) ;
78
+ // rather than including both src and test in the lib dir. Declaration
79
+ // is used by TypeScript to determine if auto-generated typings should be
80
+ // emitted.
81
+ const declaration = process . env . TYPE_GENERATION_MODE === 'auto' ;
82
+ var buildProject = ts . createProject ( 'tsconfig.json' , { rootDir : 'src' , declaration } ) ;
59
83
60
84
var buildTest = ts . createProject ( 'tsconfig.json' ) ;
61
85
@@ -71,16 +95,36 @@ gulp.task('cleanup', function() {
71
95
] ) ;
72
96
} ) ;
73
97
98
+ // Task used to compile the TypeScript project. If automatic typings
99
+ // are set to be generated (determined by TYPE_GENERATION_MODE), declarations
100
+ // for files terminating in -internal.d.ts are removed because we do not
101
+ // want to expose internally used types to developers. As auto-generated
102
+ // typings are a work-in-progress, we remove the *.d.ts files for modules
103
+ // which we do not intend to auto-generate typings for yet.
74
104
gulp . task ( 'compile' , function ( ) {
75
- return gulp . src ( paths . src )
105
+ let workflow = gulp . src ( paths . src )
76
106
// Compile Typescript into .js and .d.ts files
77
107
. pipe ( buildProject ( ) )
78
108
79
109
// Add header
80
- . pipe ( header ( banner ) )
81
-
82
- // Write to build directory
83
- . pipe ( gulp . dest ( paths . build ) )
110
+ . pipe ( header ( banner ) ) ;
111
+
112
+ // Exclude typings that are unintended (currently excludes all auto-generated
113
+ // typings, but as services are refactored to auto-generate typings this will
114
+ // change). Moreover, all *-internal.d.ts typings should not be exposed to
115
+ // developers as it denotes internally used types.
116
+ if ( declaration ) {
117
+ const configuration = [
118
+ 'lib/**/*.js' ,
119
+ 'lib/**/*.d.ts' ,
120
+ '!lib/**/*-internal.d.ts' ,
121
+ ] . concat ( TEMPORARY_TYPING_EXCLUDES ) ;
122
+
123
+ workflow = workflow . pipe ( filter ( configuration ) ) ;
124
+ }
125
+
126
+ // Write to build directory
127
+ return workflow . pipe ( gulp . dest ( paths . build ) )
84
128
} ) ;
85
129
86
130
/**
@@ -104,19 +148,23 @@ gulp.task('copyDatabase', function() {
104
148
} ) ;
105
149
106
150
gulp . task ( 'copyTypings' , function ( ) {
107
- return gulp . src ( 'src/*.d.ts' )
151
+ let workflow = gulp . src ( 'src/*.d.ts' )
108
152
// Add header
109
- . pipe ( header ( banner ) )
110
-
111
- // Write to build directory
112
- . pipe ( gulp . dest ( paths . build ) )
153
+ . pipe ( header ( banner ) ) ;
154
+
155
+ if ( declaration ) {
156
+ workflow = workflow . pipe ( filter ( paths . curatedTypings ) ) ;
157
+ }
158
+
159
+ // Write to build directory
160
+ return workflow . pipe ( gulp . dest ( paths . build ) )
113
161
} ) ;
114
162
115
163
gulp . task ( 'compile_all' , gulp . series ( 'compile' , 'copyDatabase' , 'copyTypings' , 'compile_test' ) ) ;
116
164
117
165
// Regenerates js every time a source file changes
118
166
gulp . task ( 'watch' , function ( ) {
119
- gulp . watch ( paths . src . concat ( paths . test ) , { ignoreInitial : false } , gulp . series ( 'compile_all' ) ) ;
167
+ gulp . watch ( paths . src . concat ( paths . test ) , { ignoreInitial : false } , gulp . series ( 'compile_all' ) ) ;
120
168
} ) ;
121
169
122
170
// Build task
0 commit comments