silgi 0.24.14 → 0.24.16

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.
@@ -5,10 +5,8 @@ import consola from 'consola';
5
5
  import { join } from 'pathe';
6
6
  import { useSilgiCLI } from 'silgi';
7
7
  import { version } from 'silgi/meta';
8
- import { s as silgiCLIIClose } from '../_chunks/silgiApp.mjs';
8
+ import { s as silgiCLIIClose } from '../shared/silgi.CvG35CGc.mjs';
9
9
  import { c as commonArgs, p as prepare } from './prepare.mjs';
10
- import 'ufo';
11
- import 'unctx';
12
10
  import 'knitwork';
13
11
  import 'silgi/kit';
14
12
  import 'node:fs';
@@ -16,11 +14,12 @@ import 'node:fs/promises';
16
14
  import 'hookable';
17
15
  import 'silgi/runtime/meta';
18
16
  import 'unimport';
17
+ import 'ufo';
19
18
  import '@clack/prompts';
20
19
  import 'dotenv';
21
20
  import 'mlly';
22
21
  import 'dev-jiti';
23
- import './compatibility.mjs';
22
+ import '../shared/silgi.DWfN_DdY.mjs';
24
23
  import 'semver/functions/satisfies.js';
25
24
  import 'node:url';
26
25
  import 'defu';
@@ -32,7 +31,7 @@ import '@oxc-parser/wasm';
32
31
  import 'klona';
33
32
  import 'silgi/runtime';
34
33
  import 'unstorage';
35
- import './types.mjs';
34
+ import '../shared/silgi.BIBmUBIR.mjs';
36
35
  import 'c12';
37
36
  import 'compatx';
38
37
  import 'klona/full';
@@ -41,6 +40,7 @@ import 'consola/utils';
41
40
  import 'escape-string-regexp';
42
41
  import 'pkg-types';
43
42
  import 'pathe/utils';
43
+ import 'unctx';
44
44
  import 'node:child_process';
45
45
  import 'picocolors';
46
46
 
@@ -5,7 +5,8 @@ import { consola } from 'consola';
5
5
  import { resolve } from 'pathe';
6
6
  import { version } from 'silgi/meta';
7
7
  import { c as commonArgs, p as prepare } from './prepare.mjs';
8
- import { l as loadOptions } from './types.mjs';
8
+ import { l as loadOptions } from '../shared/silgi.BIBmUBIR.mjs';
9
+ import '../shared/silgi.CvG35CGc.mjs';
9
10
  import 'knitwork';
10
11
  import 'silgi/kit';
11
12
  import 'node:fs/promises';
@@ -13,14 +14,12 @@ import 'hookable';
13
14
  import 'silgi';
14
15
  import 'silgi/runtime/meta';
15
16
  import 'unimport';
16
- import '../_chunks/silgiApp.mjs';
17
17
  import 'ufo';
18
- import 'unctx';
19
18
  import '@clack/prompts';
20
19
  import 'dotenv';
21
20
  import 'mlly';
22
21
  import 'dev-jiti';
23
- import './compatibility.mjs';
22
+ import '../shared/silgi.DWfN_DdY.mjs';
24
23
  import 'semver/functions/satisfies.js';
25
24
  import 'node:url';
26
25
  import 'defu';
@@ -33,6 +32,7 @@ import 'klona';
33
32
  import 'silgi/runtime';
34
33
  import 'unstorage';
35
34
  import 'pathe/utils';
35
+ import 'unctx';
36
36
  import 'picocolors';
37
37
  import 'c12';
38
38
  import 'compatx';
