@ariga/atlas 0.15.0 → 0.17.0
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/install.js +17 -24
- package/package.json +1 -1
package/install.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
import fs from "fs";
|
|
5
5
|
import fetch from "node-fetch";
|
|
6
6
|
import path from "path";
|
|
7
|
-
import {
|
|
7
|
+
import { execFileSync } from "child_process";
|
|
8
8
|
|
|
9
9
|
// Mapping from Node's `process.arch` to Golang's `$GOARCH`
|
|
10
10
|
const ARCH_MAPPING = {
|
|
@@ -18,7 +18,7 @@ const PLATFORM_MAPPING = {
|
|
|
18
18
|
linux: "linux",
|
|
19
19
|
};
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
function getPlatform() {
|
|
22
22
|
const arch = ARCH_MAPPING[process.arch];
|
|
23
23
|
if (!arch) {
|
|
24
24
|
console.error(`Unsupported architecture: ${process.arch}`);
|
|
@@ -32,7 +32,7 @@ const getPlatform = () => {
|
|
|
32
32
|
return platform + "-" + arch;
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
|
|
35
|
+
function getPackageVersion() {
|
|
36
36
|
const jsonPath = path.join(".", "package.json")
|
|
37
37
|
const pkgJson = JSON.parse(fs.readFileSync(jsonPath, "utf8"));
|
|
38
38
|
return pkgJson.version;
|
|
@@ -40,42 +40,35 @@ const getPackageVersion = () => {
|
|
|
40
40
|
|
|
41
41
|
const installURL = "https://atlasgo.sh"
|
|
42
42
|
const installScriptPath = "./install.sh"
|
|
43
|
+
const platform = getPlatform();
|
|
43
44
|
const binPath = "./atlas"
|
|
45
|
+
const args = ["--no-install", "--output", binPath, "--platform", platform, "-y", "--user-agent", "atlas-npm"];
|
|
44
46
|
|
|
45
47
|
// download the atlas installation script from installURL
|
|
46
|
-
|
|
48
|
+
async function getInstallScript() {
|
|
47
49
|
const resp = await fetch(installURL);
|
|
48
|
-
return
|
|
50
|
+
return resp.text();
|
|
49
51
|
};
|
|
50
52
|
|
|
51
|
-
function runInstallScript(path, version
|
|
53
|
+
function runInstallScript(path, version) {
|
|
52
54
|
if (version !== undefined) {
|
|
53
55
|
version = "v" + version;
|
|
54
56
|
} else {
|
|
55
57
|
version = "latest";
|
|
56
58
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
console.info(stdout);
|
|
65
|
-
resolve(stdout? stdout : stderr);
|
|
66
|
-
console.log("Installed Atlas successfully");
|
|
67
|
-
// make the binary executable
|
|
68
|
-
fs.chmodSync(binPath, 0o744);
|
|
69
|
-
});
|
|
70
|
-
});
|
|
59
|
+
execFileSync(path, args, {
|
|
60
|
+
stdio: "inherit",
|
|
61
|
+
env: { ...process.env, ATLAS_VERSION: version },
|
|
62
|
+
})
|
|
63
|
+
console.log("Installed Atlas successfully");
|
|
64
|
+
// make the binary executable
|
|
65
|
+
fs.chmodSync(binPath, 0o744);
|
|
71
66
|
}
|
|
72
67
|
|
|
73
68
|
async function main() {
|
|
74
69
|
const script = await getInstallScript();
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
const platform = getPlatform();
|
|
78
|
-
await runInstallScript(installScriptPath, version, platform);
|
|
70
|
+
fs.writeFileSync(installScriptPath, script, { mode: 0o744 });
|
|
71
|
+
runInstallScript(installScriptPath, getPackageVersion());
|
|
79
72
|
}
|
|
80
73
|
|
|
81
74
|
await main();
|