authup 1.0.0-beta.2 → 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 (73) hide show
  1. package/LICENSE +201 -21
  2. package/README.md +1 -1
  3. package/dist/index.cjs +298 -272
  4. package/dist/index.cjs.map +1 -1
  5. package/dist/index.mjs +298 -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 +13 -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,212 @@ 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;
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 = {}));
219
250
 
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.`);
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}`);
244
265
  }
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
266
  });
261
- if (ctx.config) {
262
- 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}`;
263
275
  } else {
264
- await container.load();
276
+ shellCommand = `npx ${PackageName.CLIENT_WEB}`;
265
277
  }
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;
278
+ return shellCommand;
289
279
  }
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;
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;
296
291
  }
297
- }
298
- let shellExecContext;
299
- try {
300
- if (service.group === 'server' && service.name === 'core') {
301
- shellExecContext = buildServerCoreExecutionContext({
302
- command: context.command,
303
- env
304
- });
292
+ if (config.port) {
293
+ env.PORT = `${config.port}`;
305
294
  }
306
- if (service.group === 'client' && service.name === 'web') {
307
- shellExecContext = buildWebAppExecutionContext({
308
- container: context.container,
309
- command: context.command,
310
- env
311
- });
295
+ if (config.apiUrl) {
296
+ env.API_URL = config.apiUrl;
312
297
  }
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);
298
+ if (config.publicUrl) {
299
+ env.PUBLIC_URL = config.publicUrl;
300
+ }
301
+ return this.extendEnvKeys(env);
320
302
  }
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}`);
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
+ }
328
311
  }
329
- });
312
+ return env;
313
+ }
330
314
  }
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();
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
+ });
340
330
  }
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);
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}`);
347
340
  }
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);
341
+ parts.push(command);
342
+ if (options.configFile) {
343
+ parts.push(`--configFile=${options.configFile}`);
351
344
  }
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();
345
+ if (options.configDirectory) {
346
+ parts.push(`--configDirectory=${options.configDirectory}`);
366
347
  }
367
- process.exit();
368
- });
348
+ return parts.join(' ');
349
+ }
369
350
  }
370
351
 
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
- });
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.`);
386
366
  }
387
367
 
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;
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);
396
433
  }
397
- await executeServicesCommand({
398
- config: ctx.config,
399
- command: ServiceCommand.START,
400
- services: keysInput,
401
- servicesAllowed
402
- });
403
434
  });
404
435
  }
405
436
 
406
- const cli = cac();
407
- buildInfoCommand(cli);
408
- buildStartCommand(cli);
409
- buildCleanupCommand(cli);
410
- cli.help();
411
- cli.parse();
437
+ Promise.resolve().then(()=>createCLIEntryPointCommand()).then((command)=>citty.runMain(command));
412
438
  //# sourceMappingURL=index.cjs.map