17
17
const debug = require ( 'debug' ) ( 'app preview' )
18
18
debug ( 'loading' )
19
19
20
- const { isValidFSM, wskflow, zoomToFitButtons, vizAndfsmViewModes, codeViewMode, handleError } = require ( './composer' ) ,
20
+ const { isValidFSM, wskflow, zoomToFitButtons, vizAndfsmViewModes, codeViewMode, handleError, optionsToString } = require ( './composer' ) ,
21
21
badges = require ( './badges' ) ,
22
22
{ readFSMFromDisk, compileToFSM } = require ( './create-from-source' ) ,
23
23
messages = require ( './messages' ) ,
@@ -111,14 +111,19 @@ module.exports = (commandTree, prequire) => {
111
111
entity . type = 'actions'
112
112
}
113
113
114
- if ( options . alreadyWatching && entity . type === 'custom' ) {
114
+ if ( execOptions . alreadyWatching ) {
115
115
// in filewatch mode (alreadyWatching), command echo is set to false
116
- // calling ui.showCustom as the main repl does not do anything for custom type entity when echo is false
117
- ui . showCustom ( entity ) ;
118
- }
116
+ // calling ui.showCustom as the main repl does not do anything for custom type entity when echo is false
117
+ if ( entity . type === 'custom' ) {
118
+ ui . showCustom ( entity ) ;
119
+ }
120
+ else {
121
+ ui . showEntity ( entity , { show : 'fsm' } )
122
+ }
123
+ }
119
124
else {
120
- resolve ( entity ) ;
121
- }
125
+ resolve ( entity )
126
+ }
122
127
123
128
}
124
129
fsmPromise . then ( formatForUser ( defaultMode ) )
@@ -127,14 +132,13 @@ module.exports = (commandTree, prequire) => {
127
132
// start rendering an empty JSON
128
133
formatForUser ( defaultMode ) ( { } )
129
134
130
- } else if ( options . alreadyWatching ) {
135
+ } else if ( execOptions . alreadyWatching ) {
131
136
// we already have the sidecar open to this file,
132
137
// so we can report the error in the sidecar
133
138
134
139
// createFromSource returns error as either an object that's {fsm:errMsg, code:originalCode}, or just the errMsg string
135
140
// here we check the error format and send the correct input to formatForUser/handleError
136
141
// in sidecar, error message shows in the fsm (JSON) tab. code tab shows the user's js code (if existed).
137
-
138
142
if ( err . fsm )
139
143
formatForUser ( 'fsm' ) ( err ) ;
140
144
else
@@ -176,18 +180,14 @@ module.exports = (commandTree, prequire) => {
176
180
delete options . e
177
181
178
182
debug ( 'environment' , environment )
179
- }
180
-
181
- if ( execOptions . alreadyWatching ) {
182
- options . alreadyWatching = execOptions . alreadyWatching ;
183
- }
183
+ }
184
184
185
185
render ( input , options , execOptions ) . then ( resolve , reject )
186
186
187
187
// and set up a file watcher to re-render upon change of the file
188
188
if ( ! execOptions || ! execOptions . alreadyWatching ) {
189
189
chokidar . watch ( expandHomeDir ( input ) ) . on ( 'change' , path => {
190
- repl . pexec ( `preview ${ path } ` , { echo : false , alreadyWatching : true } )
190
+ repl . pexec ( `preview ${ path } ${ optionsToString ( options ) } ` , { echo : false , alreadyWatching : true , noHistory : true } )
191
191
} )
192
192
}
193
193
} )
0 commit comments