Skip to content

Commit

Permalink
Folder structure (#41)
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Zegray <[email protected]>
  • Loading branch information
rzgry authored Feb 18, 2020
1 parent 5905222 commit 6cd8e23
Show file tree
Hide file tree
Showing 4 changed files with 177 additions and 172 deletions.
20 changes: 12 additions & 8 deletions src/util/starter.ts → src/commands/generateProject.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as vscode from "vscode";
import * as extract from "extract-zip";
import * as util from "./util";
import * as util from "../util/util";
import * as prompts from "../util/vscodePrompts";
import * as path from "path";
import fetch from "node-fetch";
import { OPEN_NEW_PROJECT_OPTIONS, EXTENSION_USER_AGENT } from "../properties";
Expand All @@ -23,41 +24,44 @@ export async function generateProject(): Promise<void> {
const mpConfigurations = mpSupportMatrix.configs;
const allMpVersions = Object.keys(mpConfigurations);

const groupId = await util.askForGroupID();
const groupId = await prompts.askForGroupID();
if (groupId === undefined) {
return;
}

const artifactId = await util.askForArtifactID();
const artifactId = await prompts.askForArtifactID();
if (artifactId === undefined) {
return;
}

const mpVersion = await util.askForMPVersion(allMpVersions);
const mpVersion = await prompts.askForMPVersion(allMpVersions);
if (mpVersion === undefined) {
return;
}

// ask user to select one of the servers that are available for the version of mp they selected
const mpServer = await util.askForMPServer(mpConfigurations[mpVersion].supportedServers);
const mpServer = await prompts.askForMPServer(mpConfigurations[mpVersion].supportedServers);
if (mpServer === undefined) {
return;
}

const javaSEVersion = await util.askForJavaSEVersion(mpVersion, mpServer);
const javaSEVersion = await prompts.askForJavaSEVersion(mpVersion, mpServer);
if (javaSEVersion === undefined) {
return;
}

// ask user to pick a list of mp specifications to use for the given version of mp they selected
const allSupportedSpecs = mpConfigurations[mpVersion].specs;
const specDescriptions = mpSupportMatrix.descriptions;
const mpSpecifications = await util.askForMPSpecifications(allSupportedSpecs, specDescriptions);
const mpSpecifications = await prompts.askForMPSpecifications(
allSupportedSpecs,
specDescriptions
);
if (mpSpecifications === undefined) {
return;
}

const targetFolder = await util.askForFolder({
const targetFolder = await prompts.askForFolder({
openLabel: "Generate into this folder",
});
if (targetFolder === undefined) {
Expand Down
4 changes: 2 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import * as vscode from "vscode";
import * as starter from "./util/starter";
import { generateProject } from "./commands/generateProject";

// this method is called when the extension is activated
// the extension is activated the very first time the command is executed
export function activate(context: vscode.ExtensionContext): void {
context.subscriptions.push(
vscode.commands.registerCommand("extension.microProfileStarter", starter.generateProject)
vscode.commands.registerCommand("extension.microProfileStarter", generateProject)
);
}

Expand Down
163 changes: 1 addition & 162 deletions src/util/util.ts
Original file line number Diff line number Diff line change
@@ -1,169 +1,8 @@
import * as vscode from "vscode";
import * as fs from "fs";
import fetch from "node-fetch";
import { pipeline } from "stream";
import { OpenDialogOptions, Uri, window, QuickPickItem } from "vscode";
import { MP_SERVER_LABELS, MP_VERSION_LABELS } from "../properties";
import { promisify } from "util";

export async function askForGroupID(): Promise<string | undefined> {
return await vscode.window.showInputBox({
placeHolder: "e.g. com.example",
prompt: "Specify a Group Id for your project.",
value: "com.example",
ignoreFocusOut: true,
validateInput: (value: string) => {
if (value.trim().length === 0) {
return "Group Id is required";
}
if (value.indexOf(" ") >= 0) {
return "Group Id cannot contain a blank space";
}
return null;
},
});
}

export async function askForArtifactID(): Promise<string | undefined> {
return await vscode.window.showInputBox({
placeHolder: "demo",
prompt: "Specify an Artifact Id for your project.",
value: "demo",
ignoreFocusOut: true,
validateInput: (value: string) => {
if (value.trim().length === 0) {
return "Artifact Id is required";
}
if (value.indexOf(" ") >= 0) {
return "Artifact Id cannot contain a blank space";
}
return null;
},
});
}

export async function askForJavaSEVersion(
mpVersion: string,
mpServer: string
): Promise<string | undefined> {
const MP32_JAVA_11_SUPPORTED = ["LIBERTY", "PAYARA_MICRO", "HELIDON", "THORNTAIL_V2"];

let supportedJavaSEVersions = ["SE8"];

if (mpVersion === "MP32" && MP32_JAVA_11_SUPPORTED.includes(mpServer)) {
supportedJavaSEVersions = ["SE8", "SE11"];
}

return await vscode.window.showQuickPick(supportedJavaSEVersions, {
ignoreFocusOut: true,
placeHolder: "Select a Java SE version.",
});
}

export async function askForMPVersion(mpVersions: string[]): Promise<string | undefined> {
interface MPVersionOption extends QuickPickItem {
label: string; // label is the long-name that is displayed in vscode
version: string; // version is the short-name that is used internally by the microprofile starter api
}

const mpVersionOptions: MPVersionOption[] = [];
for (const mpVersion of mpVersions) {
// if we have a label defined for the given MP version short-name add it to the options array
if (MP_VERSION_LABELS[mpVersion] != null) {
mpVersionOptions.push({
label: MP_VERSION_LABELS[mpVersion],
version: mpVersion,
});
}
}

const mpVersionQuickPickResult = await vscode.window.showQuickPick(mpVersionOptions, {
ignoreFocusOut: true,
placeHolder: "Select a MicroProfile version.",
});

if (mpVersionQuickPickResult != null) {
return mpVersionQuickPickResult.version;
}

return undefined;
}

export async function askForMPServer(mpServers: string[]): Promise<string | undefined> {
interface MPServerOption extends QuickPickItem {
label: string; // label is the long-name that is displayed in vscode
server: string; // server is the short-name that is used internally by the microprofile starter api
}

const mpServerOptions: MPServerOption[] = [];
for (const mpServer of mpServers) {
// if we have a server label for the given mp server short-name add it to the options array
if (MP_SERVER_LABELS[mpServer] != null) {
mpServerOptions.push({
label: MP_SERVER_LABELS[mpServer],
server: mpServer,
});
}
}

const mpVersionQuickPickResult = await vscode.window.showQuickPick(mpServerOptions, {
ignoreFocusOut: true,
placeHolder: "Select a MicroProfile server.",
});

if (mpVersionQuickPickResult != null) {
return mpVersionQuickPickResult.server;
}
return undefined;
}

export async function askForMPSpecifications(
specs: string[],
specDescriptions: Record<string, string>
): Promise<Array<string> | undefined> {
interface MPSpecOption extends QuickPickItem {
spec: string; // spec is the short-name used internally my microprofile starter api
label: string; // name of mp spec
detail: string; // description of mp spec
}

const mpSpecOptions: MPSpecOption[] = specs.map(spec => {
const fullDescription = specDescriptions[spec];
const [name, desc] = fullDescription.split("-");
return {
spec: spec,
label: name,
detail: trimCapitalizeFirstLetter(desc),
};
});

const specResults: MPSpecOption[] | undefined = await vscode.window.showQuickPick(mpSpecOptions, {
ignoreFocusOut: true,
canPickMany: true,
placeHolder: "Select MicroProfile specifications.",
});

if (specResults != null) {
return specResults.map(result => result.spec);
}
return undefined;
}

export async function askForFolder(customOptions: OpenDialogOptions): Promise<Uri | undefined> {
const options: OpenDialogOptions = {
canSelectFiles: false,
canSelectFolders: true,
canSelectMany: false,
};
const result = await window.showOpenDialog(Object.assign(options, customOptions));

if (result && result.length > 0) {
return result[0];
}

return undefined;
}

interface RequestOptions {
url: string;
}
Expand Down Expand Up @@ -194,6 +33,6 @@ export async function downloadFile(
export const deleteFile = promisify(fs.unlink);

export function trimCapitalizeFirstLetter(str: string): string {
const newStr = str.trim(); // remove any leading whitespace
const newStr = str.trim();
return newStr.charAt(0).toUpperCase() + newStr.slice(1);
}
Loading

0 comments on commit 6cd8e23

Please sign in to comment.