ssqch 0.7.1 → 0.8.0

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.
Files changed (153) hide show
  1. package/README.md +6 -4
  2. package/bin/ssqch.js +14 -48
  3. package/bundled/README.md +1247 -0
  4. package/bundled/completions/bash +840 -0
  5. package/bundled/completions/elvish +286 -0
  6. package/bundled/completions/fish +182 -0
  7. package/bundled/completions/powershell +318 -0
  8. package/bundled/completions/zsh +510 -0
  9. package/bundled/ssqch.d.ts +532 -0
  10. package/bundled/starter/engines/index.edge +11 -0
  11. package/bundled/starter/engines/index.ejs +11 -0
  12. package/bundled/starter/engines/index.hbs +11 -0
  13. package/bundled/starter/engines/index.liquid +11 -0
  14. package/bundled/starter/engines/layout.edge +35 -0
  15. package/bundled/starter/engines/layout.ejs +35 -0
  16. package/bundled/starter/engines/layout.hbs +35 -0
  17. package/bundled/starter/engines/layout.liquid +35 -0
  18. package/bundled/starter/gitignore +3 -0
  19. package/bundled/starter/jsconfig.json +11 -0
  20. package/bundled/starter/src/404.md +8 -0
  21. package/bundled/starter/src/_blueprints/posts.md +5 -0
  22. package/bundled/starter/src/_data/site.json +4 -0
  23. package/bundled/starter/src/_includes/layout.jinja +35 -0
  24. package/bundled/starter/src/index.jinja +11 -0
  25. package/bundled/starter/src/posts/i-know-what-i-saw.md +11 -0
  26. package/bundled/starter/src/posts/posts.json +4 -0
  27. package/bundled/starter/src/posts/raiders-of-the-lost-path.md +27 -0
  28. package/bundled/starter/src/posts/the-cache-of-the-wild.md +26 -0
  29. package/bundled/starter/src/posts/the-stump-has-moved.md +15 -0
  30. package/bundled/starter/src/posts/upon-further-review-a-stump.md +18 -0
  31. package/bundled/starter/ssqch.config.js +29 -0
  32. package/bundled/starter-docs/engines/edge/base.edge +41 -0
  33. package/bundled/starter-docs/engines/edge/containers/details.edge +5 -0
  34. package/bundled/starter-docs/engines/edge/containers/tab.edge +4 -0
  35. package/bundled/starter-docs/engines/edge/containers/tabs.edge +5 -0
  36. package/bundled/starter-docs/engines/edge/doc.edge +59 -0
  37. package/bundled/starter-docs/engines/edge/hooks/heading.edge +2 -0
  38. package/bundled/starter-docs/engines/ejs/base.ejs +41 -0
  39. package/bundled/starter-docs/engines/ejs/containers/details.ejs +5 -0
  40. package/bundled/starter-docs/engines/ejs/containers/tab.ejs +4 -0
  41. package/bundled/starter-docs/engines/ejs/containers/tabs.ejs +5 -0
  42. package/bundled/starter-docs/engines/ejs/doc.ejs +59 -0
  43. package/bundled/starter-docs/engines/ejs/hooks/heading.ejs +2 -0
  44. package/bundled/starter-docs/engines/hbs/base.hbs +41 -0
  45. package/bundled/starter-docs/engines/hbs/containers/details.hbs +5 -0
  46. package/bundled/starter-docs/engines/hbs/containers/tab.hbs +4 -0
  47. package/bundled/starter-docs/engines/hbs/containers/tabs.hbs +5 -0
  48. package/bundled/starter-docs/engines/hbs/doc.hbs +58 -0
  49. package/bundled/starter-docs/engines/hbs/hooks/heading.hbs +2 -0
  50. package/bundled/starter-docs/engines/liquid/base.liquid +41 -0
  51. package/bundled/starter-docs/engines/liquid/containers/details.liquid +5 -0
  52. package/bundled/starter-docs/engines/liquid/containers/tab.liquid +4 -0
  53. package/bundled/starter-docs/engines/liquid/containers/tabs.liquid +5 -0
  54. package/bundled/starter-docs/engines/liquid/doc.liquid +60 -0
  55. package/bundled/starter-docs/engines/liquid/hooks/heading.liquid +2 -0
  56. package/bundled/starter-docs/gitignore +4 -0
  57. package/bundled/starter-docs/src/404.md +12 -0
  58. package/bundled/starter-docs/src/_blueprints/docs.md +5 -0
  59. package/bundled/starter-docs/src/_data/nav.yml +10 -0
  60. package/bundled/starter-docs/src/_data/site.json +5 -0
  61. package/bundled/starter-docs/src/_includes/base.jinja +41 -0
  62. package/bundled/starter-docs/src/_includes/containers/details.jinja +5 -0
  63. package/bundled/starter-docs/src/_includes/containers/tab.jinja +4 -0
  64. package/bundled/starter-docs/src/_includes/containers/tabs.jinja +5 -0
  65. package/bundled/starter-docs/src/_includes/doc.jinja +59 -0
  66. package/bundled/starter-docs/src/_includes/hooks/heading.jinja +2 -0
  67. package/bundled/starter-docs/src/assets/docs.css +257 -0
  68. package/bundled/starter-docs/src/assets/docs.js +67 -0
  69. package/bundled/starter-docs/src/docs/docs.json +1 -0
  70. package/bundled/starter-docs/src/docs/guides/deploying.md +77 -0
  71. package/bundled/starter-docs/src/docs/guides/writing.md +65 -0
  72. package/bundled/starter-docs/src/docs/index.md +29 -0
  73. package/bundled/starter-docs/src/docs/install.md +42 -0
  74. package/bundled/starter-docs/src/index.md +13 -0
  75. package/bundled/starter-docs/ssqch.config.js +40 -0
  76. package/bundled/trailheads/from-component-frameworks.md +116 -0
  77. package/bundled/trailheads/from-docusaurus.md +55 -0
  78. package/bundled/trailheads/from-eleventy.md +140 -0
  79. package/bundled/trailheads/from-hexo.md +92 -0
  80. package/bundled/trailheads/from-mkdocs.md +45 -0
  81. package/bundled/trailheads/from-zola.md +71 -0
  82. package/lib/assets.js +235 -3
  83. package/lib/chunk-37KSIVNY.js +29 -0
  84. package/lib/chunk-3GYLOC6Y.js +1017 -0
  85. package/lib/chunk-3NYSSA2C.js +22 -0
  86. package/lib/chunk-3PHCFZEU.js +209 -0
  87. package/lib/chunk-4Q6WMTER.js +32 -0
  88. package/lib/chunk-6XYSFG6V.js +4423 -0
  89. package/lib/chunk-6XYSFG6V.js.LEGAL.txt +41 -0
  90. package/lib/chunk-AD3HAW3W.js +10 -0
  91. package/lib/chunk-AMBFWPZ4.js +118 -0
  92. package/lib/chunk-BOBPVAX2.js +37088 -0
  93. package/lib/chunk-BOBPVAX2.js.LEGAL.txt +27 -0
  94. package/lib/chunk-BRK4MXXO.js +565 -0
  95. package/lib/chunk-C35KIPAR.js +247 -0
  96. package/lib/chunk-CDEPYU7W.js +25 -0
  97. package/lib/chunk-CMUWRPSQ.js +113 -0
  98. package/lib/chunk-DDV6JEC2.js +46 -0
  99. package/lib/chunk-DHHQKW4F.js +71 -0
  100. package/lib/chunk-EIT4ZDT4.js +1485 -0
  101. package/lib/chunk-EZZUUPI4.js +20 -0
  102. package/lib/chunk-F65YUXZ7.js +334 -0
  103. package/lib/chunk-FVZ5JBRI.js +115 -0
  104. package/lib/chunk-FYGE634X.js +44 -0
  105. package/lib/chunk-GOE4ZSAB.js +75 -0
  106. package/lib/chunk-GSKVRAHF.js +44 -0
  107. package/lib/chunk-HR2RU2LY.js +999 -0
  108. package/lib/chunk-HXCLCXRT.js +20 -0
  109. package/lib/chunk-I3PS26CI.js +48 -0
  110. package/lib/chunk-IAFM5ITE.js +11 -0
  111. package/lib/chunk-IRHRK7XB.js +54 -0
  112. package/lib/chunk-JRT7TQQP.js +57 -0
  113. package/lib/chunk-JSPSMIJ2.js +217 -0
  114. package/lib/chunk-KBGE5MCY.js +175 -0
  115. package/lib/chunk-N5QTGQ5N.js +207 -0
  116. package/lib/chunk-NKXEPHRZ.js +136 -0
  117. package/lib/chunk-NUKCUDC4.js +146 -0
  118. package/lib/chunk-RI2L3VGO.js +376 -0
  119. package/lib/chunk-TDGBQNGW.js +251 -0
  120. package/lib/chunk-TN6EEDX2.js +3935 -0
  121. package/lib/chunk-TWCVHOKO.js +1229 -0
  122. package/lib/chunk-UGEGUUBT.js +29 -0
  123. package/lib/chunk-UU43WIZG.js +29 -0
  124. package/lib/chunk-VJWQSYEG.js +119 -0
  125. package/lib/chunk-VVPZ5PDP.js +160 -0
  126. package/lib/chunk-WMOVCQO6.js +1287 -0
  127. package/lib/chunk-WP3RPVUM.js +211 -0
  128. package/lib/chunk-YSH2NMIE.js +502 -0
  129. package/lib/cli.js +540 -0
  130. package/lib/elements.js +180 -3
  131. package/lib/image.js +27 -3
  132. package/lib/links.js +464 -3
  133. package/lib/minify.js +69 -3
  134. package/lib/redirects.js +152 -3
  135. package/lib/rss.js +139 -3
  136. package/lib/sass.js +221 -3
  137. package/lib/sitemap.js +88 -3
  138. package/lib/ssqch.js +28 -0
  139. package/package.json +83 -80
  140. package/src/serve/live.js +174 -0
  141. package/src/serve/not-found.html +31 -0
  142. package/types/globals.d.ts +3 -2
  143. package/types/image.d.ts +7 -3
  144. package/types/index.d.ts +18 -5
  145. package/types/links.d.ts +1 -1
  146. package/types/minify.d.ts +1 -1
  147. package/types/rss.d.ts +1 -1
  148. package/types/sass.d.ts +1 -1
  149. package/wasm/markdown.wasm +0 -0
  150. package/wasm/minify.wasm +0 -0
  151. package/wasm/sass.wasm +0 -0
  152. package/lib/index.js +0 -3
  153. package/platforms.json +0 -6