@@ -0,0 +1,248 @@
1
+ import { defineCommand, runCommand } from 'citty';
2
+ import { resolve } from 'pathe';
3
+ import { version } from 'silgi/meta';
4
+ import { p as prepareEnv, s as silgiCLIIClose, c as createSilgiCLI, a as prepare$2, w as writeTypesAndFiles, b as writeCoreFile, d as prepareBuild } from '../shared/silgi.CvG35CGc.mjs';
5
+ import { execSync } from 'node:child_process';
6
+ import { readFileSync } from 'node:fs';
7
+ import * as p from '@clack/prompts';
8
+ import { consola } from 'consola';
9
+ import { createJiti } from 'dev-jiti';
10
+ import color from 'picocolors';
11
+ import { useSilgiCLI } from 'silgi';
12
+ import { l as loadOptions } from '../shared/silgi.BIBmUBIR.mjs';
13
+
14
+ const commonArgs = {
15
+ dir: {
16
+ type: "string",
17
+ description: "project root directory"
18
+ },
19
+ _dir: {
20
+ type: "positional",
21
+ default: ".",
22
+ description: "project root directory (prefer using `--dir`)"
23
+ }
24
+ };
25
+
26
+ const run = defineCommand({
27
+ meta: {
28
+ name: "run",
29
+ description: "Run a command from the CLI",
30
+ version: version
31
+ },
32
+ args: {
33
+ ...commonArgs,
34
+ preset: {
35
+ type: "string",
36
+ description: "The build preset to use (you can also use `SILGI_PRESET` environment variable)."
37
+ },
38
+ tag: {
39
+ type: "string"
40
+ },
41
+ active: {
42
+ type: "boolean",
43
+ description: "Run in silgi development mode",
44
+ default: true
45
+ }
46
+ },
47
+ async run({ args }) {
48
+ const data = args.active ? await runCommand(prepare, {
49
+ rawArgs: ["--commands", "run"]
50
+ }) : void 0;
51
+ if (!data?.result?.silgi && args.active) {
52
+ consola.error("Silgi not found");
53
+ return;
54
+ }
55
+ const silgi = useSilgiCLI();
56
+ const tags = args.tag?.split(",").map((t) => t.trim());
57
+ p.intro(color.bold(`Silgi CLI ${color.green(`v${version}`)}`));
58
+ const silgiConfig = await loadOptions({});
59
+ const getCli = resolve(silgiConfig.build.dir, "cli.json");
60
+ const cli = readFileSync(getCli, "utf-8");
61
+ const cliJson = JSON.parse(cli);
62
+ await prepareEnv(silgiConfig);
63
+ let selectedCommands = [];
64
+ if (tags) {
65
+ for (const commandName of Object.keys(cliJson)) {
66
+ const scripts = cliJson[commandName];
67
+ for (const scriptName of Object.keys(scripts)) {
68
+ const script = scripts[scriptName];
69
+ if (script.tags && script.tags.some((tag) => tags.includes(tag))) {
70
+ selectedCommands.push({
71
+ command: commandName,
72
+ script: scriptName,
73
+ handler: script
74
+ });
75
+ }
76
+ }
77
+ }
78
+ if (selectedCommands.length === 0) {
79
+ return;
80
+ }
81
+ } else {
82
+ if (!silgi) {
83
+ consola.error("Silgi not found");
84
+ return;
85
+ }
86
+ if (Object.keys(cliJson).length === 0) {
87
+ consola.warn("No commands found in cli.json");
88
+ return;
89
+ }
90
+ const allTags = Object.values(silgi.commands).reduce((acc, commandGroup) => {
91
+ Object.values(commandGroup).forEach((command) => {
92
+ if (command.tags) {
93
+ command.tags.forEach((tag) => acc.add(tag));
94
+ }
95
+ });
96
+ return acc;
97
+ }, /* @__PURE__ */ new Set());
98
+ const commandName = await p.select({
99
+ message: "Select a command to run",
100
+ options: [
101
+ ...allTags.size ? [{
102
+ value: "command-tags",
103
+ label: "Command Tags",
104
+ hint: "It executes all commands that are related to the tags you select."
105
+ }] : [],
106
+ ...Object.keys(cliJson).filter((key) => {
107
+ const scripts = cliJson[key];
108
+ const scriptValues = Object.values(scripts);
109
+ return scriptValues;
110
+ }).map((key) => ({
111
+ label: key,
112
+ value: key
113
+ }))
114
+ ]
115
+ });
116
+ if (!commandName)
117
+ return;
118
+ if (commandName === "command-tags") {
119
+ const tags2 = Array.from(allTags);
120
+ const selectedTags = await p.select({
121
+ message: "Select tags to run",
122
+ options: tags2.map((tag) => ({
123
+ label: tag,
124
+ value: tag
125
+ }))
126
+ });
127
+ if (!selectedTags)
128
+ return;
129
+ selectedCommands = Object.keys(cliJson).map(
130
+ (commandName2) => {
131
+ const scripts = cliJson[commandName2];
132
+ return Object.keys(scripts).map((scriptName) => ({
133
+ command: commandName2,
134
+ script: scriptName,
135
+ handler: scripts[scriptName]
136
+ })).filter((script) => script.handler.tags?.includes(selectedTags));
137
+ }
138
+ ).flat();
139
+ } else {
140
+ const scripts = cliJson[commandName];
141
+ const scriptName = await p.select({
142
+ message: "Select a script to run",
143
+ options: Object.keys(scripts).filter((key) => !scripts[key].tags?.length).map((key) => ({
144
+ label: key,
145
+ value: key
146
+ }))
147
+ });
148
+ if (!scriptName)
149
+ return;
150
+ selectedCommands = [{
151
+ command: commandName,
152
+ script: scriptName,
153
+ handler: scripts[scriptName]
154
+ }];
155
+ }
156
+ }
157
+ for (const cmd of selectedCommands) {
158
+ if (cmd.handler.enabled === false) {
159
+ continue;
160
+ }
161
+ if (cmd.handler.type === "command") {
162
+ execSync(cmd.handler.handler, { stdio: "inherit" });
163
+ }
164
+ if (cmd.handler.type === "function") {
165
+ const jiti = createJiti(import.meta.url, {
166
+ alias: silgiConfig.alias
167
+ });
168
+ let cleanHandler = cmd.handler.handler.replace(/\n/g, "");
169
+ cleanHandler = `import { silgiCLICtx } from 'silgi'
170
+ ${cleanHandler}
171
+ `;
172
+ await jiti.evalModule(cleanHandler, {
173
+ filename: import.meta.url,
174
+ async: true,
175
+ conditions: silgiConfig.conditions,
176
+ forceTranspile: true
177
+ });
178
+ }
179
+ }
180
+ await silgiCLIIClose();
181
+ }
182
+ });
183
+
184
+ const run$1 = {
185
+ __proto__: null,
186
+ default: run
187
+ };
188
+
189
+ const prepare = defineCommand({
190
+ meta: {
191
+ name: "prepare",
192
+ description: "Generate types for the project",
193
+ version: version
194
+ },
195
+ args: {
196
+ ...commonArgs,
197
+ preset: {
198
+ type: "string",
199
+ description: "The build preset to use (you can also use `SILGI_PRESET` environment variable)."
200
+ },
201
+ stub: {
202
+ type: "boolean",
203
+ description: "Run in silgi development mode"
204
+ },
205
+ dev: {
206
+ type: "boolean",
207
+ description: "Run in silgi development mode"
208
+ },
209
+ env: {
210
+ type: "string",
211
+ description: "The environment to use"
212
+ },
213
+ commands: {
214
+ type: "string",
215
+ description: "The commands to run"
216
+ }
217
+ },
218
+ async run({ args }) {
219
+ const rootDir = resolve(args.dir || args._dir || ".");
220
+ const silgi = await createSilgiCLI({
221
+ rootDir,
222
+ dev: args.dev || args.stub,
223
+ stub: args.stub,
224
+ preset: args.preset,
225
+ commandType: "prepare",
226
+ activeEnvironment: args.env
227
+ });
228
+ await prepare$2();
229
+ await writeTypesAndFiles(silgi);
230
+ await writeCoreFile(silgi);
231
+ await prepareBuild(silgi);
232
+ if (!args.commands) {
233
+ await runCommand(run, {
234
+ rawArgs: ["--tag", "init", "--active", "false"]
235
+ });
236
+ }
237
+ return {
238
+ silgi
239
+ };
240
+ }
241
+ });
242
+
243
+ const prepare$1 = {
244
+ __proto__: null,
245
+ default: prepare
246
+ };
247
+
248
+ export { prepare$1 as a, commonArgs as c, prepare as p, run$1 as r };
@@ -1,4 +1,4 @@
1
- export { l as loadOptions, s as silgiGenerateType } from '../types.mjs';
1
+ export { l as loadOptions, s as silgiGenerateType } from '../../shared/silgi.BIBmUBIR.mjs';
2
2
  import 'c12';
