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.
Files changed (73) hide show
  1. package/LICENSE +1 -1
  2. package/dist/index.d.mts +1 -0
  3. package/dist/index.mjs +320 -400
  4. package/dist/index.mjs.map +1 -1
  5. package/dist/module.d.ts +23 -0
  6. package/dist/module.d.ts.map +1 -0
  7. package/dist/packages/client-web/config/build.d.ts +3 -0
  8. package/dist/packages/client-web/config/build.d.ts.map +1 -0
  9. package/dist/packages/client-web/config/index.d.ts +3 -0
  10. package/dist/packages/client-web/config/index.d.ts.map +1 -0
  11. package/dist/packages/client-web/config/parse.d.ts +3 -0
  12. package/dist/packages/client-web/config/parse.d.ts.map +1 -0
  13. package/dist/packages/client-web/config/read/env.d.ts +3 -0
  14. package/dist/packages/client-web/config/read/env.d.ts.map +1 -0
  15. package/dist/packages/client-web/config/read/fs.d.ts +7 -0
  16. package/dist/packages/client-web/config/read/fs.d.ts.map +1 -0
  17. package/dist/packages/client-web/config/read/index.d.ts +2 -0
  18. package/dist/packages/client-web/config/read/index.d.ts.map +1 -0
  19. package/dist/packages/client-web/config/read/module.d.ts +8 -0
  20. package/dist/packages/client-web/config/read/module.d.ts.map +1 -0
  21. package/dist/packages/client-web/config/type.d.ts +9 -0
  22. package/dist/packages/client-web/config/type.d.ts.map +1 -0
  23. package/dist/packages/client-web/index.d.ts +3 -0
  24. package/dist/packages/client-web/index.d.ts.map +1 -0
  25. package/dist/packages/client-web/module.d.ts +9 -0
  26. package/dist/packages/client-web/module.d.ts.map +1 -0
  27. package/dist/packages/constants.d.ts +9 -0
  28. package/dist/packages/constants.d.ts.map +1 -0
  29. package/dist/packages/execute.d.ts +4 -0
  30. package/dist/packages/execute.d.ts.map +1 -0
  31. package/dist/packages/index.d.ts +6 -0
  32. package/dist/packages/index.d.ts.map +1 -0
  33. package/dist/packages/normalize.d.ts +3 -0
  34. package/dist/packages/normalize.d.ts.map +1 -0
  35. package/dist/packages/server-core/index.d.ts +2 -0
  36. package/dist/packages/server-core/index.d.ts.map +1 -0
  37. package/dist/packages/server-core/module.d.ts +7 -0
  38. package/dist/packages/server-core/module.d.ts.map +1 -0
  39. package/dist/packages/types.d.ts +9 -0
  40. package/dist/packages/types.d.ts.map +1 -0
  41. package/dist/utils/shell.d.ts +4 -4
  42. package/dist/utils/shell.d.ts.map +1 -1
  43. package/package.json +34 -22
  44. package/dist/commands/cleanup.d.ts +0 -3
  45. package/dist/commands/cleanup.d.ts.map +0 -1
  46. package/dist/commands/index.d.ts +0 -4
  47. package/dist/commands/index.d.ts.map +0 -1
  48. package/dist/commands/info.d.ts +0 -3
  49. package/dist/commands/info.d.ts.map +0 -1
  50. package/dist/commands/start.d.ts +0 -3
  51. package/dist/commands/start.d.ts.map +0 -1
  52. package/dist/index.cjs +0 -418
  53. package/dist/index.cjs.map +0 -1
  54. package/dist/services/check.d.ts +0 -3
  55. package/dist/services/check.d.ts.map +0 -1
  56. package/dist/services/client-web/config.d.ts +0 -4
  57. package/dist/services/client-web/config.d.ts.map +0 -1
  58. package/dist/services/client-web/execute.d.ts +0 -8
  59. package/dist/services/client-web/execute.d.ts.map +0 -1
  60. package/dist/services/client-web/index.d.ts +0 -3
  61. package/dist/services/client-web/index.d.ts.map +0 -1
  62. package/dist/services/constants.d.ts +0 -9
  63. package/dist/services/constants.d.ts.map +0 -1
  64. package/dist/services/execute.d.ts +0 -9
  65. package/dist/services/execute.d.ts.map +0 -1
  66. package/dist/services/index.d.ts +0 -5
  67. package/dist/services/index.d.ts.map +0 -1
  68. package/dist/services/server-core/config.d.ts +0 -4
  69. package/dist/services/server-core/config.d.ts.map +0 -1
  70. package/dist/services/server-core/execute.d.ts +0 -3
  71. package/dist/services/server-core/execute.d.ts.map +0 -1
  72. package/dist/services/server-core/index.d.ts +0 -3
  73. 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 cac from 'cac';
