@humanmd/cli 0.1.0-alpha.5 → 0.1.0-alpha.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/scripts/postinstall.js +5 -45
package/package.json
CHANGED
package/scripts/postinstall.js
CHANGED
|
@@ -43,7 +43,7 @@ const version = process.env.HMD_CLI_VERSION || packageJson.version;
|
|
|
43
43
|
const tag =
|
|
44
44
|
process.env.HMD_CLI_RELEASE_TAG || (version.startsWith("v") ? version : `v${version}`);
|
|
45
45
|
const target = targetTriple();
|
|
46
|
-
const assetUrl = process.env.HMD_CLI_ASSET_URL || (
|
|
46
|
+
const assetUrl = process.env.HMD_CLI_ASSET_URL || releaseAssetUrl(repo, tag, target);
|
|
47
47
|
const workDir = mkdtempSync(join(tmpdir(), "hmd-cli-"));
|
|
48
48
|
|
|
49
49
|
try {
|
|
@@ -81,50 +81,10 @@ function targetTriple() {
|
|
|
81
81
|
return target;
|
|
82
82
|
}
|
|
83
83
|
|
|
84
|
-
|
|
85
|
-
const
|
|
86
|
-
const
|
|
87
|
-
|
|
88
|
-
?.filter((candidate) => candidate.name.includes(target))
|
|
89
|
-
.filter((candidate) => /\.(tar\.xz|tar\.gz|tgz|zip)$/.test(candidate.name))
|
|
90
|
-
.find((candidate) => /(^|[-_])hmd([-_]|$)|hmd-cli/.test(candidate.name));
|
|
91
|
-
|
|
92
|
-
if (!asset) {
|
|
93
|
-
throw new Error(`no @humanmd/cli release artifact for ${target} in ${repo}@${tag}`);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
return asset.browser_download_url;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
function fetchText(url) {
|
|
100
|
-
return new Promise((resolve, reject) => {
|
|
101
|
-
get(
|
|
102
|
-
url,
|
|
103
|
-
{
|
|
104
|
-
headers: {
|
|
105
|
-
Accept: "application/vnd.github+json",
|
|
106
|
-
"User-Agent": "@humanmd/cli postinstall",
|
|
107
|
-
},
|
|
108
|
-
},
|
|
109
|
-
(response) => {
|
|
110
|
-
if (isRedirect(response.statusCode)) {
|
|
111
|
-
fetchText(response.headers.location).then(resolve, reject);
|
|
112
|
-
return;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
if (response.statusCode < 200 || response.statusCode >= 300) {
|
|
116
|
-
reject(new Error(`GET ${url} failed with HTTP ${response.statusCode}`));
|
|
117
|
-
response.resume();
|
|
118
|
-
return;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
const chunks = [];
|
|
122
|
-
response.setEncoding("utf8");
|
|
123
|
-
response.on("data", (chunk) => chunks.push(chunk));
|
|
124
|
-
response.on("end", () => resolve(chunks.join("")));
|
|
125
|
-
}
|
|
126
|
-
).on("error", reject);
|
|
127
|
-
});
|
|
84
|
+
function releaseAssetUrl(repo, tag, target) {
|
|
85
|
+
const extension = process.platform === "win32" ? "zip" : "tar.xz";
|
|
86
|
+
const assetName = `hmd-cli-${target}.${extension}`;
|
|
87
|
+
return `https://github.com/${repo}/releases/download/${tag}/${assetName}`;
|
|
128
88
|
}
|
|
129
89
|
|
|
130
90
|
function download(url, path) {
|