From caed0e1b01240148d978b7b4efd515bbcd190dbd Mon Sep 17 00:00:00 2001 From: Ewan Harris Date: Mon, 1 Apr 2024 11:27:44 +0100 Subject: [PATCH] feat(explorer/build): add button to rebuild --- package.json | 12 ++++++++++++ package.nls.json | 3 ++- src/commands/common.ts | 1 + src/commands/index.ts | 26 ++++++++++++++++++++++++-- 4 files changed, 39 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 08507f0b6..8cfe6e3c4 100644 --- a/package.json +++ b/package.json @@ -216,6 +216,13 @@ "icon": "$(play)", "description": "%titanium.commands.build.run.description%" }, + { + "command": "titanium.build.rebuild", + "title": "%titanium.commands.build.rebuild.title%", + "category": "Titanium", + "icon": "$(debug-restart)", + "description": "%titanium.commands.build.rebuild.description%" + }, { "command": "titanium.build.debug", "title": "%titanium.commands.build.debug.title%", @@ -711,6 +718,11 @@ "when": "view == titanium.view.buildExplorer", "group": "navigation@2" }, + { + "command": "titanium.build.rebuild", + "when": "view == titanium.view.buildExplorer && titanium:build:running", + "group": "navigation@2" + }, { "command": "titanium.build.stop", "when": "view == titanium.view.buildExplorer && titanium:build:running", diff --git a/package.nls.json b/package.nls.json index 3bcb9d5ff..e2d0ffaf9 100644 --- a/package.nls.json +++ b/package.nls.json @@ -9,7 +9,8 @@ "titanium.commands.build.setLiveViewEnabled.title": "Enable LiveView", "titanium.commands.build.setLiveViewDisabled.title": "Disable LiveView", "titanium.commands.build.run.title": "Build", - "titanium.commands.build.run.description": "Build a Titanium project", + "titanium.commands.build.rebuild.title": "Rebuild", + "titanium.commands.build.rebuild.description": "Rebuild last project build", "titanium.commands.build.debug.title": "Debug", "titanium.commands.build.debug.description": "Debug a Titanium project", "titanium.commands.package.run.title": "Package", diff --git a/src/commands/common.ts b/src/commands/common.ts index 2a3b057a5..0c13aa4c0 100644 --- a/src/commands/common.ts +++ b/src/commands/common.ts @@ -38,6 +38,7 @@ export enum Commands { OpenReleaseNotes = 'titanium.updates.openReleaseNotes', OpenUrl = 'titanium.openUrl', Package = 'titanium.package.run', + Rebuild = 'titanium.build.rebuild', RefreshExplorer = 'titanium.explorer.refresh', RefreshHelp = 'titanium.helpExplorer.refresh', SelectUpdates = 'titanium.updates.select', diff --git a/src/commands/index.ts b/src/commands/index.ts index 33c39afbd..01fa0bdaa 100644 --- a/src/commands/index.ts +++ b/src/commands/index.ts @@ -3,7 +3,7 @@ import * as vscode from 'vscode'; import { ExtensionContainer } from '../container'; import { Commands } from './common'; -import { GlobalState } from '../constants'; +import { GlobalState, WorkspaceState } from '../constants'; import { buildApplication } from './buildApp'; import { buildModule } from './buildModule'; import { DeviceNode, DistributeNode, OSVerNode, PlatformNode, TargetNode, UpdateNode } from '../explorer/nodes'; @@ -11,7 +11,7 @@ import { sleep } from '../common/utils'; import { packageApplication } from './packageApp'; import { packageModule } from './packageModule'; import { promptForWorkspaceFolder, quickPick } from '../quickpicks'; -import { KeystoreInfo, LogLevel } from '../types/common'; +import { KeystoreInfo, LastBuildState, LogLevel } from '../types/common'; import { configuration } from '../configuration'; import { AlloyComponentExtension, AlloyComponentFolder, AlloyComponentType, generateComponent, generateModel } from './alloyGenerate'; import { debugSessionInformation, DEBUG_SESSION_VALUE } from '../tasks/tasksHelper'; @@ -220,6 +220,28 @@ export function registerCommands (): void { registerCommand(Commands.FixEnvironmentIssues, async () => { startup(); }); + + registerCommand(Commands.Rebuild, async () => { + if (ExtensionContainer.context.globalState.get(GlobalState.Running)) { + await vscode.commands.executeCommand(Commands.StopBuild); + await sleep(100); + } + + const lastBuildState = ExtensionContainer.context.workspaceState.get(WorkspaceState.LastBuildState); + + if (!lastBuildState) { + return; + } + + const { type, folder } = await promptForWorkspaceFolder({ apps: true, modules: true, placeHolder: 'Please select a project to build' }); + const node = new DeviceNode('', lastBuildState.platform, lastBuildState.target, lastBuildState?.deviceId, lastBuildState.target); + + if (type === 'app') { + return buildApplication(node, folder); + } else if (type === 'module') { + return buildModule(undefined, folder); + } + }); } export * from './common';