generated from axetroy/go-cli-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
93 additions
and
1 deletion.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,6 @@ | |
# vendor/ | ||
|
||
.idea | ||
bin | ||
dist | ||
coverage.out | ||
release.md | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
bin/whatchanged | ||
bin/whatchanged.exe | ||
*-lock.json | ||
*.lock |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
node_modules | ||
*.lock | ||
package-lock.json | ||
dist |
Empty file.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
throw new Error("what changed command line did not install correctly"); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"name": "whatchanged", | ||
"version": "0.2.2", | ||
"description": "An elegant changelog generator", | ||
"bin": "./bin/whatchanged", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1", | ||
"postinstall": "node scripts/postinstall.js" | ||
}, | ||
"author": "Axetroy", | ||
"license": "ISC", | ||
"dependencies": { | ||
"download": "^8.0.0", | ||
"progress": "^2.0.3" | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
const path = require("path"); | ||
const os = require("os"); | ||
const download = require("download"); | ||
const ProgressBar = require("progress"); | ||
|
||
const pkg = require("../package.json"); | ||
|
||
function getArch() { | ||
const arch = os.arch(); | ||
switch (arch) { | ||
case "ia32": | ||
case "x32": | ||
return "386"; | ||
case "x64": | ||
return "amd64"; | ||
case "arm": | ||
// @ts-expect-error ignore error | ||
const armv = process.config.variables.arm_version; | ||
|
||
if (!armv) return "armv7"; | ||
|
||
return `armv${armv}`; | ||
default: | ||
return arch; | ||
} | ||
} | ||
|
||
function getPlatform() { | ||
const platform = os.platform(); | ||
switch (platform) { | ||
case "win32": | ||
return "windows"; | ||
default: | ||
return platform; | ||
} | ||
} | ||
|
||
function getDownloadURL(version) { | ||
const url = `https://github.com/axetroy/whatchanged/releases/download/${version}/whatchanged_${getPlatform()}_${getArch()}.tar.gz`; | ||
return url; | ||
} | ||
|
||
async function install(version) { | ||
const url = getDownloadURL(version); | ||
|
||
console.log(`Downloading '${url}'`); | ||
|
||
const bar = new ProgressBar("[:bar] :percent :etas", { | ||
complete: "=", | ||
incomplete: " ", | ||
width: 20, | ||
total: 0, | ||
}); | ||
|
||
await download(url, path.join(__dirname, "..", "bin"), { | ||
extract: true, | ||
}).on("response", (res) => { | ||
bar.total = res.headers["content-length"]; | ||
res.on("data", (data) => bar.tick(data.length)); | ||
res.on("error", (err) => { | ||
console.error("error"); | ||
}); | ||
}); | ||
} | ||
|
||
install("v" + pkg.version).catch((err) => { | ||
throw err; | ||
}); |