silgi 0.25.17 → 0.25.20
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/cli/index.mjs +1 -1
- package/dist/cli/init.mjs +1 -1
- package/dist/cli/writeTypesAndFiles.mjs +0 -54
- package/dist/kit/index.d.mts +27 -1
- package/dist/kit/index.mjs +80 -1
- package/package.json +18 -18
package/dist/cli/index.mjs
CHANGED
package/dist/cli/init.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { writeFileSync } from 'node:fs';
|
|
2
|
+
import fsp from 'node:fs/promises';
|
|
2
3
|
import * as p from '@clack/prompts';
|
|
3
4
|
import { defineCommand, runCommand } from 'citty';
|
|
4
5
|
import consola from 'consola';
|
|
5
|
-
import fsp from 'node:fs/promises';
|
|
6
6
|
import { dirname } from 'pathe';
|
|
7
7
|
import { p as prepare } from './prepare.mjs';
|
|
8
8
|
import 'silgi/meta';
|
|
@@ -315,63 +315,9 @@ async function nitroFramework(silgi, skip = false) {
|
|
|
315
315
|
});
|
|
316
316
|
if (silgi.options.imports !== false) {
|
|
317
317
|
silgi.options.imports.presets ??= [];
|
|
318
|
-
silgi.options.imports.presets.push(...getNitroImportsPreset());
|
|
319
318
|
}
|
|
320
319
|
await h3Framework(silgi, true);
|
|
321
320
|
}
|
|
322
|
-
function getNitroImportsPreset() {
|
|
323
|
-
return [
|
|
324
|
-
{
|
|
325
|
-
from: "nitropack/runtime/internal/app",
|
|
326
|
-
imports: ["useNitroApp"]
|
|
327
|
-
},
|
|
328
|
-
{
|
|
329
|
-
from: "nitropack/runtime/internal/config",
|
|
330
|
-
imports: ["useRuntimeConfig", "useAppConfig"]
|
|
331
|
-
},
|
|
332
|
-
{
|
|
333
|
-
from: "nitropack/runtime/internal/plugin",
|
|
334
|
-
imports: ["defineNitroPlugin", "nitroPlugin"]
|
|
335
|
-
},
|
|
336
|
-
{
|
|
337
|
-
from: "nitropack/runtime/internal/cache",
|
|
338
|
-
imports: [
|
|
339
|
-
"defineCachedFunction",
|
|
340
|
-
"defineCachedEventHandler",
|
|
341
|
-
"cachedFunction",
|
|
342
|
-
"cachedEventHandler"
|
|
343
|
-
]
|
|
344
|
-
},
|
|
345
|
-
{
|
|
346
|
-
from: "nitropack/runtime/internal/storage",
|
|
347
|
-
imports: ["useStorage"]
|
|
348
|
-
},
|
|
349
|
-
{
|
|
350
|
-
from: "nitropack/runtime/internal/renderer",
|
|
351
|
-
imports: ["defineRenderHandler"]
|
|
352
|
-
},
|
|
353
|
-
{
|
|
354
|
-
from: "nitropack/runtime/internal/meta",
|
|
355
|
-
imports: ["defineRouteMeta"]
|
|
356
|
-
},
|
|
357
|
-
{
|
|
358
|
-
from: "nitropack/runtime/internal/route-rules",
|
|
359
|
-
imports: ["getRouteRules"]
|
|
360
|
-
},
|
|
361
|
-
{
|
|
362
|
-
from: "nitropack/runtime/internal/context",
|
|
363
|
-
imports: ["useEvent"]
|
|
364
|
-
},
|
|
365
|
-
{
|
|
366
|
-
from: "nitropack/runtime/internal/task",
|
|
367
|
-
imports: ["defineTask", "runTask"]
|
|
368
|
-
},
|
|
369
|
-
{
|
|
370
|
-
from: "nitropack/runtime/internal/error/utils",
|
|
371
|
-
imports: ["defineNitroErrorHandler"]
|
|
372
|
-
}
|
|
373
|
-
];
|
|
374
|
-
}
|
|
375
321
|
|
|
376
322
|
async function nuxtFramework(silgi, skip = false) {
|
|
377
323
|
if (silgi.options.preset !== "nuxt" && skip === false)
|
package/dist/kit/index.d.mts
CHANGED
|
@@ -18,6 +18,31 @@ declare function tryResolveModule(id: string, url?: string | string[]): Promise<
|
|
|
18
18
|
declare function writeFile(file: string, contents: Buffer | string, log?: boolean): Promise<void>;
|
|
19
19
|
declare function isDirectory(path: string): Promise<boolean>;
|
|
20
20
|
|
|
21
|
+
/**
|
|
22
|
+
* Interface for function call configurations
|
|
23
|
+
*/
|
|
24
|
+
interface FunctionConfig {
|
|
25
|
+
name: string;
|
|
26
|
+
args: any[];
|
|
27
|
+
}
|
|
28
|
+
declare function createFunctionConfigs(configs: FunctionConfig[]): FunctionConfig[];
|
|
29
|
+
/**
|
|
30
|
+
* Generic utility function to create function call configurations
|
|
31
|
+
* @param name Function name
|
|
32
|
+
* @param args Function arguments (default empty object)
|
|
33
|
+
* @returns Structured function configuration
|
|
34
|
+
*/
|
|
35
|
+
declare function createFunction(name: string, args?: any): FunctionConfig;
|
|
36
|
+
/**
|
|
37
|
+
* Format function calls with consistent indentation for code generation
|
|
38
|
+
* @param configs Array of function configurations
|
|
39
|
+
* @param indentation Spaces for indentation (default 4)
|
|
40
|
+
* @param specialVars Array of variable names that should be treated as code references not strings
|
|
41
|
+
* @param deduplicateArgs Whether to extract duplicate arguments into variables (default false)
|
|
42
|
+
* @returns Formatted string of function calls
|
|
43
|
+
*/
|
|
44
|
+
declare function formatFunctions(configs: FunctionConfig[], indentation?: number, specialVars?: string[], deduplicateArgs?: boolean): string;
|
|
45
|
+
|
|
21
46
|
declare function genEnsureSafeVar(name: string | any): string;
|
|
22
47
|
declare function getAllEntries(obj: object): [string, any][];
|
|
23
48
|
|
|
@@ -149,4 +174,5 @@ declare function hasInstalledModule(moduleKey: string, silgi?: SilgiCLI): boolea
|
|
|
149
174
|
declare const baseHeaderBannerComment: string[];
|
|
150
175
|
declare function processFilePath(src: string): string;
|
|
151
176
|
|
|
152
|
-
export { MODE_RE, addTemplate, baseHeaderBannerComment, createResolver, defineSilgiModule, defineSilgiPreset, directoryToURL, filterInPlace, genEnsureSafeVar, getAllEntries, getIpAddress, hasError, hasInstalledModule, hasSilgiModule, hash, ipAddress, isDirectory, isH3, isNitro, isNuxt, normalizeTemplate, parseServices, prettyPath, processFilePath, relativeWithDot, resolveAlias, resolvePath, resolveSilgiModule, resolveSilgiPath, serviceParseModule, toArray, tryResolveModule, useLogger, useRequest, useResponse, writeFile };
|
|
177
|
+
export { MODE_RE, addTemplate, baseHeaderBannerComment, createFunction, createFunctionConfigs, createResolver, defineSilgiModule, defineSilgiPreset, directoryToURL, filterInPlace, formatFunctions, genEnsureSafeVar, getAllEntries, getIpAddress, hasError, hasInstalledModule, hasSilgiModule, hash, ipAddress, isDirectory, isH3, isNitro, isNuxt, normalizeTemplate, parseServices, prettyPath, processFilePath, relativeWithDot, resolveAlias, resolvePath, resolveSilgiModule, resolveSilgiPath, serviceParseModule, toArray, tryResolveModule, useLogger, useRequest, useResponse, writeFile };
|
|
178
|
+
export type { FunctionConfig };
|
package/dist/kit/index.mjs
CHANGED
|
@@ -87,6 +87,85 @@ async function isDirectory$1(path) {
|
|
|
87
87
|
}
|
|
88
88
|
}
|
|
89
89
|
|
|
90
|
+
function createFunctionConfigs(configs) {
|
|
91
|
+
return configs;
|
|
92
|
+
}
|
|
93
|
+
function createFunction(name, args = {}) {
|
|
94
|
+
return {
|
|
95
|
+
name,
|
|
96
|
+
args: Object.keys(args).length > 0 ? [args] : []
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
function formatFunctions(configs, indentation = 4, specialVars = [], deduplicateArgs = false) {
|
|
100
|
+
const indent = " ".repeat(indentation);
|
|
101
|
+
const argMap = /* @__PURE__ */ new Map();
|
|
102
|
+
const argVarDeclarations = [];
|
|
103
|
+
let argCounter = 0;
|
|
104
|
+
if (deduplicateArgs) {
|
|
105
|
+
configs.forEach((config) => {
|
|
106
|
+
if (config.args.length > 0) {
|
|
107
|
+
const argStr = JSON.stringify(config.args[0]);
|
|
108
|
+
if (!argMap.has(argStr) && argStr.length > 20) {
|
|
109
|
+
const varName = `args${argCounter++}`;
|
|
110
|
+
argMap.set(argStr, varName);
|
|
111
|
+
argVarDeclarations.push(`const ${varName} = ${processArgString(argStr, specialVars, indentation)}`);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
function processArgString(argStr, specialVars2, indentLevel) {
|
|
117
|
+
const parsed = JSON.parse(argStr);
|
|
118
|
+
const prettified = formatObjectWithIndentation(parsed, indentLevel);
|
|
119
|
+
let processed = prettified;
|
|
120
|
+
specialVars2.forEach((varName) => {
|
|
121
|
+
processed = processed.replace(new RegExp(`"${varName}"`, "g"), varName);
|
|
122
|
+
});
|
|
123
|
+
return processed;
|
|
124
|
+
}
|
|
125
|
+
function formatObjectWithIndentation(obj, indentLevel) {
|
|
126
|
+
const baseIndent = " ".repeat(indentLevel);
|
|
127
|
+
const innerIndent = " ".repeat(indentLevel + 2);
|
|
128
|
+
if (typeof obj !== "object" || obj === null) {
|
|
129
|
+
return JSON.stringify(obj);
|
|
130
|
+
}
|
|
131
|
+
if (Array.isArray(obj)) {
|
|
132
|
+
if (obj.length === 0)
|
|
133
|
+
return "[]";
|
|
134
|
+
const items = obj.map(
|
|
135
|
+
(item) => `${innerIndent}${formatObjectWithIndentation(item, indentLevel + 2)}`
|
|
136
|
+
).join(",\n");
|
|
137
|
+
return `[
|
|
138
|
+
${items}
|
|
139
|
+
${baseIndent}]`;
|
|
140
|
+
}
|
|
141
|
+
if (Object.keys(obj).length === 0)
|
|
142
|
+
return "{}";
|
|
143
|
+
const entries = Object.entries(obj).map(([key, value]) => {
|
|
144
|
+
return `${innerIndent}${key}: ${formatObjectWithIndentation(value, indentLevel + 2)}`;
|
|
145
|
+
}).join(",\n");
|
|
146
|
+
return `{
|
|
147
|
+
${entries}
|
|
148
|
+
${baseIndent}}`;
|
|
149
|
+
}
|
|
150
|
+
const formattedCalls = configs.map((config) => {
|
|
151
|
+
if (config.args.length === 0) {
|
|
152
|
+
return `${indent}${config.name}()`;
|
|
153
|
+
}
|
|
154
|
+
const argStr = JSON.stringify(config.args[0]);
|
|
155
|
+
if (deduplicateArgs && argMap.has(argStr) && argStr.length > 20) {
|
|
156
|
+
return `${indent}${config.name}(${argMap.get(argStr)})`;
|
|
157
|
+
} else {
|
|
158
|
+
return `${indent}${config.name}(${processArgString(argStr, specialVars, indentation)})`;
|
|
159
|
+
}
|
|
160
|
+
}).join(",\n");
|
|
161
|
+
if (deduplicateArgs && argVarDeclarations.length > 0) {
|
|
162
|
+
return `${argVarDeclarations.join(";\n")};
|
|
163
|
+
|
|
164
|
+
${formattedCalls}`;
|
|
165
|
+
}
|
|
166
|
+
return formattedCalls;
|
|
167
|
+
}
|
|
168
|
+
|
|
90
169
|
const reservedCode = /* @__PURE__ */ new Set([
|
|
91
170
|
"process",
|
|
92
171
|
"global",
|
|
@@ -526,4 +605,4 @@ function isValidIp(ip) {
|
|
|
526
605
|
return false;
|
|
527
606
|
}
|
|
528
607
|
|
|
529
|
-
export { MODE_RE, addTemplate, baseHeaderBannerComment, createResolver, defineSilgiModule, defineSilgiPreset, directoryToURL, filterInPlace, genEnsureSafeVar, getAllEntries, getIpAddress, hasError, hasInstalledModule, hasSilgiModule, hash, ipAddress, isDirectory$1 as isDirectory, isH3, isNitro, isNuxt, normalizeTemplate, parseServices, prettyPath, processFilePath, relativeWithDot, resolveAlias, resolvePath, resolveSilgiModule, resolveSilgiPath, serviceParseModule, toArray, tryResolveModule, useLogger, useRequest, useResponse, writeFile };
|
|
608
|
+
export { MODE_RE, addTemplate, baseHeaderBannerComment, createFunction, createFunctionConfigs, createResolver, defineSilgiModule, defineSilgiPreset, directoryToURL, filterInPlace, formatFunctions, genEnsureSafeVar, getAllEntries, getIpAddress, hasError, hasInstalledModule, hasSilgiModule, hash, ipAddress, isDirectory$1 as isDirectory, isH3, isNitro, isNuxt, normalizeTemplate, parseServices, prettyPath, processFilePath, relativeWithDot, resolveAlias, resolvePath, resolveSilgiModule, resolveSilgiPath, serviceParseModule, toArray, tryResolveModule, useLogger, useRequest, useResponse, writeFile };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "silgi",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.25.
|
|
4
|
+
"version": "0.25.20",
|
|
5
5
|
"private": false,
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"exports": {
|
|
@@ -67,17 +67,17 @@
|
|
|
67
67
|
}
|
|
68
68
|
},
|
|
69
69
|
"dependencies": {
|
|
70
|
-
"@clack/prompts": "^0.10.
|
|
71
|
-
"@fastify/deepmerge": "^3.
|
|
70
|
+
"@clack/prompts": "^0.10.1",
|
|
71
|
+
"@fastify/deepmerge": "^3.1.0",
|
|
72
72
|
"@oxc-parser/wasm": "^0.60.0",
|
|
73
73
|
"@standard-schema/spec": "^1.0.0",
|
|
74
|
-
"c12": "^3.0.
|
|
74
|
+
"c12": "^3.0.3",
|
|
75
75
|
"chokidar": "^4.0.3",
|
|
76
76
|
"citty": "^0.1.6",
|
|
77
|
-
"compatx": "^0.
|
|
77
|
+
"compatx": "^0.2.0",
|
|
78
78
|
"consola": "^3.4.2",
|
|
79
79
|
"defu": "^6.1.4",
|
|
80
|
-
"destr": "^2.0.
|
|
80
|
+
"destr": "^2.0.5",
|
|
81
81
|
"dev-jiti": "^2.4.2",
|
|
82
82
|
"dot-prop": "^9.0.0",
|
|
83
83
|
"dotenv": "^16.4.7",
|
|
@@ -96,28 +96,28 @@
|
|
|
96
96
|
"pkg-types": "^2.1.0",
|
|
97
97
|
"scule": "^1.3.0",
|
|
98
98
|
"semver": "^7.7.1",
|
|
99
|
-
"std-env": "^3.
|
|
100
|
-
"ufo": "^1.
|
|
99
|
+
"std-env": "^3.9.0",
|
|
100
|
+
"ufo": "^1.6.1",
|
|
101
101
|
"unctx": "^2.4.1",
|
|
102
|
-
"unimport": "^
|
|
102
|
+
"unimport": "^5.0.0",
|
|
103
103
|
"unstorage": "^1.15.0",
|
|
104
104
|
"untyped": "^2.0.0"
|
|
105
105
|
},
|
|
106
106
|
"devDependencies": {
|
|
107
107
|
"@antfu/eslint-config": "^4.11.0",
|
|
108
|
-
"@nuxt/kit": "^3.16.
|
|
109
|
-
"@nuxt/schema": "^3.16.
|
|
108
|
+
"@nuxt/kit": "^3.16.2",
|
|
109
|
+
"@nuxt/schema": "^3.16.2",
|
|
110
110
|
"@silgi/ecosystem": "^0.4.4",
|
|
111
|
-
"@types/node": "^22.
|
|
112
|
-
"@types/semver": "^7.
|
|
111
|
+
"@types/node": "^22.14.0",
|
|
112
|
+
"@types/semver": "^7.7.0",
|
|
113
113
|
"@vitest/coverage-v8": "3.0.5",
|
|
114
|
-
"eslint": "^9.
|
|
114
|
+
"eslint": "^9.24.0",
|
|
115
115
|
"h3": "^1.15.1",
|
|
116
|
-
"nitropack": "^2.11.
|
|
117
|
-
"nuxt": "^3.16.
|
|
118
|
-
"typescript": "^5.8.
|
|
116
|
+
"nitropack": "^2.11.8",
|
|
117
|
+
"nuxt": "^3.16.2",
|
|
118
|
+
"typescript": "^5.8.3",
|
|
119
119
|
"unbuild": "^3.5.0",
|
|
120
|
-
"vitest": "^3.
|
|
120
|
+
"vitest": "^3.1.1",
|
|
121
121
|
"vue": "^3.5.13",
|
|
122
122
|
"zod": "^3.24.2"
|
|
123
123
|
},
|