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