silgi 0.42.5 → 0.43.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/_virtual/rolldown_runtime.mjs +11 -0
- package/dist/build.d.mts +3 -11
- package/dist/build.mjs +4 -48
- package/dist/cli/build/build.mjs +17 -0
- package/dist/cli/build/dev.d.mts +9 -0
- package/dist/cli/build/dev.mjs +59 -0
- package/dist/cli/build/prepare.d.mts +6 -0
- package/dist/cli/build/prepare.mjs +15 -0
- package/dist/cli/commands/commands.mjs +90 -0
- package/dist/cli/commands/env.mjs +53 -0
- package/dist/cli/commands/init.mjs +84 -0
- package/dist/cli/commands/install.mjs +52 -0
- package/dist/cli/commands/prepare.mjs +65 -0
- package/dist/cli/commands/reset.mjs +46 -0
- package/dist/cli/commands/run.mjs +105 -0
- package/dist/cli/commands/watch.mjs +48 -0
- package/dist/cli/config/defaults.mjs +117 -0
- package/dist/cli/config/index.d.mts +3 -11
- package/dist/cli/config/index.mjs +4 -17
- package/dist/cli/config/loader.d.mts +6 -0
- package/dist/cli/config/loader.mjs +71 -0
- package/dist/cli/config/resolvers/compatibility.mjs +71 -0
- package/dist/cli/config/resolvers/imports.mjs +35 -0
- package/dist/cli/config/resolvers/paths.mjs +98 -0
- package/dist/cli/config/resolvers/storage.mjs +23 -0
- package/dist/cli/config/resolvers/url.mjs +9 -0
- package/dist/cli/config/types.d.mts +14 -0
- package/dist/cli/config/types.mjs +147 -0
- package/dist/cli/core/apiful.mjs +36 -0
- package/dist/cli/core/app.mjs +105 -0
- package/dist/cli/core/devServer.mjs +10 -0
- package/dist/cli/core/env.mjs +68 -0
- package/dist/cli/core/installPackage.mjs +60 -0
- package/dist/cli/core/runtimeConfig.mjs +70 -0
- package/dist/cli/core/scan.mjs +35 -0
- package/dist/cli/core/silgi.mjs +111 -0
- package/dist/cli/core/templates.mjs +38 -0
- package/dist/cli/framework/emptyFramework.mjs +7 -0
- package/dist/cli/framework/h3.mjs +55 -0
- package/dist/cli/framework/index.mjs +15 -0
- package/dist/cli/framework/nitro.mjs +24 -0
- package/dist/cli/framework/nuxt.mjs +10 -0
- package/dist/cli/index.d.mts +1 -1
- package/dist/cli/index.mjs +24 -27
- package/dist/cli/module/exportScan.mjs +180 -0
- package/dist/cli/module/install.mjs +49 -0
- package/dist/cli/module/scan.mjs +195 -0
- package/dist/cli/scan/prepareCommands.mjs +40 -0
- package/dist/cli/scan/prepareConfigs.mjs +33 -0
- package/dist/cli/scan/prepareCoreFile.mjs +118 -0
- package/dist/cli/scan/prepareScanFile.mjs +59 -0
- package/dist/cli/scan/prepareSchema.mjs +140 -0
- package/dist/cli/scan/scanExportFile.mjs +312 -0
- package/dist/cli/scan/writeCoreFile.mjs +22 -0
- package/dist/cli/scan/writeTypesAndFiles.mjs +72 -0
- package/dist/cli/utils/cancel.mjs +14 -0
- package/dist/cli/utils/common.mjs +15 -0
- package/dist/cli/utils/compatibility.mjs +33 -0
- package/dist/cli/utils/debug.mjs +11 -0
- package/dist/cli/utils/ignore.mjs +56 -0
- package/dist/cli/utils/readScanFile.mjs +58 -0
- package/dist/cli/utils/storage.mjs +23 -0
- package/dist/core/context.d.mts +30 -0
- package/dist/core/context.mjs +32 -0
- package/dist/core/createSilgi.d.mts +6 -0
- package/dist/core/createSilgi.mjs +152 -0
- package/dist/core/error.d.mts +65 -0
- package/dist/core/error.mjs +106 -0
- package/dist/core/event.d.mts +26 -0
- package/dist/core/event.mjs +44 -0
- package/dist/core/index.d.mts +24 -316
- package/dist/core/index.mjs +27 -1345
- package/dist/core/orchestrate.mjs +113 -0
- package/dist/core/response.d.mts +20 -0
- package/dist/core/response.mjs +105 -0
- package/dist/core/silgi.d.mts +19 -0
- package/dist/core/silgi.mjs +141 -0
- package/dist/core/silgiApp.d.mts +9 -0
- package/dist/core/silgiApp.mjs +23 -0
- package/dist/core/storage.d.mts +7 -0
- package/dist/core/storage.mjs +15 -0
- package/dist/core/unctx.d.mts +21 -0
- package/dist/core/unctx.mjs +35 -0
- package/dist/core/utils/event-stream.d.mts +53 -0
- package/dist/core/utils/event-stream.mjs +38 -0
- package/dist/core/utils/event.d.mts +8 -0
- package/dist/core/utils/event.mjs +12 -0
- package/dist/core/utils/internal/event-stream.d.mts +45 -0
- package/dist/core/utils/internal/event-stream.mjs +137 -0
- package/dist/core/utils/internal/obj.mjs +9 -0
- package/dist/core/utils/internal/object.mjs +29 -0
- package/dist/core/utils/internal/query.mjs +73 -0
- package/dist/core/utils/internal/req.mjs +35 -0
- package/dist/core/utils/merge.d.mts +14 -0
- package/dist/core/utils/merge.mjs +27 -0
- package/dist/{shared/silgi.DTwQEdSr.d.mts → core/utils/middleware.d.mts} +11 -13
- package/dist/core/utils/middleware.mjs +12 -0
- package/dist/core/utils/request.mjs +35 -0
- package/dist/core/utils/resolver.d.mts +7 -0
- package/dist/core/utils/resolver.mjs +29 -0
- package/dist/core/utils/runtime.d.mts +7 -0
- package/dist/core/utils/runtime.mjs +20 -0
- package/dist/core/utils/sanitize.mjs +22 -0
- package/dist/core/utils/schema.d.mts +34 -0
- package/dist/core/utils/schema.mjs +33 -0
- package/dist/core/utils/service.d.mts +13 -0
- package/dist/core/utils/service.mjs +19 -0
- package/dist/core/utils/shared.d.mts +6 -0
- package/dist/core/utils/shared.mjs +7 -0
- package/dist/core/utils/storage.d.mts +24 -0
- package/dist/core/utils/storage.mjs +54 -0
- package/dist/index.d.mts +21 -6
- package/dist/index.mjs +22 -16
- package/dist/kit/add/add-commands.d.mts +6 -0
- package/dist/kit/add/add-commands.mjs +12 -0
- package/dist/kit/add/add-core-file.d.mts +9 -0
- package/dist/kit/add/add-core-file.mjs +11 -0
- package/dist/kit/add/add-imports.d.mts +14 -0
- package/dist/kit/add/add-imports.mjs +56 -0
- package/dist/kit/add/add-npm.d.mts +14 -0
- package/dist/kit/add/add-npm.mjs +23 -0
- package/dist/kit/define.d.mts +28 -0
- package/dist/kit/define.mjs +25 -0
- package/dist/kit/errors.d.mts +6 -0
- package/dist/kit/errors.mjs +11 -0
- package/dist/kit/esm.d.mts +11 -0
- package/dist/kit/esm.mjs +21 -0
- package/dist/kit/fs.d.mts +7 -0
- package/dist/kit/fs.mjs +23 -0
- package/dist/kit/function-utils.d.mts +27 -0
- package/dist/kit/function-utils.mjs +75 -0
- package/dist/kit/gen.d.mts +5 -0
- package/dist/kit/gen.mjs +26 -0
- package/dist/kit/hash.d.mts +4 -0
- package/dist/kit/hash.mjs +10 -0
- package/dist/kit/index.d.mts +22 -321
- package/dist/kit/index.mjs +23 -1039
- package/dist/kit/isFramework.d.mts +6 -0
- package/dist/kit/isFramework.mjs +21 -0
- package/dist/kit/logger.d.mts +6 -0
- package/dist/kit/logger.mjs +10 -0
- package/dist/kit/migration.d.mts +113 -0
- package/dist/kit/migration.mjs +301 -0
- package/dist/kit/module.d.mts +14 -0
- package/dist/kit/module.mjs +53 -0
- package/dist/kit/path.d.mts +7 -0
- package/dist/kit/path.mjs +26 -0
- package/dist/kit/preset.d.mts +8 -0
- package/dist/kit/preset.mjs +11 -0
- package/dist/kit/resolve.d.mts +37 -0
- package/dist/kit/resolve.mjs +82 -0
- package/dist/kit/template.d.mts +14 -0
- package/dist/kit/template.mjs +59 -0
- package/dist/kit/useRequest.d.mts +19 -0
- package/dist/kit/useRequest.mjs +63 -0
- package/dist/kit/utils.d.mts +34 -0
- package/dist/kit/utils.mjs +90 -0
- package/dist/package.mjs +176 -0
- package/dist/presets/_all.gen.d.mts +5 -2
- package/dist/presets/_all.gen.mjs +16 -13
- package/dist/presets/_resolve.d.mts +10 -6
- package/dist/presets/_resolve.mjs +51 -65
- package/dist/presets/_types.gen.d.mts +8 -5
- package/dist/presets/_types.gen.mjs +5 -1
- package/dist/presets/h3/preset.d.mts +5 -2
- package/dist/presets/h3/preset.mjs +33 -38
- package/dist/presets/hono/preset.d.mts +5 -2
- package/dist/presets/hono/preset.mjs +28 -35
- package/dist/presets/index.d.mts +3 -2
- package/dist/presets/index.mjs +3 -1
- package/dist/presets/nitro/preset.d.mts +5 -2
- package/dist/presets/nitro/preset.mjs +35 -42
- package/dist/presets/npmpackage/preset.d.mts +5 -2
- package/dist/presets/npmpackage/preset.mjs +27 -32
- package/dist/presets/nuxt/preset.d.mts +5 -2
- package/dist/presets/nuxt/preset.mjs +39 -44
- package/dist/runtime/index.d.mts +4 -3
- package/dist/runtime/index.mjs +5 -3
- package/dist/runtime/internal/config.d.mts +11 -7
- package/dist/runtime/internal/config.mjs +79 -90
- package/dist/runtime/internal/debug.d.mts +6 -3
- package/dist/runtime/internal/debug.mjs +9 -4
- package/dist/runtime/internal/defu.d.mts +4 -1
- package/dist/runtime/internal/defu.mjs +7 -2
- package/dist/runtime/internal/index.d.mts +7 -6
- package/dist/runtime/internal/index.mjs +8 -20
- package/dist/runtime/internal/nitro.d.mts +6 -3
- package/dist/runtime/internal/nitro.mjs +29 -37
- package/dist/runtime/internal/nuxt.d.mts +12 -8
- package/dist/runtime/internal/nuxt.mjs +12 -7
- package/dist/runtime/internal/ofetch.d.mts +8 -4
- package/dist/runtime/internal/ofetch.mjs +33 -34
- package/dist/runtime/internal/plugin.d.mts +7 -3
- package/dist/runtime/internal/plugin.mjs +7 -3
- package/dist/types/cliConfig.d.mts +288 -0
- package/dist/types/cliConfig.mjs +0 -0
- package/dist/types/cliHooks.d.mts +154 -0
- package/dist/types/cliHooks.mjs +0 -0
- package/dist/types/compatibility.d.mts +13 -0
- package/dist/types/compatibility.mjs +0 -0
- package/dist/types/config.d.mts +46 -0
- package/dist/types/config.mjs +0 -0
- package/dist/types/dotenv.d.mts +29 -0
- package/dist/types/dotenv.mjs +0 -0
- package/dist/types/event.d.mts +63 -0
- package/dist/types/event.mjs +0 -0
- package/dist/types/global.d.mts +24 -0
- package/dist/types/global.mjs +0 -0
- package/dist/types/helper.d.mts +25 -0
- package/dist/types/helper.mjs +0 -0
- package/dist/types/hooks.d.mts +37 -0
- package/dist/types/hooks.mjs +0 -0
- package/dist/types/index.d.mts +26 -1306
- package/dist/types/index.mjs +0 -1
- package/dist/types/kits.d.mts +32 -0
- package/dist/types/kits.mjs +0 -0
- package/dist/types/middleware.d.mts +31 -0
- package/dist/types/middleware.mjs +0 -0
- package/dist/types/module.d.mts +102 -0
- package/dist/types/module.mjs +0 -0
- package/dist/types/preset.d.mts +20 -0
- package/dist/types/preset.mjs +0 -0
- package/dist/types/route.d.mts +59 -0
- package/dist/types/route.mjs +0 -0
- package/dist/types/runtime/index.d.mts +5 -0
- package/dist/types/runtime/index.mjs +0 -0
- package/dist/types/runtime/nuxt.d.mts +13 -0
- package/dist/types/runtime/nuxt.mjs +0 -0
- package/dist/types/runtime/ofetch.d.mts +14 -0
- package/dist/types/runtime/ofetch.mjs +0 -0
- package/dist/types/runtime/plugin.d.mts +8 -0
- package/dist/types/runtime/plugin.mjs +0 -0
- package/dist/types/runtime/silgi.d.mts +11 -0
- package/dist/types/runtime/silgi.mjs +0 -0
- package/dist/types/schema.d.mts +86 -0
- package/dist/types/schema.mjs +0 -0
- package/dist/types/service.d.mts +102 -0
- package/dist/types/service.mjs +0 -0
- package/dist/types/shared.d.mts +19 -0
- package/dist/types/shared.mjs +0 -0
- package/dist/types/silgi.d.mts +71 -0
- package/dist/types/silgi.mjs +0 -0
- package/dist/types/silgiCLI.d.mts +118 -0
- package/dist/types/silgiCLI.mjs +0 -0
- package/dist/types/standard-schema.d.mts +61 -0
- package/dist/types/standard-schema.mjs +0 -0
- package/dist/types/storage.d.mts +30 -0
- package/dist/types/storage.mjs +0 -0
- package/package.json +20 -35
- package/dist/_chunks/silgiApp.mjs +0 -25
- package/dist/cli/build.mjs +0 -2190
- package/dist/cli/common.mjs +0 -13
- package/dist/cli/compatibility.mjs +0 -30
- package/dist/cli/dev.mjs +0 -67
- package/dist/cli/init.mjs +0 -112
- package/dist/cli/install.mjs +0 -151
- package/dist/cli/loader.mjs +0 -618
- package/dist/cli/prepare.mjs +0 -188
- package/dist/cli/reset.mjs +0 -55
- package/dist/cli/run.mjs +0 -159
- package/dist/cli/types.mjs +0 -232
- package/dist/cli/watch.mjs +0 -91
- package/dist/presets/next/preset.d.mts +0 -3
- package/dist/presets/next/preset.mjs +0 -38
- package/dist/runtime/internal/next.d.mts +0 -9
- package/dist/runtime/internal/next.mjs +0 -22
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { dirname, isAbsolute, join, relative, resolve } from "pathe";
|
|
2
|
+
import { isPresents, relativeWithDot, resolveSilgiModule } from "silgi/kit";
|
|
3
|
+
import { existsSync, lstatSync, promises } from "node:fs";
|
|
4
|
+
import { readPackageJSON } from "pkg-types";
|
|
5
|
+
import { withTrailingSlash } from "ufo";
|
|
6
|
+
import { defu } from "defu";
|
|
7
|
+
|
|
8
|
+
//#region src/cli/config/types.ts
|
|
9
|
+
function getDirectory(p) {
|
|
10
|
+
try {
|
|
11
|
+
return isAbsolute(p) && lstatSync(p).isFile() ? dirname(p) : p;
|
|
12
|
+
} catch {}
|
|
13
|
+
return p;
|
|
14
|
+
}
|
|
15
|
+
function renderAttrs(obj) {
|
|
16
|
+
const attrs = [];
|
|
17
|
+
for (const key in obj) attrs.push(renderAttr(key, obj[key]));
|
|
18
|
+
return attrs.join(" ");
|
|
19
|
+
}
|
|
20
|
+
function renderAttr(key, value) {
|
|
21
|
+
return value ? `${key}="${value}"` : "";
|
|
22
|
+
}
|
|
23
|
+
async function silgiGenerateType(silgi) {
|
|
24
|
+
const rootDirWithSlash = withTrailingSlash(silgi.options.rootDir);
|
|
25
|
+
const tsConfigPath = resolve(silgi.options.rootDir, silgi.options.typescript.tsconfigPath);
|
|
26
|
+
const tsconfigDir = dirname(tsConfigPath);
|
|
27
|
+
const include = new Set([
|
|
28
|
+
relativeWithDot(tsconfigDir, join(silgi.options.build.typesDir, "silgi-config.d.ts")).replace(/^(?=[^.])/, "./"),
|
|
29
|
+
join(relativeWithDot(tsconfigDir, silgi.options.rootDir), "**/*"),
|
|
30
|
+
...silgi.options.srcDir === silgi.options.rootDir ? [] : [join(relativeWithDot(tsconfigDir, silgi.options.srcDir), "**/*")]
|
|
31
|
+
]);
|
|
32
|
+
const exclude = new Set([relativeWithDot(tsconfigDir, "node_modules"), relativeWithDot(tsconfigDir, "dist")]);
|
|
33
|
+
for (const dir of silgi.options.modulesDir) exclude.add(relativeWithDot(silgi.options.build.dir, dir));
|
|
34
|
+
const moduleEntryPaths = [];
|
|
35
|
+
for (const m of silgi.scanModules) if (m.entryPath) moduleEntryPaths.push(getDirectory(m.entryPath));
|
|
36
|
+
const modulePaths = await resolveSilgiModule(rootDirWithSlash, moduleEntryPaths);
|
|
37
|
+
for (const path of modulePaths) {
|
|
38
|
+
const relative$1 = relativeWithDot(tsconfigDir, path);
|
|
39
|
+
include.add(join(relative$1, "runtime"));
|
|
40
|
+
exclude.add(join(relative$1, "runtime/server"));
|
|
41
|
+
include.add(join(relative$1, "dist/runtime"));
|
|
42
|
+
exclude.add(join(relative$1, "dist/runtime/server"));
|
|
43
|
+
}
|
|
44
|
+
let tsConfig = silgi.options.typescript?.tsConfig || {};
|
|
45
|
+
const defaultConfig = defu(tsConfig, {
|
|
46
|
+
compilerOptions: {
|
|
47
|
+
esModuleInterop: true,
|
|
48
|
+
allowSyntheticDefaultImports: true,
|
|
49
|
+
skipLibCheck: true,
|
|
50
|
+
allowImportingTsExtensions: true,
|
|
51
|
+
target: "ESNext",
|
|
52
|
+
allowJs: true,
|
|
53
|
+
resolveJsonModule: true,
|
|
54
|
+
moduleDetection: "force",
|
|
55
|
+
isolatedModules: true,
|
|
56
|
+
verbatimModuleSyntax: true,
|
|
57
|
+
strict: true,
|
|
58
|
+
noUncheckedIndexedAccess: true,
|
|
59
|
+
noImplicitOverride: true,
|
|
60
|
+
forceConsistentCasingInFileNames: true,
|
|
61
|
+
noEmit: true,
|
|
62
|
+
module: "Preserve",
|
|
63
|
+
moduleResolution: "bundler",
|
|
64
|
+
useDefineForClassFields: true,
|
|
65
|
+
noImplicitThis: true,
|
|
66
|
+
jsx: "preserve",
|
|
67
|
+
customConditions: silgi.options.typescript.customConditions,
|
|
68
|
+
paths: {}
|
|
69
|
+
},
|
|
70
|
+
include: [...include],
|
|
71
|
+
exclude: [...exclude]
|
|
72
|
+
});
|
|
73
|
+
tsConfig = defaultConfig;
|
|
74
|
+
if (isPresents(["hono"])) tsConfig = defu(defaultConfig, { compilerOptions: {
|
|
75
|
+
jsx: "react-jsx",
|
|
76
|
+
jsxImportSource: "hono/jsx"
|
|
77
|
+
} });
|
|
78
|
+
if (isPresents(["npm-package"])) tsConfig = defu(tsConfig, {
|
|
79
|
+
compilerOptions: {
|
|
80
|
+
target: "es2022",
|
|
81
|
+
lib: [
|
|
82
|
+
"es2022",
|
|
83
|
+
"webworker",
|
|
84
|
+
"dom.iterable"
|
|
85
|
+
],
|
|
86
|
+
moduleDetection: "force",
|
|
87
|
+
module: "preserve",
|
|
88
|
+
paths: {},
|
|
89
|
+
resolveJsonModule: true,
|
|
90
|
+
allowJs: true,
|
|
91
|
+
strict: true,
|
|
92
|
+
noImplicitOverride: true,
|
|
93
|
+
noEmit: true,
|
|
94
|
+
allowSyntheticDefaultImports: true,
|
|
95
|
+
esModuleInterop: false,
|
|
96
|
+
forceConsistentCasingInFileNames: true,
|
|
97
|
+
isolatedModules: true,
|
|
98
|
+
verbatimModuleSyntax: true,
|
|
99
|
+
skipLibCheck: true
|
|
100
|
+
},
|
|
101
|
+
include: [...include],
|
|
102
|
+
exclude: [...exclude]
|
|
103
|
+
});
|
|
104
|
+
tsConfig.compilerOptions ||= {};
|
|
105
|
+
tsConfig.compilerOptions.paths ||= {};
|
|
106
|
+
tsConfig.include ||= [];
|
|
107
|
+
for (const alias in tsConfig.compilerOptions.paths) {
|
|
108
|
+
const paths = tsConfig.compilerOptions.paths[alias];
|
|
109
|
+
tsConfig.compilerOptions.paths[alias] = await Promise.all(paths.map(async (path) => {
|
|
110
|
+
if (!isAbsolute(path)) return path;
|
|
111
|
+
const stats = await promises.stat(path).catch(() => null);
|
|
112
|
+
return relativeWithDot(tsconfigDir, stats?.isFile() ? path.replace(/\b\.\w+$/g, "") : path);
|
|
113
|
+
}));
|
|
114
|
+
}
|
|
115
|
+
const references = [];
|
|
116
|
+
await Promise.all([...silgi.options.modules, ...silgi.options._modules].map(async (id) => {
|
|
117
|
+
if (typeof id !== "string") return;
|
|
118
|
+
if (id === "./src" && silgi.options.preset === "npm-package") id = resolve(silgi.options.rootDir);
|
|
119
|
+
const pkg = await readPackageJSON(id, { url: silgi.options.rootDir }).catch(() => null);
|
|
120
|
+
references.push({ types: pkg?.name || id });
|
|
121
|
+
}));
|
|
122
|
+
const declarations = [];
|
|
123
|
+
await silgi.callHook("prepare:types", {
|
|
124
|
+
references,
|
|
125
|
+
declarations,
|
|
126
|
+
tsConfig
|
|
127
|
+
});
|
|
128
|
+
tsConfig.include = [...new Set(tsConfig.include.map((p) => isAbsolute(p) ? relativeWithDot(tsconfigDir, p) : p))];
|
|
129
|
+
tsConfig.exclude = [...new Set(tsConfig.exclude.map((p) => isAbsolute(p) ? relativeWithDot(tsconfigDir, p) : p))];
|
|
130
|
+
const _declarations = [
|
|
131
|
+
...references.map((ref) => {
|
|
132
|
+
if ("path" in ref && isAbsolute(ref.path)) ref.path = relative(silgi.options.build.dir, ref.path);
|
|
133
|
+
return `/// <reference ${renderAttrs(ref)} />`;
|
|
134
|
+
}),
|
|
135
|
+
...declarations,
|
|
136
|
+
"",
|
|
137
|
+
"export {}",
|
|
138
|
+
""
|
|
139
|
+
];
|
|
140
|
+
return {
|
|
141
|
+
declarations: _declarations,
|
|
142
|
+
tsConfig
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
//#endregion
|
|
147
|
+
export { silgiGenerateType };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { consola as consola$1 } from "consola";
|
|
2
|
+
import { join, resolve } from "pathe";
|
|
3
|
+
import { addTemplate, hasSilgiModule } from "silgi/kit";
|
|
4
|
+
import { generateDTS } from "apiful/openapi";
|
|
5
|
+
|
|
6
|
+
//#region src/cli/core/apiful.ts
|
|
7
|
+
async function generateApiFul(silgi) {
|
|
8
|
+
const config = silgi.options.apiFul;
|
|
9
|
+
if (!hasSilgiModule("openapi")) {
|
|
10
|
+
silgi.options.dev || silgi.logger.info("Silgi OpenAPI module not found, if you want to use it, please install it @silgi/openapi");
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
if (!config.services || hasSilgiModule("openapi")) {
|
|
14
|
+
config.services ??= {};
|
|
15
|
+
config.services = { silgi: { schema: join(silgi.options.build.dir, "openapi.json") } };
|
|
16
|
+
}
|
|
17
|
+
const resolvedOpenAPIServices = Object.fromEntries(Object.entries(config?.services ?? {}).filter(([, service]) => Boolean(service.schema)));
|
|
18
|
+
if (Object.keys(resolvedOpenAPIServices).length === 0) {
|
|
19
|
+
consola$1.info("No OpenAPI schemas found, skipping generation");
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
for (const service of Object.values(resolvedOpenAPIServices)) if (typeof service.schema === "string" && !service.schema.startsWith("http")) service.schema = resolve(silgi.options.rootDir, service.schema);
|
|
23
|
+
const types = await generateDTS(resolvedOpenAPIServices);
|
|
24
|
+
silgi.hook("prepare:types", (opts) => {
|
|
25
|
+
opts.references.push({ path: "./apiful.d.ts" });
|
|
26
|
+
});
|
|
27
|
+
addTemplate({
|
|
28
|
+
filename: "types/apiful.d.ts",
|
|
29
|
+
where: ".silgi",
|
|
30
|
+
write: true,
|
|
31
|
+
getContents: () => types
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
//#endregion
|
|
36
|
+
export { generateApiFul };
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { pluginsDeclaration, templates_exports } from "./templates.mjs";
|
|
2
|
+
import { dirname, resolve } from "pathe";
|
|
3
|
+
import { normalizeTemplate, useLogger } from "silgi/kit";
|
|
4
|
+
import { existsSync, mkdirSync, promises, writeFileSync } from "node:fs";
|
|
5
|
+
|
|
6
|
+
//#region src/cli/core/app.ts
|
|
7
|
+
const postTemplates = [pluginsDeclaration.filename];
|
|
8
|
+
const logger = useLogger("silgi");
|
|
9
|
+
async function generateApp(app, options = {}) {
|
|
10
|
+
app.templates = Object.values(templates_exports).concat(app.options.build.templates);
|
|
11
|
+
await app.callHook("app:templates", app);
|
|
12
|
+
app.templates = app.templates.map((tmpl) => {
|
|
13
|
+
let dir;
|
|
14
|
+
switch (tmpl.where) {
|
|
15
|
+
case ".silgi":
|
|
16
|
+
dir = app.options.build.dir;
|
|
17
|
+
break;
|
|
18
|
+
case "server":
|
|
19
|
+
dir = app.options.silgi.serverDir;
|
|
20
|
+
break;
|
|
21
|
+
case "client":
|
|
22
|
+
dir = app.options.silgi.clientDir;
|
|
23
|
+
break;
|
|
24
|
+
case "root":
|
|
25
|
+
dir = app.options.rootDir;
|
|
26
|
+
break;
|
|
27
|
+
default: dir = app.options.silgi.vfsDir;
|
|
28
|
+
}
|
|
29
|
+
return normalizeTemplate(tmpl, dir);
|
|
30
|
+
});
|
|
31
|
+
const filteredTemplates = {
|
|
32
|
+
pre: [],
|
|
33
|
+
post: []
|
|
34
|
+
};
|
|
35
|
+
for (const template of app.templates) {
|
|
36
|
+
if (template.watch === false) {
|
|
37
|
+
if (Array.isArray(app.options.watchOptions.ignored)) app.options.watchOptions.ignored.push(`${template.dst || template.src}`);
|
|
38
|
+
}
|
|
39
|
+
if (options.filter && !options.filter(template)) continue;
|
|
40
|
+
const key = template.filename && postTemplates.includes(template.filename) ? "post" : "pre";
|
|
41
|
+
filteredTemplates[key].push(template);
|
|
42
|
+
}
|
|
43
|
+
const templateContext = { app };
|
|
44
|
+
const writes = [];
|
|
45
|
+
const dirs = new Set();
|
|
46
|
+
const changedTemplates = [];
|
|
47
|
+
async function processTemplate(template) {
|
|
48
|
+
let dir;
|
|
49
|
+
switch (template.where) {
|
|
50
|
+
case ".silgi":
|
|
51
|
+
dir = app.options.build.dir;
|
|
52
|
+
break;
|
|
53
|
+
case "server":
|
|
54
|
+
dir = app.options.silgi.serverDir;
|
|
55
|
+
break;
|
|
56
|
+
case "client":
|
|
57
|
+
dir = app.options.silgi.clientDir;
|
|
58
|
+
break;
|
|
59
|
+
case "root":
|
|
60
|
+
dir = app.options.rootDir;
|
|
61
|
+
break;
|
|
62
|
+
default: dir = app.options.silgi.vfsDir;
|
|
63
|
+
}
|
|
64
|
+
const fullPath = template.dst || resolve(dir, template.filename);
|
|
65
|
+
const start = performance.now();
|
|
66
|
+
const contents = await compileTemplate(template, templateContext).catch((e) => {
|
|
67
|
+
logger.error(`Could not compile template \`${template.filename}\`.`);
|
|
68
|
+
logger.error(e);
|
|
69
|
+
throw e;
|
|
70
|
+
});
|
|
71
|
+
template.modified = true;
|
|
72
|
+
if (template.modified) changedTemplates.push(template);
|
|
73
|
+
const perf = performance.now() - start;
|
|
74
|
+
const setupTime = Math.round(perf * 100) / 100;
|
|
75
|
+
if (app.options.debug || setupTime > 500) logger.info(`Compiled \`${template.filename}\` in ${setupTime}ms`);
|
|
76
|
+
if (template.modified && template.write) {
|
|
77
|
+
dirs.add(dirname(fullPath));
|
|
78
|
+
if (template.skipIfExists && existsSync(fullPath)) return;
|
|
79
|
+
writes.push(() => writeFileSync(fullPath, contents, "utf8"));
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
await Promise.allSettled(filteredTemplates.pre.map(processTemplate));
|
|
83
|
+
await Promise.allSettled(filteredTemplates.post.map(processTemplate));
|
|
84
|
+
for (const dir of dirs) mkdirSync(dir, { recursive: true });
|
|
85
|
+
for (const write of writes) if (!app.errors.length) write();
|
|
86
|
+
if (changedTemplates.length) await app.callHook("app:templatesGenerated", app, changedTemplates, options);
|
|
87
|
+
}
|
|
88
|
+
/** @internal */
|
|
89
|
+
async function compileTemplate(template, ctx) {
|
|
90
|
+
delete ctx.utils;
|
|
91
|
+
if (template.src) try {
|
|
92
|
+
return await promises.readFile(template.src, "utf-8");
|
|
93
|
+
} catch (err) {
|
|
94
|
+
logger.error(`[nuxt] Error reading template from \`${template.src}\``);
|
|
95
|
+
throw err;
|
|
96
|
+
}
|
|
97
|
+
if (template.getContents) return template.getContents({
|
|
98
|
+
...ctx,
|
|
99
|
+
options: template.options
|
|
100
|
+
});
|
|
101
|
+
throw new Error(`[nuxt] Invalid template. Templates must have either \`src\` or \`getContents\`: ${JSON.stringify(template)}`);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
//#endregion
|
|
105
|
+
export { generateApp };
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { resolve } from "pathe";
|
|
2
|
+
import { existsSync, promises } from "node:fs";
|
|
3
|
+
import * as dotenv from "dotenv";
|
|
4
|
+
|
|
5
|
+
//#region src/cli/core/env.ts
|
|
6
|
+
/**
|
|
7
|
+
* Load and interpolate environment variables into `process.env`.
|
|
8
|
+
* If you need more control (or access to the values), consider using `loadDotenv` instead
|
|
9
|
+
*
|
|
10
|
+
*/
|
|
11
|
+
async function setupDotenv(options) {
|
|
12
|
+
const targetEnvironment = options.env ?? process.env;
|
|
13
|
+
const environment = await loadDotenv({
|
|
14
|
+
cwd: options.cwd,
|
|
15
|
+
fileName: options.fileName ?? ".env",
|
|
16
|
+
env: targetEnvironment,
|
|
17
|
+
interpolate: options.interpolate ?? true
|
|
18
|
+
});
|
|
19
|
+
for (const key in environment) if (!key.startsWith("_") && targetEnvironment[key] === void 0) targetEnvironment[key] = environment[key];
|
|
20
|
+
return environment;
|
|
21
|
+
}
|
|
22
|
+
/** Load environment variables into an object. */
|
|
23
|
+
async function loadDotenv(options) {
|
|
24
|
+
const environment = Object.create(null);
|
|
25
|
+
const dotenvFile = resolve(options.cwd, options.fileName);
|
|
26
|
+
if (existsSync(dotenvFile)) {
|
|
27
|
+
const parsed = dotenv.parse(await promises.readFile(dotenvFile, "utf8"));
|
|
28
|
+
Object.assign(environment, parsed);
|
|
29
|
+
}
|
|
30
|
+
if (!options.env?._applied) {
|
|
31
|
+
Object.assign(environment, options.env);
|
|
32
|
+
environment._applied = true;
|
|
33
|
+
}
|
|
34
|
+
if (options.interpolate) interpolate(environment);
|
|
35
|
+
return environment;
|
|
36
|
+
}
|
|
37
|
+
function interpolate(target, source = {}, parse$1 = (v) => v) {
|
|
38
|
+
function getValue(key) {
|
|
39
|
+
return source[key] === void 0 ? target[key] : source[key];
|
|
40
|
+
}
|
|
41
|
+
function interpolate$1(value, parents = []) {
|
|
42
|
+
if (typeof value !== "string") return value;
|
|
43
|
+
const matches = value.match(/(.?\$\{?[\w:]*\}?)/g) || [];
|
|
44
|
+
return parse$1(matches.reduce((newValue, match) => {
|
|
45
|
+
const parts = /(.?)\$\{?([\w:]+)?\}?/.exec(match) || [];
|
|
46
|
+
const prefix = parts[1];
|
|
47
|
+
let value$1, replacePart;
|
|
48
|
+
if (prefix === "\\") {
|
|
49
|
+
replacePart = parts[0] || "";
|
|
50
|
+
value$1 = replacePart.replace(String.raw`\$`, "$");
|
|
51
|
+
} else {
|
|
52
|
+
const key = parts[2];
|
|
53
|
+
replacePart = (parts[0] || "").slice((prefix || "").length);
|
|
54
|
+
if (key && parents.includes(key)) {
|
|
55
|
+
console.warn(`Please avoid recursive environment variables ( loop: ${parents.join(" > ")} > ${key} )`);
|
|
56
|
+
return "";
|
|
57
|
+
}
|
|
58
|
+
value$1 = key ? getValue(key) : void 0;
|
|
59
|
+
value$1 = interpolate$1(value$1, key ? [...parents, key] : parents);
|
|
60
|
+
}
|
|
61
|
+
return value$1 === void 0 ? newValue : newValue.replace(replacePart, value$1);
|
|
62
|
+
}, value));
|
|
63
|
+
}
|
|
64
|
+
for (const key in target) target[key] = interpolate$1(getValue(key));
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
//#endregion
|
|
68
|
+
export { setupDotenv };
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { useSilgiCLI } from "../../core/silgiApp.mjs";
|
|
2
|
+
import { addNPMPackage, addTemplate } from "silgi/kit";
|
|
3
|
+
|
|
4
|
+
//#region src/cli/core/installPackage.ts
|
|
5
|
+
/**
|
|
6
|
+
* Install packages for the Silgi CLI.
|
|
7
|
+
*
|
|
8
|
+
* @param silgi - The SilgiCLI instance.
|
|
9
|
+
* @default
|
|
10
|
+
*/
|
|
11
|
+
async function installPackages(silgi = useSilgiCLI()) {
|
|
12
|
+
await addNPMPackage([{
|
|
13
|
+
name: "zod-to-json-schema",
|
|
14
|
+
isDev: false,
|
|
15
|
+
when: silgi.options.schemaVendor === "zod"
|
|
16
|
+
}, {
|
|
17
|
+
name: "@valibot/to-json-schema",
|
|
18
|
+
isDev: false,
|
|
19
|
+
when: silgi.options.schemaVendor === "valibot"
|
|
20
|
+
}]);
|
|
21
|
+
await addNPMPackage([
|
|
22
|
+
{
|
|
23
|
+
name: "@fastify/deepmerge",
|
|
24
|
+
isDev: false
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
name: "@silgi/ecosystem",
|
|
28
|
+
isDev: false
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
name: "unadapter",
|
|
32
|
+
isDev: false
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
name: "apiful",
|
|
36
|
+
isDev: false
|
|
37
|
+
}
|
|
38
|
+
]);
|
|
39
|
+
const packages = {
|
|
40
|
+
dependencies: { ...silgi.options.installPackages?.dependencies },
|
|
41
|
+
devDependencies: { ...silgi.options.installPackages?.devDependencies }
|
|
42
|
+
};
|
|
43
|
+
if (silgi.options.preset === "npm-package") {
|
|
44
|
+
packages.devDependencies = {
|
|
45
|
+
...packages.devDependencies,
|
|
46
|
+
...packages.dependencies
|
|
47
|
+
};
|
|
48
|
+
packages.dependencies = {};
|
|
49
|
+
}
|
|
50
|
+
if (silgi.options.debug === true || silgi.options.debug?.install) addTemplate({
|
|
51
|
+
filename: "install.json",
|
|
52
|
+
where: ".silgi",
|
|
53
|
+
write: true,
|
|
54
|
+
getContents: () => JSON.stringify(packages, null, 2)
|
|
55
|
+
});
|
|
56
|
+
return packages;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
//#endregion
|
|
60
|
+
export { installPackages };
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { useSilgiCLI } from "silgi";
|
|
2
|
+
import { addTemplate } from "silgi/kit";
|
|
3
|
+
import { initRuntimeConfig } from "silgi/runtime";
|
|
4
|
+
import { snakeCase } from "scule";
|
|
5
|
+
|
|
6
|
+
//#region src/cli/core/runtimeConfig.ts
|
|
7
|
+
function useCLIRuntimeConfig(silgi = useSilgiCLI()) {
|
|
8
|
+
const safeRuntimeConfig = JSON.parse(JSON.stringify(silgi.options.runtimeConfig));
|
|
9
|
+
silgi.hook("prepare:configs.ts", (data) => {
|
|
10
|
+
data.runtimeConfig = safeRuntimeConfig;
|
|
11
|
+
silgi.options.envOptions = silgi.options.envOptions;
|
|
12
|
+
});
|
|
13
|
+
addTemplate({
|
|
14
|
+
filename: "env.example",
|
|
15
|
+
write: true,
|
|
16
|
+
where: ".silgi",
|
|
17
|
+
getContents() {
|
|
18
|
+
const flattenedConfig = flattenObject(safeRuntimeConfig);
|
|
19
|
+
const groupedVars = {};
|
|
20
|
+
Object.entries(flattenedConfig).forEach(([key, { value, originalPath }]) => {
|
|
21
|
+
const shouldExclude = silgi.options.codegen.env.safeList.some((safePath) => {
|
|
22
|
+
if (safePath.length !== originalPath.length) return false;
|
|
23
|
+
return safePath.every((segment, index) => segment.toLowerCase() === originalPath[index]?.toLowerCase());
|
|
24
|
+
});
|
|
25
|
+
if (shouldExclude) return;
|
|
26
|
+
if (originalPath.length > 0) {
|
|
27
|
+
const firstKey = originalPath[0];
|
|
28
|
+
if (typeof firstKey === "string") {
|
|
29
|
+
const categoryName = extractCategoryFromCamel(firstKey);
|
|
30
|
+
if (!groupedVars[categoryName]) groupedVars[categoryName] = {};
|
|
31
|
+
groupedVars[categoryName][key] = value;
|
|
32
|
+
}
|
|
33
|
+
} else {
|
|
34
|
+
if (!groupedVars.OTHER) groupedVars.OTHER = {};
|
|
35
|
+
groupedVars.OTHER[key] = value;
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
return Object.entries(groupedVars).map(([category, vars]) => {
|
|
39
|
+
const varsContent = Object.entries(vars).map(([key, value]) => `${key}=${value}`).join("\n");
|
|
40
|
+
return `# ${category}\n${varsContent}`;
|
|
41
|
+
}).join("\n\n");
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
const _sharedRuntimeConfig = initRuntimeConfig(silgi.options.envOptions, silgi.options.runtimeConfig);
|
|
45
|
+
silgi.options.runtimeConfig = safeRuntimeConfig;
|
|
46
|
+
return _sharedRuntimeConfig;
|
|
47
|
+
}
|
|
48
|
+
function extractCategoryFromCamel(str) {
|
|
49
|
+
if (/^[a-z]+[A-Z]/.test(str)) {
|
|
50
|
+
const matches = str.match(/^([a-z]+)([A-Z][a-z0-9]*)?/);
|
|
51
|
+
if (matches && matches[1] && matches[2]) return `${matches[1].toUpperCase()}_${matches[2].toUpperCase()}`;
|
|
52
|
+
}
|
|
53
|
+
return str.toUpperCase();
|
|
54
|
+
}
|
|
55
|
+
function flattenObject(obj, prefix = "SILGI", originalPath = []) {
|
|
56
|
+
return Object.entries(obj).reduce((acc, [key, value]) => {
|
|
57
|
+
const formattedKey = snakeCase(key).toUpperCase();
|
|
58
|
+
const newKey = `${prefix}_${formattedKey}`;
|
|
59
|
+
const newPath = [...originalPath, key];
|
|
60
|
+
if (typeof value === "object" && value !== null) Object.assign(acc, flattenObject(value, newKey, newPath));
|
|
61
|
+
else acc[newKey] = {
|
|
62
|
+
value,
|
|
63
|
+
originalPath: newPath
|
|
64
|
+
};
|
|
65
|
+
return acc;
|
|
66
|
+
}, {});
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
//#endregion
|
|
70
|
+
export { useCLIRuntimeConfig };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { join, relative } from "pathe";
|
|
2
|
+
import { glob } from "tinyglobby";
|
|
3
|
+
|
|
4
|
+
//#region src/cli/core/scan.ts
|
|
5
|
+
const GLOB_SCAN_PATTERN = "**/*.{js,mjs,cjs,ts,mts,cts,tsx,jsx}";
|
|
6
|
+
async function scanAndSyncOptions(silgi) {
|
|
7
|
+
const scannedModules = await scanModules(silgi);
|
|
8
|
+
silgi.options.modules = silgi.options.modules || [];
|
|
9
|
+
for (const modPath of scannedModules) if (!silgi.options.modules.includes(modPath)) silgi.options.modules.push(modPath);
|
|
10
|
+
}
|
|
11
|
+
async function scanModules(silgi) {
|
|
12
|
+
const files = await scanFiles(silgi, "silgi/modules");
|
|
13
|
+
return files.map((f) => f.fullPath);
|
|
14
|
+
}
|
|
15
|
+
async function scanFiles(silgi, name) {
|
|
16
|
+
const files = await Promise.all(silgi.options.scanDirs.map((dir) => scanDir(silgi, dir, name))).then((r) => r.flat());
|
|
17
|
+
return files;
|
|
18
|
+
}
|
|
19
|
+
async function scanDir(silgi, dir, name) {
|
|
20
|
+
const fileNames = await glob(join(name, GLOB_SCAN_PATTERN), {
|
|
21
|
+
cwd: dir,
|
|
22
|
+
dot: true,
|
|
23
|
+
ignore: silgi.options.ignore,
|
|
24
|
+
absolute: true
|
|
25
|
+
});
|
|
26
|
+
return fileNames.map((fullPath) => {
|
|
27
|
+
return {
|
|
28
|
+
fullPath,
|
|
29
|
+
path: relative(join(dir, name), fullPath)
|
|
30
|
+
};
|
|
31
|
+
}).sort((a, b) => a.path.localeCompare(b.path));
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
//#endregion
|
|
35
|
+
export { scanAndSyncOptions };
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { prepareEnv } from "../commands/env.mjs";
|
|
2
|
+
import { loadOptions } from "../config/loader.mjs";
|
|
3
|
+
import { frameworkSetup } from "../framework/index.mjs";
|
|
4
|
+
import { registerModuleExportScan } from "../module/exportScan.mjs";
|
|
5
|
+
import { installModules } from "../module/install.mjs";
|
|
6
|
+
import { scanSilgiExports } from "../scan/scanExportFile.mjs";
|
|
7
|
+
import { scanModules } from "../module/scan.mjs";
|
|
8
|
+
import { prepareConfigs } from "../scan/prepareConfigs.mjs";
|
|
9
|
+
import { prepareScanFile } from "../scan/prepareScanFile.mjs";
|
|
10
|
+
import { readScanFile } from "../utils/readScanFile.mjs";
|
|
11
|
+
import { createStorageCLI } from "../utils/storage.mjs";
|
|
12
|
+
import { scanAndSyncOptions } from "./scan.mjs";
|
|
13
|
+
import { consola as consola$1 } from "consola";
|
|
14
|
+
import { join } from "pathe";
|
|
15
|
+
import { autoImportTypes, silgiCLICtx } from "silgi";
|
|
16
|
+
import { createDebugger, createHooks } from "hookable";
|
|
17
|
+
import { resolveSilgiPath } from "silgi/kit";
|
|
18
|
+
import { sharedRuntimeConfig, useRuntimeConfig } from "silgi/runtime";
|
|
19
|
+
import { runtimeDir } from "silgi/runtime/meta";
|
|
20
|
+
import { createUnimport } from "unimport";
|
|
21
|
+
|
|
22
|
+
//#region src/cli/core/silgi.ts
|
|
23
|
+
async function createSilgiCLI(config = {}, opts = {}) {
|
|
24
|
+
const options = await loadOptions(config, opts);
|
|
25
|
+
await prepareEnv(options);
|
|
26
|
+
const hooks = createHooks();
|
|
27
|
+
const silgi = {
|
|
28
|
+
services: {},
|
|
29
|
+
middleware: [],
|
|
30
|
+
shareds: {},
|
|
31
|
+
schemas: {},
|
|
32
|
+
resolvers: [],
|
|
33
|
+
unimport: void 0,
|
|
34
|
+
options,
|
|
35
|
+
hooks,
|
|
36
|
+
errors: [],
|
|
37
|
+
_requiredModules: {},
|
|
38
|
+
logger: opts.consola || consola$1.withTag("silgi"),
|
|
39
|
+
close: () => silgi.hooks.callHook("close", silgi),
|
|
40
|
+
storage: void 0,
|
|
41
|
+
scanModules: [],
|
|
42
|
+
templates: [],
|
|
43
|
+
callHook: hooks.callHook,
|
|
44
|
+
addHooks: hooks.addHooks,
|
|
45
|
+
hook: hooks.hook,
|
|
46
|
+
adapters: {},
|
|
47
|
+
useLocalConfig: () => useRuntimeConfig(void 0, options.runtimeConfig),
|
|
48
|
+
meta: {}
|
|
49
|
+
};
|
|
50
|
+
if (silgiCLICtx.tryUse()) {
|
|
51
|
+
silgiCLICtx.unset();
|
|
52
|
+
silgiCLICtx.set(silgi);
|
|
53
|
+
} else {
|
|
54
|
+
silgiCLICtx.set(silgi);
|
|
55
|
+
silgi.hook("close", () => silgiCLICtx.unset());
|
|
56
|
+
}
|
|
57
|
+
if (silgi.options.debug) {
|
|
58
|
+
createDebugger(silgi.hooks, { tag: "silgi" });
|
|
59
|
+
silgi.options.plugins.push({
|
|
60
|
+
path: join(runtimeDir, "internal/debug"),
|
|
61
|
+
packageImport: "silgi/runtime/internal/debug"
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
await scanAndSyncOptions(silgi);
|
|
65
|
+
await scanSilgiExports();
|
|
66
|
+
await scanModules(silgi);
|
|
67
|
+
await installModules(silgi, true);
|
|
68
|
+
await prepareConfigs();
|
|
69
|
+
sharedRuntimeConfig(silgi.options.runtimeConfig, silgi.options.dev);
|
|
70
|
+
if (silgi.options.adapters && Object.keys(silgi.options.adapters)?.length > 0) for (const [key, value] of Object.entries(silgi.options.adapters)) if (typeof value === "function") {
|
|
71
|
+
const resolved = value(silgi);
|
|
72
|
+
silgi.adapters[key] = resolved instanceof Promise ? await resolved : resolved;
|
|
73
|
+
} else silgi.adapters[key] = value;
|
|
74
|
+
await prepareScanFile(silgi);
|
|
75
|
+
await readScanFile(silgi);
|
|
76
|
+
await installModules(silgi);
|
|
77
|
+
for (const framework of frameworkSetup) await framework(silgi);
|
|
78
|
+
silgi.storage = await createStorageCLI(silgi);
|
|
79
|
+
silgi.hooks.hook("close", async () => {
|
|
80
|
+
await silgi.storage.dispose();
|
|
81
|
+
});
|
|
82
|
+
if (silgi.options.logLevel !== void 0) silgi.logger.level = silgi.options.logLevel;
|
|
83
|
+
silgi.hooks.addHooks(silgi.options.hooks);
|
|
84
|
+
if (silgi.options.imports) {
|
|
85
|
+
silgi.options.imports.dirs ??= [];
|
|
86
|
+
silgi.options.imports.dirs = silgi.options.imports.dirs.map((dir) => {
|
|
87
|
+
if (typeof dir === "string") {
|
|
88
|
+
if (dir.startsWith("!")) return `!${resolveSilgiPath(dir.slice(1), options, silgi.options.rootDir)}`;
|
|
89
|
+
return resolveSilgiPath(dir, options, silgi.options.rootDir);
|
|
90
|
+
}
|
|
91
|
+
return dir;
|
|
92
|
+
});
|
|
93
|
+
silgi.options.imports.presets.push({
|
|
94
|
+
from: "silgi/types",
|
|
95
|
+
imports: autoImportTypes.map((type) => type),
|
|
96
|
+
type: true
|
|
97
|
+
});
|
|
98
|
+
silgi.options.imports.presets.push({
|
|
99
|
+
from: "silgi/runtime/internal/ofetch",
|
|
100
|
+
imports: ["createSilgiFetch", "silgi$fetch"]
|
|
101
|
+
});
|
|
102
|
+
silgi.unimport = createUnimport(silgi.options.imports);
|
|
103
|
+
await silgi.unimport.init();
|
|
104
|
+
}
|
|
105
|
+
await registerModuleExportScan(silgi);
|
|
106
|
+
await silgi.hooks.callHook("ready", silgi);
|
|
107
|
+
return silgi;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
//#endregion
|
|
111
|
+
export { createSilgiCLI };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { __export } from "../../_virtual/rolldown_runtime.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/cli/core/templates.ts
|
|
4
|
+
var templates_exports = {};
|
|
5
|
+
__export(templates_exports, {
|
|
6
|
+
pluginsDeclaration: () => pluginsDeclaration,
|
|
7
|
+
vueShim: () => vueShim
|
|
8
|
+
});
|
|
9
|
+
const vueShim = {
|
|
10
|
+
filename: "delete/testtest.d.ts",
|
|
11
|
+
where: ".silgi",
|
|
12
|
+
getContents: ({ app }) => {
|
|
13
|
+
if (!app.options.typescript.shim) return "";
|
|
14
|
+
return [
|
|
15
|
+
"declare module '*.vue' {",
|
|
16
|
+
" import { DefineComponent } from 'vue'",
|
|
17
|
+
" const component: DefineComponent<{}, {}, any>",
|
|
18
|
+
" export default component",
|
|
19
|
+
"}"
|
|
20
|
+
].join("\n");
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
const pluginsDeclaration = {
|
|
24
|
+
filename: "delete/testtest1.d.ts",
|
|
25
|
+
where: ".silgi",
|
|
26
|
+
getContents: async () => {
|
|
27
|
+
return `
|
|
28
|
+
declare module 'nuxt' {
|
|
29
|
+
interface NuxtApp {
|
|
30
|
+
$myPlugin: any;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
`;
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
//#endregion
|
|
38
|
+
export { pluginsDeclaration, templates_exports };
|