11import { command } from 'yargs'
22import { logInfoWithBackground , logError } from '../utilities/log'
3- import { flatMap , map , first , filter , tap } from 'rxjs/operators'
3+ import { flatMap , map , filter , tap , take , first } from 'rxjs/operators'
44import { rxFavicons } from '../utilities/rx-favicon'
5- import { writeFile_ , mkDirDeep_ , writeJsonFile_ } from '../utilities/rx-fs'
5+ import {
6+ writeFile_ ,
7+ mkDirDeep_ ,
8+ writeJsonFile_ ,
9+ mkDirAndContinueIfExists_
10+ } from '../utilities/rx-fs'
611import { resolve } from 'path'
712import { forkJoin } from 'rxjs'
813import readConfig_ , {
@@ -18,7 +23,12 @@ command(
1823 return args
1924 } ,
2025 args => {
21- favicon ( )
26+ favicon_ ( '.' )
27+ . pipe (
28+ first ( ) ,
29+ take ( 1 )
30+ )
31+ . subscribe ( logFaviconComplete , logError )
2232 }
2333)
2434
@@ -51,54 +61,55 @@ interface configModel {
5161 readonly result : FavIconResponse
5262}
5363
54- function mapResponsesToWriteableObservables ( response : configModel ) {
55- return readConfig_ ( ) . pipe (
56- flatMap ( config => {
57- const _confg = {
58- ...config ,
59- generatedMetaTags : response . result . html
60- }
61- return writeJsonFile_ ( resolve ( 'fusing-angular.json' ) , _confg , true )
62- } ) ,
63- flatMap ( ( ) => {
64- return forkJoin (
65- ...response . result . files . map ( file =>
66- writeFile_ (
67- resolve ( `${ response . config . output } /${ file . name } ` ) ,
68- file . contents
64+ function mapResponsesToWriteableObservables ( baseDir = '' ) {
65+ return function ( response : configModel ) {
66+ return readConfig_ ( baseDir ) . pipe (
67+ map ( config => {
68+ return {
69+ ...config ,
70+ generatedMetaTags : response . result . html
71+ }
72+ } ) ,
73+ flatMap ( config =>
74+ writeJsonFile_ ( resolve ( baseDir , 'fusing-angular.json' ) , config , true )
75+ ) ,
76+ flatMap ( ( ) =>
77+ mkDirAndContinueIfExists_ ( resolve ( baseDir , `${ response . config . output } ` ) )
78+ ) ,
79+ flatMap ( ( ) => {
80+ return forkJoin ( [
81+ ...response . result . files . map ( file =>
82+ writeFile_ (
83+ resolve ( baseDir , `${ response . config . output } /${ file . name } ` ) ,
84+ file . contents
85+ )
86+ ) ,
87+ ...response . result . images . map ( file =>
88+ writeFile_ (
89+ resolve ( baseDir , `${ response . config . output } /${ file . name } ` ) ,
90+ file . contents
91+ )
6992 )
70- )
71- )
72- } ) ,
73- map ( ( ) => {
74- return response . result . images . map ( file =>
75- writeFile_ (
76- resolve ( `${ response . config . output } /${ file . name } ` ) ,
77- file . contents
78- )
79- )
80- } )
81- )
93+ ] )
94+ } )
95+ )
96+ }
8297}
8398
84- function favicon ( ) {
85- readConfig_ ( )
86- . pipe (
87- tap ( logFaviconStart ) ,
88- filter ( requireFaviconConfig ) ,
89- map ( mapFaviconConfig ) ,
90- flatMap ( rxFavicons , ( config : FaviconConfig , result ) => ( {
91- config,
92- result
93- } ) ) ,
94- tap ( logDirectoryCheck ) ,
95- flatMap (
96- response => mkDirDeep_ ( response . config . output ) ,
97- response => ( { ...response } )
98- ) ,
99- map ( mapResponsesToWriteableObservables ) ,
100- flatMap ( fileWriteObs => forkJoin ( fileWriteObs ) ) ,
101- first ( )
102- )
103- . subscribe ( logFaviconComplete , logError )
99+ export function favicon_ ( path ?: string ) {
100+ return readConfig_ ( path ) . pipe (
101+ tap ( logFaviconStart ) ,
102+ filter ( requireFaviconConfig ) ,
103+ map ( mapFaviconConfig ) ,
104+ flatMap ( rxFavicons ( path ) , ( config : FaviconConfig , result ) => ( {
105+ config,
106+ result
107+ } ) ) ,
108+ tap ( logDirectoryCheck ) ,
109+ // flatMap(
110+ // response => mkDirDeep_(resolve(path || '', response.config.output)),
111+ // response => ({ ...response })
112+ // ),
113+ flatMap ( mapResponsesToWriteableObservables ( path ) )
114+ )
104115}
0 commit comments