From 7e4d06b1c882ef38f23380abc142db6df97dcdb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Huras?= Date: Mon, 20 May 2024 18:32:50 +0200 Subject: [PATCH] Create project using the --template when using action server 0.10.0 onwards --- docs/changelog.md | 5 +++ .../vscode-client/src/actionServer.ts | 2 +- sema4ai-code/vscode-client/src/extension.ts | 33 ------------------- .../vscode-client/src/robo/actionPackage.ts | 23 ++++++++++--- 4 files changed, 25 insertions(+), 38 deletions(-) diff --git a/docs/changelog.md b/docs/changelog.md index aedccf383..518d9b0f4 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -1,3 +1,8 @@ +New in 1.22.2 (2024-05-20) +----------------------------- + +- If `Action Server 0.10.0` onwards is being used, creates a project using the `--template minimal`. +- In the new project, if the project is not empty and the user agreed to proceed, create the contents even if it means overriding what's there. New in 1.22.1 (2024-05-04) ----------------------------- diff --git a/sema4ai-code/vscode-client/src/actionServer.ts b/sema4ai-code/vscode-client/src/actionServer.ts index ff4cd045a..9071a5209 100644 --- a/sema4ai-code/vscode-client/src/actionServer.ts +++ b/sema4ai-code/vscode-client/src/actionServer.ts @@ -48,7 +48,7 @@ const getInternalActionServerLocation = async (tmpFlag: string = "") => { return path.join(await getInternalActionServerDirLocation(), binName); }; -const getActionServerVersion = async (actionServerLocation: string): Promise => { +export const getActionServerVersion = async (actionServerLocation: string): Promise => { let result: ExecFileReturn; const maxTimes = 4; let lastError = undefined; diff --git a/sema4ai-code/vscode-client/src/extension.ts b/sema4ai-code/vscode-client/src/extension.ts index ddb1c2f8b..4fd5f9ee7 100644 --- a/sema4ai-code/vscode-client/src/extension.ts +++ b/sema4ai-code/vscode-client/src/extension.ts @@ -330,38 +330,6 @@ class CommandRegistry { } } -async function verifyRobotFrameworkInstalled() { - // No longer check whether robotframweork-lsp is installed. - // if (!roboConfig.getVerifylsp()) { - // return; - // } - // const ROBOT_EXTENSION_ID = "robocorp.robotframework-lsp"; - // let found = true; - // try { - // let extension = extensions.getExtension(ROBOT_EXTENSION_ID); - // if (!extension) { - // found = false; - // } - // } catch (error) { - // found = false; - // } - // if (!found) { - // // It seems it's not installed, install? - // let install = "Install"; - // let dontAsk = "Don't ask again"; - // let chosen = await window.showInformationMessage( - // "It seems that the Robot Framework Language Server extension is not installed to work with .robot Files.", - // install, - // dontAsk - // ); - // if (chosen == install) { - // await commands.executeCommand("workbench.extensions.search", ROBOT_EXTENSION_ID); - // } else if (chosen == dontAsk) { - // roboConfig.setVerifylsp(false); - // } - // } -} - async function cloudLoginShowConfirmationAndRefresh() { let loggedIn = await cloudLogin(); if (loggedIn) { @@ -870,7 +838,6 @@ export async function doActivate(context: ExtensionContext, C: CommandRegistry) // regardless of it -- as it may call robot.resolveInterpreter, it may need to activate the language // server extension, which in turn requires robocorp code to be activated already). installWorkspaceWatcher(context); - verifyRobotFrameworkInstalled(); } export function deactivate(): Thenable | undefined { diff --git a/sema4ai-code/vscode-client/src/robo/actionPackage.ts b/sema4ai-code/vscode-client/src/robo/actionPackage.ts index a15ff4857..7b433b591 100644 --- a/sema4ai-code/vscode-client/src/robo/actionPackage.ts +++ b/sema4ai-code/vscode-client/src/robo/actionPackage.ts @@ -5,6 +5,7 @@ import * as roboCommands from "../robocorpCommands"; import { ActionResult, IActionInfo, LocalRobotMetadataInfo } from "../protocols"; import { areThereRobotsInWorkspace, + compareVersions, isActionPackage, isDirectoryAPackageDirectory, verifyIfPathOkToCreatePackage, @@ -14,7 +15,7 @@ import { fileExists, makeDirs } from "../files"; import { QuickPickItemWithAction, askForWs, showSelectOneQuickPick } from "../ask"; import * as path from "path"; import { OUTPUT_CHANNEL, logError } from "../channel"; -import { downloadOrGetActionServerLocation } from "../actionServer"; +import { downloadOrGetActionServerLocation, getActionServerVersion } from "../actionServer"; import { createEnvWithRobocorpHome, getRobocorpHome } from "../rcc"; import { execFilePromise } from "../subprocess"; @@ -226,6 +227,8 @@ export async function createActionPackage() { return; } + const actionServerVersionPromise: Promise = getActionServerVersion(actionServerLocation); + if (await isDirectoryAPackageDirectory(ws.uri)) { return; } @@ -294,11 +297,23 @@ export async function createActionPackage() { const robocorpHome = await getRobocorpHome(); const env = createEnvWithRobocorpHome(robocorpHome); - const cwd = dirname(targetDir); - const useName = path.basename(targetDir); + await makeDirs(targetDir); try { - await execFilePromise(actionServerLocation, ["new", "--name", useName], { "env": env, "cwd": cwd }); + const actionServerVersion: string | undefined = await actionServerVersionPromise; + if (actionServerVersion === undefined) { + const msg = "Cannot do `new` command (it was not possible to get the action server version)."; + OUTPUT_CHANNEL.appendLine(msg); + window.showErrorMessage(msg); + return; + } + let cmdline = ["new", "--name", ".", "--template", "minimal"]; + const compare = compareVersions("0.10.0", actionServerVersion); + if (compare > 0) { + // old version installed (no --template available). + cmdline = ["new", "--name", "."]; + } + await execFilePromise(actionServerLocation, cmdline, { "env": env, "cwd": targetDir }); try { commands.executeCommand("workbench.files.action.refreshFilesExplorer"); } catch (error) {