1- import { spawn } from 'child_process ' ;
1+ import { spawn } from 'cross-spawn ' ;
22import { copy , readFile , writeFile } from 'fs-extra' ;
33import { prettySize } from 'pretty-size' ;
44import { file as gzipSizeFile } from 'gzip-size' ;
@@ -44,7 +44,7 @@ function zoneWrapExports() {
4444 } ) ;
4545 const zoneWrapped = toBeExported . filter ( ( [ , , zoneWrap ] ) => zoneWrap ) ;
4646 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
4848${ path . startsWith ( 'firebase/' ) ? `export * from '${ path } ';\n` : '' } ${
4949zoneWrapped . length > 0 ? `import { ɵzoneWrap } from '@angular/fire';
5050import {
@@ -109,13 +109,14 @@ ${zoneWrapped.map(([importName, exportName]) => `export const ${exportName} = ɵ
109109}
110110
111111function webpackFirestoreProtos ( ) {
112+ // TODO fix on windows
112113 return new Promise < void > ( ( resolve , reject ) => {
113114 glob ( './node_modules/@firebase/firestore/dist/src/protos/**/*.proto' , { } , async ( err , files ) => {
114115 if ( err ) { reject ( err ) ; }
115116 const fileLoader = files . map ( path =>
116117 `require('file-loader?name=${ path . replace ( './node_modules/@firebase/firestore/dist/' , '' ) } !${ path . replace ( './node_modules/' , '../../' ) } ');`
117118 ) . join ( '\n' ) ;
118- await writeFile ( './dist/packages-dist/ firestore-protos.js', fileLoader ) ;
119+ await writeFile ( dest ( ' firestore-protos.js') , fileLoader ) ;
119120 resolve ( ) ;
120121 } ) ;
121122 } ) ;
@@ -132,7 +133,7 @@ function proxyPolyfillCompat() {
132133 } ;
133134
134135 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
136137// Export a null object with the same keys as firebase/${ module } , so Proxy can work with proxy-polyfill in Internet Explorer
137138export const proxyPolyfillCompat = {
138139${ defaultObject [ module ] . map ( it => ` ${ it } : null,` ) . join ( '\n' ) }
@@ -197,6 +198,7 @@ async function fixImportForLazyModules() {
197198 const entries = Array . from ( new Set ( Object . values ( packageJson ) . filter ( v => typeof v === 'string' && v . endsWith ( '.js' ) ) ) ) as string [ ] ;
198199 // TODO don't hardcode esm2015 here, perhaps we should scan all the entry directories
199200 // e.g, if ng-packagr starts building other non-flattened entries we'll lose the dynamic import
201+ // TODO fix in Windows
200202 entries . push ( `../${ module . includes ( '/' ) ? '../' : '' } esm2015/${ module } /public_api.js` ) ;
201203 await Promise . all ( entries . map ( async path => {
202204 const source = ( await readFile ( dest ( module , path ) ) ) . toString ( ) ;
@@ -233,55 +235,72 @@ function measureLibrary() {
233235}
234236
235237async 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 ) => {
239250
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+ }
285304}
286305
287306Promise . all ( [
0 commit comments