11import * as _ from 'lodash' ;
22
33import { App , Archivable , BuildOpts , Buildable } from '../types' ;
4- import Install , { Pkg , configureDeclarations , pieToConfigureMap , toDeclarations } from '../../install' ;
4+ import Install , {
5+ Pkg ,
6+ configureDeclarations ,
7+ pieToConfigureMap ,
8+ toDeclarations
9+ } from '../../install' ;
510import { Names , getNames , webpackConfig } from '../common' ;
611import { archiveIgnores , createArchive } from '../create-archive' ;
7- import { existsSync , writeFileSync , readFileSync , readJsonSync } from 'fs-extra' ;
12+ import {
13+ existsSync ,
14+ writeFileSync ,
15+ readFileSync ,
16+ readJsonSync
17+ } from 'fs-extra' ;
818import { join , resolve } from 'path' ;
919import { JsonConfig } from '../../question/config' ;
1020import { SupportConfig } from '../../framework-support' ;
@@ -23,29 +33,36 @@ const logger = buildLogger();
2333 */
2434export default class CatalogApp
2535 implements App , Archivable < Pkg [ ] > , Buildable < Pkg [ ] , BuildOpts > {
26-
27- public static generatedFiles : string [ ] = [ 'pie-item.tar.gz' , 'pie-catalog.bundle.js' ] ;
28-
29- public static build ( args : any , loadSupport : ( JsonConfig ) => Promise < SupportConfig > ) : Promise < App > {
36+ public static generatedFiles : string [ ] = [
37+ 'pie-item.tar.gz' ,
38+ 'pie-catalog.bundle.js'
39+ ] ;
40+
41+ public static build (
42+ args : any ,
43+ loadSupport : ( JsonConfig ) => Promise < SupportConfig >
44+ ) : Promise < App > {
3045 const dir = resolve ( args . dir || process . cwd ( ) ) ;
3146 if ( ! existsSync ( join ( dir , 'docs/demo' ) ) ) {
32- throw new Error ( `Can't find a 'docs/demo' directory in path: ${ dir } . Is this a pie directory?` ) ;
47+ throw new Error (
48+ `Can't find a 'docs/demo' directory in path: ${ dir } . Is this a pie directory?`
49+ ) ;
3350 }
3451
3552 const config = JsonConfig . build ( join ( dir , 'docs/demo' ) , args ) ;
3653
37- return loadSupport ( config )
38- . then ( ( s ) => {
39- return new CatalogApp ( args , dir , config , s , getNames ( args ) ) ;
40- } ) ;
54+ return loadSupport ( config ) . then ( s => {
55+ return new CatalogApp ( args , dir , config , s , getNames ( args ) ) ;
56+ } ) ;
4157 }
4258
4359 private static ENTRY = 'catalog.entry.js' ;
4460 private static BUNDLE = 'pie-catalog.bundle.js' ;
4561 private static WEBPACK_CONFIG = 'catalog.webpack.config.js' ;
4662
4763 private static EXTERNALS = {
48- 'lodash' : '_' ,
64+ // tslint:disable-next-line:object-literal-key-quotes
65+ lodash : '_' ,
4966 'lodash.merge' : '_.merge' ,
5067 'lodash/assign' : '_.assign' ,
5168 'lodash/cloneDeep' : '_.cloneDeep' ,
@@ -55,20 +72,24 @@ export default class CatalogApp
5572 'lodash/isEqual' : '_.isEqual' ,
5673 'lodash/map' : '_.map' ,
5774 'lodash/merge' : '_.merge' ,
58- 'react' : 'React' ,
75+ // tslint:disable-next-line:object-literal-key-quotes
76+ react : 'React' ,
5977 'react-addons-transition-group' : 'React.addons.TransitionGroup' ,
6078 'react-dom' : 'ReactDOM' ,
79+ 'react-dom/server' : 'ReactDOMServer' ,
6180 'react/lib/ReactCSSTransitionGroup' : 'React.addons.CSSTransitionGroup' ,
6281 'react/lib/ReactTransitionGroup' : 'React.addons.TransitionGroup'
6382 } ;
6483
6584 private installer : Install ;
6685
67- constructor ( readonly args : any ,
86+ constructor (
87+ readonly args : any ,
6888 private pieRoot : string ,
6989 readonly config : JsonConfig ,
7090 readonly support : SupportConfig ,
71- readonly names : Names ) {
91+ readonly names : Names
92+ ) {
7293 this . installer = new Install ( config . dir , config . raw ) ;
7394 }
7495
@@ -77,30 +98,39 @@ export default class CatalogApp
7798 }
7899
79100 public async build ( opts : BuildOpts ) : Promise < Pkg [ ] > {
80-
81101 const { dirs, pkgs } = await this . installer . install ( opts . forceInstall ) ;
82102
83103 const js = `
84104 //controllers
85105 let controllers = window.controllers = {};
86- ${ pkgs . map ( bi => controllerDependency ( bi . element . tag , bi . controller . moduleId ) ) . join ( '\n' ) }
106+ ${ pkgs
107+ . map ( bi => controllerDependency ( bi . element . tag , bi . controller . moduleId ) )
108+ . join ( '\n' ) }
87109 //custom elements
88- ${ toDeclarations ( pkgs ) . map ( ( d ) => d . js ) . join ( '\n' ) }
110+ ${ toDeclarations ( pkgs )
111+ . map ( d => d . js )
112+ . join ( '\n' ) }
89113
90114 //configure elements
91- ${ configureDeclarations ( pkgs ) . map ( e => e . js ) . join ( '\n' ) }
115+ ${ configureDeclarations ( pkgs )
116+ . map ( e => e . js )
117+ . join ( '\n' ) }
92118 ` ;
93119
94120 writeFileSync ( join ( dirs . root , CatalogApp . ENTRY ) , js , 'utf8' ) ;
95121
96- const config = _ . merge ( webpackConfig (
97- dirs ,
98- this . support ,
99- CatalogApp . ENTRY ,
100- CatalogApp . BUNDLE ,
101- this . config . dir ) , {
122+ const config = _ . merge (
123+ webpackConfig (
124+ dirs ,
125+ this . support ,
126+ CatalogApp . ENTRY ,
127+ CatalogApp . BUNDLE ,
128+ this . config . dir
129+ ) ,
130+ {
102131 externals : CatalogApp . EXTERNALS
103- } ) ;
132+ }
133+ ) ;
104134
105135 logger . silly ( 'config: ' , config ) ;
106136
@@ -118,13 +148,16 @@ export default class CatalogApp
118148 }
119149 ] . concat ( config . module . rules ) ;
120150
121- await report . promise ( 'building webpack' , buildWebpack ( config , CatalogApp . WEBPACK_CONFIG ) ) ;
151+ await report . promise (
152+ 'building webpack' ,
153+ buildWebpack ( config , CatalogApp . WEBPACK_CONFIG )
154+ ) ;
122155
123156 return pkgs ;
124157 }
125158
126159 public async createArchive ( buildInfo : Pkg [ ] ) : Promise < string > {
127- const root = ( name ) => resolve ( join ( this . pieRoot , name ) ) ;
160+ const root = name => resolve ( join ( this . pieRoot , name ) ) ;
128161 const archivePath = resolve ( join ( this . config . dir , this . names . out . archive ) ) ;
129162 const pkg = readJsonSync ( root ( 'package.json' ) ) ;
130163
@@ -138,14 +171,24 @@ export default class CatalogApp
138171 logger . silly ( 'tag' , tag , 'hash' , hash , 'shorthash' , shortHash ) ;
139172
140173 if ( ! repository || ! npm ) {
141- return Promise . reject ( new Error ( 'The package.json is missing `repository` and `name` fields' ) ) ;
174+ return Promise . reject (
175+ new Error ( 'The package.json is missing `repository` and `name` fields' )
176+ ) ;
142177 }
143178
144179 /* TODO: ignore config/markup? */
145180 const ignores = archiveIgnores ( this . config . dir ) ;
146181
147- logger . silly ( 'call createArchive' , archivePath , this . config . dir , ignores , addExtras ) ;
148- const readme = existsSync ( root ( 'README.md' ) ) ? readFileSync ( root ( 'README.md' ) , 'utf8' ) : '' ;
182+ logger . silly (
183+ 'call createArchive' ,
184+ archivePath ,
185+ this . config . dir ,
186+ ignores ,
187+ addExtras
188+ ) ;
189+ const readme = existsSync ( root ( 'README.md' ) )
190+ ? readFileSync ( root ( 'README.md' ) , 'utf8' )
191+ : '' ;
149192
150193 const git = {
151194 hash,
@@ -154,15 +197,24 @@ export default class CatalogApp
154197 } ;
155198 const schemas = buildSchemas ( root ( 'docs/schemas' ) ) ;
156199 logger . silly ( 'callAddExtras...' ) ;
157- const ae = addExtras ( this . config . raw , this . config . markup , this . support ,
158- buildInfo , pkg , npm , readme , repository , git , schemas ) ;
159- return createArchive ( archivePath , this . config . dir , ignores , ae )
160- . catch ( ( e ) => {
161- const msg = `Error creating the archive: ${ e . message } ` ;
162- logger . error ( msg ) ;
163- logger . info ( e . stack ) ;
164- throw new Error ( msg ) ;
165- } ) ;
200+ const ae = addExtras (
201+ this . config . raw ,
202+ this . config . markup ,
203+ this . support ,
204+ buildInfo ,
205+ pkg ,
206+ npm ,
207+ readme ,
208+ repository ,
209+ git ,
210+ schemas
211+ ) ;
212+ return createArchive ( archivePath , this . config . dir , ignores , ae ) . catch ( e => {
213+ const msg = `Error creating the archive: ${ e . message } ` ;
214+ logger . error ( msg ) ;
215+ logger . info ( e . stack ) ;
216+ throw new Error ( msg ) ;
217+ } ) ;
166218 }
167219}
168220
@@ -176,32 +228,32 @@ export const addExtras = (
176228 readme : string ,
177229 repository : any ,
178230 git : any ,
179- schemas : any [ ] ) => ( archive : any ) : void => {
180-
181- const catalog = {
182- demo : {
183- config,
184- configureMap : pieToConfigureMap ( pkgs ) ,
185- externals : support . externals ,
186- markup,
187- } ,
188- npm,
189- package : pkg ,
190- readme,
191- repository,
192- schemas,
193- version : {
194- git,
195- pkg : pkg . version ,
196- }
197- } ;
198-
199- const catalogString = JSON . stringify ( catalog , null , ' ' ) ;
200- logger . silly ( 'catalog json: ' , catalogString ) ;
201- logger . silly ( 'archive: ' , archive ) ;
202- /**
203- * It is important that the catalog json is the first entry in the tar,
204- * so that the upload stream will consume this entry first.
205- */
206- archive . append ( catalogString , { name : 'pie-catalog-data.json' } ) ;
231+ schemas : any [ ]
232+ ) => ( archive : any ) : void => {
233+ const catalog = {
234+ demo : {
235+ config,
236+ configureMap : pieToConfigureMap ( pkgs ) ,
237+ externals : support . externals ,
238+ markup
239+ } ,
240+ npm,
241+ package : pkg ,
242+ readme,
243+ repository,
244+ schemas,
245+ version : {
246+ git,
247+ pkg : pkg . version
248+ }
207249 } ;
250+
251+ const catalogString = JSON . stringify ( catalog , null , ' ' ) ;
252+ logger . silly ( 'catalog json: ' , catalogString ) ;
253+ logger . silly ( 'archive: ' , archive ) ;
254+ /**
255+ * It is important that the catalog json is the first entry in the tar,
256+ * so that the upload stream will consume this entry first.
257+ */
258+ archive . append ( catalogString , { name : 'pie-catalog-data.json' } ) ;
259+ } ;
0 commit comments