silgi 0.24.19 → 0.24.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/dist/_chunks/silgiApp.mjs +311 -0
- package/dist/cli/compatibility.mjs +30 -0
- package/dist/cli/config/index.d.mts +11 -0
- package/dist/cli/config/index.mjs +16 -0
- package/dist/cli/dev.mjs +41 -5
- package/dist/cli/index.mjs +1 -1
- package/dist/cli/install.mjs +33 -2
- package/dist/cli/prepare.mjs +2381 -15
- package/dist/cli/types.mjs +772 -0
- package/dist/core/index.d.mts +271 -0
- package/dist/core/index.mjs +763 -0
- package/dist/index.d.mts +5 -285
- package/dist/index.mjs +11 -4165
- package/dist/kit/index.d.mts +20 -19
- package/dist/kit/index.mjs +130 -102
- package/dist/runtime/internal/config.mjs +3 -3
- package/dist/runtime/internal/nitro.d.mts +1 -1
- package/dist/runtime/internal/nitro.mjs +5 -5
- package/dist/types/index.d.mts +1 -1
- package/package.json +4 -2
- package/dist/_chunks/path.mjs +0 -62
- package/dist/cli/env.mjs +0 -40
package/dist/kit/index.d.mts
CHANGED
|
@@ -1,17 +1,34 @@
|
|
|
1
|
-
import { ConsolaOptions, ConsolaInstance } from 'consola';
|
|
2
1
|
import { SilgiCLI, ModuleOptionsCustom, ModuleDefinition, SilgiModule, ServiceParseModule, SilgiPreset, SilgiPresetMeta, SilgiTemplate, ResolvedSilgiTemplate, SilgiEvents } from 'silgi/types';
|
|
3
2
|
import { Buffer } from 'node:buffer';
|
|
3
|
+
import * as consola from 'consola';
|
|
4
|
+
import { ConsolaOptions } from 'consola';
|
|
4
5
|
import { IncomingMessage, ServerResponse } from 'node:http';
|
|
5
6
|
|
|
6
|
-
declare function useLogger(tag?: string, options?: Partial<ConsolaOptions>): ConsolaInstance;
|
|
7
|
-
|
|
8
7
|
declare function hasError(type: SilgiCLI['errors'][0]['type'], silgi?: SilgiCLI): boolean;
|
|
9
8
|
|
|
9
|
+
declare function directoryToURL(dir: string): URL;
|
|
10
|
+
/**
|
|
11
|
+
* Resolve a module from a given root path using an algorithm patterned on
|
|
12
|
+
* the upcoming `import.meta.resolve`. It returns a file URL
|
|
13
|
+
*
|
|
14
|
+
* @internal
|
|
15
|
+
*/
|
|
16
|
+
declare function tryResolveModule(id: string, url?: string | string[]): Promise<string | undefined>;
|
|
17
|
+
|
|
10
18
|
declare function writeFile(file: string, contents: Buffer | string, log?: boolean): Promise<void>;
|
|
11
19
|
declare function isDirectory(path: string): Promise<boolean>;
|
|
12
20
|
|
|
21
|
+
declare function genEnsureSafeVar(name: string | any): string;
|
|
22
|
+
declare function getAllEntries(obj: object): [string, any][];
|
|
23
|
+
|
|
13
24
|
declare function hash(data: any): string;
|
|
14
25
|
|
|
26
|
+
declare function isNuxt(): boolean;
|
|
27
|
+
declare function isNitro(): boolean;
|
|
28
|
+
declare function isH3(): boolean;
|
|
29
|
+
|
|
30
|
+
declare function useLogger(tag?: string, options?: Partial<ConsolaOptions>): consola.ConsolaInstance;
|
|
31
|
+
|
|
15
32
|
/**
|
|
16
33
|
* Define a Silgi module, automatically merging defaults with user provided options, installing
|
|
17
34
|
* any hooks that are provided, and calling an optional setup function for full control.
|
|
@@ -110,22 +127,6 @@ declare function getIpAddress(event: SilgiEvents): string | false;
|
|
|
110
127
|
*/
|
|
111
128
|
declare function ipAddress(req: IncomingMessage): string;
|
|
112
129
|
|
|
113
|
-
declare function directoryToURL(dir: string): URL;
|
|
114
|
-
/**
|
|
115
|
-
* Resolve a module from a given root path using an algorithm patterned on
|
|
116
|
-
* the upcoming `import.meta.resolve`. It returns a file URL
|
|
117
|
-
*
|
|
118
|
-
* @internal
|
|
119
|
-
*/
|
|
120
|
-
declare function tryResolveModule(id: string, url?: string | string[]): Promise<string | undefined>;
|
|
121
|
-
|
|
122
|
-
declare function genEnsureSafeVar(name: string | any): string;
|
|
123
|
-
declare function getAllEntries(obj: object): [string, any][];
|
|
124
|
-
|
|
125
|
-
declare function isNuxt(): boolean;
|
|
126
|
-
declare function isNitro(): boolean;
|
|
127
|
-
declare function isH3(): boolean;
|
|
128
|
-
|
|
129
130
|
declare function relativeWithDot(from: string, to: string): string;
|
|
130
131
|
/** @since 3.9.0 */
|
|
131
132
|
declare function toArray<T>(value: T | T[]): T[];
|
package/dist/kit/index.mjs
CHANGED
|
@@ -1,38 +1,71 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { tryUseSilgiCLI, useSilgiCLI, useSilgi } from 'silgi/core';
|
|
2
|
+
import { pathToFileURL, fileURLToPath } from 'node:url';
|
|
3
|
+
import { resolvePath as resolvePath$1 } from 'mlly';
|
|
3
4
|
import fsp from 'node:fs/promises';
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
6
|
-
|
|
5
|
+
import consola, { consola as consola$1 } from 'consola';
|
|
6
|
+
import { relative, resolve, dirname, normalize, isAbsolute, join, parse, basename } from 'pathe';
|
|
7
|
+
import { colors } from 'consola/utils';
|
|
8
|
+
import { getProperty } from 'dot-prop';
|
|
9
|
+
import { genString, genObjectFromRaw, genObjectFromValues, genObjectFromRawEntries } from 'knitwork';
|
|
7
10
|
import { hash as hash$1 } from 'ohash';
|
|
8
11
|
import { camelCase } from 'scule';
|
|
9
12
|
import { defu } from 'defu';
|
|
13
|
+
import { c as checkSilgiCompatibility } from '../cli/compatibility.mjs';
|
|
10
14
|
import { withLeadingSlash } from 'ufo';
|
|
11
15
|
import { existsSync, promises } from 'node:fs';
|
|
12
|
-
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
13
|
-
import { resolvePath as resolvePath$1 } from 'mlly';
|
|
14
16
|
import { resolveAlias as resolveAlias$1 } from 'pathe/utils';
|
|
15
17
|
import { hash as hash$2 } from 'silgi/kit';
|
|
16
|
-
import { genString, genObjectFromRaw, genObjectFromValues, genObjectFromRawEntries } from 'knitwork';
|
|
17
18
|
import 'semver/functions/satisfies.js';
|
|
18
19
|
import 'silgi/meta';
|
|
19
|
-
import 'consola/utils';
|
|
20
|
-
import 'dot-prop';
|
|
21
|
-
|
|
22
|
-
function useLogger(tag, options = {}) {
|
|
23
|
-
return tag ? consola.create(options).withTag(tag) : consola;
|
|
24
|
-
}
|
|
25
20
|
|
|
26
21
|
function hasError(type, silgi) {
|
|
27
|
-
silgi = silgi ??
|
|
22
|
+
silgi = silgi ?? tryUseSilgiCLI() ?? void 0;
|
|
28
23
|
if (silgi && silgi.errors.some((error) => error.type === type)) {
|
|
29
24
|
return true;
|
|
30
25
|
}
|
|
31
26
|
return false;
|
|
32
27
|
}
|
|
33
28
|
|
|
29
|
+
function directoryToURL(dir) {
|
|
30
|
+
return pathToFileURL(`${dir}/`);
|
|
31
|
+
}
|
|
32
|
+
async function tryResolveModule(id, url = import.meta.url) {
|
|
33
|
+
try {
|
|
34
|
+
return await resolvePath$1(id, { url });
|
|
35
|
+
} catch {
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function prettyPath(p, highlight = true) {
|
|
40
|
+
p = relative(process.cwd(), p);
|
|
41
|
+
return highlight ? colors.cyan(p) : p;
|
|
42
|
+
}
|
|
43
|
+
function resolveSilgiPath(path, silgiCLIOptions, base) {
|
|
44
|
+
if (typeof path !== "string") {
|
|
45
|
+
throw new TypeError(`Invalid path: ${path}`);
|
|
46
|
+
}
|
|
47
|
+
path = _compilePathTemplate(path)(silgiCLIOptions);
|
|
48
|
+
for (const base2 in silgiCLIOptions.alias) {
|
|
49
|
+
if (path.startsWith(base2)) {
|
|
50
|
+
path = silgiCLIOptions.alias[base2] + path.slice(base2.length);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return resolve(base || silgiCLIOptions.srcDir, path);
|
|
54
|
+
}
|
|
55
|
+
function _compilePathTemplate(contents) {
|
|
56
|
+
return (params) => contents.replace(/\{\{ ?([\w.]+) ?\}\}/g, (_, match) => {
|
|
57
|
+
const val = getProperty(params, match);
|
|
58
|
+
if (!val) {
|
|
59
|
+
consola.warn(
|
|
60
|
+
`cannot resolve template param '${match}' in ${contents.slice(0, 20)}`
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
return val || `${match}`;
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
|
|
34
67
|
async function writeFile(file, contents, log = false) {
|
|
35
|
-
const silgi =
|
|
68
|
+
const silgi = useSilgiCLI();
|
|
36
69
|
if (silgi.errors.length) {
|
|
37
70
|
return;
|
|
38
71
|
}
|
|
@@ -43,7 +76,7 @@ async function writeFile(file, contents, log = false) {
|
|
|
43
76
|
typeof contents === "string" ? "utf8" : void 0
|
|
44
77
|
);
|
|
45
78
|
if (log) {
|
|
46
|
-
consola.info("Generated", prettyPath(file));
|
|
79
|
+
consola$1.info("Generated", prettyPath(file));
|
|
47
80
|
}
|
|
48
81
|
}
|
|
49
82
|
async function isDirectory$1(path) {
|
|
@@ -54,10 +87,78 @@ async function isDirectory$1(path) {
|
|
|
54
87
|
}
|
|
55
88
|
}
|
|
56
89
|
|
|
90
|
+
const reservedCode = /* @__PURE__ */ new Set([
|
|
91
|
+
"process",
|
|
92
|
+
"global",
|
|
93
|
+
"runtime",
|
|
94
|
+
"runtimeConfig"
|
|
95
|
+
]);
|
|
96
|
+
function genEnsureSafeVar(name) {
|
|
97
|
+
if (typeof name !== "string") {
|
|
98
|
+
return genString(name);
|
|
99
|
+
}
|
|
100
|
+
for (const reserved of reservedCode) {
|
|
101
|
+
if (name === reserved || name.startsWith(`${reserved}.`)) {
|
|
102
|
+
return name;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
return genString(name);
|
|
106
|
+
}
|
|
107
|
+
function getAllEntries(obj) {
|
|
108
|
+
return Object.entries(obj).map(([
|
|
109
|
+
key,
|
|
110
|
+
value
|
|
111
|
+
]) => {
|
|
112
|
+
if (typeof value === "function") {
|
|
113
|
+
return [key, genObjectFromRaw(value)];
|
|
114
|
+
}
|
|
115
|
+
if (typeof value === "string") {
|
|
116
|
+
return [key, genEnsureSafeVar(value)];
|
|
117
|
+
}
|
|
118
|
+
if (typeof value === "object" && value !== null) {
|
|
119
|
+
if (Array.isArray(value)) {
|
|
120
|
+
return [key, genObjectFromValues(value.map(
|
|
121
|
+
(item) => typeof item === "object" && item !== null ? genObjectFromRawEntries(getAllEntries(item)) : item
|
|
122
|
+
))];
|
|
123
|
+
} else {
|
|
124
|
+
return [key, genObjectFromRawEntries(getAllEntries(value))];
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
return [key, value];
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
|
|
57
131
|
function hash(data) {
|
|
58
132
|
return camelCase(hash$1(data));
|
|
59
133
|
}
|
|
60
134
|
|
|
135
|
+
function isNuxt() {
|
|
136
|
+
const silgi = useSilgi();
|
|
137
|
+
if (silgi.options.present === "nitro" || silgi.options.present === "h3" || silgi.options.present === "nuxt") {
|
|
138
|
+
return true;
|
|
139
|
+
}
|
|
140
|
+
return false;
|
|
141
|
+
}
|
|
142
|
+
function isNitro() {
|
|
143
|
+
const silgi = useSilgi();
|
|
144
|
+
if (silgi.options.present === "nitro" || silgi.options.present === "h3") {
|
|
145
|
+
return true;
|
|
146
|
+
}
|
|
147
|
+
return false;
|
|
148
|
+
}
|
|
149
|
+
function isH3() {
|
|
150
|
+
const silgi = useSilgi();
|
|
151
|
+
if (silgi.options.present === "h3") {
|
|
152
|
+
return true;
|
|
153
|
+
}
|
|
154
|
+
return false;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
const logger = consola$1;
|
|
158
|
+
function useLogger(tag, options = {}) {
|
|
159
|
+
return tag ? logger.create(options).withTag(tag) : logger;
|
|
160
|
+
}
|
|
161
|
+
|
|
61
162
|
function defineSilgiModule(definition) {
|
|
62
163
|
if (definition) {
|
|
63
164
|
return _defineSilgiModule(definition);
|
|
@@ -72,14 +173,14 @@ function _defineSilgiModule(definition) {
|
|
|
72
173
|
}
|
|
73
174
|
const module = defu(definition, { meta: {} });
|
|
74
175
|
module.meta.configKey ||= module.meta.name;
|
|
75
|
-
async function getOptions(inlineOptions, silgi =
|
|
176
|
+
async function getOptions(inlineOptions, silgi = useSilgiCLI()) {
|
|
76
177
|
const nuxtConfigOptionsKey = module.meta.configKey || module.meta.name;
|
|
77
178
|
const nuxtConfigOptions = nuxtConfigOptionsKey && nuxtConfigOptionsKey in silgi.options ? silgi.options[nuxtConfigOptionsKey] : {};
|
|
78
179
|
const optionsDefaults = typeof module.defaults === "function" ? await module.defaults(silgi) : module.defaults ?? {};
|
|
79
180
|
const options = defu(inlineOptions, nuxtConfigOptions, optionsDefaults);
|
|
80
181
|
return Promise.resolve(options);
|
|
81
182
|
}
|
|
82
|
-
async function silgiNormalizedModule(inlineOptions, silgi =
|
|
183
|
+
async function silgiNormalizedModule(inlineOptions, silgi = tryUseSilgiCLI()) {
|
|
83
184
|
if (!silgi) {
|
|
84
185
|
throw new TypeError("Cannot use module outside of Silgi context");
|
|
85
186
|
}
|
|
@@ -226,7 +327,7 @@ async function isDirectory(path) {
|
|
|
226
327
|
return (await promises.lstat(path)).isDirectory();
|
|
227
328
|
}
|
|
228
329
|
function resolveAlias(path, alias) {
|
|
229
|
-
alias ||=
|
|
330
|
+
alias ||= tryUseSilgiCLI()?.options.alias || {};
|
|
230
331
|
return resolveAlias$1(path, alias || {});
|
|
231
332
|
}
|
|
232
333
|
function createResolver(base) {
|
|
@@ -272,10 +373,10 @@ function filterInPlace(array, predicate) {
|
|
|
272
373
|
return array;
|
|
273
374
|
}
|
|
274
375
|
const MODE_RE = /\.(server|client)(\.\w+)*$/;
|
|
275
|
-
function hasSilgiModule(moduleKey, silgi =
|
|
376
|
+
function hasSilgiModule(moduleKey, silgi = useSilgiCLI()) {
|
|
276
377
|
return silgi.scanModules.some(({ meta }) => meta.configKey === moduleKey) || Object.keys(silgi.scanModules).includes(moduleKey);
|
|
277
378
|
}
|
|
278
|
-
function hasInstalledModule(moduleKey, silgi =
|
|
379
|
+
function hasInstalledModule(moduleKey, silgi = useSilgiCLI()) {
|
|
279
380
|
const find = silgi.scanModules.find(({ meta }) => meta.configKey === moduleKey);
|
|
280
381
|
return find?.installed ?? false;
|
|
281
382
|
}
|
|
@@ -287,7 +388,7 @@ const baseHeaderBannerComment = [
|
|
|
287
388
|
"/* tslint:disable */"
|
|
288
389
|
];
|
|
289
390
|
function processFilePath(src) {
|
|
290
|
-
const silgi =
|
|
391
|
+
const silgi = useSilgiCLI();
|
|
291
392
|
if (silgi.options.typescript.removeFileExtension) {
|
|
292
393
|
src = src.replace(/\.ts$/, "");
|
|
293
394
|
return src;
|
|
@@ -296,7 +397,7 @@ function processFilePath(src) {
|
|
|
296
397
|
}
|
|
297
398
|
|
|
298
399
|
function addTemplate(_template) {
|
|
299
|
-
const silgi =
|
|
400
|
+
const silgi = useSilgiCLI();
|
|
300
401
|
const template = normalizeTemplate(_template);
|
|
301
402
|
filterInPlace(silgi.options.build.templates, (p) => normalizeTemplate(p).dst !== template.dst);
|
|
302
403
|
silgi.options.build.templates.push(template);
|
|
@@ -330,7 +431,7 @@ function normalizeTemplate(template, buildDir) {
|
|
|
330
431
|
template.write = true;
|
|
331
432
|
}
|
|
332
433
|
if (!template.dst) {
|
|
333
|
-
const silgi =
|
|
434
|
+
const silgi = useSilgiCLI();
|
|
334
435
|
const dir = template.where === ".silgi" ? silgi.options.build.dir : template.where === "server" ? silgi.options.silgi.serverDir : template.where === "client" ? silgi.options.silgi.clientDir : silgi.options.silgi.serverDir;
|
|
335
436
|
template.dst = resolve(buildDir ?? dir, template.filename);
|
|
336
437
|
}
|
|
@@ -338,21 +439,21 @@ function normalizeTemplate(template, buildDir) {
|
|
|
338
439
|
}
|
|
339
440
|
|
|
340
441
|
function useRequest(event) {
|
|
341
|
-
const silgi =
|
|
442
|
+
const silgi = useSilgi();
|
|
342
443
|
if (silgi.options.present === "nuxt" || silgi.options.present === "nitro" || silgi.options.present === "h3") {
|
|
343
444
|
return event.node.req;
|
|
344
445
|
}
|
|
345
446
|
return event;
|
|
346
447
|
}
|
|
347
448
|
function useResponse(event) {
|
|
348
|
-
const silgi =
|
|
449
|
+
const silgi = useSilgi();
|
|
349
450
|
if (silgi.options.present === "nuxt" || silgi.options.present === "nitro" || silgi.options.present === "h3") {
|
|
350
451
|
return event.node.res;
|
|
351
452
|
}
|
|
352
453
|
return event;
|
|
353
454
|
}
|
|
354
455
|
function getIpAddress(event) {
|
|
355
|
-
const silgi =
|
|
456
|
+
const silgi = useSilgi();
|
|
356
457
|
if (silgi.options.present === "nuxt" || silgi.options.present === "nitro" || silgi.options.present === "h3") {
|
|
357
458
|
const _ipAddress = ipAddress(event.node.req);
|
|
358
459
|
return _ipAddress;
|
|
@@ -425,77 +526,4 @@ function isValidIp(ip) {
|
|
|
425
526
|
return false;
|
|
426
527
|
}
|
|
427
528
|
|
|
428
|
-
|
|
429
|
-
return pathToFileURL(`${dir}/`);
|
|
430
|
-
}
|
|
431
|
-
async function tryResolveModule(id, url = import.meta.url) {
|
|
432
|
-
try {
|
|
433
|
-
return await resolvePath$1(id, { url });
|
|
434
|
-
} catch {
|
|
435
|
-
}
|
|
436
|
-
}
|
|
437
|
-
|
|
438
|
-
const reservedCode = /* @__PURE__ */ new Set([
|
|
439
|
-
"process",
|
|
440
|
-
"global",
|
|
441
|
-
"runtime",
|
|
442
|
-
"runtimeConfig"
|
|
443
|
-
]);
|
|
444
|
-
function genEnsureSafeVar(name) {
|
|
445
|
-
if (typeof name !== "string") {
|
|
446
|
-
return genString(name);
|
|
447
|
-
}
|
|
448
|
-
for (const reserved of reservedCode) {
|
|
449
|
-
if (name === reserved || name.startsWith(`${reserved}.`)) {
|
|
450
|
-
return name;
|
|
451
|
-
}
|
|
452
|
-
}
|
|
453
|
-
return genString(name);
|
|
454
|
-
}
|
|
455
|
-
function getAllEntries(obj) {
|
|
456
|
-
return Object.entries(obj).map(([
|
|
457
|
-
key,
|
|
458
|
-
value
|
|
459
|
-
]) => {
|
|
460
|
-
if (typeof value === "function") {
|
|
461
|
-
return [key, genObjectFromRaw(value)];
|
|
462
|
-
}
|
|
463
|
-
if (typeof value === "string") {
|
|
464
|
-
return [key, genEnsureSafeVar(value)];
|
|
465
|
-
}
|
|
466
|
-
if (typeof value === "object" && value !== null) {
|
|
467
|
-
if (Array.isArray(value)) {
|
|
468
|
-
return [key, genObjectFromValues(value.map(
|
|
469
|
-
(item) => typeof item === "object" && item !== null ? genObjectFromRawEntries(getAllEntries(item)) : item
|
|
470
|
-
))];
|
|
471
|
-
} else {
|
|
472
|
-
return [key, genObjectFromRawEntries(getAllEntries(value))];
|
|
473
|
-
}
|
|
474
|
-
}
|
|
475
|
-
return [key, value];
|
|
476
|
-
});
|
|
477
|
-
}
|
|
478
|
-
|
|
479
|
-
function isNuxt() {
|
|
480
|
-
const silgi = useSilgiApp();
|
|
481
|
-
if (silgi.options.present === "nitro" || silgi.options.present === "h3" || silgi.options.present === "nuxt") {
|
|
482
|
-
return true;
|
|
483
|
-
}
|
|
484
|
-
return false;
|
|
485
|
-
}
|
|
486
|
-
function isNitro() {
|
|
487
|
-
const silgi = useSilgiApp();
|
|
488
|
-
if (silgi.options.present === "nitro" || silgi.options.present === "h3") {
|
|
489
|
-
return true;
|
|
490
|
-
}
|
|
491
|
-
return false;
|
|
492
|
-
}
|
|
493
|
-
function isH3() {
|
|
494
|
-
const silgi = useSilgiApp();
|
|
495
|
-
if (silgi.options.present === "h3") {
|
|
496
|
-
return true;
|
|
497
|
-
}
|
|
498
|
-
return false;
|
|
499
|
-
}
|
|
500
|
-
|
|
501
|
-
export { MODE_RE, addTemplate, baseHeaderBannerComment, createResolver, defineSilgiModule, defineSilgiPreset, directoryToURL, filterInPlace, genEnsureSafeVar, getAllEntries, getIpAddress, hasError, hasInstalledModule, hasSilgiModule, hash, ipAddress, isDirectory$1 as isDirectory, isH3, isNitro, isNuxt, normalizeTemplate, parseServices, prettyPath, processFilePath, relativeWithDot, resolveAlias, resolvePath, resolveSilgiModule, serviceParseModule, toArray, tryResolveModule, useLogger, useRequest, useResponse, writeFile };
|
|
529
|
+
export { MODE_RE, addTemplate, baseHeaderBannerComment, createResolver, defineSilgiModule, defineSilgiPreset, directoryToURL, filterInPlace, genEnsureSafeVar, getAllEntries, getIpAddress, hasError, hasInstalledModule, hasSilgiModule, hash, ipAddress, isDirectory$1 as isDirectory, isH3, isNitro, isNuxt, normalizeTemplate, parseServices, prettyPath, processFilePath, relativeWithDot, resolveAlias, resolvePath, resolveSilgiModule, resolveSilgiPath, serviceParseModule, toArray, tryResolveModule, useLogger, useRequest, useResponse, writeFile };
|
|
@@ -2,7 +2,7 @@ import defu from "defu";
|
|
|
2
2
|
import destr from "destr";
|
|
3
3
|
import { klona } from "klona";
|
|
4
4
|
import { snakeCase } from "scule";
|
|
5
|
-
import {
|
|
5
|
+
import { tryUseSilgi, useSilgi } from "silgi/core";
|
|
6
6
|
let silgiRuntimeConfig = globalThis.__nitro__?.useRuntimeConfig?.() || process.env.RUNTIME_CONFIG;
|
|
7
7
|
let envOptions = {
|
|
8
8
|
prefix: "NITRO_",
|
|
@@ -26,7 +26,7 @@ export function useSilgiRuntimeConfig(event, inlineRuntimeConfig = {}) {
|
|
|
26
26
|
applyEnv(klona(silgiRuntimeConfig ?? {}), envOptions)
|
|
27
27
|
);
|
|
28
28
|
}
|
|
29
|
-
const silgi =
|
|
29
|
+
const silgi = tryUseSilgi();
|
|
30
30
|
if (!silgi) {
|
|
31
31
|
if (globalThis.$silgiSharedRuntimeConfig) {
|
|
32
32
|
inlineRuntimeConfig = globalThis.$silgiSharedRuntimeConfig;
|
|
@@ -67,7 +67,7 @@ export function initRuntimeConfig(envOptions2 = {}, inlineRuntimeConfig = {}) {
|
|
|
67
67
|
);
|
|
68
68
|
}
|
|
69
69
|
export function updateRuntimeConfig(runtimeConfig) {
|
|
70
|
-
const nuxt =
|
|
70
|
+
const nuxt = useSilgi();
|
|
71
71
|
Object.assign(nuxt.options.nitro.runtimeConfig, defu(runtimeConfig, nuxt.options.nitro.runtimeConfig));
|
|
72
72
|
try {
|
|
73
73
|
} catch {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createError, defineEventHandler, getQuery, H3Error, readBody } from "h3";
|
|
2
|
-
import { ErrorFactory, HttpStatus, parseURI, silgi, SilgiError,
|
|
3
|
-
export async function addNitroApp(
|
|
4
|
-
const nitro =
|
|
2
|
+
import { ErrorFactory, HttpStatus, parseURI, silgi, SilgiError, useSilgi } from "silgi/core";
|
|
3
|
+
export async function addNitroApp(silgiCtx = useSilgi()) {
|
|
4
|
+
const nitro = silgiCtx.framework;
|
|
5
5
|
nitro.router.use("/srn/**", defineEventHandler(async (event) => {
|
|
6
6
|
try {
|
|
7
7
|
const silgiConnect = silgi(event);
|
|
@@ -13,11 +13,11 @@ export async function addNitroApp(silgiAppCtx = useSilgiApp()) {
|
|
|
13
13
|
} else {
|
|
14
14
|
newPath = `${event.path}?method=${event.method}`;
|
|
15
15
|
}
|
|
16
|
-
const operation = parseURI(newPath,
|
|
16
|
+
const operation = parseURI(newPath, silgiCtx.uris);
|
|
17
17
|
if (!operation) {
|
|
18
18
|
throw ErrorFactory.create({ message: "Invalid URI", httpStatus: HttpStatus.BAD_REQUEST });
|
|
19
19
|
}
|
|
20
|
-
await
|
|
20
|
+
await silgiCtx.callHook("event:init", event, {
|
|
21
21
|
path: newPath,
|
|
22
22
|
queryParams: query,
|
|
23
23
|
operation
|
package/dist/types/index.d.mts
CHANGED
|
@@ -578,7 +578,7 @@ interface SilgiCLIOptions extends PresetOptions {
|
|
|
578
578
|
commandType: CommandType;
|
|
579
579
|
routeRules: SilgiRouteRules$1;
|
|
580
580
|
environments: DotenvOptions$1[];
|
|
581
|
-
activeEnvironment:
|
|
581
|
+
activeEnvironment: string;
|
|
582
582
|
envOptions: EnvOptions$1;
|
|
583
583
|
runtimeConfig: SilgiRuntimeConfig$1 & {
|
|
584
584
|
[key: string]: any;
|
package/package.json
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "silgi",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.24.
|
|
4
|
+
"version": "0.24.21",
|
|
5
5
|
"private": false,
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"exports": {
|
|
8
8
|
"./package.json": "./package.json",
|
|
9
|
-
".": "./dist/index.mjs",
|
|
9
|
+
".": "./dist/core/index.mjs",
|
|
10
|
+
"./core": "./dist/core/index.mjs",
|
|
10
11
|
"./cli": "./dist/cli/index.mjs",
|
|
12
|
+
"./cli/config": "./dist/cli/config/index.mjs",
|
|
11
13
|
"./kit": "./dist/kit/index.mjs",
|
|
12
14
|
"./config": "./lib/config.mjs",
|
|
13
15
|
"./types": "./dist/types/index.d.mts",
|
package/dist/_chunks/path.mjs
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import satisfies from 'semver/functions/satisfies.js';
|
|
2
|
-
import { useSilgi } from 'silgi';
|
|
3
|
-
import { version } from 'silgi/meta';
|
|
4
|
-
import consola from 'consola';
|
|
5
|
-
import { colors } from 'consola/utils';
|
|
6
|
-
import { getProperty } from 'dot-prop';
|
|
7
|
-
import { relative, resolve } from 'pathe';
|
|
8
|
-
|
|
9
|
-
const SEMANTIC_VERSION_RE = /-\d+\.[0-9a-f]+/;
|
|
10
|
-
function normalizeSemanticVersion(version) {
|
|
11
|
-
return version.replace(SEMANTIC_VERSION_RE, "");
|
|
12
|
-
}
|
|
13
|
-
const SILGI_VERSION_RE = /^v/g;
|
|
14
|
-
async function checkSilgiCompatibility(constraints, silgi = useSilgi()) {
|
|
15
|
-
const issues = [];
|
|
16
|
-
if (constraints.silgi) {
|
|
17
|
-
const _silgiVersion = version.replace(SILGI_VERSION_RE, "");
|
|
18
|
-
if (!satisfies(normalizeSemanticVersion(_silgiVersion), constraints.silgi, { includePrerelease: true })) {
|
|
19
|
-
issues.push({
|
|
20
|
-
name: "silgi",
|
|
21
|
-
message: `Silgi version \`${constraints.silgi}\` is required but currently using \`${version}\``
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
await silgi.callHook("kit:compatibility", constraints, issues);
|
|
26
|
-
issues.toString = () => issues.map((issue) => ` - [${issue.name}] ${issue.message}`).join("\n");
|
|
27
|
-
return issues;
|
|
28
|
-
}
|
|
29
|
-
function hasInstalledModule(moduleKey, silgi = useSilgi()) {
|
|
30
|
-
const find = silgi.scanModules.find(({ meta }) => meta.configKey === moduleKey);
|
|
31
|
-
return find?.installed ?? false;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
function prettyPath(p, highlight = true) {
|
|
35
|
-
p = relative(process.cwd(), p);
|
|
36
|
-
return highlight ? colors.cyan(p) : p;
|
|
37
|
-
}
|
|
38
|
-
function resolveSilgiPath(path, silgiCLIOptions, base) {
|
|
39
|
-
if (typeof path !== "string") {
|
|
40
|
-
throw new TypeError(`Invalid path: ${path}`);
|
|
41
|
-
}
|
|
42
|
-
path = _compilePathTemplate(path)(silgiCLIOptions);
|
|
43
|
-
for (const base2 in silgiCLIOptions.alias) {
|
|
44
|
-
if (path.startsWith(base2)) {
|
|
45
|
-
path = silgiCLIOptions.alias[base2] + path.slice(base2.length);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
return resolve(base || silgiCLIOptions.srcDir, path);
|
|
49
|
-
}
|
|
50
|
-
function _compilePathTemplate(contents) {
|
|
51
|
-
return (params) => contents.replace(/\{\{ ?([\w.]+) ?\}\}/g, (_, match) => {
|
|
52
|
-
const val = getProperty(params, match);
|
|
53
|
-
if (!val) {
|
|
54
|
-
consola.warn(
|
|
55
|
-
`cannot resolve template param '${match}' in ${contents.slice(0, 20)}`
|
|
56
|
-
);
|
|
57
|
-
}
|
|
58
|
-
return val || `${match}`;
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
export { checkSilgiCompatibility as c, hasInstalledModule as h, prettyPath as p, resolveSilgiPath as r };
|
package/dist/cli/env.mjs
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import * as p from '@clack/prompts';
|
|
2
|
-
import { setupDotenv } from 'silgi';
|
|
3
|
-
|
|
4
|
-
let initialized = false;
|
|
5
|
-
async function prepareEnv(silgiConfig) {
|
|
6
|
-
if (initialized)
|
|
7
|
-
return;
|
|
8
|
-
initialized = true;
|
|
9
|
-
const customEnvironments = silgiConfig.environments;
|
|
10
|
-
const environment = silgiConfig.activeEnvironment ? silgiConfig.activeEnvironment : await p.select({
|
|
11
|
-
message: "Select an environment",
|
|
12
|
-
options: customEnvironments?.length > 0 ? customEnvironments.map((env) => ({
|
|
13
|
-
label: env.fileName,
|
|
14
|
-
value: env.fileName
|
|
15
|
-
})) : [
|
|
16
|
-
{ label: "Development (.env.dev)", value: "dev" },
|
|
17
|
-
{ label: "Docker (.env.docker)", value: "docker" },
|
|
18
|
-
{ label: "Staging (.env.staging)", value: "staging" },
|
|
19
|
-
{ label: "Testing (.env.testing)", value: "testing" },
|
|
20
|
-
{ label: "Production (.env)", value: ".env" }
|
|
21
|
-
]
|
|
22
|
-
});
|
|
23
|
-
const findEnv = customEnvironments?.find((env) => env.fileName === environment);
|
|
24
|
-
if (findEnv) {
|
|
25
|
-
await setupDotenv({
|
|
26
|
-
cwd: findEnv.cwd || silgiConfig.rootDir,
|
|
27
|
-
interpolate: findEnv.interpolate,
|
|
28
|
-
fileName: findEnv.fileName,
|
|
29
|
-
env: findEnv.env
|
|
30
|
-
});
|
|
31
|
-
} else {
|
|
32
|
-
await setupDotenv({
|
|
33
|
-
cwd: silgiConfig.rootDir,
|
|
34
|
-
interpolate: true,
|
|
35
|
-
fileName: environment === ".env" ? ".env" : `.env.${environment}`
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export { prepareEnv as p };
|