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.
- package/dist/index.cjs +298 -277
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +298 -277
- package/dist/index.mjs.map +1 -1
- package/dist/module.d.ts +22 -0
- package/dist/module.d.ts.map +1 -0
- package/dist/packages/client-web/config/build.d.ts +3 -0
- package/dist/packages/client-web/config/build.d.ts.map +1 -0
- package/dist/packages/client-web/config/index.d.ts +3 -0
- package/dist/packages/client-web/config/index.d.ts.map +1 -0
- package/dist/packages/client-web/config/parse.d.ts +3 -0
- package/dist/packages/client-web/config/parse.d.ts.map +1 -0
- package/dist/packages/client-web/config/read/env.d.ts +3 -0
- package/dist/packages/client-web/config/read/env.d.ts.map +1 -0
- package/dist/packages/client-web/config/read/fs.d.ts +7 -0
- package/dist/packages/client-web/config/read/fs.d.ts.map +1 -0
- package/dist/packages/client-web/config/read/index.d.ts +2 -0
- package/dist/packages/client-web/config/read/index.d.ts.map +1 -0
- package/dist/packages/client-web/config/read/module.d.ts +8 -0
- package/dist/packages/client-web/config/read/module.d.ts.map +1 -0
- package/dist/packages/client-web/config/type.d.ts +9 -0
- package/dist/packages/client-web/config/type.d.ts.map +1 -0
- package/dist/packages/client-web/index.d.ts +3 -0
- package/dist/packages/client-web/index.d.ts.map +1 -0
- package/dist/packages/client-web/module.d.ts +9 -0
- package/dist/packages/client-web/module.d.ts.map +1 -0
- package/dist/packages/constants.d.ts +13 -0
- package/dist/packages/constants.d.ts.map +1 -0
- package/dist/packages/execute.d.ts +4 -0
- package/dist/packages/execute.d.ts.map +1 -0
- package/dist/packages/index.d.ts +6 -0
- package/dist/packages/index.d.ts.map +1 -0
- package/dist/packages/normalize.d.ts +3 -0
- package/dist/packages/normalize.d.ts.map +1 -0
- package/dist/packages/server-core/index.d.ts +2 -0
- package/dist/packages/server-core/index.d.ts.map +1 -0
- package/dist/packages/server-core/module.d.ts +7 -0
- package/dist/packages/server-core/module.d.ts.map +1 -0
- package/dist/packages/types.d.ts +9 -0
- package/dist/packages/types.d.ts.map +1 -0
- package/dist/utils/shell.d.ts +4 -3
- package/dist/utils/shell.d.ts.map +1 -1
- package/package.json +8 -8
- package/dist/commands/cleanup.d.ts +0 -3
- package/dist/commands/cleanup.d.ts.map +0 -1
- package/dist/commands/index.d.ts +0 -4
- package/dist/commands/index.d.ts.map +0 -1
- package/dist/commands/info.d.ts +0 -3
- package/dist/commands/info.d.ts.map +0 -1
- package/dist/commands/start.d.ts +0 -3
- package/dist/commands/start.d.ts.map +0 -1
- package/dist/services/check.d.ts +0 -3
- package/dist/services/check.d.ts.map +0 -1
- package/dist/services/client-web/config.d.ts +0 -4
- package/dist/services/client-web/config.d.ts.map +0 -1
- package/dist/services/client-web/execute.d.ts +0 -8
- package/dist/services/client-web/execute.d.ts.map +0 -1
- package/dist/services/client-web/index.d.ts +0 -3
- package/dist/services/client-web/index.d.ts.map +0 -1
- package/dist/services/constants.d.ts +0 -9
- package/dist/services/constants.d.ts.map +0 -1
- package/dist/services/execute.d.ts +0 -9
- package/dist/services/execute.d.ts.map +0 -1
- package/dist/services/index.d.ts +0 -5
- package/dist/services/index.d.ts.map +0 -1
- package/dist/services/server-core/config.d.ts +0 -4
- package/dist/services/server-core/config.d.ts.map +0 -1
- package/dist/services/server-core/execute.d.ts +0 -3
- package/dist/services/server-core/execute.d.ts.map +0 -1
- package/dist/services/server-core/index.d.ts +0 -3
- 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
|
|
5
|
-
var
|
|
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
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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
|
-
|
|
25
|
-
|
|
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
|
-
|
|
28
|
-
|
|
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
|
-
|
|
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
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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 (!
|
|
41
|
-
|
|
100
|
+
if (!clientRaw.publicUrl && typeof serverRaw.authorizeRedirectUrl === 'string') {
|
|
101
|
+
clientRaw.apiUrl = kit.makeURLPublicAccessible(serverRaw.authorizeRedirectUrl);
|
|
42
102
|
}
|
|
43
103
|
}
|
|
44
|
-
return
|
|
45
|
-
data: client,
|
|
46
|
-
env: true
|
|
47
|
-
});
|
|
104
|
+
return clientRaw;
|
|
48
105
|
}
|
|
49
106
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
(
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
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(`${
|
|
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
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
function
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
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
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
{
|
|
238
|
-
|
|
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
|
-
|
|
267
|
-
|
|
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
|
-
|
|
276
|
+
shellCommand = `npx ${PackageName.CLIENT_WEB}`;
|
|
270
277
|
}
|
|
271
|
-
|
|
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
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
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
|
-
|
|
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 (
|
|
312
|
-
|
|
313
|
-
container: context.container,
|
|
314
|
-
command: context.command,
|
|
315
|
-
env
|
|
316
|
-
});
|
|
295
|
+
if (config.apiUrl) {
|
|
296
|
+
env.API_URL = config.apiUrl;
|
|
317
297
|
}
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
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
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
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
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
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
|
-
|
|
347
|
-
|
|
348
|
-
const
|
|
349
|
-
if (
|
|
350
|
-
|
|
351
|
-
|
|
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
|
-
|
|
354
|
-
|
|
355
|
-
|
|
341
|
+
parts.push(command);
|
|
342
|
+
if (options.configFile) {
|
|
343
|
+
parts.push(`--configFile=${options.configFile}`);
|
|
356
344
|
}
|
|
357
|
-
|
|
358
|
-
|
|
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
|
-
|
|
373
|
-
}
|
|
348
|
+
return parts.join(' ');
|
|
349
|
+
}
|
|
374
350
|
}
|
|
375
351
|
|
|
376
|
-
function
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
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
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
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
|
-
|
|
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
|