silgi 0.19.29 → 0.19.30

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,4 +1,4 @@
1
- const version = "0.19.29";
1
+ const version = "0.19.30";
2
2
  const peerDependencies = {
3
3
  "@fastify/deepmerge": "^3.0.0",
4
4
  "@nuxt/kit": "^3.15.3",
@@ -157,13 +157,21 @@ async function h3Framework(silgi, skip = false) {
157
157
  silgi.hook("prepare:schema.ts", (data) => {
158
158
  data.importItems.nitropack = {
159
159
  import: [
160
- { name: "NitroApp", type: true }
160
+ {
161
+ name: "NitroApp",
162
+ type: true,
163
+ key: "NitroApp"
164
+ }
161
165
  ],
162
166
  from: "nitropack/types"
163
167
  };
164
168
  data.importItems.h3 = {
165
169
  import: [
166
- { name: "H3Event", type: true }
170
+ {
171
+ name: "H3Event",
172
+ type: true,
173
+ key: "H3Event"
174
+ }
167
175
  ],
168
176
  from: "h3"
169
177
  };
@@ -177,7 +185,11 @@ async function h3Framework(silgi, skip = false) {
177
185
  silgi.hook("prepare:createDTSFramework", (data) => {
178
186
  data.importItems["silgi/types"] = {
179
187
  import: [
180
- { name: "SilgiRuntimeContext", type: true }
188
+ {
189
+ name: "SilgiRuntimeContext",
190
+ type: true,
191
+ key: "SilgiRuntimeContext"
192
+ }
181
193
  ],
182
194
  from: "silgi/types"
183
195
  };
@@ -724,8 +736,8 @@ async function commands(silgi) {
724
736
  write: true,
725
737
  getContents: () => JSON.stringify(commands2, null, 2)
726
738
  });
739
+ silgi.commands = commands2;
727
740
  silgi.hook("prepare:schema.ts", async (object) => {
728
- console.log("prepare:schema.ts");
729
741
  const allTags = Object.values(commands2).reduce((acc, commandGroup) => {
730
742
  Object.values(commandGroup).forEach((command) => {
731
743
  if (command.tags) {
@@ -1586,7 +1598,7 @@ async function createSilgiCLI(config = {}, opts = {}) {
1586
1598
  options,
1587
1599
  hooks,
1588
1600
  errors: [],
1589
- // vfs: {}
1601
+ commands: {},
1590
1602
  _requiredModules: {},
1591
1603
  logger: consola.withTag("silgi"),
1592
1604
  close: () => silgi.hooks.callHook("close", silgi),
@@ -122,14 +122,18 @@ const run = defineCommand({
122
122
  const data = args.active ? await runCommand(prepare, {
123
123
  rawArgs: ["--commands", "run"]
124
124
  }) : void 0;
125
- if (data?.result?.silgi) {
126
- console.log("Setting silgi context");
125
+ if (!data?.result?.silgi) {
126
+ consola.error("Silgi not found");
127
+ return;
128
+ }
129
+ const silgi = data.result.silgi;
130
+ if (silgi) {
127
131
  if (silgiCLICtx.tryUse()) {
128
132
  silgiCLICtx.unset();
129
- silgiCLICtx.set(data.result.silgi);
133
+ silgiCLICtx.set(silgi);
130
134
  } else {
131
- silgiCLICtx.set(data.result.silgi);
132
- data.result.silgi.hook("close", () => silgiCLICtx.unset());
135
+ silgiCLICtx.set(silgi);
136
+ silgi.hook("close", () => silgiCLICtx.unset());
133
137
  }
134
138
  }
135
139
  const tags = args.tag?.split(",").map((t) => t.trim());
@@ -162,34 +166,72 @@ const run = defineCommand({
162
166
  consola.warn("No commands found in cli.json");
163
167
  return;
164
168
  }
169
+ const allTags = Object.values(silgi.commands).reduce((acc, commandGroup) => {
170
+ Object.values(commandGroup).forEach((command) => {
171
+ if (command.tags) {
172
+ command.tags.forEach((tag) => acc.add(tag));
173
+ }
174
+ });
175
+ return acc;
176
+ }, /* @__PURE__ */ new Set());
165
177
  const commandName = await p.select({
166
178
  message: "Select a command to run",
167
- options: Object.keys(cliJson).filter((key) => {
168
- const scripts2 = cliJson[key];
169
- const scriptValues = Object.values(scripts2);
170
- return scriptValues;
171
- }).map((key) => ({
172
- label: key,
173
- value: key
174
- }))
179
+ options: [
180
+ ...allTags.size ? [{
181
+ value: "command-tags",
182
+ label: "Command Tags",
183
+ hint: "It executes all commands that are related to the tags you select."
184
+ }] : [],
185
+ ...Object.keys(cliJson).filter((key) => {
186
+ const scripts = cliJson[key];
187
+ const scriptValues = Object.values(scripts);
188
+ return scriptValues;
189
+ }).map((key) => ({
190
+ label: key,
191
+ value: key
192
+ }))
193
+ ]
175
194
  });
176
195
  if (!commandName)
177
196
  return;
178
- const scripts = cliJson[commandName];
179
- const scriptName = await p.select({
180
- message: "Select a script to run",
181
- options: Object.keys(scripts).filter((key) => !scripts[key].tags?.length).map((key) => ({
182
- label: key,
183
- value: key
184
- }))
185
- });
186
- if (!scriptName)
187
- return;
188
- selectedCommands = [{
189
- command: commandName,
190
- script: scriptName,
191
- handler: scripts[scriptName]
192
- }];
197
+ if (commandName === "command-tags") {
198
+ const tags2 = Array.from(allTags);
199
+ const selectedTags = await p.select({
200
+ message: "Select tags to run",
201
+ options: tags2.map((tag) => ({
202
+ label: tag,
203
+ value: tag
204
+ }))
205
+ });
206
+ if (!selectedTags)
207
+ return;
208
+ selectedCommands = Object.keys(cliJson).map(
209
+ (commandName2) => {
210
+ const scripts = cliJson[commandName2];
211
+ return Object.keys(scripts).map((scriptName) => ({
212
+ command: commandName2,
213
+ script: scriptName,
214
+ handler: scripts[scriptName]
215
+ })).filter((script) => script.handler.tags?.includes(selectedTags));
216
+ }
217
+ ).flat();
218
+ } else {
219
+ const scripts = cliJson[commandName];
220
+ const scriptName = await p.select({
221
+ message: "Select a script to run",
222
+ options: Object.keys(scripts).filter((key) => !scripts[key].tags?.length).map((key) => ({
223
+ label: key,
224
+ value: key
225
+ }))
226
+ });
227
+ if (!scriptName)
228
+ return;
229
+ selectedCommands = [{
230
+ command: commandName,
231
+ script: scriptName,
232
+ handler: scripts[scriptName]
233
+ }];
234
+ }
193
235
  }
194
236
  for (const cmd of selectedCommands) {
195
237
  consola.info(`Running ${cmd.command}:${cmd.script}...`);
@@ -204,7 +246,7 @@ const run = defineCommand({
204
246
  alias: silgiConfig.alias
205
247
  });
206
248
  let cleanHandler = cmd.handler.handler.replace(/\n/g, "");
207
- global.__silgi_temp_obj = data?.result?.silgi;
249
+ global.__silgi_temp_obj = silgi;
208
250
  cleanHandler = `import { silgiCLICtx } from 'silgi/core'
209
251
 
210
252
  // Access from global scope
@@ -1,4 +1,4 @@
1
- const version = "0.19.29";
1
+ const version = "0.19.30";
2
2
  const peerDependencies = {
3
3
  "@fastify/deepmerge": "^3.0.0",
4
4
  "@nuxt/kit": "^3.15.3",
@@ -1,4 +1,4 @@
1
- const version = "0.19.29";
1
+ const version = "0.19.30";
2
2
  const peerDependencies = {
3
3
  "@fastify/deepmerge": "^3.0.0",
4
4
  "@nuxt/kit": "^3.15.3",
@@ -76,6 +76,13 @@ interface SilgiCLI {
76
76
  }>;
77
77
  options: SilgiCLIOptions;
78
78
  _requiredModules: Record<string, boolean>;
79
+ commands: Record<string, Record<string, {
80
+ type: 'function' | 'command';
81
+ handler: string;
82
+ description?: string;
83
+ tags?: (keyof SilgiCommands)[];
84
+ enabled?: boolean;
85
+ }>>;
79
86
  }
80
87
  type SilgiCLIDynamicConfig = Pick<SilgiCLIConfig, 'routeRules'>;
81
88
  interface SilgiFrameworkInfo {
@@ -277,13 +284,7 @@ interface SilgiCLIHooks extends SilgiHooks {
277
284
  */
278
285
  'app:templatesGenerated': (app: SilgiCLI, templates: ResolvedSilgiTemplate[], options?: GenerateAppOptions) => HookResult;
279
286
  'scanFiles:done': (app: SilgiCLI) => HookResult;
280
- 'prepare:commands': (commands: Record<string, Record<string, {
281
- type: 'function' | 'command';
282
- handler: string;
283
- description?: string;
284
- tags?: (keyof SilgiCommands)[];
285
- enabled?: boolean;
286
- }>>) => HookResult;
287
+ 'prepare:commands': (commands: SilgiCLI['commands']) => HookResult;
287
288
  'prepare:installPackages': (packages: Record<'dependencies' | 'devDependencies', Record<string, string>>) => HookResult;
288
289
  }
289
290
 
@@ -76,6 +76,13 @@ interface SilgiCLI {
76
76
  }>;
77
77
  options: SilgiCLIOptions;
78
78
  _requiredModules: Record<string, boolean>;
79
+ commands: Record<string, Record<string, {
80
+ type: 'function' | 'command';
81
+ handler: string;
82
+ description?: string;
83
+ tags?: (keyof SilgiCommands)[];
84
+ enabled?: boolean;
85
+ }>>;
79
86
  }
80
87
  type SilgiCLIDynamicConfig = Pick<SilgiCLIConfig, 'routeRules'>;
81
88
  interface SilgiFrameworkInfo {
@@ -277,13 +284,7 @@ interface SilgiCLIHooks extends SilgiHooks {
277
284
  */
278
285
  'app:templatesGenerated': (app: SilgiCLI, templates: ResolvedSilgiTemplate[], options?: GenerateAppOptions) => HookResult;
279
286
  'scanFiles:done': (app: SilgiCLI) => HookResult;
280
- 'prepare:commands': (commands: Record<string, Record<string, {
281
- type: 'function' | 'command';
282
- handler: string;
283
- description?: string;
284
- tags?: (keyof SilgiCommands)[];
285
- enabled?: boolean;
286
- }>>) => HookResult;
287
+ 'prepare:commands': (commands: SilgiCLI['commands']) => HookResult;
287
288
  'prepare:installPackages': (packages: Record<'dependencies' | 'devDependencies', Record<string, string>>) => HookResult;
288
289
  }
289
290
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "silgi",
3
3
  "type": "module",
4
- "version": "0.19.29",
4
+ "version": "0.19.30",
5
5
  "private": false,
6
6
  "sideEffects": false,
7
7
  "exports": {