@@ -0,0 +1,247 @@
1
+ import { createRequire as __ssqchCreateRequire } from "node:module";
2
+ const require = __ssqchCreateRequire(import.meta.url);
3
+ import {
4
+ BuildError
5
+ } from "./chunk-6XYSFG6V.js";
6
+ import {
7
+ realPath
8
+ } from "./chunk-VJWQSYEG.js";
9
+
10
+ // src/modules.ts
11
+ import fs from "node:fs";
12
+ import path from "node:path";
13
+ import { execFileSync } from "node:child_process";
14
+ import os from "node:os";
15
+ import { registerHooks } from "node:module";
16
+ import { fileURLToPath, pathToFileURL } from "node:url";
17
+ var SELF = path.dirname(path.dirname(fileURLToPath(new URL("../src/modules.ts", import.meta.url).href)));
18
+ var BUILT_IN = ["ssqch/image", "ssqch/rss", "ssqch/assets", "ssqch/links", "ssqch/sitemap", "ssqch/redirects", "ssqch/sass", "ssqch/elements", "ssqch/minify"];
19
+ var COMPILED = fs.existsSync(path.join(SELF, "lib", "ssqch.js"));
20
+ var API = COMPILED ? pathToFileURL(path.join(SELF, "lib", "ssqch.js")).href : new URL("./exports/ssqch.ts", new URL("../src/modules.ts", import.meta.url).href).href;
21
+ var builtInUrl = (specifier) => COMPILED ? pathToFileURL(path.join(SELF, "lib", `${specifier.slice(6)}.js`)) : new URL(`./exports/${specifier.slice(6)}.ts`, new URL("../src/modules.ts", import.meta.url).href);
22
+ var loadedFiles = /* @__PURE__ */ new Set();
23
+ var isSiteUrl = (url) => {
24
+ if (!url?.startsWith("file:")) return false;
25
+ const file = fileURLToPath(url);
26
+ return !file.startsWith(SELF + path.sep) && !file.split(path.sep).includes("node_modules");
27
+ };
28
+ var ENDINGS = [".js", ".mjs", ".cjs", ".ts", ".mts", ".json", "/index.js", "/index.mjs", "/index.cjs", "/index.ts"];
29
+ var hooked = false;
30
+ function hookModules() {
31
+ if (hooked) return;
32
+ hooked = true;
33
+ const note = (resolved) => {
34
+ if (isSiteUrl(resolved.url)) loadedFiles.add(fileURLToPath(resolved.url));
35
+ return resolved;
36
+ };
37
+ registerHooks({
38
+ resolve(specifier, context, next) {
39
+ return note(resolveFor(specifier, context, next));
40
+ }
41
+ });
42
+ function resolveFor(...[specifier, context, next]) {
43
+ if (specifier.startsWith("file:") && specifier.endsWith(FORCE_ESM)) return { ...next(specifier, context), format: "module" };
44
+ if (specifier === "ssqch") return { url: API, shortCircuit: true };
45
+ if (specifier.startsWith("ssqch/")) {
46
+ const url = builtInUrl(specifier);
47
+ if (BUILT_IN.includes(specifier) && fs.existsSync(url)) return { url: url.href, shortCircuit: true };
48
+ }
49
+ const fromSite = isSiteUrl(context.parentURL);
50
+ const attempt = (name) => {
51
+ if (fromSite && /\.json(\?.*)?$/i.test(name) && !context.importAttributes?.type) {
52
+ const importAttributes = { ...context.importAttributes, type: "json" };
53
+ return { ...next(name, { ...context, importAttributes }), importAttributes };
54
+ }
55
+ return next(name, context);
56
+ };
57
+ try {
58
+ return attempt(specifier);
59
+ } catch (e) {
60
+ const relative = specifier.startsWith("./") || specifier.startsWith("../") || path.isAbsolute(specifier) || specifier.startsWith("file:");
61
+ if (!fromSite || !relative || !["ERR_MODULE_NOT_FOUND", "ERR_UNSUPPORTED_DIR_IMPORT"].includes(e?.code)) throw e;
62
+ const [bare, query = ""] = specifier.split(/(?=\?)/, 2);
63
+ for (const ending of ENDINGS) {
64
+ try {
65
+ return attempt(bare.replace(/\/$/, "") + ending + query);
66
+ } catch {
67
+ }
68
+ }
69
+ throw e;
70
+ }
71
+ }
72
+ }
73
+ var versions = /* @__PURE__ */ new Map();
74
+ async function importFile(file) {
75
+ hookModules();
76
+ const mtimeMs = fs.statSync(file).mtimeMs;
77
+ let entry = versions.get(file);
78
+ if (!entry) versions.set(file, entry = { mtimeMs, version: 0 });
79
+ else if (entry.mtimeMs !== mtimeMs) {
80
+ entry.mtimeMs = mtimeMs;
81
+ entry.version++;
82
+ }
83
+ const url = pathToFileURL(file).href + (entry.version ? `?v=${entry.version}` : "");
84
+ try {
85
+ return await watchSettle(import(url));
86
+ } catch (e) {
87
+ if (!(e instanceof SyntaxError) || !failedAsCommonJS(e, file) || !MODULE_SYNTAX.test(fs.readFileSync(file, "utf8"))) throw e;
88
+ return watchSettle(import(url + (url.includes("?") ? "&" : "?") + FORCE_ESM));
89
+ }
90
+ }
91
+ var FORCE_ESM = "ssqch-esm";
92
+ var MODULE_SYNTAX = /(?:^|[;{}()\s])(?:export\s|import\s*[\w{*'"]|import\.meta)/m;
93
+ function failedAsCommonJS(e, file) {
94
+ const named = /^(.+):\d+\r?\n/.exec(e.stack ?? "")?.[1];
95
+ return named !== void 0 && (named === file || named === realPath(file));
96
+ }
97
+ var waiting = [];
98
+ var watching = false;
99
+ function watchSettle(promise) {
100
+ if (!watching) {
101
+ watching = true;
102
+ process.on("beforeExit", () => {
103
+ const reject = waiting.pop();
104
+ reject?.(new BuildError("a Promise never settled (nothing was left to resolve it: no timers or requests were pending)"));
105
+ });
106
+ }
107
+ return new Promise((resolve, reject) => {
108
+ waiting.push(reject);
109
+ const done = () => {
110
+ const i = waiting.lastIndexOf(reject);
111
+ if (i !== -1) waiting.splice(i, 1);
112
+ };
113
+ promise.then((v) => {
114
+ done();
115
+ resolve(v);
116
+ }, (e) => {
117
+ done();
118
+ reject(e);
119
+ });
120
+ });
121
+ }
122
+ function settle(value) {
123
+ return value instanceof Promise ? watchSettle(value) : value;
124
+ }
125
+ function shownPath(file, root) {
126
+ const rel = path.relative(realPath(root), realPath(file));
127
+ return rel.startsWith("..") || path.isAbsolute(rel) ? file : rel.split(path.sep).join("/");
128
+ }
129
+ function describeThrown(e, root) {
130
+ if (e instanceof BuildError) return e.message;
131
+ if (!(e instanceof Error)) return `uncaught ${typeof e === "string" ? e : safeString(e)}`;
132
+ const message = packageMessage(e, root) ?? e.message;
133
+ const frames = e instanceof SyntaxError ? syntaxFrames(e, root) : [];
134
+ frames.push(...siteFrames(e.stack ?? "", root));
135
+ return frames.length ? `${message}
136
+ ${frames.join("\n")}` : message;
137
+ }
138
+ function packageMessage(e, root) {
139
+ const code = e.code;
140
+ const notInstalled = (name) => `package "${name}" isn't installed (no node_modules/${name} folder here or in a parent folder; run npm install)`;
141
+ const packageOf = (specifier) => specifier.split("/").slice(0, specifier.startsWith("@") ? 2 : 1).join("/");
142
+ if (code === "ERR_MODULE_NOT_FOUND") {
143
+ const found = /^Cannot find package '([^']+)'/.exec(e.message);
144
+ if (found) return notInstalled(packageOf(found[1]));
145
+ }
146
+ if (code === "MODULE_NOT_FOUND") {
147
+ const found = /^Cannot find module '([^']+)'\nRequire stack:\n- ([^\n]+)/.exec(e.message);
148
+ if (found) {
149
+ const [, specifier, from] = found;
150
+ const bare = !specifier.startsWith(".") && !path.isAbsolute(specifier);
151
+ return `Cannot find module '${specifier}' from '${shownPath(from, root)}': ${bare ? notInstalled(packageOf(specifier)) : "file not found"}`;
152
+ }
153
+ }
154
+ if (code === "ERR_PACKAGE_PATH_NOT_EXPORTED") {
155
+ const found = /^Package subpath '([^']+)' is not defined by "exports" in (.+?)[\\/]package\.json/.exec(e.message);
156
+ if (found) {
157
+ const name = found[2].split(/[\\/]node_modules[\\/]/).pop().replaceAll("\\", "/");
158
+ const required = /\n\s+at (?:Module\.)?require \(/.test(e.stack ?? "") || /\n\s+at Module\._resolveFilename/.test(e.stack ?? "");
159
+ return `package "${name}" doesn't export "${found[1]}" for ${required ? "require" : "import"} (see the "exports" in its package.json)`;
160
+ }
161
+ }
162
+ return void 0;
163
+ }
164
+ var safeString = (v) => {
165
+ try {
166
+ return String(v);
167
+ } catch {
168
+ return "a non-Error value";
169
+ }
170
+ };
171
+ function frameOf(line) {
172
+ const at = /^\s+at /.exec(line);
173
+ if (!at) return void 0;
174
+ let rest = line.slice(at[0].length);
175
+ let name;
176
+ if (rest.endsWith(")")) {
177
+ let depth = 0;
178
+ let open = -1;
179
+ for (let i = rest.length - 1; i >= 0; i--) {
180
+ if (rest[i] === ")") depth++;
181
+ else if (rest[i] === "(" && --depth === 0) {
182
+ open = i;
183
+ break;
184
+ }
185
+ }
186
+ if (open <= 0 || rest[open - 1] !== " ") return void 0;
187
+ name = rest.slice(0, open - 1);
188
+ rest = rest.slice(open + 1, -1);
189
+ }
190
+ const place = /^((?:file:\/\/|\/|[A-Za-z]:[\\/]).*?):(\d+):(\d+)$/.exec(rest);
191
+ return place ? [name, place[1], place[2], place[3]] : void 0;
192
+ }
193
+ function siteFrames(stack, root) {
194
+ const out = [];
195
+ for (const line of stack.split("\n")) {
196
+ const found = frameOf(line);
197
+ if (!found) continue;
198
+ const [name, where, row, column] = found;
199
+ let file;
200
+ try {
201
+ file = where.startsWith("file:") ? fileURLToPath(where.split("?")[0]) : where;
202
+ } catch {
203
+ continue;
204
+ }
205
+ if (file.startsWith(SELF + path.sep)) continue;
206
+ const plain = name?.replace(/^async /, "").replace(/ \[as [^\]]+\]$/, "").replace(/^(Object|Module)\./, "");
207
+ out.push(` at ${plain || "<anonymous>"} (${shownPath(file, root)}:${row}:${column})`);
208
+ }
209
+ return out;
210
+ }
211
+ function syntaxFrames(e, root) {
212
+ const first = /^(.+):(\d+)\n/.exec(e.stack ?? "");
213
+ if (first && fs.existsSync(first[1])) return [` at ${shownPath(first[1], root)}:${first[2]}:1`];
214
+ let tmp;
215
+ try {
216
+ tmp = fs.mkdtempSync(path.join(os.tmpdir(), "ssqch-check-"));
217
+ for (const file of [...loadedFiles].reverse().slice(0, 8)) {
218
+ const ext = /\.(m|c)?ts$/.test(file) ? ".mts" : ".mjs";
219
+ const copy = path.join(tmp, `check${ext}`);
220
+ fs.copyFileSync(file, copy);
221
+ try {
222
+ execFileSync(process.execPath, ["--check", copy], { stdio: ["ignore", "ignore", "pipe"], encoding: "utf8", timeout: 2e4 });
223
+ } catch (failed) {
224
+ const lines = String(failed.stderr ?? "").split("\n");
225
+ const at = lines.findIndex((l) => /[\\/]check\.m[jt]s:\d+$/.test(l.trimEnd()));
226
+ const row = at === -1 ? void 0 : /:(\d+)$/.exec(lines[at].trimEnd())?.[1];
227
+ if (row === void 0) continue;
228
+ const caret = lines[at + 2]?.indexOf("^") ?? -1;
229
+ return [` at ${shownPath(file, root)}:${row}:${caret === -1 ? 1 : caret + 1}`];
230
+ }
231
+ }
232
+ } catch {
233
+ } finally {
234
+ if (tmp) fs.rmSync(tmp, { recursive: true, force: true });
235
+ }
236
+ return [];
237
+ }
238
+
239
+ export {
240
+ loadedFiles,
241
+ hookModules,
242
+ importFile,
243
+ watchSettle,
244
+ settle,
245
+ shownPath,
246
+ describeThrown
247
+ };
@@ -0,0 +1,25 @@
1
+ import { createRequire as __ssqchCreateRequire } from "node:module";
2
+ const require = __ssqchCreateRequire(import.meta.url);
3
+ import {
4
+ DEFAULT_ENGINE,
5
+ ENGINES,
6
+ STARTERS,
7
+ agentsMd,
8
+ runInit,
9
+ starterEngines,
10
+ starterFiles,
11
+ write
12
+ } from "./chunk-WP3RPVUM.js";
13
+ import "./chunk-6XYSFG6V.js";
14
+ import "./chunk-VJWQSYEG.js";
15
+ import "./chunk-I3PS26CI.js";
16
+ export {
17
+ DEFAULT_ENGINE,
18
+ ENGINES,
19
+ STARTERS,
20
+ agentsMd,
21
+ runInit,
22
+ starterEngines,
23
+ starterFiles,
24
+ write
25
+ };
@@ -0,0 +1,113 @@
1
+ import { createRequire as __ssqchCreateRequire } from "node:module";
2
+ const require = __ssqchCreateRequire(import.meta.url);
3
+
4
+ // src/quote.ts
5
+ var UNPRINTABLE = /[\p{Cc}\p{Cf}\p{Cs}\p{Co}\p{Cn}\p{Zl}\p{Zp}\p{Zs}\p{Grapheme_Extend}]/u;
6
+ function escaped(c, quote) {
7
+ switch (c) {
8
+ case "\0":
9
+ return "\\0";
10
+ case " ":
11
+ return "\\t";
12
+ case "\r":
13
+ return "\\r";
14
+ case "\n":
15
+ return "\\n";
16
+ case "\\":
17
+ return "\\\\";
18
+ case quote:
19
+ return `\\${quote}`;
20
+ case " ":
21
+ return " ";
22
+ }
23
+ return UNPRINTABLE.test(c) ? `\\u{${c.codePointAt(0).toString(16)}}` : c;
24
+ }
25
+ function quoted(text) {
26
+ let out = '"';
27
+ if (/^[\x20-\x7e]*$/.test(text) && !/["\\]/.test(text)) return `"${text}"`;
28
+ for (const c of text) out += escaped(c, '"');
29
+ return out + '"';
30
+ }
31
+ function quotedChar(c) {
32
+ return `'${escaped(c, "'")}'`;
33
+ }
34
+ var charCount = (text) => {
35
+ let n = 0;
36
+ for (const _ of text) n++;
37
+ return n;
38
+ };
39
+ var padEnd = (text, width) => text + " ".repeat(Math.max(0, width - charCount(text)));
40
+ var padStart = (text, width) => " ".repeat(Math.max(0, width - charCount(text))) + text;
41
+ function firstChars(text, n) {
42
+ if (text.length <= n) return text;
43
+ let out = "";
44
+ let i = 0;
45
+ for (const c of text) {
46
+ if (i++ === n) break;
47
+ out += c;
48
+ }
49
+ return out;
50
+ }
51
+ function jsString(value) {
52
+ if (value instanceof Date) return Number.isNaN(value.getTime()) ? "Invalid Date" : value.toISOString();
53
+ if (Array.isArray(value)) return value.map((v) => v === void 0 || v === null ? "" : jsString(v)).join(",");
54
+ if (typeof value === "function") return "function () { [native code] }";
55
+ if (value !== null && typeof value === "object") return "[object Object]";
56
+ return String(value);
57
+ }
58
+ function serdeFloat(x) {
59
+ if (x === 0) return Object.is(x, -0) ? "-0.0" : "0.0";
60
+ const [mantissa, e] = x.toExponential().split("e");
61
+ const exp = Number(e);
62
+ const sign = x < 0 ? "-" : "";
63
+ const digits = mantissa.replace(/^-/, "").replace(".", "");
64
+ if (exp < -5 || exp > 15) return `${sign}${digits[0]}${digits.length > 1 ? `.${digits.slice(1)}` : ""}e${exp < 0 ? "-" : "+"}${Math.abs(exp)}`;
65
+ if (exp < 0) return `${sign}0.${"0".repeat(-exp - 1)}${digits}`;
66
+ return `${sign}${digits.slice(0, exp + 1).padEnd(exp + 1, "0")}.${digits.slice(exp + 1) || "0"}`;
67
+ }
68
+ function prettyJson(value, indent = "") {
69
+ if (typeof value === "number") return !Number.isFinite(value) ? "null" : Number.isInteger(value) && Math.abs(value) < 9e15 ? String(value) : serdeFloat(value);
70
+ if (value === null || typeof value !== "object") return JSON.stringify(value) ?? "null";
71
+ const inner = indent + " ";
72
+ if (Array.isArray(value)) return value.length ? `[
73
+ ${value.map((v) => inner + prettyJson(v, inner)).join(",\n")}
74
+ ${indent}]` : "[]";
75
+ const entries = Object.entries(value).filter(([, v]) => v !== void 0);
76
+ return entries.length ? `{
77
+ ${entries.map(([k, v]) => `${inner}${JSON.stringify(k)}: ${prettyJson(v, inner)}`).join(",\n")}
78
+ ${indent}}` : "{}";
79
+ }
80
+ function toJsonValue(value, above = /* @__PURE__ */ new Set()) {
81
+ if (value === void 0 || value === null || typeof value === "function" || typeof value === "symbol") return null;
82
+ if (typeof value === "number") return Number.isFinite(value) ? value : null;
83
+ if (typeof value === "bigint") return Number(value);
84
+ if (typeof value !== "object") return value;
85
+ if (value instanceof Date) return Number.isNaN(value.getTime()) ? null : value.toISOString();
86
+ if (above.has(value)) return null;
87
+ above.add(value);
88
+ let out;
89
+ if (Array.isArray(value)) out = value.map((v) => toJsonValue(v, above));
90
+ else {
91
+ const obj = {};
92
+ for (const [key, v] of Object.entries(value)) {
93
+ if (v === void 0 || typeof v === "function" || typeof v === "symbol") continue;
94
+ obj[key] = toJsonValue(v, above);
95
+ }
96
+ out = obj;
97
+ }
98
+ above.delete(value);
99
+ return out;
100
+ }
101
+
102
+ export {
103
+ quoted,
104
+ quotedChar,
105
+ charCount,
106
+ padEnd,
107
+ padStart,
108
+ firstChars,
109
+ jsString,
110
+ serdeFloat,
111
+ prettyJson,
112
+ toJsonValue
113
+ };
@@ -0,0 +1,46 @@
1
+ import { createRequire as __ssqchCreateRequire } from "node:module";
2
+ const require = __ssqchCreateRequire(import.meta.url);
3
+ import {
4
+ slashes
5
+ } from "./chunk-VJWQSYEG.js";
6
+
7
+ // src/dirs.ts
8
+ import fs from "node:fs";
9
+ import path from "node:path";
10
+ var CONFIG_FILES = ["ssqch.config.js", "ssqch.config.mjs", "ssqch.config.cjs", "ssqch.config.ts", "ssqch.config.mts"];
11
+ function dirsOf(config) {
12
+ const input = path.resolve(config.root, config.input);
13
+ return {
14
+ root: config.root,
15
+ input,
16
+ output: path.resolve(config.root, config.output),
17
+ includes: path.resolve(input, config.includes),
18
+ layouts: path.resolve(input, config.layouts ?? config.includes),
19
+ data: path.resolve(input, config.data)
20
+ };
21
+ }
22
+ function shownDir(config, configured) {
23
+ if (path.isAbsolute(configured)) return configured;
24
+ const base = fs.existsSync(config.root) ? config.root : config.rootGiven;
25
+ return /[\\/]$/.test(base) ? base + configured : base + path.sep + configured;
26
+ }
27
+ function shownOutput(config, native = false) {
28
+ const output = path.resolve(config.root, config.output);
29
+ const inside = output === config.root || output.startsWith(config.root + path.sep);
30
+ const shown = path.isAbsolute(config.output) && !inside ? output : path.relative(config.root, output);
31
+ return native ? shown : slashes(shown);
32
+ }
33
+ function parseEnvironment(s) {
34
+ const name = s.toLowerCase();
35
+ if (name === "dev" || name === "development") return "development";
36
+ if (name === "prod" || name === "production") return "production";
37
+ return void 0;
38
+ }
39
+
40
+ export {
41
+ CONFIG_FILES,
42
+ dirsOf,
43
+ shownDir,
44
+ shownOutput,
45
+ parseEnvironment
46
+ };
@@ -0,0 +1,71 @@
1
+ import { createRequire as __ssqchCreateRequire } from "node:module";
2
+ const require = __ssqchCreateRequire(import.meta.url);
3
+ import {
4
+ types,
5
+ write
6
+ } from "./chunk-WP3RPVUM.js";
7
+ import {
8
+ loadConfig,
9
+ schemaTypes
10
+ } from "./chunk-TN6EEDX2.js";
11
+ import "./chunk-IRHRK7XB.js";
12
+ import "./chunk-NKXEPHRZ.js";
13
+ import "./chunk-AD3HAW3W.js";
14
+ import "./chunk-DDV6JEC2.js";
15
+ import "./chunk-EIT4ZDT4.js";
16
+ import "./chunk-FVZ5JBRI.js";
17
+ import "./chunk-TDGBQNGW.js";
18
+ import "./chunk-UU43WIZG.js";
19
+ import "./chunk-C35KIPAR.js";
20
+ import "./chunk-CMUWRPSQ.js";
21
+ import {
22
+ messageOf,
23
+ red
24
+ } from "./chunk-6XYSFG6V.js";
25
+ import "./chunk-VJWQSYEG.js";
26
+ import "./chunk-I3PS26CI.js";
27
+
28
+ // src/commands/types.ts
29
+ import path from "node:path";
30
+ function schemaDeclarations(schemas) {
31
+ if (schemas.length === 0) return "";
32
+ let out = '\n// This site\'s `schemas`. Run `ssqch types` again after changing them.\ndeclare module "ssqch" {\n interface Schemas {\n';
33
+ for (const [name, typescript] of schemas) {
34
+ const plain = /^[A-Za-z0-9_]+$/.test(name) && !/^\d/.test(name);
35
+ out += ` ${plain ? name : JSON.stringify(name)}: ${typescript};
36
+ `;
37
+ }
38
+ return out + " }\n}\n";
39
+ }
40
+ async function runTypes(options) {
41
+ const { root } = options;
42
+ const out = root !== void 0 && !path.isAbsolute(options.out) ? /[\\/]$/.test(root) ? root + options.out : root + path.sep + options.out : options.out;
43
+ const file = path.resolve(out);
44
+ let text = types();
45
+ let schemas = 0;
46
+ try {
47
+ const env = "development";
48
+ const config = await loadConfig({ root: root ?? ".", env, quiet: true });
49
+ const found = await schemaTypes(config);
50
+ schemas = found.length;
51
+ text += schemaDeclarations(found);
52
+ } catch (e) {
53
+ process.stderr.write(`warn: couldn't read the site's config, so its schemas aren't in the types: ${messageOf(e)}
54
+ `);
55
+ }
56
+ try {
57
+ write(file, text, out);
58
+ } catch (e) {
59
+ process.stderr.write(`${red("error:")} ${e.message}
60
+ `);
61
+ return 1;
62
+ }
63
+ const withSchemas = schemas === 0 ? "" : schemas === 1 ? " (with 1 schema)" : ` (with ${schemas} schemas)`;
64
+ process.stdout.write(`Wrote ${out}${withSchemas}. List it in jsconfig.json's "include" so editors pick it up.
65
+ `);
66
+ return 0;
67
+ }
68
+ export {
69
+ runTypes,
70
+ schemaDeclarations
71
+ };