11import * as path from "path" ;
22import fs from "fs" ;
33import fsExtra from "fs-extra" ;
4+ import which from "which" ;
45import { parse } from "yaml" ;
56import { TreeObject } from "treeify" ;
67import { tmpdir } from "os" ;
@@ -175,22 +176,24 @@ export class PortalRecipeAction {
175176 stepName : string
176177 ) : Promise < Result < string , string > > {
177178 this . prompts . displayContentStepInfo ( ) ;
178- this . prompts . startProgressIndicatorWithMessage ( "Waiting for you to close the text editor" ) ;
179179 let editor = process . env . EDITOR ;
180180 let editorArgs : string [ ] = [ ] ;
181+ const tempFilePath = path . join ( tmpdir ( ) , `recipe-markdown-content-${ Date . now ( ) } .md` ) ;
182+ const template = `# The Heading Goes Here\n\nThis is placeholder text for your API Recipe content step. Feel free to edit this. Save your changes and then close the file once you're done.` ;
183+ await fsExtra . writeFile ( tempFilePath , template ) ;
181184
182185 try {
183- const tempFilePath = path . join ( tmpdir ( ) , `recipe-markdown-content-${ Date . now ( ) } .md` ) ;
184- const template = `# The Heading Goes Here\n\nThis is placeholder text for your API Recipe content step. Feel free to edit this. Save your changes and then close the file once you're done.` ;
185-
186- await fsExtra . writeFile ( tempFilePath , template ) ;
187-
188186 if ( ! editor ) {
189187 if ( process . platform === "win32" ) {
190188 await execa ( "cmd" , [ "/c" , "start" , "/wait" , "notepad" , tempFilePath ] , { stdio : "ignore" } ) ;
191- } else {
192- editor = "nano" ;
193- await execa ( editor , [ tempFilePath ] , { stdio : "ignore" } ) ;
189+ } else if ( process . platform === "darwin" || process . platform === "linux" ) {
190+ editor = "vim" ;
191+ try {
192+ await execa ( editor , [ tempFilePath ] , { stdio : "inherit" } ) ;
193+ }
194+ catch ( error ) {
195+ // User exiting vim can throw a non-zero exit code leading to exception, ignore it.
196+ }
194197 }
195198 } else {
196199 if ( editor === "code" || editor . endsWith ( "code.cmd" ) || editor . endsWith ( "code.exe" ) ) {
@@ -200,17 +203,17 @@ export class PortalRecipeAction {
200203 await execa ( editor , editorArgs , { stdio : "ignore" } ) ;
201204 }
202205
203- this . prompts . stopProgressIndicatorWithMessage ( "✅ Text editor closed." ) ;
204206 const fileContent = await fsExtra . readFile ( tempFilePath , "utf-8" ) ;
205-
206- await fsExtra . unlink ( tempFilePath ) ;
207-
208207 recipe . addContentStep ( stepName , stepName , fileContent ) ;
208+
209209 this . prompts . displayStepAddedSuccessfullyMessage ( ) ;
210210 return Result . success ( "Added content step successfully." ) ;
211211 } catch ( error ) {
212212 return Result . failure ( `Unable to add content step. Please try again later.` ) ;
213213 }
214+ finally {
215+ await fsExtra . unlink ( tempFilePath ) ;
216+ }
214217 }
215218
216219 private async promptUserAndAddEndpointStepToRecipe (
0 commit comments