authup 1.0.0-beta.19 → 1.0.0-beta.20

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 (71) hide show
  1. package/dist/index.cjs +298 -277
  2. package/dist/index.cjs.map +1 -1
  3. package/dist/index.mjs +298 -277
  4. package/dist/index.mjs.map +1 -1
  5. package/dist/module.d.ts +22 -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 +13 -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 -3
  42. package/dist/utils/shell.d.ts.map +1 -1
  43. package/package.json +8 -8
  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/services/check.d.ts +0 -3
  53. package/dist/services/check.d.ts.map +0 -1
  54. package/dist/services/client-web/config.d.ts +0 -4
  55. package/dist/services/client-web/config.d.ts.map +0 -1
  56. package/dist/services/client-web/execute.d.ts +0 -8
  57. package/dist/services/client-web/execute.d.ts.map +0 -1
  58. package/dist/services/client-web/index.d.ts +0 -3
  59. package/dist/services/client-web/index.d.ts.map +0 -1
  60. package/dist/services/constants.d.ts +0 -9
  61. package/dist/services/constants.d.ts.map +0 -1
  62. package/dist/services/execute.d.ts +0 -9
  63. package/dist/services/execute.d.ts.map +0 -1
  64. package/dist/services/index.d.ts +0 -5
  65. package/dist/services/index.d.ts.map +0 -1
  66. package/dist/services/server-core/config.d.ts +0 -4
  67. package/dist/services/server-core/config.d.ts.map +0 -1
  68. package/dist/services/server-core/execute.d.ts +0 -3
  69. package/dist/services/server-core/execute.d.ts.map +0 -1
  70. package/dist/services/server-core/index.d.ts +0 -3
  71. package/dist/services/server-core/index.d.ts.map +0 -1
package/dist/index.mjs CHANGED
@@ -1,65 +1,129 @@
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, isObject, hasOwnProperty } from '@authup/kit';
2
+ import { defineCommand, runMain } from 'citty';
3
+ import fs from 'node:fs';
7
4
  import path from 'node:path';
8
- import { exec } from 'node:child_process';
9
5
  import process from 'node:process';
6
+ import { makeURLPublicAccessible, extendObject, isObject, hasOwnProperty } from '@authup/kit';
7
+ import { dycraft, defineGetter } from 'dycraft';
8
+ import zod from 'zod';
9
+ import { merge } from 'smob';
10
+ import { oneOf, readInt, read } from 'envix';
11
+ import { Container } from 'confinity';
12
+ import consola from 'consola';
13
+ import { exec } from 'node:child_process';
10
14
  import findUpPackagePath from 'resolve-package-path';
11
- import { parseConfig, buildConfig as buildConfig$1 } from '@authup/server-core';
12
- import readline from 'node:readline';
13
- import chalk from 'chalk';
14
15
 
