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