silgi 0.7.1 → 0.7.3
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 +5 -0
- package/dist/cli/{utils/compatibility.mjs → compatibility.mjs} +1 -1
- package/dist/cli/config/index.d.mts +11 -0
- package/dist/cli/config/index.d.ts +11 -0
- package/dist/{core/config/types.mjs → cli/config/index.mjs} +19 -2
- package/dist/cli/index.mjs +3 -3
- package/dist/cli/loader.mjs +581 -0
- package/dist/cli/prepare.mjs +1621 -0
- package/dist/core/index.d.mts +2 -37
- package/dist/core/index.d.ts +2 -37
- package/dist/core/index.mjs +809 -16
- package/dist/ecosystem/nitro/index.mjs +62 -1
- package/dist/ecosystem/nuxt/module.mjs +1 -1
- package/dist/kit/index.mjs +299 -10
- package/dist/meta/index.d.mts +1 -1
- package/dist/meta/index.d.ts +1 -1
- package/dist/meta/index.mjs +1 -1
- package/package.json +5 -1
- package/dist/cli/build/framework/h3.mjs +0 -46
- package/dist/cli/build/framework/index.mjs +0 -7
- package/dist/cli/build/framework/nitro.mjs +0 -28
- package/dist/cli/build/framework/nuxt.mjs +0 -9
- package/dist/cli/build/prepare.mjs +0 -7
- package/dist/cli/build/scanURIs.mjs +0 -27
- package/dist/cli/build/template/framework.mjs +0 -91
- package/dist/cli/build/template/schema.mjs +0 -115
- package/dist/cli/build/template/silgi.mjs +0 -149
- package/dist/cli/build/types.mjs +0 -130
- package/dist/cli/commands/prepare.mjs +0 -49
- package/dist/cli/common.mjs +0 -13
- package/dist/cli/core/app.mjs +0 -89
- package/dist/cli/core/scan.mjs +0 -40
- package/dist/cli/core/silgi.mjs +0 -77
- package/dist/cli/core/storage.mjs +0 -11
- package/dist/cli/core/templates.mjs +0 -29
- package/dist/cli/module/exportScan.mjs +0 -69
- package/dist/cli/module/install.mjs +0 -52
- package/dist/cli/module/scan.mjs +0 -141
- package/dist/cli/utils/generateRouterDTS.mjs +0 -84
- package/dist/cli/utils/ignore.mjs +0 -46
- package/dist/cli/utils/readCoreFile.mjs +0 -47
- package/dist/cli/utils/scan.mjs +0 -147
- package/dist/cli/utils/storage.mjs +0 -21
- package/dist/cli/utils/uri.mjs +0 -71
- package/dist/core/config/defaults.mjs +0 -96
- package/dist/core/config/loader.mjs +0 -98
- package/dist/core/config/resolvers/compatibility.mjs +0 -90
- package/dist/core/config/resolvers/imports.mjs +0 -96
- package/dist/core/config/resolvers/paths.mjs +0 -194
- package/dist/core/config/resolvers/storage.mjs +0 -25
- package/dist/core/config/resolvers/url.mjs +0 -7
- package/dist/core/createSilgi.mjs +0 -84
- package/dist/core/error.mjs +0 -227
- package/dist/core/fetch/ofetch.mjs +0 -35
- package/dist/core/parser.mjs +0 -136
- package/dist/core/silgi.mjs +0 -114
- package/dist/core/silgiApp.mjs +0 -15
- package/dist/core/unctx.mjs +0 -27
- package/dist/core/uris/uri.mjs +0 -33
- package/dist/core/uris/utils.mjs +0 -127
- package/dist/core/utils/event.mjs +0 -5
- package/dist/core/utils/global.mjs +0 -12
- package/dist/core/utils/merge.mjs +0 -25
- package/dist/core/utils/schema.mjs +0 -5
- package/dist/core/utils/service.mjs +0 -5
- package/dist/core/utils/shared.mjs +0 -5
- package/dist/core/utils/storage.mjs +0 -70
- package/dist/ecosystem/nitro/module.mjs +0 -62
- package/dist/kit/esm.mjs +0 -10
- package/dist/kit/fs.mjs +0 -25
- package/dist/kit/isFramework.mjs +0 -25
- package/dist/kit/logger.mjs +0 -8
- package/dist/kit/module.mjs +0 -73
- package/dist/kit/path.mjs +0 -34
- package/dist/kit/preset.mjs +0 -6
- package/dist/kit/resolve.mjs +0 -78
- package/dist/kit/template.mjs +0 -47
- package/dist/kit/utils.mjs +0 -20
- package/dist/package.json.mjs +0 -5
- package/dist/schema/common.mjs +0 -43
- package/dist/schema/index.mjs +0 -9
- package/dist/schema/internal.mjs +0 -22
- /package/dist/cli/{commands/init.mjs → init.mjs} +0 -0
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
const vueShim = {
|
|
2
|
-
filename: "types/vue-shim.d.ts",
|
|
3
|
-
getContents: ({ app }) => {
|
|
4
|
-
if (!app.options.typescript.shim) {
|
|
5
|
-
return "";
|
|
6
|
-
}
|
|
7
|
-
return [
|
|
8
|
-
"declare module '*.vue' {",
|
|
9
|
-
" import { DefineComponent } from 'vue'",
|
|
10
|
-
" const component: DefineComponent<{}, {}, any>",
|
|
11
|
-
" export default component",
|
|
12
|
-
"}"
|
|
13
|
-
].join("\n");
|
|
14
|
-
}
|
|
15
|
-
};
|
|
16
|
-
const pluginsDeclaration = {
|
|
17
|
-
filename: "types/plugins.d.ts",
|
|
18
|
-
getContents: async () => {
|
|
19
|
-
return `
|
|
20
|
-
declare module 'nuxt' {
|
|
21
|
-
interface NuxtApp {
|
|
22
|
-
$myPlugin: any;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
`;
|
|
26
|
-
}
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
export { pluginsDeclaration, vueShim };
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { pascalCase } from 'scule';
|
|
2
|
-
import { relativeWithDot } from 'silgi/kit';
|
|
3
|
-
|
|
4
|
-
async function registerModuleExportScan(silgi) {
|
|
5
|
-
silgi.hook("prepare:schema.ts", async (options) => {
|
|
6
|
-
for (const module of silgi.scanModules) {
|
|
7
|
-
const exports = module.meta.exports;
|
|
8
|
-
if (!exports?.length)
|
|
9
|
-
continue;
|
|
10
|
-
const configKey = module.meta.configKey;
|
|
11
|
-
const moduleName = module.meta.name || module.meta._packageName;
|
|
12
|
-
options.importItems[configKey] = {
|
|
13
|
-
import: [],
|
|
14
|
-
from: module.meta._packageName ? moduleName : relativeWithDot(silgi.options.build.typesDir, module.entryPath)
|
|
15
|
-
};
|
|
16
|
-
const exportedTypes = exports.filter((exp) => exp.type).map((exp) => exp.name);
|
|
17
|
-
if (exportedTypes.includes("ModuleOptions")) {
|
|
18
|
-
const importName = pascalCase(`${configKey}Config`);
|
|
19
|
-
options.importItems[configKey].import.push({
|
|
20
|
-
name: `ModuleOptions as ${importName}`,
|
|
21
|
-
type: true
|
|
22
|
-
});
|
|
23
|
-
options.configs.push({ key: configKey, value: importName });
|
|
24
|
-
}
|
|
25
|
-
if (exportedTypes.includes("ModuleRuntimeContext")) {
|
|
26
|
-
const importName = pascalCase(`${configKey}Context`);
|
|
27
|
-
options.importItems[configKey].import.push({
|
|
28
|
-
name: `ModuleRuntimeContext as ${importName}`,
|
|
29
|
-
type: true
|
|
30
|
-
});
|
|
31
|
-
options.contexts.push({ key: configKey, value: importName });
|
|
32
|
-
}
|
|
33
|
-
if (exportedTypes.includes("ModuleRuntimeMethods")) {
|
|
34
|
-
const importName = pascalCase(`${configKey}Method`);
|
|
35
|
-
options.importItems[configKey].import.push({
|
|
36
|
-
name: `ModuleRuntimeMethods as ${importName}`,
|
|
37
|
-
type: true
|
|
38
|
-
});
|
|
39
|
-
options.methods.push({ key: configKey, value: importName });
|
|
40
|
-
}
|
|
41
|
-
if (exportedTypes.includes("ModuleRuntimeShared")) {
|
|
42
|
-
const importName = pascalCase(`${configKey}Shared`);
|
|
43
|
-
options.importItems[configKey].import.push({
|
|
44
|
-
name: `ModuleRuntimeShared as ${importName}`,
|
|
45
|
-
type: true
|
|
46
|
-
});
|
|
47
|
-
options.shareds.push({ key: configKey, value: importName });
|
|
48
|
-
}
|
|
49
|
-
if (exportedTypes.includes("ModuleHooks")) {
|
|
50
|
-
const importName = pascalCase(`${configKey}Hooks`);
|
|
51
|
-
options.importItems[configKey].import.push({
|
|
52
|
-
name: `ModuleHooks as ${importName}`,
|
|
53
|
-
type: true
|
|
54
|
-
});
|
|
55
|
-
options.hooks.push({ key: configKey, value: importName });
|
|
56
|
-
}
|
|
57
|
-
if (exportedTypes.includes("ModuleRuntimeHooks")) {
|
|
58
|
-
const importName = pascalCase(`${configKey}RuntimeHooks`);
|
|
59
|
-
options.importItems[configKey].import.push({
|
|
60
|
-
name: `ModuleRuntimeHooks as ${importName}`,
|
|
61
|
-
type: true
|
|
62
|
-
});
|
|
63
|
-
options.runtimeHooks.push({ key: configKey, value: importName });
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
export { registerModuleExportScan };
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { createJiti } from 'dev-jiti';
|
|
2
|
-
import { useSilgiCLI } from 'silgi/core';
|
|
3
|
-
import { hasInstalledModule } from '../utils/compatibility.mjs';
|
|
4
|
-
|
|
5
|
-
async function loadSilgiModuleInstance(silgiModule) {
|
|
6
|
-
if (typeof silgiModule === "string") {
|
|
7
|
-
throw new TypeError(`Could not load \`${silgiModule}\`. Is it installed?`);
|
|
8
|
-
}
|
|
9
|
-
if (typeof silgiModule !== "function") {
|
|
10
|
-
throw new TypeError(`Nuxt module should be a function: ${silgiModule}`);
|
|
11
|
-
}
|
|
12
|
-
return { silgiModule };
|
|
13
|
-
}
|
|
14
|
-
async function installModules(silgi) {
|
|
15
|
-
const jiti = createJiti(silgi.options.rootDir, {
|
|
16
|
-
alias: silgi.options.alias
|
|
17
|
-
});
|
|
18
|
-
for (const module of silgi.scanModules) {
|
|
19
|
-
if (hasInstalledModule(module.meta.configKey)) {
|
|
20
|
-
silgi.logger.info(`Module ${module.meta.configKey} installed`);
|
|
21
|
-
}
|
|
22
|
-
try {
|
|
23
|
-
const silgiModule = await jiti.import(module.entryPath, {
|
|
24
|
-
default: true,
|
|
25
|
-
conditions: silgi.options.conditions
|
|
26
|
-
});
|
|
27
|
-
if (silgiModule.name !== "silgiNormalizedModule") {
|
|
28
|
-
silgi.scanModules = silgi.scanModules.filter((m) => m.entryPath !== module.entryPath);
|
|
29
|
-
continue;
|
|
30
|
-
}
|
|
31
|
-
await installModule(silgiModule, silgi);
|
|
32
|
-
} catch (err) {
|
|
33
|
-
silgi.logger.error(err);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
async function installModule(moduleToInstall, silgi = useSilgiCLI(), inlineOptions) {
|
|
38
|
-
const { silgiModule } = await loadSilgiModuleInstance(moduleToInstall);
|
|
39
|
-
const res = await silgiModule({}, silgi) ?? {};
|
|
40
|
-
if (res === false) {
|
|
41
|
-
return false;
|
|
42
|
-
}
|
|
43
|
-
const metaData = await silgiModule.getMeta?.();
|
|
44
|
-
const installedModule = silgi.scanModules.find((m) => m.meta.configKey === metaData?.configKey);
|
|
45
|
-
if (installedModule) {
|
|
46
|
-
installedModule.installed = true;
|
|
47
|
-
} else {
|
|
48
|
-
throw new Error(`Module ${metaData?.name} not found`);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export { installModules, loadSilgiModuleInstance };
|
package/dist/cli/module/scan.mjs
DELETED
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
import { existsSync, promises } from 'node:fs';
|
|
2
|
-
import { pathToFileURL, fileURLToPath } from 'node:url';
|
|
3
|
-
import { consola } from 'consola';
|
|
4
|
-
import { createJiti } from 'dev-jiti';
|
|
5
|
-
import { resolve as resolve$1 } from 'mlly';
|
|
6
|
-
import { resolve, join, isAbsolute } from 'pathe';
|
|
7
|
-
import { resolveAlias, resolvePath } from 'silgi/kit';
|
|
8
|
-
import { isRelative } from 'ufo';
|
|
9
|
-
import { scanExports } from 'unimport';
|
|
10
|
-
|
|
11
|
-
const logger = consola;
|
|
12
|
-
async function _resolveSilgiModule(mod, silgi) {
|
|
13
|
-
let _url;
|
|
14
|
-
let buildTimeModuleMeta = {};
|
|
15
|
-
const jiti = createJiti(silgi.options.rootDir, {
|
|
16
|
-
alias: silgi.options.alias
|
|
17
|
-
});
|
|
18
|
-
if (typeof mod === "string") {
|
|
19
|
-
const paths = /* @__PURE__ */ new Set();
|
|
20
|
-
mod = resolveAlias(mod, silgi.options.alias);
|
|
21
|
-
if (isRelative(mod)) {
|
|
22
|
-
mod = resolve(silgi.options.rootDir, mod);
|
|
23
|
-
}
|
|
24
|
-
paths.add(join(mod, "module"));
|
|
25
|
-
paths.add(mod);
|
|
26
|
-
for (const path of paths) {
|
|
27
|
-
try {
|
|
28
|
-
const src = isAbsolute(path) ? pathToFileURL(await resolvePath(path, { fallbackToOriginal: false, extensions: silgi.options.extensions })).href : await resolve$1(path, { url: silgi.options.modulesDir.map((m) => pathToFileURL(m.replace(/\/node_modules\/?$/, ""))), extensions: silgi.options.extensions });
|
|
29
|
-
mod = await jiti.import(src, {
|
|
30
|
-
default: true,
|
|
31
|
-
conditions: silgi.options.conditions
|
|
32
|
-
});
|
|
33
|
-
_url = fileURLToPath(new URL(src));
|
|
34
|
-
const moduleMetadataPath = new URL("module.json", src);
|
|
35
|
-
if (existsSync(moduleMetadataPath)) {
|
|
36
|
-
buildTimeModuleMeta = JSON.parse(await promises.readFile(moduleMetadataPath, "utf-8"));
|
|
37
|
-
} else {
|
|
38
|
-
if (typeof mod === "function") {
|
|
39
|
-
const meta = await mod.getMeta?.();
|
|
40
|
-
const _exports = await scanExports(_url, true);
|
|
41
|
-
buildTimeModuleMeta = {
|
|
42
|
-
...meta,
|
|
43
|
-
exports: _exports.map(({ from, ...rest }) => rest)
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
break;
|
|
48
|
-
} catch (error) {
|
|
49
|
-
const code = error.code;
|
|
50
|
-
if (code === "MODULE_NOT_FOUND" || code === "ERR_PACKAGE_PATH_NOT_EXPORTED" || code === "ERR_MODULE_NOT_FOUND" || code === "ERR_UNSUPPORTED_DIR_IMPORT" || code === "ENOTDIR") {
|
|
51
|
-
continue;
|
|
52
|
-
}
|
|
53
|
-
logger.error(`Error while importing module \`${mod}\`: ${error}`);
|
|
54
|
-
throw error;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
if (!buildTimeModuleMeta) {
|
|
59
|
-
throw new Error(`Module ${mod} is not a valid Silgi module`);
|
|
60
|
-
}
|
|
61
|
-
if (typeof mod === "function") {
|
|
62
|
-
if (silgi.scanModules.some((m) => m.meta?.configKey === buildTimeModuleMeta.configKey)) {
|
|
63
|
-
throw new Error(`Module with key \`${buildTimeModuleMeta.configKey}\` already exists`);
|
|
64
|
-
}
|
|
65
|
-
silgi.scanModules.push({
|
|
66
|
-
meta: buildTimeModuleMeta,
|
|
67
|
-
entryPath: _url,
|
|
68
|
-
installed: false,
|
|
69
|
-
options: await mod.getOptions?.() || {}
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
async function scanModules(silgi) {
|
|
74
|
-
const _modules = [
|
|
75
|
-
...silgi.options._modules,
|
|
76
|
-
...silgi.options.modules
|
|
77
|
-
];
|
|
78
|
-
for await (const mod of _modules) {
|
|
79
|
-
await _resolveSilgiModule(mod, silgi);
|
|
80
|
-
}
|
|
81
|
-
const moduleMap = new Map(
|
|
82
|
-
silgi.scanModules.map((m) => [m.meta?.configKey, m])
|
|
83
|
-
);
|
|
84
|
-
const graph = createDependencyGraph(silgi.scanModules);
|
|
85
|
-
const sortedKeys = topologicalSort(graph);
|
|
86
|
-
const modules = sortedKeys.map((key) => moduleMap.get(key)).filter((module) => Boolean(module));
|
|
87
|
-
silgi.scanModules = modules;
|
|
88
|
-
}
|
|
89
|
-
function createDependencyGraph(modules) {
|
|
90
|
-
const graph = /* @__PURE__ */ new Map();
|
|
91
|
-
modules.forEach((module) => {
|
|
92
|
-
const key = module.meta?.configKey;
|
|
93
|
-
if (key) {
|
|
94
|
-
graph.set(key, /* @__PURE__ */ new Set());
|
|
95
|
-
}
|
|
96
|
-
});
|
|
97
|
-
modules.forEach((module) => {
|
|
98
|
-
const key = module.meta?.configKey;
|
|
99
|
-
const deps = module.meta?.dependencies || [];
|
|
100
|
-
if (key && deps.length > 0) {
|
|
101
|
-
const modulesDeps = graph.get(key) || /* @__PURE__ */ new Set();
|
|
102
|
-
deps.forEach((dep) => {
|
|
103
|
-
if (graph.has(dep)) {
|
|
104
|
-
modulesDeps.add(dep);
|
|
105
|
-
}
|
|
106
|
-
});
|
|
107
|
-
graph.set(key, modulesDeps);
|
|
108
|
-
}
|
|
109
|
-
});
|
|
110
|
-
return graph;
|
|
111
|
-
}
|
|
112
|
-
function topologicalSort(graph) {
|
|
113
|
-
const visited = /* @__PURE__ */ new Set();
|
|
114
|
-
const temp = /* @__PURE__ */ new Set();
|
|
115
|
-
const order = [];
|
|
116
|
-
function visit(node) {
|
|
117
|
-
if (temp.has(node))
|
|
118
|
-
throw new Error(`Circular dependency detected: ${node}`);
|
|
119
|
-
if (visited.has(node))
|
|
120
|
-
return;
|
|
121
|
-
temp.add(node);
|
|
122
|
-
const deps = graph.get(node) || /* @__PURE__ */ new Set();
|
|
123
|
-
for (const dep of deps) {
|
|
124
|
-
visit(dep);
|
|
125
|
-
}
|
|
126
|
-
temp.delete(node);
|
|
127
|
-
visited.add(node);
|
|
128
|
-
order.unshift(node);
|
|
129
|
-
}
|
|
130
|
-
for (const [node, deps] of graph.entries()) {
|
|
131
|
-
if (deps.size === 0 && !visited.has(node))
|
|
132
|
-
visit(node);
|
|
133
|
-
}
|
|
134
|
-
for (const node of graph.keys()) {
|
|
135
|
-
if (!visited.has(node))
|
|
136
|
-
visit(node);
|
|
137
|
-
}
|
|
138
|
-
return order;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
export { logger, scanModules };
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import { promises } from 'node:fs';
|
|
2
|
-
import { resolve } from 'pathe';
|
|
3
|
-
|
|
4
|
-
async function generateRouterDTS(silgi) {
|
|
5
|
-
silgi.hook("finish:types", async (data) => {
|
|
6
|
-
const uris = data.object.uris;
|
|
7
|
-
const subPath = "srn";
|
|
8
|
-
const groupedPaths = /* @__PURE__ */ new Map();
|
|
9
|
-
Object.entries(uris || {}).forEach(([key, params]) => {
|
|
10
|
-
const [service, resource, method, action] = key.split("/");
|
|
11
|
-
const basePath = params ? `${subPath}/${service}/${resource}/${action}/${params}` : `${subPath}/${service}/${resource}/${action}`;
|
|
12
|
-
const fullPath = `${subPath}/${service}/${resource}/${action}`;
|
|
13
|
-
if (!groupedPaths.has(basePath)) {
|
|
14
|
-
groupedPaths.set(basePath, /* @__PURE__ */ new Map());
|
|
15
|
-
}
|
|
16
|
-
groupedPaths.get(basePath)?.set(method.toLowerCase(), fullPath);
|
|
17
|
-
});
|
|
18
|
-
const keys = [
|
|
19
|
-
" keys: {",
|
|
20
|
-
Array.from(groupedPaths.entries()).map(([basePath, methods]) => {
|
|
21
|
-
return ` '/${basePath}': {${Array.from(methods.entries()).map(([method, path]) => `
|
|
22
|
-
${method}: '/${path}'`).join(",")}
|
|
23
|
-
}`;
|
|
24
|
-
}).join(",\n"),
|
|
25
|
-
" }",
|
|
26
|
-
""
|
|
27
|
-
].join("\n");
|
|
28
|
-
const groupedRoutes = Object.entries(uris || {}).reduce((acc, [key, _params]) => {
|
|
29
|
-
const [service, resource, method, action] = key.split("/");
|
|
30
|
-
const routePath = `${subPath}/${service}/${resource}/${action}`;
|
|
31
|
-
if (!acc[routePath]) {
|
|
32
|
-
acc[routePath] = {};
|
|
33
|
-
}
|
|
34
|
-
acc[routePath][method] = {
|
|
35
|
-
input: `ExtractInputFromURI<'${key}'>`,
|
|
36
|
-
output: `ExtractOutputFromURI<'${key}'>`,
|
|
37
|
-
params: `ExtractRouterParamsFromURI<'${key}'>['params']`
|
|
38
|
-
};
|
|
39
|
-
return acc;
|
|
40
|
-
}, {});
|
|
41
|
-
const routerTypes = Object.entries(groupedRoutes).map(([path, methods]) => {
|
|
42
|
-
const methodEntries = Object.entries(methods).map(([method, { input, output, params }]) => {
|
|
43
|
-
return ` '${method}': {
|
|
44
|
-
input: ${input},
|
|
45
|
-
output: ${output}
|
|
46
|
-
params: ${params}
|
|
47
|
-
}`;
|
|
48
|
-
}).join(",\n");
|
|
49
|
-
return ` '/${path}': {
|
|
50
|
-
${methodEntries}
|
|
51
|
-
}`;
|
|
52
|
-
});
|
|
53
|
-
const nitro = [
|
|
54
|
-
"declare module 'nitropack/types' {",
|
|
55
|
-
" interface InternalApi extends RouterTypes {}",
|
|
56
|
-
"}"
|
|
57
|
-
];
|
|
58
|
-
const content = [
|
|
59
|
-
keys.slice(0, -1),
|
|
60
|
-
// son satırdaki boş satırı kaldır
|
|
61
|
-
...routerTypes
|
|
62
|
-
].join(",\n");
|
|
63
|
-
const context = [
|
|
64
|
-
"import type { ExtractInputFromURI, ExtractOutputFromURI, ExtractRouterParamsFromURI } from 'silgi/types'",
|
|
65
|
-
"",
|
|
66
|
-
"export interface RouterTypes {",
|
|
67
|
-
content,
|
|
68
|
-
"}",
|
|
69
|
-
"",
|
|
70
|
-
"declare module 'silgi/types' {",
|
|
71
|
-
" interface SilgiRouterTypes extends RouterTypes {",
|
|
72
|
-
" }",
|
|
73
|
-
"}",
|
|
74
|
-
"",
|
|
75
|
-
silgi.options.preset === "h3" || silgi.options.preset === "nitro" ? nitro.join("\n") : "",
|
|
76
|
-
"",
|
|
77
|
-
"export {}"
|
|
78
|
-
].join("\n");
|
|
79
|
-
const outputPath = resolve(silgi.options.build.typesDir, "silgi-routes.d.ts");
|
|
80
|
-
await promises.writeFile(outputPath, context);
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
export { generateRouterDTS };
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { existsSync, readFileSync } from 'node:fs';
|
|
2
|
-
import ignore from 'ignore';
|
|
3
|
-
import { relative, join } from 'pathe';
|
|
4
|
-
|
|
5
|
-
function resolveIgnorePatterns(silgi, relativePath) {
|
|
6
|
-
if (!silgi) {
|
|
7
|
-
return [];
|
|
8
|
-
}
|
|
9
|
-
const ignorePatterns = silgi.options.ignore.flatMap((s) => resolveGroupSyntax(s));
|
|
10
|
-
const nuxtignoreFile = join(silgi.options.rootDir, ".nuxtignore");
|
|
11
|
-
if (existsSync(nuxtignoreFile)) {
|
|
12
|
-
const contents = readFileSync(nuxtignoreFile, "utf-8");
|
|
13
|
-
ignorePatterns.push(...contents.trim().split(/\r?\n/));
|
|
14
|
-
}
|
|
15
|
-
return ignorePatterns;
|
|
16
|
-
}
|
|
17
|
-
function isIgnored(pathname, silgi, _stats) {
|
|
18
|
-
if (!silgi) {
|
|
19
|
-
return false;
|
|
20
|
-
}
|
|
21
|
-
if (!silgi._ignore) {
|
|
22
|
-
silgi._ignore = ignore(silgi.options.ignoreOptions);
|
|
23
|
-
silgi._ignore.add(resolveIgnorePatterns(silgi));
|
|
24
|
-
}
|
|
25
|
-
const relativePath = relative(silgi.options.rootDir, pathname);
|
|
26
|
-
if (relativePath[0] === "." && relativePath[1] === ".") {
|
|
27
|
-
return false;
|
|
28
|
-
}
|
|
29
|
-
return !!(relativePath && silgi._ignore.ignores(relativePath));
|
|
30
|
-
}
|
|
31
|
-
function resolveGroupSyntax(group) {
|
|
32
|
-
let groups = [group];
|
|
33
|
-
while (groups.some((group2) => group2.includes("{"))) {
|
|
34
|
-
groups = groups.flatMap((group2) => {
|
|
35
|
-
const [head, ...tail] = group2.split("{");
|
|
36
|
-
if (tail.length) {
|
|
37
|
-
const [body = "", ...rest] = tail.join("{").split("}");
|
|
38
|
-
return body.split(",").map((part) => `${head}${part}${rest.join("")}`);
|
|
39
|
-
}
|
|
40
|
-
return group2;
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
return groups;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export { isIgnored, resolveGroupSyntax, resolveIgnorePatterns };
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { promises } from 'node:fs';
|
|
2
|
-
import { createJiti } from 'dev-jiti';
|
|
3
|
-
import { resolve } from 'pathe';
|
|
4
|
-
|
|
5
|
-
async function readCoreFile(silgi) {
|
|
6
|
-
const path = resolve(silgi.options.silgi.serverDir, "core.ts");
|
|
7
|
-
const context = await promises.readFile(path, { encoding: "utf-8" });
|
|
8
|
-
const injectedResult = await silgi.unimport.injectImports(context, path);
|
|
9
|
-
if (!injectedResult) {
|
|
10
|
-
throw new Error("Failed to inject imports");
|
|
11
|
-
}
|
|
12
|
-
const jiti = createJiti(silgi.options.rootDir, {
|
|
13
|
-
fsCache: false,
|
|
14
|
-
moduleCache: false,
|
|
15
|
-
debug: silgi.options.debug,
|
|
16
|
-
alias: silgi.options.alias
|
|
17
|
-
});
|
|
18
|
-
const coreFile = await jiti.evalModule(
|
|
19
|
-
injectedResult.code,
|
|
20
|
-
{
|
|
21
|
-
filename: path,
|
|
22
|
-
async: true,
|
|
23
|
-
conditions: silgi.options.conditions
|
|
24
|
-
},
|
|
25
|
-
async (data, name) => {
|
|
26
|
-
return (await silgi.unimport.injectImports(data, name)).code;
|
|
27
|
-
}
|
|
28
|
-
);
|
|
29
|
-
silgi.uris = coreFile.uris;
|
|
30
|
-
silgi.schemas = coreFile.schemas;
|
|
31
|
-
silgi.services = coreFile.services;
|
|
32
|
-
silgi.shareds = coreFile.shareds;
|
|
33
|
-
silgi.modulesURIs = coreFile.modulesURIs;
|
|
34
|
-
return {
|
|
35
|
-
context,
|
|
36
|
-
object: {
|
|
37
|
-
schemas: coreFile.schemas,
|
|
38
|
-
uris: coreFile.uris,
|
|
39
|
-
services: coreFile.services,
|
|
40
|
-
shareds: coreFile.shareds,
|
|
41
|
-
modulesURIs: coreFile.modulesURIs
|
|
42
|
-
},
|
|
43
|
-
path
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export { readCoreFile };
|
package/dist/cli/utils/scan.mjs
DELETED
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
import { readFileSync } from 'node:fs';
|
|
2
|
-
import { readdir } from 'node:fs/promises';
|
|
3
|
-
import { consola } from 'consola';
|
|
4
|
-
import { globby } from 'globby';
|
|
5
|
-
import { dirname, basename, relative, join, resolve, extname } from 'pathe';
|
|
6
|
-
import { SchemaParser } from 'silgi/core';
|
|
7
|
-
import { relativeWithDot } from 'silgi/kit';
|
|
8
|
-
import { withTrailingSlash } from 'ufo';
|
|
9
|
-
import { isIgnored } from './ignore.mjs';
|
|
10
|
-
|
|
11
|
-
async function scanFiles(silgi) {
|
|
12
|
-
const filePaths = /* @__PURE__ */ new Set();
|
|
13
|
-
const scannedPaths = [];
|
|
14
|
-
const dir = silgi.options.serverDir;
|
|
15
|
-
const files = (await globby(dir, { cwd: silgi.options.rootDir, ignore: silgi.options.ignore })).sort();
|
|
16
|
-
if (files.length) {
|
|
17
|
-
const siblings = await readdir(dirname(dir)).catch(() => []);
|
|
18
|
-
const directory = basename(dir);
|
|
19
|
-
if (!siblings.includes(directory)) {
|
|
20
|
-
const directoryLowerCase = directory.toLowerCase();
|
|
21
|
-
const caseCorrected = siblings.find((sibling) => sibling.toLowerCase() === directoryLowerCase);
|
|
22
|
-
if (caseCorrected) {
|
|
23
|
-
const original = relative(silgi.options.serverDir, dir);
|
|
24
|
-
const corrected = relative(silgi.options.serverDir, join(dirname(dir), caseCorrected));
|
|
25
|
-
consola.warn(`Components not scanned from \`~/${corrected}\`. Did you mean to name the directory \`~/${original}\` instead?`);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
for (const _file of files) {
|
|
30
|
-
const filePath = resolve(dir, _file);
|
|
31
|
-
if (scannedPaths.find((d) => filePath.startsWith(withTrailingSlash(d))) || isIgnored(filePath, silgi)) {
|
|
32
|
-
continue;
|
|
33
|
-
}
|
|
34
|
-
if (filePaths.has(filePath)) {
|
|
35
|
-
continue;
|
|
36
|
-
}
|
|
37
|
-
filePaths.add(filePath);
|
|
38
|
-
if (silgi.options.extensions.includes(extname(filePath))) {
|
|
39
|
-
const parser = new SchemaParser({
|
|
40
|
-
debug: false
|
|
41
|
-
});
|
|
42
|
-
const readfile = readFileSync(filePath, "utf-8");
|
|
43
|
-
const { exportVariables, parseInterfaceDeclarations } = parser.parseExports(readfile, filePath);
|
|
44
|
-
const createServices = exportVariables("createService", filePath);
|
|
45
|
-
if (createServices.length > 0) {
|
|
46
|
-
for (const createService of createServices) {
|
|
47
|
-
const { exportName, path } = createService;
|
|
48
|
-
silgi.hook("prepare:core.ts", (options) => {
|
|
49
|
-
options.services.push(exportName);
|
|
50
|
-
});
|
|
51
|
-
silgi.hook("prepare:core.ts", (options) => {
|
|
52
|
-
options.importItems[path] ??= {
|
|
53
|
-
import: [],
|
|
54
|
-
from: relativeWithDot(silgi.options.silgi.serverDir, path)
|
|
55
|
-
};
|
|
56
|
-
options.importItems[path].import.push({
|
|
57
|
-
name: exportName
|
|
58
|
-
});
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
const createSchemas = exportVariables("createSchema", filePath);
|
|
63
|
-
if (createSchemas.length > 0) {
|
|
64
|
-
for (const createSchema of createSchemas) {
|
|
65
|
-
const { exportName, path } = createSchema;
|
|
66
|
-
silgi.hook("prepare:core.ts", (options) => {
|
|
67
|
-
options.schemas.push(exportName);
|
|
68
|
-
});
|
|
69
|
-
silgi.hook("prepare:core.ts", (options) => {
|
|
70
|
-
options.importItems[path] ??= {
|
|
71
|
-
import: [],
|
|
72
|
-
from: relativeWithDot(silgi.options.silgi.serverDir, path)
|
|
73
|
-
};
|
|
74
|
-
options.importItems[path].import.push({
|
|
75
|
-
name: exportName
|
|
76
|
-
});
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
const createShareds = exportVariables("createShared", filePath);
|
|
81
|
-
if (createShareds.length > 0) {
|
|
82
|
-
for (const createShared of createShareds) {
|
|
83
|
-
const { exportName, path } = createShared;
|
|
84
|
-
silgi.hook("prepare:core.ts", (options) => {
|
|
85
|
-
options.shareds.push(exportName);
|
|
86
|
-
});
|
|
87
|
-
silgi.hook("prepare:core.ts", (options) => {
|
|
88
|
-
options.importItems[path] ??= {
|
|
89
|
-
import: [],
|
|
90
|
-
// Relative path kaldirmamiz gerekiyor bunlar hooklarin bittigi yerde karar verilmeli.
|
|
91
|
-
from: relativeWithDot(silgi.options.silgi.serverDir, path)
|
|
92
|
-
};
|
|
93
|
-
options.importItems[path].import.push({
|
|
94
|
-
name: exportName
|
|
95
|
-
});
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
const sharedsTypes = parseInterfaceDeclarations("ExtendShared", filePath);
|
|
100
|
-
if (sharedsTypes.length > 0) {
|
|
101
|
-
for (const sharedType of sharedsTypes) {
|
|
102
|
-
const { exportName, path } = sharedType;
|
|
103
|
-
silgi.hook("prepare:schema.ts", (options) => {
|
|
104
|
-
options.shareds.push({
|
|
105
|
-
key: exportName,
|
|
106
|
-
value: exportName
|
|
107
|
-
});
|
|
108
|
-
});
|
|
109
|
-
silgi.hook("prepare:schema.ts", (options) => {
|
|
110
|
-
options.importItems[path] ??= {
|
|
111
|
-
import: [],
|
|
112
|
-
from: path
|
|
113
|
-
};
|
|
114
|
-
options.importItems[path].import.push({
|
|
115
|
-
name: exportName,
|
|
116
|
-
type: true
|
|
117
|
-
});
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
const contextTypes = parseInterfaceDeclarations("ExtendContext", filePath);
|
|
122
|
-
if (contextTypes.length > 0) {
|
|
123
|
-
for (const contextType of contextTypes) {
|
|
124
|
-
const { exportName, path } = contextType;
|
|
125
|
-
silgi.hook("prepare:schema.ts", (options) => {
|
|
126
|
-
options.contexts.push({
|
|
127
|
-
key: exportName,
|
|
128
|
-
value: exportName
|
|
129
|
-
});
|
|
130
|
-
});
|
|
131
|
-
silgi.hook("prepare:schema.ts", (options) => {
|
|
132
|
-
options.importItems[path] ??= {
|
|
133
|
-
import: [],
|
|
134
|
-
from: path
|
|
135
|
-
};
|
|
136
|
-
options.importItems[path].import.push({
|
|
137
|
-
name: exportName,
|
|
138
|
-
type: true
|
|
139
|
-
});
|
|
140
|
-
});
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
export { scanFiles };
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { klona } from 'klona';
|
|
2
|
-
import { createStorage, builtinDrivers } from 'unstorage';
|
|
3
|
-
|
|
4
|
-
async function createStorageCLI(silgi) {
|
|
5
|
-
const storage = createStorage();
|
|
6
|
-
const mounts = klona({
|
|
7
|
-
...silgi.options.storage,
|
|
8
|
-
...silgi.options.devStorage
|
|
9
|
-
});
|
|
10
|
-
for (const [path, opts] of Object.entries(mounts)) {
|
|
11
|
-
if (opts.driver) {
|
|
12
|
-
const driver = await import(builtinDrivers[opts.driver] || opts.driver).then((r) => r.default || r);
|
|
13
|
-
storage.mount(path, driver(opts));
|
|
14
|
-
} else {
|
|
15
|
-
silgi.logger.warn(`No \`driver\` set for storage mount point "${path}".`);
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
return storage;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export { createStorageCLI };
|