3
- import { deserializeKey, Container, EnvKey } from '@authup/config';
4
- import consola from 'consola';
5
- import { buildConfig } from '@authup/client-web-config';
6
- import { makeURLPublicAccessible } from '@authup/core';
7
- import path from 'node:path';
8
- import { exec } from 'node:child_process';
9
- import process from 'node:process';
10
- import { isObject, hasOwnProperty } from 'smob';
11
- import findUpPackagePath from 'resolve-package-path';
12
- import { parseConfig, buildConfig as buildConfig$1 } from '@authup/server-core';
13
- import readline from 'node:readline';
14
- import chalk from 'chalk';
15
-
16
- function isServiceValid(input) {
17
- let key;
18
- if (typeof input === 'string') {
19
- key = deserializeKey(input);
20
- } else {
21
- key = input;
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
- async function buildClientWebConfig(container) {
33
- const client = container.getData('client/web');
34
- const server = container.getData('server/core');
35
- if (server) {
36
- if (!client.apiUrl && typeof server.publicUrl === 'string') {
37
- client.apiUrl = makeURLPublicAccessible(server.publicUrl);
38
- }
39
- if (!client.publicUrl && typeof server.authorizeRedirectUrl === 'string') {
40
- client.apiUrl = makeURLPublicAccessible(server.authorizeRedirectUrl);
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
- * Copyright (c) 2023.
51
- * Author Peter Placzek (tada5hi)
52
- * For the full copyright and license information,
53
- * view the LICENSE file that was distributed with this source code.
54
- */ var ServicePackageName;
55
- (function(ServicePackageName) {
56
- ServicePackageName["CLIENT_WEB"] = "@authup/client-web";
57
- ServicePackageName["SERVER_CORE"] = "@authup/server-core";
58
- })(ServicePackageName || (ServicePackageName = {}));
59
- var ServiceCommand;
60
- (function(ServiceCommand) {
61
- ServiceCommand["START"] = "start";
62
- ServiceCommand["CLEANUP"] = "cleanup";
63
- })(ServiceCommand || (ServiceCommand = {}));
64
-
65
- /*
66
- * Copyright (c) 2022.
67
- * Author Peter Placzek (tada5hi)
68
- * For the full copyright and license information,
69
- * view the LICENSE file that was distributed with this source code.
70
- */ function removeLineBreaks(input) {
71
- return input.replace(/(\r\n|\n|\r)/gm, '');
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
- function parseProcessOutputData(input) {
75
- if (typeof input !== 'string') {
76
- return [];
77
- }
78
- const lines = input.split(/\r?\n/).filter((element)=>element);
79
- const items = [];
80
- for(let i = 0; i < lines.length; i++){
81
- const line = removeLineBreaks(lines[i]).trim();
82
- if (line.length === 0) {
83
- continue;
84
- }
85
- try {
86
- const parsed = JSON.parse(line);
87
- if (isObject(parsed) && hasOwnProperty(parsed, 'message') && typeof parsed.message === 'string') {
88
- items.push(parsed.message);
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
- * Copyright (c) 2022.
101
- * Author Peter Placzek (tada5hi)
102
- * For the full copyright and license information,
103
- * view the LICENSE file that was distributed with this source code.
104
- */ function stringifyObjectArgs(ob) {
105
- const parts = [];
106
- const keys = Object.keys(ob);
107
- for(let i = 0; i < keys.length; i++){
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
- function extendEnv(input) {
168
- const env = {};
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
- function buildWebAppExecutionContext(ctx) {
179
- if (ctx.command !== ServiceCommand.START) {
180
- throw new Error(`The command ${ctx.command} is not supported`);
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
- async function buildServerCoreConfig(container) {
217
- const data = parseConfig(container.getData('server/core'));
218
- return buildConfig$1({
219
- data,
220
- env: true
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
- function buildServerCoreExecutionContext(ctx) {
225
- let command;
226
- const modulePath = findModulePath(ServicePackageName.SERVER_CORE);
227
- if (typeof modulePath === 'string') {
228
- const directory = path.dirname(modulePath);
229
- const outputPath = path.join(directory, 'dist', 'cli', 'index.js');
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
- function buildInfoCommand(cac) {
257
- cac.command('info', 'Get information about the configuration.').option('-c, --config [config]', 'Specify a configuration file').action(async (ctx)=>{
258
- const container = new Container({
259
- prefix: 'authup',
260
- keys: [
261
- 'client/web',
262
- 'server/core'
263
- ]
264
- });
265
- if (ctx.config) {
266
- await container.loadFromFilePath(ctx.config);
267
- } else {
268
- await container.load();
269
- }
270
- const clientWeb = await buildClientWebConfig(container);
271
- consola.info(`Host: ${clientWeb.host}`);
272
- consola.info(`Port: ${clientWeb.port}`);
273
- consola.info('------------');
274
- const serverCore = await buildServerCoreConfig(container);
275
- consola.info(`Host: ${serverCore.host}`);
276
- consola.info(`Port: ${serverCore.port}`);
277
- consola.info(`Environment: ${serverCore.env}`);
278
- consola.info(`RootPath: ${serverCore.rootPath}`);
279
- consola.info(`WritableDirectoryPath: ${serverCore.writableDirectoryPath}`);
280
- consola.info('------------');
281
- consola.info('Report an issue: https://github.com/authup/authup/issues/new');
282
- consola.info('Suggest an improvement: https://github.com/authup/authup/discussions/new');
283
- consola.info('Read documentation: https://authup.org');
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
- async function executeServiceCommand(context) {
288
- let service;
289
- if (typeof context.service === 'string') {
290
- service = deserializeKey(context.service);
291
- } else {
292
- service = context.service;
293
- }
294
- const env = {};
295
- const config = context.container.get(`${service.group}/${service.name}`);
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
- async function executeServicesCommand(context) {
336
- const container = new Container({
337
- prefix: 'authup',
338
- keys: context.servicesAllowed || context.services
339
- });
340
- if (context.config) {
341
- await container.loadFromFilePath(context.config);
342
- } else {
343
- await container.load();
344
- }
345
- const promises = [];
346
- for(let i = 0; i < context.services.length; i++){
347
- const service = deserializeKey(context.services[i]);
348
- if (!isServiceValid(service)) {
349
- consola.error(`${chalk.red(`${service.group}/${service.name}`)}: The service does not exist.`);
350
- process.exit(1);
351
- }
352
- if (context.servicesAllowed && context.servicesAllowed.indexOf(`${service.group}/${service.name}`) === -1) {
353
- consola.error(`${chalk.red(`${service.group}/${service.name}`)}: The service does not support the ${context.command} command.`);
354
- process.exit(1);
355
- }
356
- promises.push(executeServiceCommand({
357
- command: context.command,
358
- service,
359
- container
360
- }));
361
- }
362
- const childProcesses = await Promise.all(promises);
363
- const readLine = readline.createInterface({
364
- input: process.stdin,
365
- output: process.stdout
366
- });
367
- readLine.on('SIGINT', ()=>{
368
- for(let i = 0; i < childProcesses.length; i++){
369
- childProcesses[i].kill();
370
- }
371
- process.exit();
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
- function buildCleanupCommand(cac) {
376
- cac.command('cleanup [...services]', 'Cleanup a service').option('-c, --config [config]', 'Specify a configuration file').action(async (keysInput, ctx)=>{
377
- const servicesAllowed = [
378
- 'server/core'
379
- ];
380
- if (!keysInput || keysInput.length === 0) {
381
- keysInput = servicesAllowed;
382
- }
383
- await executeServicesCommand({
384
- config: ctx.config,
385
- command: ServiceCommand.CLEANUP,
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
- function buildStartCommand(cac) {
393
- cac.command('start [...services]', 'Start a service').option('-c, --config [config]', 'Specify a configuration file').action(async (keysInput, ctx)=>{
394
- const servicesAllowed = [
395
- 'client/web',
396
- 'server/core'
397
- ];
398
- if (!keysInput || keysInput.length === 0) {
399
- keysInput = servicesAllowed;
400
- }
401
- await executeServicesCommand({
402
- config: ctx.config,
403
- command: ServiceCommand.START,
404
- services: keysInput,
405
- servicesAllowed
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
- const cli = cac();
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