silgi 0.7.1 → 0.7.2

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.
Files changed (83) hide show
  1. package/dist/_chunks/index.mjs +5 -0
  2. package/dist/cli/{utils/compatibility.mjs → compatibility.mjs} +1 -1
  3. package/dist/cli/config/index.d.mts +11 -0
  4. package/dist/cli/config/index.d.ts +11 -0
  5. package/dist/{core/config/types.mjs → cli/config/index.mjs} +19 -2
  6. package/dist/cli/index.mjs +3 -3
  7. package/dist/cli/loader.mjs +581 -0
  8. package/dist/cli/prepare.mjs +1488 -0
  9. package/dist/core/index.d.mts +2 -10
  10. package/dist/core/index.d.ts +2 -10
  11. package/dist/core/index.mjs +943 -16
  12. package/dist/ecosystem/nitro/index.mjs +62 -1
  13. package/dist/ecosystem/nuxt/module.mjs +1 -1
  14. package/dist/kit/index.mjs +299 -10
  15. package/dist/meta/index.d.mts +1 -1
  16. package/dist/meta/index.d.ts +1 -1
  17. package/dist/meta/index.mjs +1 -1
  18. package/package.json +5 -1
  19. package/dist/cli/build/framework/h3.mjs +0 -46
  20. package/dist/cli/build/framework/index.mjs +0 -7
  21. package/dist/cli/build/framework/nitro.mjs +0 -28
  22. package/dist/cli/build/framework/nuxt.mjs +0 -9
  23. package/dist/cli/build/prepare.mjs +0 -7
  24. package/dist/cli/build/scanURIs.mjs +0 -27
  25. package/dist/cli/build/template/framework.mjs +0 -91
  26. package/dist/cli/build/template/schema.mjs +0 -115
  27. package/dist/cli/build/template/silgi.mjs +0 -149
  28. package/dist/cli/build/types.mjs +0 -130
  29. package/dist/cli/commands/prepare.mjs +0 -49
  30. package/dist/cli/common.mjs +0 -13
  31. package/dist/cli/core/app.mjs +0 -89
  32. package/dist/cli/core/scan.mjs +0 -40
  33. package/dist/cli/core/silgi.mjs +0 -77
  34. package/dist/cli/core/storage.mjs +0 -11
  35. package/dist/cli/core/templates.mjs +0 -29
  36. package/dist/cli/module/exportScan.mjs +0 -69
  37. package/dist/cli/module/install.mjs +0 -52
  38. package/dist/cli/module/scan.mjs +0 -141
  39. package/dist/cli/utils/generateRouterDTS.mjs +0 -84
  40. package/dist/cli/utils/ignore.mjs +0 -46
  41. package/dist/cli/utils/readCoreFile.mjs +0 -47
  42. package/dist/cli/utils/scan.mjs +0 -147
  43. package/dist/cli/utils/storage.mjs +0 -21
  44. package/dist/cli/utils/uri.mjs +0 -71
  45. package/dist/core/config/defaults.mjs +0 -96
  46. package/dist/core/config/loader.mjs +0 -98
  47. package/dist/core/config/resolvers/compatibility.mjs +0 -90
  48. package/dist/core/config/resolvers/imports.mjs +0 -96
  49. package/dist/core/config/resolvers/paths.mjs +0 -194
  50. package/dist/core/config/resolvers/storage.mjs +0 -25
  51. package/dist/core/config/resolvers/url.mjs +0 -7
  52. package/dist/core/createSilgi.mjs +0 -84
  53. package/dist/core/error.mjs +0 -227
  54. package/dist/core/fetch/ofetch.mjs +0 -35
  55. package/dist/core/parser.mjs +0 -136
  56. package/dist/core/silgi.mjs +0 -114
  57. package/dist/core/silgiApp.mjs +0 -15
  58. package/dist/core/unctx.mjs +0 -27
  59. package/dist/core/uris/uri.mjs +0 -33
  60. package/dist/core/uris/utils.mjs +0 -127
  61. package/dist/core/utils/event.mjs +0 -5
  62. package/dist/core/utils/global.mjs +0 -12
  63. package/dist/core/utils/merge.mjs +0 -25
  64. package/dist/core/utils/schema.mjs +0 -5
  65. package/dist/core/utils/service.mjs +0 -5
  66. package/dist/core/utils/shared.mjs +0 -5
  67. package/dist/core/utils/storage.mjs +0 -70
  68. package/dist/ecosystem/nitro/module.mjs +0 -62
  69. package/dist/kit/esm.mjs +0 -10
  70. package/dist/kit/fs.mjs +0 -25
  71. package/dist/kit/isFramework.mjs +0 -25
  72. package/dist/kit/logger.mjs +0 -8
  73. package/dist/kit/module.mjs +0 -73
  74. package/dist/kit/path.mjs +0 -34
  75. package/dist/kit/preset.mjs +0 -6
  76. package/dist/kit/resolve.mjs +0 -78
  77. package/dist/kit/template.mjs +0 -47
  78. package/dist/kit/utils.mjs +0 -20
  79. package/dist/package.json.mjs +0 -5
  80. package/dist/schema/common.mjs +0 -43
  81. package/dist/schema/index.mjs +0 -9
  82. package/dist/schema/internal.mjs +0 -22
  83. /package/dist/cli/{commands/init.mjs → init.mjs} +0 -0
