@@ -92,7 +92,7 @@ const patternlab_module = function(config) {
9292 * @see {@link ./events.md|all events }
9393 * @returns {Promise } a promise fulfilled when build is complete
9494 */
95- build : function ( options ) {
95+ build : async function ( options ) {
9696 // process.on('unhandledRejection', (reason, p) => {
9797 // console.log('Unhandled Rejection at: Promise', p, 'reason:', reason);
9898 // // application specific logging, throwing an error, or other logic here
@@ -109,53 +109,51 @@ const patternlab_module = function(config) {
109109 }
110110 patternlab . isBusy = true ;
111111
112- return buildPatterns ( options . cleanPublic , patternlab , options . data ) . then (
113- ( ) => {
114- return new ui_builder ( ) . buildFrontend ( patternlab ) . then ( ( ) => {
115- copier ( )
116- . copyAndWatch ( patternlab . config . paths , patternlab , options )
117- . then ( ( ) => {
118- patternlab . isBusy = false ;
119- // only wire up this listener and the one inside serve.js
120- // figure out how to detect if serve was called. we should not assume it was
121- if (
122- patternlab . serverReady //check for server presence
123- ? this . events . listenerCount (
124- events . PATTERNLAB_PATTERN_CHANGE
125- ) === 1 //if the server is started, it has already setup one listener
126- : ! this . events . listenerCount (
127- events . PATTERNLAB_PATTERN_CHANGE
128- ) // else, check for the presnce of none
129- ) {
130- this . events . on ( events . PATTERNLAB_PATTERN_CHANGE , ( ) => {
131- if ( ! patternlab . isBusy ) {
132- return this . build ( options ) . then ( ( ) => {
133- patternlab . isBusy = false ;
134- } ) ;
135- }
136- return Promise . resolve ( ) ;
137- } ) ;
138- }
112+ return await buildPatterns (
113+ options . cleanPublic ,
114+ patternlab ,
115+ options . data
116+ ) . then ( ( ) => {
117+ return new ui_builder ( ) . buildFrontend ( patternlab ) . then ( ( ) => {
118+ copier ( )
119+ . copyAndWatch ( patternlab . config . paths , patternlab , options )
120+ . then ( ( ) => {
121+ patternlab . isBusy = false ;
122+ // only wire up this listener and the one inside serve.js
123+ // figure out how to detect if serve was called. we should not assume it was
124+ if (
125+ patternlab . serverReady //check for server presence
126+ ? this . events . listenerCount (
127+ events . PATTERNLAB_PATTERN_CHANGE
128+ ) === 1 //if the server is started, it has already setup one listener
129+ : ! this . events . listenerCount ( events . PATTERNLAB_PATTERN_CHANGE ) // else, check for the presnce of none
130+ ) {
131+ this . events . on ( events . PATTERNLAB_PATTERN_CHANGE , ( ) => {
132+ if ( ! patternlab . isBusy ) {
133+ return this . build ( options ) . then ( ( ) => {
134+ patternlab . isBusy = false ;
135+ } ) ;
136+ }
137+ return Promise . resolve ( ) ;
138+ } ) ;
139+ }
139140
140- if (
141- ! this . events . listenerCount ( events . PATTERNLAB_GLOBAL_CHANGE )
142- ) {
143- this . events . on ( events . PATTERNLAB_GLOBAL_CHANGE , ( ) => {
144- if ( ! patternlab . isBusy ) {
145- return this . build (
146- Object . assign ( { } , options , { cleanPublic : true } ) // rebuild everything
147- ) ;
148- }
149- return Promise . resolve ( ) ;
150- } ) ;
151- }
152- } )
153- . then ( ( ) => {
154- this . events . emit ( events . PATTERNLAB_BUILD_END , patternlab ) ;
155- } ) ;
156- } ) ;
157- }
158- ) ;
141+ if ( ! this . events . listenerCount ( events . PATTERNLAB_GLOBAL_CHANGE ) ) {
142+ this . events . on ( events . PATTERNLAB_GLOBAL_CHANGE , ( ) => {
143+ if ( ! patternlab . isBusy ) {
144+ return this . build (
145+ Object . assign ( { } , options , { cleanPublic : true } ) // rebuild everything
146+ ) ;
147+ }
148+ return Promise . resolve ( ) ;
149+ } ) ;
150+ }
151+ } )
152+ . then ( ( ) => {
153+ this . events . emit ( events . PATTERNLAB_BUILD_END , patternlab ) ;
154+ } ) ;
155+ } ) ;
156+ } ) ;
159157 } ,
160158
161159 /**
@@ -194,7 +192,7 @@ const patternlab_module = function(config) {
194192 installplugin : function ( pluginName ) {
195193 //get the config
196194 const configPath = path . resolve ( process . cwd ( ) , 'patternlab-config.json' ) ;
197- const plugin_manager = new pm ( config , configPath ) ;
195+ const plugin_manager = new pm ( ) ;
198196
199197 plugin_manager . install_plugin ( pluginName ) ;
200198 } ,
@@ -236,19 +234,21 @@ const patternlab_module = function(config) {
236234 * @param {bool } [options.watch=true] whether or not Pattern Lab should watch configured `source/` directories for changes to rebuild
237235 * @returns {Promise } a promise fulfilled when build is complete
238236 */
239- patternsonly : function ( options ) {
237+ patternsonly : async function ( options ) {
240238 if ( patternlab && patternlab . isBusy ) {
241239 logger . info (
242240 'Pattern Lab is busy building a previous run - returning early.'
243241 ) ;
244242 return Promise . resolve ( ) ;
245243 }
246244 patternlab . isBusy = true ;
247- return buildPatterns ( options . cleanPublic , patternlab , options . data ) . then (
248- ( ) => {
249- patternlab . isBusy = false ;
250- }
251- ) ;
245+ return await buildPatterns (
246+ options . cleanPublic ,
247+ patternlab ,
248+ options . data
249+ ) . then ( ( ) => {
250+ patternlab . isBusy = false ;
251+ } ) ;
252252 } ,
253253
254254 /**
0 commit comments