silgi 0.25.12 → 0.25.13

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.
@@ -0,0 +1,59 @@
1
+ import fsp from 'node:fs/promises';
2
+ import consola, { consola as consola$1 } from 'consola';
3
+ import { relative, resolve, dirname } from 'pathe';
4
+ import { useSilgiCLI } from 'silgi';
5
+ import { colors } from 'consola/utils';
6
+ import { getProperty } from 'dot-prop';
7
+
8
+ function prettyPath(p, highlight = true) {
9
+ p = relative(process.cwd(), p);
10
+ return highlight ? colors.cyan(p) : p;
11
+ }
12
+ function resolveSilgiPath(path, silgiCLIOptions, base) {
13
+ if (typeof path !== "string") {
14
+ throw new TypeError(`Invalid path: ${path}`);
15
+ }
16
+ path = _compilePathTemplate(path)(silgiCLIOptions);
17
+ for (const base2 in silgiCLIOptions.alias) {
18
+ if (path.startsWith(base2)) {
19
+ path = silgiCLIOptions.alias[base2] + path.slice(base2.length);
20
+ }
21
+ }
22
+ return resolve(base || silgiCLIOptions.srcDir, path);
23
+ }
24
+ function _compilePathTemplate(contents) {
25
+ return (params) => contents.replace(/\{\{ ?([\w.]+) ?\}\}/g, (_, match) => {
26
+ const val = getProperty(params, match);
27
+ if (!val) {
28
+ consola.warn(
29
+ `cannot resolve template param '${match}' in ${contents.slice(0, 20)}`
30
+ );
31
+ }
32
+ return val || `${match}`;
33
+ });
34
+ }
35
+
36
+ async function writeFile(file, contents, log = false) {
37
+ const silgi = useSilgiCLI();
38
+ if (silgi.errors.length) {
39
+ return;
40
+ }
41
+ await fsp.mkdir(dirname(file), { recursive: true });
42
+ await fsp.writeFile(
43
+ file,
44
+ contents,
45
+ typeof contents === "string" ? "utf8" : void 0
46
+ );
47
+ if (log) {
48
+ consola$1.info("Generated", prettyPath(file));
49
+ }
50
+ }
51
+ async function isDirectory(path) {
52
+ try {
53
+ return (await fsp.stat(path)).isDirectory();
54
+ } catch {
55
+ return false;
56
+ }
57
+ }
58
+
59
+ export { isDirectory as i, prettyPath as p, resolveSilgiPath as r, writeFile as w };
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import { defineCommand, runMain } from 'citty';
3
3
 
4
- const version = "0.25.12";
4
+ const version = "0.25.13";
5
5
  const packageJson = {
6
6
  version: version};
7
7
 
package/dist/cli/init.mjs CHANGED
@@ -2,6 +2,12 @@ import { writeFileSync } from 'node:fs';
2
2
  import * as p from '@clack/prompts';
3
3
  import { defineCommand } from 'citty';
4
4
  import consola from 'consola';
5
+ import fsp from 'node:fs/promises';
6
+ import { dirname } from 'pathe';
7
+ import { w as writeFile } from '../_chunks/fs.mjs';
8
+ import 'silgi';
9
+ import 'consola/utils';
10
+ import 'dot-prop';
5
11
 