@@ -1 +1,62 @@
1
- export { default } from './module.mjs';
1
+ import { execSync } from 'node:child_process';
2
+ import { fileURLToPath } from 'node:url';
3
+ import { resolve, dirname, join } from 'pathe';
4
+ import { loadOptions } from 'silgi/cli/config';
5
+ import { relativeWithDot } from 'silgi/kit';
6
+ import { autoImportTypes } from 'silgi/types';
7
+
8
+ const module = {
9
+ name: "silgi",
10
+ setup: async (nitro) => {
11
+ const silgiConfig = await loadOptions({});
12
+ nitro.options.plugins = nitro.options.plugins || [];
13
+ nitro.options.plugins.push(
14
+ fileURLToPath(new URL("runtime/plugin", import.meta.url))
15
+ );
16
+ const tsConfigPath = resolve(
17
+ nitro.options.buildDir,
18
+ nitro.options.typescript.tsconfigPath
19
+ );
20
+ const tsconfigDir = dirname(tsConfigPath);
21
+ nitro.options.typescript.strict = true;
22
+ nitro.options.typescript.tsConfig ??= {};
23
+ nitro.options.typescript.tsConfig.extends = "./silgi.tsconfig.json";
24
+ nitro.options.typescript.tsConfig.include ??= [];
25
+ nitro.options.typescript.tsConfig.exclude ??= [];
26
+ if (silgiConfig.typescript.internalPaths || silgiConfig.stub) {
27
+ nitro.options.alias ||= {};
28
+ nitro.options.alias = {
29
+ ...nitro.options.alias,
30
+ ...silgiConfig.alias
31
+ // 'silgi/runtime': fileURLToPath(`${new URL(pkgDir, import.meta.url)}dist/runtime/`),
32
+ };
33
+ }
34
+ nitro.options.typescript.tsConfig.include.push(join(relativeWithDot(tsconfigDir, silgiConfig.build.dir), "**/*"));
35
+ nitro.options.typescript.tsConfig.compilerOptions ??= {};
36
+ nitro.options.typescript.tsConfig.compilerOptions.paths ??= {};
37
+ nitro.hooks.hook("types:extend", async () => {
38
+ const isStub = silgiConfig.stub ? "pnpm silgi prepare --stub" : "pnpm silgi prepare";
39
+ execSync(isStub, { stdio: "inherit", cwd: nitro.options.rootDir, env: process.env });
40
+ });
41
+ nitro.options.exportConditions ??= [];
42
+ nitro.options.exportConditions.push(...silgiConfig.conditions);
43
+ if (nitro.options.imports) {
44
+ nitro.options.imports.dirs ??= [];
45
+ nitro.options.imports.dirs.push(
46
+ join(silgiConfig.silgi.serverDir, "**/*")
47
+ );
48
+ nitro.options.imports.presets ??= [];
49
+ nitro.options.imports.presets.push({
50
+ from: "silgi",
51
+ imports: ["silgi"]
52
+ });
53
+ nitro.options.imports.presets.push({
54
+ from: "silgi/types",
55
+ imports: autoImportTypes.map((type) => type),
56
+ type: true
57
+ });
58
+ }
59
+ }
60
+ };
61
+
62
+ export { module as default };
@@ -1,7 +1,7 @@
1
1
  import { defineNuxtModule, addImports } from '@nuxt/kit';
