authup 1.0.0-beta.2 → 1.0.0-beta.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -21
- package/README.md +1 -1
- package/dist/index.cjs +293 -272
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +293 -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 +9 -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,207 @@ function findModulePath(module) {
|
|
|
164
225
|
return modulePath;
|
|
165
226
|
}
|
|
166
227
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
const env = ctx.env || {};
|
|
183
|
-
const data = ctx.container.getData('client/web');
|
|
184
|
-
const config = buildConfig({
|
|
185
|
-
data,
|
|
186
|
-
env: true
|
|
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 = /*#__PURE__*/ function(PackageName) {
|
|
234
|
+
PackageName["CLIENT_WEB"] = "@authup/client-web";
|
|
235
|
+
PackageName["SERVER_CORE"] = "@authup/server-core";
|
|
236
|
+
return PackageName;
|
|
237
|
+
}({});
|
|
238
|
+
var PackageID = /*#__PURE__*/ function(PackageID) {
|
|
239
|
+
PackageID["CLIENT_WEB"] = "client.web";
|
|
240
|
+
PackageID["SERVER_CORE"] = "server.core";
|
|
241
|
+
return PackageID;
|
|
242
|
+
}({});
|
|
217
243
|
|
|
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.`);
|
|
244
|
+
class ClientWebPackage {
|
|
245
|
+
async execute(command, options = {}) {
|
|
246
|
+
const shellCommand = await this.buildShellCommand();
|
|
247
|
+
const env = await this.buildEnv({
|
|
248
|
+
configDirectory: options.configDirectory,
|
|
249
|
+
configFile: options.configFile
|
|
250
|
+
});
|
|
251
|
+
return execShellCommand(shellCommand, {
|
|
252
|
+
env,
|
|
253
|
+
logDataStream (line) {
|
|
254
|
+
consola.info(`${PackageID.CLIENT_WEB}: ${line}`);
|
|
255
|
+
},
|
|
256
|
+
logErrorStream (line) {
|
|
257
|
+
consola.warn(`${PackageID.CLIENT_WEB}: ${line}`);
|
|
242
258
|
}
|
|
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
259
|
});
|
|
259
|
-
|
|
260
|
-
|
|
260
|
+
}
|
|
261
|
+
async buildShellCommand() {
|
|
262
|
+
let shellCommand;
|
|
263
|
+
const modulePath = findModulePath(PackageName.CLIENT_WEB);
|
|
264
|
+
if (typeof modulePath === 'string') {
|
|
265
|
+
const directory = path.dirname(modulePath);
|
|
266
|
+
const outputPath = path.join(directory, '.output', 'server', 'index.mjs');
|
|
267
|
+
shellCommand = `node ${outputPath}`;
|
|
261
268
|
} else {
|
|
262
|
-
|
|
269
|
+
shellCommand = `npx ${PackageName.CLIENT_WEB}`;
|
|
263
270
|
}
|
|
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;
|
|
271
|
+
return shellCommand;
|
|
287
272
|
}
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
273
|
+
async buildEnv(ctx) {
|
|
274
|
+
const env = {};
|
|
275
|
+
const configRaw = await readClientWebConfigRaw({
|
|
276
|
+
fs: {
|
|
277
|
+
file: ctx.configFile,
|
|
278
|
+
cwd: ctx.configDirectory
|
|
279
|
+
}
|
|
280
|
+
});
|
|
281
|
+
const config = buildClientWebConfig(configRaw);
|
|
282
|
+
if (config.host) {
|
|
283
|
+
env.HOST = config.host;
|
|
294
284
|
}
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
try {
|
|
298
|
-
if (service.group === 'server' && service.name === 'core') {
|
|
299
|
-
shellExecContext = buildServerCoreExecutionContext({
|
|
300
|
-
command: context.command,
|
|
301
|
-
env
|
|
302
|
-
});
|
|
285
|
+
if (config.port) {
|
|
286
|
+
env.PORT = `${config.port}`;
|
|
303
287
|
}
|
|
304
|
-
if (
|
|
305
|
-
|
|
306
|
-
container: context.container,
|
|
307
|
-
command: context.command,
|
|
308
|
-
env
|
|
309
|
-
});
|
|
288
|
+
if (config.apiUrl) {
|
|
289
|
+
env.API_URL = config.apiUrl;
|
|
310
290
|
}
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
if (!shellExecContext) {
|
|
316
|
-
consola.error(`${service.group}/${service.name}: The service is not supported.`);
|
|
317
|
-
process.exit(1);
|
|
291
|
+
if (config.publicUrl) {
|
|
292
|
+
env.PUBLIC_URL = config.publicUrl;
|
|
293
|
+
}
|
|
294
|
+
return this.extendEnvKeys(env);
|
|
318
295
|
}
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
296
|
+
extendEnvKeys(input) {
|
|
297
|
+
const env = {};
|
|
298
|
+
const keys = Object.keys(input);
|
|
299
|
+
for(let i = 0; i < keys.length; i++){
|
|
300
|
+
env[keys[i]] = input[keys[i]];
|
|
301
|
+
if (!keys[i].match(/^(?:NUXT|NITRO)_.*$/)) {
|
|
302
|
+
env[`NUXT_PUBLIC_${keys[i]}`] = input[keys[i]];
|
|
303
|
+
}
|
|
326
304
|
}
|
|
327
|
-
|
|
305
|
+
return env;
|
|
306
|
+
}
|
|
328
307
|
}
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
308
|
+
|
|
309
|
+
class ServerCorePackage {
|
|
310
|
+
async execute(command, options = {}) {
|
|
311
|
+
const shellCommand = await this.buildShellCommand(command, {
|
|
312
|
+
configDirectory: options.configDirectory,
|
|
313
|
+
configFile: options.configFile
|
|
314
|
+
});
|
|
315
|
+
return execShellCommand(shellCommand, {
|
|
316
|
+
logDataStream (line) {
|
|
317
|
+
consola.info(`${PackageID.SERVER_CORE}: ${line}`);
|
|
318
|
+
},
|
|
319
|
+
logErrorStream (line) {
|
|
320
|
+
consola.warn(`${PackageID.SERVER_CORE}: ${line}`);
|
|
321
|
+
}
|
|
322
|
+
});
|
|
338
323
|
}
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
const
|
|
342
|
-
if (
|
|
343
|
-
|
|
344
|
-
|
|
324
|
+
async buildShellCommand(command, options) {
|
|
325
|
+
const parts = [];
|
|
326
|
+
const modulePath = findModulePath(PackageName.SERVER_CORE);
|
|
327
|
+
if (typeof modulePath === 'string') {
|
|
328
|
+
const directory = path.dirname(modulePath);
|
|
329
|
+
const outputPath = path.join(directory, 'dist', 'cli', 'index.js');
|
|
330
|
+
parts.push(`node ${outputPath}`);
|
|
331
|
+
} else {
|
|
332
|
+
parts.push(`npx ${PackageName.SERVER_CORE}`);
|
|
345
333
|
}
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
334
|
+
parts.push(command);
|
|
335
|
+
if (options.configFile) {
|
|
336
|
+
parts.push(`--configFile=${options.configFile}`);
|
|
349
337
|
}
|
|
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();
|
|
338
|
+
if (options.configDirectory) {
|
|
339
|
+
parts.push(`--configDirectory=${options.configDirectory}`);
|
|
364
340
|
}
|
|
365
|
-
|
|
366
|
-
}
|
|
341
|
+
return parts.join(' ');
|
|
342
|
+
}
|
|
367
343
|
}
|
|
368
344
|
|
|
369
|
-
function
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
});
|
|
345
|
+
async function executePackageCommand(pkg, command, options = {}) {
|
|
346
|
+
switch(pkg){
|
|
347
|
+
case PackageID.CLIENT_WEB:
|
|
348
|
+
{
|
|
349
|
+
const serverCore = new ClientWebPackage();
|
|
350
|
+
return serverCore.execute(command, options);
|
|
351
|
+
}
|
|
352
|
+
case PackageID.SERVER_CORE:
|
|
353
|
+
{
|
|
354
|
+
const serverCore = new ServerCorePackage();
|
|
355
|
+
return serverCore.execute(command, options);
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
throw new Error(`The package ${pkg} is not supported.`);
|
|
384
359
|
}
|
|
385
360
|
|
|
386
|
-
function
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
361
|
+
function normalizePackageID(input) {
|
|
362
|
+
const value = input.trim().toLowerCase();
|
|
363
|
+
switch(value){
|
|
364
|
+
case 'client.web':
|
|
365
|
+
case 'client/web':
|
|
366
|
+
case 'client-web':
|
|
367
|
+
{
|
|
368
|
+
return PackageID.CLIENT_WEB;
|
|
369
|
+
}
|
|
370
|
+
case 'server.core':
|
|
371
|
+
case 'server/core':
|
|
372
|
+
case 'server-core':
|
|
373
|
+
{
|
|
374
|
+
return PackageID.SERVER_CORE;
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
return undefined;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
async function createCLIEntryPointCommand() {
|
|
381
|
+
const pkgRaw = await fs.promises.readFile(path.join(process.cwd(), 'package.json'), {
|
|
382
|
+
encoding: 'utf8'
|
|
383
|
+
});
|
|
384
|
+
const pkg = JSON.parse(pkgRaw);
|
|
385
|
+
return defineCommand({
|
|
386
|
+
meta: {
|
|
387
|
+
name: pkg.name,
|
|
388
|
+
version: pkg.version,
|
|
389
|
+
description: pkg.description
|
|
390
|
+
},
|
|
391
|
+
args: {
|
|
392
|
+
command: {
|
|
393
|
+
type: 'positional',
|
|
394
|
+
description: 'The command which should be forwarded to the package.'
|
|
395
|
+
},
|
|
396
|
+
package: {
|
|
397
|
+
type: 'positional',
|
|
398
|
+
description: 'The package, which should be targeted.',
|
|
399
|
+
required: false
|
|
400
|
+
},
|
|
401
|
+
configDirectory: {
|
|
402
|
+
type: 'string',
|
|
403
|
+
description: 'Config directory path',
|
|
404
|
+
alias: 'cD'
|
|
405
|
+
},
|
|
406
|
+
configFile: {
|
|
407
|
+
type: 'string',
|
|
408
|
+
description: 'Name of one or more configuration files.',
|
|
409
|
+
alias: 'cF'
|
|
410
|
+
}
|
|
411
|
+
},
|
|
412
|
+
async run (ctx) {
|
|
413
|
+
let pkgs = ctx.args.package ? ctx.args.package.split(',') : [];
|
|
414
|
+
pkgs = pkgs.map((pkg)=>normalizePackageID(pkg)).filter((pkg)=>Boolean(pkg));
|
|
415
|
+
if (pkgs.length === 0) {
|
|
416
|
+
pkgs = Object.values(PackageID);
|
|
417
|
+
}
|
|
418
|
+
const promises = [];
|
|
419
|
+
for(let i = 0; i < pkgs.length; i++){
|
|
420
|
+
promises.push(executePackageCommand(pkgs[i], ctx.args.command, {
|
|
421
|
+
configFile: ctx.args.configFile,
|
|
422
|
+
configDirectory: ctx.args.configDirectory
|
|
423
|
+
}));
|
|
424
|
+
}
|
|
425
|
+
await Promise.all(promises);
|
|
394
426
|
}
|
|
395
|
-
await executeServicesCommand({
|
|
396
|
-
config: ctx.config,
|
|
397
|
-
command: ServiceCommand.START,
|
|
398
|
-
services: keysInput,
|
|
399
|
-
servicesAllowed
|
|
400
|
-
});
|
|
401
427
|
});
|
|
402
428
|
}
|
|
403
429
|
|
|
404
|
-
|
|
405
|
-
buildInfoCommand(cli);
|
|
406
|
-
buildStartCommand(cli);
|
|
407
|
-
buildCleanupCommand(cli);
|
|
408
|
-
cli.help();
|
|
409
|
-
cli.parse();
|
|
430
|
+
Promise.resolve().then(()=>createCLIEntryPointCommand()).then((command)=>runMain(command));
|
|
410
431
|
//# sourceMappingURL=index.mjs.map
|