15
- function isServiceValid(input) {
16
- let key;
17
- if (typeof input === 'string') {
18
- key = deserializeKey(input);
19
- } else {
20
- key = input;
16
+ function parseClientWebConfig(input = {}) {
17
+ const schema = 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
+ });
23
+ return schema.parse(input);
24
+ }
25
+
26
+ function buildClientWebConfig(raw) {
27
+ const config = dycraft({
28
+ defaults: {
29
+ port: 3000,
30
+ host: '0.0.0.0',
31
+ apiUrl: 'http://127.0.0.1:3001/'
32
+ },
33
+ getters: {
34
+ publicUrl: defineGetter((context)=>`http://${makeURLPublicAccessible(context.get('host'))}:${context.get('port')}/`)
35
+ }
36
+ });
37
+ return extendObject(config, parseClientWebConfig(raw));
38
+ }
39
+
40
+ function readClientWebConfigFromEnv() {
41
+ const config = {};
42
+ const port = oneOf([
43
+ readInt('UI_PORT'),
44
+ readInt('NITRO_UI_PORT'),
45
+ readInt('NUXT_UI_PORT'),
46
+ readInt('NUXT_PUBLIC_UI_PORT'),
47
+ readInt('PORT'),
48
+ readInt('NITRO_PORT'),
49
+ readInt('NUXT_PORT'),
50
+ readInt('NUXT_PUBLIC_PORT')
51
+ ]);
52
+ if (typeof port !== 'undefined') {
53
+ config.port = port;
54
+ }
55
+ const host = oneOf([
56
+ read('HOST'),
57
+ read('NITRO_HOST'),
58
+ read('NUXT_HOST')
59
+ ]);
60
+ if (host) {
61
+ config.host = host;
21
62
  }
22
- if (key.group !== 'client' && key.group !== 'server') {
23
- return false;
63
+ const apiUrl = oneOf([
64
+ read('API_URL'),
65
+ read('NUXT_API_URL'),
66
+ read('NUXT_PUBLIC_API_URL')
67
+ ]);
68
+ if (apiUrl) {
69
+ config.apiUrl = apiUrl;
24
70
  }
25
- if (key.group === 'client') {
26
- return key.name === 'web';
71
+ const publicURL = oneOf([
72
+ read('PUBLIC_URL'),
73
+ read('NUXT_PUBLIC_URL'),
74
+ read('NUXT_PUBLIC_PUBLIC_URL')
75
+ ]);
76
+ if (publicURL) {
77
+ config.publicUrl = publicURL;
27
78
  }
28
- return key.name === 'core';
79
+ return config;
29
80
  }
30
81
 
31
- async function buildClientWebConfig(container) {
32
- const client = container.getData('client/web');
33
- const server = container.getData('server/core');
34
- if (server) {
35
- if (!client.apiUrl && typeof server.publicUrl === 'string') {
36
- client.apiUrl = makeURLPublicAccessible(server.publicUrl);
82
+ async function readClientWebConfigFromFS(options = {}) {
83
+ const container = new Container({
84
+ prefix: 'authup',
85
+ cwd: options.cwd
86
+ });
87
+ if (options.file) {
88
+ await container.loadFile(options.file);
89
+ } else {
90
+ await container.load();
91
+ }
92
+ const clientRaw = container.get('client.web') || {};
93
+ const serverRaw = container.get('server.core') || {};
94
+ if (serverRaw) {
95
+ if (!clientRaw.apiUrl && typeof serverRaw.publicUrl === 'string') {
96
+ clientRaw.apiUrl = makeURLPublicAccessible(serverRaw.publicUrl);
37
97
  }
38
- if (!client.publicUrl && typeof server.authorizeRedirectUrl === 'string') {
39
- client.apiUrl = makeURLPublicAccessible(server.authorizeRedirectUrl);
98
+ if (!clientRaw.publicUrl && typeof serverRaw.authorizeRedirectUrl === 'string') {
99
+ clientRaw.apiUrl = makeURLPublicAccessible(serverRaw.authorizeRedirectUrl);
40
100
  }
41
101
  }
42
- return buildConfig({
43
- data: client,
44
- env: true
45
- });
102
+ return clientRaw;
46
103
  }
47
104
 
48
- /*
49
- * Copyright (c) 2023.
50
- * Author Peter Placzek (tada5hi)
51
- * For the full copyright and license information,
52
- * view the LICENSE file that was distributed with this source code.
53
- */ var ServicePackageName;
54
- (function(ServicePackageName) {
55
- ServicePackageName["CLIENT_WEB"] = "@authup/client-web";
56
- ServicePackageName["SERVER_CORE"] = "@authup/server-core";
57
- })(ServicePackageName || (ServicePackageName = {}));
58
- var ServiceCommand;
59
- (function(ServiceCommand) {
60
- ServiceCommand["START"] = "start";
61
- ServiceCommand["CLEANUP"] = "cleanup";
62
- })(ServiceCommand || (ServiceCommand = {}));
105
+ async function readClientWebConfigRaw(options = {}) {
106
+ if (options.fs && options.env) {
107
+ const fsOptions = boolableToObject(options.fs);
108
+ const fs = await readClientWebConfigFromFS(fsOptions);
109
+ const env = readClientWebConfigFromEnv();
110
+ return merge(env, fs);
111
+ }
112
+ if (options.fs) {
113
+ const fsOptions = boolableToObject(options.fs);
114
+ return readClientWebConfigFromFS(fsOptions);
115
+ }
116
+ if (options.env) {
117
+ return readClientWebConfigFromEnv();
118
+ }
119
+ return {};
120
+ }
121
+ function boolableToObject(input) {
122
+ if (typeof input === 'boolean') {
123
+ return {};
124
+ }
125
+ return input;
126
+ }
63
127
 
64
128
  /*
65
129
  * Copyright (c) 2022.
@@ -109,15 +173,13 @@ function parseProcessOutputData(input) {
109
173
  return parts.join(' ');
110
174
  }
111
175
 
112
- async function execShellCommand(ctx) {
113
- ctx.env = ctx.env || {};
114
- ctx.args = ctx.args || {};
176
+ async function execShellCommand(command, ctx = {}) {
115
177
  return new Promise((resolve, reject)=>{
116
- const childProcess = exec(`${ctx.command} ${stringifyObjectArgs(ctx.args)}`, {
178
+ const childProcess = exec(`${command} ${stringifyObjectArgs(ctx.args || {})}`, {
117
179
  env: {
118
180
  PATH: process.env.PATH,
119
181
  ...ctx.envFromProcess ? process.env : {},
120
- ...ctx.env
182
+ ...ctx.env ? ctx.env : {}
121
183
  }
122
184
  });
123
185
  childProcess.on('error', (data)=>{
@@ -163,253 +225,212 @@ function findModulePath(module) {
163
225
  return modulePath;
164
226
  }
165
227
 
166
- function extendEnv(input) {
167
- const env = {};
168
- const keys = Object.keys(input);
169
- for(let i = 0; i < keys.length; i++){
170
- env[keys[i]] = input[keys[i]];
171
- if (!keys[i].match(/^(?:NUXT|NITRO)_.*$/)) {
172
- env[`NUXT_PUBLIC_${keys[i]}`] = input[keys[i]];
173
- }
174
- }
175
- return env;
176
- }
177
- function buildWebAppExecutionContext(ctx) {
178
- if (ctx.command !== ServiceCommand.START) {
179
- throw new Error(`The command ${ctx.command} is not supported`);
180
- }
181
- const env = ctx.env || {};
182
- const data = ctx.container.getData('client/web');
183
- const config = buildConfig({
184
- data,
185
- env: true
186
- });
187
- if (config.host) {
188
- env.HOST = config.host;
189
- }
190
- if (config.port) {
191
- env.PORT = `${config.port}`;
192
- }
193
- if (config.apiUrl) {
194
- env.API_URL = config.apiUrl;
195
- }
196
- if (config.publicUrl) {
197
- env.PUBLIC_URL = config.publicUrl;
198
- }
199
- let command;
200
- const modulePath = findModulePath(ServicePackageName.CLIENT_WEB);
201
- if (typeof modulePath === 'string') {
202
- const directory = path.dirname(modulePath);
203
- const outputPath = path.join(directory, '.output', 'server', 'index.mjs');
204
- command = `node ${outputPath}`;
205
- } else {
206
- command = `npx ${ServicePackageName.CLIENT_WEB}`;
207
- }
208
- return {
209
- ...ctx,
210
- command,
211
- env: extendEnv(env)
212
- };
213
- }
214
-
215
- async function buildServerCoreConfig(container) {
216
- const data = parseConfig(container.getData('server/core'));
217
- return buildConfig$1({
218
- data,
219
- env: true
220
- });
221
- }
228
+ /*
229
+ * Copyright (c) 2023.
230
+ * Author Peter Placzek (tada5hi)
231
+ * For the full copyright and license information,
232
+ * view the LICENSE file that was distributed with this source code.
233
+ */ var PackageName;
234
+ (function(PackageName) {
235
+ PackageName["CLIENT_WEB"] = "@authup/client-web";
236
+ PackageName["SERVER_CORE"] = "@authup/server-core";
237
+ })(PackageName || (PackageName = {}));
238
+ var PackageID;
239
+ (function(PackageID) {
240
+ PackageID["CLIENT_WEB"] = "client.web";
241
+ PackageID["SERVER_CORE"] = "server.core";
242
+ })(PackageID || (PackageID = {}));
243
+ var PackageCommand;
244
+ (function(PackageCommand) {
245
+ PackageCommand["START"] = "start";
246
+ PackageCommand["CLEANUP"] = "cleanup";
247
+ })(PackageCommand || (PackageCommand = {}));
222
248
 
223
- function buildServerCoreExecutionContext(ctx) {
224
- let command;
225
- const modulePath = findModulePath(ServicePackageName.SERVER_CORE);
226
- if (typeof modulePath === 'string') {
227
- const directory = path.dirname(modulePath);
228
- const outputPath = path.join(directory, 'dist', 'cli', 'index.js');
229
- command = `node ${outputPath}`;
230
- } else {
231
- command = `npx ${ServicePackageName.SERVER_CORE}`;
232
- }
233
- switch(ctx.command){
234
- case ServiceCommand.START:
235
- {
236
- command += ' start';
237
- break;
238
- }
239
- case ServiceCommand.CLEANUP:
240
- {
241
- command += ' reset';
242
- break;
243
- }
244
- default:
245
- {
246
- throw new Error(`The command ${ctx.command} is not supported.`);
249
+ class ClientWebPackage {
250
+ async execute(command, options = {}) {
251
+ const shellCommand = await this.buildShellCommand();
252
+ const env = await this.buildEnv({
253
+ configDirectory: options.configDirectory,
254
+ configFile: options.configFile
255
+ });
256
+ return execShellCommand(shellCommand, {
257
+ env,
258
+ logDataStream (line) {
259
+ consola.info(`${PackageID.CLIENT_WEB}: ${line}`);
260
+ },
261
+ logErrorStream (line) {
262
+ consola.warn(`${PackageID.CLIENT_WEB}: ${line}`);
247
263
  }
248
- }
249
- return {
250
- ...ctx,
251
- command
252
- };
253
- }
254
-
255
- function buildInfoCommand(cac) {
256
- cac.command('info', 'Get information about the configuration.').option('-c, --config [config]', 'Specify a configuration file').action(async (ctx)=>{
257
- const container = new Container({
258
- prefix: 'authup',
259
- keys: [
260
- 'client/web',
261
- 'server/core'
262
- ]
263
264
  });
264
- if (ctx.config) {
265
- await container.loadFromFilePath(ctx.config);
265
+ }
266
+ async buildShellCommand() {
267
+ let shellCommand;
268
+ const modulePath = findModulePath(PackageName.CLIENT_WEB);
269
+ if (typeof modulePath === 'string') {
270
+ const directory = path.dirname(modulePath);
271
+ const outputPath = path.join(directory, '.output', 'server', 'index.mjs');
272
+ shellCommand = `node ${outputPath}`;
266
273
  } else {
267
- await container.load();
274
+ shellCommand = `npx ${PackageName.CLIENT_WEB}`;
268
275
  }
269
- const clientWeb = await buildClientWebConfig(container);
270
- consola.info(`Host: ${clientWeb.host}`);
271
- consola.info(`Port: ${clientWeb.port}`);
272
- consola.info('------------');
273
- const serverCore = await buildServerCoreConfig(container);
274
- consola.info(`Host: ${serverCore.host}`);
275
- consola.info(`Port: ${serverCore.port}`);
276
- consola.info(`Environment: ${serverCore.env}`);
277
- consola.info(`RootPath: ${serverCore.rootPath}`);
278
- consola.info(`WritableDirectoryPath: ${serverCore.writableDirectoryPath}`);
279
- consola.info('------------');
280
- consola.info('Report an issue: https://github.com/authup/authup/issues/new');
281
- consola.info('Suggest an improvement: https://github.com/authup/authup/discussions/new');
282
- consola.info('Read documentation: https://authup.org');
283
- });
284
- }
285
-
286
- async function executeServiceCommand(context) {
287
- let service;
288
- if (typeof context.service === 'string') {
289
- service = deserializeKey(context.service);
290
- } else {
291
- service = context.service;
276
+ return shellCommand;
292
277
  }
293
- const env = {};
294
- const config = context.container.get(`${service.group}/${service.name}`);
295
- if (config) {
296
- const paths = config.paths.join(',');
297
- if (paths.length > 0) {
298
- env[EnvKey.CONFIG_FILE] = paths;
278
+ async buildEnv(ctx) {
279
+ const env = {};
280
+ const configRaw = await readClientWebConfigRaw({
281
+ fs: {
282
+ file: ctx.configFile,
283
+ cwd: ctx.configDirectory
284
+ }
285
+ });
286
+ const config = buildClientWebConfig(configRaw);
287
+ if (config.host) {
288
+ env.HOST = config.host;
299
289
  }
300
- }
301
- let shellExecContext;
302
- try {
303
- if (service.group === 'server' && service.name === 'core') {
304
- shellExecContext = buildServerCoreExecutionContext({
305
- command: context.command,
306
- env
307
- });
290
+ if (config.port) {
291
+ env.PORT = `${config.port}`;
308
292
  }
309
- if (service.group === 'client' && service.name === 'web') {
310
- shellExecContext = buildWebAppExecutionContext({
311
- container: context.container,
312
- command: context.command,
313
- env
314
- });
293
+ if (config.apiUrl) {
294
+ env.API_URL = config.apiUrl;
315
295
  }
316
- } catch (e) {
317
- consola.error(`${service.group}/${service.name}: The service command ${context.command} not supported.`);
318
- process.exit(1);
319
- }
320
- if (!shellExecContext) {
321
- consola.error(`${service.group}/${service.name}: The service is not supported.`);
322
- process.exit(1);
296
+ if (config.publicUrl) {
297
+ env.PUBLIC_URL = config.publicUrl;
298
+ }
299
+ return this.extendEnvKeys(env);
323
300
  }
324
- return execShellCommand({
325
- ...shellExecContext,
326
- logDataStream (line) {
327
- consola.info(`${service.group}/${service.name}: ${line}`);
328
- },
329
- logErrorStream (line) {
330
- consola.warn(`${service.group}/${service.name}: ${line}`);
301
+ extendEnvKeys(input) {
302
+ const env = {};
303
+ const keys = Object.keys(input);
304
+ for(let i = 0; i < keys.length; i++){
305
+ env[keys[i]] = input[keys[i]];
306
+ if (!keys[i].match(/^(?:NUXT|NITRO)_.*$/)) {
307
+ env[`NUXT_PUBLIC_${keys[i]}`] = input[keys[i]];
308
+ }
331
309
  }
332
- });
310
+ return env;
311
+ }
333
312
  }
334
- async function executeServicesCommand(context) {
335
- const container = new Container({
336
- prefix: 'authup',
337
- keys: context.servicesAllowed || context.services
338
- });
339
- if (context.config) {
340
- await container.loadFromFilePath(context.config);
341
- } else {
342
- await container.load();
313
+
314
+ class ServerCorePackage {
315
+ async execute(command, options = {}) {
316
+ const shellCommand = await this.buildShellCommand(command, {
317
+ configDirectory: options.configDirectory,
318
+ configFile: options.configFile
319
+ });
320
+ return execShellCommand(shellCommand, {
321
+ logDataStream (line) {
322
+ consola.info(`${PackageID.SERVER_CORE}: ${line}`);
323
+ },
324
+ logErrorStream (line) {
325
+ consola.warn(`${PackageID.SERVER_CORE}: ${line}`);
326
+ }
327
+ });
343
328
  }
344
- const promises = [];
345
- for(let i = 0; i < context.services.length; i++){
346
- const service = deserializeKey(context.services[i]);
347
- if (!isServiceValid(service)) {
348
- consola.error(`${chalk.red(`${service.group}/${service.name}`)}: The service does not exist.`);
349
- process.exit(1);
329
+ async buildShellCommand(command, options) {
330
+ const parts = [];
331
+ const modulePath = findModulePath(PackageName.SERVER_CORE);
332
+ if (typeof modulePath === 'string') {
333
+ const directory = path.dirname(modulePath);
334
+ const outputPath = path.join(directory, 'dist', 'cli', 'index.js');
335
+ parts.push(`node ${outputPath}`);
336
+ } else {
337
+ parts.push(`npx ${PackageName.SERVER_CORE}`);
350
338
  }
351
- if (context.servicesAllowed && context.servicesAllowed.indexOf(`${service.group}/${service.name}`) === -1) {
352
- consola.error(`${chalk.red(`${service.group}/${service.name}`)}: The service does not support the ${context.command} command.`);
353
- process.exit(1);
339
+ parts.push(command);
340
+ if (options.configFile) {
341
+ parts.push(`--configFile=${options.configFile}`);
354
342
  }
355
- promises.push(executeServiceCommand({
356
- command: context.command,
357
- service,
358
- container
359
- }));
360
- }
361
- const childProcesses = await Promise.all(promises);
362
- const readLine = readline.createInterface({
363
- input: process.stdin,
364
- output: process.stdout
365
- });
366
- readLine.on('SIGINT', ()=>{
367
- for(let i = 0; i < childProcesses.length; i++){
368
- childProcesses[i].kill();
343
+ if (options.configDirectory) {
344
+ parts.push(`--configDirectory=${options.configDirectory}`);
369
345
  }
370
- process.exit();
371
- });
346
+ return parts.join(' ');
347
+ }
372
348
  }
373
349
 
374
- function buildCleanupCommand(cac) {
375
- cac.command('cleanup [...services]', 'Cleanup a service').option('-c, --config [config]', 'Specify a configuration file').action(async (keysInput, ctx)=>{
376
- const servicesAllowed = [
377
- 'server/core'
378
- ];
379
- if (!keysInput || keysInput.length === 0) {
380
- keysInput = servicesAllowed;
381
- }
382
- await executeServicesCommand({
383
- config: ctx.config,
384
- command: ServiceCommand.CLEANUP,
385
- services: keysInput,
386
- servicesAllowed
387
- });
388
- });
350
+ async function executePackageCommand(pkg, command, options = {}) {
351
+ switch(pkg){
352
+ case PackageID.CLIENT_WEB:
353
+ {
354
+ const serverCore = new ClientWebPackage();
355
+ return serverCore.execute(command, options);
356
+ }
357
+ case PackageID.SERVER_CORE:
358
+ {
359
+ const serverCore = new ServerCorePackage();
360
+ return serverCore.execute(command, options);
361
+ }
362
+ }
363
+ throw new Error(`The package ${pkg} is not supported.`);
389
364
  }
390
365
 
391
- function buildStartCommand(cac) {
392
- cac.command('start [...services]', 'Start a service').option('-c, --config [config]', 'Specify a configuration file').action(async (keysInput, ctx)=>{
393
- const servicesAllowed = [
394
- 'client/web',
395
- 'server/core'
396
- ];
397
- if (!keysInput || keysInput.length === 0) {
398
- keysInput = servicesAllowed;
366
+ function normalizePackageID(input) {
367
+ const value = input.trim().toLowerCase();
368
+ switch(value){
369
+ case 'client.web':
370
+ case 'client/web':
371
+ case 'client-web':
372
+ {
373
+ return PackageID.CLIENT_WEB;
374
+ }
375
+ case 'server.core':
376
+ case 'server/core':
377
+ case 'server-core':
378
+ {
379
+ return PackageID.SERVER_CORE;
380
+ }
381
+ }
382
+ return undefined;
383
+ }
384
+
385
+ async function createCLIEntryPointCommand() {
386
+ const pkgRaw = await fs.promises.readFile(path.join(process.cwd(), 'package.json'), {
387
+ encoding: 'utf8'
388
+ });
389
+ const pkg = JSON.parse(pkgRaw);
390
+ return defineCommand({
391
+ meta: {
392
+ name: pkg.name,
393
+ version: pkg.version,
394
+ description: pkg.description
395
+ },
396
+ args: {
397
+ command: {
398
+ type: 'positional',
399
+ description: 'The command which should be forwarded to the package.'
400
+ },
401
+ package: {
402
+ type: 'positional',
403
+ description: 'The package, which should be targeted.',
404
+ required: false
405
+ },
406
+ configDirectory: {
407
+ type: 'string',
408
+ description: 'Config directory path',
409
+ alias: 'cD'
410
+ },
411
+ configFile: {
412
+ type: 'string',
413
+ description: 'Name of one or more configuration files.',
414
+ alias: 'cF'
415
+ }
416
+ },
417
+ async run (ctx) {
418
+ let pkgs = ctx.args.package ? ctx.args.package.split(',') : [];
419
+ pkgs = pkgs.map((pkg)=>normalizePackageID(pkg)).filter((pkg)=>Boolean(pkg));
420
+ if (pkgs.length === 0) {
421
+ pkgs = Object.values(PackageID);
422
+ }
423
+ const promises = [];
424
+ for(let i = 0; i < pkgs.length; i++){
425
+ promises.push(executePackageCommand(pkgs[i], ctx.args.command, {
426
+ configFile: ctx.args.configFile,
427
+ configDirectory: ctx.args.configDirectory
428
+ }));
429
+ }
430
+ await Promise.all(promises);
399
431
  }
400
- await executeServicesCommand({
401
- config: ctx.config,
402
- command: ServiceCommand.START,
403
- services: keysInput,
404
- servicesAllowed
405
- });
406
432
  });
407
433
  }
408
434
 
409
- const cli = cac();
410
- buildInfoCommand(cli);
411
- buildStartCommand(cli);
412
- buildCleanupCommand(cli);
413
- cli.help();
414
- cli.parse();
435
+ Promise.resolve().then(()=>createCLIEntryPointCommand()).then((command)=>runMain(command));
415
436
  //# sourceMappingURL=index.mjs.map