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