silgi 0.25.18 → 0.26.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.
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import { defineCommand, runMain } from 'citty';
3
3
 
4
- const version = "0.25.18";
4
+ const version = "0.26.0";
5
5
  const packageJson = {
6
6
  version: version};
7
7
 
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';
@@ -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 };
@@ -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 };
@@ -1,3 +1,4 @@
1
+ import { ApifulConfig } from 'apiful/config';
1
2
  import { C12InputConfig, ResolvedConfig, ConfigWatcher, WatchConfigOptions } from 'c12';
2
3
  import { ChokidarOptions } from 'chokidar';
3
4
  import { DateString, CompatibilityDateSpec, CompatibilityDates } from 'compatx';
@@ -801,6 +802,7 @@ interface SilgiCLIOptions extends PresetOptions {
801
802
  description?: string;
802
803
  }>>;
803
804
  installPackages: Record<'dependencies' | 'devDependencies', Record<string, string>>;
805
+ apiFul: ApifulConfig;
804
806
  }
805
807
  /**
806
808
  * Silgi input config (silgi.config)
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "silgi",
3
3
  "type": "module",
4
- "version": "0.25.18",
4
+ "version": "0.26.0",
5
5
  "private": false,
6
6
  "sideEffects": false,
7
7
  "exports": {
@@ -67,17 +67,18 @@
67
67
  }
68
68
  },
69
69
  "dependencies": {
70
- "@clack/prompts": "^0.10.0",
71
- "@fastify/deepmerge": "^3.0.0",
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.2",
74
+ "apiful": "^2.0.2",
75
+ "c12": "^3.0.3",
75
76
  "chokidar": "^4.0.3",
76
77
  "citty": "^0.1.6",
77
- "compatx": "^0.1.8",
78
+ "compatx": "^0.2.0",
78
79
  "consola": "^3.4.2",
79
80
  "defu": "^6.1.4",
80
- "destr": "^2.0.3",
81
+ "destr": "^2.0.5",
81
82
  "dev-jiti": "^2.4.2",
82
83
  "dot-prop": "^9.0.0",
83
84
  "dotenv": "^16.4.7",
@@ -96,28 +97,28 @@
96
97
  "pkg-types": "^2.1.0",
97
98
  "scule": "^1.3.0",
98
99
  "semver": "^7.7.1",
99
- "std-env": "^3.8.1",
100
- "ufo": "^1.5.4",
100
+ "std-env": "^3.9.0",
101
+ "ufo": "^1.6.1",
101
102
  "unctx": "^2.4.1",
102
- "unimport": "^4.1.2",
103
+ "unimport": "^5.0.0",
103
104
  "unstorage": "^1.15.0",
104
105
  "untyped": "^2.0.0"
105
106
  },
106
107
  "devDependencies": {
107
108
  "@antfu/eslint-config": "^4.11.0",
108
- "@nuxt/kit": "^3.16.1",
109
- "@nuxt/schema": "^3.16.1",
109
+ "@nuxt/kit": "^3.16.2",
110
+ "@nuxt/schema": "^3.16.2",
110
111
  "@silgi/ecosystem": "^0.4.4",
111
- "@types/node": "^22.13.13",
112
- "@types/semver": "^7.5.8",
112
+ "@types/node": "^22.14.0",
113
+ "@types/semver": "^7.7.0",
113
114
  "@vitest/coverage-v8": "3.0.5",
114
- "eslint": "^9.23.0",
115
+ "eslint": "^9.24.0",
115
116
  "h3": "^1.15.1",
116
- "nitropack": "^2.11.7",
117
- "nuxt": "^3.16.1",
118
- "typescript": "^5.8.2",
117
+ "nitropack": "^2.11.8",
118
+ "nuxt": "^3.16.2",
119
+ "typescript": "^5.8.3",
119
120
  "unbuild": "^3.5.0",
120
- "vitest": "^3.0.9",
121
+ "vitest": "^3.1.1",
121
122
  "vue": "^3.5.13",
122
123
  "zod": "^3.24.2"
123
124
  },