forked from learn-anything/learn-anything
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcmd.ts
149 lines (137 loc) · 4.4 KB
/
cmd.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
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
import { $ } from "bnx"
// TODO: make it so you can for given command get its help
// or take the `//` before each case and generate a table in readme with possible commands and descriptions
const args = Bun.argv
const command = args[2]
switch (command) {
// sets up .env files for grafbase, grafbase/edgedb and website + clones other LA repos
case "init":
await setupEnvFiles()
await getFullMonorepo()
break
// sets up .env files for grafbase, grafbase/edgedb and website
case "env":
await setupEnvFiles()
break
// clones other LA repos
case "getFullMonorepo":
await getFullMonorepo()
break
// seed edgedb from files in seed folder
// TODO: finish
case "seedEdgeDb":
await seedEdgeDb()
break
// updates mobius schema in shared/lib/mobius so all graphql clients are type safe
case "updateMobiusSchema":
await updateMobiusSchema()
break
case undefined:
console.log("No command provided")
break
default:
console.log("Unknown command")
break
}
async function setupEnvFiles() {
const currentFilePath = import.meta.path
const grafbaseEnvPath = `${currentFilePath.replace(
"cmd.ts",
"grafbase/.env"
)}`
const grfabaseEnvfileExists = await Bun.file(grafbaseEnvPath).exists()
if (!grfabaseEnvfileExists) {
Bun.write(
grafbaseEnvPath,
`LOCAL=true
EDGEDB_DSN=
PUBLIC_HANKO_API_URL=https://e879ccc9-285e-49d3-b37e-b569f0db4035.hanko.io
INTERNAL_SECRET=secret`
)
} else {
console.log(`File: ${grafbaseEnvPath} already exists`)
}
const grafbaseEdgedbEnvPath = `${currentFilePath.replace(
"cmd.ts",
"grafbase/edgedb/.env"
)}`
const grafbaseEdgedbEnvFileExists = await Bun.file(
grafbaseEdgedbEnvPath
).exists()
if (!grafbaseEdgedbEnvFileExists) {
Bun.write(
grafbaseEdgedbEnvPath,
`LOCAL=true
GRAFBASE_URL=http://127.0.0.1:4000/graphql
GRAFBASE_INTERNAL_SECRET=secret
LOCAL_USER_HANKO_ID=
wikiFolderPath=
email=`
)
} else {
console.log(`File: ${grafbaseEdgedbEnvPath} already exists`)
}
const websiteEnvFilePath = `${currentFilePath.replace(
"cmd.ts",
"website/.env"
)}`
const websiteEnvFileExists = await Bun.file(websiteEnvFilePath).exists()
if (!websiteEnvFileExists) {
Bun.write(
websiteEnvFilePath,
`VITE_HANKO_API=https://e879ccc9-285e-49d3-b37e-b569f0db4035.hanko.io
VITE_GRAFBASE_API_URL=http://127.0.0.1:4000/graphql
VITE_GRAFBASE_INTERNAL_SECRET=secret`
)
} else {
console.log(`File: ${websiteEnvFilePath} already exists`)
}
console.log(".env files created")
// TODO: create .env file with my current content for local dev! for easy DX win
// TODO: update readme telling users they should have the .env file already
// if they ran `dev-setup`
// TODO: do same for website/.env
// and grafbase/edgedb/.env
// update readme so its very good
// as part of setup
// make it accept an argument for `seed-db`
// parse `seed/..` and fill local edgedb with content!
// load limited connections from .json (part of seed)
// + topics so it works and connections work too
// as part of setup add topics etc.
// ask to create a member/admin user automatically (default yes)
// if yes, ask for email to use
// if no provided use `user@email.com` as member with admin ability
// parse args!
// everything as part of seed repo
// make setup fully interactive!
// check if `edgedb` is installed and in path
// if not, find OS, then provide user with installing
// edgedb for them, run curl for them? or some other way
// maybe in future have `setup -with-nix` or provide
// flake with flox or how grafbase repo has it
}
// TODO: add error checks, nice log in case folder already exists
// https://github.com/wobsoriano/bnx/issues/3
async function getFullMonorepo() {
await $`git clone https://github.com/learn-anything/ai`
await $`git clone https://github.com/learn-anything/solana`
}
// TODO: make better, automate full seed without any feedback from user
async function seedEdgeDb() {
await $`mv seed/seed.db grafbase/edgedb`
}
async function updateMobiusSchema() {
const schema = (
await $`npx grafbase@latest introspect http://127.0.0.1:4000/graphql`
).trim()
const formattedSchema = `export const grafbaseTypeDefs = \`
${schema}
\``
const currentFilePath = import.meta.path
const mobiusFilePath = `${currentFilePath.replace(
"cmd.ts",
"shared/lib/mobius.ts"
)}`
Bun.write(mobiusFilePath, formattedSchema)
}