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