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