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.mjs
CHANGED
|
@@ -1,65 +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, isObject, hasOwnProperty } from '@authup/kit';
|
|
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';
|
|
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';
|
|
10
14
|
import findUpPackagePath from 'resolve-package-path';
|
|
11
|
-
import { parseConfig, buildConfig as buildConfig$1 } from '@authup/server-core';
|
|
12
|
-
import readline from 'node:readline';
|
|
13
|
-
import chalk from 'chalk';
|
|
14
15
|
|
|
15
|
-
function
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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;
|
|
21
62
|
}
|
|
22
|
-
|
|
23
|
-
|
|
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;
|
|
24
70
|
}
|
|
25
|
-
|
|
26
|
-
|
|
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;
|
|
27
78
|
}
|
|
28
|
-
return
|
|
79
|
+
return config;
|
|
29
80
|
}
|
|
30
81
|
|
|
31
|
-
async function
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
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);
|
|
37
97
|
}
|
|
38
|
-
if (!
|
|
39
|
-
|
|
98
|
+
if (!clientRaw.publicUrl && typeof serverRaw.authorizeRedirectUrl === 'string') {
|
|
99
|
+
clientRaw.apiUrl = makeURLPublicAccessible(serverRaw.authorizeRedirectUrl);
|
|
40
100
|
}
|
|
41
101
|
}
|
|
42
|
-
return
|
|
43
|
-
data: client,
|
|
44
|
-
env: true
|
|
45
|
-
});
|
|
102
|
+
return clientRaw;
|
|
46
103
|
}
|
|
47
104
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
(
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
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
|
+
}
|
|
63
127
|
|
|
64
128
|
/*
|
|
65
129
|
* Copyright (c) 2022.
|
|
@@ -109,15 +173,13 @@ function parseProcessOutputData(input) {
|
|
|
109
173
|
return parts.join(' ');
|
|
110
174
|
}
|
|
111
175
|
|
|
112
|
-
async function execShellCommand(ctx) {
|
|
113
|
-
ctx.env = ctx.env || {};
|
|
114
|
-
ctx.args = ctx.args || {};
|
|
176
|
+
async function execShellCommand(command, ctx = {}) {
|
|
115
177
|
return new Promise((resolve, reject)=>{
|
|
116
|
-
const childProcess = exec(`${
|
|
178
|
+
const childProcess = exec(`${command} ${stringifyObjectArgs(ctx.args || {})}`, {
|
|
117
179
|
env: {
|
|
118
180
|
PATH: process.env.PATH,
|
|
119
181
|
...ctx.envFromProcess ? process.env : {},
|
|
120
|
-
...ctx.env
|
|
182
|
+
...ctx.env ? ctx.env : {}
|
|
121
183
|
}
|
|
122
184
|
});
|
|
123
185
|
childProcess.on('error', (data)=>{
|
|
@@ -163,253 +225,212 @@ function findModulePath(module) {
|
|
|
163
225
|
return modulePath;
|
|
164
226
|
}
|
|
165
227
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
function
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
});
|
|
187
|
-
if (config.host) {
|
|
188
|
-
env.HOST = config.host;
|
|
189
|
-
}
|
|
190
|
-
if (config.port) {
|
|
191
|
-
env.PORT = `${config.port}`;
|
|
192
|
-
}
|
|
193
|
-
if (config.apiUrl) {
|
|
194
|
-
env.API_URL = config.apiUrl;
|
|
195
|
-
}
|
|
196
|
-
if (config.publicUrl) {
|
|
197
|
-
env.PUBLIC_URL = config.publicUrl;
|
|
198
|
-
}
|
|
199
|
-
let command;
|
|
200
|
-
const modulePath = findModulePath(ServicePackageName.CLIENT_WEB);
|
|
201
|
-
if (typeof modulePath === 'string') {
|
|
202
|
-
const directory = path.dirname(modulePath);
|
|
203
|
-
const outputPath = path.join(directory, '.output', 'server', 'index.mjs');
|
|
204
|
-
command = `node ${outputPath}`;
|
|
205
|
-
} else {
|
|
206
|
-
command = `npx ${ServicePackageName.CLIENT_WEB}`;
|
|
207
|
-
}
|
|
208
|
-
return {
|
|
209
|
-
...ctx,
|
|
210
|
-
command,
|
|
211
|
-
env: extendEnv(env)
|
|
212
|
-
};
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
async function buildServerCoreConfig(container) {
|
|
216
|
-
const data = parseConfig(container.getData('server/core'));
|
|
217
|
-
return buildConfig$1({
|
|
218
|
-
data,
|
|
219
|
-
env: true
|
|
220
|
-
});
|
|
221
|
-
}
|
|
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 = {}));
|
|
222
248
|
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
{
|
|
236
|
-
|
|
237
|
-
break;
|
|
238
|
-
}
|
|
239
|
-
case ServiceCommand.CLEANUP:
|
|
240
|
-
{
|
|
241
|
-
command += ' reset';
|
|
242
|
-
break;
|
|
243
|
-
}
|
|
244
|
-
default:
|
|
245
|
-
{
|
|
246
|
-
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}`);
|
|
247
263
|
}
|
|
248
|
-
}
|
|
249
|
-
return {
|
|
250
|
-
...ctx,
|
|
251
|
-
command
|
|
252
|
-
};
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
function buildInfoCommand(cac) {
|
|
256
|
-
cac.command('info', 'Get information about the configuration.').option('-c, --config [config]', 'Specify a configuration file').action(async (ctx)=>{
|
|
257
|
-
const container = new Container({
|
|
258
|
-
prefix: 'authup',
|
|
259
|
-
keys: [
|
|
260
|
-
'client/web',
|
|
261
|
-
'server/core'
|
|
262
|
-
]
|
|
263
264
|
});
|
|
264
|
-
|
|
265
|
-
|
|
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}`;
|
|
266
273
|
} else {
|
|
267
|
-
|
|
274
|
+
shellCommand = `npx ${PackageName.CLIENT_WEB}`;
|
|
268
275
|
}
|
|
269
|
-
|
|
270
|
-
consola.info(`Host: ${clientWeb.host}`);
|
|
271
|
-
consola.info(`Port: ${clientWeb.port}`);
|
|
272
|
-
consola.info('------------');
|
|
273
|
-
const serverCore = await buildServerCoreConfig(container);
|
|
274
|
-
consola.info(`Host: ${serverCore.host}`);
|
|
275
|
-
consola.info(`Port: ${serverCore.port}`);
|
|
276
|
-
consola.info(`Environment: ${serverCore.env}`);
|
|
277
|
-
consola.info(`RootPath: ${serverCore.rootPath}`);
|
|
278
|
-
consola.info(`WritableDirectoryPath: ${serverCore.writableDirectoryPath}`);
|
|
279
|
-
consola.info('------------');
|
|
280
|
-
consola.info('Report an issue: https://github.com/authup/authup/issues/new');
|
|
281
|
-
consola.info('Suggest an improvement: https://github.com/authup/authup/discussions/new');
|
|
282
|
-
consola.info('Read documentation: https://authup.org');
|
|
283
|
-
});
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
async function executeServiceCommand(context) {
|
|
287
|
-
let service;
|
|
288
|
-
if (typeof context.service === 'string') {
|
|
289
|
-
service = deserializeKey(context.service);
|
|
290
|
-
} else {
|
|
291
|
-
service = context.service;
|
|
276
|
+
return shellCommand;
|
|
292
277
|
}
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
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;
|
|
299
289
|
}
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
try {
|
|
303
|
-
if (service.group === 'server' && service.name === 'core') {
|
|
304
|
-
shellExecContext = buildServerCoreExecutionContext({
|
|
305
|
-
command: context.command,
|
|
306
|
-
env
|
|
307
|
-
});
|
|
290
|
+
if (config.port) {
|
|
291
|
+
env.PORT = `${config.port}`;
|
|
308
292
|
}
|
|
309
|
-
if (
|
|
310
|
-
|
|
311
|
-
container: context.container,
|
|
312
|
-
command: context.command,
|
|
313
|
-
env
|
|
314
|
-
});
|
|
293
|
+
if (config.apiUrl) {
|
|
294
|
+
env.API_URL = config.apiUrl;
|
|
315
295
|
}
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
if (!shellExecContext) {
|
|
321
|
-
consola.error(`${service.group}/${service.name}: The service is not supported.`);
|
|
322
|
-
process.exit(1);
|
|
296
|
+
if (config.publicUrl) {
|
|
297
|
+
env.PUBLIC_URL = config.publicUrl;
|
|
298
|
+
}
|
|
299
|
+
return this.extendEnvKeys(env);
|
|
323
300
|
}
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
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
|
+
}
|
|
331
309
|
}
|
|
332
|
-
|
|
310
|
+
return env;
|
|
311
|
+
}
|
|
333
312
|
}
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
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
|
+
});
|
|
343
328
|
}
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
const
|
|
347
|
-
if (
|
|
348
|
-
|
|
349
|
-
|
|
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}`);
|
|
350
338
|
}
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
339
|
+
parts.push(command);
|
|
340
|
+
if (options.configFile) {
|
|
341
|
+
parts.push(`--configFile=${options.configFile}`);
|
|
354
342
|
}
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
service,
|
|
358
|
-
container
|
|
359
|
-
}));
|
|
360
|
-
}
|
|
361
|
-
const childProcesses = await Promise.all(promises);
|
|
362
|
-
const readLine = readline.createInterface({
|
|
363
|
-
input: process.stdin,
|
|
364
|
-
output: process.stdout
|
|
365
|
-
});
|
|
366
|
-
readLine.on('SIGINT', ()=>{
|
|
367
|
-
for(let i = 0; i < childProcesses.length; i++){
|
|
368
|
-
childProcesses[i].kill();
|
|
343
|
+
if (options.configDirectory) {
|
|
344
|
+
parts.push(`--configDirectory=${options.configDirectory}`);
|
|
369
345
|
}
|
|
370
|
-
|
|
371
|
-
}
|
|
346
|
+
return parts.join(' ');
|
|
347
|
+
}
|
|
372
348
|
}
|
|
373
349
|
|
|
374
|
-
function
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
});
|
|
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.`);
|
|
389
364
|
}
|
|
390
365
|
|
|
391
|
-
function
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
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);
|
|
399
431
|
}
|
|
400
|
-
await executeServicesCommand({
|
|
401
|
-
config: ctx.config,
|
|
402
|
-
command: ServiceCommand.START,
|
|
403
|
-
services: keysInput,
|
|
404
|
-
servicesAllowed
|
|
405
|
-
});
|
|
406
432
|
});
|
|
407
433
|
}
|
|
408
434
|
|
|
409
|
-
|
|
410
|
-
buildInfoCommand(cli);
|
|
411
|
-
buildStartCommand(cli);
|
|
412
|
-
buildCleanupCommand(cli);
|
|
413
|
-
cli.help();
|
|
414
|
-
cli.parse();
|
|
435
|
+
Promise.resolve().then(()=>createCLIEntryPointCommand()).then((command)=>runMain(command));
|
|
415
436
|
//# sourceMappingURL=index.mjs.map
|