silgi 0.7.57 → 0.8.0
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/index.mjs +1 -1
- package/dist/cli/common.mjs +13 -0
- package/dist/cli/config/index.mjs +2 -1
- package/dist/cli/index.mjs +2 -3
- package/dist/cli/loader.mjs +555 -0
- package/dist/cli/prepare.mjs +27 -18
- package/dist/cli/run.mjs +62 -0
- package/dist/cli/types.mjs +6 -554
- package/dist/kit/index.mjs +4 -4
- package/dist/meta/index.d.mts +1 -1
- package/dist/meta/index.d.ts +1 -1
- package/dist/types/index.d.mts +2 -4
- package/dist/types/index.d.ts +2 -4
- package/package.json +3 -1
package/dist/_chunks/index.mjs
CHANGED
package/dist/cli/index.mjs
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { defineCommand, runMain } from 'citty';
|
|
2
|
-
import consola from 'consola';
|
|
3
2
|
import { p as packageJson } from '../_chunks/index.mjs';
|
|
4
3
|
|
|
5
4
|
const main = defineCommand({
|
|
@@ -16,10 +15,10 @@ const main = defineCommand({
|
|
|
16
15
|
},
|
|
17
16
|
subCommands: {
|
|
18
17
|
prepare: () => import('./prepare.mjs').then((m) => m.default),
|
|
19
|
-
init: () => import('./init.mjs').then((m) => m.default)
|
|
18
|
+
init: () => import('./init.mjs').then((m) => m.default),
|
|
19
|
+
run: () => import('./run.mjs').then((m) => m.default)
|
|
20
20
|
},
|
|
21
21
|
run({ args }) {
|
|
22
|
-
consola.info("Silgi CLI , --help for more info");
|
|
23
22
|
if (args.version)
|
|
24
23
|
console.warn("Silgi version:", packageJson.version);
|
|
25
24
|
}
|
|
@@ -0,0 +1,555 @@
|
|
|
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
|
+
// Dirs
|
|
25
|
+
scanDirs: [],
|
|
26
|
+
build: {
|
|
27
|
+
dir: ".silgi",
|
|
28
|
+
typesDir: "{{ build.dir }}/types",
|
|
29
|
+
templates: []
|
|
30
|
+
},
|
|
31
|
+
output: {
|
|
32
|
+
dir: "{{ rootDir }}/.output",
|
|
33
|
+
serverDir: "{{ output.dir }}/server",
|
|
34
|
+
publicDir: "{{ output.dir }}/public"
|
|
35
|
+
},
|
|
36
|
+
serverDir: "{{ rootDir }}/server",
|
|
37
|
+
clientDir: "{{ rootDir }}/client",
|
|
38
|
+
silgi: {
|
|
39
|
+
serverDir: "{{ serverDir }}/silgi",
|
|
40
|
+
clientDir: "{{ clientDir }}/silgi",
|
|
41
|
+
publicDir: "{{ silgi.serverDir }}/public",
|
|
42
|
+
utilsDir: "{{ silgi.serverDir }}/utils",
|
|
43
|
+
vfsDir: "{{ silgi.serverDir }}/vfs",
|
|
44
|
+
typesDir: "{{ silgi.serverDir }}/types"
|
|
45
|
+
},
|
|
46
|
+
// Modules
|
|
47
|
+
_modules: [],
|
|
48
|
+
modules: [],
|
|
49
|
+
// Features
|
|
50
|
+
// experimental: {},
|
|
51
|
+
future: {},
|
|
52
|
+
storage: {},
|
|
53
|
+
devStorage: {},
|
|
54
|
+
stub: false,
|
|
55
|
+
// bundledStorage: [],
|
|
56
|
+
// publicAssets: [],
|
|
57
|
+
// serverAssets: [],
|
|
58
|
+
plugins: [],
|
|
59
|
+
// tasks: {},
|
|
60
|
+
// scheduledTasks: {},
|
|
61
|
+
imports: {
|
|
62
|
+
exclude: [],
|
|
63
|
+
dirs: [],
|
|
64
|
+
presets: [],
|
|
65
|
+
virtualImports: ["#silgiImports"]
|
|
66
|
+
},
|
|
67
|
+
// virtual: {},
|
|
68
|
+
// compressPublicAssets: false,
|
|
69
|
+
ignore: [],
|
|
70
|
+
// Dev
|
|
71
|
+
dev: false,
|
|
72
|
+
// devServer: { watch: [] },
|
|
73
|
+
watchOptions: { ignoreInitial: true },
|
|
74
|
+
// devProxy: {},
|
|
75
|
+
// Logging
|
|
76
|
+
// logging: {
|
|
77
|
+
// compressedSizes: true,
|
|
78
|
+
// buildSuccess: true,
|
|
79
|
+
// },
|
|
80
|
+
// Routing
|
|
81
|
+
// baseURL: process.env.NITRO_APP_BASE_URL || '/',
|
|
82
|
+
// handlers: [],
|
|
83
|
+
// devHandlers: [],
|
|
84
|
+
// errorHandler: undefined,
|
|
85
|
+
// routeRules: {},
|
|
86
|
+
// Advanced
|
|
87
|
+
typescript: {
|
|
88
|
+
strict: false,
|
|
89
|
+
generateTsConfig: true,
|
|
90
|
+
// generateRuntimeConfigTypes: true,
|
|
91
|
+
tsconfigPath: ".silgi/types/silgi.tsconfig.json",
|
|
92
|
+
tsConfig: {},
|
|
93
|
+
customConditions: []
|
|
94
|
+
},
|
|
95
|
+
conditions: [],
|
|
96
|
+
nodeModulesDirs: [],
|
|
97
|
+
// hooks: {},
|
|
98
|
+
commands: {},
|
|
99
|
+
// Framework
|
|
100
|
+
framework: {
|
|
101
|
+
name: "h3",
|
|
102
|
+
version: ""
|
|
103
|
+
},
|
|
104
|
+
extensions: [".js", ".jsx", ".mjs", ".ts", ".tsx", ".vue"],
|
|
105
|
+
ignoreOptions: void 0
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
const fallbackCompatibilityDate = "2025-02-04";
|
|
109
|
+
async function resolveCompatibilityOptions(options) {
|
|
110
|
+
options.compatibilityDate = resolveCompatibilityDatesFromEnv(
|
|
111
|
+
options.compatibilityDate
|
|
112
|
+
);
|
|
113
|
+
if (!options.compatibilityDate.default) {
|
|
114
|
+
options.compatibilityDate.default = await _resolveDefault(options);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
let _fallbackInfoShown = false;
|
|
118
|
+
let _promptedUserToUpdate = false;
|
|
119
|
+
async function _resolveDefault(options) {
|
|
120
|
+
const _todayDate = formatDate(/* @__PURE__ */ new Date());
|
|
121
|
+
const consola = _consola.withTag("silgi");
|
|
122
|
+
consola.warn(`No valid compatibility date is specified.`);
|
|
123
|
+
const onFallback = () => {
|
|
124
|
+
if (!_fallbackInfoShown) {
|
|
125
|
+
consola.info(
|
|
126
|
+
[
|
|
127
|
+
`Using \`${fallbackCompatibilityDate}\` as fallback.`,
|
|
128
|
+
` Please specify compatibility date to avoid unwanted behavior changes:`,
|
|
129
|
+
` - Add \`compatibilityDate: '${_todayDate}'\` to the config file.`,
|
|
130
|
+
` - Or set \`COMPATIBILITY_DATE=${_todayDate}\` environment variable.`,
|
|
131
|
+
``
|
|
132
|
+
].join("\n")
|
|
133
|
+
);
|
|
134
|
+
_fallbackInfoShown = true;
|
|
135
|
+
}
|
|
136
|
+
return fallbackCompatibilityDate;
|
|
137
|
+
};
|
|
138
|
+
const shallUpdate = !_promptedUserToUpdate && await consola.prompt(
|
|
139
|
+
`Do you want to auto update config file to set ${colors.cyan(`compatibilityDate: '${_todayDate}'`)}?`,
|
|
140
|
+
{
|
|
141
|
+
type: "confirm",
|
|
142
|
+
default: true
|
|
143
|
+
}
|
|
144
|
+
);
|
|
145
|
+
_promptedUserToUpdate = true;
|
|
146
|
+
if (!shallUpdate) {
|
|
147
|
+
return onFallback();
|
|
148
|
+
}
|
|
149
|
+
const { updateConfig } = await import('c12/update');
|
|
150
|
+
const updateResult = await updateConfig({
|
|
151
|
+
configFile: "silgi.config",
|
|
152
|
+
cwd: options.rootDir,
|
|
153
|
+
async onCreate({ configFile }) {
|
|
154
|
+
const shallCreate = await consola.prompt(
|
|
155
|
+
`Do you want to initialize a new config in ${colors.cyan(relative(".", configFile))}?`,
|
|
156
|
+
{
|
|
157
|
+
type: "confirm",
|
|
158
|
+
default: true
|
|
159
|
+
}
|
|
160
|
+
);
|
|
161
|
+
if (shallCreate !== true) {
|
|
162
|
+
return false;
|
|
163
|
+
}
|
|
164
|
+
return _getDefaultNitroConfig();
|
|
165
|
+
},
|
|
166
|
+
async onUpdate(config) {
|
|
167
|
+
config.compatibilityDate = _todayDate;
|
|
168
|
+
}
|
|
169
|
+
}).catch((error) => {
|
|
170
|
+
consola.error(`Failed to update config: ${error.message}`);
|
|
171
|
+
return null;
|
|
172
|
+
});
|
|
173
|
+
if (updateResult?.configFile) {
|
|
174
|
+
consola.success(
|
|
175
|
+
`Compatibility date set to \`${_todayDate}\` in \`${relative(".", updateResult.configFile)}\``
|
|
176
|
+
);
|
|
177
|
+
return _todayDate;
|
|
178
|
+
}
|
|
179
|
+
return onFallback();
|
|
180
|
+
}
|
|
181
|
+
function _getDefaultNitroConfig() {
|
|
182
|
+
return (
|
|
183
|
+
/* js */
|
|
184
|
+
`
|
|
185
|
+
import { defineSilgiConfig } from 'silgi/config'
|
|
186
|
+
|
|
187
|
+
export default defineSilgiConfig({})
|
|
188
|
+
`
|
|
189
|
+
);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
async function resolveImportsOptions(options) {
|
|
193
|
+
if (options.imports === false) {
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
options.imports.presets ??= [];
|
|
197
|
+
options.imports.presets.push(...getSilgiImportsPreset());
|
|
198
|
+
if (options.preset === "h3") {
|
|
199
|
+
const h3Exports = await resolveModuleExportNames("h3", {
|
|
200
|
+
url: import.meta.url
|
|
201
|
+
});
|
|
202
|
+
options.imports.presets ??= [];
|
|
203
|
+
options.imports.presets.push({
|
|
204
|
+
from: "h3",
|
|
205
|
+
imports: h3Exports.filter((n) => !/^[A-Z]/.test(n) && n !== "use")
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
options.imports.dirs ??= [];
|
|
209
|
+
options.imports.dirs.push(
|
|
210
|
+
...options.scanDirs.map((dir) => join(dir, "utils/**/*"))
|
|
211
|
+
);
|
|
212
|
+
if (Array.isArray(options.imports.exclude) && options.imports.exclude.length === 0) {
|
|
213
|
+
options.imports.exclude.push(/[/\\]\.git[/\\]/);
|
|
214
|
+
options.imports.exclude.push(options.build.dir);
|
|
215
|
+
const scanDirsInNodeModules = options.scanDirs.map((dir) => dir.match(/(?<=\/)node_modules\/(.+)$/)?.[1]).filter(Boolean);
|
|
216
|
+
options.imports.exclude.push(
|
|
217
|
+
scanDirsInNodeModules.length > 0 ? new RegExp(
|
|
218
|
+
`node_modules\\/(?!${scanDirsInNodeModules.map((dir) => escapeRE(dir)).join("|")})`
|
|
219
|
+
) : /[/\\]node_modules[/\\]/
|
|
220
|
+
);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
function getSilgiImportsPreset() {
|
|
224
|
+
return [
|
|
225
|
+
// TODO: buraya bizim importlarimiz gelecek.
|
|
226
|
+
{
|
|
227
|
+
from: "silgi",
|
|
228
|
+
imports: [
|
|
229
|
+
"createShared",
|
|
230
|
+
"useSilgi",
|
|
231
|
+
"createService",
|
|
232
|
+
"createSchema"
|
|
233
|
+
]
|
|
234
|
+
},
|
|
235
|
+
// {
|
|
236
|
+
// from: 'nitropack/runtime',
|
|
237
|
+
// imports: ['useRuntimeConfig', 'useAppConfig'],
|
|
238
|
+
// },
|
|
239
|
+
// {
|
|
240
|
+
// from: 'nitropack/runtime',
|
|
241
|
+
// imports: ['defineNitroPlugin', 'nitroPlugin'],
|
|
242
|
+
// },
|
|
243
|
+
// {
|
|
244
|
+
// from: 'nitropack/runtime/internal/cache',
|
|
245
|
+
// imports: [
|
|
246
|
+
// 'defineCachedFunction',
|
|
247
|
+
// 'defineCachedEventHandler',
|
|
248
|
+
// 'cachedFunction',
|
|
249
|
+
// 'cachedEventHandler',
|
|
250
|
+
// ],
|
|
251
|
+
// },
|
|
252
|
+
{
|
|
253
|
+
from: "silgi/core",
|
|
254
|
+
imports: ["useSilgiStorage"]
|
|
255
|
+
}
|
|
256
|
+
// {
|
|
257
|
+
// from: 'nitropack/runtime/internal/renderer',
|
|
258
|
+
// imports: ['defineRenderHandler'],
|
|
259
|
+
// },
|
|
260
|
+
// {
|
|
261
|
+
// from: 'nitropack/runtime/internal/meta',
|
|
262
|
+
// imports: ['defineRouteMeta'],
|
|
263
|
+
// },
|
|
264
|
+
// {
|
|
265
|
+
// from: 'nitropack/runtime/internal/route-rules',
|
|
266
|
+
// imports: ['getRouteRules'],
|
|
267
|
+
// },
|
|
268
|
+
// {
|
|
269
|
+
// from: 'nitropack/runtime/internal/context',
|
|
270
|
+
// imports: ['useEvent'],
|
|
271
|
+
// },
|
|
272
|
+
// {
|
|
273
|
+
// from: 'nitropack/runtime/internal/task',
|
|
274
|
+
// imports: ['defineTask', 'runTask'],
|
|
275
|
+
// },
|
|
276
|
+
// {
|
|
277
|
+
// from: 'nitropack/runtime/internal/error/utils',
|
|
278
|
+
// imports: ['defineNitroErrorHandler'],
|
|
279
|
+
// },
|
|
280
|
+
];
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
async function resolvePathOptions(options) {
|
|
284
|
+
options.rootDir = resolve(options.rootDir || ".");
|
|
285
|
+
options.workspaceDir = await findWorkspaceDir(options.rootDir).catch(
|
|
286
|
+
() => options.rootDir
|
|
287
|
+
);
|
|
288
|
+
options.srcDir = resolve(options.srcDir || options.rootDir);
|
|
289
|
+
for (const key of ["srcDir"]) {
|
|
290
|
+
options[key] = resolve(options.rootDir, options[key]);
|
|
291
|
+
}
|
|
292
|
+
options.build.dir = resolve(options.rootDir, options.build.dir);
|
|
293
|
+
options.build.typesDir = resolveSilgiPath(
|
|
294
|
+
options.build.typesDir || SilgiCLIDefaults.build.typesDir,
|
|
295
|
+
options,
|
|
296
|
+
options.rootDir
|
|
297
|
+
);
|
|
298
|
+
if (options.preset === "npm-package") {
|
|
299
|
+
const packageJsonPath = resolve(options.rootDir, "package.json");
|
|
300
|
+
const packageJson = await readPackageJSON(packageJsonPath);
|
|
301
|
+
if (packageJson.name === void 0) {
|
|
302
|
+
throw new Error("Package name is undefined");
|
|
303
|
+
}
|
|
304
|
+
options.alias ||= {};
|
|
305
|
+
options.alias[packageJson.name] = join(options.rootDir, "src/module");
|
|
306
|
+
options.alias[`${packageJson.name}/runtime/`] = join(options.rootDir, "src/runtime");
|
|
307
|
+
options.alias[`${packageJson.name}/runtime/*`] = join(options.rootDir, "src/runtime/*");
|
|
308
|
+
options.alias[`${packageJson.name}/types`] = join(options.rootDir, "src/types");
|
|
309
|
+
}
|
|
310
|
+
if (options.stub) {
|
|
311
|
+
options.alias = {
|
|
312
|
+
...options.alias,
|
|
313
|
+
"silgi/runtime": join(runtimeDir),
|
|
314
|
+
"#internal/silgi": join(runtimeDir),
|
|
315
|
+
"silgi/runtime/*": join(runtimeDir, "*"),
|
|
316
|
+
"#internal/silgi/*": join(runtimeDir, "*")
|
|
317
|
+
};
|
|
318
|
+
}
|
|
319
|
+
options.alias = {
|
|
320
|
+
...options.alias,
|
|
321
|
+
"~/": join(options.srcDir, "/"),
|
|
322
|
+
"@/": join(options.srcDir, "/"),
|
|
323
|
+
"~~/": join(options.rootDir, "/"),
|
|
324
|
+
"@@/": join(options.rootDir, "/")
|
|
325
|
+
};
|
|
326
|
+
if (options.preset === "npm-package") {
|
|
327
|
+
options.alias = {
|
|
328
|
+
...options.alias,
|
|
329
|
+
"#silgi/app/": join(options.build.dir, "/")
|
|
330
|
+
};
|
|
331
|
+
}
|
|
332
|
+
if (options.alias && typeof options.alias === "object") {
|
|
333
|
+
((options.typescript.tsConfig ??= {}).compilerOptions ??= {}).paths ??= {};
|
|
334
|
+
const paths = options.typescript.tsConfig.compilerOptions.paths;
|
|
335
|
+
for (const [key, value] of Object.entries(options.alias)) {
|
|
336
|
+
if (typeof paths === "object") {
|
|
337
|
+
paths[key] = [value];
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
if (options.typescript.tsConfig.compilerOptions?.paths && typeof options.typescript.tsConfig.compilerOptions.paths === "object") {
|
|
342
|
+
((options.typescript.tsConfig ??= {}).compilerOptions ??= {}).paths ??= {};
|
|
343
|
+
const paths = options.typescript.tsConfig.compilerOptions.paths;
|
|
344
|
+
for (const [key, value] of Object.entries(options.alias)) {
|
|
345
|
+
if (typeof paths === "object") {
|
|
346
|
+
paths[key] = [value];
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
options.modulesDir = [resolve(options.rootDir, "node_modules")];
|
|
351
|
+
options.output.dir = resolveSilgiPath(
|
|
352
|
+
options.output.dir || SilgiCLIDefaults.output.dir,
|
|
353
|
+
options,
|
|
354
|
+
options.rootDir
|
|
355
|
+
);
|
|
356
|
+
options.output.publicDir = resolveSilgiPath(
|
|
357
|
+
options.output.publicDir || SilgiCLIDefaults.output.publicDir,
|
|
358
|
+
options,
|
|
359
|
+
options.rootDir
|
|
360
|
+
);
|
|
361
|
+
options.output.serverDir = resolveSilgiPath(
|
|
362
|
+
options.output.serverDir || SilgiCLIDefaults.output.serverDir,
|
|
363
|
+
options,
|
|
364
|
+
options.rootDir
|
|
365
|
+
);
|
|
366
|
+
options.serverDir = resolveSilgiPath(
|
|
367
|
+
options.serverDir || SilgiCLIDefaults.serverDir,
|
|
368
|
+
options,
|
|
369
|
+
options.rootDir
|
|
370
|
+
);
|
|
371
|
+
options.clientDir = resolveSilgiPath(
|
|
372
|
+
options.clientDir || SilgiCLIDefaults.clientDir,
|
|
373
|
+
options,
|
|
374
|
+
options.rootDir
|
|
375
|
+
);
|
|
376
|
+
options.silgi.serverDir = resolveSilgiPath(
|
|
377
|
+
options.silgi.serverDir || SilgiCLIDefaults.silgi.serverDir,
|
|
378
|
+
options,
|
|
379
|
+
options.rootDir
|
|
380
|
+
);
|
|
381
|
+
options.silgi.clientDir = resolveSilgiPath(
|
|
382
|
+
options.silgi.clientDir || SilgiCLIDefaults.silgi.clientDir,
|
|
383
|
+
options,
|
|
384
|
+
options.rootDir
|
|
385
|
+
);
|
|
386
|
+
options.silgi.publicDir = resolveSilgiPath(
|
|
387
|
+
options.silgi.publicDir || SilgiCLIDefaults.silgi.publicDir,
|
|
388
|
+
options,
|
|
389
|
+
options.rootDir
|
|
390
|
+
);
|
|
391
|
+
options.silgi.utilsDir = resolveSilgiPath(
|
|
392
|
+
options.silgi.utilsDir || SilgiCLIDefaults.silgi.utilsDir,
|
|
393
|
+
options,
|
|
394
|
+
options.rootDir
|
|
395
|
+
);
|
|
396
|
+
options.silgi.vfsDir = resolveSilgiPath(
|
|
397
|
+
options.silgi.vfsDir || SilgiCLIDefaults.silgi.vfsDir,
|
|
398
|
+
options,
|
|
399
|
+
options.rootDir
|
|
400
|
+
);
|
|
401
|
+
options.silgi.typesDir = resolveSilgiPath(
|
|
402
|
+
options.silgi.typesDir || SilgiCLIDefaults.silgi.typesDir,
|
|
403
|
+
options,
|
|
404
|
+
options.rootDir
|
|
405
|
+
);
|
|
406
|
+
options.nodeModulesDirs.push(resolve(options.workspaceDir, "node_modules"));
|
|
407
|
+
options.nodeModulesDirs.push(resolve(options.rootDir, "node_modules"));
|
|
408
|
+
options.nodeModulesDirs.push(resolve(pkgDir, "node_modules"));
|
|
409
|
+
options.nodeModulesDirs.push(resolve(pkgDir, ".."));
|
|
410
|
+
options.nodeModulesDirs = [
|
|
411
|
+
...new Set(
|
|
412
|
+
options.nodeModulesDirs.map((dir) => resolve(options.rootDir, dir))
|
|
413
|
+
)
|
|
414
|
+
];
|
|
415
|
+
options.scanDirs.unshift(options.srcDir);
|
|
416
|
+
options.scanDirs = options.scanDirs.map(
|
|
417
|
+
(dir) => resolve(options.srcDir, dir)
|
|
418
|
+
);
|
|
419
|
+
options.scanDirs = [...new Set(options.scanDirs)];
|
|
420
|
+
options.appConfigFiles ??= [];
|
|
421
|
+
options.appConfigFiles = options.appConfigFiles.map((file) => _tryResolve(resolveSilgiPath(file, options))).filter(Boolean);
|
|
422
|
+
for (const dir of options.scanDirs) {
|
|
423
|
+
const configFile = _tryResolve("app.config", dir);
|
|
424
|
+
if (configFile && !options.appConfigFiles.includes(configFile)) {
|
|
425
|
+
options.appConfigFiles.push(configFile);
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
function _tryResolve(path, base = ".", extensions = ["", ".js", ".ts", ".mjs", ".cjs", ".json"]) {
|
|
430
|
+
path = resolve(base, path);
|
|
431
|
+
if (existsSync(path)) {
|
|
432
|
+
return path;
|
|
433
|
+
}
|
|
434
|
+
for (const ext of extensions) {
|
|
435
|
+
const p = path + ext;
|
|
436
|
+
if (existsSync(p)) {
|
|
437
|
+
return p;
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
async function resolveStorageOptions(options) {
|
|
443
|
+
const fsMounts = {
|
|
444
|
+
root: resolve(options.rootDir),
|
|
445
|
+
src: resolve(options.srcDir),
|
|
446
|
+
build: resolve(options.build.dir),
|
|
447
|
+
cache: resolve(options.build.dir, "cache")
|
|
448
|
+
};
|
|
449
|
+
for (const p in fsMounts) {
|
|
450
|
+
options.devStorage[p] = options.devStorage[p] || {
|
|
451
|
+
driver: "fs",
|
|
452
|
+
readOnly: p === "root" || p === "src",
|
|
453
|
+
base: fsMounts[p]
|
|
454
|
+
};
|
|
455
|
+
}
|
|
456
|
+
if (options.dev && options.storage.data === void 0 && options.devStorage.data === void 0) {
|
|
457
|
+
options.devStorage.data = {
|
|
458
|
+
driver: "fs",
|
|
459
|
+
base: resolve(options.rootDir, ".data/kv")
|
|
460
|
+
};
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
async function resolveURLOptions(options) {
|
|
465
|
+
options.baseURL = withLeadingSlash(withTrailingSlash(options.baseURL));
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
const configResolvers = [
|
|
469
|
+
resolveCompatibilityOptions,
|
|
470
|
+
resolvePathOptions,
|
|
471
|
+
resolveImportsOptions,
|
|
472
|
+
// resolveRouteRulesOptions,
|
|
473
|
+
// resolveDatabaseOptions,
|
|
474
|
+
// resolveFetchOptions,
|
|
475
|
+
// resolveExportConditionsOptions,
|
|
476
|
+
// resolveRuntimeConfigOptions,
|
|
477
|
+
// resolveOpenAPIOptions,
|
|
478
|
+
resolveURLOptions,
|
|
479
|
+
// resolveAssetsOptions,
|
|
480
|
+
resolveStorageOptions
|
|
481
|
+
// resolveErrorOptions,
|
|
482
|
+
];
|
|
483
|
+
async function loadOptions(configOverrides = {}, opts = {}) {
|
|
484
|
+
const options = await _loadUserConfig(configOverrides, opts);
|
|
485
|
+
for (const resolver of configResolvers) {
|
|
486
|
+
await resolver(options);
|
|
487
|
+
}
|
|
488
|
+
return options;
|
|
489
|
+
}
|
|
490
|
+
async function _loadUserConfig(configOverrides = {}, opts = {}) {
|
|
491
|
+
const presetOverride = configOverrides.preset || process.env.SILGI_PRESET;
|
|
492
|
+
if (configOverrides.dev) ;
|
|
493
|
+
configOverrides = klona(configOverrides);
|
|
494
|
+
globalThis.defineSilgiConfig = globalThis.defineSilgiConfig || ((c) => c);
|
|
495
|
+
let compatibilityDate = configOverrides.compatibilityDate || opts.compatibilityDate || (process.env.SILGI_COMPATIBILITY_DATE || process.env.SERVER_COMPATIBILITY_DATE || process.env.COMPATIBILITY_DATE);
|
|
496
|
+
const { resolvePreset } = await import('silgi/presets');
|
|
497
|
+
const loadedConfig = await (opts.watch ? watchConfig : loadConfig)({
|
|
498
|
+
name: "silgi",
|
|
499
|
+
cwd: configOverrides.rootDir,
|
|
500
|
+
dotenv: configOverrides.dev,
|
|
501
|
+
extend: { extendKey: ["extends", "preset"] },
|
|
502
|
+
overrides: {
|
|
503
|
+
...configOverrides,
|
|
504
|
+
preset: presetOverride
|
|
505
|
+
},
|
|
506
|
+
async defaultConfig({ configs }) {
|
|
507
|
+
const getConf = (key) => configs.main?.[key] ?? configs.rc?.[key] ?? configs.packageJson?.[key];
|
|
508
|
+
if (!compatibilityDate) {
|
|
509
|
+
compatibilityDate = getConf("compatibilityDate");
|
|
510
|
+
}
|
|
511
|
+
return {
|
|
512
|
+
// typescript: {
|
|
513
|
+
// generateRuntimeConfigTypes:
|
|
514
|
+
// !framework?.name || framework.name === 'nitro',
|
|
515
|
+
// },
|
|
516
|
+
preset: presetOverride || (await resolvePreset("", {
|
|
517
|
+
static: getConf("static"),
|
|
518
|
+
compatibilityDate: compatibilityDate || fallbackCompatibilityDate
|
|
519
|
+
}))?._meta?.name
|
|
520
|
+
};
|
|
521
|
+
},
|
|
522
|
+
defaults: SilgiCLIDefaults,
|
|
523
|
+
jitiOptions: {
|
|
524
|
+
alias: {
|
|
525
|
+
"silgi": "silgi/config",
|
|
526
|
+
"silgi/config": "silgi/config"
|
|
527
|
+
}
|
|
528
|
+
},
|
|
529
|
+
async resolve(id) {
|
|
530
|
+
const preset = await resolvePreset(id, {
|
|
531
|
+
static: configOverrides.static,
|
|
532
|
+
compatibilityDate: compatibilityDate || fallbackCompatibilityDate
|
|
533
|
+
});
|
|
534
|
+
if (preset) {
|
|
535
|
+
return {
|
|
536
|
+
config: klona(preset)
|
|
537
|
+
};
|
|
538
|
+
}
|
|
539
|
+
},
|
|
540
|
+
...opts.c12
|
|
541
|
+
});
|
|
542
|
+
delete globalThis.defineSilgiConfig;
|
|
543
|
+
const options = klona(loadedConfig.config);
|
|
544
|
+
options._config = configOverrides;
|
|
545
|
+
options._c12 = loadedConfig;
|
|
546
|
+
const _presetName = (loadedConfig.layers || []).find((l) => l.config?._meta?.name)?.config?._meta?.name || presetOverride;
|
|
547
|
+
options.preset = _presetName;
|
|
548
|
+
options.compatibilityDate = resolveCompatibilityDates(
|
|
549
|
+
compatibilityDate,
|
|
550
|
+
options.compatibilityDate
|
|
551
|
+
);
|
|
552
|
+
return options;
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
export { loadOptions as l };
|
package/dist/cli/prepare.mjs
CHANGED
|
@@ -6,12 +6,13 @@ import { promises, existsSync, readFileSync, writeFileSync, mkdirSync } from 'no
|
|
|
6
6
|
import { readdir } from 'node:fs/promises';
|
|
7
7
|
import { resolvePath, parseNodeModulePath, lookupNodeModuleSubpath, resolve as resolve$1 } from 'mlly';
|
|
8
8
|
import { resolveAlias } from 'pathe/utils';
|
|
9
|
-
import { relativeWithDot, isDirectory, writeFile, resolveAlias as resolveAlias$1, resolvePath as resolvePath$1, normalizeTemplate, useLogger } from 'silgi/kit';
|
|
9
|
+
import { relativeWithDot, isDirectory, writeFile, resolveAlias as resolveAlias$1, resolvePath as resolvePath$1, normalizeTemplate, useLogger, addTemplate } from 'silgi/kit';
|
|
10
10
|
import { toExports, scanExports, createUnimport } from 'unimport';
|
|
11
11
|
import { createJiti } from 'dev-jiti';
|
|
12
12
|
import { readPackageJSON } from 'pkg-types';
|
|
13
13
|
import { hash } from 'ohash';
|
|
14
|
-
import { s as silgiGenerateType
|
|
14
|
+
import { s as silgiGenerateType } from './types.mjs';
|
|
15
|
+
import { c as commonArgs } from './common.mjs';
|
|
15
16
|
import { consola } from 'consola';
|
|
16
17
|
import { createHooks, createDebugger } from 'hookable';
|
|
17
18
|
import { useSilgiCLI, silgiCLICtx } from 'silgi/core';
|
|
@@ -24,14 +25,15 @@ import ignore from 'ignore';
|
|
|
24
25
|
import { parseSync } from '@oxc-parser/wasm';
|
|
25
26
|
import { klona } from 'klona';
|
|
26
27
|
import { createStorage, builtinDrivers } from 'unstorage';
|
|
28
|
+
import { l as loadOptions } from './loader.mjs';
|
|
29
|
+
import 'defu';
|
|
30
|
+
import 'semver/functions/satisfies.js';
|
|
27
31
|
import 'c12';
|
|
28
32
|
import 'compatx';
|
|
29
33
|
import 'klona/full';
|
|
30
34
|
import 'std-env';
|
|
31
35
|
import 'consola/utils';
|
|
32
36
|
import 'escape-string-regexp';
|
|
33
|
-
import 'defu';
|
|
34
|
-
import 'semver/functions/satisfies.js';
|
|
35
37
|
|
|
36
38
|
async function h3Framework(silgi, skip = false) {
|
|
37
39
|
if (silgi.options.preset !== "h3" && skip === false)
|
|
@@ -822,18 +824,6 @@ async function writeTypesAndFiles(silgi) {
|
|
|
822
824
|
await silgi.hooks.callHook("finish:types", readCore);
|
|
823
825
|
}
|
|
824
826
|
|
|
825
|
-
const commonArgs = {
|
|
826
|
-
dir: {
|
|
827
|
-
type: "string",
|
|
828
|
-
description: "project root directory"
|
|
829
|
-
},
|
|
830
|
-
_dir: {
|
|
831
|
-
type: "positional",
|
|
832
|
-
default: ".",
|
|
833
|
-
description: "project root directory (prefer using `--dir`)"
|
|
834
|
-
}
|
|
835
|
-
};
|
|
836
|
-
|
|
837
827
|
async function registerModuleExportScan(silgi) {
|
|
838
828
|
silgi.hook("prepare:schema.ts", async (options) => {
|
|
839
829
|
for (const module of silgi.scanModules) {
|
|
@@ -1430,7 +1420,8 @@ async function createStorageCLI(silgi) {
|
|
|
1430
1420
|
}
|
|
1431
1421
|
|
|
1432
1422
|
const vueShim = {
|
|
1433
|
-
filename: "
|
|
1423
|
+
filename: "delete/testtest.d.ts",
|
|
1424
|
+
where: ".silgi",
|
|
1434
1425
|
getContents: ({ app }) => {
|
|
1435
1426
|
if (!app.options.typescript.shim) {
|
|
1436
1427
|
return "";
|
|
@@ -1445,7 +1436,8 @@ const vueShim = {
|
|
|
1445
1436
|
}
|
|
1446
1437
|
};
|
|
1447
1438
|
const pluginsDeclaration = {
|
|
1448
|
-
filename: "
|
|
1439
|
+
filename: "delete/testtest1.d.ts",
|
|
1440
|
+
where: ".silgi",
|
|
1449
1441
|
getContents: async () => {
|
|
1450
1442
|
return `
|
|
1451
1443
|
declare module 'nuxt' {
|
|
@@ -1543,6 +1535,22 @@ async function compileTemplate(template, ctx) {
|
|
|
1543
1535
|
throw new Error(`[nuxt] Invalid template. Templates must have either \`src\` or \`getContents\`: ${JSON.stringify(template)}`);
|
|
1544
1536
|
}
|
|
1545
1537
|
|
|
1538
|
+
async function commands(silgi) {
|
|
1539
|
+
const commands2 = {
|
|
1540
|
+
module1: {
|
|
1541
|
+
dev: 'echo "module dev"',
|
|
1542
|
+
build: 'echo "module build"'
|
|
1543
|
+
}
|
|
1544
|
+
};
|
|
1545
|
+
await silgi.callHook("prepare:commands", commands2);
|
|
1546
|
+
addTemplate({
|
|
1547
|
+
filename: "cli.json",
|
|
1548
|
+
where: ".silgi",
|
|
1549
|
+
write: true,
|
|
1550
|
+
getContents: () => JSON.stringify(commands2, null, 2)
|
|
1551
|
+
});
|
|
1552
|
+
}
|
|
1553
|
+
|
|
1546
1554
|
const GLOB_SCAN_PATTERN = "**/*.{js,mjs,cjs,ts,mts,cts,tsx,jsx}";
|
|
1547
1555
|
async function scanAndSyncOptions(silgi) {
|
|
1548
1556
|
const scannedModules = await scanModules(silgi);
|
|
@@ -1631,6 +1639,7 @@ async function createSilgiCLI(config = {}, opts = {}) {
|
|
|
1631
1639
|
silgi.hooks.addHooks(silgi.options.hooks);
|
|
1632
1640
|
await installModules(silgi);
|
|
1633
1641
|
await silgi.hooks.callHook("scanFiles:done", silgi);
|
|
1642
|
+
await commands(silgi);
|
|
1634
1643
|
await generateApp(silgi);
|
|
1635
1644
|
if (silgi.options.imports) {
|
|
1636
1645
|
silgi.unimport = createUnimport(silgi.options.imports);
|