3
3
  import 'compatx';
4
4
  import 'klona/full';
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import { defineCommand, runMain } from 'citty';
3
3
 
4
- const version = "0.24.14";
4
+ const version = "0.24.16";
5
5
  const packageJson = {
6
6
  version: version};
7
7
 
@@ -18,11 +18,11 @@ const main = defineCommand({
18
18
  }
19
19
  },
20
20
  subCommands: {
21
- prepare: () => import('./prepare.mjs').then(function (n) { return n.a; }).then((m) => m.default),
22
- init: () => import('./init.mjs').then((m) => m.default),
23
- run: () => import('./prepare.mjs').then(function (n) { return n.r; }).then((m) => m.default),
24
- install: () => import('./install.mjs').then((m) => m.default),
25
- dev: () => import('./dev.mjs').then((m) => m.default)
21
+ prepare: () => import('../chunks/prepare.mjs').then(function (n) { return n.a; }).then((m) => m.default),
22
+ init: () => import('../chunks/init.mjs').then((m) => m.default),
23
+ run: () => import('../chunks/prepare.mjs').then(function (n) { return n.r; }).then((m) => m.default),
24
+ install: () => import('../chunks/install.mjs').then((m) => m.default),
25
+ dev: () => import('../chunks/dev.mjs').then((m) => m.default)
26
26
  },
