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
package/dist/kit/index.mjs
CHANGED
|
@@ -1,1039 +1,23 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import { hash
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
19
|
-
import { resolveAlias
|
|
20
|
-
import
|
|
21
|
-
import
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
const RELATIVE_RE = /^([^.])/;
|
|
25
|
-
function relativeWithDot(from, to) {
|
|
26
|
-
return relative(from, to).replace(RELATIVE_RE, "./$1") || ".";
|
|
27
|
-
}
|
|
28
|
-
function toArray(value) {
|
|
29
|
-
return Array.isArray(value) ? value : [value];
|
|
30
|
-
}
|
|
31
|
-
function filterInPlace(array, predicate) {
|
|
32
|
-
for (let i = array.length; i--; i >= 0) {
|
|
33
|
-
if (!predicate(array[i], i, array)) {
|
|
34
|
-
array.splice(i, 1);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
return array;
|
|
38
|
-
}
|
|
39
|
-
const MODE_RE = /\.(server|client)(\.\w+)*$/;
|
|
40
|
-
function hasSilgiModule(moduleKey, silgi = useSilgiCLI()) {
|
|
41
|
-
return silgi.scanModules.some(({ meta }) => meta.configKey === moduleKey) || Object.keys(silgi.scanModules).includes(moduleKey);
|
|
42
|
-
}
|
|
43
|
-
function hasInstalledModule(moduleKey, silgi = useSilgiCLI()) {
|
|
44
|
-
const find = silgi.scanModules.find(({ meta }) => meta.configKey === moduleKey);
|
|
45
|
-
return find?.installed ?? false;
|
|
46
|
-
}
|
|
47
|
-
const baseHeaderBannerComment = [
|
|
48
|
-
"// DO NOT EDIT THIS FILE",
|
|
49
|
-
"// This file is generated by Silgi",
|
|
50
|
-
"/* eslint-disable */",
|
|
51
|
-
"/* prettier-ignore */",
|
|
52
|
-
"/* tslint:disable */"
|
|
53
|
-
];
|
|
54
|
-
function processFilePath(src) {
|
|
55
|
-
const silgi = useSilgiCLI();
|
|
56
|
-
if (silgi.options.typescript.removeFileExtension) {
|
|
57
|
-
src = src.replace(/\.ts$/, "");
|
|
58
|
-
return src;
|
|
59
|
-
}
|
|
60
|
-
return src;
|
|
61
|
-
}
|
|
62
|
-
function isPresents(names) {
|
|
63
|
-
const silgi = useSilgiCLI();
|
|
64
|
-
return names.filter((name) => silgi.options.preset.includes(name)).length > 0;
|
|
65
|
-
}
|
|
66
|
-
function isRuntimePresents(names) {
|
|
67
|
-
const silgi = useSilgi();
|
|
68
|
-
return names.includes(silgi.options.present);
|
|
69
|
-
}
|
|
70
|
-
function removeExtension(filePath, force = false) {
|
|
71
|
-
const silgi = useSilgiCLI();
|
|
72
|
-
if (silgi.options.typescript.removeFileExtension || force) {
|
|
73
|
-
const ext = extname(filePath);
|
|
74
|
-
return ext ? filePath.slice(0, -ext.length) : filePath;
|
|
75
|
-
}
|
|
76
|
-
return filePath;
|
|
77
|
-
}
|
|
78
|
-
function getServicePath(_route) {
|
|
79
|
-
let method = "";
|
|
80
|
-
let type = "";
|
|
81
|
-
let route = _route;
|
|
82
|
-
const parts = route.split(":");
|
|
83
|
-
if (parts.length === 3) {
|
|
84
|
-
type = parts[0].toLowerCase();
|
|
85
|
-
method = parts[1].toUpperCase();
|
|
86
|
-
if (method === "GLOBAL" || method === "ALL") {
|
|
87
|
-
method = "";
|
|
88
|
-
}
|
|
89
|
-
route = parts[2];
|
|
90
|
-
} else if (parts.length === 2) {
|
|
91
|
-
method = parts[0].toUpperCase();
|
|
92
|
-
if (method === "GLOBAL" || method === "ALL") {
|
|
93
|
-
method = "";
|
|
94
|
-
}
|
|
95
|
-
route = parts[1];
|
|
96
|
-
}
|
|
97
|
-
return {
|
|
98
|
-
method,
|
|
99
|
-
type,
|
|
100
|
-
route
|
|
101
|
-
};
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
async function addCommands(data) {
|
|
105
|
-
useSilgiCLI$1().hook("prepare:commands", (commads) => {
|
|
106
|
-
commads.push(...toArray(data));
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
async function addCoreFile(data) {
|
|
111
|
-
const silgi = useSilgiCLI$1();
|
|
112
|
-
if (data.before)
|
|
113
|
-
silgi.hook("before:core.ts", data.before);
|
|
114
|
-
if (data.after)
|
|
115
|
-
silgi.hook("after:core.ts", data.after);
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
function addImports(data) {
|
|
119
|
-
const genImports = [
|
|
120
|
-
...data?.imports ?? []
|
|
121
|
-
];
|
|
122
|
-
const genTypeImports = [
|
|
123
|
-
...data?.typeImports ?? []
|
|
124
|
-
];
|
|
125
|
-
function addImportItem(data2) {
|
|
126
|
-
for (const item of toArray$1(data2)) {
|
|
127
|
-
const isSpecifier = genImports.some((i) => i.specifier === item.specifier);
|
|
128
|
-
if (isSpecifier) {
|
|
129
|
-
const index = genImports.findIndex((i) => i.specifier === item.specifier);
|
|
130
|
-
if (Array.isArray(genImports[index].imports)) {
|
|
131
|
-
genImports[index].imports ??= [];
|
|
132
|
-
genImports[index].imports.push(...toArray$1(item.imports));
|
|
133
|
-
} else {
|
|
134
|
-
genImports[index].imports = item.imports;
|
|
135
|
-
}
|
|
136
|
-
} else {
|
|
137
|
-
genImports.push({
|
|
138
|
-
specifier: item.specifier,
|
|
139
|
-
imports: item.imports,
|
|
140
|
-
options: item.options
|
|
141
|
-
});
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
function addImportItemType(data2) {
|
|
146
|
-
for (const item of toArray$1(data2)) {
|
|
147
|
-
const isSpecifier = genTypeImports.some((i) => i.specifier === item.specifier);
|
|
148
|
-
if (isSpecifier) {
|
|
149
|
-
const index = genTypeImports.findIndex((i) => i.specifier === item.specifier);
|
|
150
|
-
if (Array.isArray(genTypeImports[index].imports)) {
|
|
151
|
-
genTypeImports[index].imports ??= [];
|
|
152
|
-
const newImports = toArray$1(item.imports);
|
|
153
|
-
for (const newImport of newImports) {
|
|
154
|
-
const isDuplicate = genTypeImports[index].imports.some((existingImport) => {
|
|
155
|
-
if (typeof existingImport === "string" && typeof newImport === "string") {
|
|
156
|
-
return existingImport === newImport;
|
|
157
|
-
} else if (typeof existingImport === "object" && typeof newImport === "object") {
|
|
158
|
-
return existingImport.name === newImport.name && existingImport.as === newImport.as;
|
|
159
|
-
}
|
|
160
|
-
return false;
|
|
161
|
-
});
|
|
162
|
-
if (!isDuplicate) {
|
|
163
|
-
genTypeImports[index].imports.push(newImport);
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
} else {
|
|
167
|
-
genTypeImports[index].imports = item.imports;
|
|
168
|
-
}
|
|
169
|
-
} else {
|
|
170
|
-
genTypeImports.push({
|
|
171
|
-
specifier: item.specifier,
|
|
172
|
-
imports: item.imports,
|
|
173
|
-
options: item.options
|
|
174
|
-
});
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
return {
|
|
179
|
-
genImports,
|
|
180
|
-
genTypeImports,
|
|
181
|
-
addImportItem,
|
|
182
|
-
addImportItemType
|
|
183
|
-
};
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
187
|
-
async function addNPMPackage(data) {
|
|
188
|
-
const silgi = useSilgiCLI$1();
|
|
189
|
-
if (silgi.options.commandType !== "install") {
|
|
190
|
-
return;
|
|
191
|
-
}
|
|
192
|
-
for (const item of toArray(data)) {
|
|
193
|
-
if (item.when === false) {
|
|
194
|
-
continue;
|
|
195
|
-
}
|
|
196
|
-
const getPackageVersion = execSync(
|
|
197
|
-
`pnpm info ${item.name} version`,
|
|
198
|
-
{ encoding: "utf-8" }
|
|
199
|
-
);
|
|
200
|
-
silgi.logger.withTag("add-npm").success(
|
|
201
|
-
"Checking package version",
|
|
202
|
-
item.name,
|
|
203
|
-
getPackageVersion.trim()
|
|
204
|
-
);
|
|
205
|
-
let version = item.version || getPackageVersion.trim();
|
|
206
|
-
version = `^${version}`;
|
|
207
|
-
if (item.isDev) {
|
|
208
|
-
silgi.options.installPackages.devDependencies[item.name] = version;
|
|
209
|
-
} else {
|
|
210
|
-
silgi.options.installPackages.dependencies[item.name] = version;
|
|
211
|
-
}
|
|
212
|
-
await delay(50);
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
function defineFramework(preset) {
|
|
217
|
-
return {
|
|
218
|
-
/**
|
|
219
|
-
* Build the framework handler
|
|
220
|
-
* @param callback The callback function that will receive typed options (can be async)
|
|
221
|
-
*/
|
|
222
|
-
build(callback) {
|
|
223
|
-
return async function handler(options) {
|
|
224
|
-
await callback(options);
|
|
225
|
-
};
|
|
226
|
-
}
|
|
227
|
-
};
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
function hasError(type, silgi) {
|
|
231
|
-
silgi = silgi ?? tryUseSilgiCLI() ?? void 0;
|
|
232
|
-
if (silgi && silgi.errors.some((error) => error.type === type)) {
|
|
233
|
-
return true;
|
|
234
|
-
}
|
|
235
|
-
return false;
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
function directoryToURL(dir) {
|
|
239
|
-
return pathToFileURL(`${dir}/`);
|
|
240
|
-
}
|
|
241
|
-
async function tryResolveModule(id, url = import.meta.url) {
|
|
242
|
-
try {
|
|
243
|
-
return await resolvePath$1(id, { url });
|
|
244
|
-
} catch {
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
function prettyPath(p, highlight = true) {
|
|
249
|
-
p = relative(process.cwd(), p);
|
|
250
|
-
return highlight ? colors.cyan(p) : p;
|
|
251
|
-
}
|
|
252
|
-
function resolveSilgiPath(path, silgiCLIOptions, base) {
|
|
253
|
-
if (typeof path !== "string") {
|
|
254
|
-
throw new TypeError(`Invalid path: ${path}`);
|
|
255
|
-
}
|
|
256
|
-
path = _compilePathTemplate(path)(silgiCLIOptions);
|
|
257
|
-
for (const base2 in silgiCLIOptions.alias) {
|
|
258
|
-
if (path.startsWith(base2)) {
|
|
259
|
-
path = silgiCLIOptions.alias[base2] + path.slice(base2.length);
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
return resolve(base || silgiCLIOptions.srcDir, path);
|
|
263
|
-
}
|
|
264
|
-
function _compilePathTemplate(contents) {
|
|
265
|
-
return (params) => contents.replace(/\{\{ ?([\w.]+) ?\}\}/g, (_, match) => {
|
|
266
|
-
const val = getProperty(params, match);
|
|
267
|
-
if (!val) {
|
|
268
|
-
consola.warn(
|
|
269
|
-
`cannot resolve template param '${match}' in ${contents.slice(0, 20)}`
|
|
270
|
-
);
|
|
271
|
-
}
|
|
272
|
-
return val || `${match}`;
|
|
273
|
-
});
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
async function writeFile(file, contents, log = false) {
|
|
277
|
-
const silgi = useSilgiCLI();
|
|
278
|
-
if (silgi.errors.length) {
|
|
279
|
-
return;
|
|
280
|
-
}
|
|
281
|
-
await fsp.mkdir(dirname(file), { recursive: true });
|
|
282
|
-
await fsp.writeFile(
|
|
283
|
-
file,
|
|
284
|
-
contents,
|
|
285
|
-
typeof contents === "string" ? "utf8" : void 0
|
|
286
|
-
);
|
|
287
|
-
if (log) {
|
|
288
|
-
silgi.logger.info("Generated", prettyPath(file));
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
async function isDirectory$1(path) {
|
|
292
|
-
try {
|
|
293
|
-
return (await fsp.stat(path)).isDirectory();
|
|
294
|
-
} catch {
|
|
295
|
-
return false;
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
function createFunctionConfigs(configs) {
|
|
300
|
-
return configs;
|
|
301
|
-
}
|
|
302
|
-
function createFunction(name, args = {}) {
|
|
303
|
-
return {
|
|
304
|
-
name,
|
|
305
|
-
args: Object.keys(args).length > 0 ? [args] : []
|
|
306
|
-
};
|
|
307
|
-
}
|
|
308
|
-
function formatFunctions(configs, indentation = 4, specialVars = [], deduplicateArgs = false) {
|
|
309
|
-
const indent = " ".repeat(indentation);
|
|
310
|
-
const argMap = /* @__PURE__ */ new Map();
|
|
311
|
-
const argVarDeclarations = [];
|
|
312
|
-
let argCounter = 0;
|
|
313
|
-
if (deduplicateArgs) {
|
|
314
|
-
configs.forEach((config) => {
|
|
315
|
-
if (config.args.length > 0) {
|
|
316
|
-
const argStr = JSON.stringify(config.args[0]);
|
|
317
|
-
if (!argMap.has(argStr) && argStr.length > 20) {
|
|
318
|
-
const varName = `args${argCounter++}`;
|
|
319
|
-
argMap.set(argStr, varName);
|
|
320
|
-
argVarDeclarations.push(`const ${varName} = ${processArgString(argStr, specialVars, indentation)}`);
|
|
321
|
-
}
|
|
322
|
-
}
|
|
323
|
-
});
|
|
324
|
-
}
|
|
325
|
-
function processArgString(argStr, specialVars2, indentLevel) {
|
|
326
|
-
const parsed = JSON.parse(argStr);
|
|
327
|
-
const prettified = formatObjectWithIndentation(parsed, indentLevel);
|
|
328
|
-
let processed = prettified;
|
|
329
|
-
specialVars2.forEach((varName) => {
|
|
330
|
-
processed = processed.replace(new RegExp(`"${varName}"`, "g"), varName);
|
|
331
|
-
});
|
|
332
|
-
return processed;
|
|
333
|
-
}
|
|
334
|
-
function formatObjectWithIndentation(obj, indentLevel) {
|
|
335
|
-
const baseIndent = " ".repeat(indentLevel);
|
|
336
|
-
const innerIndent = " ".repeat(indentLevel + 2);
|
|
337
|
-
if (typeof obj !== "object" || obj === null) {
|
|
338
|
-
return JSON.stringify(obj);
|
|
339
|
-
}
|
|
340
|
-
if (Array.isArray(obj)) {
|
|
341
|
-
if (obj.length === 0)
|
|
342
|
-
return "[]";
|
|
343
|
-
const items = obj.map(
|
|
344
|
-
(item) => `${innerIndent}${formatObjectWithIndentation(item, indentLevel + 2)}`
|
|
345
|
-
).join(",\n");
|
|
346
|
-
return `[
|
|
347
|
-
${items}
|
|
348
|
-
${baseIndent}]`;
|
|
349
|
-
}
|
|
350
|
-
if (Object.keys(obj).length === 0)
|
|
351
|
-
return "{}";
|
|
352
|
-
const entries = Object.entries(obj).map(([key, value]) => {
|
|
353
|
-
return `${innerIndent}${key}: ${formatObjectWithIndentation(value, indentLevel + 2)}`;
|
|
354
|
-
}).join(",\n");
|
|
355
|
-
return `{
|
|
356
|
-
${entries}
|
|
357
|
-
${baseIndent}}`;
|
|
358
|
-
}
|
|
359
|
-
const formattedCalls = configs.map((config) => {
|
|
360
|
-
if (config.args.length === 0) {
|
|
361
|
-
return `${indent}${config.name}()`;
|
|
362
|
-
}
|
|
363
|
-
const argStr = JSON.stringify(config.args[0]);
|
|
364
|
-
if (deduplicateArgs && argMap.has(argStr) && argStr.length > 20) {
|
|
365
|
-
return `${indent}${config.name}(${argMap.get(argStr)})`;
|
|
366
|
-
} else {
|
|
367
|
-
return `${indent}${config.name}(${processArgString(argStr, specialVars, indentation)})`;
|
|
368
|
-
}
|
|
369
|
-
}).join(",\n");
|
|
370
|
-
if (deduplicateArgs && argVarDeclarations.length > 0) {
|
|
371
|
-
return `${argVarDeclarations.join(";\n")};
|
|
372
|
-
|
|
373
|
-
${formattedCalls}`;
|
|
374
|
-
}
|
|
375
|
-
return formattedCalls;
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
const reservedCode = /* @__PURE__ */ new Set([
|
|
379
|
-
"process",
|
|
380
|
-
"global",
|
|
381
|
-
"runtime",
|
|
382
|
-
"runtimeConfig"
|
|
383
|
-
]);
|
|
384
|
-
function genEnsureSafeVar(name) {
|
|
385
|
-
if (typeof name !== "string") {
|
|
386
|
-
return genString(name);
|
|
387
|
-
}
|
|
388
|
-
for (const reserved of reservedCode) {
|
|
389
|
-
if (name === reserved || name.startsWith(`${reserved}.`)) {
|
|
390
|
-
return name;
|
|
391
|
-
}
|
|
392
|
-
}
|
|
393
|
-
return genString(name);
|
|
394
|
-
}
|
|
395
|
-
function getAllEntries(obj) {
|
|
396
|
-
return Object.entries(obj).map(([
|
|
397
|
-
key,
|
|
398
|
-
value
|
|
399
|
-
]) => {
|
|
400
|
-
if (typeof value === "function") {
|
|
401
|
-
return [key, genObjectFromRaw(value)];
|
|
402
|
-
}
|
|
403
|
-
if (typeof value === "string") {
|
|
404
|
-
return [key, genEnsureSafeVar(value)];
|
|
405
|
-
}
|
|
406
|
-
if (typeof value === "object" && value !== null) {
|
|
407
|
-
if (Array.isArray(value)) {
|
|
408
|
-
return [key, genObjectFromValues(value.map(
|
|
409
|
-
(item) => typeof item === "object" && item !== null ? genObjectFromRawEntries(getAllEntries(item)) : item
|
|
410
|
-
))];
|
|
411
|
-
} else {
|
|
412
|
-
return [key, genObjectFromRawEntries(getAllEntries(value))];
|
|
413
|
-
}
|
|
414
|
-
}
|
|
415
|
-
return [key, value];
|
|
416
|
-
});
|
|
417
|
-
}
|
|
418
|
-
|
|
419
|
-
function hash(data) {
|
|
420
|
-
return `_${camelCase(hash$1(data))}`;
|
|
421
|
-
}
|
|
422
|
-
|
|
423
|
-
function isNuxt() {
|
|
424
|
-
const silgi = useSilgi();
|
|
425
|
-
if (silgi.options.present === "nitro" || silgi.options.present === "h3" || silgi.options.present === "nuxt") {
|
|
426
|
-
return true;
|
|
427
|
-
}
|
|
428
|
-
return false;
|
|
429
|
-
}
|
|
430
|
-
function isNitro() {
|
|
431
|
-
const silgi = useSilgi();
|
|
432
|
-
if (silgi.options.present === "nitro" || silgi.options.present === "h3") {
|
|
433
|
-
return true;
|
|
434
|
-
}
|
|
435
|
-
return false;
|
|
436
|
-
}
|
|
437
|
-
function isH3() {
|
|
438
|
-
const silgi = useSilgi();
|
|
439
|
-
if (silgi.options.present === "h3") {
|
|
440
|
-
return true;
|
|
441
|
-
}
|
|
442
|
-
return false;
|
|
443
|
-
}
|
|
444
|
-
|
|
445
|
-
const logger = consola$1;
|
|
446
|
-
function useLogger(tag, options = {}) {
|
|
447
|
-
return tag ? logger.create(options).withTag(tag) : logger;
|
|
448
|
-
}
|
|
449
|
-
|
|
450
|
-
var MigrationStatus = /* @__PURE__ */ ((MigrationStatus2) => {
|
|
451
|
-
MigrationStatus2["SUCCESS"] = "success";
|
|
452
|
-
MigrationStatus2["ERROR"] = "error";
|
|
453
|
-
MigrationStatus2["SKIPPED"] = "skipped";
|
|
454
|
-
return MigrationStatus2;
|
|
455
|
-
})(MigrationStatus || {});
|
|
456
|
-
async function generateMigration(data, directoryPath, fileNamePrefix = "data_", options = {}) {
|
|
457
|
-
const {
|
|
458
|
-
description,
|
|
459
|
-
verbose = false,
|
|
460
|
-
prettyPrint = true,
|
|
461
|
-
usePatch = true,
|
|
462
|
-
skipIfNoChanges = true
|
|
463
|
-
} = options;
|
|
464
|
-
try {
|
|
465
|
-
try {
|
|
466
|
-
if (!existsSync(directoryPath)) {
|
|
467
|
-
await mkdir(directoryPath, { recursive: true });
|
|
468
|
-
}
|
|
469
|
-
} catch (error) {
|
|
470
|
-
return {
|
|
471
|
-
success: false,
|
|
472
|
-
status: "error" /* ERROR */,
|
|
473
|
-
error: `Dizin olu\u015Fturulamad\u0131: ${error}`
|
|
474
|
-
};
|
|
475
|
-
}
|
|
476
|
-
const latestPath = join(directoryPath, "latest.json");
|
|
477
|
-
let existingData = null;
|
|
478
|
-
let hasChanges = true;
|
|
479
|
-
let patch = [];
|
|
480
|
-
if (existsSync(latestPath)) {
|
|
481
|
-
try {
|
|
482
|
-
const latestContent = await readFile(latestPath, "utf-8");
|
|
483
|
-
const latestInfo2 = JSON.parse(latestContent);
|
|
484
|
-
if (latestInfo2?.file) {
|
|
485
|
-
const existingFilePath = join(directoryPath, latestInfo2.file);
|
|
486
|
-
if (existsSync(existingFilePath)) {
|
|
487
|
-
const fileContent2 = await readFile(existingFilePath, "utf-8");
|
|
488
|
-
try {
|
|
489
|
-
if (latestInfo2.isPatch) {
|
|
490
|
-
const result = await migrationUp(directoryPath);
|
|
491
|
-
if (result.success && result.data) {
|
|
492
|
-
existingData = result.data;
|
|
493
|
-
}
|
|
494
|
-
} else {
|
|
495
|
-
existingData = JSON.parse(fileContent2);
|
|
496
|
-
}
|
|
497
|
-
if (existingData) {
|
|
498
|
-
patch = rfc6902.createPatch(existingData, data);
|
|
499
|
-
hasChanges = patch.length > 0;
|
|
500
|
-
if (verbose && hasChanges) {
|
|
501
|
-
console.warn("De\u011Fi\u015Fiklikler tespit edildi:", patch);
|
|
502
|
-
}
|
|
503
|
-
}
|
|
504
|
-
} catch (err) {
|
|
505
|
-
console.warn(`Migration verisi i\u015Flenirken hata: ${err}`);
|
|
506
|
-
}
|
|
507
|
-
}
|
|
508
|
-
}
|
|
509
|
-
} catch (error) {
|
|
510
|
-
console.warn(`Latest bilgisi okunamad\u0131: ${error}`);
|
|
511
|
-
}
|
|
512
|
-
}
|
|
513
|
-
if (!hasChanges && existingData !== null && skipIfNoChanges) {
|
|
514
|
-
if (verbose) {
|
|
515
|
-
console.warn("De\u011Fi\u015Fiklik yok, migration olu\u015Fturulmad\u0131.");
|
|
516
|
-
}
|
|
517
|
-
return {
|
|
518
|
-
success: true,
|
|
519
|
-
status: "skipped" /* SKIPPED */
|
|
520
|
-
};
|
|
521
|
-
}
|
|
522
|
-
const timestamp = Math.floor(Date.now() / 1e3);
|
|
523
|
-
const isPatch = usePatch && patch.length > 0 && existingData !== null;
|
|
524
|
-
const fileName = `${fileNamePrefix}${isPatch ? "patch_" : ""}${timestamp}.json`;
|
|
525
|
-
const filePath = join(directoryPath, fileName);
|
|
526
|
-
const fileContent = isPatch ? patch : data;
|
|
527
|
-
const indent = prettyPrint ? 2 : 0;
|
|
528
|
-
await writeFile$1(filePath, JSON.stringify(fileContent, null, indent), "utf-8");
|
|
529
|
-
const latestInfo = {
|
|
530
|
-
timestamp,
|
|
531
|
-
file: fileName,
|
|
532
|
-
created: (/* @__PURE__ */ new Date()).toISOString(),
|
|
533
|
-
description,
|
|
534
|
-
isPatch
|
|
535
|
-
};
|
|
536
|
-
await writeFile$1(latestPath, JSON.stringify(latestInfo, null, indent), "utf-8");
|
|
537
|
-
if (verbose) {
|
|
538
|
-
console.warn(`Yeni ${isPatch ? "patch" : "tam veri"} migration olu\u015Fturuldu: ${fileName}`);
|
|
539
|
-
}
|
|
540
|
-
return {
|
|
541
|
-
success: true,
|
|
542
|
-
status: "success" /* SUCCESS */,
|
|
543
|
-
filePath,
|
|
544
|
-
timestamp,
|
|
545
|
-
isPatch,
|
|
546
|
-
data: fileContent
|
|
547
|
-
};
|
|
548
|
-
} catch (error) {
|
|
549
|
-
return {
|
|
550
|
-
success: false,
|
|
551
|
-
status: "error" /* ERROR */,
|
|
552
|
-
error: `Migration olu\u015Fturma hatas\u0131: ${error instanceof Error ? error.message : String(error)}`
|
|
553
|
-
};
|
|
554
|
-
}
|
|
555
|
-
}
|
|
556
|
-
async function getMigration(migrationsDir, fileName) {
|
|
557
|
-
try {
|
|
558
|
-
if (!existsSync(migrationsDir)) {
|
|
559
|
-
return {
|
|
560
|
-
success: false,
|
|
561
|
-
status: "error" /* ERROR */,
|
|
562
|
-
error: `Migration dizini bulunamad\u0131: ${migrationsDir}`
|
|
563
|
-
};
|
|
564
|
-
}
|
|
565
|
-
if (!fileName) {
|
|
566
|
-
const latestPath = join(migrationsDir, "latest.json");
|
|
567
|
-
if (!existsSync(latestPath)) {
|
|
568
|
-
return {
|
|
569
|
-
success: false,
|
|
570
|
-
status: "error" /* ERROR */,
|
|
571
|
-
error: `Latest bilgisi bulunamad\u0131: ${latestPath}`
|
|
572
|
-
};
|
|
573
|
-
}
|
|
574
|
-
const latestContent = await readFile(latestPath, "utf-8");
|
|
575
|
-
const latestInfo = JSON.parse(latestContent);
|
|
576
|
-
fileName = latestInfo.file;
|
|
577
|
-
}
|
|
578
|
-
const migrationPath = join(migrationsDir, fileName);
|
|
579
|
-
if (!existsSync(migrationPath)) {
|
|
580
|
-
return {
|
|
581
|
-
success: false,
|
|
582
|
-
status: "error" /* ERROR */,
|
|
583
|
-
error: `Migration dosyas\u0131 bulunamad\u0131: ${migrationPath}`
|
|
584
|
-
};
|
|
585
|
-
}
|
|
586
|
-
const migrationContent = await readFile(migrationPath, "utf-8");
|
|
587
|
-
const data = JSON.parse(migrationContent);
|
|
588
|
-
const isPatch = fileName.includes("_patch_");
|
|
589
|
-
const timestampMatch = fileName.match(/(\d+)\.json$/);
|
|
590
|
-
const timestamp = timestampMatch ? Number.parseInt(timestampMatch[1]) : void 0;
|
|
591
|
-
return {
|
|
592
|
-
success: true,
|
|
593
|
-
status: "success" /* SUCCESS */,
|
|
594
|
-
filePath: migrationPath,
|
|
595
|
-
timestamp,
|
|
596
|
-
isPatch,
|
|
597
|
-
data
|
|
598
|
-
};
|
|
599
|
-
} catch (error) {
|
|
600
|
-
return {
|
|
601
|
-
success: false,
|
|
602
|
-
status: "error" /* ERROR */,
|
|
603
|
-
error: `Migration bilgileri al\u0131n\u0131rken hata: ${error instanceof Error ? error.message : String(error)}`
|
|
604
|
-
};
|
|
605
|
-
}
|
|
606
|
-
}
|
|
607
|
-
async function listMigrations(migrationsDir, filePrefix) {
|
|
608
|
-
try {
|
|
609
|
-
if (!existsSync(migrationsDir)) {
|
|
610
|
-
return [];
|
|
611
|
-
}
|
|
612
|
-
const { readdir } = await import('node:fs/promises');
|
|
613
|
-
const files = await readdir(migrationsDir);
|
|
614
|
-
const jsonFiles = files.filter((file) => file.endsWith(".json") && file !== "latest.json");
|
|
615
|
-
const filteredFiles = filePrefix ? jsonFiles.filter((file) => file.startsWith(filePrefix)) : jsonFiles;
|
|
616
|
-
return filteredFiles.map((file) => {
|
|
617
|
-
const isPatch = file.includes("_patch_");
|
|
618
|
-
const timestampMatch = file.match(/(\d+)\.json$/);
|
|
619
|
-
const timestamp = timestampMatch ? Number.parseInt(timestampMatch[1]) : 0;
|
|
620
|
-
return {
|
|
621
|
-
timestamp,
|
|
622
|
-
file,
|
|
623
|
-
created: "",
|
|
624
|
-
// Dosya içeriğinden çıkarılabilir ancak performans için boş bırakıldı
|
|
625
|
-
isPatch
|
|
626
|
-
};
|
|
627
|
-
}).sort((a, b) => a.timestamp - b.timestamp);
|
|
628
|
-
} catch (error) {
|
|
629
|
-
console.error(`Migration listesi al\u0131namad\u0131: ${error instanceof Error ? error.message : String(error)}`);
|
|
630
|
-
return [];
|
|
631
|
-
}
|
|
632
|
-
}
|
|
633
|
-
async function migrationUp(migrationsDir, targetTimestamp) {
|
|
634
|
-
try {
|
|
635
|
-
const migrations = await listMigrations(migrationsDir);
|
|
636
|
-
if (migrations.length === 0) {
|
|
637
|
-
return {
|
|
638
|
-
success: false,
|
|
639
|
-
status: "error" /* ERROR */,
|
|
640
|
-
error: "Migration bulunamad\u0131"
|
|
641
|
-
};
|
|
642
|
-
}
|
|
643
|
-
const targetMigrations = targetTimestamp ? migrations.filter((m) => m.timestamp <= targetTimestamp) : migrations;
|
|
644
|
-
if (targetMigrations.length === 0) {
|
|
645
|
-
return {
|
|
646
|
-
success: false,
|
|
647
|
-
status: "error" /* ERROR */,
|
|
648
|
-
error: "Belirtilen zaman damgas\u0131na kadar migration bulunamad\u0131"
|
|
649
|
-
};
|
|
650
|
-
}
|
|
651
|
-
const baseIndex = targetMigrations.findIndex((m) => !m.isPatch);
|
|
652
|
-
if (baseIndex === -1) {
|
|
653
|
-
return {
|
|
654
|
-
success: false,
|
|
655
|
-
status: "error" /* ERROR */,
|
|
656
|
-
error: "Tam veri migration bulunamad\u0131"
|
|
657
|
-
};
|
|
658
|
-
}
|
|
659
|
-
const baseMigration = await getMigration(
|
|
660
|
-
migrationsDir,
|
|
661
|
-
targetMigrations[baseIndex].file
|
|
662
|
-
);
|
|
663
|
-
if (!baseMigration.success || !baseMigration.data) {
|
|
664
|
-
return {
|
|
665
|
-
success: false,
|
|
666
|
-
status: "error" /* ERROR */,
|
|
667
|
-
error: `Temel veri al\u0131n\u0131rken hata: ${baseMigration.error || "Veri yok"}`
|
|
668
|
-
};
|
|
669
|
-
}
|
|
670
|
-
let currentData;
|
|
671
|
-
if (Array.isArray(baseMigration.data)) {
|
|
672
|
-
currentData = [...baseMigration.data];
|
|
673
|
-
} else {
|
|
674
|
-
try {
|
|
675
|
-
currentData = baseMigration.data ? JSON.parse(JSON.stringify(baseMigration.data)) : {};
|
|
676
|
-
} catch {
|
|
677
|
-
currentData = baseMigration.data;
|
|
678
|
-
}
|
|
679
|
-
}
|
|
680
|
-
for (let i = baseIndex + 1; i < targetMigrations.length; i++) {
|
|
681
|
-
if (!targetMigrations[i].isPatch) {
|
|
682
|
-
const fullMigration = await getMigration(
|
|
683
|
-
migrationsDir,
|
|
684
|
-
targetMigrations[i].file
|
|
685
|
-
);
|
|
686
|
-
if (fullMigration.success && fullMigration.data) {
|
|
687
|
-
if (Array.isArray(fullMigration.data)) {
|
|
688
|
-
currentData = [...fullMigration.data];
|
|
689
|
-
} else {
|
|
690
|
-
try {
|
|
691
|
-
currentData = JSON.parse(JSON.stringify(fullMigration.data));
|
|
692
|
-
} catch {
|
|
693
|
-
currentData = fullMigration.data;
|
|
694
|
-
}
|
|
695
|
-
}
|
|
696
|
-
} else {
|
|
697
|
-
console.warn(`Tam veri migration okunamad\u0131: ${targetMigrations[i].file}`);
|
|
698
|
-
}
|
|
699
|
-
continue;
|
|
700
|
-
}
|
|
701
|
-
const patchMigration = await getMigration(
|
|
702
|
-
migrationsDir,
|
|
703
|
-
targetMigrations[i].file
|
|
704
|
-
);
|
|
705
|
-
if (!patchMigration.success || !patchMigration.data) {
|
|
706
|
-
console.warn(`Patch migration okunamad\u0131: ${targetMigrations[i].file}`);
|
|
707
|
-
continue;
|
|
708
|
-
}
|
|
709
|
-
try {
|
|
710
|
-
const result = rfc6902.applyPatch(
|
|
711
|
-
currentData,
|
|
712
|
-
patchMigration.data
|
|
713
|
-
);
|
|
714
|
-
const errors = result.filter((r) => r !== null);
|
|
715
|
-
if (errors.length > 0) {
|
|
716
|
-
console.warn(`Patch uygulama uyar\u0131s\u0131 (${targetMigrations[i].file}):`, JSON.stringify(errors));
|
|
717
|
-
}
|
|
718
|
-
} catch (patchError) {
|
|
719
|
-
return {
|
|
720
|
-
success: false,
|
|
721
|
-
status: "error" /* ERROR */,
|
|
722
|
-
error: `Patch uygulama hatas\u0131 (${targetMigrations[i].file}): ${patchError instanceof Error ? patchError.message : String(patchError)}`
|
|
723
|
-
};
|
|
724
|
-
}
|
|
725
|
-
}
|
|
726
|
-
return {
|
|
727
|
-
success: true,
|
|
728
|
-
status: "success" /* SUCCESS */,
|
|
729
|
-
data: currentData,
|
|
730
|
-
timestamp: targetMigrations[targetMigrations.length - 1].timestamp
|
|
731
|
-
};
|
|
732
|
-
} catch (error) {
|
|
733
|
-
const errorMessage = error instanceof Error ? error.message : String(error || "Undefined error");
|
|
734
|
-
return {
|
|
735
|
-
success: false,
|
|
736
|
-
status: "error" /* ERROR */,
|
|
737
|
-
error: `Migration uygulama hatas\u0131: ${errorMessage}`
|
|
738
|
-
};
|
|
739
|
-
}
|
|
740
|
-
}
|
|
741
|
-
async function migrationDown(migrationsDir, targetTimestamp) {
|
|
742
|
-
try {
|
|
743
|
-
if (targetTimestamp === void 0) {
|
|
744
|
-
const migrations = await listMigrations(migrationsDir);
|
|
745
|
-
if (migrations.length <= 1) {
|
|
746
|
-
return {
|
|
747
|
-
success: false,
|
|
748
|
-
status: "error" /* ERROR */,
|
|
749
|
-
error: "Geri al\u0131nabilecek bir \xF6nceki migration bulunamad\u0131"
|
|
750
|
-
};
|
|
751
|
-
}
|
|
752
|
-
const previousMigrations = migrations.slice(0, migrations.length - 1);
|
|
753
|
-
targetTimestamp = previousMigrations[previousMigrations.length - 1].timestamp;
|
|
754
|
-
}
|
|
755
|
-
return await migrationUp(migrationsDir, targetTimestamp);
|
|
756
|
-
} catch (error) {
|
|
757
|
-
const errorMessage = error instanceof Error ? error.message : String(error || "Undefined error");
|
|
758
|
-
return {
|
|
759
|
-
success: false,
|
|
760
|
-
status: "error" /* ERROR */,
|
|
761
|
-
error: `Migration geri alma hatas\u0131: ${errorMessage}`
|
|
762
|
-
};
|
|
763
|
-
}
|
|
764
|
-
}
|
|
765
|
-
|
|
766
|
-
function defineSilgiModule(definition) {
|
|
767
|
-
if (definition) {
|
|
768
|
-
return _defineSilgiModule(definition);
|
|
769
|
-
}
|
|
770
|
-
return {
|
|
771
|
-
with: (definition2) => _defineSilgiModule(definition2)
|
|
772
|
-
};
|
|
773
|
-
}
|
|
774
|
-
function _defineSilgiModule(definition) {
|
|
775
|
-
if (typeof definition === "function") {
|
|
776
|
-
return _defineSilgiModule({ setup: definition });
|
|
777
|
-
}
|
|
778
|
-
const module = defu(definition, { meta: {} });
|
|
779
|
-
module.meta.configKey ||= module.meta.name;
|
|
780
|
-
async function getOptions(inlineOptions, silgi = useSilgiCLI()) {
|
|
781
|
-
const nuxtConfigOptionsKey = module.meta.configKey || module.meta.name;
|
|
782
|
-
const nuxtConfigOptions = nuxtConfigOptionsKey && nuxtConfigOptionsKey in silgi.options ? silgi.options[nuxtConfigOptionsKey] : {};
|
|
783
|
-
const optionsDefaults = typeof module.defaults === "function" ? await module.defaults(silgi) : module.defaults ?? {};
|
|
784
|
-
const options = defu(inlineOptions, nuxtConfigOptions, optionsDefaults);
|
|
785
|
-
return Promise.resolve(options);
|
|
786
|
-
}
|
|
787
|
-
async function silgiNormalizedModule(inlineOptions, silgi = tryUseSilgiCLI()) {
|
|
788
|
-
if (!silgi) {
|
|
789
|
-
throw new TypeError("Cannot use module outside of Silgi context");
|
|
790
|
-
}
|
|
791
|
-
const uniqueKey = module.meta.configKey || module.meta.name;
|
|
792
|
-
if (uniqueKey && !silgi.options.isPreparingModules) {
|
|
793
|
-
silgi._requiredModules ||= {};
|
|
794
|
-
if (silgi._requiredModules[uniqueKey]) {
|
|
795
|
-
return false;
|
|
796
|
-
}
|
|
797
|
-
silgi._requiredModules[uniqueKey] = true;
|
|
798
|
-
}
|
|
799
|
-
if (module.meta.compatibility) {
|
|
800
|
-
const issues = await checkSilgiCompatibility(module.meta.compatibility, silgi);
|
|
801
|
-
if (issues.length) {
|
|
802
|
-
silgi.logger.warn(`Module \`${module.meta.name}\` is disabled due to incompatibility issues:
|
|
803
|
-
${issues.toString()}`);
|
|
804
|
-
return;
|
|
805
|
-
}
|
|
806
|
-
}
|
|
807
|
-
const _options = await getOptions(inlineOptions, silgi);
|
|
808
|
-
if (module.hooks) {
|
|
809
|
-
silgi.hooks.addHooks(module.hooks);
|
|
810
|
-
}
|
|
811
|
-
const start = performance.now();
|
|
812
|
-
const res = await module.setup?.call(null, _options, silgi) ?? {};
|
|
813
|
-
const perf = performance.now() - start;
|
|
814
|
-
const setupTime = Math.round(perf * 100) / 100;
|
|
815
|
-
if (setupTime > 5e3 && uniqueKey !== "@silgi/telemetry") {
|
|
816
|
-
silgi.logger.warn(`Slow module \`${uniqueKey || "<no name>"}\` took \`${setupTime}ms\` to setup.`);
|
|
817
|
-
} else if (silgi.options.debug) {
|
|
818
|
-
silgi.logger.info(`Module \`${uniqueKey || "<no name>"}\` took \`${setupTime}ms\` to setup.`);
|
|
819
|
-
}
|
|
820
|
-
if (res === false) {
|
|
821
|
-
return false;
|
|
822
|
-
}
|
|
823
|
-
return defu(res, {
|
|
824
|
-
timings: {
|
|
825
|
-
setup: setupTime
|
|
826
|
-
}
|
|
827
|
-
});
|
|
828
|
-
}
|
|
829
|
-
silgiNormalizedModule.getMeta = () => Promise.resolve(module.meta);
|
|
830
|
-
silgiNormalizedModule.getOptions = getOptions;
|
|
831
|
-
return silgiNormalizedModule;
|
|
832
|
-
}
|
|
833
|
-
|
|
834
|
-
function defineSilgiPreset(preset, meta) {
|
|
835
|
-
if (meta?.url && typeof preset !== "function") ;
|
|
836
|
-
return { ...preset, _meta: meta };
|
|
837
|
-
}
|
|
838
|
-
|
|
839
|
-
async function resolvePath(path, opts = {}) {
|
|
840
|
-
const _path = path;
|
|
841
|
-
path = normalize(path);
|
|
842
|
-
if (isAbsolute(path)) {
|
|
843
|
-
if (existsSync(path) && !await isDirectory(path)) {
|
|
844
|
-
return path;
|
|
845
|
-
}
|
|
846
|
-
}
|
|
847
|
-
const cwd = opts.cwd || process.cwd();
|
|
848
|
-
const extensions = opts.extensions || [".ts", ".mjs", ".cjs", ".json"];
|
|
849
|
-
const modulesDir = opts.modulesDir || [];
|
|
850
|
-
path = resolveAlias(path);
|
|
851
|
-
if (!isAbsolute(path)) {
|
|
852
|
-
path = resolve(cwd, path);
|
|
853
|
-
}
|
|
854
|
-
let _isDir = false;
|
|
855
|
-
if (existsSync(path)) {
|
|
856
|
-
_isDir = await isDirectory(path);
|
|
857
|
-
if (!_isDir) {
|
|
858
|
-
return path;
|
|
859
|
-
}
|
|
860
|
-
}
|
|
861
|
-
for (const ext of extensions) {
|
|
862
|
-
const pathWithExt = path + ext;
|
|
863
|
-
if (existsSync(pathWithExt)) {
|
|
864
|
-
return pathWithExt;
|
|
865
|
-
}
|
|
866
|
-
const pathWithIndex = join(path, `index${ext}`);
|
|
867
|
-
if (_isDir && existsSync(pathWithIndex)) {
|
|
868
|
-
return pathWithIndex;
|
|
869
|
-
}
|
|
870
|
-
}
|
|
871
|
-
const resolveModulePath = await resolvePath$1(_path, { url: [cwd, ...modulesDir] }).catch(() => null);
|
|
872
|
-
if (resolveModulePath) {
|
|
873
|
-
return resolveModulePath;
|
|
874
|
-
}
|
|
875
|
-
return opts.fallbackToOriginal ? _path : path;
|
|
876
|
-
}
|
|
877
|
-
async function isDirectory(path) {
|
|
878
|
-
return (await promises.lstat(path)).isDirectory();
|
|
879
|
-
}
|
|
880
|
-
function resolveAlias(path, alias) {
|
|
881
|
-
alias ||= tryUseSilgiCLI()?.options.alias || {};
|
|
882
|
-
return resolveAlias$1(path, alias || {});
|
|
883
|
-
}
|
|
884
|
-
function createResolver(base) {
|
|
885
|
-
if (!base) {
|
|
886
|
-
throw new Error("`base` argument is missing for createResolver(base)!");
|
|
887
|
-
}
|
|
888
|
-
base = base.toString();
|
|
889
|
-
if (base.startsWith("file://")) {
|
|
890
|
-
base = dirname(fileURLToPath(base));
|
|
891
|
-
}
|
|
892
|
-
return {
|
|
893
|
-
resolve: (...path) => resolve(base, ...path),
|
|
894
|
-
resolvePath: (path, opts) => resolvePath(path, { cwd: base, ...opts })
|
|
895
|
-
};
|
|
896
|
-
}
|
|
897
|
-
async function resolveSilgiModule(base, paths) {
|
|
898
|
-
const resolved = [];
|
|
899
|
-
const resolver = createResolver(base);
|
|
900
|
-
for (const path of paths) {
|
|
901
|
-
if (path.startsWith(base)) {
|
|
902
|
-
resolved.push(path.split("/index.ts")[0]);
|
|
903
|
-
} else {
|
|
904
|
-
const resolvedPath = await resolver.resolvePath(path);
|
|
905
|
-
resolved.push(resolvedPath.slice(0, resolvedPath.lastIndexOf(path) + path.length));
|
|
906
|
-
}
|
|
907
|
-
}
|
|
908
|
-
return resolved;
|
|
909
|
-
}
|
|
910
|
-
|
|
911
|
-
function addTemplate(_template) {
|
|
912
|
-
const silgi = useSilgiCLI();
|
|
913
|
-
const template = normalizeTemplate(_template);
|
|
914
|
-
filterInPlace(silgi.options.build.templates, (p) => normalizeTemplate(p).dst !== template.dst);
|
|
915
|
-
silgi.options.build.templates.push(template);
|
|
916
|
-
return template;
|
|
917
|
-
}
|
|
918
|
-
function normalizeTemplate(template, buildDir) {
|
|
919
|
-
if (!template) {
|
|
920
|
-
throw new Error(`Invalid template: ${JSON.stringify(template)}`);
|
|
921
|
-
}
|
|
922
|
-
if (typeof template === "string") {
|
|
923
|
-
template = { src: template };
|
|
924
|
-
} else {
|
|
925
|
-
template = { ...template };
|
|
926
|
-
}
|
|
927
|
-
if (template.src) {
|
|
928
|
-
if (!existsSync(template.src)) {
|
|
929
|
-
throw new Error(`Template not found: ${template.src}`);
|
|
930
|
-
}
|
|
931
|
-
if (!template.filename) {
|
|
932
|
-
const srcPath = parse(template.src);
|
|
933
|
-
template.filename = template.fileName || `${basename(srcPath.dir)}.${srcPath.name}.${hash$2(template.src)}${srcPath.ext}`;
|
|
934
|
-
}
|
|
935
|
-
}
|
|
936
|
-
if (!template.src && !template.getContents) {
|
|
937
|
-
throw new Error(`Invalid template. Either \`getContents\` or \`src\` should be provided: ${JSON.stringify(template)}`);
|
|
938
|
-
}
|
|
939
|
-
if (!template.filename) {
|
|
940
|
-
throw new Error(`Invalid template. \`filename\` must be provided: ${JSON.stringify(template)}`);
|
|
941
|
-
}
|
|
942
|
-
if (template.filename.endsWith(".d.ts")) {
|
|
943
|
-
template.write = true;
|
|
944
|
-
}
|
|
945
|
-
if (!template.dst) {
|
|
946
|
-
const silgi = useSilgiCLI();
|
|
947
|
-
let dir;
|
|
948
|
-
switch (template.where) {
|
|
949
|
-
case ".silgi":
|
|
950
|
-
dir = silgi.options.build.dir;
|
|
951
|
-
break;
|
|
952
|
-
case "server":
|
|
953
|
-
dir = silgi.options.silgi.serverDir;
|
|
954
|
-
break;
|
|
955
|
-
case "client":
|
|
956
|
-
dir = silgi.options.silgi.clientDir;
|
|
957
|
-
break;
|
|
958
|
-
case "root":
|
|
959
|
-
dir = silgi.options.rootDir;
|
|
960
|
-
break;
|
|
961
|
-
default:
|
|
962
|
-
dir = silgi.options.silgi.serverDir;
|
|
963
|
-
}
|
|
964
|
-
template.dst = resolve(buildDir ?? dir, template.filename);
|
|
965
|
-
}
|
|
966
|
-
return template;
|
|
967
|
-
}
|
|
968
|
-
|
|
969
|
-
function useRequest(event) {
|
|
970
|
-
const silgi = useSilgi();
|
|
971
|
-
if (silgi.options.present === "nuxt" || silgi.options.present === "nitro" || silgi.options.present === "h3") {
|
|
972
|
-
return event.node.req;
|
|
973
|
-
}
|
|
974
|
-
return event;
|
|
975
|
-
}
|
|
976
|
-
function getIpAddress(req) {
|
|
977
|
-
const headers = [
|
|
978
|
-
"cf-connecting-ip",
|
|
979
|
-
// Cloudflare
|
|
980
|
-
"true-client-ip",
|
|
981
|
-
// Akamai and Cloudflare
|
|
982
|
-
"x-real-ip",
|
|
983
|
-
// Nginx proxy/FastCGI
|
|
984
|
-
"x-forwarded-for",
|
|
985
|
-
// Standard proxy header
|
|
986
|
-
"x-client-ip",
|
|
987
|
-
// Apache
|
|
988
|
-
"x-forwarded",
|
|
989
|
-
// Alternative format
|
|
990
|
-
"forwarded",
|
|
991
|
-
// RFC 7239 compliant format
|
|
992
|
-
"forwarded-for",
|
|
993
|
-
// RFC 7239 variant
|
|
994
|
-
"x-appengine-user-ip",
|
|
995
|
-
// Google App Engine
|
|
996
|
-
"x-cluster-client-ip",
|
|
997
|
-
// GCP load balancer
|
|
998
|
-
"fastly-client-ip",
|
|
999
|
-
// Fastly CDN
|
|
1000
|
-
"x-azure-clientip",
|
|
1001
|
-
// Azure
|
|
1002
|
-
"x-original-forwarded-for",
|
|
1003
|
-
// Secondary forwarded-for header
|
|
1004
|
-
"x-lb-forwarded-for",
|
|
1005
|
-
// Load balancer specific
|
|
1006
|
-
"cdn-loop"
|
|
1007
|
-
// Used by some CDNs
|
|
1008
|
-
];
|
|
1009
|
-
for (const header of headers) {
|
|
1010
|
-
const value = req.headers.get(header);
|
|
1011
|
-
if (!value)
|
|
1012
|
-
continue;
|
|
1013
|
-
let ip;
|
|
1014
|
-
if (header === "x-forwarded-for" || header === "forwarded-for" || header === "x-original-forwarded-for") {
|
|
1015
|
-
ip = value.split(",")[0];
|
|
1016
|
-
} else if (header === "forwarded") {
|
|
1017
|
-
const match = value.match(/for=([^;]+)/);
|
|
1018
|
-
ip = match ? match[1].trim().replace(/^\[|\]$/g, "") : "";
|
|
1019
|
-
} else {
|
|
1020
|
-
ip = value;
|
|
1021
|
-
}
|
|
1022
|
-
const cleanIp = ip.trim();
|
|
1023
|
-
if (cleanIp && isValidIp(cleanIp)) {
|
|
1024
|
-
return cleanIp;
|
|
1025
|
-
}
|
|
1026
|
-
}
|
|
1027
|
-
return "";
|
|
1028
|
-
}
|
|
1029
|
-
function isValidIp(ip) {
|
|
1030
|
-
if (ip === "::1" || ip === "localhost" || ip === "127.0.0.1")
|
|
1031
|
-
return true;
|
|
1032
|
-
if (/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.test(ip))
|
|
1033
|
-
return true;
|
|
1034
|
-
if (/^[0-9a-f:]+$/i.test(ip))
|
|
1035
|
-
return true;
|
|
1036
|
-
return false;
|
|
1037
|
-
}
|
|
1038
|
-
|
|
1039
|
-
export { MODE_RE, MigrationStatus, addCommands, addCoreFile, addImports, addNPMPackage, addTemplate, baseHeaderBannerComment, createFunction, createFunctionConfigs, createResolver, defineFramework, defineSilgiModule, defineSilgiPreset, directoryToURL, filterInPlace, formatFunctions, genEnsureSafeVar, generateMigration, getAllEntries, getIpAddress, getMigration, getServicePath, hasError, hasInstalledModule, hasSilgiModule, hash, isDirectory$1 as isDirectory, isH3, isNitro, isNuxt, isPresents, isRuntimePresents, listMigrations, migrationDown, migrationUp, normalizeTemplate, prettyPath, processFilePath, relativeWithDot, removeExtension, resolveAlias, resolvePath, resolveSilgiModule, resolveSilgiPath, toArray, tryResolveModule, useLogger, useRequest, writeFile };
|
|
1
|
+
import { MODE_RE, baseHeaderBannerComment, filterInPlace, getServicePath, hasInstalledModule, hasSilgiModule, isPresents, isRuntimePresents, processFilePath, relativeWithDot, removeExtension, toArray } from "./utils.mjs";
|
|
2
|
+
import { addCommands } from "./add/add-commands.mjs";
|
|
3
|
+
import { addCoreFile } from "./add/add-core-file.mjs";
|
|
4
|
+
import { addImports } from "./add/add-imports.mjs";
|
|
5
|
+
import { addNPMPackage } from "./add/add-npm.mjs";
|
|
6
|
+
import { defineFramework } from "./define.mjs";
|
|
7
|
+
import { hasError } from "./errors.mjs";
|
|
8
|
+
import { directoryToURL, tryResolveModule } from "./esm.mjs";
|
|
9
|
+
import { prettyPath, resolveSilgiPath } from "./path.mjs";
|
|
10
|
+
import { isDirectory, writeFile } from "./fs.mjs";
|
|
11
|
+
import { createFunction, createFunctionConfigs, formatFunctions } from "./function-utils.mjs";
|
|
12
|
+
import { genEnsureSafeVar, getAllEntries } from "./gen.mjs";
|
|
13
|
+
import { hash } from "./hash.mjs";
|
|
14
|
+
import { isH3, isNitro, isNuxt } from "./isFramework.mjs";
|
|
15
|
+
import { useLogger } from "./logger.mjs";
|
|
16
|
+
import { MigrationStatus, generateMigration, getMigration, listMigrations, migrationDown, migrationUp } from "./migration.mjs";
|
|
17
|
+
import { defineSilgiModule } from "./module.mjs";
|
|
18
|
+
import { defineSilgiPreset } from "./preset.mjs";
|
|
19
|
+
import { createResolver, resolveAlias, resolvePath, resolveSilgiModule } from "./resolve.mjs";
|
|
20
|
+
import { addTemplate, normalizeTemplate } from "./template.mjs";
|
|
21
|
+
import { getIpAddress, useRequest } from "./useRequest.mjs";
|
|
22
|
+
|
|
23
|
+
export { MODE_RE, MigrationStatus, addCommands, addCoreFile, addImports, addNPMPackage, addTemplate, baseHeaderBannerComment, createFunction, createFunctionConfigs, createResolver, defineFramework, defineSilgiModule, defineSilgiPreset, directoryToURL, filterInPlace, formatFunctions, genEnsureSafeVar, generateMigration, getAllEntries, getIpAddress, getMigration, getServicePath, hasError, hasInstalledModule, hasSilgiModule, hash, isDirectory, isH3, isNitro, isNuxt, isPresents, isRuntimePresents, listMigrations, migrationDown, migrationUp, normalizeTemplate, prettyPath, processFilePath, relativeWithDot, removeExtension, resolveAlias, resolvePath, resolveSilgiModule, resolveSilgiPath, toArray, tryResolveModule, useLogger, useRequest, writeFile };
|