import { Disposable , InputBox , QuickInputButtons , window } from "vscode" ; import { IProjectCreationMetadata , IProjectCreationStep , StepResult } from "./types" ; export class SpecifyArtifactIdStep implements IProjectCreationStep { public previousStep ? : IProjectCreationStep ; public async run ( metadata ) { const disposables = [ ] ; const quickInputPromise = new Promise < StepResult > ( ( resolve , reject ) => { const inputBox = window . createInputBox ( ) ; inputBox . title = "Create Maven Project" ; inputBox . placeholder = "e.g. demo" ; inputBox . prompt = "Input artifact Id of your project." ; inputBox . value = metadata . artifactId ?? "demo" ; inputBox . ignoreFocusOut = true ; if ( this . previousStep ) { inputBox . buttons = [ ( QuickInputButtons . Back ) ] ; disposables . push ( inputBox . onDidTriggerButton ( ( item ) => { if ( item === QuickInputButtons . Back ) { resolve ( StepResult . PREVIOUS ) ; } } ) ) ; } disposables . push ( inputBox . onDidChangeValue ( ( ) => { const validationMessage = this . artifactIdValidation ( inputBox . value ) ; inputBox . enabled = validationMessage === undefined ; inputBox . validationMessage = validationMessage ; } ) , inputBox . onDidAccept ( ( ) => { if ( ! inputBox . enabled ) { reject ( "Invalid artifactId submitted." ) ; } metadata . artifactId = inputBox . value ; resolve ( StepResult . NEXT ) ; } ) , inputBox . onDidHide ( ( ) => { resolve ( StepResult . STOP ) ; } ) ) ; disposables . push ( inputBox ) ; inputBox . show ( ) ; } ) ; try { return await quickInputPromise ; } finally { disposables . forEach ( d => d . dispose ( ) ) ; } } private artifactIdValidation ( value ) { return ( /^[a-z_][a-z0-9_]*(-[a-z_][a-z0-9_]*)*$/ . test ( value ) ) ? undefined : "Invalid Artifact Id" ; } }