From 63b76a39eeaa995900d1873f2f53e2e937aaa783 Mon Sep 17 00:00:00 2001 From: Michal Date: Mon, 16 Aug 2021 16:05:13 +0200 Subject: [PATCH 1/4] ask for env and pulish for net5 --- src/commands/functions/createTag.ts | 49 +++++++++++++++++++++++++---- 1 file changed, 43 insertions(+), 6 deletions(-) diff --git a/src/commands/functions/createTag.ts b/src/commands/functions/createTag.ts index b154d33..9519011 100644 --- a/src/commands/functions/createTag.ts +++ b/src/commands/functions/createTag.ts @@ -1,14 +1,17 @@ +/* eslint-disable no-empty */ +/* eslint-disable @typescript-eslint/no-unused-vars */ import { ProgressLocation, QuickPickItem, Uri, window, workspace } from "vscode"; import { functionsClient } from "../../client"; import { getTarReadStream } from "../../utils/tar"; import { ext } from "../../extensionVariables"; +import * as path from "path"; import * as fs from "fs"; import { TagsTreeItem } from "../../tree/functions/tags/TagsTreeItem"; import { selectWorkspaceFolder } from "../../utils/workspace"; import { ProgressMessage } from "../../utils/types"; import { Tag } from "../../appwrite"; import { activateTag } from "./activateTag"; - +import { execSync } from "child_process"; export async function createTag(item?: TagsTreeItem | Uri): Promise { if (item instanceof Uri) { const functions = await functionsClient?.list(); @@ -39,7 +42,7 @@ export async function createTag(item?: TagsTreeItem | Uri): Promise { if (pick.detail === undefined) { return; } - return await createTagFromUri(pick.detail, command, item, progress); + return await createTagFromUri(pick.detail, command, item.path, progress, false); } ); if (tag) { @@ -61,13 +64,32 @@ export async function createTag(item?: TagsTreeItem | Uri): Promise { value = tags.tags[tags.tags.length - 1].command; } const command = await window.showInputBox({ value, prompt: "Command to run your code" }); + const commaasdsdnd = await window.showInputBox({ value, prompt: folder }); if (command === undefined) { return; } + // there is a special way to publishing a tag for .net5.0 + const envPick = await window.showQuickPick( + [".net5.0", "other"], + { placeHolder: "Select env" } + ); + let customTarCreation = false; + try { + if (envPick === ".net5.0") { + const comm = "dotnet publish --runtime linux-x64 --framework net5.0 --no-self-contained " + folder; + const result = execSync(comm); + if (fs.statSync(folder + "/bin/Debug/net5.0/linux-x64/")) { + customTarCreation = true; + } + } + } catch (error) { + window.showErrorMessage("Error publishing .net archive.\n" + error); + } + const tag = await window.withProgress( { location: ProgressLocation.Notification, title: "Creating tag..." }, async (progress, _token) => { - return await createTagFromUri(func.$id, command, Uri.parse(folder), progress); + return await createTagFromUri(func.$id, command, folder, progress, customTarCreation); } ); @@ -102,10 +124,11 @@ export async function createTag(item?: TagsTreeItem | Uri): Promise { if (command === undefined) { return; } + const tag = await window.withProgress( { location: ProgressLocation.Notification, title: "Creating tag..." }, async (progress, _token) => { - return await createTagFromUri(funcId, command, Uri.parse(folder), progress); + return await createTagFromUri(funcId, command, folder, progress, false); } ); @@ -116,7 +139,7 @@ export async function createTag(item?: TagsTreeItem | Uri): Promise { } } -async function createTagFromUri(functionId: string, command: string, uri: Uri, progress: ProgressMessage): Promise { +async function createTagFromUri(functionId: string, command: string, uri: string, progress: ProgressMessage, customTarCreation: boolean): Promise { progress.report({ message: "Creating tarball", increment: 10 }); if (functionsClient === undefined) { @@ -125,7 +148,21 @@ async function createTagFromUri(functionId: string, command: string, uri: Uri, p let tarFilePath; try { - tarFilePath = await getTarReadStream(uri); + if (customTarCreation === false) { + tarFilePath = await getTarReadStream(Uri.parse(uri)); + } + else { + const comm = "tar -C " + uri + "/bin/Debug/net5.0/linux-x64 -zcvf" + uri + "/code.tar.gz publish"; + const result = execSync(comm); + if (fs.statSync(uri + "code.tar.gz")) { + + window.showInformationMessage("udalo sie"); + + } else { + window.showErrorMessage("Error creating tar file.\n"); + + } + } } catch (e) { window.showErrorMessage("Error creating tar file.\n" + e); return; From 31e89fe94320d4b3185ada51a95aba354d3abd82 Mon Sep 17 00:00:00 2001 From: Michal Date: Mon, 16 Aug 2021 16:18:10 +0200 Subject: [PATCH 2/4] assign correct tar path --- src/commands/functions/createTag.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/commands/functions/createTag.ts b/src/commands/functions/createTag.ts index 9519011..6196f23 100644 --- a/src/commands/functions/createTag.ts +++ b/src/commands/functions/createTag.ts @@ -153,9 +153,10 @@ async function createTagFromUri(functionId: string, command: string, uri: string } else { const comm = "tar -C " + uri + "/bin/Debug/net5.0/linux-x64 -zcvf" + uri + "/code.tar.gz publish"; + const a = uri + "/code.tar.gz"; const result = execSync(comm); - if (fs.statSync(uri + "code.tar.gz")) { - + if (fs.statSync(a)) { + tarFilePath = a; window.showInformationMessage("udalo sie"); } else { From 712355a46a315b1c16ffa5052a4424c53607dd46 Mon Sep 17 00:00:00 2001 From: Michal Date: Mon, 16 Aug 2021 16:22:31 +0200 Subject: [PATCH 3/4] cleaning --- src/commands/functions/createTag.ts | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/src/commands/functions/createTag.ts b/src/commands/functions/createTag.ts index 6196f23..1c18946 100644 --- a/src/commands/functions/createTag.ts +++ b/src/commands/functions/createTag.ts @@ -64,20 +64,20 @@ export async function createTag(item?: TagsTreeItem | Uri): Promise { value = tags.tags[tags.tags.length - 1].command; } const command = await window.showInputBox({ value, prompt: "Command to run your code" }); - const commaasdsdnd = await window.showInputBox({ value, prompt: folder }); if (command === undefined) { return; } // there is a special way to publishing a tag for .net5.0 const envPick = await window.showQuickPick( [".net5.0", "other"], - { placeHolder: "Select env" } + { placeHolder: "Select runtime" } ); + let customTarCreation = false; try { if (envPick === ".net5.0") { const comm = "dotnet publish --runtime linux-x64 --framework net5.0 --no-self-contained " + folder; - const result = execSync(comm); + execSync(comm); if (fs.statSync(folder + "/bin/Debug/net5.0/linux-x64/")) { customTarCreation = true; } @@ -148,22 +148,19 @@ async function createTagFromUri(functionId: string, command: string, uri: string let tarFilePath; try { - if (customTarCreation === false) { - tarFilePath = await getTarReadStream(Uri.parse(uri)); - } - else { - const comm = "tar -C " + uri + "/bin/Debug/net5.0/linux-x64 -zcvf" + uri + "/code.tar.gz publish"; - const a = uri + "/code.tar.gz"; + if (customTarCreation === true) { + const tarPath = uri + "/code.tar.gz"; + const comm = "tar -C " + uri + "/bin/Debug/net5.0/linux-x64 -zcvf" + tarPath; const result = execSync(comm); - if (fs.statSync(a)) { - tarFilePath = a; - window.showInformationMessage("udalo sie"); - + if (fs.statSync(tarPath)) { + tarFilePath = tarPath; } else { window.showErrorMessage("Error creating tar file.\n"); - } } + else { + tarFilePath = await getTarReadStream(Uri.parse(uri)); + } } catch (e) { window.showErrorMessage("Error creating tar file.\n" + e); return; From 3c2de05f8d3094ba259159631ce0329aa10929fe Mon Sep 17 00:00:00 2001 From: MSierpinski Date: Tue, 17 Aug 2021 13:54:32 +0200 Subject: [PATCH 4/4] cleanup + restore publish for tar creation --- src/commands/functions/createTag.ts | 31 ++++++++++++++--------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/src/commands/functions/createTag.ts b/src/commands/functions/createTag.ts index 1c18946..11d0183 100644 --- a/src/commands/functions/createTag.ts +++ b/src/commands/functions/createTag.ts @@ -1,10 +1,7 @@ -/* eslint-disable no-empty */ -/* eslint-disable @typescript-eslint/no-unused-vars */ import { ProgressLocation, QuickPickItem, Uri, window, workspace } from "vscode"; import { functionsClient } from "../../client"; import { getTarReadStream } from "../../utils/tar"; import { ext } from "../../extensionVariables"; -import * as path from "path"; import * as fs from "fs"; import { TagsTreeItem } from "../../tree/functions/tags/TagsTreeItem"; import { selectWorkspaceFolder } from "../../utils/workspace"; @@ -12,6 +9,7 @@ import { ProgressMessage } from "../../utils/types"; import { Tag } from "../../appwrite"; import { activateTag } from "./activateTag"; import { execSync } from "child_process"; + export async function createTag(item?: TagsTreeItem | Uri): Promise { if (item instanceof Uri) { const functions = await functionsClient?.list(); @@ -42,7 +40,7 @@ export async function createTag(item?: TagsTreeItem | Uri): Promise { if (pick.detail === undefined) { return; } - return await createTagFromUri(pick.detail, command, item.path, progress, false); + return await createTagFromUri(pick.detail, command, item.path, progress, "", ""); } ); if (tag) { @@ -67,19 +65,22 @@ export async function createTag(item?: TagsTreeItem | Uri): Promise { if (command === undefined) { return; } + // there is a special way to publishing a tag for .net5.0 const envPick = await window.showQuickPick( [".net5.0", "other"], { placeHolder: "Select runtime" } ); - let customTarCreation = false; + let customTarCreationCommand = ""; + let customTarPath = ""; try { if (envPick === ".net5.0") { const comm = "dotnet publish --runtime linux-x64 --framework net5.0 --no-self-contained " + folder; execSync(comm); if (fs.statSync(folder + "/bin/Debug/net5.0/linux-x64/")) { - customTarCreation = true; + customTarPath = folder + "/code.tar.gz"; + customTarCreationCommand = "tar -C " + folder + "/bin/Debug/net5.0/linux-x64 -zcvf " + customTarPath + " publish"; } } } catch (error) { @@ -89,7 +90,7 @@ export async function createTag(item?: TagsTreeItem | Uri): Promise { const tag = await window.withProgress( { location: ProgressLocation.Notification, title: "Creating tag..." }, async (progress, _token) => { - return await createTagFromUri(func.$id, command, folder, progress, customTarCreation); + return await createTagFromUri(func.$id, command, folder, progress, customTarCreationCommand, customTarPath); } ); @@ -128,7 +129,7 @@ export async function createTag(item?: TagsTreeItem | Uri): Promise { const tag = await window.withProgress( { location: ProgressLocation.Notification, title: "Creating tag..." }, async (progress, _token) => { - return await createTagFromUri(funcId, command, folder, progress, false); + return await createTagFromUri(funcId, command, folder, progress, "", ""); } ); @@ -139,7 +140,7 @@ export async function createTag(item?: TagsTreeItem | Uri): Promise { } } -async function createTagFromUri(functionId: string, command: string, uri: string, progress: ProgressMessage, customTarCreation: boolean): Promise { +async function createTagFromUri(functionId: string, command: string, folder: string, progress: ProgressMessage, customTarCreationCommand: string, customTarPath: string): Promise { progress.report({ message: "Creating tarball", increment: 10 }); if (functionsClient === undefined) { @@ -148,18 +149,16 @@ async function createTagFromUri(functionId: string, command: string, uri: string let tarFilePath; try { - if (customTarCreation === true) { - const tarPath = uri + "/code.tar.gz"; - const comm = "tar -C " + uri + "/bin/Debug/net5.0/linux-x64 -zcvf" + tarPath; - const result = execSync(comm); - if (fs.statSync(tarPath)) { - tarFilePath = tarPath; + if (customTarCreationCommand !== "") { + execSync(customTarCreationCommand); + if (fs.statSync(customTarPath)) { + tarFilePath = customTarPath; } else { window.showErrorMessage("Error creating tar file.\n"); } } else { - tarFilePath = await getTarReadStream(Uri.parse(uri)); + tarFilePath = await getTarReadStream(Uri.parse(folder)); } } catch (e) { window.showErrorMessage("Error creating tar file.\n" + e);