authup 1.0.0-beta.4 → 1.0.0-beta.41
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/dist/index.d.mts +1 -0
- package/dist/index.mjs +320 -400
- package/dist/index.mjs.map +1 -1
- package/dist/module.d.ts +23 -0
- package/dist/module.d.ts.map +1 -0
- package/dist/packages/client-web/config/build.d.ts +3 -0
- package/dist/packages/client-web/config/build.d.ts.map +1 -0
- package/dist/packages/client-web/config/index.d.ts +3 -0
- package/dist/packages/client-web/config/index.d.ts.map +1 -0
- package/dist/packages/client-web/config/parse.d.ts +3 -0
- package/dist/packages/client-web/config/parse.d.ts.map +1 -0
- package/dist/packages/client-web/config/read/env.d.ts +3 -0
- package/dist/packages/client-web/config/read/env.d.ts.map +1 -0
- package/dist/packages/client-web/config/read/fs.d.ts +7 -0
- package/dist/packages/client-web/config/read/fs.d.ts.map +1 -0
- package/dist/packages/client-web/config/read/index.d.ts +2 -0
- package/dist/packages/client-web/config/read/index.d.ts.map +1 -0
- package/dist/packages/client-web/config/read/module.d.ts +8 -0
- package/dist/packages/client-web/config/read/module.d.ts.map +1 -0
- package/dist/packages/client-web/config/type.d.ts +9 -0
- package/dist/packages/client-web/config/type.d.ts.map +1 -0
- package/dist/packages/client-web/index.d.ts +3 -0
- package/dist/packages/client-web/index.d.ts.map +1 -0
- package/dist/packages/client-web/module.d.ts +9 -0
- package/dist/packages/client-web/module.d.ts.map +1 -0
- package/dist/packages/constants.d.ts +9 -0
- package/dist/packages/constants.d.ts.map +1 -0
- package/dist/packages/execute.d.ts +4 -0
- package/dist/packages/execute.d.ts.map +1 -0
- package/dist/packages/index.d.ts +6 -0
- package/dist/packages/index.d.ts.map +1 -0
- package/dist/packages/normalize.d.ts +3 -0
- package/dist/packages/normalize.d.ts.map +1 -0
- package/dist/packages/server-core/index.d.ts +2 -0
- package/dist/packages/server-core/index.d.ts.map +1 -0
- package/dist/packages/server-core/module.d.ts +7 -0
- package/dist/packages/server-core/module.d.ts.map +1 -0
- package/dist/packages/types.d.ts +9 -0
- package/dist/packages/types.d.ts.map +1 -0
- package/dist/utils/shell.d.ts +4 -4
- package/dist/utils/shell.d.ts.map +1 -1
- package/package.json +34 -22
- package/dist/commands/cleanup.d.ts +0 -3
- package/dist/commands/cleanup.d.ts.map +0 -1
- package/dist/commands/index.d.ts +0 -4
- package/dist/commands/index.d.ts.map +0 -1
- package/dist/commands/info.d.ts +0 -3
- package/dist/commands/info.d.ts.map +0 -1
- package/dist/commands/start.d.ts +0 -3
- package/dist/commands/start.d.ts.map +0 -1
- package/dist/index.cjs +0 -418
- package/dist/index.cjs.map +0 -1
- package/dist/services/check.d.ts +0 -3
- package/dist/services/check.d.ts.map +0 -1
- package/dist/services/client-web/config.d.ts +0 -4
- package/dist/services/client-web/config.d.ts.map +0 -1
- package/dist/services/client-web/execute.d.ts +0 -8
- package/dist/services/client-web/execute.d.ts.map +0 -1
- package/dist/services/client-web/index.d.ts +0 -3
- package/dist/services/client-web/index.d.ts.map +0 -1
- package/dist/services/constants.d.ts +0 -9
- package/dist/services/constants.d.ts.map +0 -1
- package/dist/services/execute.d.ts +0 -9
- package/dist/services/execute.d.ts.map +0 -1
- package/dist/services/index.d.ts +0 -5
- package/dist/services/index.d.ts.map +0 -1
- package/dist/services/server-core/config.d.ts +0 -4
- package/dist/services/server-core/config.d.ts.map +0 -1
- package/dist/services/server-core/execute.d.ts +0 -3
- package/dist/services/server-core/execute.d.ts.map +0 -1
- package/dist/services/server-core/index.d.ts +0 -3
- package/dist/services/server-core/index.d.ts.map +0 -1
package/dist/index.mjs
CHANGED
|
@@ -1,416 +1,336 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import { makeURLPublicAccessible } from
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import {
|
|
11
|
-
import
|
|
12
|
-
import
|
|
13
|
-
import
|
|
14
|
-
import
|
|
15
|
-
|
|
16
|
-
function
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
if (key.group !== 'client' && key.group !== 'server') {
|
|
24
|
-
return false;
|
|
25
|
-
}
|
|
26
|
-
if (key.group === 'client') {
|
|
27
|
-
return key.name === 'web';
|
|
28
|
-
}
|
|
29
|
-
return key.name === 'core';
|
|
2
|
+
import { defineCommand, runMain } from "citty";
|
|
3
|
+
import fs from "node:fs";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import process from "node:process";
|
|
6
|
+
import { extendObject, hasOwnProperty, isObject, makeURLPublicAccessible } from "@authup/kit";
|
|
7
|
+
import { defineGetter, dycraft } from "dycraft";
|
|
8
|
+
import zod from "zod";
|
|
9
|
+
import { merge } from "smob";
|
|
10
|
+
import { oneOf, read, readInt } from "envix";
|
|
11
|
+
import { Container } from "confinity";
|
|
12
|
+
import consola from "consola";
|
|
13
|
+
import { exec } from "node:child_process";
|
|
14
|
+
import findUpPackagePath from "resolve-package-path";
|
|
15
|
+
//#region src/packages/client-web/config/parse.ts
|
|
16
|
+
function parseClientWebConfig(input = {}) {
|
|
17
|
+
return zod.object({
|
|
18
|
+
port: zod.number().nonnegative().optional(),
|
|
19
|
+
host: zod.string().optional(),
|
|
20
|
+
apiUrl: zod.string().url().optional(),
|
|
21
|
+
publicUrl: zod.string().url().optional()
|
|
22
|
+
}).parse(input);
|
|
30
23
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}
|
|
43
|
-
return buildConfig({
|
|
44
|
-
data: client,
|
|
45
|
-
env: true
|
|
46
|
-
});
|
|
24
|
+
//#endregion
|
|
25
|
+
//#region src/packages/client-web/config/build.ts
|
|
26
|
+
function buildClientWebConfig(raw) {
|
|
27
|
+
return extendObject(dycraft({
|
|
28
|
+
defaults: {
|
|
29
|
+
port: 3e3,
|
|
30
|
+
host: "0.0.0.0",
|
|
31
|
+
apiUrl: "http://127.0.0.1:3001/"
|
|
32
|
+
},
|
|
33
|
+
getters: { publicUrl: defineGetter((context) => `http://${makeURLPublicAccessible(context.get("host"))}:${context.get("port")}/`) }
|
|
34
|
+
}), parseClientWebConfig(raw));
|
|
47
35
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
(
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
(
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
36
|
+
//#endregion
|
|
37
|
+
//#region src/packages/client-web/config/read/env.ts
|
|
38
|
+
function readClientWebConfigFromEnv() {
|
|
39
|
+
const config = {};
|
|
40
|
+
const port = oneOf([
|
|
41
|
+
readInt("UI_PORT"),
|
|
42
|
+
readInt("NITRO_UI_PORT"),
|
|
43
|
+
readInt("NUXT_UI_PORT"),
|
|
44
|
+
readInt("NUXT_PUBLIC_UI_PORT"),
|
|
45
|
+
readInt("PORT"),
|
|
46
|
+
readInt("NITRO_PORT"),
|
|
47
|
+
readInt("NUXT_PORT"),
|
|
48
|
+
readInt("NUXT_PUBLIC_PORT")
|
|
49
|
+
]);
|
|
50
|
+
if (typeof port !== "undefined") config.port = port;
|
|
51
|
+
const host = oneOf([
|
|
52
|
+
read("HOST"),
|
|
53
|
+
read("NITRO_HOST"),
|
|
54
|
+
read("NUXT_HOST")
|
|
55
|
+
]);
|
|
56
|
+
if (host) config.host = host;
|
|
57
|
+
const apiUrl = oneOf([
|
|
58
|
+
read("API_URL"),
|
|
59
|
+
read("NUXT_API_URL"),
|
|
60
|
+
read("NUXT_PUBLIC_API_URL")
|
|
61
|
+
]);
|
|
62
|
+
if (apiUrl) config.apiUrl = apiUrl;
|
|
63
|
+
const publicURL = oneOf([
|
|
64
|
+
read("PUBLIC_URL"),
|
|
65
|
+
read("NUXT_PUBLIC_URL"),
|
|
66
|
+
read("NUXT_PUBLIC_PUBLIC_URL")
|
|
67
|
+
]);
|
|
68
|
+
if (publicURL) config.publicUrl = publicURL;
|
|
69
|
+
return config;
|
|
72
70
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
continue;
|
|
90
|
-
}
|
|
91
|
-
} catch (e) {
|
|
92
|
-
// no json :/
|
|
93
|
-
}
|
|
94
|
-
items.push(line);
|
|
95
|
-
}
|
|
96
|
-
return items;
|
|
71
|
+
//#endregion
|
|
72
|
+
//#region src/packages/client-web/config/read/fs.ts
|
|
73
|
+
async function readClientWebConfigFromFS(options = {}) {
|
|
74
|
+
const container = new Container({
|
|
75
|
+
prefix: "authup",
|
|
76
|
+
cwd: options.cwd
|
|
77
|
+
});
|
|
78
|
+
if (options.file) await container.loadFile(options.file);
|
|
79
|
+
else await container.load();
|
|
80
|
+
const clientRaw = container.get("client.web") || {};
|
|
81
|
+
const serverRaw = container.get("server.core") || {};
|
|
82
|
+
if (serverRaw) {
|
|
83
|
+
if (!clientRaw.apiUrl && typeof serverRaw.publicUrl === "string") clientRaw.apiUrl = makeURLPublicAccessible(serverRaw.publicUrl);
|
|
84
|
+
if (!clientRaw.publicUrl && typeof serverRaw.authorizeRedirectUrl === "string") clientRaw.apiUrl = makeURLPublicAccessible(serverRaw.authorizeRedirectUrl);
|
|
85
|
+
}
|
|
86
|
+
return clientRaw;
|
|
97
87
|
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
parts.push(`--${keys[i]} ${ob[keys[i]]}`);
|
|
109
|
-
}
|
|
110
|
-
return parts.join(' ');
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
async function execShellCommand(ctx) {
|
|
114
|
-
ctx.env = ctx.env || {};
|
|
115
|
-
ctx.args = ctx.args || {};
|
|
116
|
-
return new Promise((resolve, reject)=>{
|
|
117
|
-
const childProcess = exec(`${ctx.command} ${stringifyObjectArgs(ctx.args)}`, {
|
|
118
|
-
env: {
|
|
119
|
-
PATH: process.env.PATH,
|
|
120
|
-
...ctx.envFromProcess ? process.env : {},
|
|
121
|
-
...ctx.env
|
|
122
|
-
}
|
|
123
|
-
});
|
|
124
|
-
childProcess.on('error', (data)=>{
|
|
125
|
-
reject(data);
|
|
126
|
-
});
|
|
127
|
-
childProcess.on('spawn', ()=>{
|
|
128
|
-
resolve(childProcess);
|
|
129
|
-
});
|
|
130
|
-
childProcess.stderr.setEncoding('utf-8');
|
|
131
|
-
childProcess.stderr.on('data', (data)=>{
|
|
132
|
-
if (typeof data !== 'string' || data.length === 0) {
|
|
133
|
-
return;
|
|
134
|
-
}
|
|
135
|
-
if (ctx.logErrorStream) {
|
|
136
|
-
ctx.logErrorStream(data);
|
|
137
|
-
}
|
|
138
|
-
});
|
|
139
|
-
childProcess.stdout.on('data', (data)=>{
|
|
140
|
-
if (typeof data !== 'string' || data.length === 0) {
|
|
141
|
-
return;
|
|
142
|
-
}
|
|
143
|
-
if (!ctx.logDataStream) {
|
|
144
|
-
return;
|
|
145
|
-
}
|
|
146
|
-
const lines = parseProcessOutputData(data);
|
|
147
|
-
for(let i = 0; i < lines.length; i++){
|
|
148
|
-
ctx.logDataStream(lines[i]);
|
|
149
|
-
}
|
|
150
|
-
});
|
|
151
|
-
});
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
const PACKAGE_DIRECTORY = path.join(__dirname, '..');
|
|
155
|
-
|
|
156
|
-
function findModulePath(module) {
|
|
157
|
-
let modulePath = findUpPackagePath(module, PACKAGE_DIRECTORY);
|
|
158
|
-
if (PACKAGE_DIRECTORY !== process.cwd()) {
|
|
159
|
-
modulePath = findUpPackagePath(module, process.cwd());
|
|
160
|
-
}
|
|
161
|
-
if (!modulePath) {
|
|
162
|
-
return undefined;
|
|
163
|
-
}
|
|
164
|
-
return modulePath;
|
|
88
|
+
//#endregion
|
|
89
|
+
//#region src/packages/client-web/config/read/module.ts
|
|
90
|
+
async function readClientWebConfigRaw(options = {}) {
|
|
91
|
+
if (options.fs && options.env) {
|
|
92
|
+
const fs = await readClientWebConfigFromFS(boolableToObject(options.fs));
|
|
93
|
+
return merge(readClientWebConfigFromEnv(), fs);
|
|
94
|
+
}
|
|
95
|
+
if (options.fs) return readClientWebConfigFromFS(boolableToObject(options.fs));
|
|
96
|
+
if (options.env) return readClientWebConfigFromEnv();
|
|
97
|
+
return {};
|
|
165
98
|
}
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
const keys = Object.keys(input);
|
|
170
|
-
for(let i = 0; i < keys.length; i++){
|
|
171
|
-
env[keys[i]] = input[keys[i]];
|
|
172
|
-
if (!keys[i].match(/^(?:NUXT|NITRO)_.*$/)) {
|
|
173
|
-
env[`NUXT_PUBLIC_${keys[i]}`] = input[keys[i]];
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
return env;
|
|
99
|
+
function boolableToObject(input) {
|
|
100
|
+
if (typeof input === "boolean") return {};
|
|
101
|
+
return input;
|
|
177
102
|
}
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
const env = ctx.env || {};
|
|
183
|
-
const data = ctx.container.getData('client/web');
|
|
184
|
-
const config = buildConfig({
|
|
185
|
-
data,
|
|
186
|
-
env: true
|
|
187
|
-
});
|
|
188
|
-
if (config.host) {
|
|
189
|
-
env.HOST = config.host;
|
|
190
|
-
}
|
|
191
|
-
if (config.port) {
|
|
192
|
-
env.PORT = `${config.port}`;
|
|
193
|
-
}
|
|
194
|
-
if (config.apiUrl) {
|
|
195
|
-
env.API_URL = config.apiUrl;
|
|
196
|
-
}
|
|
197
|
-
if (config.publicUrl) {
|
|
198
|
-
env.PUBLIC_URL = config.publicUrl;
|
|
199
|
-
}
|
|
200
|
-
let command;
|
|
201
|
-
const modulePath = findModulePath(ServicePackageName.CLIENT_WEB);
|
|
202
|
-
if (typeof modulePath === 'string') {
|
|
203
|
-
const directory = path.dirname(modulePath);
|
|
204
|
-
const outputPath = path.join(directory, '.output', 'server', 'index.mjs');
|
|
205
|
-
command = `node ${outputPath}`;
|
|
206
|
-
} else {
|
|
207
|
-
command = `npx ${ServicePackageName.CLIENT_WEB}`;
|
|
208
|
-
}
|
|
209
|
-
return {
|
|
210
|
-
...ctx,
|
|
211
|
-
command,
|
|
212
|
-
env: extendEnv(env)
|
|
213
|
-
};
|
|
103
|
+
//#endregion
|
|
104
|
+
//#region src/utils/line-breaks.ts
|
|
105
|
+
function removeLineBreaks(input) {
|
|
106
|
+
return input.replace(/(\r\n|\n|\r)/gm, "");
|
|
214
107
|
}
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
108
|
+
//#endregion
|
|
109
|
+
//#region src/utils/process-output.ts
|
|
110
|
+
function parseProcessOutputData(input) {
|
|
111
|
+
if (typeof input !== "string") return [];
|
|
112
|
+
const lines = input.split(/\r?\n/).filter((element) => element);
|
|
113
|
+
const items = [];
|
|
114
|
+
for (const line_ of lines) {
|
|
115
|
+
const line = removeLineBreaks(line_).trim();
|
|
116
|
+
if (line.length === 0) continue;
|
|
117
|
+
try {
|
|
118
|
+
const parsed = JSON.parse(line);
|
|
119
|
+
if (isObject(parsed) && hasOwnProperty(parsed, "message") && typeof parsed.message === "string") {
|
|
120
|
+
items.push(parsed.message);
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
} catch {}
|
|
124
|
+
items.push(line);
|
|
125
|
+
}
|
|
126
|
+
return items;
|
|
222
127
|
}
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
command = `node ${outputPath}`;
|
|
231
|
-
} else {
|
|
232
|
-
command = `npx ${ServicePackageName.SERVER_CORE}`;
|
|
233
|
-
}
|
|
234
|
-
switch(ctx.command){
|
|
235
|
-
case ServiceCommand.START:
|
|
236
|
-
{
|
|
237
|
-
command += ' start';
|
|
238
|
-
break;
|
|
239
|
-
}
|
|
240
|
-
case ServiceCommand.CLEANUP:
|
|
241
|
-
{
|
|
242
|
-
command += ' reset';
|
|
243
|
-
break;
|
|
244
|
-
}
|
|
245
|
-
default:
|
|
246
|
-
{
|
|
247
|
-
throw new Error(`The command ${ctx.command} is not supported.`);
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
return {
|
|
251
|
-
...ctx,
|
|
252
|
-
command
|
|
253
|
-
};
|
|
128
|
+
//#endregion
|
|
129
|
+
//#region src/utils/stringify-object-args.ts
|
|
130
|
+
function stringifyObjectArgs(ob) {
|
|
131
|
+
const parts = [];
|
|
132
|
+
const keys = Object.keys(ob);
|
|
133
|
+
for (const key of keys) parts.push(`--${key} ${ob[key]}`);
|
|
134
|
+
return parts.join(" ");
|
|
254
135
|
}
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
});
|
|
136
|
+
//#endregion
|
|
137
|
+
//#region src/utils/shell.ts
|
|
138
|
+
async function execShellCommand(command, ctx = {}) {
|
|
139
|
+
return new Promise((resolve, reject) => {
|
|
140
|
+
const childProcess = exec(`${command} ${stringifyObjectArgs(ctx.args || {})}`, { env: {
|
|
141
|
+
PATH: process.env.PATH,
|
|
142
|
+
...ctx.envFromProcess ? process.env : {},
|
|
143
|
+
...ctx.env ? ctx.env : {}
|
|
144
|
+
} });
|
|
145
|
+
childProcess.on("error", (data) => {
|
|
146
|
+
reject(data);
|
|
147
|
+
});
|
|
148
|
+
childProcess.on("spawn", () => {
|
|
149
|
+
resolve(childProcess);
|
|
150
|
+
});
|
|
151
|
+
if (childProcess.stderr) {
|
|
152
|
+
childProcess.stderr.setEncoding("utf-8");
|
|
153
|
+
childProcess.stderr.on("data", (data) => {
|
|
154
|
+
if (typeof data !== "string" || data.length === 0) return;
|
|
155
|
+
if (ctx.logErrorStream) ctx.logErrorStream(data);
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
if (childProcess.stdout) childProcess.stdout.on("data", (data) => {
|
|
159
|
+
if (typeof data !== "string" || data.length === 0) return;
|
|
160
|
+
if (!ctx.logDataStream) return;
|
|
161
|
+
const lines = parseProcessOutputData(data);
|
|
162
|
+
for (const line of lines) ctx.logDataStream(line);
|
|
163
|
+
});
|
|
164
|
+
});
|
|
285
165
|
}
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
if (config) {
|
|
297
|
-
const paths = config.paths.join(',');
|
|
298
|
-
if (paths.length > 0) {
|
|
299
|
-
env[EnvKey.CONFIG_FILE] = paths;
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
let shellExecContext;
|
|
303
|
-
try {
|
|
304
|
-
if (service.group === 'server' && service.name === 'core') {
|
|
305
|
-
shellExecContext = buildServerCoreExecutionContext({
|
|
306
|
-
command: context.command,
|
|
307
|
-
env
|
|
308
|
-
});
|
|
309
|
-
}
|
|
310
|
-
if (service.group === 'client' && service.name === 'web') {
|
|
311
|
-
shellExecContext = buildWebAppExecutionContext({
|
|
312
|
-
container: context.container,
|
|
313
|
-
command: context.command,
|
|
314
|
-
env
|
|
315
|
-
});
|
|
316
|
-
}
|
|
317
|
-
} catch (e) {
|
|
318
|
-
consola.error(`${service.group}/${service.name}: The service command ${context.command} not supported.`);
|
|
319
|
-
process.exit(1);
|
|
320
|
-
}
|
|
321
|
-
if (!shellExecContext) {
|
|
322
|
-
consola.error(`${service.group}/${service.name}: The service is not supported.`);
|
|
323
|
-
process.exit(1);
|
|
324
|
-
}
|
|
325
|
-
return execShellCommand({
|
|
326
|
-
...shellExecContext,
|
|
327
|
-
logDataStream (line) {
|
|
328
|
-
consola.info(`${service.group}/${service.name}: ${line}`);
|
|
329
|
-
},
|
|
330
|
-
logErrorStream (line) {
|
|
331
|
-
consola.warn(`${service.group}/${service.name}: ${line}`);
|
|
332
|
-
}
|
|
333
|
-
});
|
|
166
|
+
//#endregion
|
|
167
|
+
//#region src/constants.ts
|
|
168
|
+
const PACKAGE_DIRECTORY = path.join(__dirname, "..");
|
|
169
|
+
//#endregion
|
|
170
|
+
//#region src/utils/modules-path.ts
|
|
171
|
+
function findModulePath(module) {
|
|
172
|
+
let modulePath = findUpPackagePath(module, PACKAGE_DIRECTORY);
|
|
173
|
+
if (PACKAGE_DIRECTORY !== process.cwd()) modulePath = findUpPackagePath(module, process.cwd());
|
|
174
|
+
if (!modulePath) return;
|
|
175
|
+
return modulePath;
|
|
334
176
|
}
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
177
|
+
//#endregion
|
|
178
|
+
//#region src/packages/constants.ts
|
|
179
|
+
let PackageID = /* @__PURE__ */ function(PackageID) {
|
|
180
|
+
PackageID["CLIENT_WEB"] = "client.web";
|
|
181
|
+
PackageID["SERVER_CORE"] = "server.core";
|
|
182
|
+
return PackageID;
|
|
183
|
+
}({});
|
|
184
|
+
//#endregion
|
|
185
|
+
//#region src/packages/client-web/module.ts
|
|
186
|
+
var ClientWebPackage = class {
|
|
187
|
+
async execute(command, options = {}) {
|
|
188
|
+
return execShellCommand(await this.buildShellCommand(), {
|
|
189
|
+
env: await this.buildEnv({
|
|
190
|
+
configDirectory: options.configDirectory,
|
|
191
|
+
configFile: options.configFile
|
|
192
|
+
}),
|
|
193
|
+
logDataStream(line) {
|
|
194
|
+
consola.info(`client.web: ${line}`);
|
|
195
|
+
},
|
|
196
|
+
logErrorStream(line) {
|
|
197
|
+
consola.warn(`client.web: ${line}`);
|
|
198
|
+
}
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
async buildShellCommand() {
|
|
202
|
+
let shellCommand;
|
|
203
|
+
const modulePath = findModulePath("@authup/client-web");
|
|
204
|
+
if (typeof modulePath === "string") {
|
|
205
|
+
const directory = path.dirname(modulePath);
|
|
206
|
+
shellCommand = `node ${path.join(directory, ".output", "server", "index.mjs")}`;
|
|
207
|
+
} else shellCommand = `npx @authup/client-web`;
|
|
208
|
+
return shellCommand;
|
|
209
|
+
}
|
|
210
|
+
async buildEnv(ctx) {
|
|
211
|
+
const env = {};
|
|
212
|
+
const config = buildClientWebConfig(await readClientWebConfigRaw({ fs: {
|
|
213
|
+
file: ctx.configFile,
|
|
214
|
+
cwd: ctx.configDirectory
|
|
215
|
+
} }));
|
|
216
|
+
if (config.host) env.HOST = config.host;
|
|
217
|
+
if (config.port) env.PORT = `${config.port}`;
|
|
218
|
+
if (config.apiUrl) env.API_URL = config.apiUrl;
|
|
219
|
+
if (config.publicUrl) env.PUBLIC_URL = config.publicUrl;
|
|
220
|
+
return this.extendEnvKeys(env);
|
|
221
|
+
}
|
|
222
|
+
extendEnvKeys(input) {
|
|
223
|
+
const env = {};
|
|
224
|
+
const keys = Object.keys(input);
|
|
225
|
+
for (const key of keys) {
|
|
226
|
+
env[key] = input[key];
|
|
227
|
+
if (!key.match(/^(?:NUXT|NITRO)_.*$/)) env[`NUXT_PUBLIC_${key}`] = input[key];
|
|
228
|
+
}
|
|
229
|
+
return env;
|
|
230
|
+
}
|
|
231
|
+
};
|
|
232
|
+
//#endregion
|
|
233
|
+
//#region src/packages/server-core/module.ts
|
|
234
|
+
var ServerCorePackage = class {
|
|
235
|
+
async execute(command, options = {}) {
|
|
236
|
+
return execShellCommand(await this.buildShellCommand(command, {
|
|
237
|
+
configDirectory: options.configDirectory,
|
|
238
|
+
configFile: options.configFile
|
|
239
|
+
}), {
|
|
240
|
+
logDataStream(line) {
|
|
241
|
+
consola.info(`server.core: ${line}`);
|
|
242
|
+
},
|
|
243
|
+
logErrorStream(line) {
|
|
244
|
+
consola.warn(`server.core: ${line}`);
|
|
245
|
+
}
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
async buildShellCommand(command, options) {
|
|
249
|
+
const parts = [];
|
|
250
|
+
const modulePath = findModulePath("@authup/server-core");
|
|
251
|
+
if (typeof modulePath === "string") {
|
|
252
|
+
const directory = path.dirname(modulePath);
|
|
253
|
+
const outputPath = path.join(directory, "dist", "cli.mjs");
|
|
254
|
+
parts.push(`node ${outputPath}`);
|
|
255
|
+
} else parts.push(`npx @authup/server-core`);
|
|
256
|
+
parts.push(command);
|
|
257
|
+
if (options.configFile) parts.push(`--configFile=${options.configFile}`);
|
|
258
|
+
if (options.configDirectory) parts.push(`--configDirectory=${options.configDirectory}`);
|
|
259
|
+
return parts.join(" ");
|
|
260
|
+
}
|
|
261
|
+
};
|
|
262
|
+
//#endregion
|
|
263
|
+
//#region src/packages/execute.ts
|
|
264
|
+
async function executePackageCommand(pkg, command, options = {}) {
|
|
265
|
+
switch (pkg) {
|
|
266
|
+
case "client.web": return new ClientWebPackage().execute(command, options);
|
|
267
|
+
case "server.core": return new ServerCorePackage().execute(command, options);
|
|
268
|
+
}
|
|
269
|
+
throw new Error(`The package ${pkg} is not supported.`);
|
|
373
270
|
}
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
services: keysInput,
|
|
387
|
-
servicesAllowed
|
|
388
|
-
});
|
|
389
|
-
});
|
|
271
|
+
//#endregion
|
|
272
|
+
//#region src/packages/normalize.ts
|
|
273
|
+
function normalizePackageID(input) {
|
|
274
|
+
switch (input.trim().toLowerCase()) {
|
|
275
|
+
case "client.web":
|
|
276
|
+
case "client/web":
|
|
277
|
+
case "client-web": return "client.web";
|
|
278
|
+
case "server.core":
|
|
279
|
+
case "server/core":
|
|
280
|
+
case "server-core": return "server.core";
|
|
281
|
+
}
|
|
282
|
+
return null;
|
|
390
283
|
}
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
284
|
+
//#endregion
|
|
285
|
+
//#region src/module.ts
|
|
286
|
+
async function createCLIEntryPointCommand() {
|
|
287
|
+
const pkgRaw = await fs.promises.readFile(path.join(process.cwd(), "package.json"), { encoding: "utf8" });
|
|
288
|
+
const pkg = JSON.parse(pkgRaw);
|
|
289
|
+
return defineCommand({
|
|
290
|
+
meta: {
|
|
291
|
+
name: pkg.name,
|
|
292
|
+
version: pkg.version,
|
|
293
|
+
description: pkg.description
|
|
294
|
+
},
|
|
295
|
+
args: {
|
|
296
|
+
command: {
|
|
297
|
+
type: "positional",
|
|
298
|
+
description: "The command which should be forwarded to the package.",
|
|
299
|
+
required: true
|
|
300
|
+
},
|
|
301
|
+
package: {
|
|
302
|
+
type: "positional",
|
|
303
|
+
description: "The package, which should be targeted.",
|
|
304
|
+
required: false
|
|
305
|
+
},
|
|
306
|
+
configDirectory: {
|
|
307
|
+
type: "string",
|
|
308
|
+
description: "Config directory path",
|
|
309
|
+
alias: "cD"
|
|
310
|
+
},
|
|
311
|
+
configFile: {
|
|
312
|
+
type: "string",
|
|
313
|
+
description: "Name of one or more configuration files.",
|
|
314
|
+
alias: "cF"
|
|
315
|
+
}
|
|
316
|
+
},
|
|
317
|
+
async run(ctx) {
|
|
318
|
+
let packages = ctx.args.package ? ctx.args.package.split(",") : [];
|
|
319
|
+
if (packages.length > 0) packages = packages.map((pkg) => normalizePackageID(pkg)).filter((pkg) => Boolean(pkg)).map((pkg) => `${pkg}`);
|
|
320
|
+
if (packages.length === 0) packages = Object.values(PackageID);
|
|
321
|
+
const promises = [];
|
|
322
|
+
for (const package_ of packages) promises.push(executePackageCommand(package_, ctx.args.command, {
|
|
323
|
+
configFile: ctx.args.configFile,
|
|
324
|
+
configDirectory: ctx.args.configDirectory
|
|
325
|
+
}));
|
|
326
|
+
await Promise.all(promises);
|
|
327
|
+
}
|
|
328
|
+
});
|
|
408
329
|
}
|
|
330
|
+
//#endregion
|
|
331
|
+
//#region src/index.ts
|
|
332
|
+
Promise.resolve().then(() => createCLIEntryPointCommand()).then((command) => runMain(command));
|
|
333
|
+
//#endregion
|
|
334
|
+
export {};
|
|
409
335
|
|
|
410
|
-
|
|
411
|
-
buildInfoCommand(cli);
|
|
412
|
-
buildStartCommand(cli);
|
|
413
|
-
buildCleanupCommand(cli);
|
|
414
|
-
cli.help();
|
|
415
|
-
cli.parse();
|
|
416
|
-
//# sourceMappingURL=index.mjs.map
|
|
336
|
+
//# sourceMappingURL=index.mjs.map
|