You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ma...@apache.org on 2023/10/31 22:15:06 UTC
(camel-karavan) branch main updated: Crete Kamelet in VS Code #315
This is an automated email from the ASF dual-hosted git repository.
marat pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-karavan.git
The following commit(s) were added to refs/heads/main by this push:
new 46049890 Crete Kamelet in VS Code #315
46049890 is described below
commit 4604989047729a2780872d39d587cdaa1bc9ff78
Author: Marat Gubaidullin <ma...@talismancloud.io>
AuthorDate: Tue Oct 31 18:14:59 2023 -0400
Crete Kamelet in VS Code #315
---
karavan-vscode/package.json | 16 ++++++++++++++++
karavan-vscode/src/designerView.ts | 28 ++++++++++++++++++++++------
karavan-vscode/src/extension.ts | 10 +++++++++-
karavan-vscode/src/openapiView.ts | 2 +-
karavan-vscode/src/utils.ts | 21 ++++++++++++++++++---
5 files changed, 66 insertions(+), 11 deletions(-)
diff --git a/karavan-vscode/package.json b/karavan-vscode/package.json
index fc243f81..02f67a60 100644
--- a/karavan-vscode/package.json
+++ b/karavan-vscode/package.json
@@ -41,6 +41,7 @@
],
"activationEvents": [
"onCommand:karavan.create-yaml",
+ "onCommand:karavan.create-kamelet",
"onCommand:karavan.create-application",
"onCommand:karavan.deploy",
"onCommand:karavan.open",
@@ -470,6 +471,11 @@
"title": "Karavan: Create Integration",
"icon": "$(add)"
},
+ {
+ "command": "karavan.create-kamelet",
+ "title": "Karavan: Create Kamelet",
+ "icon": "$(add)"
+ },
{
"command": "karavan.create-application",
"title": "Karavan: Create Application",
@@ -539,6 +545,11 @@
"when": "explorerResourceIsFolder || explorerResourceIsRoot",
"group": "karavan@2"
},
+ {
+ "command": "karavan.create-kamelet",
+ "when": "explorerResourceIsFolder || explorerResourceIsRoot",
+ "group": "karavan@2"
+ },
{
"command": "karavan.topology",
"when": "explorerResourceIsFolder || explorerResourceIsRoot || resourceFilename =~ /.camel.yaml$/",
@@ -613,6 +624,11 @@
"when": "view == integrations",
"group": "navigation@0"
},
+ {
+ "command": "karavan.create-kamelet",
+ "when": "view == integrations",
+ "group": "navigation@0"
+ },
{
"command": "karavan.run-project-jbang",
"when": "view == integrations",
diff --git a/karavan-vscode/src/designerView.ts b/karavan-vscode/src/designerView.ts
index 944b5d9e..6b832fc1 100644
--- a/karavan-vscode/src/designerView.ts
+++ b/karavan-vscode/src/designerView.ts
@@ -18,7 +18,7 @@ import {Uri, window, commands, WebviewPanel, ExtensionContext, ViewColumn, Webvi
import * as path from "path";
import * as utils from "./utils";
import { CamelDefinitionYaml } from "core/api/CamelDefinitionYaml";
-import { Integration } from "core/model/IntegrationDefinition";
+import { Integration, KameletTypesArray, KameletTypes, Metadata, MetadataLabels } from "core/model/IntegrationDefinition";
import { getWebviewContent } from "./webviewContent";
const KARAVAN_LOADED = "karavan:loaded";
@@ -58,11 +58,24 @@ export class DesignerView {
}
createIntegration(type: 'crd' | 'plain' | 'kamelet', rootPath?: string) {
+ if (type === 'kamelet') {
+ const kameletTypes = ["sink", "source", "action"];
+ window.showQuickPick(kameletTypes, { title: "Select Type", canPickMany: false }).then((kameletType) => {
+ if (kameletType) {
+ this.inputIntegrationName(type, rootPath, (kameletType as KameletTypes));
+ }
+ })
+ } else {
+ this.inputIntegrationName(type, rootPath);
+ }
+ }
+
+ inputIntegrationName(type: 'crd' | 'plain' | 'kamelet', rootPath?: string, kameletType?: KameletTypes) {
window
.showInputBox({
- title: type === 'crd' ? "Create Camel Integration CRD" : "Create Camel Integration YAML",
+ title: type === 'kamelet' ? 'Create Kamelet' : "Create Integration",
ignoreFocusOut: true,
- prompt: "Integration name",
+ prompt: type === 'kamelet' ? 'Kamelet Name' : "Integration name",
validateInput: (text: string): string | undefined => {
if (!text || text.length === 0) {
return 'Name should not be empty';
@@ -72,11 +85,14 @@ export class DesignerView {
}
}).then(value => {
if (value) {
- const name = utils.nameFromTitle(value);
- const i = Integration.createNew(name);
+ const name = utils.nameFromTitle(type, value, kameletType);
+ const filename = utils.fileNameFromName(type, name, kameletType);
+ const i:Integration = Integration.createNew(name, type);
+ if (type === 'kamelet' && i.metadata && kameletType) {
+ i.metadata.labels = new MetadataLabels({"camel.apache.org/kamelet.type": kameletType});
+ }
i.type = type;
const yaml = CamelDefinitionYaml.integrationToYaml(i);
- const filename = name.toLocaleLowerCase().endsWith('.camel.yaml') ? name : name.split('.')[0] + '.camel.yaml';
const relativePath = (this.rootPath ? rootPath?.replace(this.rootPath, "") : rootPath) + path.sep + filename;
const fullPath = (rootPath ? rootPath : this.rootPath) + path.sep + filename;
utils.save(relativePath, yaml);
diff --git a/karavan-vscode/src/extension.ts b/karavan-vscode/src/extension.ts
index ae52d15f..ca716fbf 100644
--- a/karavan-vscode/src/extension.ts
+++ b/karavan-vscode/src/extension.ts
@@ -53,12 +53,20 @@ export function activate(context: ExtensionContext) {
});
context.subscriptions.push(topologyCommand);
- // Create new Integration YAML command
+ // Create new Integration command
const createYaml = commands.registerCommand("karavan.create-yaml", (...args: any[]) => {
designer.createIntegration("plain", args[0]?.fsPath)
});
context.subscriptions.push(createYaml);
+
+ // Create new Kamelet command
+ const createKamelet = commands.registerCommand("karavan.create-kamelet", (...args: any[]) => {
+ designer.createIntegration("kamelet", args[0]?.fsPath)
+ });
+ context.subscriptions.push(createKamelet);
+
+
// Open integration in designer command
const open = commands.registerCommand("karavan.open", (...args: any[]) => {
designer.karavanOpen(args[0].fsPath, args[0].tab);
diff --git a/karavan-vscode/src/openapiView.ts b/karavan-vscode/src/openapiView.ts
index 89cf70b1..77b54601 100644
--- a/karavan-vscode/src/openapiView.ts
+++ b/karavan-vscode/src/openapiView.ts
@@ -141,7 +141,7 @@ export async function inputFileName(rootPath?: string, openApi?: OpenApiItem) {
}
}).then(value => {
if (value && openApi?.fsPath && rootPath) {
- const name = utils.nameFromTitle(value);
+ const name = utils.nameFromTitle('plain', value);
const filename = name.toLocaleLowerCase().endsWith('.camel.yaml') ? name : name.split('.')[0] + '.camel.yaml';
const fullPath = rootPath + path.sep + filename;
selectRouteGeneration(rootPath, openApi.fsPath, fullPath, false);
diff --git a/karavan-vscode/src/utils.ts b/karavan-vscode/src/utils.ts
index 21bbd538..c55901ee 100644
--- a/karavan-vscode/src/utils.ts
+++ b/karavan-vscode/src/utils.ts
@@ -17,7 +17,7 @@
import * as path from "path";
import { workspace, Uri, window, ExtensionContext, FileType } from "vscode";
import { CamelDefinitionYaml } from "core/api/CamelDefinitionYaml";
-import { Integration } from "core/model/IntegrationDefinition";
+import { KameletTypes } from "webview/core/model/IntegrationDefinition";
export function getRoot(): string | undefined {
return (workspace.workspaceFolders && (workspace.workspaceFolders.length > 0))
@@ -152,8 +152,23 @@ export function toCliFilename(filename: string): string {
: filename.replace(/\s/g, "\\ ");
}
-export function nameFromTitle(title: string): string {
- return title.replace(/[^a-z0-9+]+/gi, "-").toLowerCase();
+export function nameFromTitle(type: 'crd' | 'plain' | 'kamelet', title: string, kameletType?: KameletTypes): string {
+ title = title.replace(/[^a-z0-9+]+/gi, "-").toLowerCase();
+ if (type === 'kamelet') {
+ const suffix = '-' + kameletType;
+ return title.toLocaleLowerCase().endsWith(suffix) ? title : title + suffix;
+ } else {
+ return title;
+ }
+}
+
+export function fileNameFromName(type: 'crd' | 'plain' | 'kamelet', name: string, kameletType?: KameletTypes): string {
+ if (type === 'kamelet') {
+ const suffix = '.kamelet.yaml'
+ return name.toLocaleLowerCase().endsWith(suffix) ? name : name.split('.')[0] + suffix;
+ } else {
+ return name.toLocaleLowerCase().endsWith('.camel.yaml') ? name : name.split('.')[0] + '.camel.yaml';
+ }
}
export async function getAllFiles(dirPath, arrayOfFiles: string[]) {