Last active
September 23, 2020 19:40
-
-
Save ljmotta/bc9d451204d5b6058a01087071fccb6b to your computer and use it in GitHub Desktop.
Base64Png VS Code Extension
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() }, | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"version": "0.2.0", | |
"configurations": [ | |
{ | |
"name": "Run Extension", | |
"type": "extensionHost", | |
"request": "launch", | |
"runtimeExecutable": "${execPath}", | |
"args": ["--extensionDevelopmentPath=${workspaceFolder}"], | |
"outFiles": ["${workspaceFolder}/dist/**/*.js"], | |
"preLaunchTask": "npm: build" | |
} | |
] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"activationEvents": [ | |
"onCustomEditor:kieKogitoWebviewBase64PNGEditor", | |
"onCommand:extension.kogito.createBase64Png" | |
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"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" | |
} | |
} | |
] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"engines": { | |
"vscode": "^1.46.0" | |
}, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"contributes": { | |
"languages": [ | |
{ | |
"id": "base64png", | |
"extensions": [ | |
".base64png" | |
], | |
"aliases": [ | |
"base64png", | |
"Base64 PNG" | |
] | |
}, | |
{ | |
"id": "png", | |
"extensions": [ | |
".png" | |
], | |
"aliases": [ | |
"png", | |
"Png" | |
] | |
} | |
] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"main": "./dist/extension.js", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"publisher": "kogito-tooling-examples", | |
"name": "base64png-editor-vscode-extension" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"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" | |
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"version": "2.0.0", | |
"tasks": [ | |
{ | |
"type": "npm", | |
"script": "build", | |
"problemMatcher": "$tsc-watch", | |
"isBackground": true, | |
"presentation": { | |
"reveal": "never" | |
}, | |
"group": { | |
"kind": "build", | |
"isDefault": true | |
} | |
} | |
] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | |
}); | |
}) | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as vscode from "vscode"; | |
export function activate(context: vscode.ExtensionContext) { | |
console.info("Extension is alive."); | |
} | |
export function deactivate() { | |
console.info("Extension is deactivating"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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