-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart.ts
More file actions
134 lines (124 loc) · 4.11 KB
/
start.ts
File metadata and controls
134 lines (124 loc) · 4.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
import { existsSync, readFileSync } from "fs";
import * as path from "path";
import * as os from "os";
import { log, setLogLevel } from "./utils/logger";
import { execute as exec } from "./runners";
setLogLevel(5);
const isWin = process.platform === "win32";
const home = os.homedir();
const asdfDir = path.join(home, ".asdf");
const asdfShims = path.join(home, ".asdf", "shims");
const env = {
...process.env,
PATH: `${asdfShims}:${process.env.PATH}`,
ASDF_DIR: asdfDir,
};
const versionsPath = path.join(__dirname, "versions.sh");
// Homebrew (macOS only)
// if (!isWin) {
// try {
// await exec({command: "brew --version", dir: home}, "start_script");
// log({level: 5, color: "YELLOW"}, "Homebrew is installed.")
// } catch {
// log({level: 3, color: "GREEN"}, "Installing Homebrew...")
// await exec({command: '/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"', dir: home}, "start_script");
// }
// }
const main = async () => {
let asdfInstalled = false;
try {
await exec(
{ command: isWin ? "where asdf" : "asdf --version", dir: home },
"start_script"
);
asdfInstalled = true;
log({ level: 5, color: "YELLOW" }, "asdf is installed.");
} catch {
if (!isWin) {
log({ level: 3, color: "GREEN" }, "Installing asdf...");
await exec({ command: "brew install asdf", dir: home }, "start_script");
asdfInstalled = true;
} else {
console.error(
"asdf installation on Windows is not automated. Please install asdf manually."
);
process.exit(1);
}
}
// Source versions.sh (parse for env vars)
const versions: Record<string, string> = {};
if (existsSync(versionsPath)) {
log({ level: 3, color: "GREEN" }, "Sourcing versions.sh...");
const lines = readFileSync(versionsPath, "utf8").split("\n");
for (const line of lines) {
const match = line.match(/^\s*([a-zA-Z_][a-zA-Z0-9_]*)=(.*)$/);
if (match) {
versions[match[1]] = match[2].replace(/['"]/g, "");
}
}
} else {
console.error("versions.sh not found in the same directory.");
process.exit(1);
}
// Helper for asdf install
async function asdfInstall(plugin: string, version: string) {
try {
await exec({ command: `asdf list ${plugin}`, dir: home }, "start_script");
log({ level: 5, color: "YELLOW" }, `${plugin} is already installed.`);
} catch {
await exec(
{ command: `asdf plugin-add ${plugin}`, dir: home },
"start_script"
);
await exec(
{ command: `asdf install ${plugin} ${version}`, dir: home },
"start_script"
);
await exec(
{ command: `asdf global ${plugin} ${version}`, dir: home },
"start_script"
);
}
}
// Install Erlang, Elixir, Node.js
if (asdfInstalled) {
if (versions.erlang) await asdfInstall("erlang", versions.erlang);
if (versions.elixir) await asdfInstall("elixir", versions.elixir);
if (versions.nodejs) await asdfInstall("nodejs", versions.nodejs);
}
if (!isWin) {
try {
await exec({ command: "docker --version", dir: home }, "start_script");
log({ level: 5, color: "YELLOW" }, "Docker is installed.");
} catch {
log({ level: 3, color: "GREEN" }, "Installing Docker...");
await exec(
{ command: "brew install --cask docker", dir: home },
"start_script"
);
log(
{ level: 3, color: "GREEN" },
"Docker installed. Please launch Docker Desktop manually if required."
);
}
} else {
log(
{ level: 1, color: "RED" },
"!!! Please install Docker Desktop manually on Windows: https://www.docker.com/products/docker-desktop/ !!!"
);
}
// Install Hex and Phoenix (Elixir)
log({ level: 3, color: "GREEN" }, "Installing Hex and Phoenix...");
await exec(
{ command: "mix local.hex --force", dir: home, env },
"start_script"
);
await exec(
{ command: "mix archive.install hex phx_new --force", dir: home },
"start_script"
);
log({ level: 1, color: "GREEN" }, "Setup complete.");
};
main().catch((error) => {
console.error("Error:", error);
});