silgi 0.29.6 → 0.29.7

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/dev.mjs CHANGED
@@ -45,7 +45,6 @@ import 'klona';
45
45
  import 'silgi/runtime';
46
46
  import 'unstorage';
47
47
  import 'scule';
48
- import 'node:child_process';
49
48
 
50
49
  async function reloadScan(path, _stats) {
51
50
  const silgi = useSilgiCLI();
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import { defineCommand, runMain } from 'citty';
3
3
 
4
- const version = "0.29.6";
4
+ const version = "0.29.7";
5
5
  const packageJson = {
6
6
  version: version};
7
7
 
@@ -20,7 +20,7 @@ const main = defineCommand({
20
20
  subCommands: {
21
21
  prepare: () => import('./prepare.mjs').then(function (n) { return n.a; }).then((m) => m.default),
22
22
  init: () => import('./init.mjs').then((m) => m.default),
23
- run: () => import('./prepare.mjs').then(function (n) { return n.r; }).then((m) => m.default),
23
+ run: () => import('./run.mjs').then((m) => m.default),
24
24
  install: () => import('./install.mjs').then((m) => m.default),
25
25
  dev: () => import('./dev.mjs').then((m) => m.default)
26
26
  },
package/dist/cli/init.mjs CHANGED
@@ -41,9 +41,6 @@ import 'klona';
41
41
  import 'silgi/runtime';
42
42
  import 'unstorage';
43
43
  import 'scule';
44
- import 'node:child_process';
45
- import '../_chunks/silgiApp.mjs';
46
- import 'unctx';
47
44
 
48
45
  const init = defineCommand({
49
46
  meta: {
@@ -1,17 +1,7 @@
1
- import { defineCommand, runCommand } from 'citty';
1
+ import { defineCommand } from 'citty';
2
2
  import { resolve } from 'pathe';
3
3
  import { version } from 'silgi/meta';
4
- import { p as prepareEnv, c as createSilgiCLI, b as build } from './silgi.mjs';
5
- import { execSync } from 'node:child_process';
6
- import * as p from '@clack/prompts';
7
- import { isCancel, cancel } from '@clack/prompts';
8
- import { consola } from 'consola';
9
- import { createJiti } from 'dev-jiti';
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';
14
- import { l as loadOptions } from './types.mjs';
4
+ import { c as createSilgiCLI, b as build } from './silgi.mjs';
15
5
 
16
6
  const commonArgs = {
17
7
  dir: {
@@ -25,171 +15,6 @@ const commonArgs = {
25
15
  }
26
16
  };
27
17
 
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
-
94
- const run = defineCommand({
95
- meta: {
96
- name: "run",
97
- description: "Run a command from the CLI",
98
- version: version
99
- },
100
- args: {
101
- ...commonArgs,
102
- preset: {
103
- type: "string",
104
- description: "The build preset to use (you can also use `SILGI_PRESET` environment variable)."
105
- },
106
- tag: {
107
- type: "string"
108
- },
109
- active: {
110
- type: "boolean",
111
- description: "Run in silgi development mode",
112
- default: true
113
- }
114
- },
115
- async run({ args }) {
116
- const data = args.active ? await runCommand(prepare, {
117
- rawArgs: ["--commandType", "run"]
118
- }) : void 0;
119
- const silgi = useSilgiCLI$1();
120
- const commands = await scanCommands();
121
- globalThis.__nitro__ = globalThis.__nitro__ || {};
122
- globalThis.__nitro__.useRuntimeConfig = function() {
123
- return data?.result?.silgi?.options?.runtimeConfig || {};
124
- };
125
- if (!data?.result?.silgi && args.active) {
126
- consola.error("Silgi not found");
127
- return;
128
- }
129
- const tags = args.tag?.split(",").map((t) => t.trim());
130
- const silgiConfig = await loadOptions({});
131
- await prepareEnv(silgiConfig);
132
- let selectedCommands = [];
133
- if (tags?.length) {
134
- selectedCommands = commands.filter((cmd) => cmd.tags?.some((tag) => tags.includes(tag))).filter((cmd) => cmd.when !== false);
135
- } else {
136
- selectedCommands = commands.filter((cmd) => cmd.when !== false);
137
- }
138
- const multiSelect = await p.groupMultiselect({
139
- message: "Select commands to run",
140
- required: true,
141
- options: {
142
- ...selectedCommands.sort((a, b) => (a.order || Infinity) - (b.order || Infinity)).reduce((acc, cmd) => {
143
- if (!acc[cmd.group || ""]) {
144
- acc[cmd.group || ""] = [];
145
- }
146
- acc[cmd.group || ""].push({
147
- label: cmd.name,
148
- value: cmd,
149
- hint: cmd.description
150
- });
151
- return acc;
152
- }, {})
153
- }
154
- });
155
- cancelOnCancel({ value: multiSelect });
156
- selectedCommands = multiSelect;
157
- const spinner = p.spinner({
158
- indicator: "dots"
159
- });
160
- for (const cmd of selectedCommands) {
161
- const data2 = cmd.getContents({ app: silgi });
162
- spinner.start(`[${cmd.group}] ${cmd.name}...`);
163
- if (cmd.type === "command") {
164
- execSync(data2, { stdio: "inherit" });
165
- }
166
- if (cmd.type === "function") {
167
- const jiti = createJiti(import.meta.url, {
168
- alias: silgiConfig.alias
169
- });
170
- let cleanHandler = cmd.getContents({ app: silgi }).replace(/\n/g, "");
171
- cleanHandler = `import { silgiCLICtx } from 'silgi'
172
- ${cleanHandler}
173
- `;
174
- await jiti.evalModule(cleanHandler, {
175
- filename: import.meta.url,
176
- async: true,
177
- conditions: silgiConfig.conditions,
178
- forceTranspile: true
179
- });
180
- }
181
- spinner.stop();
182
- consola.success(`[${cmd.group}] ${cmd.name} done`);
183
- }
184
- await silgiCLIIClose();
185
- }
186
- });
187
-
188
- const run$1 = {
189
- __proto__: null,
190
- default: run
191
- };
192
-
193
18
  const prepare = defineCommand({
194
19
  meta: {
195
20
  name: "prepare",
@@ -230,14 +55,6 @@ const prepare = defineCommand({
230
55
  activeEnvironment: args.env
231
56
  });
232
57
  await build(silgi);
233
- if (args.commandType !== "run") {
234
- await runCommand(run, {
235
- rawArgs: ["--tag", "init", "--active", "false"]
236
- });
237
- }
238
- return {
239
- silgi
240
- };
241
58
  }
242
59
  });
243
60
 
@@ -246,4 +63,4 @@ const prepare$1 = {
246
63
  default: prepare
247
64
  };
248
65
 
249
- export { prepare$1 as a, commonArgs as c, prepare as p, run$1 as r };
66
+ export { prepare$1 as a, commonArgs as c, prepare as p };
@@ -0,0 +1,209 @@
1
+ import { execSync } from 'node:child_process';
2
+ import * as p from '@clack/prompts';
3
+ import { isCancel, cancel } from '@clack/prompts';
4
+ import { defineCommand, runCommand } from 'citty';
5
+ import { consola } from 'consola';
6
+ import { createJiti } from 'dev-jiti';
7
+ import { useSilgiCLI as useSilgiCLI$1 } from 'silgi';
8
+ import { version } from 'silgi/meta';
9
+ import { u as useSilgiCLI, a as silgiCLIIClose } from '../_chunks/silgiApp.mjs';
10
+ import { addTemplate } from 'silgi/kit';
11
+ import { generateTypes, resolveSchema } from 'untyped';
12
+ import { c as commonArgs, p as prepare } from './prepare.mjs';
13
+ import { p as prepareEnv } from './silgi.mjs';
14
+ import { l as loadOptions } from './types.mjs';
15
+ import 'unctx';
16
+ import 'pathe';
17
+ import 'apiful/openapi';
18
+ import 'node:fs';
19
+ import 'node:fs/promises';
20
+ import 'knitwork';
21
+ import 'mlly';
22
+ import 'pathe/utils';
23
+ import 'silgi/runtime/meta';
24
+ import 'unimport';
25
+ import 'hookable';
26
+ import '../_chunks/routeRules.mjs';
27
+ import 'ufo';
28
+ import 'dotenv';
29
+ import './compatibility.mjs';
30
+ import 'semver/functions/satisfies.js';
31
+ import 'node:url';
32
+ import 'defu';
33
+ import 'exsolve';
34
+ import 'globby';
35
+ import 'ignore';
36
+ import '@oxc-parser/wasm';
37
+ import 'klona';
38
+ import 'silgi/runtime';
39
+ import 'unstorage';
40
+ import 'scule';
41
+ import 'c12';
42
+ import 'compatx';
43
+ import 'klona/full';
44
+ import 'std-env';
45
+ import 'consola/utils';
46
+ import 'escape-string-regexp';
47
+ import 'pkg-types';
48
+
49
+ function debugMode(name) {
50
+ const silgi = useSilgiCLI();
51
+ if (silgi.options.debug === true || typeof silgi.options.debug === "object" && silgi.options.debug[name]) {
52
+ return true;
53
+ }
54
+ return false;
55
+ }
56
+
57
+ async function scanCommands(silgi = useSilgiCLI()) {
58
+ const commands = [];
59
+ await silgi.callHook("prepare:commands", commands);
60
+ if (debugMode("command")) {
61
+ addTemplate({
62
+ filename: "cli.json",
63
+ where: ".silgi",
64
+ write: true,
65
+ getContents: () => JSON.stringify(commands, null, 2)
66
+ });
67
+ }
68
+ silgi.hook("prepare:schema.ts", async (object) => {
69
+ const allTags = commands.reduce((acc, commandGroup) => {
70
+ Object.values(commandGroup).forEach((command) => {
71
+ if (command.tags) {
72
+ command.tags.forEach((tag) => acc.add(tag));
73
+ }
74
+ });
75
+ return acc;
76
+ }, /* @__PURE__ */ new Set());
77
+ const data = [
78
+ "",
79
+ generateTypes(
80
+ await resolveSchema(
81
+ {
82
+ ...Object.fromEntries(Array.from(allTags.values()).map((tag) => [tag, "string"]))
83
+ }
84
+ ),
85
+ {
86
+ interfaceName: "SilgiCommandsExtended",
87
+ addExport: false,
88
+ addDefaults: false,
89
+ allowExtraKeys: false,
90
+ indentation: 0
91
+ }
92
+ ),
93
+ ""
94
+ ];
95
+ object.customImports?.push(...data);
96
+ });
97
+ return commands;
98
+ }
99
+
100
+ function cancelOnCancel({
101
+ value,
102
+ message = "Cancelled",
103
+ onBeforeExit,
104
+ exitCode = 0
105
+ } = {}) {
106
+ const handleCancel = () => {
107
+ cancel(message);
108
+ onBeforeExit?.();
109
+ process.exit(exitCode);
110
+ };
111
+ if (!value || isCancel(value))
112
+ handleCancel();
113
+ }
114
+
115
+ const run = defineCommand({
116
+ meta: {
117
+ name: "run",
118
+ description: "Run a command from the CLI",
119
+ version: version
120
+ },
121
+ args: {
122
+ ...commonArgs,
123
+ preset: {
124
+ type: "string",
125
+ description: "The build preset to use (you can also use `SILGI_PRESET` environment variable)."
126
+ },
127
+ tag: {
128
+ type: "string"
129
+ },
130
+ active: {
131
+ type: "boolean",
132
+ description: "Run in silgi development mode",
133
+ default: true
134
+ }
135
+ },
136
+ async run({ args }) {
137
+ const data = args.active ? await runCommand(prepare, {
138
+ rawArgs: ["--commandType", "run"]
139
+ }) : void 0;
140
+ const silgi = useSilgiCLI$1();
141
+ const commands = await scanCommands();
142
+ globalThis.__nitro__ = globalThis.__nitro__ || {};
143
+ globalThis.__nitro__.useRuntimeConfig = function() {
144
+ return data?.result?.silgi?.options?.runtimeConfig || {};
145
+ };
146
+ if (!data?.result?.silgi && args.active) {
147
+ consola.error("Silgi not found");
148
+ return;
149
+ }
150
+ const tags = args.tag?.split(",").map((t) => t.trim());
151
+ const silgiConfig = await loadOptions({});
152
+ await prepareEnv(silgiConfig);
153
+ let selectedCommands = [];
154
+ if (tags?.length) {
155
+ selectedCommands = commands.filter((cmd) => cmd.tags?.some((tag) => tags.includes(tag))).filter((cmd) => cmd.when !== false);
156
+ } else {
157
+ selectedCommands = commands.filter((cmd) => cmd.when !== false);
158
+ }
159
+ const multiSelect = await p.groupMultiselect({
160
+ message: "Select commands to run",
161
+ required: true,
162
+ options: {
163
+ ...selectedCommands.sort((a, b) => (a.order || Infinity) - (b.order || Infinity)).reduce((acc, cmd) => {
164
+ if (!acc[cmd.group || ""]) {
165
+ acc[cmd.group || ""] = [];
166
+ }
167
+ acc[cmd.group || ""].push({
168
+ label: cmd.name,
169
+ value: cmd,
170
+ hint: cmd.description
171
+ });
172
+ return acc;
173
+ }, {})
174
+ }
175
+ });
176
+ cancelOnCancel({ value: multiSelect });
177
+ selectedCommands = multiSelect;
178
+ const spinner = p.spinner({
179
+ indicator: "dots"
180
+ });
181
+ for (const cmd of selectedCommands) {
182
+ const data2 = cmd.getContents({ app: silgi });
183
+ spinner.start(`[${cmd.group}] ${cmd.name}...`);
184
+ if (cmd.type === "command") {
185
+ execSync(data2, { stdio: "inherit" });
186
+ }
187
+ if (cmd.type === "function") {
188
+ const jiti = createJiti(import.meta.url, {
189
+ alias: silgiConfig.alias
190
+ });
191
+ let cleanHandler = cmd.getContents({ app: silgi }).replace(/\n/g, "");
192
+ cleanHandler = `import { silgiCLICtx } from 'silgi'
193
+ ${cleanHandler}
194
+ `;
195
+ await jiti.evalModule(cleanHandler, {
196
+ filename: import.meta.url,
197
+ async: true,
198
+ conditions: silgiConfig.conditions,
199
+ forceTranspile: true
200
+ });
201
+ }
202
+ spinner.stop();
203
+ consola.success(`[${cmd.group}] ${cmd.name} done`);
204
+ }
205
+ await silgiCLIIClose();
206
+ }
207
+ });
208
+
209
+ export { run as default };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "silgi",
3
3
  "type": "module",
4
- "version": "0.29.6",
4
+ "version": "0.29.7",
5
5
  "private": false,
6
6
  "sideEffects": false,
7
7
  "exports": {