1
- import { spawn } from 'child_process ' ;
1
+ import { spawn } from 'cross-spawn ' ;
2
2
import { copy , readFile , writeFile } from 'fs-extra' ;
3
3
import { prettySize } from 'pretty-size' ;
4
4
import { file as gzipSizeFile } from 'gzip-size' ;
@@ -44,7 +44,7 @@ function zoneWrapExports() {
44
44
} ) ;
45
45
const zoneWrapped = toBeExported . filter ( ( [ , , zoneWrap ] ) => zoneWrap ) ;
46
46
const rawExport = toBeExported . filter ( ( [ , , zoneWrap ] ) => ! zoneWrap ) ;
47
- await writeFile ( `./ src/ ${ module } /${ name } .ts`, `// DO NOT MODIFY, this file is autogenerated by tools/build.ts
47
+ await writeFile ( join ( process . cwd ( ) , ' src' , ` ${ module } /${ name } .ts`) , `// DO NOT MODIFY, this file is autogenerated by tools/build.ts
48
48
${ path . startsWith ( 'firebase/' ) ? `export * from '${ path } ';\n` : '' } ${
49
49
zoneWrapped . length > 0 ? `import { ɵzoneWrap } from '@angular/fire';
50
50
import {
@@ -109,13 +109,14 @@ ${zoneWrapped.map(([importName, exportName]) => `export const ${exportName} = ɵ
109
109
}
110
110
111
111
function webpackFirestoreProtos ( ) {
112
+ // TODO fix on windows
112
113
return new Promise < void > ( ( resolve , reject ) => {
113
114
glob ( './node_modules/@firebase/firestore/dist/src/protos/**/*.proto' , { } , async ( err , files ) => {
114
115
if ( err ) { reject ( err ) ; }
115
116
const fileLoader = files . map ( path =>
116
117
`require('file-loader?name=${ path . replace ( './node_modules/@firebase/firestore/dist/' , '' ) } !${ path . replace ( './node_modules/' , '../../' ) } ');`
117
118
) . join ( '\n' ) ;
118
- await writeFile ( './dist/packages-dist/ firestore-protos.js', fileLoader ) ;
119
+ await writeFile ( dest ( ' firestore-protos.js') , fileLoader ) ;
119
120
resolve ( ) ;
120
121
} ) ;
121
122
} ) ;
@@ -132,7 +133,7 @@ function proxyPolyfillCompat() {
132
133
} ;
133
134
134
135
return Promise . all ( Object . keys ( defaultObject ) . map ( module =>
135
- writeFile ( `./ src/ ${ module } /base.ts`, `// DO NOT MODIFY, this file is autogenerated by tools/build.ts
136
+ writeFile ( join ( process . cwd ( ) , ' src' , ` ${ module } /base.ts`) , `// DO NOT MODIFY, this file is autogenerated by tools/build.ts
136
137
// Export a null object with the same keys as firebase/${ module } , so Proxy can work with proxy-polyfill in Internet Explorer
137
138
export const proxyPolyfillCompat = {
138
139
${ defaultObject [ module ] . map ( it => ` ${ it } : null,` ) . join ( '\n' ) }
@@ -197,6 +198,7 @@ async function fixImportForLazyModules() {
197
198
const entries = Array . from ( new Set ( Object . values ( packageJson ) . filter ( v => typeof v === 'string' && v . endsWith ( '.js' ) ) ) ) as string [ ] ;
198
199
// TODO don't hardcode esm2015 here, perhaps we should scan all the entry directories
199
200
// e.g, if ng-packagr starts building other non-flattened entries we'll lose the dynamic import
201
+ // TODO fix in Windows
200
202
entries . push ( `../${ module . includes ( '/' ) ? '../' : '' } esm2015/${ module } /public_api.js` ) ;
201
203
await Promise . all ( entries . map ( async path => {
202
204
const source = ( await readFile ( dest ( module , path ) ) ) . toString ( ) ;
@@ -233,55 +235,72 @@ function measureLibrary() {
233
235
}
234
236
235
237
async function buildDocs ( ) {
236
- // INVESTIGATE json to stdout rather than FS?
237
- await Promise . all ( MODULES . map ( module => spawnPromise ( 'npx' , [ 'typedoc' , `${ module === 'core' ? './src' : `./src/${ module } ` } ` , '--json' , `./dist/typedocs/${ module } .json` ] ) ) ) ;
238
- const entries = await Promise . all ( MODULES . map ( async ( module ) => {
238
+ try {
239
+ // INVESTIGATE json to stdout rather than FS?
240
+ await Promise . all (
241
+ MODULES . map ( module =>
242
+ spawnPromise ( 'npx' , [ 'typedoc' ,
243
+ `${ module === 'core' ?
244
+ join ( process . cwd ( ) , 'src' ) :
245
+ join ( process . cwd ( ) , 'src' , module ) } `,
246
+ '--json' ,
247
+ join ( process . cwd ( ) , 'dist' , 'typedocs' , `${ module } .json` )
248
+ ] ) ) ) ;
249
+ const entries = await Promise . all ( MODULES . map ( async ( module ) => {
239
250
240
- const buffer = await readFile ( `./dist/typedocs/${ module } .json` ) ;
241
- const typedoc = JSON . parse ( buffer . toString ( ) ) ;
242
- if ( ! typedoc . children ) {
243
- console . error ( 'typedoc fail' , module ) ;
244
- }
245
- // TODO infer the entryPoint from the package.json
246
- const entryPoint = typedoc . children . find ( ( c : any ) => c . name === '"public_api"' ) ;
247
- const allChildren = [ ] . concat ( ...typedoc . children . map ( child =>
248
- // TODO chop out the working directory and filename
249
- child . children ? child . children . map ( c => ( { ...c , path : dirname ( child . originalName . split ( process . cwd ( ) ) [ 1 ] ) } ) ) : [ ]
250
- ) ) ;
251
- return ( entryPoint . children || [ ] )
252
- . filter ( c => c . name [ 0 ] !== 'ɵ' && c . name [ 0 ] !== '_' /* private */ )
253
- . map ( child => ( { ...allChildren . find ( c => child . target === c . id ) } ) )
254
- . reduce ( ( acc , child ) => ( { ...acc , [ encodeURIComponent ( child . name ) ] : child } ) , { } ) ;
255
- } ) ) ;
256
- const root = await rootPackage ;
257
- const pipes = [ 'MonoTypeOperatorFunction' , 'OperatorFunction' , 'AuthPipe' , 'UnaryFunction' ] ;
258
- const tocType = child => {
259
- const decorators : string [ ] = child . decorators && child . decorators . map ( d => d . name ) || [ ] ;
260
- if ( decorators . includes ( 'NgModule' ) ) {
261
- return 'NgModule' ;
262
- } else if ( child . kindString === 'Type alias' ) {
263
- return 'Type alias' ;
264
- } else if ( child . kindString === 'Variable' && child . defaultValue && child . defaultValue . startsWith ( 'new InjectionToken' ) ) {
265
- return 'InjectionToken' ;
266
- } else if ( child . type ) {
267
- return pipes . includes ( child . type . name ) ? 'Pipe' : child . type . name ;
268
- } else if ( child . signatures && child . signatures [ 0 ] && child . signatures [ 0 ] . type && pipes . includes ( child . signatures [ 0 ] . type . name ) ) {
269
- return 'Pipe' ;
270
- } else {
271
- return child . kindString ;
272
- }
273
- } ;
274
- const tableOfContents = entries . reduce ( ( acc , entry , index ) =>
275
- ( {
276
- ...acc , [ MODULES [ index ] ] : {
277
- name : ENTRY_NAMES [ index ] ,
278
- exports : Object . keys ( entry ) . reduce ( ( acc , key ) => ( { ...acc , [ key ] : tocType ( entry [ key ] ) } ) , { } )
279
- }
280
- } ) ,
281
- { }
282
- ) ;
283
- const afdoc = entries . reduce ( ( acc , entry , index ) => ( { ...acc , [ MODULES [ index ] ] : entry } ) , { table_of_contents : tableOfContents } ) ;
284
- return writeFile ( `./api-${ root . version } .json` , JSON . stringify ( afdoc , null , 2 ) ) ;
251
+ const buffer = await readFile ( join ( process . cwd ( ) , 'dist' , 'typedocs' , `${ module } .json` ) ) ;
252
+ const typedoc = JSON . parse ( buffer . toString ( ) ) ;
253
+ if ( ! typedoc . children ) {
254
+ console . error ( 'typedoc fail' , module ) ;
255
+ }
256
+ // TODO infer the entryPoint from the package.json
257
+ const entryPoint = typedoc . children . find ( ( c : any ) => c . name === '"public_api"' ) ;
258
+ const allChildren = [ ] . concat ( ...typedoc . children . map ( child =>
259
+ // TODO chop out the working directory and filename
260
+ child . children ?
261
+ child . children . map ( c => {
262
+ return { ...c , path : dirname ( child . originalName . split ( process . cwd ( ) ) [ 1 ] ) } ;
263
+ } ) :
264
+ [ ]
265
+ ) ) ;
266
+ return ( entryPoint . children || [ ] )
267
+ . filter ( c => c . name [ 0 ] !== 'ɵ' && c . name [ 0 ] !== '_' /* private */ )
268
+ . map ( child => ( { ...allChildren . find ( c => child . target === c . id ) } ) )
269
+ . reduce ( ( acc , child ) => ( { ...acc , [ encodeURIComponent ( child . name ) ] : child } ) , { } ) ;
270
+ } ) ) ;
271
+ const root = await rootPackage ;
272
+ const pipes = [ 'MonoTypeOperatorFunction' , 'OperatorFunction' , 'AuthPipe' , 'UnaryFunction' ] ;
273
+ const tocType = child => {
274
+ const decorators : string [ ] = child . decorators && child . decorators . map ( d => d . name ) || [ ] ;
275
+ if ( decorators . includes ( 'NgModule' ) ) {
276
+ return 'NgModule' ;
277
+ } else if ( child . kindString === 'Type alias' ) {
278
+ return 'Type alias' ;
279
+ } else if ( child . kindString === 'Variable' && child . defaultValue && child . defaultValue . startsWith ( 'new InjectionToken' ) ) {
280
+ return 'InjectionToken' ;
281
+ } else if ( child . type ) {
282
+ return pipes . includes ( child . type . name ) ? 'Pipe' : child . type . name ;
283
+ } else if ( child . signatures && child . signatures [ 0 ] && child . signatures [ 0 ] . type && pipes . includes ( child . signatures [ 0 ] . type . name ) ) {
284
+ return 'Pipe' ;
285
+ } else {
286
+ return child . kindString ;
287
+ }
288
+ } ;
289
+ const tableOfContents = entries . reduce ( ( acc , entry , index ) =>
290
+ ( {
291
+ ...acc , [ MODULES [ index ] ] : {
292
+ name : ENTRY_NAMES [ index ] ,
293
+ exports : Object . keys ( entry ) . reduce ( ( acc , key ) => ( { ...acc , [ key ] : tocType ( entry [ key ] ) } ) , { } )
294
+ }
295
+ } ) ,
296
+ { }
297
+ ) ;
298
+ const afdoc = entries . reduce ( ( acc , entry , index ) => ( { ...acc , [ MODULES [ index ] ] : entry } ) , { table_of_contents : tableOfContents } ) ;
299
+ return writeFile ( join ( process . cwd ( ) , `api-${ root . version } .json` ) , JSON . stringify ( afdoc , null , 2 ) ) ;
300
+ } catch ( e ) {
301
+ console . warn ( e ) ;
302
+ return Promise . resolve ( ) ;
303
+ }
285
304
}
286
305
287
306
Promise . all ( [
0 commit comments