forked from open-source-labs/DenoGres
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmod.ts
80 lines (75 loc) · 2.22 KB
/
mod.ts
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
/* This module contains the denoGres commands that are compiled when typed in a command line */
import { config, parse } from "./deps.ts";
import "https://deno.land/x/dotenv/load.ts";
import { init } from "./src/functions/init.ts";
import seed from "./src/functions/seed.ts";
import { resolve } from "https://deno.land/[email protected]/path/win32.ts";
import sync from "./src/functions/sync.ts";
import { dbPull } from "./src/functions/dbPull.ts";
import restoreModel from "./src/functions/restore.ts";
switch (Deno.args[0]) {
case "--init":
init();
break;
case "--log": {
const myLog = Deno.readTextFileSync(
"./Migrations/log/migration_log.txt",
);
console.log(myLog);
break;
}
case "--db-pull": {
const envVar = parse(await Deno.readTextFile("./.env"));
if (envVar.DATABASE_URI === "") {
console.log("Please enter a valid DATABASE_URI value in .env");
} else {
dbPull();
}
break;
}
case "--db-sync": {
Deno.args[1] === "-x" ? sync(true) : sync();
break;
}
case "-h":
case "--help": {
console.log(displayHelpMsg());
break;
}
case "--gui": {
const app = Deno.run({
cmd: [
"deno",
"run",
"-Ar",
"--unstable",
"https://deno.land/x/denogres/webview/webview.ts",
// "https://deno.land/x/denogresdev/webview/webview.ts",
],
});
await app.status();
break;
}
case "--db-seed": {
Deno.args[1] === undefined ? seed() : seed(Deno.args[1]);
break;
}
case "--restore": {
restoreModel();
break;
}
default:
}
function displayHelpMsg() {
return `flags:
--db-pull: Introspect database, create and populate model.ts file
--db-seed: Upload locally stored data file to the PostgreSQL database
--db-sync: Update the PostgreSQL database schema to match the DenoGres Model schema
--gui: Launch the DenoGres graphical user interface
-h, --help: Display the list of all commands
--init: Set-up files required by DenoGres
--log: Display a historical log of DenoGres Model schemas
--restore: Restore locally stored DenoGres Model schemas and sync with the PostgreSQL database`;
}
export { Model } from "./src/class/Model.ts";
export { manyToMany } from "./src/class/Model.ts";