4
4
import * as fse from "fs-extra" ;
5
5
import * as _ from "lodash" ;
6
6
import * as path from "path" ;
7
+ import * as semver from "semver" ;
7
8
import { commands , Disposable , Extension , ExtensionContext , extensions , QuickPickItem , Uri , window , workspace } from "vscode" ;
8
9
import { instrumentOperationAsVsCodeCommand } from "vscode-extension-telemetry-wrapper" ;
9
10
import { Commands } from "../commands" ;
@@ -58,6 +59,8 @@ export class ProjectController implements Disposable {
58
59
59
60
if ( choice . metadata . type === ProjectType . NoBuildTool ) {
60
61
await scaffoldSimpleProject ( this . context ) ;
62
+ } else if ( choice . metadata . createCommandId && choice . metadata . createCommandArgs ) {
63
+ await commands . executeCommand ( choice . metadata . createCommandId , ...choice . metadata . createCommandArgs ) ;
61
64
} else if ( choice . metadata . createCommandId ) {
62
65
await commands . executeCommand ( choice . metadata . createCommandId ) ;
63
66
}
@@ -75,7 +78,9 @@ interface IProjectTypeMetadata {
75
78
type : ProjectType ;
76
79
extensionId : string ;
77
80
extensionName : string ;
81
+ leastExtensionVersion ?: string ;
78
82
createCommandId : string ;
83
+ createCommandArgs ?: any [ ] ;
79
84
}
80
85
81
86
interface IProjectTypeQuickPick extends QuickPickItem {
@@ -88,6 +93,7 @@ enum ProjectType {
88
93
SpringBoot = "SpringBoot" ,
89
94
Quarkus = "Quarkus" ,
90
95
MicroProfile = "MicroProfile" ,
96
+ JavaFX = "JavaFX" ,
91
97
}
92
98
93
99
async function ensureExtension ( typeName : string , metaData : IProjectTypeMetadata ) : Promise < boolean > {
@@ -101,6 +107,11 @@ async function ensureExtension(typeName: string, metaData: IProjectTypeMetadata)
101
107
return false ;
102
108
}
103
109
110
+ if ( metaData . leastExtensionVersion && semver . lt ( extension . packageJSON . version , metaData . leastExtensionVersion ) ) {
111
+ await promptUpdateExtension ( typeName , metaData ) ;
112
+ return false ;
113
+ }
114
+
104
115
await extension . activate ( ) ;
105
116
return true ;
106
117
}
@@ -112,6 +123,13 @@ async function promptInstallExtension(projectType: string, metaData: IProjectTyp
112
123
}
113
124
}
114
125
126
+ async function promptUpdateExtension ( projectType : string , metaData : IProjectTypeMetadata ) : Promise < void > {
127
+ const choice : string | undefined = await window . showInformationMessage ( `${ metaData . extensionName } needs to be updated to create ${ projectType } projects. Please re-run the command 'Java: Create Java Project...' after the extension is updated.` , "Update" ) ;
128
+ if ( choice === "Update" ) {
129
+ commands . executeCommand ( Commands . INSTALL_EXTENSION , metaData . extensionId ) ;
130
+ }
131
+ }
132
+
115
133
async function scaffoldSimpleProject ( context : ExtensionContext ) : Promise < void > {
116
134
const workspaceFolder = Utility . getDefaultWorkspaceFolder ( ) ;
117
135
const location : Uri [ ] | undefined = await window . showOpenDialog ( {
@@ -205,4 +223,20 @@ const projectTypes: IProjectType[] = [
205
223
createCommandId : "extension.microProfileStarter" ,
206
224
} ,
207
225
} ,
226
+ {
227
+ displayName : "JavaFX" ,
228
+ description : "create from archetype" ,
229
+ metadata : {
230
+ type : ProjectType . JavaFX ,
231
+ extensionId : "vscjava.vscode-maven" ,
232
+ extensionName : "Maven for Java" ,
233
+ leastExtensionVersion : "0.35.0" ,
234
+ createCommandId : "maven.archetype.generate" ,
235
+ createCommandArgs : [ {
236
+ archetypeGroupId : "org.openjfx" ,
237
+ archetypeArtifactId : "javafx-archetype-fxml" ,
238
+ archetypeVersion : "RELEASE" ,
239
+ } ] ,
240
+ } ,
241
+ } ,
208
242
] ;
0 commit comments