silgi 0.29.7 → 0.29.8
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 +1 -0
- package/dist/cli/index.mjs +2 -2
- package/dist/cli/init.mjs +3 -0
- package/dist/cli/prepare.mjs +187 -3
- package/package.json +1 -1
- package/dist/cli/run.mjs +0 -209
package/dist/cli/dev.mjs
CHANGED
package/dist/cli/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { defineCommand, runMain } from 'citty';
|
|
3
3
|
|
|
4
|
-
const version = "0.29.
|
|
4
|
+
const version = "0.29.8";
|
|
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('./
|
|
23
|
+
run: () => import('./prepare.mjs').then(function (n) { return n.r; }).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
package/dist/cli/prepare.mjs
CHANGED
|
@@ -1,7 +1,17 @@
|
|
|
1
|
-
import { defineCommand } from 'citty';
|
|
1
|
+
import { defineCommand, runCommand } from 'citty';
|
|
2
2
|
import { resolve } from 'pathe';
|
|
3
3
|
import { version } from 'silgi/meta';
|
|
4
|
-
import { c as createSilgiCLI, b as build } from './silgi.mjs';
|
|
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';
|
|
5
15
|
|
|
6
16
|
const commonArgs = {
|
|
7
17
|
dir: {
|
|
@@ -15,6 +25,175 @@ const commonArgs = {
|
|
|
15
25
|
}
|
|
16
26
|
};
|
|
17
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
|
+
|
|
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
|
+
prepare: {
|
|
110
|
+
type: "boolean",
|
|
111
|
+
description: "Run in silgi development mode",
|
|
112
|
+
default: true
|
|
113
|
+
}
|
|
114
|
+
},
|
|
115
|
+
async run({ args }) {
|
|
116
|
+
if (args.prepare) {
|
|
117
|
+
await runCommand(prepare, {
|
|
118
|
+
rawArgs: ["--commandType", "run"]
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
const silgi = useSilgiCLI$1();
|
|
122
|
+
if (!silgi) {
|
|
123
|
+
throw new Error("Silgi is not initialized");
|
|
124
|
+
}
|
|
125
|
+
const commands = await scanCommands();
|
|
126
|
+
globalThis.__nitro__ = globalThis.__nitro__ || {};
|
|
127
|
+
globalThis.__nitro__.useRuntimeConfig = function() {
|
|
128
|
+
return silgi?.options?.runtimeConfig || {};
|
|
129
|
+
};
|
|
130
|
+
const tags = args.tag?.split(",").map((t) => t.trim());
|
|
131
|
+
const silgiConfig = await loadOptions({});
|
|
132
|
+
await prepareEnv(silgiConfig);
|
|
133
|
+
let selectedCommands = [];
|
|
134
|
+
if (tags?.length) {
|
|
135
|
+
selectedCommands = commands.filter((cmd) => cmd.tags?.some((tag) => tags.includes(tag))).filter((cmd) => cmd.when !== false);
|
|
136
|
+
} else {
|
|
137
|
+
selectedCommands = commands.filter((cmd) => cmd.when !== false);
|
|
138
|
+
}
|
|
139
|
+
if (!selectedCommands.length) {
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
const multiSelect = await p.groupMultiselect({
|
|
143
|
+
message: "Select commands to run",
|
|
144
|
+
required: true,
|
|
145
|
+
options: {
|
|
146
|
+
...selectedCommands.sort((a, b) => (a.order || Infinity) - (b.order || Infinity)).reduce((acc, cmd) => {
|
|
147
|
+
if (!acc[cmd.group || ""]) {
|
|
148
|
+
acc[cmd.group || ""] = [];
|
|
149
|
+
}
|
|
150
|
+
acc[cmd.group || ""].push({
|
|
151
|
+
label: cmd.name,
|
|
152
|
+
value: cmd,
|
|
153
|
+
hint: cmd.description
|
|
154
|
+
});
|
|
155
|
+
return acc;
|
|
156
|
+
}, {})
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
cancelOnCancel({ value: multiSelect });
|
|
160
|
+
selectedCommands = multiSelect;
|
|
161
|
+
const spinner = p.spinner({
|
|
162
|
+
indicator: "dots"
|
|
163
|
+
});
|
|
164
|
+
for (const cmd of selectedCommands) {
|
|
165
|
+
const data = cmd.getContents({ app: silgi });
|
|
166
|
+
spinner.start(`[${cmd.group}] ${cmd.name}...`);
|
|
167
|
+
if (cmd.type === "command") {
|
|
168
|
+
execSync(data, { stdio: "inherit" });
|
|
169
|
+
}
|
|
170
|
+
if (cmd.type === "function") {
|
|
171
|
+
const jiti = createJiti(import.meta.url, {
|
|
172
|
+
alias: silgiConfig.alias
|
|
173
|
+
});
|
|
174
|
+
let cleanHandler = cmd.getContents({ app: silgi }).replace(/\n/g, "");
|
|
175
|
+
cleanHandler = `import { silgiCLICtx } from 'silgi'
|
|
176
|
+
${cleanHandler}
|
|
177
|
+
`;
|
|
178
|
+
await jiti.evalModule(cleanHandler, {
|
|
179
|
+
filename: import.meta.url,
|
|
180
|
+
async: true,
|
|
181
|
+
conditions: silgiConfig.conditions,
|
|
182
|
+
forceTranspile: true
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
spinner.stop();
|
|
186
|
+
consola.success(`[${cmd.group}] ${cmd.name} done`);
|
|
187
|
+
}
|
|
188
|
+
await silgiCLIIClose();
|
|
189
|
+
}
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
const run$1 = {
|
|
193
|
+
__proto__: null,
|
|
194
|
+
default: run
|
|
195
|
+
};
|
|
196
|
+
|
|
18
197
|
const prepare = defineCommand({
|
|
19
198
|
meta: {
|
|
20
199
|
name: "prepare",
|
|
@@ -55,6 +234,11 @@ const prepare = defineCommand({
|
|
|
55
234
|
activeEnvironment: args.env
|
|
56
235
|
});
|
|
57
236
|
await build(silgi);
|
|
237
|
+
if (args.commandType !== "run") {
|
|
238
|
+
await runCommand(run, {
|
|
239
|
+
rawArgs: ["--tag", "init", "--prepare", "false"]
|
|
240
|
+
});
|
|
241
|
+
}
|
|
58
242
|
}
|
|
59
243
|
});
|
|
60
244
|
|
|
@@ -63,4 +247,4 @@ const prepare$1 = {
|
|
|
63
247
|
default: prepare
|
|
64
248
|
};
|
|
65
249
|
|
|
66
|
-
export { prepare$1 as a, commonArgs as c, prepare as p };
|
|
250
|
+
export { prepare$1 as a, commonArgs as c, prepare as p, run$1 as r };
|
package/package.json
CHANGED
package/dist/cli/run.mjs
DELETED
|
@@ -1,209 +0,0 @@
|
|
|
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 };
|