-
-
Notifications
You must be signed in to change notification settings - Fork 229
Expand file tree
/
Copy path_setup_utils.mjs
More file actions
191 lines (166 loc) · 4.43 KB
/
_setup_utils.mjs
File metadata and controls
191 lines (166 loc) · 4.43 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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
import { fs, os } from "zx";
import { readDotenv, withDotenvUpdater } from "./lib/dotenv.mjs";
import { safeRandomString } from "./lib/random.mjs";
if (parseInt(process.version.split(".")[0], 10) < 10) {
throw new Error("This project requires Node.js >= 10.0.0");
}
// fixes runSync not throwing ENOENT on windows
export const yarnCmd = os.platform() === "win32" ? "yarn.cmd" : "yarn";
export const projectName = process.env.PROJECT_NAME;
export { readDotenv, withDotenvUpdater };
export function updateDotenv(add, answers) {
add(
"GRAPHILE_LICENSE",
null,
`\
# If you're supporting PostGraphile's development via Patreon or Graphile
# Store, add your license key from https://store.graphile.com here so you can
# use the Pro plugin - thanks so much!`
);
add(
"NODE_ENV",
"development",
`\
# This is a development environment (production wouldn't write envvars to a file)`
);
add(
"ROOT_DATABASE_URL",
null,
`\
# Superuser connection string (to a _different_ database), so databases can be dropped/created (may not be necessary in production)`
);
add(
"DATABASE_HOST",
null,
`\
# Where's the DB, and who owns it?`
);
add("DATABASE_NAME");
add("DATABASE_OWNER", answers.DATABASE_NAME);
add("DATABASE_OWNER_PASSWORD", safeRandomString(30));
add(
"DATABASE_AUTHENTICATOR",
`${answers.DATABASE_NAME}_authenticator`,
`\
# The PostGraphile database user, which has very limited
# privileges, but can switch into the DATABASE_VISITOR role`
);
add("DATABASE_AUTHENTICATOR_PASSWORD", safeRandomString(30));
add(
"DATABASE_VISITOR",
`${answers.DATABASE_NAME}_visitor`,
`\
# Visitor role, cannot be logged into directly`
);
add(
"SECRET",
safeRandomString(30),
`\
# This secret is used for signing cookies`
);
add(
"JWT_SECRET",
safeRandomString(48),
`\
# This secret is used for signing JWT tokens (we don't use this by default)`
);
add(
"PORT",
"5678",
`\
# This port is the one you'll connect to`
);
add(
"ROOT_URL",
"http://localhost:5678",
`\
# This is needed any time we use absolute URLs, e.g. for OAuth callback URLs
# IMPORTANT: must NOT end with a slash`
);
add(
"GITHUB_KEY",
null,
`\
# To enable login with GitHub, create a GitHub application by visiting
# https://github.com/settings/applications/new and then enter the Client
# ID/Secret below
#
# Name: PostGraphile Starter (Dev)
# Homepage URL: http://localhost:5678
# Authorization callback URL: http://localhost:5678/auth/github/callback
#
# Client ID:`
);
add(
"GITHUB_SECRET",
null,
`\
# Client Secret:`
);
const nodeVersion = parseInt(
process.version.replace(/\..*$/, "").replace(/[^0-9]/g, ""),
10
);
add(
"GRAPHILE_TURBO",
nodeVersion >= 12 ? "1" : "",
`\
# Set to 1 only if you're on Node v12 of higher; enables advanced optimisations:`
);
if (projectName) {
add(
"COMPOSE_PROJECT_NAME",
projectName,
`\
# The name of the folder you cloned graphile-starter to (so we can run docker-compose inside a container):`
);
}
}
export async function checkGit() {
try {
const gitStat = await fs.stat(`${__dirname}/../.git`);
if (!gitStat || !gitStat.isDirectory()) {
throw new Error("No .git folder found");
}
} catch (e) {
console.error();
console.error();
console.error();
console.error(
"ERROR: Graphile Starter must run inside of a git versioned folder. Please run the following:"
);
console.error();
console.error(" git init");
console.error(" git add .");
console.error(" git commit -m 'Graphile Starter base'");
console.error();
console.error(
"For more information, read https://github.com/graphile/starter#making-it-yours"
);
console.error();
console.error();
console.error();
process.exit(1);
}
}
export const runMain = (main) => {
main().catch((e) => {
console.error(e);
process.exit(1);
});
};
export const outro = (message) => {
console.log();
console.log();
console.log("____________________________________________________________");
console.log();
console.log();
console.log(message);
console.log();
console.log();
console.log("🙏 Please support our Open Source work:");
console.log(" https://graphile.org/sponsor");
console.log();
console.log("____________________________________________________________");
console.log();
};