2
2
  import { resolvePath } from 'mlly';
3
3
  import { join } from 'pathe';
4
- import { loadOptions } from 'silgi/core';
4
+ import { loadOptions } from 'silgi/cli/config';
5
5
  import { relativeWithDot } from 'silgi/kit';
6
6
  import { autoImportTypes } from 'silgi/types';
7
7
 
@@ -1,10 +1,299 @@
1
- export { tryResolveModule } from './esm.mjs';
2
- export { isDirectory, writeFile } from './fs.mjs';
3
- export { isH3, isNitro, isNuxt } from './isFramework.mjs';
4
- export { useLogger } from './logger.mjs';
5
- export { defineSilgiModule } from './module.mjs';
6
- export { prettyPath, resolveSilgiPath } from './path.mjs';
7
- export { defineSilgiPreset } from './preset.mjs';
8
- export { createResolver, resolveAlias, resolvePath, resolveSilgiModule } from './resolve.mjs';
9
- export { addTemplate, normalizeTemplate } from './template.mjs';
10
- export { MODE_RE, filterInPlace, relativeWithDot, toArray } from './utils.mjs';
1
+ import { resolvePath as resolvePath$1 } from 'mlly';
2
+ import fsp from 'node:fs/promises';
3
+ import consola, { consola as consola$1 } from 'consola';
4
+ import { relative, resolve, dirname, normalize, isAbsolute, join, parse, basename } from 'pathe';
5
+ import { colors } from 'consola/utils';
6
+ import { getProperty } from 'dot-prop';
7
+ import { useSilgi, tryUseSilgiCLI, useSilgiCLI } from 'silgi/core';
8
+ import { defu } from 'defu';
9
+ import { c as checkSilgiCompatibility } from '../cli/compatibility.mjs';
10
+ import { existsSync, promises } from 'node:fs';
11
+ import { fileURLToPath } from 'node:url';
12
+ import { resolveAlias as resolveAlias$1 } from 'pathe/utils';
13
+ import { hash } from 'ohash';
14
+ import 'semver/functions/satisfies.js';
15
+ import 'silgi/meta';
16
+
17
+ async function tryResolveModule(id, url = import.meta.url) {
18
+ try {
19
+ return await resolvePath$1(id, { url });
20
+ } catch {
21
+ }
22
+ }
23
+
24
+ function prettyPath(p, highlight = true) {
25
+ p = relative(process.cwd(), p);
26
+ return highlight ? colors.cyan(p) : p;
27
+ }
28
+ function resolveSilgiPath(path, silgiCLIOptions, base) {
29
+ if (typeof path !== "string") {
30
+ throw new TypeError(`Invalid path: ${path}`);
31
+ }
32
+ path = _compilePathTemplate(path)(silgiCLIOptions);
33
+ for (const base2 in silgiCLIOptions.alias) {
34
+ if (path.startsWith(base2)) {
35
+ path = silgiCLIOptions.alias[base2] + path.slice(base2.length);
36
+ }
37
+ }
38
+ return resolve(base || silgiCLIOptions.srcDir, path);
39
+ }
40
+ function _compilePathTemplate(contents) {
41
+ return (params) => contents.replace(/\{\{ ?([\w.]+) ?\}\}/g, (_, match) => {
42
+ const val = getProperty(params, match);
43
+ if (!val) {
44
+ consola.warn(
45
+ `cannot resolve template param '${match}' in ${contents.slice(0, 20)}`
46
+ );
47
+ }
48
+ return val || `${match}`;
49
+ });
50
+ }
51
+
52
+ async function writeFile(file, contents, log = false) {
53
+ await fsp.mkdir(dirname(file), { recursive: true });
54
+ await fsp.writeFile(
55
+ file,
56
+ contents,
57
+ typeof contents === "string" ? "utf8" : void 0
58
+ );
59
+ if (log) {
60
+ consola$1.info("Generated", prettyPath(file));
61
+ }
62
+ }
63
+ async function isDirectory$1(path) {
64
+ try {
65
+ return (await fsp.stat(path)).isDirectory();
66
+ } catch {
67
+ return false;
68
+ }
69
+ }
70
+
71
+ function isNuxt() {
72
+ const silgi = useSilgi();
73
+ if (silgi.options.present === "nitro" || silgi.options.present === "h3" || silgi.options.present === "nuxt") {
74
+ return true;
75
+ }
76
+ return false;
77
+ }
78
+ function isNitro() {
79
+ const silgi = useSilgi();
80
+ if (silgi.options.present === "nitro" || silgi.options.present === "h3") {
81
+ return true;
82
+ }
83
+ return false;
84
+ }
85
+ function isH3() {
86
+ const silgi = useSilgi();
87
+ if (silgi.options.present === "h3") {
88
+ return true;
89
+ }
90
+ return false;
91
+ }
92
+
93
+ const logger = consola$1;
94
+ function useLogger(tag, options = {}) {
95
+ return tag ? logger.create(options).withTag(tag) : logger;
96
+ }
97
+
98
+ function defineSilgiModule(definition) {
99
+ if (definition) {
100
+ return _defineSilgiModule(definition);
101
+ }
102
+ return {
103
+ with: (definition2) => _defineSilgiModule(definition2)
104
+ };
105
+ }
106
+ function _defineSilgiModule(definition) {
107
+ if (typeof definition === "function") {
108
+ return _defineSilgiModule({ setup: definition });
109
+ }
110
+ const module = defu(definition, { meta: {} });
111
+ module.meta.configKey ||= module.meta.name;
112
+ async function getOptions(inlineOptions, silgi = useSilgiCLI()) {
113
+ const nuxtConfigOptionsKey = module.meta.configKey || module.meta.name;
114
+ const nuxtConfigOptions = nuxtConfigOptionsKey && nuxtConfigOptionsKey in silgi.options ? silgi.options[nuxtConfigOptionsKey] : {};
115
+ const optionsDefaults = module.defaults instanceof Function ? await module.defaults(silgi) : module.defaults ?? {};
116
+ const options = defu(inlineOptions, nuxtConfigOptions, optionsDefaults);
117
+ return Promise.resolve(options);
118
+ }
119
+ async function silgiNormalizedModule(inlineOptions, silgi = tryUseSilgiCLI()) {
120
+ if (!silgi) {
121
+ throw new TypeError("Cannot use module outside of Silgi context");
122
+ }
123
+ const uniqueKey = module.meta.configKey || module.meta.name;
124
+ if (uniqueKey) {
125
+ silgi._requiredModules ||= {};
126
+ if (silgi._requiredModules[uniqueKey]) {
127
+ return false;
128
+ }
129
+ silgi._requiredModules[uniqueKey] = true;
130
+ }
131
+ if (module.meta.compatibility) {
132
+ const issues = await checkSilgiCompatibility(module.meta.compatibility, silgi);
133
+ if (issues.length) {
134
+ silgi.logger.warn(`Module \`${module.meta.name}\` is disabled due to incompatibility issues:
135
+ ${issues.toString()}`);
136
+ return;
137
+ }
138
+ }
139
+ const _options = await getOptions(inlineOptions, silgi);
140
+ if (module.hooks) {
141
+ silgi.hooks.addHooks(module.hooks);
142
+ }
143
+ const start = performance.now();
144
+ const res = await module.setup?.call(null, _options, silgi) ?? {};
145
+ const perf = performance.now() - start;
146
+ const setupTime = Math.round(perf * 100) / 100;
147
+ if (setupTime > 5e3 && uniqueKey !== "@silgi/telemetry") {
148
+ silgi.logger.warn(`Slow module \`${uniqueKey || "<no name>"}\` took \`${setupTime}ms\` to setup.`);
149
+ } else if (silgi.options.debug) {
150
+ silgi.logger.info(`Module \`${uniqueKey || "<no name>"}\` took \`${setupTime}ms\` to setup.`);
151
+ }
152
+ if (res === false) {
153
+ return false;
154
+ }
155
+ return defu(res, {
156
+ timings: {
157
+ setup: setupTime
158
+ }
159
+ });
160
+ }
161
+ silgiNormalizedModule.getMeta = () => Promise.resolve(module.meta);
162
+ silgiNormalizedModule.getOptions = getOptions;
163
+ return silgiNormalizedModule;
164
+ }
165
+
166
+ function defineSilgiPreset(preset, meta) {
167
+ if (meta?.url && typeof preset !== "function") ;
168
+ return { ...preset, _meta: meta };
169
+ }
170
+
171
+ async function resolvePath(path, opts = {}) {
172
+ const _path = path;
173
+ path = normalize(path);
174
+ if (isAbsolute(path)) {
175
+ if (existsSync(path) && !await isDirectory(path)) {
176
+ return path;
177
+ }
178
+ }
179
+ const cwd = opts.cwd || process.cwd();
180
+ const extensions = opts.extensions || [".ts", ".mjs", ".cjs", ".json"];
181
+ const modulesDir = opts.modulesDir || [];
182
+ path = resolveAlias(path);
183
+ if (!isAbsolute(path)) {
184
+ path = resolve(cwd, path);
185
+ }
186
+ let _isDir = false;
187
+ if (existsSync(path)) {
188
+ _isDir = await isDirectory(path);
189
+ if (!_isDir) {
190
+ return path;
191
+ }
192
+ }
193
+ for (const ext of extensions) {
194
+ const pathWithExt = path + ext;
195
+ if (existsSync(pathWithExt)) {
196
+ return pathWithExt;
197
+ }
198
+ const pathWithIndex = join(path, `index${ext}`);
199
+ if (_isDir && existsSync(pathWithIndex)) {
200
+ return pathWithIndex;
201
+ }
202
+ }
203
+ const resolveModulePath = await resolvePath$1(_path, { url: [cwd, ...modulesDir] }).catch(() => null);
204
+ if (resolveModulePath) {
205
+ return resolveModulePath;
206
+ }
207
+ return opts.fallbackToOriginal ? _path : path;
208
+ }
209
+ async function isDirectory(path) {
210
+ return (await promises.lstat(path)).isDirectory();
211
+ }
212
+ function resolveAlias(path, alias) {
213
+ return resolveAlias$1(path, alias || {});
214
+ }
215
+ function createResolver(base) {
216
+ if (!base) {
217
+ throw new Error("`base` argument is missing for createResolver(base)!");
218
+ }
219
+ base = base.toString();
220
+ if (base.startsWith("file://")) {
221
+ base = dirname(fileURLToPath(base));
222
+ }
223
+ return {
224
+ resolve: (...path) => resolve(base, ...path),
225
+ resolvePath: (path, opts) => resolvePath(path, { cwd: base, ...opts })
226
+ };
227
+ }
228
+ async function resolveSilgiModule(base, paths) {
229
+ const resolved = [];
230
+ const resolver = createResolver(base);
231
+ for (const path of paths) {
232
+ if (path.startsWith(base)) {
233
+ resolved.push(path.split("/index.ts")[0]);
234
+ } else {
235
+ const resolvedPath = await resolver.resolvePath(path);
236
+ resolved.push(resolvedPath.slice(0, resolvedPath.lastIndexOf(path) + path.length));
237
+ }
238
+ }
239
+ return resolved;
240
+ }
241
+
242
+ const RELATIVE_RE = /^([^.])/;
243
+ function relativeWithDot(from, to) {
244
+ return relative(from, to).replace(RELATIVE_RE, "./$1") || ".";
245
+ }
246
+ function toArray(value) {
247
+ return Array.isArray(value) ? value : [value];
248
+ }
249
+ function filterInPlace(array, predicate) {
250
+ for (let i = array.length; i--; i >= 0) {
251
+ if (!predicate(array[i], i, array)) {
252
+ array.splice(i, 1);
253
+ }
254
+ }
255
+ return array;
256
+ }
257
+ const MODE_RE = /\.(server|client)(\.\w+)*$/;
258
+
259
+ function addTemplate(_template) {
260
+ const silgi = useSilgiCLI();
261
+ const template = normalizeTemplate(_template);
262
+ filterInPlace(silgi.options.build.templates, (p) => normalizeTemplate(p).dst !== template.dst);
263
+ silgi.options.build.templates.push(template);
264
+ return template;
265
+ }
266
+ function normalizeTemplate(template, buildDir) {
267
+ if (!template) {
268
+ throw new Error(`Invalid template: ${JSON.stringify(template)}`);
269
+ }
270
+ if (typeof template === "string") {
271
+ template = { src: template };
272
+ } else {
273
+ template = { ...template };
274
+ }
275
+ if (template.src) {
276
+ if (!existsSync(template.src)) {
277
+ throw new Error(`Template not found: ${template.src}`);
278
+ }
279
+ if (!template.filename) {
280
+ const srcPath = parse(template.src);
281
+ template.filename = template.fileName || `${basename(srcPath.dir)}.${srcPath.name}.${hash(template.src)}${srcPath.ext}`;
282
+ }
283
+ }
284
+ if (!template.src && !template.getContents) {
285
+ throw new Error(`Invalid template. Either \`getContents\` or \`src\` should be provided: ${JSON.stringify(template)}`);
286
+ }
287
+ if (!template.filename) {
288
+ throw new Error(`Invalid template. \`filename\` must be provided: ${JSON.stringify(template)}`);
289
+ }
290
+ if (template.filename.endsWith(".d.ts")) {
291
+ template.write = true;
292
+ }
293
+ if (!template.dst) {
294
+ template.dst = resolve(buildDir ?? useSilgiCLI().options.silgi.serverDir, template.filename);
295
+ }
296
+ return template;
297
+ }
298
+
299
+ export { MODE_RE, addTemplate, createResolver, defineSilgiModule, defineSilgiPreset, filterInPlace, isDirectory$1 as isDirectory, isH3, isNitro, isNuxt, normalizeTemplate, prettyPath, relativeWithDot, resolveAlias, resolvePath, resolveSilgiModule, resolveSilgiPath, toArray, tryResolveModule, useLogger, writeFile };
@@ -1,3 +1,3 @@
1
- const version = "0.7.1";
1
+ const version = "0.7.2";
2
2
 
