From 07b6dc8cd004ff159c280225f1ff02e129d01885 Mon Sep 17 00:00:00 2001 From: lucsomers Date: Tue, 27 Feb 2024 13:40:42 +0100 Subject: [PATCH] added interfaces to the command classes --- src/commands/checkVersionCommand.ts | 9 +++++---- src/commands/generateAtlasCommand.ts | 8 ++++---- src/commands/generateFunctionalSpecCommand.ts | 10 +++++----- src/commands/generatePrototypeCommand.ts | 6 ++++-- src/extension.ts | 20 +++++++++++-------- src/interfaces/ICommand.ts | 4 ++++ 6 files changed, 34 insertions(+), 23 deletions(-) create mode 100644 src/interfaces/ICommand.ts diff --git a/src/commands/checkVersionCommand.ts b/src/commands/checkVersionCommand.ts index 1e5b3ab..77c2bd3 100644 --- a/src/commands/checkVersionCommand.ts +++ b/src/commands/checkVersionCommand.ts @@ -1,12 +1,13 @@ import * as vscode from 'vscode'; import { ampersandVersionChecker } from '../ampersand'; -export class checkVersionCommand{ - static checkVersionCommand() - { +export class checkVersionCommand implements ICommand{ + commandName: string = "extension.checkVersion"; + + RunCommand(): void { if (!vscode.workspace.rootPath) { vscode.window.showWarningMessage("Checking ampersand only works if you work in a workspace.") - return null; + return; } let versionString : string = ampersandVersionChecker.getVersion(); diff --git a/src/commands/generateAtlasCommand.ts b/src/commands/generateAtlasCommand.ts index 88842b3..3d6d311 100644 --- a/src/commands/generateAtlasCommand.ts +++ b/src/commands/generateAtlasCommand.ts @@ -1,12 +1,12 @@ -import * as vscode from 'vscode'; import { config, fileUtils, terminalUtils } from "../utils"; import { terminalBuilder } from '../builders'; -export class generateAtlasCommand { +export class generateAtlasCommand implements ICommand { + commandName: string = "extension.generateAtlas"; + private builder : terminalBuilder = new terminalBuilder(); - public GenerateAtlasCommand() - { + RunCommand(): void { if(config.mainScriptSetting === undefined || config.folderSetting === undefined) return; diff --git a/src/commands/generateFunctionalSpecCommand.ts b/src/commands/generateFunctionalSpecCommand.ts index 1df95f4..be794f9 100644 --- a/src/commands/generateFunctionalSpecCommand.ts +++ b/src/commands/generateFunctionalSpecCommand.ts @@ -1,12 +1,12 @@ -import * as vscode from 'vscode'; import { config, fileUtils, terminalUtils } from '../utils'; import { terminalBuilder } from '../builders'; -export class generateFunctionalSpecCommand{ - private builder : terminalBuilder = new terminalBuilder(); +export class generateFunctionalSpecCommand implements ICommand { + commandName: string = "extension.generateFunctionalSpec"; - public GenerateFunctionalSpecCommand() - { + private builder : terminalBuilder = new terminalBuilder(); + + RunCommand(): void { if(config.mainScriptSetting === undefined || config.folderSetting === undefined) return; diff --git a/src/commands/generatePrototypeCommand.ts b/src/commands/generatePrototypeCommand.ts index 454acd5..ad74536 100644 --- a/src/commands/generatePrototypeCommand.ts +++ b/src/commands/generatePrototypeCommand.ts @@ -3,7 +3,9 @@ import * as vscode from 'vscode'; import { terminalBuilder } from "../builders/terminalBuilder"; import { manifest } from '../models/manifest'; -export class generatePrototypeCommand { +export class generatePrototypeCommand implements ICommand { + commandName: string = "extension.generatePrototype"; + static portForwardTerminal: vscode.Terminal | undefined = undefined; private builder : terminalBuilder = new terminalBuilder(); @@ -14,7 +16,7 @@ export class generatePrototypeCommand { this.manifestFile = new manifest(context.extensionPath); } - public async GeneratePrototypeCommand() + public async RunCommand() { this.tryKillPortForwardedProcessAndTerminal(); diff --git a/src/extension.ts b/src/extension.ts index 0f8694c..295e84f 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -4,11 +4,9 @@ import * as fs from 'fs'; import { fileUtils, watcherUtils } from "./utils"; import { ampersandVersionChecker } from './ampersand'; import { constants } from './constants'; -import { generateFunctionalSpecCommand, checkVersionCommand, generateAtlasCommand, generatePrototypeCommand } from './commands'; +import { checkVersionCommand, generateAtlasCommand, generateFunctionalSpecCommand, generatePrototypeCommand } from './commands'; -let generatePrototypeCommandInstance: generatePrototypeCommand; -let generateFunctionalSpecCommandInstance : generateFunctionalSpecCommand; -let generateAtlasCommandInstance : generateAtlasCommand; +let commands: ICommand[]; // this method is called when your extension is activated // your extension is activated the very first time the command is executed @@ -24,10 +22,16 @@ export function activate(context: vscode.ExtensionContext) { watcherUtils.setupLastRunningWatcher(context); - pushDisposable(context, "extension.checkVersion", () => checkVersionCommand.checkVersionCommand()) - pushDisposable(context, "extension.generateFunctionalSpec", () => new generateFunctionalSpecCommand().GenerateFunctionalSpecCommand()) - pushDisposable(context, "extension.generateAtlas", () => new generateAtlasCommand().GenerateAtlasCommand()) - pushDisposable(context, "extension.generatePrototype", () => new generatePrototypeCommand(context).GeneratePrototypeCommand()) + commands.push( + new generatePrototypeCommand(context), + new generateAtlasCommand(), + new generateFunctionalSpecCommand(), + new checkVersionCommand() + ); + + commands.forEach(command => { + pushDisposable(context, command.commandName, () => command.RunCommand()); + }); generateWorkingFolders(); createAndFillGitIgnore(); diff --git a/src/interfaces/ICommand.ts b/src/interfaces/ICommand.ts new file mode 100644 index 0000000..8bd8aad --- /dev/null +++ b/src/interfaces/ICommand.ts @@ -0,0 +1,4 @@ +interface ICommand { + readonly commandName : string; + RunCommand(): void; +} \ No newline at end of file