silgi 0.27.5 → 0.27.6
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 +287 -1
- package/dist/build.d.mts +3 -16
- package/dist/build.mjs +8 -32
- package/dist/cli/build.mjs +861 -0
- package/dist/cli/config/index.mjs +2 -1
- package/dist/cli/dev.mjs +12 -12
- package/dist/cli/index.mjs +1 -1
- package/dist/cli/init.mjs +14 -14
- package/dist/cli/install.mjs +14 -14
- package/dist/cli/loader.mjs +598 -0
- package/dist/cli/prepare.mjs +1575 -18
- package/dist/cli/types.mjs +6 -597
- package/dist/core/index.mjs +2 -2
- package/dist/index.mjs +1 -2
- package/package.json +1 -1
- package/dist/_chunks/routeRules.mjs +0 -288
- package/dist/cli/writeTypesAndFiles.mjs +0 -2413
|
@@ -0,0 +1,598 @@
|
|
|
1
|
+
import { watchConfig, loadConfig } from 'c12';
|
|
2
|
+
import { resolveCompatibilityDatesFromEnv, formatDate, resolveCompatibilityDates } from 'compatx';
|
|
3
|
+
import { klona } from 'klona/full';
|
|
4
|
+
import { isDebug, isTest } from 'std-env';
|
|
5
|
+
import consola from 'consola';
|
|
6
|
+
import { colors } from 'consola/utils';
|
|
7
|
+
import { relative, join, resolve } from 'pathe';
|
|
8
|
+
import escapeRE from 'escape-string-regexp';
|
|
9
|
+
import { resolveModuleExportNames } from 'mlly';
|
|
10
|
+
import { existsSync } from 'node:fs';
|
|
11
|
+
import { findWorkspaceDir, readPackageJSON } from 'pkg-types';
|
|
12
|
+
import { resolveSilgiPath } from 'silgi/kit';
|
|
13
|
+
import { runtimeDir, pkgDir } from 'silgi/runtime/meta';
|
|
14
|
+
import { withLeadingSlash, withTrailingSlash } from 'ufo';
|
|
15
|
+
|
|
16
|
+
const SilgiCLIDefaults = {
|
|
17
|
+
// General
|
|
18
|
+
debug: isDebug,
|
|
19
|
+
// timing: isDebug,
|
|
20
|
+
logLevel: isTest ? 1 : 3,
|
|
21
|
+
// runtimeConfig: { app: {}, silgi: {} },
|
|
22
|
+
appConfig: {},
|
|
23
|
+
appConfigFiles: [],
|
|
24
|
+
commandType: "prepare",
|
|
25
|
+
runtimeConfig: {
|
|
26
|
+
silgi: {
|
|
27
|
+
version: "0.0.1"
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
serviceParseModules: [],
|
|
31
|
+
storages: [],
|
|
32
|
+
devServer: {
|
|
33
|
+
watch: []
|
|
34
|
+
},
|
|
35
|
+
// Dirs
|
|
36
|
+
scanDirs: [],
|
|
37
|
+
build: {
|
|
38
|
+
dir: ".silgi",
|
|
39
|
+
typesDir: "{{ build.dir }}/types",
|
|
40
|
+
templates: []
|
|
41
|
+
},
|
|
42
|
+
output: {
|
|
43
|
+
dir: "{{ rootDir }}/.output",
|
|
44
|
+
serverDir: "{{ output.dir }}/server",
|
|
45
|
+
publicDir: "{{ output.dir }}/public"
|
|
46
|
+
},
|
|
47
|
+
serverDir: "{{ rootDir }}/server",
|
|
48
|
+
clientDir: "{{ rootDir }}/client",
|
|
49
|
+
silgi: {
|
|
50
|
+
serverDir: "{{ serverDir }}/silgi",
|
|
51
|
+
clientDir: "{{ clientDir }}/silgi",
|
|
52
|
+
publicDir: "{{ silgi.serverDir }}/public",
|
|
53
|
+
utilsDir: "{{ silgi.serverDir }}/utils",
|
|
54
|
+
vfsDir: "{{ silgi.serverDir }}/vfs",
|
|
55
|
+
typesDir: "{{ silgi.serverDir }}/types"
|
|
56
|
+
},
|
|
57
|
+
// Codegen
|
|
58
|
+
codegen: {
|
|
59
|
+
env: {
|
|
60
|
+
safeList: [
|
|
61
|
+
["silgi", "version"]
|
|
62
|
+
]
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
// Modules
|
|
66
|
+
_modules: [],
|
|
67
|
+
modules: [],
|
|
68
|
+
routeRules: {},
|
|
69
|
+
// Features
|
|
70
|
+
// experimental: {},
|
|
71
|
+
future: {},
|
|
72
|
+
storage: {},
|
|
73
|
+
devStorage: {},
|
|
74
|
+
stub: false,
|
|
75
|
+
// bundledStorage: [],
|
|
76
|
+
// publicAssets: [],
|
|
77
|
+
// serverAssets: [],
|
|
78
|
+
plugins: [],
|
|
79
|
+
// tasks: {},
|
|
80
|
+
// scheduledTasks: {},
|
|
81
|
+
imports: {
|
|
82
|
+
exclude: [],
|
|
83
|
+
dirs: [],
|
|
84
|
+
presets: [],
|
|
85
|
+
virtualImports: ["#silgiImports"]
|
|
86
|
+
},
|
|
87
|
+
// virtual: {},
|
|
88
|
+
// compressPublicAssets: false,
|
|
89
|
+
ignore: [],
|
|
90
|
+
// Dev
|
|
91
|
+
dev: false,
|
|
92
|
+
// devServer: { watch: [] },
|
|
93
|
+
watchOptions: {
|
|
94
|
+
ignoreInitial: true,
|
|
95
|
+
ignored: [
|
|
96
|
+
"**/node_modules/**",
|
|
97
|
+
"**/.git/**",
|
|
98
|
+
"**/.silgi/**",
|
|
99
|
+
"**/.output/**",
|
|
100
|
+
"**/.vscode/**",
|
|
101
|
+
"**/.idea/**",
|
|
102
|
+
"**/.nuxt/**",
|
|
103
|
+
"**/.next/**",
|
|
104
|
+
"**/.gitignore",
|
|
105
|
+
"**/.gitattributes",
|
|
106
|
+
"**/assets/**",
|
|
107
|
+
"**/dist/**",
|
|
108
|
+
"**/build/**",
|
|
109
|
+
"**/coverage/**",
|
|
110
|
+
"**/test/**",
|
|
111
|
+
"**/tests/**",
|
|
112
|
+
"**/tmp/**"
|
|
113
|
+
]
|
|
114
|
+
},
|
|
115
|
+
// devProxy: {},
|
|
116
|
+
// Logging
|
|
117
|
+
// logging: {
|
|
118
|
+
// compressedSizes: true,
|
|
119
|
+
// buildSuccess: true,
|
|
120
|
+
// },
|
|
121
|
+
// Routing
|
|
122
|
+
// baseURL: process.env.NITRO_APP_BASE_URL || '/',
|
|
123
|
+
// handlers: [],
|
|
124
|
+
// devHandlers: [],
|
|
125
|
+
// errorHandler: undefined,
|
|
126
|
+
// Advanced
|
|
127
|
+
typescript: {
|
|
128
|
+
strict: false,
|
|
129
|
+
generateTsConfig: true,
|
|
130
|
+
// generateRuntimeConfigTypes: true,
|
|
131
|
+
tsconfigPath: ".silgi/types/silgi.tsconfig.json",
|
|
132
|
+
tsConfig: {},
|
|
133
|
+
customConditions: [],
|
|
134
|
+
generateRuntimeConfigTypes: true,
|
|
135
|
+
removeFileExtension: false
|
|
136
|
+
},
|
|
137
|
+
conditions: [],
|
|
138
|
+
nodeModulesDirs: [],
|
|
139
|
+
// hooks: {},
|
|
140
|
+
commands: {},
|
|
141
|
+
// Framework
|
|
142
|
+
framework: {
|
|
143
|
+
name: "h3",
|
|
144
|
+
version: ""
|
|
145
|
+
},
|
|
146
|
+
extensions: [".js", ".jsx", ".mjs", ".ts", ".tsx", ".vue"],
|
|
147
|
+
ignoreOptions: void 0,
|
|
148
|
+
// 3. party
|
|
149
|
+
apiFul: {}
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
const fallbackCompatibilityDate = "2025-02-04";
|
|
153
|
+
async function resolveCompatibilityOptions(options) {
|
|
154
|
+
options.compatibilityDate = resolveCompatibilityDatesFromEnv(
|
|
155
|
+
options.compatibilityDate
|
|
156
|
+
);
|
|
157
|
+
if (!options.compatibilityDate.default) {
|
|
158
|
+
options.compatibilityDate.default = await _resolveDefault(options);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
let _fallbackInfoShown = false;
|
|
162
|
+
let _promptedUserToUpdate = false;
|
|
163
|
+
async function _resolveDefault(options) {
|
|
164
|
+
const _todayDate = formatDate(/* @__PURE__ */ new Date());
|
|
165
|
+
const consola$1 = consola.withTag("silgi");
|
|
166
|
+
consola$1.warn(`No valid compatibility date is specified.`);
|
|
167
|
+
const onFallback = () => {
|
|
168
|
+
if (!_fallbackInfoShown) {
|
|
169
|
+
consola$1.info(
|
|
170
|
+
[
|
|
171
|
+
`Using \`${fallbackCompatibilityDate}\` as fallback.`,
|
|
172
|
+
` Please specify compatibility date to avoid unwanted behavior changes:`,
|
|
173
|
+
` - Add \`compatibilityDate: '${_todayDate}'\` to the config file.`,
|
|
174
|
+
` - Or set \`COMPATIBILITY_DATE=${_todayDate}\` environment variable.`,
|
|
175
|
+
``
|
|
176
|
+
].join("\n")
|
|
177
|
+
);
|
|
178
|
+
_fallbackInfoShown = true;
|
|
179
|
+
}
|
|
180
|
+
return fallbackCompatibilityDate;
|
|
181
|
+
};
|
|
182
|
+
const shallUpdate = !_promptedUserToUpdate && await consola$1.prompt(
|
|
183
|
+
`Do you want to auto update config file to set ${colors.cyan(`compatibilityDate: '${_todayDate}'`)}?`,
|
|
184
|
+
{
|
|
185
|
+
type: "confirm",
|
|
186
|
+
default: true
|
|
187
|
+
}
|
|
188
|
+
);
|
|
189
|
+
_promptedUserToUpdate = true;
|
|
190
|
+
if (!shallUpdate) {
|
|
191
|
+
return onFallback();
|
|
192
|
+
}
|
|
193
|
+
const { updateConfig } = await import('c12/update');
|
|
194
|
+
const updateResult = await updateConfig({
|
|
195
|
+
configFile: "silgi.config",
|
|
196
|
+
cwd: options.rootDir,
|
|
197
|
+
async onCreate({ configFile }) {
|
|
198
|
+
const shallCreate = await consola$1.prompt(
|
|
199
|
+
`Do you want to initialize a new config in ${colors.cyan(relative(".", configFile))}?`,
|
|
200
|
+
{
|
|
201
|
+
type: "confirm",
|
|
202
|
+
default: true
|
|
203
|
+
}
|
|
204
|
+
);
|
|
205
|
+
if (shallCreate !== true) {
|
|
206
|
+
return false;
|
|
207
|
+
}
|
|
208
|
+
return _getDefaultNitroConfig();
|
|
209
|
+
},
|
|
210
|
+
async onUpdate(config) {
|
|
211
|
+
config.compatibilityDate = _todayDate;
|
|
212
|
+
}
|
|
213
|
+
}).catch((error) => {
|
|
214
|
+
consola$1.error(`Failed to update config: ${error.message}`);
|
|
215
|
+
return null;
|
|
216
|
+
});
|
|
217
|
+
if (updateResult?.configFile) {
|
|
218
|
+
consola$1.success(
|
|
219
|
+
`Compatibility date set to \`${_todayDate}\` in \`${relative(".", updateResult.configFile)}\``
|
|
220
|
+
);
|
|
221
|
+
return _todayDate;
|
|
222
|
+
}
|
|
223
|
+
return onFallback();
|
|
224
|
+
}
|
|
225
|
+
function _getDefaultNitroConfig() {
|
|
226
|
+
return (
|
|
227
|
+
/* js */
|
|
228
|
+
`
|
|
229
|
+
import { defineSilgiConfig } from 'silgi/config'
|
|
230
|
+
|
|
231
|
+
export default defineSilgiConfig({})
|
|
232
|
+
`
|
|
233
|
+
);
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
async function resolveImportsOptions(options) {
|
|
237
|
+
if (options.imports === false) {
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
options.imports.presets ??= [];
|
|
241
|
+
options.imports.presets.push(...getSilgiImportsPreset());
|
|
242
|
+
if (options.preset === "h3") {
|
|
243
|
+
const h3Exports = await resolveModuleExportNames("h3", {
|
|
244
|
+
url: import.meta.url
|
|
245
|
+
});
|
|
246
|
+
options.imports.presets ??= [];
|
|
247
|
+
options.imports.presets.push({
|
|
248
|
+
from: "h3",
|
|
249
|
+
imports: h3Exports.filter((n) => !/^[A-Z]/.test(n) && n !== "use")
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
options.imports.dirs ??= [];
|
|
253
|
+
options.imports.dirs.push(
|
|
254
|
+
...options.scanDirs.map((dir) => join(dir, "utils/**/*"))
|
|
255
|
+
);
|
|
256
|
+
if (Array.isArray(options.imports.exclude) && options.imports.exclude.length === 0) {
|
|
257
|
+
options.imports.exclude.push(/[/\\]\.git[/\\]/);
|
|
258
|
+
options.imports.exclude.push(options.build.dir);
|
|
259
|
+
const scanDirsInNodeModules = options.scanDirs.map((dir) => dir.match(/(?<=\/)node_modules\/(.+)$/)?.[1]).filter(Boolean);
|
|
260
|
+
options.imports.exclude.push(
|
|
261
|
+
scanDirsInNodeModules.length > 0 ? new RegExp(
|
|
262
|
+
`node_modules\\/(?!${scanDirsInNodeModules.map((dir) => escapeRE(dir)).join("|")})`
|
|
263
|
+
) : /[/\\]node_modules[/\\]/
|
|
264
|
+
);
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
function getSilgiImportsPreset() {
|
|
268
|
+
return [
|
|
269
|
+
// TODO: buraya bizim importlarimiz gelecek.
|
|
270
|
+
{
|
|
271
|
+
from: "silgi",
|
|
272
|
+
imports: [
|
|
273
|
+
"createShared",
|
|
274
|
+
"useSilgi",
|
|
275
|
+
"createService",
|
|
276
|
+
"createSchema"
|
|
277
|
+
]
|
|
278
|
+
},
|
|
279
|
+
// {
|
|
280
|
+
// from: 'nitropack/runtime',
|
|
281
|
+
// imports: ['useRuntimeConfig', 'useAppConfig'],
|
|
282
|
+
// },
|
|
283
|
+
// {
|
|
284
|
+
// from: 'nitropack/runtime',
|
|
285
|
+
// imports: ['defineNitroPlugin', 'nitroPlugin'],
|
|
286
|
+
// },
|
|
287
|
+
// {
|
|
288
|
+
// from: 'nitropack/runtime/internal/cache',
|
|
289
|
+
// imports: [
|
|
290
|
+
// 'defineCachedFunction',
|
|
291
|
+
// 'defineCachedEventHandler',
|
|
292
|
+
// 'cachedFunction',
|
|
293
|
+
// 'cachedEventHandler',
|
|
294
|
+
// ],
|
|
295
|
+
// },
|
|
296
|
+
{
|
|
297
|
+
from: "silgi",
|
|
298
|
+
imports: ["useSilgiStorage"]
|
|
299
|
+
}
|
|
300
|
+
// {
|
|
301
|
+
// from: 'nitropack/runtime/internal/renderer',
|
|
302
|
+
// imports: ['defineRenderHandler'],
|
|
303
|
+
// },
|
|
304
|
+
// {
|
|
305
|
+
// from: 'nitropack/runtime/internal/meta',
|
|
306
|
+
// imports: ['defineRouteMeta'],
|
|
307
|
+
// },
|
|
308
|
+
// {
|
|
309
|
+
// from: 'nitropack/runtime/internal/route-rules',
|
|
310
|
+
// imports: ['getRouteRules'],
|
|
311
|
+
// },
|
|
312
|
+
// {
|
|
313
|
+
// from: 'nitropack/runtime/internal/context',
|
|
314
|
+
// imports: ['useEvent'],
|
|
315
|
+
// },
|
|
316
|
+
// {
|
|
317
|
+
// from: 'nitropack/runtime/internal/task',
|
|
318
|
+
// imports: ['defineTask', 'runTask'],
|
|
319
|
+
// },
|
|
320
|
+
// {
|
|
321
|
+
// from: 'nitropack/runtime/internal/error/utils',
|
|
322
|
+
// imports: ['defineNitroErrorHandler'],
|
|
323
|
+
// },
|
|
324
|
+
];
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
async function resolvePathOptions(options) {
|
|
328
|
+
options.rootDir = resolve(options.rootDir || ".");
|
|
329
|
+
options.workspaceDir = await findWorkspaceDir(options.rootDir).catch(
|
|
330
|
+
() => options.rootDir
|
|
331
|
+
);
|
|
332
|
+
options.srcDir = resolve(options.srcDir || options.rootDir);
|
|
333
|
+
for (const key of ["srcDir"]) {
|
|
334
|
+
options[key] = resolve(options.rootDir, options[key]);
|
|
335
|
+
}
|
|
336
|
+
options.build.dir = resolve(options.rootDir, options.build.dir);
|
|
337
|
+
options.build.typesDir = resolveSilgiPath(
|
|
338
|
+
options.build.typesDir || SilgiCLIDefaults.build.typesDir,
|
|
339
|
+
options,
|
|
340
|
+
options.rootDir
|
|
341
|
+
);
|
|
342
|
+
if (options.preset === "npm-package") {
|
|
343
|
+
const packageJsonPath = resolve(options.rootDir, "package.json");
|
|
344
|
+
const packageJson = await readPackageJSON(packageJsonPath);
|
|
345
|
+
if (packageJson.name === void 0) {
|
|
346
|
+
throw new Error("Package name is undefined");
|
|
347
|
+
}
|
|
348
|
+
options.alias ||= {};
|
|
349
|
+
options.alias[packageJson.name] = join(options.rootDir, "src/module");
|
|
350
|
+
options.alias[`${packageJson.name}/runtime/`] = join(options.rootDir, "src/runtime");
|
|
351
|
+
options.alias[`${packageJson.name}/runtime/*`] = join(options.rootDir, "src/runtime/*");
|
|
352
|
+
options.alias[`${packageJson.name}/types`] = join(options.rootDir, "src/types");
|
|
353
|
+
}
|
|
354
|
+
if (options.stub) {
|
|
355
|
+
options.alias = {
|
|
356
|
+
...options.alias,
|
|
357
|
+
"silgi/runtime": join(runtimeDir),
|
|
358
|
+
"#internal/silgi": join(runtimeDir),
|
|
359
|
+
"silgi/runtime/*": join(runtimeDir, "*"),
|
|
360
|
+
"#internal/silgi/*": join(runtimeDir, "*")
|
|
361
|
+
};
|
|
362
|
+
}
|
|
363
|
+
options.alias = {
|
|
364
|
+
...options.alias,
|
|
365
|
+
"~/": join(options.srcDir, "/"),
|
|
366
|
+
"@/": join(options.srcDir, "/"),
|
|
367
|
+
"~~/": join(options.rootDir, "/"),
|
|
368
|
+
"@@/": join(options.rootDir, "/")
|
|
369
|
+
};
|
|
370
|
+
if (options.preset === "npm-package") {
|
|
371
|
+
options.alias = {
|
|
372
|
+
...options.alias
|
|
373
|
+
// '#silgi/app/': join(options.build.dir, '/'),
|
|
374
|
+
};
|
|
375
|
+
}
|
|
376
|
+
if (options.alias && typeof options.alias === "object") {
|
|
377
|
+
((options.typescript.tsConfig ??= {}).compilerOptions ??= {}).paths ??= {};
|
|
378
|
+
const paths = options.typescript.tsConfig.compilerOptions.paths;
|
|
379
|
+
for (const [key, value] of Object.entries(options.alias)) {
|
|
380
|
+
if (typeof paths === "object") {
|
|
381
|
+
paths[key] = [value];
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
if (options.typescript.tsConfig.compilerOptions?.paths && typeof options.typescript.tsConfig.compilerOptions.paths === "object") {
|
|
386
|
+
((options.typescript.tsConfig ??= {}).compilerOptions ??= {}).paths ??= {};
|
|
387
|
+
const paths = options.typescript.tsConfig.compilerOptions.paths;
|
|
388
|
+
for (const [key, value] of Object.entries(options.alias)) {
|
|
389
|
+
if (typeof paths === "object") {
|
|
390
|
+
paths[key] = [value];
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
options.modulesDir = [resolve(options.rootDir, "node_modules")];
|
|
395
|
+
options.output.dir = resolveSilgiPath(
|
|
396
|
+
options.output.dir || SilgiCLIDefaults.output.dir,
|
|
397
|
+
options,
|
|
398
|
+
options.rootDir
|
|
399
|
+
);
|
|
400
|
+
options.output.publicDir = resolveSilgiPath(
|
|
401
|
+
options.output.publicDir || SilgiCLIDefaults.output.publicDir,
|
|
402
|
+
options,
|
|
403
|
+
options.rootDir
|
|
404
|
+
);
|
|
405
|
+
options.output.serverDir = resolveSilgiPath(
|
|
406
|
+
options.output.serverDir || SilgiCLIDefaults.output.serverDir,
|
|
407
|
+
options,
|
|
408
|
+
options.rootDir
|
|
409
|
+
);
|
|
410
|
+
options.serverDir = resolveSilgiPath(
|
|
411
|
+
options.serverDir || SilgiCLIDefaults.serverDir,
|
|
412
|
+
options,
|
|
413
|
+
options.rootDir
|
|
414
|
+
);
|
|
415
|
+
options.clientDir = resolveSilgiPath(
|
|
416
|
+
options.clientDir || SilgiCLIDefaults.clientDir,
|
|
417
|
+
options,
|
|
418
|
+
options.rootDir
|
|
419
|
+
);
|
|
420
|
+
options.silgi.serverDir = resolveSilgiPath(
|
|
421
|
+
options.silgi.serverDir || SilgiCLIDefaults.silgi.serverDir,
|
|
422
|
+
options,
|
|
423
|
+
options.rootDir
|
|
424
|
+
);
|
|
425
|
+
options.silgi.clientDir = resolveSilgiPath(
|
|
426
|
+
options.silgi.clientDir || SilgiCLIDefaults.silgi.clientDir,
|
|
427
|
+
options,
|
|
428
|
+
options.rootDir
|
|
429
|
+
);
|
|
430
|
+
options.silgi.publicDir = resolveSilgiPath(
|
|
431
|
+
options.silgi.publicDir || SilgiCLIDefaults.silgi.publicDir,
|
|
432
|
+
options,
|
|
433
|
+
options.rootDir
|
|
434
|
+
);
|
|
435
|
+
options.silgi.utilsDir = resolveSilgiPath(
|
|
436
|
+
options.silgi.utilsDir || SilgiCLIDefaults.silgi.utilsDir,
|
|
437
|
+
options,
|
|
438
|
+
options.rootDir
|
|
439
|
+
);
|
|
440
|
+
options.silgi.vfsDir = resolveSilgiPath(
|
|
441
|
+
options.silgi.vfsDir || SilgiCLIDefaults.silgi.vfsDir,
|
|
442
|
+
options,
|
|
443
|
+
options.rootDir
|
|
444
|
+
);
|
|
445
|
+
options.silgi.typesDir = resolveSilgiPath(
|
|
446
|
+
options.silgi.typesDir || SilgiCLIDefaults.silgi.typesDir,
|
|
447
|
+
options,
|
|
448
|
+
options.rootDir
|
|
449
|
+
);
|
|
450
|
+
options.nodeModulesDirs.push(resolve(options.workspaceDir, "node_modules"));
|
|
451
|
+
options.nodeModulesDirs.push(resolve(options.rootDir, "node_modules"));
|
|
452
|
+
options.nodeModulesDirs.push(resolve(pkgDir, "node_modules"));
|
|
453
|
+
options.nodeModulesDirs.push(resolve(pkgDir, ".."));
|
|
454
|
+
options.nodeModulesDirs = [
|
|
455
|
+
...new Set(
|
|
456
|
+
options.nodeModulesDirs.map((dir) => resolve(options.rootDir, dir))
|
|
457
|
+
)
|
|
458
|
+
];
|
|
459
|
+
options.scanDirs.unshift(options.srcDir);
|
|
460
|
+
options.scanDirs = options.scanDirs.map(
|
|
461
|
+
(dir) => resolve(options.srcDir, dir)
|
|
462
|
+
);
|
|
463
|
+
options.scanDirs = [...new Set(options.scanDirs)];
|
|
464
|
+
options.appConfigFiles ??= [];
|
|
465
|
+
options.appConfigFiles = options.appConfigFiles.map((file) => _tryResolve(resolveSilgiPath(file, options))).filter(Boolean);
|
|
466
|
+
for (const dir of options.scanDirs) {
|
|
467
|
+
const configFile = _tryResolve("app.config", dir);
|
|
468
|
+
if (configFile && !options.appConfigFiles.includes(configFile)) {
|
|
469
|
+
options.appConfigFiles.push(configFile);
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
function _tryResolve(path, base = ".", extensions = ["", ".js", ".ts", ".mjs", ".cjs", ".json"]) {
|
|
474
|
+
path = resolve(base, path);
|
|
475
|
+
if (existsSync(path)) {
|
|
476
|
+
return path;
|
|
477
|
+
}
|
|
478
|
+
for (const ext of extensions) {
|
|
479
|
+
const p = path + ext;
|
|
480
|
+
if (existsSync(p)) {
|
|
481
|
+
return p;
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
async function resolveStorageOptions(options) {
|
|
487
|
+
const fsMounts = {
|
|
488
|
+
root: resolve(options.rootDir),
|
|
489
|
+
src: resolve(options.srcDir),
|
|
490
|
+
build: resolve(options.build.dir),
|
|
491
|
+
cache: resolve(options.build.dir, "cache")
|
|
492
|
+
};
|
|
493
|
+
for (const p in fsMounts) {
|
|
494
|
+
options.devStorage[p] = options.devStorage[p] || {
|
|
495
|
+
driver: "fs",
|
|
496
|
+
readOnly: p === "root" || p === "src",
|
|
497
|
+
base: fsMounts[p]
|
|
498
|
+
};
|
|
499
|
+
}
|
|
500
|
+
if (options.dev && options.storage.data === void 0 && options.devStorage.data === void 0) {
|
|
501
|
+
options.devStorage.data = {
|
|
502
|
+
driver: "fs",
|
|
503
|
+
base: resolve(options.rootDir, ".data/kv")
|
|
504
|
+
};
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
async function resolveURLOptions(options) {
|
|
509
|
+
options.baseURL = withLeadingSlash(withTrailingSlash(options.baseURL));
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
const configResolvers = [
|
|
513
|
+
resolveCompatibilityOptions,
|
|
514
|
+
resolvePathOptions,
|
|
515
|
+
resolveImportsOptions,
|
|
516
|
+
// resolveRouteRulesOptions,
|
|
517
|
+
// resolveDatabaseOptions,
|
|
518
|
+
// resolveFetchOptions,
|
|
519
|
+
// resolveExportConditionsOptions,
|
|
520
|
+
// resolveRuntimeConfigOptions,
|
|
521
|
+
// resolveOpenAPIOptions,
|
|
522
|
+
resolveURLOptions,
|
|
523
|
+
// resolveAssetsOptions,
|
|
524
|
+
resolveStorageOptions
|
|
525
|
+
// resolveErrorOptions,
|
|
526
|
+
];
|
|
527
|
+
async function loadOptions(configOverrides = {}, opts = {}) {
|
|
528
|
+
const options = await _loadUserConfig(configOverrides, opts);
|
|
529
|
+
for (const resolver of configResolvers) {
|
|
530
|
+
await resolver(options);
|
|
531
|
+
}
|
|
532
|
+
return options;
|
|
533
|
+
}
|
|
534
|
+
async function _loadUserConfig(configOverrides = {}, opts = {}) {
|
|
535
|
+
const presetOverride = configOverrides.preset || process.env.SILGI_PRESET;
|
|
536
|
+
if (configOverrides.dev) ;
|
|
537
|
+
configOverrides = klona(configOverrides);
|
|
538
|
+
globalThis.defineSilgiConfig = globalThis.defineSilgiConfig || ((c) => c);
|
|
539
|
+
let compatibilityDate = configOverrides.compatibilityDate || opts.compatibilityDate || (process.env.SILGI_COMPATIBILITY_DATE || process.env.SERVER_COMPATIBILITY_DATE || process.env.COMPATIBILITY_DATE);
|
|
540
|
+
const { resolvePreset } = await import('silgi/presets');
|
|
541
|
+
const loadedConfig = await (opts.watch ? watchConfig : loadConfig)({
|
|
542
|
+
name: "silgi",
|
|
543
|
+
cwd: configOverrides.rootDir,
|
|
544
|
+
dotenv: configOverrides.dev,
|
|
545
|
+
extend: { extendKey: ["extends", "preset"] },
|
|
546
|
+
overrides: {
|
|
547
|
+
...configOverrides,
|
|
548
|
+
preset: presetOverride
|
|
549
|
+
},
|
|
550
|
+
async defaultConfig({ configs }) {
|
|
551
|
+
const getConf = (key) => configs.main?.[key] ?? configs.rc?.[key] ?? configs.packageJson?.[key];
|
|
552
|
+
if (!compatibilityDate) {
|
|
553
|
+
compatibilityDate = getConf("compatibilityDate");
|
|
554
|
+
}
|
|
555
|
+
return {
|
|
556
|
+
// typescript: {
|
|
557
|
+
// generateRuntimeConfigTypes:
|
|
558
|
+
// !framework?.name || framework.name === 'nitro',
|
|
559
|
+
// },
|
|
560
|
+
preset: presetOverride || (await resolvePreset("", {
|
|
561
|
+
static: getConf("static"),
|
|
562
|
+
compatibilityDate: compatibilityDate || fallbackCompatibilityDate
|
|
563
|
+
}))?._meta?.name
|
|
564
|
+
};
|
|
565
|
+
},
|
|
566
|
+
defaults: SilgiCLIDefaults,
|
|
567
|
+
jitiOptions: {
|
|
568
|
+
alias: {
|
|
569
|
+
"silgi/config": "silgi/config"
|
|
570
|
+
}
|
|
571
|
+
},
|
|
572
|
+
async resolve(id) {
|
|
573
|
+
const preset = await resolvePreset(id, {
|
|
574
|
+
static: configOverrides.static,
|
|
575
|
+
compatibilityDate: compatibilityDate || fallbackCompatibilityDate
|
|
576
|
+
});
|
|
577
|
+
if (preset) {
|
|
578
|
+
return {
|
|
579
|
+
config: klona(preset)
|
|
580
|
+
};
|
|
581
|
+
}
|
|
582
|
+
},
|
|
583
|
+
...opts.c12
|
|
584
|
+
});
|
|
585
|
+
delete globalThis.defineSilgiConfig;
|
|
586
|
+
const options = klona(loadedConfig.config);
|
|
587
|
+
options._config = configOverrides;
|
|
588
|
+
options._c12 = loadedConfig;
|
|
589
|
+
const _presetName = (loadedConfig.layers || []).find((l) => l.config?._meta?.name)?.config?._meta?.name || presetOverride;
|
|
590
|
+
options.preset = _presetName;
|
|
591
|
+
options.compatibilityDate = resolveCompatibilityDates(
|
|
592
|
+
compatibilityDate,
|
|
593
|
+
options.compatibilityDate
|
|
594
|
+
);
|
|
595
|
+
return options;
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
export { loadOptions as l };
|