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