3
3
  export { version };
@@ -1,3 +1,3 @@
1
- const version = "0.7.1";
1
+ const version = "0.7.2";
2
2
 
3
3
  export { version };
@@ -1 +1 @@
1
- export { version } from '../package.json.mjs';
1
+ export { v as version } from '../_chunks/index.mjs';
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "silgi",
3
3
  "type": "module",
4
- "version": "0.7.1",
4
+ "version": "0.7.2",
5
5
  "private": false,
6
6
  "sideEffects": false,
7
7
  "exports": {
@@ -9,6 +9,10 @@
9
9
  "types": "./cli.d.ts",
10
10
  "import": "./dist/cli/index.mjs"
11
11
  },
12
+ "./cli/config": {
13
+ "types": "./dist/cli/config/index.d.ts",
14
+ "import": "./dist/cli/config/index.mjs"
15
+ },
12
16
  "./config": {
13
17
  "types": "./config.d.ts",
14
18
  "import": "./dist/config/index.mjs"
@@ -1,46 +0,0 @@
1
- async function h3Framework(silgi, skip = false) {
2
- if (silgi.options.preset !== "h3" && skip === false)
3
- return;
4
- if (silgi.options.preset === "h3") {
5
- silgi.hook("after:prepare:schema.ts", (data) => {
6
- data.unshift("type FrameworkContextExtends = NitroApp");
7
- });
8
- }
9
- silgi.hook("prepare:schema.ts", (data) => {
10
- data.importItems.nitropack = {
11
- import: [
12
- { name: "NitroApp", type: true }
13
- ],
14
- from: "nitropack/types"
15
- };
16
- data.importItems.h3 = {
17
- import: [
18
- { name: "H3Event", type: true }
19
- ],
20
- from: "h3"
21
- };
22
- data.events.push({
23
- key: "H3Event",
24
- value: "H3Event",
25
- extends: true,
26
- isSilgiContext: false
27
- });
28
- });
29
- silgi.hook("prepare:createDTSFramework", (data) => {
30
- data.importItems["silgi/types"] = {
31
- import: [
32
- { name: "ModuleRuntimeContext", type: true }
33
- ],
34
- from: "silgi/types"
35
- };
36
- data.customContent?.push(
37
- "",
38
- 'declare module "h3" {',
39
- " interface H3EventContext extends ModuleRuntimeContext {}",
40
- "}",
41
- ""
42
- );
43
- });
44
- }
45
-
46
- export { h3Framework };
@@ -1,7 +0,0 @@
1
- import { h3Framework } from './h3.mjs';
2
- import { nitroFramework } from './nitro.mjs';
3
- import { nuxtFramework } from './nuxt.mjs';
4
-
5
- const frameworkSetup = [h3Framework, nitroFramework, nuxtFramework];
6
-
7
- export { frameworkSetup };
@@ -1,28 +0,0 @@
1
- import { join } from 'pathe';
2
- import { runtimeDir } from 'silgi/runtime/meta';
3
- import { h3Framework } from './h3.mjs';
4
-
5
- async function nitroFramework(silgi, skip = false) {
6
- if (silgi.options.preset !== "nitro" && skip === false)
7
- return;
8
- silgi.hook("prepare:schema.ts", (data) => {
9
- data.importItems.nitropack = {
10
- import: [
11
- { name: "NitroApp", type: true }
12
- ],
13
- from: "nitropack/types"
14
- };
15
- });
16
- silgi.hook("after:prepare:schema.ts", (data) => {
17
- data.unshift("type FrameworkContextExtends = NitroApp");
18
- });
19
- silgi.options.plugins.push({
20
- packageImport: "silgi/runtime/internal/nitro",
21
- path: join(runtimeDir, "internal/nitro")
22
- });
23
- silgi.hook("prepare:core.ts", (_data) => {
24
- });
25
- await h3Framework(silgi, true);
26
- }
27
-
28
- export { nitroFramework };
@@ -1,9 +0,0 @@
1
- import { nitroFramework } from './nitro.mjs';
2
-
3
- async function nuxtFramework(silgi, skip = false) {
4
- if (silgi.options.preset !== "nuxt" && skip === false)
5
- return;
6
- await nitroFramework(silgi, true);
7
- }
8
-
9
- export { nuxtFramework };
@@ -1,7 +0,0 @@
1
- import 'node:fs';
2
- import 'node:fs/promises';
3
-
4
- async function prepare(_silgi) {
5
- }
6
-
7
- export { prepare };
@@ -1,27 +0,0 @@
1
- import { promises } from 'node:fs';
2
- import { readCoreFile } from '../utils/readCoreFile.mjs';
3
- import { traverseObject, scanActionModulesUris } from '../utils/uri.mjs';
4
-
5
- async function scanUris(silgi) {
6
- const { context, object, path } = await readCoreFile(silgi);
7
- const uriMap = traverseObject(silgi, object.schemas, []);
8
- const modulesURIs = scanActionModulesUris(silgi, object.services, []);
9
- const uriContent = Array.from(uriMap.entries()).map(([uri, params]) => ` '${uri}': '${params}',`).join("\n");
10
- let newContext = "";
11
- if (uriMap.size > 0) {
12
- newContext = context.replace(
13
- /export const uris = \{[^}]*\}/,
14
- `export const uris = {
15
- ${uriContent}
16
- }`
17
- ).replace(
18
- /export const modulesURIs = \{[^}]*\}/,
19
- `export const modulesURIs = ${JSON.stringify(modulesURIs, null, 2)}`
20
- );
21
- } else {
22
- newContext = context;
23
- }
24
- await promises.writeFile(path, newContext);
25
- }
26
-
27
- export { scanUris };
@@ -1,91 +0,0 @@
1
- import { isAbsolute } from 'pathe';
2
- import { readPackageJSON } from 'pkg-types';
3
- import { relativeWithDot } from 'silgi/kit';
4
-
5
- async function createCoreFramework(silgi) {
6
- const relativeRootDir = relativeWithDot(silgi.options.rootDir, silgi.options.serverDir);
7
- if (silgi.options.preset !== "nitro" && silgi.options.preset !== "h3")
8
- return;
9
- const importItems = {
10
- "silgi/types": {
11
- import: [
12
- { name: "ModuleRuntimeContext", type: true }
13
- ],
14
- from: "silgi/types"
15
- }
16
- };
17
- await Promise.all([...silgi.options.modules, ...silgi.options._modules].map(async (id) => {
18
- if (typeof id !== "string") {
19
- return;
20
- }
21
- const pkg = await readPackageJSON(id, { url: silgi.options.modulesDir }).catch(() => null);
22
- if (!pkg?.name) {
23
- return;
24
- }
25
- if (importItems[pkg.name]) {
26
- importItems[pkg.name].from = isAbsolute(id) ? relativeWithDot(relativeRootDir, id) : id;
27
- }
28
- }));
29
- const customImports = [];
30
- const functions = [];
31
- await silgi.callHook("prepare:createCoreFramework", {
32
- importItems,
33
- customImports,
34
- functions
35
- });
36
- const content = [
37
- ...functions.map((f) => f.params?.length ? ` await ${f.name}(framework, ${f.params.join(",")})` : ` await ${f.name}(framework)`)
38
- ];
39
- return {
40
- content,
41
- importItems,
42
- customImports
43
- };
44
- }
45
- async function createDTSFramework(silgi) {
46
- const relativeRootDir = relativeWithDot(silgi.options.rootDir, silgi.options.serverDir);
47
- const importItems = {
48
- "silgi/types": {
49
- import: [
50
- { name: "ModuleRuntimeContext", type: true }
51
- ],
52
- from: "silgi/types"
53
- }
54
- };
55
- await Promise.all([...silgi.options.modules, ...silgi.options._modules].map(async (id) => {
56
- if (typeof id !== "string") {
57
- return;
58
- }
59
- const pkg = await readPackageJSON(id, { url: silgi.options.modulesDir }).catch(() => null);
60
- if (!pkg?.name) {
61
- return;
62
- }
63
- if (importItems[pkg.name]) {
64
- importItems[pkg.name].from = isAbsolute(id) ? relativeWithDot(relativeRootDir, id) : id;
65
- }
66
- }));
67
- const customImports = [];
68
- const customContent = [];
69
- await silgi.callHook("prepare:createDTSFramework", {
70
- importItems,
71
- customImports,
72
- customContent
73
- });
74
- const content = [
75
- ...Object.entries(importItems).map(([_name, { from, import: imports }]) => {
76
- const path = isAbsolute(from) ? relativeWithDot(silgi.options.build.typesDir, from) : from;
77
- return `import { ${imports.map(({ type, name }) => type ? `type ${name}` : name).join(", ")} } from '${path}'`;
78
- }),
79
- "",
80
- ...customImports,
81
- "",
82
- ...customContent,
83
- ""
84
- ];
85
- return {
86
- content,
87
- importItems
88
- };
89
- }
90
-
91
- export { createCoreFramework, createDTSFramework };