diff --git a/.gitignore b/.gitignore index 35a77d7..6198bab 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,5 @@ dist node_modules .vscode-test/ *.vsix -build \ No newline at end of file +build +snekdown*-*x86_64* \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md deleted file mode 100644 index c264e03..0000000 --- a/CHANGELOG.md +++ /dev/null @@ -1,9 +0,0 @@ -# Change Log - -All notable changes to the "snekdown-preview" extension will be documented in this file. - -Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file. - -## [Unreleased] - -- Initial release \ No newline at end of file diff --git a/README.md b/README.md index fcb99ae..e9be66d 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,18 @@ downloads the latest one. ## Release Notes -### 1.0.0 +### 0.9.3 + +- Add update command + +### 0.9.2 + +- Fix downloader buffer behaviour + +### 0.9.1 + +- Fix windows download path + +### 0.9.0 Initial release of the snekdown extension \ No newline at end of file diff --git a/package.json b/package.json index d0dccda..711f5ec 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ "url": "https://github.com/Trivernis/snekdown-vscode-extension.git" }, "description": "Preview and commands for the snekdown markdown flavour", - "version": "0.9.2", + "version": "0.9.3", "engines": { "vscode": "^1.52.0" }, @@ -25,6 +25,9 @@ "onCommand:snekdown.preview", "onCommand:snekdown.preview-side", "onCommand:snekdown.clear-cache", + "onCommand:snekdown.update-binary", + "onCommand:snekdown.export-html", + "onCommand:snekdown.export-pdf", "onLanguage:snekdown", "onLanguage:markdown" ], @@ -39,6 +42,10 @@ "command": "snekdown.clear-cache", "title": "Snekdown: Clear Cache" }, + { + "command": "snekdown.update-binary", + "title": "Snekdown: Update Binary" + }, { "command": "snekdown.preview", "title": "Snekdown: Open Preview" diff --git a/src/extension.ts b/src/extension.ts index 55d13fe..0a52e59 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -9,18 +9,33 @@ let snekdownWebview: SnekdownWebView; export async function activate(context: vscode.ExtensionContext) { const snekdownWrapper = new SnekdownWrapper(context); - await snekdownWrapper.download(); + + await vscode.window.withProgress({ + location: vscode.ProgressLocation.Window, + title: "Downloading Snekdown" + }, async () => { + await snekdownWrapper.download() + }) context.subscriptions.push(vscode.commands.registerCommand('snekdown.init', async () => { await snekdownWrapper.init(); vscode.window.showInformationMessage("Snekdown Project initialized."); })); - context.subscriptions.push(vscode.commands.registerCommand('snekdown.clear-ache', async () => { + context.subscriptions.push(vscode.commands.registerCommand('snekdown.clear-cache', async () => { await snekdownWrapper.clearCache(); vscode.window.showInformationMessage("Snekdown cache cleared."); })) + context.subscriptions.push(vscode.commands.registerCommand('snekdown.update-binary', async () => { + await vscode.window.withProgress({ + location: vscode.ProgressLocation.Window, + title: "Downloading Snekdown" + }, async () => { + await snekdownWrapper.download(true) + }); + })) + context.subscriptions.push(vscode.commands.registerTextEditorCommand('snekdown.preview', async () => { if (!snekdownWebview || snekdownWebview.isDisposed) { snekdownWebview = new SnekdownWebView(context, snekdownWrapper, vscode.ViewColumn.One); @@ -43,7 +58,10 @@ export async function activate(context: vscode.ExtensionContext) { value: placeholderOutput, }); if (outputFile) { - await vscode.window.withProgress({ location: vscode.ProgressLocation.Window, title: "Rendering HTML" }, async () => { + await vscode.window.withProgress({ + location: vscode.ProgressLocation.Window, + title: "Rendering HTML" + }, async () => { await snekdownWrapper.renderToFile(inputFile, outputFile as string, RenderingFormat.html); }); } @@ -57,7 +75,10 @@ export async function activate(context: vscode.ExtensionContext) { value: placeholderOutput, }); if (outputFile) { - await vscode.window.withProgress({ location: vscode.ProgressLocation.Window, title: "Rendering PDF" }, async () => { + await vscode.window.withProgress({ + location: vscode.ProgressLocation.Window, + title: "Rendering PDF" + }, async () => { await snekdownWrapper.renderToFile(inputFile, outputFile as string, RenderingFormat.pdf); }); } diff --git a/src/snekdown-wrapper.ts b/src/snekdown-wrapper.ts index 89b24de..0fad378 100644 --- a/src/snekdown-wrapper.ts +++ b/src/snekdown-wrapper.ts @@ -68,34 +68,50 @@ export class SnekdownWrapper { /** * Detects or downloads the snekdown executable */ - public async download () { + public async download (force: boolean = false) { let execPath: string; + let res: any; switch (os.platform()) { case 'win32': execPath = this.buildExecutablePath(SNEKDOWN_FILE_WINDOWS); - await fetch(SNEKDOWN_URL_WINDOWS).then(res => { - fs.writeFileSync(execPath, res.buffer); - }); this.executable = execPath; + + await SnekdownWrapper.downloadFile(SNEKDOWN_URL_WINDOWS, this.executable, force); break; case 'linux': - if (fs.existsSync("/usr/bin/snekdown")) { + if (fs.existsSync("/usr/bin/snekdown") && false) { this.executable = "/usr/bin/snekdown"; break; } execPath = this.buildExecutablePath(SNEKDOWN_FILE_LINUX); - await fetch(SNEKDOWN_URL_LINUX).then(res => { - fs.writeFileSync(execPath, res.buffer); - }); this.executable = execPath; + await SnekdownWrapper.downloadFile(SNEKDOWN_URL_LINUX, this.executable, force); + chmodSync(execPath, "555"); break; default: throw new Error("OS Platform not supported."); } } + + /** + * Downloads a file if it doesn't exist + * @param url + * @param path + * @param force + */ + private static async downloadFile(url: string, path: string, force: boolean = false) { + if (fs.existsSync(path)) { + if (!force) { + return; + } + fs.unlinkSync(path); + } + const res = await fetch(url); + fs.writeFileSync(path, await res.buffer()); + } /** * Builds the path in the extension folder for a given file