silgi 0.28.11 → 0.29.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/cli/index.mjs +1 -1
- package/dist/cli/prepare.mjs +105 -173
- package/dist/cli/silgi.mjs +0 -45
- package/dist/cli/types.mjs +0 -1
- package/dist/kit/index.d.mts +4 -3
- package/dist/kit/index.mjs +54 -48
- package/dist/types/index.d.mts +18 -16
- package/package.json +1 -1
package/dist/cli/index.mjs
CHANGED
package/dist/cli/prepare.mjs
CHANGED
|
@@ -3,12 +3,14 @@ import { resolve } from 'pathe';
|
|
|
3
3
|
import { version } from 'silgi/meta';
|
|
4
4
|
import { p as prepareEnv, c as createSilgiCLI, b as build } from './silgi.mjs';
|
|
5
5
|
import { execSync } from 'node:child_process';
|
|
6
|
-
import { readFileSync } from 'node:fs';
|
|
7
6
|
import * as p from '@clack/prompts';
|
|
7
|
+
import { isCancel, cancel } from '@clack/prompts';
|
|
8
8
|
import { consola } from 'consola';
|
|
9
9
|
import { createJiti } from 'dev-jiti';
|
|
10
|
-
import { useSilgiCLI } from 'silgi';
|
|
11
|
-
import { a as silgiCLIIClose } from '../_chunks/silgiApp.mjs';
|
|
10
|
+
import { useSilgiCLI as useSilgiCLI$1 } from 'silgi';
|
|
11
|
+
import { u as useSilgiCLI, a as silgiCLIIClose } from '../_chunks/silgiApp.mjs';
|
|
12
|
+
import { addTemplate } from 'silgi/kit';
|
|
13
|
+
import { generateTypes, resolveSchema } from 'untyped';
|
|
12
14
|
import { l as loadOptions } from './types.mjs';
|
|
13
15
|
|
|
14
16
|
const commonArgs = {
|
|
@@ -23,6 +25,72 @@ const commonArgs = {
|
|
|
23
25
|
}
|
|
24
26
|
};
|
|
25
27
|
|
|
28
|
+
function debugMode(name) {
|
|
29
|
+
const silgi = useSilgiCLI();
|
|
30
|
+
if (silgi.options.debug === true || typeof silgi.options.debug === "object" && silgi.options.debug[name]) {
|
|
31
|
+
return true;
|
|
32
|
+
}
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
async function scanCommands(silgi = useSilgiCLI()) {
|
|
37
|
+
const commands = [];
|
|
38
|
+
await silgi.callHook("prepare:commands", commands);
|
|
39
|
+
if (debugMode("command")) {
|
|
40
|
+
addTemplate({
|
|
41
|
+
filename: "cli.json",
|
|
42
|
+
where: ".silgi",
|
|
43
|
+
write: true,
|
|
44
|
+
getContents: () => JSON.stringify(commands, null, 2)
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
silgi.hook("prepare:schema.ts", async (object) => {
|
|
48
|
+
const allTags = commands.reduce((acc, commandGroup) => {
|
|
49
|
+
Object.values(commandGroup).forEach((command) => {
|
|
50
|
+
if (command.tags) {
|
|
51
|
+
command.tags.forEach((tag) => acc.add(tag));
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
return acc;
|
|
55
|
+
}, /* @__PURE__ */ new Set());
|
|
56
|
+
const data = [
|
|
57
|
+
"",
|
|
58
|
+
generateTypes(
|
|
59
|
+
await resolveSchema(
|
|
60
|
+
{
|
|
61
|
+
...Object.fromEntries(Array.from(allTags.values()).map((tag) => [tag, "string"]))
|
|
62
|
+
}
|
|
63
|
+
),
|
|
64
|
+
{
|
|
65
|
+
interfaceName: "SilgiCommandsExtended",
|
|
66
|
+
addExport: false,
|
|
67
|
+
addDefaults: false,
|
|
68
|
+
allowExtraKeys: false,
|
|
69
|
+
indentation: 0
|
|
70
|
+
}
|
|
71
|
+
),
|
|
72
|
+
""
|
|
73
|
+
];
|
|
74
|
+
object.customImports?.push(...data);
|
|
75
|
+
});
|
|
76
|
+
return commands;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function cancelOnCancel({
|
|
80
|
+
value,
|
|
81
|
+
message = "Cancelled",
|
|
82
|
+
onBeforeExit,
|
|
83
|
+
exitCode = 0
|
|
84
|
+
} = {}) {
|
|
85
|
+
const handleCancel = () => {
|
|
86
|
+
cancel(message);
|
|
87
|
+
onBeforeExit?.();
|
|
88
|
+
process.exit(exitCode);
|
|
89
|
+
};
|
|
90
|
+
if (!value || isCancel(value))
|
|
91
|
+
handleCancel();
|
|
92
|
+
}
|
|
93
|
+
|
|
26
94
|
const command$1 = defineCommand({
|
|
27
95
|
meta: {
|
|
28
96
|
name: "run",
|
|
@@ -48,191 +116,53 @@ const command$1 = defineCommand({
|
|
|
48
116
|
const data = args.active ? await runCommand(command, {
|
|
49
117
|
rawArgs: ["--commands", "run"]
|
|
50
118
|
}) : void 0;
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
return data?.result?.silgi?.options?.runtimeConfig || {};
|
|
54
|
-
};
|
|
119
|
+
const silgi = useSilgiCLI$1();
|
|
120
|
+
const commands = await scanCommands();
|
|
55
121
|
if (!data?.result?.silgi && args.active) {
|
|
56
122
|
consola.error("Silgi not found");
|
|
57
123
|
return;
|
|
58
124
|
}
|
|
59
|
-
const silgi = useSilgiCLI();
|
|
60
125
|
const tags = args.tag?.split(",").map((t) => t.trim());
|
|
61
126
|
const silgiConfig = await loadOptions({});
|
|
62
|
-
const getCli = resolve(silgiConfig.build.dir, "cli.json");
|
|
63
|
-
const cli = readFileSync(getCli, "utf-8");
|
|
64
|
-
const cliJson = JSON.parse(cli);
|
|
65
127
|
await prepareEnv(silgiConfig);
|
|
66
128
|
let selectedCommands = [];
|
|
67
|
-
if (tags) {
|
|
68
|
-
|
|
69
|
-
const scripts = cliJson[commandName];
|
|
70
|
-
for (const scriptName of Object.keys(scripts)) {
|
|
71
|
-
const script = scripts[scriptName];
|
|
72
|
-
if (script.tags && script.tags.some((tag) => tags.includes(tag))) {
|
|
73
|
-
selectedCommands.push({
|
|
74
|
-
command: commandName,
|
|
75
|
-
script: scriptName,
|
|
76
|
-
handler: script
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
if (selectedCommands.length === 0) {
|
|
82
|
-
return;
|
|
83
|
-
}
|
|
129
|
+
if (tags?.length) {
|
|
130
|
+
selectedCommands = commands.filter((cmd) => cmd.tags?.some((tag) => tags.includes(tag))).filter((cmd) => cmd.when !== false);
|
|
84
131
|
} else {
|
|
85
|
-
|
|
86
|
-
consola.error("Silgi not found");
|
|
87
|
-
return;
|
|
88
|
-
}
|
|
89
|
-
if (Object.keys(cliJson).length === 0) {
|
|
90
|
-
consola.warn("No commands found in cli.json");
|
|
91
|
-
return;
|
|
92
|
-
}
|
|
93
|
-
const allTags = Object.values(silgi.commands).reduce((acc, commandGroup) => {
|
|
94
|
-
Object.values(commandGroup).forEach((command2) => {
|
|
95
|
-
if (command2.tags) {
|
|
96
|
-
command2.tags.forEach((tag) => acc.add(tag));
|
|
97
|
-
}
|
|
98
|
-
});
|
|
99
|
-
return acc;
|
|
100
|
-
}, /* @__PURE__ */ new Set());
|
|
101
|
-
const commandName = await p.select({
|
|
102
|
-
message: "Select a command to run",
|
|
103
|
-
options: [
|
|
104
|
-
...allTags.size ? [{
|
|
105
|
-
value: "command-tags",
|
|
106
|
-
label: "Command Tags",
|
|
107
|
-
hint: "It executes all commands that are related to the tags you select."
|
|
108
|
-
}] : [],
|
|
109
|
-
{
|
|
110
|
-
value: "functions",
|
|
111
|
-
label: "Functions",
|
|
112
|
-
hint: "Select and run individual functions"
|
|
113
|
-
},
|
|
114
|
-
...Object.keys(cliJson).filter((key) => {
|
|
115
|
-
const scripts = cliJson[key];
|
|
116
|
-
const scriptValues = Object.values(scripts);
|
|
117
|
-
return scriptValues;
|
|
118
|
-
}).map((key) => ({
|
|
119
|
-
label: key,
|
|
120
|
-
value: key
|
|
121
|
-
}))
|
|
122
|
-
]
|
|
123
|
-
});
|
|
124
|
-
if (!commandName)
|
|
125
|
-
return;
|
|
126
|
-
if (commandName === "command-tags") {
|
|
127
|
-
const tags2 = Array.from(allTags);
|
|
128
|
-
const selectedTags = await p.select({
|
|
129
|
-
message: "Select tags to run",
|
|
130
|
-
options: tags2.map((tag) => ({
|
|
131
|
-
label: tag,
|
|
132
|
-
value: tag
|
|
133
|
-
}))
|
|
134
|
-
});
|
|
135
|
-
if (!selectedTags)
|
|
136
|
-
return;
|
|
137
|
-
selectedCommands = Object.keys(cliJson).map(
|
|
138
|
-
(commandName2) => {
|
|
139
|
-
const scripts = cliJson[commandName2];
|
|
140
|
-
return Object.keys(scripts).map((scriptName) => ({
|
|
141
|
-
command: commandName2,
|
|
142
|
-
script: scriptName,
|
|
143
|
-
handler: scripts[scriptName]
|
|
144
|
-
})).filter((script) => script.handler.tags?.includes(selectedTags));
|
|
145
|
-
}
|
|
146
|
-
).flat();
|
|
147
|
-
} else if (commandName === "functions") {
|
|
148
|
-
const functionGroups = Object.keys(cliJson).reduce((groups, cmdName) => {
|
|
149
|
-
const scripts2 = cliJson[cmdName];
|
|
150
|
-
if (!Object.values(scripts2).some((script) => script.type === "function")) {
|
|
151
|
-
return groups;
|
|
152
|
-
}
|
|
153
|
-
groups.push(cmdName);
|
|
154
|
-
return groups;
|
|
155
|
-
}, []);
|
|
156
|
-
if (functionGroups.length === 0) {
|
|
157
|
-
consola.warn("No function groups found in cli.json");
|
|
158
|
-
return;
|
|
159
|
-
}
|
|
160
|
-
const selectedGroup = await p.select({
|
|
161
|
-
message: "Select a project group",
|
|
162
|
-
options: functionGroups.map((group) => ({
|
|
163
|
-
label: group,
|
|
164
|
-
value: group
|
|
165
|
-
}))
|
|
166
|
-
});
|
|
167
|
-
if (!selectedGroup)
|
|
168
|
-
return;
|
|
169
|
-
const availableFunctions = [];
|
|
170
|
-
const scripts = cliJson[selectedGroup];
|
|
171
|
-
for (const scriptName of Object.keys(scripts)) {
|
|
172
|
-
const script = scripts[scriptName];
|
|
173
|
-
if (script && script.type === "function") {
|
|
174
|
-
availableFunctions.push({
|
|
175
|
-
command: selectedGroup,
|
|
176
|
-
script: scriptName,
|
|
177
|
-
handler: script
|
|
178
|
-
});
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
if (availableFunctions.length === 0) {
|
|
182
|
-
consola.warn(`No functions found in the ${selectedGroup} group`);
|
|
183
|
-
return;
|
|
184
|
-
}
|
|
185
|
-
const selectedFunction = await p.select({
|
|
186
|
-
message: `Select a function from ${selectedGroup}`,
|
|
187
|
-
options: availableFunctions.map((fn, index) => ({
|
|
188
|
-
label: fn.script,
|
|
189
|
-
value: index.toString(),
|
|
190
|
-
hint: fn.handler.description || void 0
|
|
191
|
-
}))
|
|
192
|
-
});
|
|
193
|
-
if (!selectedFunction)
|
|
194
|
-
return;
|
|
195
|
-
const selectedIndex = Number.parseInt(selectedFunction, 10);
|
|
196
|
-
const selectedFunctionObj = availableFunctions[selectedIndex];
|
|
197
|
-
if (!selectedFunctionObj || !selectedFunctionObj.handler) {
|
|
198
|
-
consola.error("Selected function not found or invalid");
|
|
199
|
-
return;
|
|
200
|
-
}
|
|
201
|
-
selectedCommands = [{
|
|
202
|
-
command: selectedFunctionObj.command,
|
|
203
|
-
script: selectedFunctionObj.script,
|
|
204
|
-
handler: selectedFunctionObj.handler
|
|
205
|
-
}];
|
|
206
|
-
} else {
|
|
207
|
-
const scripts = cliJson[commandName];
|
|
208
|
-
const scriptName = await p.select({
|
|
209
|
-
message: "Select a script to run",
|
|
210
|
-
options: Object.keys(scripts).filter((key) => !scripts[key].tags?.length).map((key) => ({
|
|
211
|
-
label: key,
|
|
212
|
-
value: key
|
|
213
|
-
}))
|
|
214
|
-
});
|
|
215
|
-
if (!scriptName)
|
|
216
|
-
return;
|
|
217
|
-
selectedCommands = [{
|
|
218
|
-
command: commandName,
|
|
219
|
-
script: scriptName,
|
|
220
|
-
handler: scripts[scriptName]
|
|
221
|
-
}];
|
|
222
|
-
}
|
|
132
|
+
selectedCommands = commands.filter((cmd) => cmd.when !== false);
|
|
223
133
|
}
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
134
|
+
const multiSelect = await p.groupMultiselect({
|
|
135
|
+
message: "Select commands to run",
|
|
136
|
+
required: true,
|
|
137
|
+
options: {
|
|
138
|
+
...selectedCommands.reduce((acc, cmd) => {
|
|
139
|
+
acc[cmd.group || ""] = [
|
|
140
|
+
{
|
|
141
|
+
label: cmd.name,
|
|
142
|
+
value: cmd,
|
|
143
|
+
hint: cmd.description
|
|
144
|
+
}
|
|
145
|
+
];
|
|
146
|
+
return acc;
|
|
147
|
+
}, {})
|
|
227
148
|
}
|
|
228
|
-
|
|
229
|
-
|
|
149
|
+
});
|
|
150
|
+
cancelOnCancel({ value: multiSelect });
|
|
151
|
+
selectedCommands = multiSelect;
|
|
152
|
+
const spinner = p.spinner({
|
|
153
|
+
indicator: "dots"
|
|
154
|
+
});
|
|
155
|
+
for (const cmd of selectedCommands) {
|
|
156
|
+
const data2 = cmd.getContents({ app: silgi });
|
|
157
|
+
spinner.start(`[${cmd.group}] ${cmd.name}...`);
|
|
158
|
+
if (cmd.type === "command") {
|
|
159
|
+
execSync(data2, { stdio: "inherit" });
|
|
230
160
|
}
|
|
231
|
-
if (cmd.
|
|
161
|
+
if (cmd.type === "function") {
|
|
232
162
|
const jiti = createJiti(import.meta.url, {
|
|
233
163
|
alias: silgiConfig.alias
|
|
234
164
|
});
|
|
235
|
-
let cleanHandler = cmd.
|
|
165
|
+
let cleanHandler = cmd.getContents({ app: silgi }).replace(/\n/g, "");
|
|
236
166
|
cleanHandler = `import { silgiCLICtx } from 'silgi'
|
|
237
167
|
${cleanHandler}
|
|
238
168
|
`;
|
|
@@ -243,6 +173,8 @@ const command$1 = defineCommand({
|
|
|
243
173
|
forceTranspile: true
|
|
244
174
|
});
|
|
245
175
|
}
|
|
176
|
+
spinner.stop();
|
|
177
|
+
consola.success(`[${cmd.group}] ${cmd.name} done`);
|
|
246
178
|
}
|
|
247
179
|
await silgiCLIIClose();
|
|
248
180
|
}
|
package/dist/cli/silgi.mjs
CHANGED
|
@@ -1534,49 +1534,6 @@ ${cycleStr}`);
|
|
|
1534
1534
|
return order;
|
|
1535
1535
|
}
|
|
1536
1536
|
|
|
1537
|
-
async function commands(silgi) {
|
|
1538
|
-
const commands2 = {
|
|
1539
|
-
...silgi.options.commands
|
|
1540
|
-
};
|
|
1541
|
-
await silgi.callHook("prepare:commands", commands2);
|
|
1542
|
-
addTemplate({
|
|
1543
|
-
filename: "cli.json",
|
|
1544
|
-
where: ".silgi",
|
|
1545
|
-
write: true,
|
|
1546
|
-
getContents: () => JSON.stringify(commands2, null, 2)
|
|
1547
|
-
});
|
|
1548
|
-
silgi.commands = commands2;
|
|
1549
|
-
silgi.hook("prepare:schema.ts", async (object) => {
|
|
1550
|
-
const allTags = Object.values(commands2).reduce((acc, commandGroup) => {
|
|
1551
|
-
Object.values(commandGroup).forEach((command) => {
|
|
1552
|
-
if (command.tags) {
|
|
1553
|
-
command.tags.forEach((tag) => acc.add(tag));
|
|
1554
|
-
}
|
|
1555
|
-
});
|
|
1556
|
-
return acc;
|
|
1557
|
-
}, /* @__PURE__ */ new Set());
|
|
1558
|
-
const data = [
|
|
1559
|
-
"",
|
|
1560
|
-
generateTypes(
|
|
1561
|
-
await resolveSchema(
|
|
1562
|
-
{
|
|
1563
|
-
...Object.fromEntries(Array.from(allTags.values()).map((tag) => [tag, "string"]))
|
|
1564
|
-
}
|
|
1565
|
-
),
|
|
1566
|
-
{
|
|
1567
|
-
interfaceName: "SilgiCommandsExtended",
|
|
1568
|
-
addExport: false,
|
|
1569
|
-
addDefaults: false,
|
|
1570
|
-
allowExtraKeys: false,
|
|
1571
|
-
indentation: 0
|
|
1572
|
-
}
|
|
1573
|
-
),
|
|
1574
|
-
""
|
|
1575
|
-
];
|
|
1576
|
-
object.customImports?.push(...data);
|
|
1577
|
-
});
|
|
1578
|
-
}
|
|
1579
|
-
|
|
1580
1537
|
function resolveIgnorePatterns(silgi, relativePath) {
|
|
1581
1538
|
if (!silgi) {
|
|
1582
1539
|
return [];
|
|
@@ -2306,7 +2263,6 @@ async function createSilgiCLI(config = {}, opts = {}) {
|
|
|
2306
2263
|
options,
|
|
2307
2264
|
hooks,
|
|
2308
2265
|
errors: [],
|
|
2309
|
-
commands: {},
|
|
2310
2266
|
_requiredModules: {},
|
|
2311
2267
|
logger: consola.withTag("silgi"),
|
|
2312
2268
|
close: () => silgi.hooks.callHook("close", silgi),
|
|
@@ -2363,7 +2319,6 @@ async function createSilgiCLI(config = {}, opts = {}) {
|
|
|
2363
2319
|
silgi.hooks.addHooks(silgi.options.hooks);
|
|
2364
2320
|
await installModules(silgi);
|
|
2365
2321
|
await silgi.hooks.callHook("scanFiles:done", silgi);
|
|
2366
|
-
await commands(silgi);
|
|
2367
2322
|
await generateApp(silgi);
|
|
2368
2323
|
if (silgi.options.imports) {
|
|
2369
2324
|
silgi.options.imports.dirs ??= [];
|
package/dist/cli/types.mjs
CHANGED
package/dist/kit/index.d.mts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import { SilgiCLI, ModuleOptionsCustom, ModuleDefinition, SilgiModule, ServiceParseModule, SilgiPreset, SilgiPresetMeta, SilgiTemplate, ResolvedSilgiTemplate, SilgiEvents } from 'silgi/types';
|
|
1
|
+
import { Commands, SilgiCLI, ModuleOptionsCustom, ModuleDefinition, SilgiModule, ServiceParseModule, SilgiPreset, SilgiPresetMeta, SilgiTemplate, ResolvedSilgiTemplate, SilgiEvents } from 'silgi/types';
|
|
2
2
|
import { Buffer } from 'node:buffer';
|
|
3
3
|
import { ConsolaOptions, ConsolaInstance } from 'consola';
|
|
4
4
|
import * as rfc6902 from 'rfc6902';
|
|
5
5
|
import { IncomingMessage, ServerResponse } from 'node:http';
|
|
6
6
|
|
|
7
|
+
declare function addCommands(data: Commands | Commands[]): Promise<void>;
|
|
8
|
+
|
|
7
9
|
declare function addNPMPackage(data: {
|
|
8
10
|
name: string;
|
|
9
11
|
version?: string;
|
|
@@ -269,7 +271,6 @@ declare function getIpAddress(event: SilgiEvents): string | boolean;
|
|
|
269
271
|
declare function ipAddress(req: IncomingMessage): string;
|
|
270
272
|
|
|
271
273
|
declare function relativeWithDot(from: string, to: string): string;
|
|
272
|
-
/** @since 3.9.0 */
|
|
273
274
|
declare function toArray<T>(value: T | T[]): T[];
|
|
274
275
|
/**
|
|
275
276
|
* Filter out items from an array in place. This function mutates the array.
|
|
@@ -290,5 +291,5 @@ declare function hasInstalledModule(moduleKey: string, silgi?: SilgiCLI): boolea
|
|
|
290
291
|
declare const baseHeaderBannerComment: string[];
|
|
291
292
|
declare function processFilePath(src: string): string;
|
|
292
293
|
|
|
293
|
-
export { MODE_RE, MigrationStatus, addNPMPackage, addTemplate, baseHeaderBannerComment, createFunction, createFunctionConfigs, createResolver, defineSilgiModule, defineSilgiPreset, directoryToURL, filterInPlace, formatFunctions, genEnsureSafeVar, generateMigration, getAllEntries, getIpAddress, getMigration, hasError, hasInstalledModule, hasSilgiModule, hash, ipAddress, isDirectory, isH3, isNitro, isNuxt, listMigrations, migrationDown, migrationUp, normalizeTemplate, parseServices, prettyPath, processFilePath, relativeWithDot, resolveAlias, resolvePath, resolveSilgiModule, resolveSilgiPath, serviceParseModule, toArray, tryResolveModule, useLogger, useRequest, useResponse, writeFile };
|
|
294
|
+
export { MODE_RE, MigrationStatus, addCommands, addNPMPackage, addTemplate, baseHeaderBannerComment, createFunction, createFunctionConfigs, createResolver, defineSilgiModule, defineSilgiPreset, directoryToURL, filterInPlace, formatFunctions, genEnsureSafeVar, generateMigration, getAllEntries, getIpAddress, getMigration, hasError, hasInstalledModule, hasSilgiModule, hash, ipAddress, isDirectory, isH3, isNitro, isNuxt, listMigrations, migrationDown, migrationUp, normalizeTemplate, parseServices, prettyPath, processFilePath, relativeWithDot, resolveAlias, resolvePath, resolveSilgiModule, resolveSilgiPath, serviceParseModule, toArray, tryResolveModule, useLogger, useRequest, useResponse, writeFile };
|
|
294
295
|
export type { FunctionConfig, JsonPatch, MigrationData, MigrationInfo, MigrationOptions, MigrationResult };
|
package/dist/kit/index.mjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
+
import { u as useSilgiCLI$1 } from '../_chunks/silgiApp.mjs';
|
|
2
|
+
import { relative, resolve, dirname, join, normalize, isAbsolute, parse, basename } from 'pathe';
|
|
3
|
+
import { useSilgiCLI, tryUseSilgiCLI, useSilgi } from 'silgi';
|
|
1
4
|
import { execSync } from 'node:child_process';
|
|
2
|
-
import { u as useSilgiCLI } from '../_chunks/silgiApp.mjs';
|
|
3
|
-
import { tryUseSilgiCLI, useSilgiCLI as useSilgiCLI$1, useSilgi } from 'silgi';
|
|
4
5
|
import { pathToFileURL, fileURLToPath } from 'node:url';
|
|
5
6
|
import { resolvePath as resolvePath$1 } from 'mlly';
|
|
6
7
|
import fsp, { mkdir, readFile, writeFile as writeFile$1 } from 'node:fs/promises';
|
|
7
8
|
import consola, { consola as consola$1 } from 'consola';
|
|
8
|
-
import { relative, resolve, dirname, join, normalize, isAbsolute, parse, basename } from 'pathe';
|
|
9
9
|
import { colors } from 'consola/utils';
|
|
10
10
|
import { getProperty } from 'dot-prop';
|
|
11
11
|
import { genString, genObjectFromRaw, genObjectFromValues, genObjectFromRawEntries } from 'knitwork';
|
|
@@ -22,9 +22,54 @@ import 'unctx';
|
|
|
22
22
|
import 'semver/functions/satisfies.js';
|
|
23
23
|
import 'silgi/meta';
|
|
24
24
|
|
|
25
|
+
const RELATIVE_RE = /^([^.])/;
|
|
26
|
+
function relativeWithDot(from, to) {
|
|
27
|
+
return relative(from, to).replace(RELATIVE_RE, "./$1") || ".";
|
|
28
|
+
}
|
|
29
|
+
function toArray(value) {
|
|
30
|
+
return Array.isArray(value) ? value : [value];
|
|
31
|
+
}
|
|
32
|
+
function filterInPlace(array, predicate) {
|
|
33
|
+
for (let i = array.length; i--; i >= 0) {
|
|
34
|
+
if (!predicate(array[i], i, array)) {
|
|
35
|
+
array.splice(i, 1);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return array;
|
|
39
|
+
}
|
|
40
|
+
const MODE_RE = /\.(server|client)(\.\w+)*$/;
|
|
41
|
+
function hasSilgiModule(moduleKey, silgi = useSilgiCLI()) {
|
|
42
|
+
return silgi.scanModules.some(({ meta }) => meta.configKey === moduleKey) || Object.keys(silgi.scanModules).includes(moduleKey);
|
|
43
|
+
}
|
|
44
|
+
function hasInstalledModule(moduleKey, silgi = useSilgiCLI()) {
|
|
45
|
+
const find = silgi.scanModules.find(({ meta }) => meta.configKey === moduleKey);
|
|
46
|
+
return find?.installed ?? false;
|
|
47
|
+
}
|
|
48
|
+
const baseHeaderBannerComment = [
|
|
49
|
+
"// DO NOT EDIT THIS FILE",
|
|
50
|
+
"// This file is generated by Silgi",
|
|
51
|
+
"/* eslint-disable */",
|
|
52
|
+
"/* prettier-ignore */",
|
|
53
|
+
"/* tslint:disable */"
|
|
54
|
+
];
|
|
55
|
+
function processFilePath(src) {
|
|
56
|
+
const silgi = useSilgiCLI();
|
|
57
|
+
if (silgi.options.typescript.removeFileExtension) {
|
|
58
|
+
src = src.replace(/\.ts$/, "");
|
|
59
|
+
return src;
|
|
60
|
+
}
|
|
61
|
+
return src;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
async function addCommands(data) {
|
|
65
|
+
useSilgiCLI$1().hook("prepare:commands", (commads) => {
|
|
66
|
+
commads.push(...toArray(data));
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
|
|
25
70
|
const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
26
71
|
async function addNPMPackage(data) {
|
|
27
|
-
const silgi = useSilgiCLI();
|
|
72
|
+
const silgi = useSilgiCLI$1();
|
|
28
73
|
for (const item of data) {
|
|
29
74
|
if (item.when === false) {
|
|
30
75
|
continue;
|
|
@@ -96,7 +141,7 @@ function _compilePathTemplate(contents) {
|
|
|
96
141
|
}
|
|
97
142
|
|
|
98
143
|
async function writeFile(file, contents, log = false) {
|
|
99
|
-
const silgi = useSilgiCLI
|
|
144
|
+
const silgi = useSilgiCLI();
|
|
100
145
|
if (silgi.errors.length) {
|
|
101
146
|
return;
|
|
102
147
|
}
|
|
@@ -599,7 +644,7 @@ function _defineSilgiModule(definition) {
|
|
|
599
644
|
}
|
|
600
645
|
const module = defu(definition, { meta: {} });
|
|
601
646
|
module.meta.configKey ||= module.meta.name;
|
|
602
|
-
async function getOptions(inlineOptions, silgi = useSilgiCLI
|
|
647
|
+
async function getOptions(inlineOptions, silgi = useSilgiCLI()) {
|
|
603
648
|
const nuxtConfigOptionsKey = module.meta.configKey || module.meta.name;
|
|
604
649
|
const nuxtConfigOptions = nuxtConfigOptionsKey && nuxtConfigOptionsKey in silgi.options ? silgi.options[nuxtConfigOptionsKey] : {};
|
|
605
650
|
const optionsDefaults = typeof module.defaults === "function" ? await module.defaults(silgi) : module.defaults ?? {};
|
|
@@ -783,47 +828,8 @@ async function resolveSilgiModule(base, paths) {
|
|
|
783
828
|
return resolved;
|
|
784
829
|
}
|
|
785
830
|
|
|
786
|
-
const RELATIVE_RE = /^([^.])/;
|
|
787
|
-
function relativeWithDot(from, to) {
|
|
788
|
-
return relative(from, to).replace(RELATIVE_RE, "./$1") || ".";
|
|
789
|
-
}
|
|
790
|
-
function toArray(value) {
|
|
791
|
-
return Array.isArray(value) ? value : [value];
|
|
792
|
-
}
|
|
793
|
-
function filterInPlace(array, predicate) {
|
|
794
|
-
for (let i = array.length; i--; i >= 0) {
|
|
795
|
-
if (!predicate(array[i], i, array)) {
|
|
796
|
-
array.splice(i, 1);
|
|
797
|
-
}
|
|
798
|
-
}
|
|
799
|
-
return array;
|
|
800
|
-
}
|
|
801
|
-
const MODE_RE = /\.(server|client)(\.\w+)*$/;
|
|
802
|
-
function hasSilgiModule(moduleKey, silgi = useSilgiCLI$1()) {
|
|
803
|
-
return silgi.scanModules.some(({ meta }) => meta.configKey === moduleKey) || Object.keys(silgi.scanModules).includes(moduleKey);
|
|
804
|
-
}
|
|
805
|
-
function hasInstalledModule(moduleKey, silgi = useSilgiCLI$1()) {
|
|
806
|
-
const find = silgi.scanModules.find(({ meta }) => meta.configKey === moduleKey);
|
|
807
|
-
return find?.installed ?? false;
|
|
808
|
-
}
|
|
809
|
-
const baseHeaderBannerComment = [
|
|
810
|
-
"// DO NOT EDIT THIS FILE",
|
|
811
|
-
"// This file is generated by Silgi",
|
|
812
|
-
"/* eslint-disable */",
|
|
813
|
-
"/* prettier-ignore */",
|
|
814
|
-
"/* tslint:disable */"
|
|
815
|
-
];
|
|
816
|
-
function processFilePath(src) {
|
|
817
|
-
const silgi = useSilgiCLI$1();
|
|
818
|
-
if (silgi.options.typescript.removeFileExtension) {
|
|
819
|
-
src = src.replace(/\.ts$/, "");
|
|
820
|
-
return src;
|
|
821
|
-
}
|
|
822
|
-
return src;
|
|
823
|
-
}
|
|
824
|
-
|
|
825
831
|
function addTemplate(_template) {
|
|
826
|
-
const silgi = useSilgiCLI
|
|
832
|
+
const silgi = useSilgiCLI();
|
|
827
833
|
const template = normalizeTemplate(_template);
|
|
828
834
|
filterInPlace(silgi.options.build.templates, (p) => normalizeTemplate(p).dst !== template.dst);
|
|
829
835
|
silgi.options.build.templates.push(template);
|
|
@@ -857,7 +863,7 @@ function normalizeTemplate(template, buildDir) {
|
|
|
857
863
|
template.write = true;
|
|
858
864
|
}
|
|
859
865
|
if (!template.dst) {
|
|
860
|
-
const silgi = useSilgiCLI
|
|
866
|
+
const silgi = useSilgiCLI();
|
|
861
867
|
const dir = template.where === ".silgi" ? silgi.options.build.dir : template.where === "server" ? silgi.options.silgi.serverDir : template.where === "client" ? silgi.options.silgi.clientDir : silgi.options.silgi.serverDir;
|
|
862
868
|
template.dst = resolve(buildDir ?? dir, template.filename);
|
|
863
869
|
}
|
|
@@ -952,4 +958,4 @@ function isValidIp(ip) {
|
|
|
952
958
|
return false;
|
|
953
959
|
}
|
|
954
960
|
|
|
955
|
-
export { MODE_RE, MigrationStatus, addNPMPackage, addTemplate, baseHeaderBannerComment, createFunction, createFunctionConfigs, createResolver, defineSilgiModule, defineSilgiPreset, directoryToURL, filterInPlace, formatFunctions, genEnsureSafeVar, generateMigration, getAllEntries, getIpAddress, getMigration, hasError, hasInstalledModule, hasSilgiModule, hash, ipAddress, isDirectory$1 as isDirectory, isH3, isNitro, isNuxt, listMigrations, migrationDown, migrationUp, normalizeTemplate, parseServices, prettyPath, processFilePath, relativeWithDot, resolveAlias, resolvePath, resolveSilgiModule, resolveSilgiPath, serviceParseModule, toArray, tryResolveModule, useLogger, useRequest, useResponse, writeFile };
|
|
961
|
+
export { MODE_RE, MigrationStatus, addCommands, addNPMPackage, addTemplate, baseHeaderBannerComment, createFunction, createFunctionConfigs, createResolver, defineSilgiModule, defineSilgiPreset, directoryToURL, filterInPlace, formatFunctions, genEnsureSafeVar, generateMigration, getAllEntries, getIpAddress, getMigration, hasError, hasInstalledModule, hasSilgiModule, hash, ipAddress, isDirectory$1 as isDirectory, isH3, isNitro, isNuxt, listMigrations, migrationDown, migrationUp, normalizeTemplate, parseServices, prettyPath, processFilePath, relativeWithDot, resolveAlias, resolvePath, resolveSilgiModule, resolveSilgiPath, serviceParseModule, toArray, tryResolveModule, useLogger, useRequest, useResponse, writeFile };
|
package/dist/types/index.d.mts
CHANGED
|
@@ -47,8 +47,6 @@ interface ImportItem {
|
|
|
47
47
|
customImports: string[];
|
|
48
48
|
customContent?: string[];
|
|
49
49
|
}
|
|
50
|
-
interface SilgiCommands {
|
|
51
|
-
}
|
|
52
50
|
interface SilgiCLI {
|
|
53
51
|
_ignore?: Ignore;
|
|
54
52
|
errors: {
|
|
@@ -82,13 +80,6 @@ interface SilgiCLI {
|
|
|
82
80
|
}>;
|
|
83
81
|
options: SilgiCLIOptions;
|
|
84
82
|
_requiredModules: Record<string, boolean>;
|
|
85
|
-
commands: Record<string, Record<string, {
|
|
86
|
-
type: 'function' | 'command';
|
|
87
|
-
handler: string;
|
|
88
|
-
description?: string;
|
|
89
|
-
tags?: (keyof SilgiCommands)[];
|
|
90
|
-
enabled?: boolean;
|
|
91
|
-
}>>;
|
|
92
83
|
adapters: Record<string, Adapter<Record<string, any>, TablesSchema, InferModelTypes<TablesSchema>>>;
|
|
93
84
|
}
|
|
94
85
|
type SilgiCLIDynamicConfig = Pick<SilgiCLIConfig, 'routeRules'>;
|
|
@@ -605,7 +596,9 @@ interface SilgiCLIOptions extends PresetOptions {
|
|
|
605
596
|
modules: (SilgiModule<any> | string | [SilgiModule | string, Record<string, any>] | undefined | null | false)[];
|
|
606
597
|
_modules: (SilgiModule<any> | string | [SilgiModule | string, Record<string, any>] | undefined | null | false)[];
|
|
607
598
|
isPreparingModules: boolean;
|
|
608
|
-
debug:
|
|
599
|
+
debug: true | {
|
|
600
|
+
command?: boolean;
|
|
601
|
+
};
|
|
609
602
|
preset: PresetName;
|
|
610
603
|
static: boolean;
|
|
611
604
|
logLevel: LogLevel;
|
|
@@ -805,11 +798,6 @@ interface SilgiCLIOptions extends PresetOptions {
|
|
|
805
798
|
* ```
|
|
806
799
|
*/
|
|
807
800
|
ignoreOptions: Options;
|
|
808
|
-
commands: Record<string, Record<string, {
|
|
809
|
-
type: 'function' | 'command';
|
|
810
|
-
handler: string;
|
|
811
|
-
description?: string;
|
|
812
|
-
}>>;
|
|
813
801
|
installPackages: Record<'dependencies' | 'devDependencies', Record<string, string>>;
|
|
814
802
|
apiFul: ApifulConfig;
|
|
815
803
|
adapters: Record<string, Adapter<Record<string, any>, TablesSchema, InferModelTypes<TablesSchema>>>;
|
|
@@ -1159,6 +1147,20 @@ interface GraphQLJSON {
|
|
|
1159
1147
|
references: any;
|
|
1160
1148
|
}
|
|
1161
1149
|
|
|
1150
|
+
interface SilgiCommands {
|
|
1151
|
+
}
|
|
1152
|
+
interface Commands {
|
|
1153
|
+
name: string;
|
|
1154
|
+
description?: string;
|
|
1155
|
+
group: string;
|
|
1156
|
+
when?: boolean;
|
|
1157
|
+
type: 'function' | 'command';
|
|
1158
|
+
tags?: (keyof SilgiCommands)[] | (string | object)[];
|
|
1159
|
+
getContents: (data: {
|
|
1160
|
+
app: SilgiCLI;
|
|
1161
|
+
}) => string;
|
|
1162
|
+
}
|
|
1163
|
+
|
|
1162
1164
|
interface BaseNamespaceType extends Record<keyof DefaultNamespaces, Record<string, BaseSchemaType<StandardSchemaV1>>> {
|
|
1163
1165
|
}
|
|
1164
1166
|
type Namespaces<T extends BaseNamespaceType> = {
|
|
@@ -1178,4 +1180,4 @@ interface ServiceParseModule {
|
|
|
1178
1180
|
(params: ServiceParse): Awaited<void> | void;
|
|
1179
1181
|
}
|
|
1180
1182
|
|
|
1181
|
-
export type { AllPaths, AppConfig, Awaitable, BaseNamespaceType, BaseSchemaType, BaseSilgiMethodType, CaptureError, CapturedErrorContext, CommandType, CreateScope, DeepPartial, DeepRequired, DefaultHooks, DefaultNamespaces, DefaultRouteConfig, DefaultRouteRules, DotenvOptions, EnvOptions, EventHandlerResponse, ExtendContext, ExtendShared, ExtractInputFromURI, ExtractOutputFromURI, ExtractPathParams, ExtractPathParamsFromURI, ExtractQueryParamsFromURI, ExtractSourceFromURI, FrameworkContext, GenerateAppOptions, GraphQLJSON, HookResult, HttpMethod, ImportItem, LoadConfigOptions, MergedSilgiSchema, MethodHandlerType, ModuleDefinition, ModuleHookContext, ModuleMeta, ModuleOptionsCustom, ModuleSetupInstallResult, ModuleSetupReturn, Namespaces, NitroBuildInfo, PrepareCore, RequiredServiceType, ResolvedMethodHandlerType, ResolvedModuleMeta, ResolvedModuleOptions, ResolvedServiceType, ResolvedSilgiTemplate, RouteRules, RouterParams, ScanFile, ServiceParse, ServiceParseModule, ServiceType, Silgi, SilgiAppPlugin, SilgiCLI, SilgiCLIConfig, SilgiCLIDynamicConfig, SilgiCLIHooks, SilgiCLIOptions, SilgiCommands, SilgiCompatibility, SilgiCompatibilityIssue, SilgiCompatibilityIssues, SilgiConfig, SilgiEvents, SilgiFetchClient, SilgiFetchOptions, SilgiFrameworkInfo, SilgiFunction, SilgiHooks, SilgiModule, SilgiModuleInput, SilgiModuleOptions, SilgiNamespaces, SilgiOperation, SilgiOptions, SilgiPreset, SilgiPresetMeta, SilgiRouteRules, SilgiRouterTypes, SilgiRuntimeActions, SilgiRuntimeConfig, SilgiRuntimeContext, SilgiRuntimeHooks, SilgiRuntimeMethods, SilgiRuntimeOptions, SilgiRuntimeRouteRules, SilgiRuntimeRouteRulesConfig, SilgiRuntimeShareds, SilgiRuntimeSharedsExtend, SilgiSchema, SilgiServiceInterface, SilgiStorageBase, SilgiTemplate, SilgiURIs, StorageConfig, StorageKeyGenerator, StorageKeyParams, StorageMounts, TSReference, TrimAfterFourSlashes, URIsTypes };
|
|
1183
|
+
export type { AllPaths, AppConfig, Awaitable, BaseNamespaceType, BaseSchemaType, BaseSilgiMethodType, CaptureError, CapturedErrorContext, CommandType, Commands, CreateScope, DeepPartial, DeepRequired, DefaultHooks, DefaultNamespaces, DefaultRouteConfig, DefaultRouteRules, DotenvOptions, EnvOptions, EventHandlerResponse, ExtendContext, ExtendShared, ExtractInputFromURI, ExtractOutputFromURI, ExtractPathParams, ExtractPathParamsFromURI, ExtractQueryParamsFromURI, ExtractSourceFromURI, FrameworkContext, GenerateAppOptions, GraphQLJSON, HookResult, HttpMethod, ImportItem, LoadConfigOptions, MergedSilgiSchema, MethodHandlerType, ModuleDefinition, ModuleHookContext, ModuleMeta, ModuleOptionsCustom, ModuleSetupInstallResult, ModuleSetupReturn, Namespaces, NitroBuildInfo, PrepareCore, RequiredServiceType, ResolvedMethodHandlerType, ResolvedModuleMeta, ResolvedModuleOptions, ResolvedServiceType, ResolvedSilgiTemplate, RouteRules, RouterParams, ScanFile, ServiceParse, ServiceParseModule, ServiceType, Silgi, SilgiAppPlugin, SilgiCLI, SilgiCLIConfig, SilgiCLIDynamicConfig, SilgiCLIHooks, SilgiCLIOptions, SilgiCommands, SilgiCompatibility, SilgiCompatibilityIssue, SilgiCompatibilityIssues, SilgiConfig, SilgiEvents, SilgiFetchClient, SilgiFetchOptions, SilgiFrameworkInfo, SilgiFunction, SilgiHooks, SilgiModule, SilgiModuleInput, SilgiModuleOptions, SilgiNamespaces, SilgiOperation, SilgiOptions, SilgiPreset, SilgiPresetMeta, SilgiRouteRules, SilgiRouterTypes, SilgiRuntimeActions, SilgiRuntimeConfig, SilgiRuntimeContext, SilgiRuntimeHooks, SilgiRuntimeMethods, SilgiRuntimeOptions, SilgiRuntimeRouteRules, SilgiRuntimeRouteRulesConfig, SilgiRuntimeShareds, SilgiRuntimeSharedsExtend, SilgiSchema, SilgiServiceInterface, SilgiStorageBase, SilgiTemplate, SilgiURIs, StorageConfig, StorageKeyGenerator, StorageKeyParams, StorageMounts, TSReference, TrimAfterFourSlashes, URIsTypes };
|