-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7721049
commit 5270f26
Showing
10 changed files
with
156 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./terminalBuilder"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import * as vscode from 'vscode'; | ||
import { terminalInfo } from "../models/terminal"; | ||
import { fileUtils } from '../utils'; | ||
|
||
export class terminalBuilder | ||
{ | ||
private terminalInfoBuild:terminalInfo = new terminalInfo; | ||
|
||
private reset() { | ||
this.terminalInfoBuild = new terminalInfo; | ||
} | ||
|
||
public getTerminal(): vscode.Terminal { | ||
const toReturn = vscode.window.createTerminal({name:this.terminalInfoBuild.terminalName,cwd:fileUtils.generateWorkspacePath(this.terminalInfoBuild.workingDir)}); | ||
this.reset(); | ||
return toReturn; | ||
} | ||
|
||
public setName(terminalName:string) : terminalBuilder { | ||
this.terminalInfoBuild.terminalName = terminalName; | ||
return this; | ||
} | ||
|
||
public setVisibility(terminalVisible:boolean) : terminalBuilder { | ||
this.terminalInfoBuild.terminalVisible = terminalVisible; | ||
return this; | ||
} | ||
|
||
public setWorkingDir(workingDir:string[]) : terminalBuilder { | ||
this.terminalInfoBuild.workingDir = workingDir; | ||
return this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,24 @@ | ||
import * as vscode from 'vscode'; | ||
import { config, fileUtils, terminalUtils } from '../utils'; | ||
import { terminalBuilder } from '../builders'; | ||
|
||
export class generateFunctionalSpecCommand{ | ||
static GenerateFunctionalSpecCommand() | ||
private builder : terminalBuilder = new terminalBuilder(); | ||
|
||
public GenerateFunctionalSpecCommand() | ||
{ | ||
if(config.mainScriptSetting === undefined || config.folderSetting === undefined) | ||
return; | ||
|
||
const mainScriptPath: string = fileUtils.generateWorkspacePath([config.folderSetting, config.mainScriptSetting]); | ||
|
||
terminalUtils.RunCommandsInNewTerminal("Ampersand generate functional spec", | ||
const terminal = this.builder.setName("Ampersand generate functional spec") | ||
.setWorkingDir(['ampersand']) | ||
.getTerminal(); | ||
|
||
terminalUtils.RunCommandsInExistingTerminal(terminal, | ||
[`ampersand documentation --no-text --format docx ${mainScriptPath}`, | ||
`ampersand documentation ${mainScriptPath} --format docx --no-graphics --language=NL --ConceptualAnalysis --verbosity debug`], | ||
['ampersand']); | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,76 +1,75 @@ | ||
import { config, fileUtils, terminalUtils, zipUtils } from "../utils"; | ||
import * as vscode from 'vscode'; | ||
import * as path from 'path'; | ||
import { terminalBuilder } from "../builders/terminalBuilder"; | ||
import { manifest } from '../models/manifest'; | ||
|
||
export class generatePrototypeCommand { | ||
private static portForwardTerminalPID: vscode.Terminal | undefined; | ||
private portForwardTerminal: vscode.Terminal | undefined; | ||
private builder : terminalBuilder = new terminalBuilder(); | ||
|
||
static GeneratePrototypeCommand(context: vscode.ExtensionContext) | ||
private manifestFile : manifest; | ||
|
||
constructor(context: vscode.ExtensionContext) | ||
{ | ||
//Get extension path | ||
if(context === undefined) | ||
return; | ||
this.manifestFile = new manifest(context.extensionPath); | ||
} | ||
|
||
const extensionPath: string = context.extensionPath; | ||
public GeneratePrototypeCommand() | ||
{ | ||
this.tryKillPortForwardedProcessAndTerminal(); | ||
|
||
const encodedZipContent:string|undefined = zipUtils.zipFolder(extensionPath); | ||
vscode.workspace.fs.readFile(this.manifestFile.templateFileUri).then((data: Uint8Array) => this.replaceMarkers(data)); | ||
} | ||
|
||
if(encodedZipContent === undefined) | ||
private tryKillPortForwardedProcessAndTerminal() | ||
{ | ||
if(this.portForwardTerminal === undefined) | ||
return; | ||
|
||
const encodedMainScript: string = btoa(config.mainScriptSetting as string); | ||
const templateFileUri: vscode.Uri = vscode.Uri.file(path.join(extensionPath, 'assets', 'prototype-template.yaml')); | ||
const manifestFileName: string = fileUtils.generateWorkspacePath(['ampersand', 'prototype.yaml']); | ||
|
||
const manifestFileUri: vscode.Uri = vscode.Uri.file(manifestFileName); | ||
|
||
tryKillPortForwardedProcessAndTerminal(this.portForwardTerminalPID); | ||
|
||
vscode.workspace.fs.readFile(templateFileUri).then((data: Uint8Array) => replaceMarkers(data,encodedZipContent)); | ||
const buildTerminal = this.builder.setName("default name") | ||
.setVisibility(false) | ||
.getTerminal(); | ||
|
||
function tryKillPortForwardedProcessAndTerminal(terminalToKill : vscode.Terminal | undefined) | ||
{ | ||
if(terminalToKill === undefined) | ||
return; | ||
|
||
//get the processID from the terminal that needs to be killed | ||
terminalToKill.processId.then((terminalToKillPID: number | undefined) => { | ||
let killerTerminal = terminalUtils.RunCommandsInNewTerminal("Kill processes", | ||
[`PID=$(ps -ef | grep 'kubectl port-forward' | grep -v grep | awk '{print $2}')`, | ||
`kill $PID`, | ||
(`kill -9 ${terminalToKillPID}`)], | ||
false); | ||
//get the processID from the terminal that needs to be killed | ||
this.portForwardTerminal.processId.then((terminalToKillPID: number | undefined) => { | ||
terminalUtils.RunCommandsInExistingTerminal(buildTerminal, | ||
[`PID=$(ps -ef | grep 'kubectl port-forward' | grep -v grep | awk '{print $2}')`, | ||
`kill $PID`, | ||
(`kill -9 ${terminalToKillPID}`)]) | ||
|
||
//Get own terminal PID to kill it later | ||
killerTerminal.processId.then((killerTerminalPID: number|undefined) => { | ||
|
||
//Kill self to cleanup | ||
terminalUtils.RunCommandsInExistingTerminal(killerTerminal,[(`kill -9 ${killerTerminalPID}`)]); | ||
}); | ||
//Get own terminal PID to kill it later | ||
buildTerminal.processId.then((killerTerminalPID: number|undefined) => { | ||
|
||
//Kill self to cleanup | ||
terminalUtils.RunCommandsInExistingTerminal(buildTerminal,[(`kill -9 ${killerTerminalPID}`)]); | ||
}); | ||
} | ||
}); | ||
} | ||
|
||
function replaceMarkers(data: Uint8Array, encodedZipContent:string) | ||
{ | ||
const newData: Uint8Array = fileUtils.replaceMarkers(data, new Map<string, string>( | ||
[ | ||
['{{zipFileContent}}', encodedZipContent], | ||
['{{mainScript}}', encodedMainScript] | ||
] | ||
)); | ||
vscode.workspace.fs.writeFile(manifestFileUri, newData).then(runPrototypeCommand) | ||
} | ||
private replaceMarkers(data: Uint8Array) | ||
{ | ||
const newData: Uint8Array = fileUtils.replaceMarkers(data, new Map<string, string>( | ||
[ | ||
['{{zipFileContent}}', this.manifestFile.encodedZipContent], | ||
['{{mainScript}}', this.manifestFile.encodedMainScript] | ||
] | ||
)); | ||
|
||
vscode.workspace.fs.writeFile(this.manifestFile.fileUri, newData).then(this.runPrototypeCommand) | ||
} | ||
|
||
function runPrototypeCommand() | ||
{ | ||
const deployment: string = 'prototype'; | ||
const service: string = 'prototype'; | ||
private runPrototypeCommand() | ||
{ | ||
const deployment: string = 'prototype'; | ||
const service: string = 'prototype'; | ||
|
||
this.portForwardTerminal = this.builder.setName("Run prototype in minikube") | ||
.getTerminal(); | ||
|
||
generatePrototypeCommand.portForwardTerminalPID = terminalUtils.RunCommandsInNewTerminal("Run prototype in minikube", | ||
[`kubectl apply -f ${manifestFileUri.fsPath}`, | ||
`kubectl rollout status deployment/${deployment} --timeout=300s`, | ||
`kubectl port-forward svc/${service} -n default 8000:80`,]); | ||
} | ||
terminalUtils.RunCommandsInExistingTerminal(this.portForwardTerminal, | ||
[`kubectl apply -f ${this.manifestFile.fileUri.fsPath}`, | ||
`kubectl rollout status deployment/${deployment} --timeout=300s`, | ||
`kubectl port-forward svc/${service} -n default 8000:80`,]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from "./terminal"; | ||
export * from "./manifest"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import * as vscode from 'vscode'; | ||
import { config, fileUtils, terminalUtils, zipUtils } from "../utils"; | ||
import * as path from 'path'; | ||
|
||
export class manifest{ | ||
private readonly _encodedZipContent: string | undefined; | ||
|
||
public get encodedZipContent(): string { | ||
return (this._encodedZipContent === undefined) ? "" : this._encodedZipContent; | ||
} | ||
|
||
public readonly encodedMainScript: string; | ||
public readonly templateFileUri: vscode.Uri; | ||
public readonly fileUri: vscode.Uri; | ||
|
||
constructor(extensionPath: string) | ||
{ | ||
this._encodedZipContent = zipUtils.zipFolder(extensionPath); | ||
this.encodedMainScript = btoa(config.mainScriptSetting as string); | ||
this.templateFileUri = vscode.Uri.file(path.join(extensionPath, 'assets', 'prototype-template.yaml')); | ||
|
||
const fileName = fileUtils.generateWorkspacePath(['ampersand', 'prototype.yaml']); | ||
this.fileUri = vscode.Uri.file(fileName) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export class terminalInfo | ||
{ | ||
public terminalName: string = "default"; | ||
|
||
public terminalVisible: boolean = true; | ||
public workingDir : string[] = [``]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters