From eebb84c1fb0f23dad423ce48073aa82f30f443f8 Mon Sep 17 00:00:00 2001 From: fox Date: Sun, 9 Jun 2019 23:31:53 +0800 Subject: [PATCH] fix the notice infomation --- .gitignore | 3 ++- .vscodeignore | 2 +- CHANGELOG.md | 5 +++++ package.json | 2 +- src/downloader.ts | 43 ++++++++++++++++++++++++++++++++++++++----- 5 files changed, 47 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index 1c1bf4e7..9deffd5e 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,5 @@ node_modules branch.txt minichangelog.txt version.txt -dist \ No newline at end of file +dist +bin \ No newline at end of file diff --git a/.vscodeignore b/.vscodeignore index 60b649cb..78e2d932 100644 --- a/.vscodeignore +++ b/.vscodeignore @@ -23,5 +23,5 @@ typings vsc-extension-quickstart.md webpack.config.json yarn.lock - +bin diff --git a/CHANGELOG.md b/CHANGELOG.md index 7d3e3ac6..7ebc883b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ Check [Keep a Changelog](https://keepachangelog.com/) for recommendations on how to structure this file. + +## 6.0.0 +- Let the plugin work out of the box and automatically download the shfmt of the corresponding platform. +- No longer get shfmt from PATH + ## 5.0.1 - support both `-i` flag and `editor.tabSize` setting diff --git a/package.json b/package.json index aee9feb4..9278af9c 100644 --- a/package.json +++ b/package.json @@ -137,7 +137,7 @@ "null" ], "default": null, - "description": "shfmt -h to see detail usage , example: -i 4 -p" + "description": "shfmt -h to see detail usage , example: -p -bn -ci" }, "shellformat.effectLanguages": { "type": "array", diff --git a/src/downloader.ts b/src/downloader.ts index 92396c0c..4f09a0e0 100644 --- a/src/downloader.ts +++ b/src/downloader.ts @@ -118,6 +118,15 @@ export function getArchExtension(): Arch { return Arch.unknown; } } + +function getExecuteableFileExt() { + if (process.platform === "win32") { + return ".exe"; + } else { + return ""; + } +} + export function getPlatform(): Platform { switch (process.platform) { case "win32": @@ -141,7 +150,9 @@ export function getPlatFormFilename() { if (arch === Arch.unknown || platform == Platform.unknown) { throw new Error("do not find release shfmt for your platform"); } - return `shfmt_${config.shfmtVersion}_${platform}_${arch}`; + return `shfmt_${ + config.shfmtVersion + }_${platform}_${arch}${getExecuteableFileExt()}`; } export function getReleaseDownloadUrl() { @@ -181,26 +192,47 @@ export async function checkInstall( await ensureDirectory(path.dirname(destPath)); const needDownload = await checkNeedInstall(destPath, output); if (needDownload) { + output.show(); try { await cleanFile(destPath); } catch (err) { output.appendLine( `clean old file failed:[ ${destPath} ] ,please delete it mutual` ); + output.show(); return; } const url = getReleaseDownloadUrl(); try { - output.appendLine("will download automated!"); + output.appendLine("Shfmt will be downloaded automatically!"); + output.appendLine(`download url: ${url}`); + output.appendLine(`download to: ${destPath}`); + output.appendLine( + `If the download fails, you can manually download it to the dest directory.` + ); + output.appendLine( + 'Or download to another directory, and then set the "shellformat.path" as the path' + ); + output.appendLine( + `download shfmt page: https://github.com/mvdan/sh/releases` + ); + output.appendLine( + `You can't use this plugin until the download is successful.` + ); + output.show(); await download2(url, destPath, (d, t) => { output.appendLine(`downloaded:[${((100.0 * d) / t).toFixed(2)}%]`); + output.show(); }); await fs.promises.chmod(destPath, 755); - output.appendLine(`download success`); + output.appendLine(`download success, You can use it successfully!`); + output.appendLine( + "Suggestions or issues can be submitted here https://git.io/vsshell-issues" + ); } catch (err) { output.appendLine(`download failed: ${err}`); } - output.show(true); + output.show(); } } @@ -233,7 +265,8 @@ async function checkNeedInstall( } return needInstall; } catch (err) { - output.appendLine(`not download shfmt yet!`); + output.appendLine(`shfmt hasn't downloaded yet!`); + output.show(); return true; } }