@platforma-sdk/bootstrap 2.0.0 → 2.0.1
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/assets/compose-backend.yaml +6 -6
- package/dist/cmd-opts.d.ts +6 -3
- package/dist/cmd-opts.d.ts.map +1 -1
- package/dist/commands/start/docker/s3.d.ts +6 -3
- package/dist/commands/start/docker/s3.d.ts.map +1 -1
- package/dist/commands/start/docker.d.ts +6 -3
- package/dist/commands/start/docker.d.ts.map +1 -1
- package/dist/commands/start/local/s3.d.ts +6 -3
- package/dist/commands/start/local/s3.d.ts.map +1 -1
- package/dist/commands/start/local.d.ts +6 -3
- package/dist/commands/start/local.d.ts.map +1 -1
- package/dist/core.d.ts +15 -6
- package/dist/core.d.ts.map +1 -1
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +47 -40
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +928 -469
- package/dist/index.mjs.map +1 -1
- package/dist/package.d.ts +0 -1
- package/dist/package.d.ts.map +1 -1
- package/dist/platforma.d.ts.map +1 -1
- package/dist/state.d.ts +3 -0
- package/dist/state.d.ts.map +1 -1
- package/dist/templates/pl-config.d.ts.map +1 -1
- package/dist/templates/types.d.ts +6 -0
- package/dist/templates/types.d.ts.map +1 -1
- package/dist/util.d.ts +2 -0
- package/dist/util.d.ts.map +1 -1
- package/package.json +10 -7
- package/src/block.ts +0 -82
- package/src/cmd-opts.ts +0 -175
- package/src/commands/create-block.ts +0 -21
- package/src/commands/reset.ts +0 -23
- package/src/commands/start/docker/s3.ts +0 -59
- package/src/commands/start/docker.ts +0 -65
- package/src/commands/start/local/s3.ts +0 -96
- package/src/commands/start/local.ts +0 -89
- package/src/commands/start.ts +0 -23
- package/src/commands/stop.ts +0 -23
- package/src/core.ts +0 -696
- package/src/index.ts +0 -10
- package/src/package.ts +0 -54
- package/src/platforma.ts +0 -194
- package/src/run.ts +0 -120
- package/src/state.ts +0 -105
- package/src/templates/pl-config.ts +0 -280
- package/src/templates/types.ts +0 -172
- package/src/util.ts +0 -55
|
@@ -1,280 +0,0 @@
|
|
|
1
|
-
import fs from 'fs';
|
|
2
|
-
import * as types from './types';
|
|
3
|
-
import { assertNever, resolveTilde } from '../util';
|
|
4
|
-
import state from '../state';
|
|
5
|
-
|
|
6
|
-
export type { plOptions } from './types';
|
|
7
|
-
|
|
8
|
-
export function storageSettingsFromURL(
|
|
9
|
-
storageURL: string,
|
|
10
|
-
baseDir?: string,
|
|
11
|
-
defaults?: types.storageOptions
|
|
12
|
-
): types.storageOptions {
|
|
13
|
-
storageURL = resolveTilde(storageURL);
|
|
14
|
-
const url = new URL(storageURL, `file:${baseDir}`);
|
|
15
|
-
|
|
16
|
-
switch (url.protocol) {
|
|
17
|
-
case 's3:':
|
|
18
|
-
var bucketName = url.hostname;
|
|
19
|
-
var region = url.searchParams.get('region');
|
|
20
|
-
|
|
21
|
-
return {
|
|
22
|
-
...defaults,
|
|
23
|
-
|
|
24
|
-
type: 'S3',
|
|
25
|
-
bucketName,
|
|
26
|
-
region
|
|
27
|
-
} as types.storageOptions;
|
|
28
|
-
|
|
29
|
-
case 's3e:':
|
|
30
|
-
var p = url.pathname.split('/').slice(1); // '/bucket/keyPrefix' -> ['', 'bucket', 'keyPrefix'] -> ['bucket', 'keyPrefix']
|
|
31
|
-
var bucketName = p[0];
|
|
32
|
-
var keyPrefix = p.length > 1 ? p[1] : '';
|
|
33
|
-
|
|
34
|
-
return {
|
|
35
|
-
...defaults,
|
|
36
|
-
|
|
37
|
-
type: 'S3',
|
|
38
|
-
endpoint: `http://${url.host}/`,
|
|
39
|
-
bucketName,
|
|
40
|
-
keyPrefix,
|
|
41
|
-
region: url.searchParams.get('region'),
|
|
42
|
-
key: url.username ? `static:${url.username}` : '',
|
|
43
|
-
secret: url.password ? `static:${url.password}` : ''
|
|
44
|
-
} as types.storageOptions;
|
|
45
|
-
|
|
46
|
-
case 's3es:':
|
|
47
|
-
var p = url.pathname.split('/').slice(1); // '/bucket/keyPrefix' -> ['', 'bucket', 'keyPrefix'] -> ['bucket', 'keyPrefix']
|
|
48
|
-
var bucketName = p[0];
|
|
49
|
-
var keyPrefix = p.length > 1 ? p[1] : '';
|
|
50
|
-
|
|
51
|
-
return {
|
|
52
|
-
...defaults,
|
|
53
|
-
|
|
54
|
-
type: 'S3',
|
|
55
|
-
endpoint: `https://${url.host}/`,
|
|
56
|
-
bucketName,
|
|
57
|
-
keyPrefix,
|
|
58
|
-
region: url.searchParams.get('region'),
|
|
59
|
-
key: url.username ? `static:${url.username}` : '',
|
|
60
|
-
secret: url.password ? `static:${url.password}` : ''
|
|
61
|
-
} as types.storageOptions;
|
|
62
|
-
|
|
63
|
-
case 'file:':
|
|
64
|
-
return {
|
|
65
|
-
type: 'FS',
|
|
66
|
-
rootPath: url.pathname
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
default:
|
|
70
|
-
throw new Error(`storage protocol '${url.protocol}' is not supported`);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
export function loadDefaults(jwtKey: string, options?: types.plOptions): types.plSettings {
|
|
75
|
-
const localRoot = options?.localRoot ?? state.path('data', 'local-custom');
|
|
76
|
-
|
|
77
|
-
const log: types.logSettings = {
|
|
78
|
-
level: options?.log?.level ?? 'info',
|
|
79
|
-
path: options?.log?.path ?? `${localRoot}/platforma.log`
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
const grpc: types.grpcSettings = {
|
|
83
|
-
listen: options?.grpc?.listen ?? 'localhost:6345',
|
|
84
|
-
tls: {
|
|
85
|
-
enable: defaultBool(options?.grpc?.tls?.enable, false),
|
|
86
|
-
clientAuthMode: options?.grpc?.tls?.clientAuthMode ?? 'NoAuth',
|
|
87
|
-
certFile: options?.grpc?.tls?.certFile ?? `${localRoot}/certs/tls.cert`,
|
|
88
|
-
keyFile: options?.grpc?.tls?.keyFile ?? `${localRoot}/certs/tls.key`,
|
|
89
|
-
|
|
90
|
-
...options?.grpc?.tls
|
|
91
|
-
}
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
const core: types.coreSettings = {
|
|
95
|
-
auth: {
|
|
96
|
-
enabled: options?.core?.auth?.enabled ?? false,
|
|
97
|
-
drivers: options?.core?.auth?.drivers ?? [
|
|
98
|
-
{ driver: 'jwt', key: jwtKey },
|
|
99
|
-
{ driver: 'htpasswd', path: `${localRoot}/users.htpasswd` }
|
|
100
|
-
]
|
|
101
|
-
}
|
|
102
|
-
};
|
|
103
|
-
|
|
104
|
-
const primary = defaultStorageSettings(
|
|
105
|
-
'main',
|
|
106
|
-
`${localRoot}/storages/main`,
|
|
107
|
-
'main-bucket',
|
|
108
|
-
options?.storages?.primary
|
|
109
|
-
);
|
|
110
|
-
|
|
111
|
-
var work: types.storageSettings;
|
|
112
|
-
const wType = options?.storages?.work?.type;
|
|
113
|
-
switch (wType) {
|
|
114
|
-
case undefined:
|
|
115
|
-
case 'FS':
|
|
116
|
-
work = types.emptyFSSettings('work');
|
|
117
|
-
work.rootPath = options?.storages?.work?.rootPath ?? `${localRoot}/storages/work`;
|
|
118
|
-
work.indexCachePeriod = options?.storages?.work?.indexCachePeriod ?? '1m';
|
|
119
|
-
break;
|
|
120
|
-
|
|
121
|
-
default:
|
|
122
|
-
throw new Error("work storage MUST have 'FS' type as it is used for working directories management");
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
const library = defaultStorageSettings(
|
|
126
|
-
'library',
|
|
127
|
-
`${localRoot}/storages/library`,
|
|
128
|
-
'library-bucket',
|
|
129
|
-
options?.storages?.library
|
|
130
|
-
);
|
|
131
|
-
|
|
132
|
-
const monitoring: types.monitoringSettings = {
|
|
133
|
-
enabled: defaultBool(options?.monitoring?.enabled, true),
|
|
134
|
-
listen: options?.monitoring?.listen ?? '127.0.0.1:9090'
|
|
135
|
-
};
|
|
136
|
-
const debug: types.debugSettings = {
|
|
137
|
-
enabled: defaultBool(options?.debug?.enabled, true),
|
|
138
|
-
listen: options?.debug?.listen ?? '127.0.0.1:9091'
|
|
139
|
-
};
|
|
140
|
-
const license: types.licenseSettings = {
|
|
141
|
-
value: options?.license?.value ?? '',
|
|
142
|
-
file: options?.license?.file ?? ''
|
|
143
|
-
};
|
|
144
|
-
|
|
145
|
-
return {
|
|
146
|
-
localRoot,
|
|
147
|
-
license,
|
|
148
|
-
log,
|
|
149
|
-
grpc,
|
|
150
|
-
core,
|
|
151
|
-
monitoring,
|
|
152
|
-
debug,
|
|
153
|
-
storages: { primary, work, library },
|
|
154
|
-
hacks: { libraryDownloadable: true }
|
|
155
|
-
};
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
function defaultStorageSettings(
|
|
159
|
-
storageID: string,
|
|
160
|
-
defaultLocation: string,
|
|
161
|
-
defaultBucket: string,
|
|
162
|
-
options?: types.storageOptions
|
|
163
|
-
): types.storageSettings {
|
|
164
|
-
var storage: types.storageSettings;
|
|
165
|
-
const pType = options?.type;
|
|
166
|
-
switch (pType) {
|
|
167
|
-
case undefined:
|
|
168
|
-
case 'FS':
|
|
169
|
-
storage = types.emptyFSSettings(storageID);
|
|
170
|
-
storage.rootPath = options?.rootPath ?? defaultLocation;
|
|
171
|
-
break;
|
|
172
|
-
|
|
173
|
-
case 'S3':
|
|
174
|
-
storage = types.emptyS3Settings(storageID);
|
|
175
|
-
|
|
176
|
-
storage.endpoint = options?.endpoint ?? 'http://localhost:9000';
|
|
177
|
-
storage.presignEndpoint = options?.presignEndpoint ?? 'http://localhost:9000';
|
|
178
|
-
storage.bucketName = options?.bucketName ?? defaultBucket;
|
|
179
|
-
storage.createBucket = defaultBool(options?.createBucket, true);
|
|
180
|
-
storage.forcePathStyle = defaultBool(options?.forcePathStyle, true);
|
|
181
|
-
storage.key = options?.key ?? '';
|
|
182
|
-
storage.secret = options?.secret ?? '';
|
|
183
|
-
storage.keyPrefix = options?.keyPrefix ?? '';
|
|
184
|
-
storage.accessPrefixes = options?.accessPrefixes ?? [''];
|
|
185
|
-
storage.uploadKeyPrefix = options?.uploadKeyPrefix ?? '';
|
|
186
|
-
break;
|
|
187
|
-
|
|
188
|
-
default:
|
|
189
|
-
assertNever(pType);
|
|
190
|
-
throw new Error('unknown storage type'); // calm down TS type analyzer
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
return storage;
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
export function render(options: types.plSettings): string {
|
|
197
|
-
const disableMon = options.monitoring.enabled ? '' : ' disabled';
|
|
198
|
-
const disableDbg = options.debug.enabled ? '' : ' disabled';
|
|
199
|
-
const libraryDownloadable = options.hacks.libraryDownloadable ? 'true' : 'false';
|
|
200
|
-
|
|
201
|
-
var miLicenseSecret = options.license.value;
|
|
202
|
-
if (options.license.file != '') {
|
|
203
|
-
miLicenseSecret = fs.readFileSync(options.license.file).toString().trimEnd();
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
return `
|
|
207
|
-
license:
|
|
208
|
-
value: '${options.license.value}'
|
|
209
|
-
file: '${options.license.file}'
|
|
210
|
-
|
|
211
|
-
logging:
|
|
212
|
-
level: '${options.log.level}'
|
|
213
|
-
destinations:
|
|
214
|
-
- path: '${options.log.path}'
|
|
215
|
-
|
|
216
|
-
monitoring${disableMon}:
|
|
217
|
-
listen: '${options.monitoring.listen}'
|
|
218
|
-
|
|
219
|
-
debug${disableDbg}:
|
|
220
|
-
listen: '${options.debug.listen}'
|
|
221
|
-
|
|
222
|
-
core:
|
|
223
|
-
logging:
|
|
224
|
-
extendedInfo: true
|
|
225
|
-
dumpResourceData: true
|
|
226
|
-
|
|
227
|
-
grpc:
|
|
228
|
-
listen: '${options.grpc.listen}'
|
|
229
|
-
|
|
230
|
-
tlsEnabled: ${JSON.stringify(options.grpc.tls.enable)}
|
|
231
|
-
tls:
|
|
232
|
-
clientAuthMode: '${options.grpc.tls.clientAuthMode}'
|
|
233
|
-
certificates:
|
|
234
|
-
- certFile: '${options.grpc.tls.certFile}'
|
|
235
|
-
keyFile: '${options.grpc.tls.keyFile}'
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
authEnabled: ${JSON.stringify(options.core.auth.enabled)}
|
|
239
|
-
auth: ${JSON.stringify(options.core.auth.drivers)}
|
|
240
|
-
db:
|
|
241
|
-
path: '${options.localRoot}/db'
|
|
242
|
-
|
|
243
|
-
controllers:
|
|
244
|
-
data:
|
|
245
|
-
main:
|
|
246
|
-
storages:
|
|
247
|
-
main:
|
|
248
|
-
mode: primary
|
|
249
|
-
downloadable: true
|
|
250
|
-
|
|
251
|
-
library:
|
|
252
|
-
mode: passive
|
|
253
|
-
downloadable: ${libraryDownloadable}
|
|
254
|
-
|
|
255
|
-
work:
|
|
256
|
-
mode: active
|
|
257
|
-
downloadable: false
|
|
258
|
-
|
|
259
|
-
storages:
|
|
260
|
-
- ${JSON.stringify(options.storages.primary)}
|
|
261
|
-
- ${JSON.stringify(options.storages.library)}
|
|
262
|
-
- ${JSON.stringify(options.storages.work)}
|
|
263
|
-
|
|
264
|
-
runner:
|
|
265
|
-
type: local
|
|
266
|
-
storageRoot: '${(options.storages.work as types.fsStorageSettings).rootPath}'
|
|
267
|
-
secrets:
|
|
268
|
-
- map:
|
|
269
|
-
MI_LICENSE: ${JSON.stringify(miLicenseSecret)}
|
|
270
|
-
|
|
271
|
-
packageLoader:
|
|
272
|
-
packagesRoot: '${options.localRoot}/packages'
|
|
273
|
-
|
|
274
|
-
workflows: {}
|
|
275
|
-
`;
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
function defaultBool(v: boolean | undefined, def: boolean): boolean {
|
|
279
|
-
return v === undefined ? def : v;
|
|
280
|
-
}
|
package/src/templates/types.ts
DELETED
|
@@ -1,172 +0,0 @@
|
|
|
1
|
-
export type plSettings = {
|
|
2
|
-
localRoot: string;
|
|
3
|
-
|
|
4
|
-
license: licenseSettings;
|
|
5
|
-
log: logSettings;
|
|
6
|
-
grpc: grpcSettings;
|
|
7
|
-
core: coreSettings;
|
|
8
|
-
storages: storagesSettings;
|
|
9
|
-
|
|
10
|
-
monitoring: monitoringSettings;
|
|
11
|
-
debug: debugSettings;
|
|
12
|
-
|
|
13
|
-
hacks: {
|
|
14
|
-
libraryDownloadable: boolean;
|
|
15
|
-
};
|
|
16
|
-
};
|
|
17
|
-
export type plOptions = {
|
|
18
|
-
localRoot?: string;
|
|
19
|
-
|
|
20
|
-
license?: licenseOptions;
|
|
21
|
-
log?: logOptions;
|
|
22
|
-
grpc?: grpcOptions;
|
|
23
|
-
core?: coreOptions;
|
|
24
|
-
storages?: storagesOptions;
|
|
25
|
-
|
|
26
|
-
monitoring?: monitoringOptions;
|
|
27
|
-
debug?: debugOptions;
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
export type licenseSettings = {
|
|
31
|
-
value: string;
|
|
32
|
-
file: string;
|
|
33
|
-
};
|
|
34
|
-
export type licenseOptions = DeepPartial<licenseSettings>;
|
|
35
|
-
|
|
36
|
-
export type logSettings = {
|
|
37
|
-
level: string;
|
|
38
|
-
path: string;
|
|
39
|
-
};
|
|
40
|
-
export type logOptions = DeepPartial<logSettings>;
|
|
41
|
-
|
|
42
|
-
export type coreSettings = {
|
|
43
|
-
auth: authSettings;
|
|
44
|
-
};
|
|
45
|
-
export type coreOptions = {
|
|
46
|
-
auth?: authOptions;
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
export type authSettings = {
|
|
50
|
-
enabled: boolean;
|
|
51
|
-
drivers: authDriver[];
|
|
52
|
-
};
|
|
53
|
-
export type authOptions = Partial<authSettings>;
|
|
54
|
-
|
|
55
|
-
export type authDriver =
|
|
56
|
-
| {
|
|
57
|
-
driver: 'ldap';
|
|
58
|
-
serverUrl: string; // 'ldaps://ldap.example.com:1111'
|
|
59
|
-
defaultDN: string; // 'cn=%u,ou=users,ou=users,dc=example,dc=com'
|
|
60
|
-
}
|
|
61
|
-
| {
|
|
62
|
-
driver: 'jwt';
|
|
63
|
-
key: string;
|
|
64
|
-
}
|
|
65
|
-
| {
|
|
66
|
-
driver: 'htpasswd';
|
|
67
|
-
path: string;
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
export type grpcSettings = {
|
|
71
|
-
listen: string;
|
|
72
|
-
tls: tlsSettings;
|
|
73
|
-
};
|
|
74
|
-
export type grpcOptions = Partial<grpcSettings>;
|
|
75
|
-
|
|
76
|
-
export type tlsSettings = {
|
|
77
|
-
enable: boolean;
|
|
78
|
-
clientAuthMode: tlsAuthMode;
|
|
79
|
-
certFile: string;
|
|
80
|
-
keyFile: string;
|
|
81
|
-
};
|
|
82
|
-
export type tlsOptions = Partial<tlsSettings>;
|
|
83
|
-
|
|
84
|
-
export type tlsAuthMode = 'NoAuth' | 'RequestAnyCert' | 'RequireAnyCert' | 'RequestValidCert' | 'RequireValidCert';
|
|
85
|
-
|
|
86
|
-
export type storagesSettings = {
|
|
87
|
-
primary: storageSettings;
|
|
88
|
-
work: fsStorageSettings;
|
|
89
|
-
library: storageSettings;
|
|
90
|
-
};
|
|
91
|
-
export type storagesOptions = {
|
|
92
|
-
primary?: storageOptions;
|
|
93
|
-
work?: storageOptions;
|
|
94
|
-
library?: storageOptions;
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
export type storageSettings = s3StorageSettings | fsStorageSettings;
|
|
98
|
-
export type storageOptions = s3StorageOptions | fsStorageOptions;
|
|
99
|
-
|
|
100
|
-
type storageID = { id: string };
|
|
101
|
-
type commonStorageSettings = {
|
|
102
|
-
indexCachePeriod: string;
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
export type s3StorageSettings = storageID & s3StorageType & commonStorageSettings & s3StorageTypeSettings;
|
|
106
|
-
export type s3StorageOptions = s3StorageType & Partial<commonStorageSettings> & Partial<s3StorageTypeSettings>;
|
|
107
|
-
export function emptyS3Settings(id: string): s3StorageSettings {
|
|
108
|
-
return {
|
|
109
|
-
id: id,
|
|
110
|
-
type: 'S3',
|
|
111
|
-
indexCachePeriod: '0s',
|
|
112
|
-
endpoint: '',
|
|
113
|
-
region: '',
|
|
114
|
-
presignEndpoint: '',
|
|
115
|
-
bucketName: '',
|
|
116
|
-
createBucket: false,
|
|
117
|
-
forcePathStyle: false,
|
|
118
|
-
key: '',
|
|
119
|
-
secret: '',
|
|
120
|
-
keyPrefix: '',
|
|
121
|
-
accessPrefixes: [],
|
|
122
|
-
uploadKeyPrefix: ''
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
type s3StorageType = { type: 'S3' };
|
|
127
|
-
type s3StorageTypeSettings = {
|
|
128
|
-
endpoint: string;
|
|
129
|
-
presignEndpoint: string;
|
|
130
|
-
region: string;
|
|
131
|
-
bucketName: string;
|
|
132
|
-
createBucket: boolean;
|
|
133
|
-
forcePathStyle: boolean;
|
|
134
|
-
key: string;
|
|
135
|
-
secret: string;
|
|
136
|
-
keyPrefix: string;
|
|
137
|
-
accessPrefixes: string[];
|
|
138
|
-
uploadKeyPrefix: string;
|
|
139
|
-
};
|
|
140
|
-
|
|
141
|
-
export type fsStorageSettings = storageID & fsStorageType & commonStorageSettings & fsStorageTypeSettings;
|
|
142
|
-
export type fsStorageOptions = fsStorageType & Partial<commonStorageSettings> & Partial<fsStorageTypeSettings>;
|
|
143
|
-
export function emptyFSSettings(id: string): fsStorageSettings {
|
|
144
|
-
return {
|
|
145
|
-
id: id,
|
|
146
|
-
type: 'FS',
|
|
147
|
-
indexCachePeriod: '0s',
|
|
148
|
-
rootPath: ''
|
|
149
|
-
};
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
type fsStorageType = { type: 'FS' };
|
|
153
|
-
type fsStorageTypeSettings = {
|
|
154
|
-
rootPath: string;
|
|
155
|
-
};
|
|
156
|
-
|
|
157
|
-
export type monitoringSettings = {
|
|
158
|
-
enabled: boolean;
|
|
159
|
-
listen: string;
|
|
160
|
-
};
|
|
161
|
-
export type monitoringOptions = Partial<monitoringSettings>;
|
|
162
|
-
|
|
163
|
-
export type debugSettings = {
|
|
164
|
-
enabled: boolean;
|
|
165
|
-
listen: string;
|
|
166
|
-
};
|
|
167
|
-
export type debugOptions = Partial<debugSettings>;
|
|
168
|
-
|
|
169
|
-
/** Makes all keys and keys in sub-objects optional. */
|
|
170
|
-
type DeepPartial<T> = {
|
|
171
|
-
[P in keyof T]?: T[P] extends object ? DeepPartial<T[P]> : T[P];
|
|
172
|
-
};
|
package/src/util.ts
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import os from 'os';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
|
|
4
|
-
import winston from 'winston';
|
|
5
|
-
import { randomBytes } from 'crypto';
|
|
6
|
-
import readlineSync from 'readline-sync';
|
|
7
|
-
|
|
8
|
-
export function askYN(prompt: string): boolean {
|
|
9
|
-
const answer = readlineSync.question(`${prompt} [y/N] `);
|
|
10
|
-
return answer.toLowerCase() === 'y';
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export function assertNever(n: never) {
|
|
14
|
-
throw new Error('this should never happen');
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export function createLogger(level: string = 'debug'): winston.Logger {
|
|
18
|
-
return winston.createLogger({
|
|
19
|
-
level: level,
|
|
20
|
-
|
|
21
|
-
format: winston.format.combine(
|
|
22
|
-
winston.format.printf(({ level, message }) => {
|
|
23
|
-
const indent = ' '.repeat(level.length + 2); // For ': ' after the level
|
|
24
|
-
const indentedMessage = message
|
|
25
|
-
.split('\n')
|
|
26
|
-
.map((line: string, index: number) => (index === 0 ? line : indent + line))
|
|
27
|
-
.join('\n');
|
|
28
|
-
|
|
29
|
-
const colorize = (l: string) => winston.format.colorize().colorize(l, l);
|
|
30
|
-
|
|
31
|
-
return `${colorize(level)}: ${indentedMessage}`;
|
|
32
|
-
})
|
|
33
|
-
),
|
|
34
|
-
|
|
35
|
-
transports: [
|
|
36
|
-
new winston.transports.Console({
|
|
37
|
-
stderrLevels: ['error', 'warn', 'info', 'debug'],
|
|
38
|
-
handleExceptions: true
|
|
39
|
-
})
|
|
40
|
-
]
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export function randomStr(len: number): string {
|
|
45
|
-
return randomBytes(Math.ceil(len / 2))
|
|
46
|
-
.toString('hex')
|
|
47
|
-
.slice(0, len);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export function resolveTilde(p: string): string {
|
|
51
|
-
if (p.startsWith('~')) {
|
|
52
|
-
return path.join(os.homedir(), p.slice(1));
|
|
53
|
-
}
|
|
54
|
-
return p;
|
|
55
|
-
}
|