Skip to content

Commit

Permalink
fix the notice infomation
Browse files Browse the repository at this point in the history
  • Loading branch information
foxundermoon committed Jun 9, 2019
1 parent ddd0cd2 commit eebb84c
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 8 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ node_modules
branch.txt
minichangelog.txt
version.txt
dist
dist
bin
2 changes: 1 addition & 1 deletion .vscodeignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ typings
vsc-extension-quickstart.md
webpack.config.json
yarn.lock

bin

5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
43 changes: 38 additions & 5 deletions src/downloader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand All @@ -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() {
Expand Down Expand Up @@ -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();
}
}

Expand Down Expand Up @@ -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;
}
}
Expand Down

0 comments on commit eebb84c

Please sign in to comment.