Repository navigation
Expand file tree
/
Copy pathutils.ts
More file actions
86 lines (76 loc) · 2.2 KB
/
Copy pathutils.ts
File metadata and controls
86 lines (76 loc) · 2.2 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
import { parse as parseEnv } from "@std/dotenv";
import { parse as parseYaml, stringify as stringifyYaml } from "@std/yaml";
import { exists } from "@std/fs";
import { join, resolve } from "@std/path";
export const ROOT = import.meta.dirname!;
export type Service = {
name: string;
repo: string;
config: string;
data: string[];
};
export const SERVICES: Service[] = [
{
name: "client",
repo: "openhotel",
config: "app/server/config.yml",
data: ["app/server/server-database*", "app/server/database-backups"],
},
{
name: "auth",
repo: "auth",
config: "app/server/config.yml",
data: [
"app/server/database*",
"app/server/deleteme-database*",
"app/server/backups",
],
},
{
name: "onet",
repo: "onet",
config: "config.yml",
data: ["database*", "collections-key"],
},
{
name: "web",
repo: "web",
config: "app/server/config.yml",
data: ["app/server/database*", "app/server/backups"],
},
{
name: "asset-editor",
repo: "asset-editor",
config: "app/server/config.yml",
data: [],
},
{
name: "static",
repo: "static",
config: "app/server/config.yml",
data: ["app/server/database*", "app/server/files"],
},
];
export const ok = (message: string) =>
console.log(`%c✔ ${message}`, "color: green");
export const warn = (message: string) =>
console.log(`%c⚠ ${message}`, "color: yellow");
export const fail = (message: string): never => {
console.log(`%c✘ ${message}`, "color: red");
Deno.exit(1);
};
export const loadEnv = async (): Promise<Record<string, string>> => {
const envPath = join(ROOT, ".env");
if (!(await exists(envPath))) {
await Deno.copyFile(join(ROOT, ".env.example"), envPath);
ok(".env created from .env.example");
}
return parseEnv(await Deno.readTextFile(envPath));
};
export const getReposDir = (env: Record<string, string>) =>
resolve(ROOT, env.REPOS_DIR ?? "..");
export const readYaml = async <Data = Record<string, unknown>>(
path: string,
): Promise<Data> => (parseYaml(await Deno.readTextFile(path)) ?? {}) as Data;
export const writeYaml = (path: string, data: unknown) =>
Deno.writeTextFile(path, stringifyYaml(data, { lineWidth: -1 }));