27
27
  run({ args }) {
28
28
  if (args.version)
package/dist/index.d.mts CHANGED
@@ -1,8 +1,21 @@
1
- import { SilgiConfig, Silgi, SilgiEvents, SilgiFunction, SilgiOperation, MergedSilgiSchema, ServiceType, SilgiSchema, RequiredServiceType, SilgiRuntimeSharedsExtend, SilgiRuntimeContext, DefaultNamespaces, BaseSchemaType, SilgiRuntimeShareds, StorageConfig, SilgiCLI, SilgiStorageBase } from 'silgi/types';
1
+ import { SilgiCLI, SilgiCLIConfig, LoadConfigOptions, SilgiConfig, Silgi, SilgiEvents, SilgiFunction, SilgiOperation, MergedSilgiSchema, ServiceType, SilgiSchema, RequiredServiceType, SilgiRuntimeSharedsExtend, SilgiRuntimeContext, DefaultNamespaces, BaseSchemaType, SilgiRuntimeShareds, StorageConfig, SilgiStorageBase } from 'silgi/types';
2
2
  import { StandardSchemaV1 } from '@standard-schema/spec';
3
3
  import { Storage, StorageValue } from 'unstorage';
4
4
  import * as unctx from 'unctx';
5
5
 
6
+ /**
7
+ * Prepares route rules for the build
8
+ */
9
+ declare function prepareBuild(silgi: SilgiCLI): Promise<void>;
10
+
11
+ declare function prepare(_silgi: SilgiCLI): Promise<void>;
12
+
13
+ declare function createSilgiCLI(config?: SilgiCLIConfig, opts?: LoadConfigOptions): Promise<SilgiCLI>;
14
+
15
+ declare function writeCoreFile(silgi: SilgiCLI): Promise<void>;
16
+
17
+ declare function writeTypesAndFiles(silgi: SilgiCLI): Promise<void>;
18
+
6
19
  declare function createSilgi(config: SilgiConfig): Promise<Silgi>;
7
20
 
8
21
  declare function silgi(event?: SilgiEvents | Record<string, any>): SilgiFunction;
@@ -267,5 +280,5 @@ declare function storageMount<T extends Storage = Storage>(silgi?: Silgi): (base
267
280
 
268
281
  declare const autoImportTypes: string[];
269
282
 
270
- export { ErrorCategory, ErrorFactory, ErrorSeverity, HttpStatus, SilgiError, autoImportTypes, createSchema, createService, createShared, createSilgi, createStorage, getEvent, getEventContext, isBaseError, mergeSchemas, mergeServices, mergeShared, parseURI, replaceRuntimeValues, silgi, silgiCLICtx, silgiCtx, storageMount, tryUseSilgi, tryUseSilgiCLI, useSilgi, useSilgiCLI, useSilgiStorage };
283
+ export { ErrorCategory, ErrorFactory, ErrorSeverity, HttpStatus, SilgiError, autoImportTypes, createSchema, createService, createShared, createSilgi, createSilgiCLI, createStorage, getEvent, getEventContext, isBaseError, mergeSchemas, mergeServices, mergeShared, parseURI, prepare, prepareBuild, replaceRuntimeValues, silgi, silgiCLICtx, silgiCtx, storageMount, tryUseSilgi, tryUseSilgiCLI, useSilgi, useSilgiCLI, useSilgiStorage, writeCoreFile, writeTypesAndFiles };
271
284
  export type { BaseError, ErrorMetadata };
package/dist/index.mjs CHANGED
@@ -1,14 +1,44 @@
1
+ import { e as createRouteRules } from './shared/silgi.CvG35CGc.mjs';
2
+ export { c as createSilgiCLI, a as prepare, d as prepareBuild, f as silgiCLICtx, t as tryUseSilgiCLI, u as useSilgiCLI, b as writeCoreFile, w as writeTypesAndFiles } from './shared/silgi.CvG35CGc.mjs';
1
3
  import { createConsola } from 'consola';
2
4
  import defu, { defu as defu$1 } from 'defu';
3
5
  import { createHooks } from 'hookable';
4
- import { c as createRouteRules } from './_chunks/silgiApp.mjs';
5
- export { a as silgiCLICtx, t as tryUseSilgiCLI, u as useSilgiCLI } from './_chunks/silgiApp.mjs';
6
6
  import { getContext } from 'unctx';
7
7
  import { Buffer } from 'node:buffer';
8
8
  import { klona } from 'klona';
9
9
  import { useSilgiRuntimeConfig } from 'silgi/runtime';
10
10
  import { createStorage as createStorage$1, builtinDrivers, prefixStorage } from 'unstorage';
11
+ import 'knitwork';
12
+ import 'pathe';
13
+ import 'silgi/kit';
14
+ import 'node:fs';
15
+ import 'node:fs/promises';
16
+ import 'silgi';
17
+ import 'silgi/runtime/meta';
18
+ import 'unimport';
11
19
  import 'ufo';
20
+ import '@clack/prompts';
21
+ import 'dotenv';
22
+ import 'mlly';
23
+ import 'dev-jiti';
24
+ import './shared/silgi.DWfN_DdY.mjs';
25
+ import 'semver/functions/satisfies.js';
26
+ import 'silgi/meta';
27
+ import 'node:url';
28
+ import 'exsolve';
29
+ import 'untyped';
30
+ import 'globby';
31
+ import 'ignore';
32
+ import '@oxc-parser/wasm';
33
+ import './shared/silgi.BIBmUBIR.mjs';
34
+ import 'c12';
35
+ import 'compatx';
36
+ import 'klona/full';
37
+ import 'std-env';
38
+ import 'consola/utils';
39
+ import 'escape-string-regexp';
40
+ import 'pkg-types';
41
+ import 'pathe/utils';
12
42
 
13
43
  const silgiCtx = getContext("silgi");
14
44
  function useSilgi() {
@@ -1,34 +1,17 @@
1
+ import { ConsolaOptions, ConsolaInstance } from 'consola';
1
2
  import { SilgiCLI, ModuleOptionsCustom, ModuleDefinition, SilgiModule, ServiceParseModule, SilgiPreset, SilgiPresetMeta, SilgiTemplate, ResolvedSilgiTemplate, SilgiEvents } from 'silgi/types';
2
3
  import { Buffer } from 'node:buffer';
3
- import * as consola from 'consola';
4
- import { ConsolaOptions } from 'consola';
5
4
  import { IncomingMessage, ServerResponse } from 'node:http';
6
5
 
7
- declare function hasError(type: SilgiCLI['errors'][0]['type'], silgi?: SilgiCLI): boolean;
6
+ declare function useLogger(tag?: string, options?: Partial<ConsolaOptions>): ConsolaInstance;
8
7
 
9
- declare function directoryToURL(dir: string): URL;
10
- /**
11
- * Resolve a module from a given root path using an algorithm patterned on
12
- * the upcoming `import.meta.resolve`. It returns a file URL
13
- *
14
- * @internal
15
- */
16
- declare function tryResolveModule(id: string, url?: string | string[]): Promise<string | undefined>;
8
+ declare function hasError(type: SilgiCLI['errors'][0]['type'], silgi?: SilgiCLI): boolean;
17
9
 
18
10
  declare function writeFile(file: string, contents: Buffer | string, log?: boolean): Promise<void>;
19
11
  declare function isDirectory(path: string): Promise<boolean>;
20
12
 
21
- declare function genEnsureSafeVar(name: string | any): string;
22
- declare function getAllEntries(obj: object): [string, any][];
23
-
24
13
  declare function hash(data: any): string;
25
14
 
26
- declare function isNuxt(): boolean;
27
- declare function isNitro(): boolean;
28
- declare function isH3(): boolean;
29
-
30
- declare function useLogger(tag?: string, options?: Partial<ConsolaOptions>): consola.ConsolaInstance;
31
-
32
15
  /**
33
16
  * Define a Silgi module, automatically merging defaults with user provided options, installing
34
17
  * any hooks that are provided, and calling an optional setup function for full control.
@@ -127,6 +110,22 @@ declare function getIpAddress(event: SilgiEvents): string | false;
127
110
  */
128
111
  declare function ipAddress(req: IncomingMessage): string;
129
112
 
113
+ declare function directoryToURL(dir: string): URL;
114
+ /**
115
+ * Resolve a module from a given root path using an algorithm patterned on
116
+ * the upcoming `import.meta.resolve`. It returns a file URL
117
+ *
118
+ * @internal
119
+ */
120
+ declare function tryResolveModule(id: string, url?: string | string[]): Promise<string | undefined>;
121
+
122
+ declare function genEnsureSafeVar(name: string | any): string;
123
+ declare function getAllEntries(obj: object): [string, any][];
124
+
125
+ declare function isNuxt(): boolean;
126
+ declare function isNitro(): boolean;
127
+ declare function isH3(): boolean;
128
+
130
129
  declare function relativeWithDot(from: string, to: string): string;
131
130
  /** @since 3.9.0 */
132
131
  declare function toArray<T>(value: T | T[]): T[];