authup 1.0.0-beta.2 → 1.0.0-beta.21

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