6
12
  const init = defineCommand({
7
13
  meta: {
@@ -58,7 +64,9 @@ const init = defineCommand({
58
64
  "})",
59
65
  ""
60
66
  ];
61
- writeFileSync("server/plugins/silgi.ts", plugin.join("\n"));
67
+ const file = "server/plugins/silgi.ts";
68
+ await fsp.mkdir(dirname(file), { recursive: true });
69
+ await writeFile(file, plugin.join("\n"));
62
70
  consola.success("Silgi plugin created, see server/plugins/silgi.ts");
63
71
  }
64
72
  writeFileSync("silgi.config.ts", context.join("\n"));
@@ -1,20 +1,21 @@
1
- import { tryUseSilgiCLI, useSilgiCLI, useSilgi } from 'silgi';
1
+ import { tryUseSilgiCLI, useSilgi, useSilgiCLI } from 'silgi';
2
2
  import { pathToFileURL, fileURLToPath } from 'node:url';
3
3
  import { resolvePath as resolvePath$1 } from 'mlly';
4
- import fsp from 'node:fs/promises';
5
- import consola, { consola as consola$1 } from 'consola';
6
- import { relative, resolve, dirname, normalize, isAbsolute, join, parse, basename } from 'pathe';
7
- import { colors } from 'consola/utils';
8
- import { getProperty } from 'dot-prop';
4
+ export { i as isDirectory, p as prettyPath, r as resolveSilgiPath, w as writeFile } from '../_chunks/fs.mjs';
9
5
  import { genString, genObjectFromRaw, genObjectFromValues, genObjectFromRawEntries } from 'knitwork';
10
6
  import { hash as hash$1 } from 'ohash';
11
7
  import { camelCase } from 'scule';
8
+ import { consola } from 'consola';
12
9
  import { defu } from 'defu';
13
10
  import { c as checkSilgiCompatibility } from '../cli/compatibility.mjs';
14
11
  import { withLeadingSlash } from 'ufo';
15
12
  import { existsSync, promises } from 'node:fs';
13
+ import { dirname, resolve, normalize, isAbsolute, join, relative, parse, basename } from 'pathe';
16
14
  import { resolveAlias as resolveAlias$1 } from 'pathe/utils';
17
15
  import { hash as hash$2 } from 'silgi/kit';
16
+ import 'node:fs/promises';
17
+ import 'consola/utils';
18
+ import 'dot-prop';
18
19
  import 'semver/functions/satisfies.js';
19
20
  import 'silgi/meta';
20
21
 
@@ -36,57 +37,6 @@ async function tryResolveModule(id, url = import.meta.url) {
36
37
  }
37
38
  }
38
39
 
39
- function prettyPath(p, highlight = true) {
40
- p = relative(process.cwd(), p);
41
- return highlight ? colors.cyan(p) : p;
42
- }
43
- function resolveSilgiPath(path, silgiCLIOptions, base) {
44
- if (typeof path !== "string") {
45
- throw new TypeError(`Invalid path: ${path}`);
46
- }
47
- path = _compilePathTemplate(path)(silgiCLIOptions);
48
- for (const base2 in silgiCLIOptions.alias) {
49
- if (path.startsWith(base2)) {
50
- path = silgiCLIOptions.alias[base2] + path.slice(base2.length);
51
- }
52
- }
53
- return resolve(base || silgiCLIOptions.srcDir, path);
54
- }
55
- function _compilePathTemplate(contents) {
56
- return (params) => contents.replace(/\{\{ ?([\w.]+) ?\}\}/g, (_, match) => {
57
- const val = getProperty(params, match);
58
- if (!val) {
59
- consola.warn(
60
- `cannot resolve template param '${match}' in ${contents.slice(0, 20)}`
61
- );
62
- }
63
- return val || `${match}`;
64
- });
65
- }
66
-
67
- async function writeFile(file, contents, log = false) {
68
- const silgi = useSilgiCLI();
69
- if (silgi.errors.length) {
70
- return;
71
- }
72
- await fsp.mkdir(dirname(file), { recursive: true });
73
- await fsp.writeFile(
74
- file,
75
- contents,
76
- typeof contents === "string" ? "utf8" : void 0
77
- );
78
- if (log) {
79
- consola$1.info("Generated", prettyPath(file));
80
- }
81
- }
82
- async function isDirectory$1(path) {
83
- try {
84
- return (await fsp.stat(path)).isDirectory();
85
- } catch {
86
- return false;
87
- }
88
- }
89
-
90
40
  const reservedCode = /* @__PURE__ */ new Set([
91
41
  "process",
92
42
  "global",
@@ -154,7 +104,7 @@ function isH3() {
154
104
  return false;
155
105
  }
156
106
 
157
- const logger = consola$1;
107
+ const logger = consola;
158
108
  function useLogger(tag, options = {}) {
159
109
  return tag ? logger.create(options).withTag(tag) : logger;
160
110
  }
@@ -526,4 +476,4 @@ function isValidIp(ip) {
526
476
  return false;
527
477
  }
528
478
 
529
- export { MODE_RE, addTemplate, baseHeaderBannerComment, createResolver, defineSilgiModule, defineSilgiPreset, directoryToURL, filterInPlace, genEnsureSafeVar, getAllEntries, getIpAddress, hasError, hasInstalledModule, hasSilgiModule, hash, ipAddress, isDirectory$1 as isDirectory, isH3, isNitro, isNuxt, normalizeTemplate, parseServices, prettyPath, processFilePath, relativeWithDot, resolveAlias, resolvePath, resolveSilgiModule, resolveSilgiPath, serviceParseModule, toArray, tryResolveModule, useLogger, useRequest, useResponse, writeFile };
479
+ export { MODE_RE, addTemplate, baseHeaderBannerComment, createResolver, defineSilgiModule, defineSilgiPreset, directoryToURL, filterInPlace, genEnsureSafeVar, getAllEntries, getIpAddress, hasError, hasInstalledModule, hasSilgiModule, hash, ipAddress, isH3, isNitro, isNuxt, normalizeTemplate, parseServices, processFilePath, relativeWithDot, resolveAlias, resolvePath, resolveSilgiModule, serviceParseModule, toArray, tryResolveModule, useLogger, useRequest, useResponse };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "silgi",
3
3
  "type": "module",
4
- "version": "0.25.12",
4
+ "version": "0.25.13",
5
5
  "private": false,
6
6
  "sideEffects": false,
7
7
  "exports": {