silgi 0.43.25 → 0.43.27

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,5 +1,4 @@
1
1
  import { generateApiFul } from "../core/apiful.mjs";
2
- import { generateApp } from "../core/app.mjs";
3
2
  import { prepareCommands } from "../scan/prepareCommands.mjs";
4
3
  import { writeCoreFile } from "../scan/writeCoreFile.mjs";
5
4
  import { writeTypesAndFiles } from "../scan/writeTypesAndFiles.mjs";
@@ -10,7 +9,6 @@ async function build(silgi) {
10
9
  await prepareCommands(silgi);
11
10
  await writeCoreFile(silgi);
12
11
  await writeTypesAndFiles(silgi);
13
- await generateApp(silgi);
14
12
  }
15
13
 
16
14
  //#endregion
@@ -1,5 +1,5 @@
1
1
  import { silgiCLIIClose, useSilgiCLI } from "../../core/silgiApp.mjs";
2
- import { watchFile } from "../core/devServer.mjs";
2
+ import { reloadScan } from "../core/devServer.mjs";
3
3
  import { prepareBuild } from "./prepare.mjs";
4
4
  import { watch } from "chokidar";
5
5
  import consola from "consola";
@@ -69,7 +69,7 @@ async function watchDev() {
69
69
  if (!watchReloadEvents.has(event)) return;
70
70
  changedFiles.add(path);
71
71
  try {
72
- await watchFile(event, path, stats);
72
+ await reloadScan(path, stats);
73
73
  await reload();
74
74
  } catch (error) {
75
75
  consola.withTag("silgi").error(error);
@@ -1,6 +1,6 @@
1
1
  import { consola as consola$1 } from "consola";
2
2
  import { join, resolve } from "pathe";
3
- import { addTemplate, hasSilgiModule } from "silgi/kit";
3
+ import { hasSilgiModule, writeTemplate } from "silgi/kit";
4
4
  import { generateDTS } from "apiful/openapi";
5
5
 
6
6
  //#region src/cli/core/apiful.ts
@@ -24,7 +24,7 @@ async function generateApiFul(silgi) {
24
24
  silgi.hook("prepare:types", (opts) => {
25
25
  opts.references.push({ path: "./apiful.d.ts" });
26
26
  });
27
- addTemplate({
27
+ writeTemplate({
28
28
  filename: "types/apiful.d.ts",
29
29
  where: ".silgi",
30
30
  write: true,
@@ -1,10 +1,10 @@
1
1
  import { useSilgiCLI } from "silgi";
2
2
 
3
3
  //#region src/cli/core/devServer.ts
4
- async function watchFile(event, file, stats) {
4
+ async function reloadScan(path, _stats) {
5
5
  const silgi = useSilgiCLI();
6
- await silgi.callHook("watch:file", event, file, stats);
6
+ await silgi.callHook("reload:scan", path, _stats);
7
7
  }
8
8
 
9
9
  //#endregion
10
- export { watchFile };
10
+ export { reloadScan };
@@ -1,5 +1,5 @@
1
1
  import { useSilgiCLI } from "../../core/silgiApp.mjs";
2
- import { addNPMPackage, addTemplate } from "silgi/kit";
2
+ import { addNPMPackage, writeTemplate } from "silgi/kit";
3
3
 
4
4
  //#region src/cli/core/installPackage.ts
5
5
  /**
@@ -47,7 +47,7 @@ async function installPackages(silgi = useSilgiCLI()) {
47
47
  };
48
48
  packages.dependencies = {};
49
49
  }
50
- if (silgi.options.debug === true || silgi.options.debug?.install) addTemplate({
50
+ if (silgi.options.debug === true || silgi.options.debug?.install) writeTemplate({
51
51
  filename: "install.json",
52
52
  where: ".silgi",
53
53
  write: true,
@@ -1,5 +1,5 @@
1
1
  import { useSilgiCLI } from "silgi";
2
- import { addTemplate } from "silgi/kit";
2
+ import { writeTemplate } from "silgi/kit";
3
3
  import { initRuntimeConfig } from "silgi/runtime";
4
4
  import { snakeCase } from "scule";
5
5
 
@@ -10,7 +10,7 @@ function useCLIRuntimeConfig(silgi = useSilgiCLI()) {
10
10
  data.runtimeConfig = safeRuntimeConfig;
11
11
  silgi.options.envOptions = silgi.options.envOptions;
12
12
  });
13
- addTemplate({
13
+ writeTemplate({
14
14
  filename: "env.example",
15
15
  write: true,
16
16
  where: ".silgi",
@@ -1,4 +1,4 @@
1
- import { addCoreFile, addTemplate, isPresents } from "silgi/kit";
1
+ import { addCoreFile, isPresents, writeTemplate } from "silgi/kit";
2
2
 
3
3
  //#region src/cli/framework/h3.ts
4
4
  async function h3Framework(silgi, skip = false) {
@@ -13,7 +13,7 @@ async function h3Framework(silgi, skip = false) {
13
13
  }]);
14
14
  });
15
15
  silgi.hook("prepare:types", (opts) => {
16
- addTemplate({
16
+ writeTemplate({
17
17
  filename: "types/h3.d.ts",
18
18
  where: ".silgi",
19
19
  getContents: () => {
@@ -1,13 +1,13 @@
1
1
  import { useSilgiCLI } from "../../core/silgiApp.mjs";
2
2
  import { debugMode } from "../utils/debug.mjs";
3
- import { addTemplate } from "silgi/kit";
3
+ import { writeTemplate } from "silgi/kit";
4
4
  import { genAugmentation } from "knitwork";
5
5
 
6
6
  //#region src/cli/scan/prepareCommands.ts
7
7
  async function prepareCommands(silgi = useSilgiCLI()) {
8
8
  const commands = [];
9
9
  await silgi.callHook("prepare:commands", commands);
10
- if (debugMode("command")) addTemplate({
10
+ if (debugMode("command")) writeTemplate({
11
11
  filename: "cli.json",
12
12
  where: ".silgi",
13
13
  write: true,
@@ -25,7 +25,7 @@ async function prepareCommands(silgi = useSilgiCLI()) {
25
25
  "",
26
26
  "export {}"
27
27
  ];
28
- addTemplate({
28
+ writeTemplate({
29
29
  filename: "types/commands.d.ts",
30
30
  write: true,
31
31
  where: ".silgi",
@@ -48,16 +48,12 @@ async function prepareSchema(silgi) {
48
48
  "",
49
49
  `type SilgiModuleContextExtends = ${data.contexts.length ? data.contexts.map(({ value }) => value).join(" & ") : "{}"}`,
50
50
  "",
51
- data.events.length ? (() => {
52
- const extendsTypes = data.events.filter((item) => item.extends).map((item) => item.value).join(", ");
53
- const hasExtends = extendsTypes.length > 0;
54
- return `interface SilgiModuleEventsExtends ${hasExtends ? `extends ${extendsTypes} ` : ""}{
51
+ data.events.length ? `interface SilgiModuleEventsExtends extends ${data.events.map((item) => item.extends ? item.value : "").join(", ")} {
55
52
  ${data.events.map((item) => {
56
- if (item.isSilgiContext) addSilgiContext = true;
57
- return !item.extends && !addSilgiContext ? ` ${item.key}: ${item.value}` : item.isSilgiContext ? " context: SilgiRuntimeContext" : "";
58
- }).join(",\n")}
59
- }`;
60
- })() : "interface SilgiModuleEventsExtends {}",
53
+ if (item.isSilgiContext) addSilgiContext = true;
54
+ return !item.extends && !addSilgiContext ? ` ${item.key}: ${item.value}` : item.isSilgiContext ? " context: SilgiRuntimeContext" : "";
55
+ }).join(",\n")}
56
+ }` : "interface SilgiModuleEventsExtends {}",
61
57
  "",
62
58
  `type SetupModuleOptionExtend = ${data.setupModuleOption?.length ? data.setupModuleOption.map(({ value }) => `${value}`).join(" & ") : "{}"}`,
63
59
  "",
@@ -7,7 +7,7 @@ import { createStorage, useSilgiStorage } from "./utils/storage.mjs";
7
7
  import { createSilgi } from "./createSilgi.mjs";
8
8
  import { SilgiHttpEvent } from "./event.mjs";
9
9
  import { handleResponse, kHandled, kNotFound } from "./response.mjs";
10
- import { createResolver$1 as createResolver, getUrlPrefix } from "./utils/resolver.mjs";
10
+ import { createResolver, getUrlPrefix } from "./utils/resolver.mjs";
11
11
  import { getWebsocket, handler, middleware, silgiFetch } from "./silgi.mjs";
12
12
  import { storageMount } from "./storage.mjs";
13
13
  import { createEventStream } from "./utils/event-stream.mjs";
@@ -26,4 +26,4 @@ function getUrlPrefix(path, method) {
26
26
  }
27
27
 
28
28
  //#endregion
29
- export { createResolver as createResolver$1, getUrlPrefix };
29
+ export { createResolver, getUrlPrefix };
package/dist/index.mjs CHANGED
@@ -7,7 +7,7 @@ import { createStorage, useSilgiStorage } from "./core/utils/storage.mjs";
7
7
  import { createSilgi } from "./core/createSilgi.mjs";
8
8
  import { SilgiHttpEvent } from "./core/event.mjs";
9
9
  import { handleResponse, kHandled, kNotFound } from "./core/response.mjs";
10
- import { createResolver$1 as createResolver, getUrlPrefix } from "./core/utils/resolver.mjs";
10
+ import { createResolver, getUrlPrefix } from "./core/utils/resolver.mjs";
11
11
  import { getWebsocket, handler, middleware, silgiFetch } from "./core/silgi.mjs";
12
12
  import { storageMount } from "./core/storage.mjs";
13
13
  import { createEventStream } from "./core/utils/event-stream.mjs";
package/dist/kit/fs.d.mts CHANGED
@@ -1,7 +1,4 @@
1
- import { Buffer } from "node:buffer";
2
-
3
1
  //#region src/kit/fs.d.ts
4
- declare function writeFile(file: string, contents: Buffer | string, log?: boolean): Promise<void>;
5
2
  declare function isDirectory(path: string): Promise<boolean>;
6
3
  //#endregion
7
- export { isDirectory as isDirectory$1, writeFile as writeFile$1 };
4
+ export { isDirectory as isDirectory$1 };
package/dist/kit/fs.mjs CHANGED
@@ -1,16 +1,6 @@
1
- import { prettyPath } from "./path.mjs";
2
- import { dirname } from "pathe";
3
- import { useSilgiCLI } from "silgi";
4
1
  import fsp from "node:fs/promises";
5
2
 
6
3
  //#region src/kit/fs.ts
7
- async function writeFile$1(file, contents, log = false) {
8
- const silgi = useSilgiCLI();
9
- if (silgi.errors.length) return;
10
- await fsp.mkdir(dirname(file), { recursive: true });
11
- await fsp.writeFile(file, contents, typeof contents === "string" ? "utf8" : void 0);
12
- if (log) silgi.logger.info("Generated", prettyPath(file));
13
- }
14
4
  async function isDirectory(path) {
15
5
  try {
16
6
  return (await fsp.stat(path)).isDirectory();
@@ -20,4 +10,4 @@ async function isDirectory(path) {
20
10
  }
21
11
 
22
12
  //#endregion
23
- export { isDirectory, writeFile$1 as writeFile };
13
+ export { isDirectory };
@@ -5,7 +5,7 @@ import { addNPMPackage$1 as addNPMPackage } from "./add/add-npm.mjs";
5
5
  import { defineFramework$1 as defineFramework } from "./define.mjs";
6
6
  import { hasError$1 as hasError } from "./errors.mjs";
7
7
  import { directoryToURL$1 as directoryToURL, tryResolveModule$1 as tryResolveModule } from "./esm.mjs";
8
- import { isDirectory$1 as isDirectory, writeFile$1 as writeFile } from "./fs.mjs";
8
+ import { isDirectory$1 as isDirectory } from "./fs.mjs";
9
9
  import { FunctionConfig, createFunction$1 as createFunction, createFunctionConfigs$1 as createFunctionConfigs, formatFunctions$1 as formatFunctions } from "./function-utils.mjs";
10
10
  import { genEnsureSafeVar$1 as genEnsureSafeVar, getAllEntries$1 as getAllEntries } from "./gen.mjs";
11
11
  import { hash$1 as hash } from "./hash.mjs";
@@ -16,7 +16,7 @@ import { defineSilgiModule$1 as defineSilgiModule } from "./module.mjs";
16
16
  import { prettyPath$1 as prettyPath, resolveSilgiPath$1 as resolveSilgiPath } from "./path.mjs";
17
17
  import { defineSilgiPreset$1 as defineSilgiPreset } from "./preset.mjs";
18
18
  import { createResolver$2 as createResolver, resolveAlias$1 as resolveAlias, resolvePath$1 as resolvePath, resolveSilgiModule$1 as resolveSilgiModule } from "./resolve.mjs";
19
- import { addTemplate$1 as addTemplate, normalizeTemplate$1 as normalizeTemplate } from "./template.mjs";
19
+ import { normalizeTemplate$1 as normalizeTemplate, writeFile$1 as writeFile, writeTemplate$1 as writeTemplate } from "./template.mjs";
20
20
  import { getIpAddress$1 as getIpAddress, useRequest$1 as useRequest } from "./useRequest.mjs";
21
21
  import { MODE_RE$1 as MODE_RE, baseHeaderBannerComment$1 as baseHeaderBannerComment, filterInPlace$1 as filterInPlace, getServicePath$1 as getServicePath, hasInstalledModule$2 as hasInstalledModule, hasSilgiModule$1 as hasSilgiModule, isPresents$1 as isPresents, isRuntimePresents$1 as isRuntimePresents, processFilePath$1 as processFilePath, relativeWithDot$1 as relativeWithDot, removeExtension$1 as removeExtension, toArray$1 as toArray } from "./utils.mjs";
22
- export { FunctionConfig, JsonPatch, MODE_RE, MigrationData, MigrationInfo, MigrationOptions, MigrationResult, MigrationStatus, addCommands, addCoreFile, addImports, addNPMPackage, addTemplate, baseHeaderBannerComment, createFunction, createFunctionConfigs, createResolver, defineFramework, defineSilgiModule, defineSilgiPreset, directoryToURL, filterInPlace, formatFunctions, genEnsureSafeVar, generateMigration, getAllEntries, getIpAddress, getMigration, getServicePath, hasError, hasInstalledModule, hasSilgiModule, hash, isDirectory, isH3, isNitro, isNuxt, isPresents, isRuntimePresents, listMigrations, migrationDown, migrationUp, normalizeTemplate, prettyPath, processFilePath, relativeWithDot, removeExtension, resolveAlias, resolvePath, resolveSilgiModule, resolveSilgiPath, toArray, tryResolveModule, useLogger, useRequest, writeFile };
22
+ export { FunctionConfig, JsonPatch, MODE_RE, MigrationData, MigrationInfo, MigrationOptions, MigrationResult, MigrationStatus, addCommands, addCoreFile, addImports, addNPMPackage, baseHeaderBannerComment, createFunction, createFunctionConfigs, createResolver, defineFramework, defineSilgiModule, defineSilgiPreset, directoryToURL, filterInPlace, formatFunctions, genEnsureSafeVar, generateMigration, getAllEntries, getIpAddress, getMigration, getServicePath, hasError, hasInstalledModule, hasSilgiModule, hash, isDirectory, isH3, isNitro, isNuxt, isPresents, isRuntimePresents, listMigrations, migrationDown, migrationUp, normalizeTemplate, prettyPath, processFilePath, relativeWithDot, removeExtension, resolveAlias, resolvePath, resolveSilgiModule, resolveSilgiPath, toArray, tryResolveModule, useLogger, useRequest, writeFile, writeTemplate };
@@ -6,8 +6,7 @@ import { addNPMPackage } from "./add/add-npm.mjs";
6
6
  import { defineFramework } from "./define.mjs";
7
7
  import { hasError } from "./errors.mjs";
8
8
  import { directoryToURL, tryResolveModule } from "./esm.mjs";
9
- import { prettyPath, resolveSilgiPath } from "./path.mjs";
10
- import { isDirectory, writeFile } from "./fs.mjs";
9
+ import { isDirectory } from "./fs.mjs";
11
10
  import { createFunction, createFunctionConfigs, formatFunctions } from "./function-utils.mjs";
12
11
  import { genEnsureSafeVar, getAllEntries } from "./gen.mjs";
13
12
  import { hash } from "./hash.mjs";
@@ -15,9 +14,10 @@ import { isH3, isNitro, isNuxt } from "./isFramework.mjs";
15
14
  import { useLogger } from "./logger.mjs";
16
15
  import { MigrationStatus, generateMigration, getMigration, listMigrations, migrationDown, migrationUp } from "./migration.mjs";
17
16
  import { defineSilgiModule } from "./module.mjs";
17
+ import { prettyPath, resolveSilgiPath } from "./path.mjs";
18
18
  import { defineSilgiPreset } from "./preset.mjs";
19
- import { createResolver, resolveAlias, resolvePath, resolveSilgiModule } from "./resolve.mjs";
20
- import { addTemplate, normalizeTemplate } from "./template.mjs";
19
+ import { createResolver$1 as createResolver, resolveAlias, resolvePath, resolveSilgiModule } from "./resolve.mjs";
20
+ import { normalizeTemplate, writeFile, writeTemplate } from "./template.mjs";
21
21
  import { getIpAddress, useRequest } from "./useRequest.mjs";
22
22
 
23
- export { MODE_RE, MigrationStatus, addCommands, addCoreFile, addImports, addNPMPackage, addTemplate, baseHeaderBannerComment, createFunction, createFunctionConfigs, createResolver, defineFramework, defineSilgiModule, defineSilgiPreset, directoryToURL, filterInPlace, formatFunctions, genEnsureSafeVar, generateMigration, getAllEntries, getIpAddress, getMigration, getServicePath, hasError, hasInstalledModule, hasSilgiModule, hash, isDirectory, isH3, isNitro, isNuxt, isPresents, isRuntimePresents, listMigrations, migrationDown, migrationUp, normalizeTemplate, prettyPath, processFilePath, relativeWithDot, removeExtension, resolveAlias, resolvePath, resolveSilgiModule, resolveSilgiPath, toArray, tryResolveModule, useLogger, useRequest, writeFile };
23
+ export { MODE_RE, MigrationStatus, addCommands, addCoreFile, addImports, addNPMPackage, baseHeaderBannerComment, createFunction, createFunctionConfigs, createResolver, defineFramework, defineSilgiModule, defineSilgiPreset, directoryToURL, filterInPlace, formatFunctions, genEnsureSafeVar, generateMigration, getAllEntries, getIpAddress, getMigration, getServicePath, hasError, hasInstalledModule, hasSilgiModule, hash, isDirectory, isH3, isNitro, isNuxt, isPresents, isRuntimePresents, listMigrations, migrationDown, migrationUp, normalizeTemplate, prettyPath, processFilePath, relativeWithDot, removeExtension, resolveAlias, resolvePath, resolveSilgiModule, resolveSilgiPath, toArray, tryResolveModule, useLogger, useRequest, writeFile, writeTemplate };
@@ -79,4 +79,4 @@ async function resolveSilgiModule(base, paths) {
79
79
  }
80
80
 
81
81
  //#endregion
82
- export { createResolver, resolveAlias$1 as resolveAlias, resolvePath$1 as resolvePath, resolveSilgiModule };
82
+ export { createResolver as createResolver$1, resolveAlias$1 as resolveAlias, resolvePath$1 as resolvePath, resolveSilgiModule };
@@ -1,14 +1,19 @@
1
+ import { Buffer } from "node:buffer";
1
2
  import { ResolvedSilgiTemplate, SilgiTemplate } from "silgi/types";
2
3
 
3
4
  //#region src/kit/template.d.ts
4
5
 
5
6
  /**
6
- * Renders given template during build into the virtual file system (and optionally to disk in the project `buildDir`)
7
+ * Writes a template file to disk immediately
7
8
  */
8
- declare function addTemplate<T>(_template: SilgiTemplate<T> | string): ResolvedSilgiTemplate<T>;
9
+ declare function writeTemplate<T>(_template: SilgiTemplate<T> | string): ResolvedSilgiTemplate<T>;
10
+ /**
11
+ * Simple file writing with CLI error checking (replaces fs.ts writeFile)
12
+ */
13
+ declare function writeFile(file: string, contents: Buffer | string, log?: boolean): Promise<void>;
9
14
  /**
10
15
  * Normalize a silgi template object
11
16
  */
12
17
  declare function normalizeTemplate<T>(template: SilgiTemplate<T> | string, buildDir?: string): ResolvedSilgiTemplate<T>;
13
18
  //#endregion
14
- export { addTemplate as addTemplate$1, normalizeTemplate as normalizeTemplate$1 };
19
+ export { normalizeTemplate as normalizeTemplate$1, writeFile as writeFile$1, writeTemplate as writeTemplate$1 };
@@ -1,24 +1,56 @@
1
- import { filterInPlace } from "./utils.mjs";
2
- import { basename, parse, resolve } from "pathe";
1
+ import { basename, dirname, parse, resolve } from "pathe";
3
2
  import { useSilgiCLI } from "silgi";
4
3
  import { hash } from "silgi/kit";
5
- import { existsSync } from "node:fs";
4
+ import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
6
5
 
7
6
  //#region src/kit/template.ts
8
7
  /**
9
- * Renders given template during build into the virtual file system (and optionally to disk in the project `buildDir`)
8
+ * Writes a template file to disk immediately
10
9
  */
11
- function addTemplate$1(_template) {
12
- const silgi = useSilgiCLI();
13
- const template = normalizeTemplate$1(_template);
14
- filterInPlace(silgi.options.build.templates, (p) => normalizeTemplate$1(p).dst !== template.dst);
15
- silgi.options.build.templates.push(template);
10
+ function writeTemplate$1(_template) {
11
+ const template = normalizeTemplate(_template);
12
+ writeTemplateNow(template).catch((err) => {
13
+ console.error("Error writing template:", err);
14
+ });
16
15
  return template;
17
16
  }
18
17
  /**
18
+ * Simple file writing with CLI error checking (replaces fs.ts writeFile)
19
+ */
20
+ async function writeFile$1(file, contents, log = false) {
21
+ const silgi = useSilgiCLI();
22
+ if (silgi.errors.length) return;
23
+ const filename = basename(file);
24
+ writeTemplate$1({
25
+ filename,
26
+ dst: file,
27
+ getContents: () => contents.toString(),
28
+ write: true
29
+ });
30
+ if (log) silgi.logger.info("Generated", file);
31
+ }
32
+ /**
33
+ * Write template to disk
34
+ */
35
+ async function writeTemplateNow(template) {
36
+ if (template.skipIfExists && existsSync(template.dst)) return;
37
+ let contents;
38
+ if (template.src) contents = readFileSync(template.src, "utf-8");
39
+ else if (template.getContents) {
40
+ const silgi = useSilgiCLI();
41
+ const result = template.getContents({
42
+ app: silgi,
43
+ options: template.options
44
+ });
45
+ contents = await Promise.resolve(result);
46
+ } else throw new Error(`Template must have either 'src' or 'getContents'`);
47
+ mkdirSync(dirname(template.dst), { recursive: true });
48
+ writeFileSync(template.dst, contents, "utf8");
49
+ }
50
+ /**
19
51
  * Normalize a silgi template object
20
52
  */
21
- function normalizeTemplate$1(template, buildDir) {
53
+ function normalizeTemplate(template, buildDir) {
22
54
  if (!template) throw new Error(`Invalid template: ${JSON.stringify(template)}`);
23
55
  if (typeof template === "string") template = { src: template };
24
56
  else template = { ...template };
@@ -56,4 +88,4 @@ function normalizeTemplate$1(template, buildDir) {
56
88
  }
57
89
 
58
90
  //#endregion
59
- export { addTemplate$1 as addTemplate, normalizeTemplate$1 as normalizeTemplate };
91
+ export { normalizeTemplate, writeFile$1 as writeFile, writeTemplate$1 as writeTemplate };
package/dist/package.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  //#region package.json
2
2
  var name = "silgi";
3
3
  var type = "module";
4
- var version = "0.43.25";
4
+ var version = "0.43.27";
5
5
  var private$1 = false;
6
6
  var packageManager = "pnpm@10.12.4";
7
7
  var sideEffects = false;
@@ -80,7 +80,7 @@ interface SilgiCLIOptions extends PresetOptions {
80
80
  dir: string;
81
81
  typesDir: string;
82
82
  /**
83
- * It is recommended to use `addTemplate` from `@nuxt/kit` instead of this option.
83
+ * It is recommended to use `writeTemplate` from `@nuxt/kit` instead of this option.
84
84
  *
85
85
  *
86
86
  * @example
@@ -20,7 +20,7 @@ interface SilgiCLIHooks extends SilgiHooks {
20
20
  * @returns Promise
21
21
  */
22
22
  "close": (silgi: SilgiCLI) => HookResult;
23
- "watch:file": (event: string, file: string, stats?: Stats) => HookResult;
23
+ "reload:scan": (path: string, stats?: Stats) => HookResult;
24
24
  // Kit
25
25
  /**
26
26
  * Allows extending compatibility checks.
@@ -127,18 +127,6 @@ interface SilgiCLIHooks extends SilgiHooks {
127
127
  }) => HookResult;
128
128
  "after:schema.ts": (content: string[]) => HookResult;
129
129
  "prepare:configs.ts": (cliOptions: Record<string, any>) => HookResult;
130
- /**
131
- * Called during `SilgiCLI` generation, to allow customizing, modifying or adding new files to the build directory (either virtually or to written to `.nuxt`).
132
- * @param app The configured `SilgiCLI` object
133
- * @returns Promise
134
- */
135
- "app:templates": (app: SilgiCLI) => HookResult;
136
- /**
137
- * Called after templates are compiled into the [virtual file system](https://nuxt.com/docs/guide/directory-structure/nuxt#virtual-file-system) (vfs).
138
- * @param app The configured `SilgiCLI` object
139
- * @returns Promise
140
- */
141
- "app:templatesGenerated": (app: SilgiCLI, templates: ResolvedSilgiTemplate[], options?: GenerateAppOptions) => HookResult;
142
130
  "prepare:commands": (commands: Commands[]) => HookResult;
143
131
  }
144
132
  type TSReference = {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "silgi",
3
3
  "type": "module",
4
- "version": "0.43.25",
4
+ "version": "0.43.27",
5
5
  "private": false,
6
6
  "sideEffects": false,
7
7
  "exports": {
@@ -97,7 +97,7 @@
97
97
  "destr": "^2.0.5",
98
98
  "dev-jiti": "^2.4.2",
99
99
  "dot-prop": "^9.0.0",
100
- "dotenv": "^17.0.1",
100
+ "dotenv": "^17.1.0",
101
101
  "escape-string-regexp": "^5.0.0",
102
102
  "execa": "^9.6.0",
103
103
  "exsolve": "^1.0.7",
@@ -134,7 +134,7 @@
134
134
  "@antfu/eslint-config": "^4.16.2",
135
135
  "@nuxt/kit": "^3.17.6",
136
136
  "@nuxt/schema": "^3.17.6",
137
- "@silgi/ecosystem": "^0.7.3",
137
+ "@silgi/ecosystem": "^0.7.5",
138
138
  "@types/micromatch": "^4.0.9",
139
139
  "@types/node": "^24.0.10",
140
140
  "@types/semver": "^7.7.0",
@@ -147,7 +147,7 @@
147
147
  "typescript": "^5.8.3",
148
148
  "vitest": "^3.2.4",
149
149
  "vue": "^3.5.17",
150
- "zod": "^3.25.74"
150
+ "zod": "^3.25.75"
151
151
  },
152
152
  "resolutions": {
153
153
  "silgi": "link:."
@@ -1,11 +0,0 @@
1
- //#region rolldown:runtime
2
- var __defProp = Object.defineProperty;
3
- var __export = (target, all) => {
4
- for (var name in all) __defProp(target, name, {
5
- get: all[name],
6
- enumerable: true
7
- });
8
- };
9
-
10
- //#endregion
11
- export { __export };
@@ -1,105 +0,0 @@
1
- import { pluginsDeclaration, templates_exports } from "./templates.mjs";
2
- import { dirname, resolve } from "pathe";
3
- import { normalizeTemplate, useLogger } from "silgi/kit";
4
- import { existsSync, mkdirSync, promises, writeFileSync } from "node:fs";
5
-
6
- //#region src/cli/core/app.ts
7
- const postTemplates = [pluginsDeclaration.filename];
8
- const logger = useLogger("silgi");
9
- async function generateApp(app, options = {}) {
10
- app.templates = Object.values(templates_exports).concat(app.options.build.templates);
11
- await app.callHook("app:templates", app);
12
- app.templates = app.templates.map((tmpl) => {
13
- let dir;
14
- switch (tmpl.where) {
15
- case ".silgi":
16
- dir = app.options.build.dir;
17
- break;
18
- case "server":
19
- dir = app.options.silgi.serverDir;
20
- break;
21
- case "client":
22
- dir = app.options.silgi.clientDir;
23
- break;
24
- case "root":
25
- dir = app.options.rootDir;
26
- break;
27
- default: dir = app.options.silgi.vfsDir;
28
- }
29
- return normalizeTemplate(tmpl, dir);
30
- });
31
- const filteredTemplates = {
32
- pre: [],
33
- post: []
34
- };
35
- for (const template of app.templates) {
36
- if (template.watch === false) {
37
- if (Array.isArray(app.options.watchOptions.ignored)) app.options.watchOptions.ignored.push(`${template.dst || template.src}`);
38
- }
39
- if (options.filter && !options.filter(template)) continue;
40
- const key = template.filename && postTemplates.includes(template.filename) ? "post" : "pre";
41
- filteredTemplates[key].push(template);
42
- }
43
- const templateContext = { app };
44
- const writes = [];
45
- const dirs = new Set();
46
- const changedTemplates = [];
47
- async function processTemplate(template) {
48
- let dir;
49
- switch (template.where) {
50
- case ".silgi":
51
- dir = app.options.build.dir;
52
- break;
53
- case "server":
54
- dir = app.options.silgi.serverDir;
55
- break;
56
- case "client":
57
- dir = app.options.silgi.clientDir;
58
- break;
59
- case "root":
60
- dir = app.options.rootDir;
61
- break;
62
- default: dir = app.options.silgi.vfsDir;
63
- }
64
- const fullPath = template.dst || resolve(dir, template.filename);
65
- const start = performance.now();
66
- const contents = await compileTemplate(template, templateContext).catch((e) => {
67
- logger.error(`Could not compile template \`${template.filename}\`.`);
68
- logger.error(e);
69
- throw e;
70
- });
71
- template.modified = true;
72
- if (template.modified) changedTemplates.push(template);
73
- const perf = performance.now() - start;
74
- const setupTime = Math.round(perf * 100) / 100;
75
- if (app.options.debug || setupTime > 500) logger.info(`Compiled \`${template.filename}\` in ${setupTime}ms`);
76
- if (template.modified && template.write) {
77
- dirs.add(dirname(fullPath));
78
- if (template.skipIfExists && existsSync(fullPath)) return;
79
- writes.push(() => writeFileSync(fullPath, contents, "utf8"));
80
- }
81
- }
82
- await Promise.allSettled(filteredTemplates.pre.map(processTemplate));
83
- await Promise.allSettled(filteredTemplates.post.map(processTemplate));
84
- for (const dir of dirs) mkdirSync(dir, { recursive: true });
85
- for (const write of writes) if (!app.errors.length) write();
86
- if (changedTemplates.length) await app.callHook("app:templatesGenerated", app, changedTemplates, options);
87
- }
88
- /** @internal */
89
- async function compileTemplate(template, ctx) {
90
- delete ctx.utils;
91
- if (template.src) try {
92
- return await promises.readFile(template.src, "utf-8");
93
- } catch (err) {
94
- logger.error(`[nuxt] Error reading template from \`${template.src}\``);
95
- throw err;
96
- }
97
- if (template.getContents) return template.getContents({
98
- ...ctx,
99
- options: template.options
100
- });
101
- throw new Error(`[nuxt] Invalid template. Templates must have either \`src\` or \`getContents\`: ${JSON.stringify(template)}`);
102
- }
103
-
104
- //#endregion
105
- export { generateApp };
@@ -1,38 +0,0 @@
1
- import { __export } from "../../_virtual/rolldown_runtime.mjs";
2
-
3
- //#region src/cli/core/templates.ts
4
- var templates_exports = {};
5
- __export(templates_exports, {
6
- pluginsDeclaration: () => pluginsDeclaration,
7
- vueShim: () => vueShim
8
- });
9
- const vueShim = {
10
- filename: "delete/testtest.d.ts",
11
- where: ".silgi",
12
- getContents: ({ app }) => {
13
- if (!app.options.typescript.shim) return "";
14
- return [
15
- "declare module '*.vue' {",
16
- " import { DefineComponent } from 'vue'",
17
- " const component: DefineComponent<{}, {}, any>",
18
- " export default component",
19
- "}"
20
- ].join("\n");
21
- }
22
- };
23
- const pluginsDeclaration = {
24
- filename: "delete/testtest1.d.ts",
25
- where: ".silgi",
26
- getContents: async () => {
27
- return `
28
- declare module 'nuxt' {
29
- interface NuxtApp {
30
- $myPlugin: any;
31
- }
32
- }
33
- `;
34
- }
35
- };
36
-
37
- //#endregion
38
- export { pluginsDeclaration, templates_exports };