silgi 0.28.12 → 0.29.1

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,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import { defineCommand, runMain } from 'citty';
3
3
 
4
- const version = "0.28.12";
4
+ const version = "0.29.1";
5
5
  const packageJson = {
6
6
  version: version};
7
7
 
@@ -135,14 +135,15 @@ const command$1 = defineCommand({
135
135
  message: "Select commands to run",
136
136
  required: true,
137
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
- ];
138
+ ...selectedCommands.sort((a, b) => (a.order || Infinity) - (b.order || Infinity)).reduce((acc, cmd) => {
139
+ if (!acc[cmd.group || ""]) {
140
+ acc[cmd.group || ""] = [];
141
+ }
142
+ acc[cmd.group || ""].push({
143
+ label: cmd.name,
144
+ value: cmd,
145
+ hint: cmd.description
146
+ });
146
147
  return acc;
147
148
  }, {})
148
149
  }
@@ -2293,6 +2293,7 @@ async function createSilgiCLI(config = {}, opts = {}) {
2293
2293
  silgiCLICtx.set(silgi);
2294
2294
  silgi.hook("close", () => silgiCLICtx.unset());
2295
2295
  }
2296
+ await silgi.hooks.callHook("ready", silgi);
2296
2297
  if (silgi.options.debug) {
2297
2298
  createDebugger(silgi.hooks, { tag: "silgi" });
2298
2299
  silgi.options.plugins.push({
@@ -1,7 +1,7 @@
1
1
  import { watchConfig, loadConfig } from 'c12';
2
2
  import { resolveCompatibilityDatesFromEnv, formatDate, resolveCompatibilityDates } from 'compatx';
3
3
  import { klona } from 'klona/full';
4
- import { isDebug, isTest } from 'std-env';
4
+ import { isTest, isDebug } from 'std-env';
5
5
  import consola from 'consola';
6
6
  import { colors } from 'consola/utils';
7
7
  import { relative, join, resolve, dirname, isAbsolute } from 'pathe';
@@ -16,7 +16,7 @@ import { defu } from 'defu';
16
16
 
17
17
  const SilgiCLIDefaults = {
18
18
  // General
19
- debug: isDebug,
19
+ debug: isDebug === true ? true : void 0,
20
20
  // timing: isDebug,
21
21
  logLevel: isTest ? 1 : 3,
22
22
  // runtimeConfig: { app: {}, silgi: {} },
@@ -1,15 +1,22 @@
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;
10
12
  isDev?: boolean;
11
13
  when?: boolean;
12
- }[]): Promise<void>;
14
+ }[] | {
15
+ name: string;
16
+ version?: string;
17
+ isDev?: boolean;
18
+ when?: boolean;
19
+ }): Promise<void>;
13
20
 
14
21
  declare function hasError(type: SilgiCLI['errors'][0]['type'], silgi?: SilgiCLI): boolean;
15
22
 
@@ -289,5 +296,5 @@ declare function hasInstalledModule(moduleKey: string, silgi?: SilgiCLI): boolea
289
296
  declare const baseHeaderBannerComment: string[];
290
297
  declare function processFilePath(src: string): string;
291
298
 
292
- 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 };
299
+ 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 };
293
300
  export type { FunctionConfig, JsonPatch, MigrationData, MigrationInfo, MigrationOptions, MigrationResult };
@@ -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,10 +22,55 @@ 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();
28
- for (const item of data) {
72
+ const silgi = useSilgiCLI$1();
73
+ for (const item of toArray(data)) {
29
74
  if (item.when === false) {
30
75
  continue;
31
76
  }
@@ -96,7 +141,7 @@ function _compilePathTemplate(contents) {
96
141
  }
97
142
 
98
143
  async function writeFile(file, contents, log = false) {
99
- const silgi = useSilgiCLI$1();
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$1()) {
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$1();
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$1();
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 };
@@ -1,5 +1,4 @@
1
- import { defineSilgiPreset } from "silgi/kit";
2
- import { peerDependencies } from "silgi/meta";
1
+ import { addNPMPackage, defineSilgiPreset } from "silgi/kit";
3
2
  const h3 = defineSilgiPreset(
4
3
  {
5
4
  static: true,
@@ -11,11 +10,11 @@ const h3 = defineSilgiPreset(
11
10
  crawlLinks: true
12
11
  },
13
12
  hooks: {
14
- "prepare:installPackages": async (packages) => {
15
- packages.dependencies = {
16
- ...packages.dependencies,
17
- h3: peerDependencies.h3
18
- };
13
+ ready: async () => {
14
+ await addNPMPackage({
15
+ name: "h3",
16
+ isDev: true
17
+ });
19
18
  }
20
19
  }
21
20
  },
@@ -1,5 +1,4 @@
1
- import { defineSilgiPreset } from "silgi/kit";
2
- import { peerDependencies } from "silgi/meta";
1
+ import { addNPMPackage, defineSilgiPreset } from "silgi/kit";
3
2
  const nitro = defineSilgiPreset(
4
3
  {
5
4
  static: true,
@@ -26,11 +25,11 @@ const nitro = defineSilgiPreset(
26
25
  ]
27
26
  },
28
27
  hooks: {
29
- "prepare:installPackages": async (packages) => {
30
- packages.dependencies = {
31
- ...packages.dependencies,
32
- h3: peerDependencies.h3
33
- };
28
+ ready: async () => {
29
+ await addNPMPackage({
30
+ name: "h3",
31
+ isDev: true
32
+ });
34
33
  }
35
34
  },
36
35
  storages: ["data", "/assets"]
@@ -1,5 +1,4 @@
1
- import { defineSilgiPreset } from "silgi/kit";
2
- import { peerDependencies } from "silgi/meta";
1
+ import { addNPMPackage, defineSilgiPreset } from "silgi/kit";
3
2
  const nuxt = defineSilgiPreset(
4
3
  {
5
4
  static: true,
@@ -27,11 +26,11 @@ const nuxt = defineSilgiPreset(
27
26
  ]
28
27
  },
29
28
  hooks: {
30
- "prepare:installPackages": async (packages) => {
31
- packages.dependencies = {
32
- ...packages.dependencies,
33
- h3: peerDependencies.h3
34
- };
29
+ ready: async () => {
30
+ await addNPMPackage({
31
+ name: "h3",
32
+ isDev: true
33
+ });
35
34
  }
36
35
  },
37
36
  storages: ["data", "/assets"]
@@ -147,6 +147,21 @@ interface ResolvedSilgiTemplate<Options = TemplateDefaultOptions> extends SilgiT
147
147
  modified?: boolean;
148
148
  }
149
149
 
150
+ interface SilgiCommands {
151
+ }
152
+ interface Commands {
153
+ name: string;
154
+ description?: string;
155
+ group: string;
156
+ when?: boolean;
157
+ type: 'function' | 'command';
158
+ tags?: (keyof SilgiCommands)[] | (string | object)[];
159
+ getContents: (data: {
160
+ app: SilgiCLI;
161
+ }) => string;
162
+ order?: number;
163
+ }
164
+
150
165
  interface SilgiCLIHooks extends SilgiHooks {
151
166
  /**
152
167
  * Called after Silgi initialization, when the Silgi instance is ready to work.
@@ -263,7 +278,7 @@ interface SilgiCLIHooks extends SilgiHooks {
263
278
  */
264
279
  'app:templatesGenerated': (app: SilgiCLI, templates: ResolvedSilgiTemplate[], options?: GenerateAppOptions) => HookResult;
265
280
  'scanFiles:done': (app: SilgiCLI) => HookResult;
266
- 'prepare:commands': (commands: SilgiCLI['commands']) => HookResult;
281
+ 'prepare:commands': (commands: Commands[]) => HookResult;
267
282
  }
268
283
  type TSReference = {
269
284
  types: string;
@@ -1147,20 +1162,6 @@ interface GraphQLJSON {
1147
1162
  references: any;
1148
1163
  }
1149
1164
 
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
-
1164
1165
  interface BaseNamespaceType extends Record<keyof DefaultNamespaces, Record<string, BaseSchemaType<StandardSchemaV1>>> {
1165
1166
  }
1166
1167
  type Namespaces<T extends BaseNamespaceType> = {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "silgi",
3
3
  "type": "module",
4
- "version": "0.28.12",
4
+ "version": "0.29.1",
5
5
  "private": false,
6
6
  "sideEffects": false,
7
7
  "exports": {