Skip to content

Instantly share code, notes, and snippets.

@ljmotta
Last active September 23, 2020 19:40
Show Gist options
  • Save ljmotta/bc9d451204d5b6058a01087071fccb6b to your computer and use it in GitHub Desktop.
Save ljmotta/bc9d451204d5b6058a01087071fccb6b to your computer and use it in GitHub Desktop.
Base64Png VS Code Extension
import * as EditorEnvelope from "@kogito-tooling/editor/dist/envelope";
import { Base64PngEditorFactory } from "base64png-editor";
import { ChannelType, getOperatingSystem } from "@kogito-tooling/channel-common-api";
declare global {
export const acquireVsCodeApi: any;
}
EditorEnvelope.init({
container: document.getElementById("envelope-app")!,
bus: acquireVsCodeApi(),
editorFactory: new Base64PngEditorFactory(),
editorContext: { channel: ChannelType.VSCODE, operatingSystem: getOperatingSystem() },
});
{
"version": "0.2.0",
"configurations": [
{
"name": "Run Extension",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": ["--extensionDevelopmentPath=${workspaceFolder}"],
"outFiles": ["${workspaceFolder}/dist/**/*.js"],
"preLaunchTask": "npm: build"
}
]
}
"activationEvents": [
"onCustomEditor:kieKogitoWebviewBase64PNGEditor",
"onCommand:extension.kogito.createBase64Png"
]
"contributes": {
"customEditors": [
{
"viewType": "kieKogitoWebviewBase64PNGEditor",
"displayName": "Kogito Base64Png React Editor",
"selector": [
{
"filenamePattern": "*.base64png"
}
]
}
],
"commands": [
{
"command": "extension.kogito.createBase64Png",
"title": "Create Base64 PNG",
"icon": {
"light": "./static/kogito-logo-128x128.png",
"dark": "./static/kogito-logo-128x128.png"
}
},
{
"command": "extension.kogito.getPreviewSvg",
"title": "Save Preview SVG",
"icon": {
"light": "./static/svg-icon-light.png",
"dark": "./static/svg-icon-dark.png"
}
}
]
}
"engines": {
"vscode": "^1.46.0"
},
"contributes": {
"languages": [
{
"id": "base64png",
"extensions": [
".base64png"
],
"aliases": [
"base64png",
"Base64 PNG"
]
},
{
"id": "png",
"extensions": [
".png"
],
"aliases": [
"png",
"Png"
]
}
]
}
"main": "./dist/extension.js",
"contributes": {
"menus": {
"commandPalette": [
{
"when": "resourceLangId == png",
"command": "extension.kogito.createBase64Png"
},
{
"when": "resourceLangId == base64png",
"command": "extension.kogito.getPreviewSvg"
}
],
"editor/title": [
{
"when": "resourceLangId == png",
"command": "extension.kogito.createBase64Png",
"group": "navigation"
},
{
"when": "resourceLangId == base64png",
"command": "extension.kogito.getPreviewSvg",
"group": "navigation"
}
]
}
}
"publisher": "kogito-tooling-examples",
"name": "base64png-editor-vscode-extension"
"contributes": {
"customEditors": [
{
"viewType": "kieKogitoWebviewBase64PNGEditor",
"displayName": "Kogito Base64Png React Editor",
"selector": [
{
"filenamePattern": "*.base64png"
}
]
}
],
"commands": [
{
"command": "extension.kogito.createBase64Png",
"title": "Create Base64 PNG",
"icon": {
"light": "./static/kogito-logo-128x128.png",
"dark": "./static/kogito-logo-128x128.png"
}
},
{
"command": "extension.kogito.getPreviewSvg",
"title": "Save Preview SVG",
"icon": {
"light": "./static/svg-icon-light.png",
"dark": "./static/svg-icon-dark.png"
}
}
],
"menus": {
"commandPalette": [
{
"when": "resourceLangId == png",
"command": "extension.kogito.createBase64Png"
},
{
"when": "resourceLangId == base64png",
"command": "extension.kogito.getPreviewSvg"
}
],
"editor/title": [
{
"when": "resourceLangId == png",
"command": "extension.kogito.createBase64Png",
"group": "navigation"
},
{
"when": "resourceLangId == base64png",
"command": "extension.kogito.getPreviewSvg",
"group": "navigation"
}
]
},
"languages": [
{
"id": "base64png",
"extensions": [
".base64png"
],
"aliases": [
"base64png",
"Base64 PNG"
]
},
{
"id": "png",
"extensions": [
".png"
],
"aliases": [
"png",
"Png"
]
}
]
},
"activationEvents": [
"onCustomEditor:kieKogitoWebviewBase64PNGEditor",
"onCommand:extension.kogito.createBase64Png"
]
{
"version": "2.0.0",
"tasks": [
{
"type": "npm",
"script": "build",
"problemMatcher": "$tsc-watch",
"isBackground": true,
"presentation": {
"reveal": "never"
},
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
import * as vscode from "vscode";
import * as path from "path";
import * as fs from "fs";
context.subscriptions.push(
vscode.commands.registerCommand("extension.kogito.createBase64Png", (file: { fsPath: string }) => {
const buffer = fs.readFileSync(file.fsPath);
const parsedPath = path.parse(file.fsPath);
const base64FileName = `${parsedPath.name}${parsedPath.ext}.base64png`;
const base64AbsoluteFilePath = path.join(parsedPath.dir, base64FileName);
fs.writeFileSync(base64AbsoluteFilePath, buffer.toString("base64"));
vscode.window.showInformationMessage("Generated the Base64 file with success!", "Open").then((selected) => {
if (!selected) {
return;
}
vscode.commands.executeCommand("vscode.open", vscode.Uri.parse(base64AbsoluteFilePath));
});
})
);
import * as vscode from "vscode";
export function activate(context: vscode.ExtensionContext) {
console.info("Extension is alive.");
}
export function deactivate() {
console.info("Extension is deactivating");
}
import * as vscode from "vscode";
import * as KogitoVsCode from "@kogito-tooling/vscode-extension";
KogitoVsCode.startExtension({
extensionName: "kogito-tooling-examples.base64png-editor-vscode-extension",
context: context,
viewType: "kieKogitoWebviewBase64PNGEditor",
getPreviewCommandId: "extension.kogito.getPreviewSvg",
editorEnvelopeLocator: {
targetOrigin: "vscode",
mapping: new Map([
[
"base64png",
{
resourcesPathPrefix: `dist/`,
envelopePath: `dist/envelope/index.js`,
},
],
]),
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment