blogger-hbs 0.0.4 → 0.0.5
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.
- package/README.md +15 -123
- package/dist/cli/index.js +104 -29
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/stats.d.ts +58 -0
- package/dist/cli/stats.js +156 -0
- package/dist/cli/stats.js.map +1 -0
- package/dist/compiler/chunks.d.ts +3 -1
- package/dist/compiler/compile.d.ts +1 -1
- package/dist/compiler/compile.js +3 -3
- package/dist/compiler/compile.js.map +1 -1
- package/dist/compiler/dependencies.js +2 -1
- package/dist/compiler/dependencies.js.map +1 -1
- package/dist/compiler/errors.d.ts +8 -1
- package/dist/compiler/errors.js +4 -0
- package/dist/compiler/errors.js.map +1 -1
- package/dist/compiler/plugins.js +44 -24
- package/dist/compiler/plugins.js.map +1 -1
- package/dist/compiler/rsbuild.d.ts +2 -2
- package/dist/compiler/rsbuild.js +8 -2
- package/dist/compiler/rsbuild.js.map +1 -1
- package/dist/compiler/scan.d.ts +5 -1
- package/dist/compiler/scan.js +28 -11
- package/dist/compiler/scan.js.map +1 -1
- package/dist/compiler/validate.d.ts +3 -2
- package/dist/compiler/validate.js +16 -7
- package/dist/compiler/validate.js.map +1 -1
- package/dist/compiler/watch.d.ts +6 -3
- package/dist/compiler/watch.js +8 -2
- package/dist/compiler/watch.js.map +1 -1
- package/dist/index.d.ts +4 -3
- package/dist/index.js +2 -2
- package/dist/plugins/index.d.ts +19 -4
- package/dist/plugins/index.js +25 -4
- package/dist/plugins/index.js.map +1 -1
- package/dist/runtime/helpers/args.d.ts +26 -0
- package/dist/runtime/helpers/args.js +73 -0
- package/dist/runtime/helpers/args.js.map +1 -0
- package/dist/runtime/helpers/error.d.ts +10 -4
- package/dist/runtime/helpers/error.js +21 -11
- package/dist/runtime/helpers/error.js.map +1 -1
- package/dist/runtime/helpers/functions.d.ts +99 -9
- package/dist/runtime/helpers/functions.js +446 -64
- package/dist/runtime/helpers/functions.js.map +1 -1
- package/dist/runtime/helpers/index.d.ts +2 -2
- package/dist/runtime/helpers/index.js +2 -2
- package/dist/runtime/import.js +11 -9
- package/dist/runtime/import.js.map +1 -1
- package/dist/runtime/index.d.ts +3 -2
- package/dist/runtime/index.js +2 -2
- package/dist/runtime/render.d.ts +1 -1
- package/dist/runtime/render.js +43 -9
- package/dist/runtime/render.js.map +1 -1
- package/dist/runtime/tags.js +7 -6
- package/dist/runtime/tags.js.map +1 -1
- package/dist/xml/expressions.js +48 -17
- package/dist/xml/expressions.js.map +1 -1
- package/dist/xml/format.d.ts +23 -16
- package/dist/xml/format.js +128 -144
- package/dist/xml/format.js.map +1 -1
- package/dist/xml/index.d.ts +3 -2
- package/dist/xml/index.js +2 -2
- package/dist/xml/info.d.ts +30 -0
- package/dist/xml/info.js +46 -0
- package/dist/xml/info.js.map +1 -0
- package/dist/xml/layout.d.ts +39 -0
- package/dist/xml/layout.js +245 -0
- package/dist/xml/layout.js.map +1 -0
- package/dist/xml/process.d.ts +40 -0
- package/dist/xml/process.js +176 -0
- package/dist/xml/process.js.map +1 -0
- package/dist/xml/scanner.d.ts +37 -1
- package/dist/xml/scanner.js +255 -97
- package/dist/xml/scanner.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -8,7 +8,8 @@ Build Blogger themes from Handlebars templates, with bundled scripts and styles.
|
|
|
8
8
|
- Split a theme into templates with `{{import "./header.hbs"}}`, data with `{{import "./data.json"}}`.
|
|
9
9
|
- Import scripts and styles, bundled with [Rsbuild](https://rsbuild.rs) and inlined: `{{import "./main.ts"}}`.
|
|
10
10
|
- Every template is validated as XML, and the rendered theme is validated and formatted as Blogger saves it.
|
|
11
|
-
-
|
|
11
|
+
- Plugins provide partials, data and helpers, bundled into the theme.
|
|
12
|
+
- The compiled theme renders in any JavaScript runtime, a Cloudflare Worker too, with `blogger-hbs/runtime`.
|
|
12
13
|
|
|
13
14
|
## Usage
|
|
14
15
|
|
|
@@ -18,12 +19,12 @@ pnpm add -D blogger-hbs
|
|
|
18
19
|
|
|
19
20
|
```ts
|
|
20
21
|
// blogger-hbs.config.ts
|
|
21
|
-
import { defineConfig } from
|
|
22
|
+
import { defineConfig } from "blogger-hbs";
|
|
22
23
|
|
|
23
24
|
export default defineConfig({
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
entry: "src/index.hbs",
|
|
26
|
+
alias: { "~": "src" },
|
|
27
|
+
context: {},
|
|
27
28
|
});
|
|
28
29
|
```
|
|
29
30
|
|
|
@@ -35,122 +36,13 @@ blogger-hbs --help # all the options
|
|
|
35
36
|
|
|
36
37
|
The same is available from JavaScript with `compileTemplate`, `watchTemplate` and `renderTemplate`.
|
|
37
38
|
|
|
38
|
-
##
|
|
39
|
+
## Documentation
|
|
39
40
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
const renderer = createRenderer(theme);
|
|
49
|
-
|
|
50
|
-
export default {
|
|
51
|
-
async fetch() {
|
|
52
|
-
const html = await renderer.render({ title: 'Blog' });
|
|
53
|
-
return new Response(html, { headers: { 'content-type': 'text/html' } });
|
|
54
|
-
},
|
|
55
|
-
};
|
|
56
|
-
```
|
|
57
|
-
|
|
58
|
-
`createRenderer(theme, { plugins })` takes runtime plugins of the host rendering the theme, for example with data of the request in `prepare`. The helpers of the theme itself are in `compiled.js`, see [Helpers of the theme](#helpers-of-the-theme). `formatXml` and `validateXml` are in `blogger-hbs/runtime` as well. A compiled module is rendered by the version of `blogger-hbs` it is compiled with, `createRenderer` checks it.
|
|
59
|
-
|
|
60
|
-
## Helpers of the theme
|
|
61
|
-
|
|
62
|
-
Helpers are given by the runtime of a plugin, which is bundled into `compiled.js`: the theme renders with them wherever it is rendered. A plugin of the theme itself only needs a name and its runtime.
|
|
63
|
-
|
|
64
|
-
```ts
|
|
65
|
-
// blogger-hbs.config.ts
|
|
66
|
-
export default defineConfig({
|
|
67
|
-
plugins: [{ name: 'theme', runtime: { entry: './src/runtime.ts' } }],
|
|
68
|
-
});
|
|
69
|
-
```
|
|
70
|
-
|
|
71
|
-
```ts
|
|
72
|
-
// src/runtime.ts
|
|
73
|
-
import { defineRuntimePlugin } from 'blogger-hbs/runtime';
|
|
74
|
-
|
|
75
|
-
export default defineRuntimePlugin((api) => ({
|
|
76
|
-
helpers: {
|
|
77
|
-
upper: (text: string) => text.toUpperCase(),
|
|
78
|
-
},
|
|
79
|
-
}));
|
|
80
|
-
```
|
|
81
|
-
|
|
82
|
-
## Plugins
|
|
83
|
-
|
|
84
|
-
A compile plugin provides partials (`{{> name.partial}}`) and data (`{{@name.value}}`) when compiling, and can come with a runtime half for rendering.
|
|
85
|
-
|
|
86
|
-
```ts
|
|
87
|
-
import { fileURLToPath } from 'node:url';
|
|
88
|
-
import type { CompilePlugin } from 'blogger-hbs';
|
|
89
|
-
|
|
90
|
-
export function myPlugin(options: { prefix: string }): CompilePlugin {
|
|
91
|
-
return {
|
|
92
|
-
name: 'my',
|
|
93
|
-
provide({ requests }, plugin) {
|
|
94
|
-
// every partial used, with where and how: `{{> my.badge size=16}}`
|
|
95
|
-
for (const { name, usages } of requests) {
|
|
96
|
-
for (const usage of usages) {
|
|
97
|
-
if ('color' in usage.hash) {
|
|
98
|
-
plugin.error(`'color' is not a prop of ${name}`, usage);
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
return Object.fromEntries(
|
|
103
|
-
requests.map(({ name }) => [name, `<span class='${name}'/>`]),
|
|
104
|
-
);
|
|
105
|
-
},
|
|
106
|
-
// bundled into compiled.js, it can not use Node.js modules
|
|
107
|
-
runtime: {
|
|
108
|
-
entry: fileURLToPath(new URL('./runtime.js', import.meta.url)),
|
|
109
|
-
options: { prefix: options.prefix },
|
|
110
|
-
},
|
|
111
|
-
};
|
|
112
|
-
}
|
|
113
|
-
```
|
|
114
|
-
|
|
115
|
-
```ts
|
|
116
|
-
// runtime.ts, published as runtime.js
|
|
117
|
-
import { defineRuntimePlugin } from 'blogger-hbs/runtime';
|
|
118
|
-
|
|
119
|
-
export default defineRuntimePlugin((api, options: { prefix: string }) => ({
|
|
120
|
-
helpers: {
|
|
121
|
-
greet: (name: string) =>
|
|
122
|
-
new api.SafeString(`${options.prefix} ${api.escapeExpression(name)}`),
|
|
123
|
-
},
|
|
124
|
-
// before every render, can be async, read as `{{@my.posts}}`
|
|
125
|
-
async prepare(context) {
|
|
126
|
-
return { posts: [] };
|
|
127
|
-
},
|
|
128
|
-
// after every render
|
|
129
|
-
transform: (html) => html,
|
|
130
|
-
}));
|
|
131
|
-
```
|
|
132
|
-
|
|
133
|
-
| Hook | When |
|
|
134
|
-
| --- | --- |
|
|
135
|
-
| `buildStart(plugin)` | first, in every compilation, also each time when watching |
|
|
136
|
-
| `preprocess(templates, plugin)` | with every template, their ASTs can be changed |
|
|
137
|
-
| `provide({ partials, requests, templates }, plugin)` | with the partials used, again for those the provided ones use |
|
|
138
|
-
| `finalize({ provided, missing, requests, available }, plugin)` | once, for partials that need all the others |
|
|
139
|
-
| `data({ provided, available, templates }, plugin)` | once, the values are JSON |
|
|
140
|
-
| `buildEnd(plugin, error?)` | last, when the templates are compiled |
|
|
141
|
-
|
|
142
|
-
### Partials of a plugin
|
|
143
|
-
|
|
144
|
-
A plugin `my` provides its main partial and any names separated by single dots:
|
|
145
|
-
|
|
146
|
-
| In a template | Key provided |
|
|
147
|
-
| --- | --- |
|
|
148
|
-
| `{{> my}}`, `{{#> my}}...{{/my}}` | `.` |
|
|
149
|
-
| `{{> my.badge}}` | `badge` |
|
|
150
|
-
| `{{> my.badge.small}}` | `badge.small` |
|
|
151
|
-
|
|
152
|
-
A name is checked as it is written, `{{> my.}}`, `{{> my..badge}}`, `{{> my.badge.}}` and `{{> my/badge}}` are errors where they are, and a theme can not define an inline partial with a name of a plugin, `{{#*inline "my.badge"}}`. Partials of no plugin are left to Handlebars.
|
|
153
|
-
|
|
154
|
-
Every hook gets the plugin context: `root`, `entry`, `mode`, `watch`, `resolve(specifier, importer?)` with the aliases, `addWatchFile(file)`, `warn(message, loc?)` and `error(message, loc?)`. `enforce: 'pre'` or `'post'` runs a plugin before or after the others.
|
|
155
|
-
|
|
156
|
-
The runtime halves of all the plugins are bundled together, a module they share (a dependency of two plugins) is in `compiled.js` once and is the same instance for both. The runtime half is set up with `api` (`SafeString`, `escapeExpression`, `createFrame`, `HelperError`) and the options, which are JSON. Its helpers also work with `renderTemplate`, `prepare` and `transform` need `createRenderer`.
|
|
41
|
+
- [Configuration](./docs/configuration.md): the options of the config and of the CLI.
|
|
42
|
+
- [Templates](./docs/templates.md): importing templates, data, scripts and styles.
|
|
43
|
+
- [Helpers](./docs/helpers.md): the built-in helpers and those of a theme.
|
|
44
|
+
- [Plugins](./docs/plugins.md): partials, data, hooks and runtimes of plugins.
|
|
45
|
+
- [Validation and formatting](./docs/validation.md): what is checked, and how the theme is written.
|
|
46
|
+
- [Rendering anywhere](./docs/rendering.md): `blogger-hbs/runtime` and `createRenderer`.
|
|
47
|
+
- [JavaScript API](./docs/api.md): `compileTemplate`, `watchTemplate` and the others.
|
|
48
|
+
- [Errors](./docs/errors.md): what errors say and how to throw them.
|
package/dist/cli/index.js
CHANGED
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
import { CompileError } from "../compiler/errors.js";
|
|
2
|
+
import { withLocation } from "../plugins/index.js";
|
|
2
3
|
import { didYouMean } from "../utils/suggest.js";
|
|
3
4
|
import { COMPILE_OPTION_KEYS, assertCompileOptions, assertDirectories, assertEntry, resolvePaths } from "../compiler/options.js";
|
|
4
|
-
import {
|
|
5
|
+
import { processXml } from "../xml/process.js";
|
|
5
6
|
import { compileTemplate } from "../compiler/compile.js";
|
|
6
7
|
import { watchTemplate } from "../compiler/watch.js";
|
|
7
8
|
import { loadConfig } from "../config.js";
|
|
8
9
|
import { createRenderer } from "../runtime/render.js";
|
|
10
|
+
import { collectStats, formatStats } from "./stats.js";
|
|
9
11
|
import * as path from "node:path";
|
|
10
12
|
import * as fs from "node:fs/promises";
|
|
11
|
-
import { createRequire } from "node:module";
|
|
12
13
|
import { watch } from "node:fs";
|
|
13
14
|
import { styleText } from "node:util";
|
|
14
15
|
import { cac } from "cac";
|
|
15
16
|
//#region src/cli/index.ts
|
|
16
|
-
const { version } =
|
|
17
|
+
const { version } = JSON.parse(await fs.readFile(new URL("../../package.json", import.meta.url), "utf-8"));
|
|
17
18
|
const log = {
|
|
18
19
|
success: (message) => console.log(`${styleText("green", "✓")} ${message}`),
|
|
19
20
|
info: (message) => console.log(`${styleText("cyan", "●")} ${message}`),
|
|
@@ -22,6 +23,7 @@ const log = {
|
|
|
22
23
|
};
|
|
23
24
|
const cli = cac("blogger-hbs");
|
|
24
25
|
cli.command("[root]", "Compile the template and render it").alias("build").option("-c, --config <file>", "Path of the config file").option("--entry <file>", "Entry template, relative to the root").option("-o, --out-dir <dir>", "Output directory, relative to the root").option("--context <file>", "JSON file with the context to render with").option("-w, --watch", "Build again when a file changes").option("--no-clean", "Keep the files in the output directory").option("--no-validate", "Do not validate the rendered template as XML, nor format it (templates are always validated when compiling)").option("--no-format", "Do not format the rendered template").example("blogger-hbs").example("blogger-hbs --watch").example("blogger-hbs ./theme --entry src/index.hbs --context context.json").action(async (rootArg, rawFlags) => {
|
|
26
|
+
printHeader();
|
|
25
27
|
const text = (value) => value === void 0 ? void 0 : String(value);
|
|
26
28
|
const root = text(rootArg);
|
|
27
29
|
const flags = {
|
|
@@ -49,7 +51,7 @@ function describeCliError(error) {
|
|
|
49
51
|
const flags = [...cli.commands, cli.globalCommand].flatMap((command) => command.options.flatMap((option) => option.rawName.match(/--[\w-]+/g) ?? []));
|
|
50
52
|
const unknown = /^Unknown option `(.+)`$/.exec(error.message)?.[1];
|
|
51
53
|
const hint = unknown ? didYouMean(unknown, flags, "`") : "";
|
|
52
|
-
return /* @__PURE__ */ new Error(`${error.message}${hint}\
|
|
54
|
+
return /* @__PURE__ */ new Error(`${error.message}${hint}\nRun 'blogger-hbs --help' to see the available options`);
|
|
53
55
|
}
|
|
54
56
|
async function setup(root, flags) {
|
|
55
57
|
const cwd = process.cwd();
|
|
@@ -83,7 +85,8 @@ async function setup(root, flags) {
|
|
|
83
85
|
format: flags.format === false ? false : output.format ?? true,
|
|
84
86
|
clean,
|
|
85
87
|
context: flags.context ? await readContext(path.resolve(cwd, flags.context), flags.context) : config.context ?? {},
|
|
86
|
-
publicDir: await resolvePublicDir(resolvedRoot, config.publicDir, outDir)
|
|
88
|
+
publicDir: await resolvePublicDir(resolvedRoot, config.publicDir, outDir),
|
|
89
|
+
sizes: /* @__PURE__ */ new Map()
|
|
87
90
|
};
|
|
88
91
|
}
|
|
89
92
|
/** The public directory, `public` when it exists unless set otherwise. */
|
|
@@ -155,7 +158,7 @@ async function build(root, flags) {
|
|
|
155
158
|
const start = performance.now();
|
|
156
159
|
const compiled = await compileTemplate(current.options);
|
|
157
160
|
log.success(`Compiled in ${elapsed(start)}`);
|
|
158
|
-
await write(current, compiled);
|
|
161
|
+
await write(current, compiled, start);
|
|
159
162
|
}
|
|
160
163
|
/** Watches the template and restarts when the config file changes. */
|
|
161
164
|
async function watchBuild(root, flags) {
|
|
@@ -167,6 +170,15 @@ async function watchBuild(root, flags) {
|
|
|
167
170
|
const start = async () => {
|
|
168
171
|
let begin = performance.now();
|
|
169
172
|
let first = true;
|
|
173
|
+
/** Shown before what a rebuild prints, after the first build. */
|
|
174
|
+
let divider = "";
|
|
175
|
+
/** Once, before the first thing a rebuild prints, its output can be the same. */
|
|
176
|
+
const printDivider = () => {
|
|
177
|
+
if (divider) {
|
|
178
|
+
console.log(divider);
|
|
179
|
+
divider = "";
|
|
180
|
+
}
|
|
181
|
+
};
|
|
170
182
|
try {
|
|
171
183
|
await copyPublic(current);
|
|
172
184
|
} catch (error) {
|
|
@@ -174,15 +186,20 @@ async function watchBuild(root, flags) {
|
|
|
174
186
|
}
|
|
175
187
|
watcher = await watchTemplate({
|
|
176
188
|
...current.options,
|
|
177
|
-
onStart() {
|
|
189
|
+
onStart({ files }) {
|
|
178
190
|
begin = performance.now();
|
|
191
|
+
divider = first ? "" : formatDivider(files);
|
|
179
192
|
},
|
|
180
193
|
async onCompile(compiled) {
|
|
194
|
+
printDivider();
|
|
181
195
|
log.success(`${first ? "Compiled" : "Rebuilt"} in ${elapsed(begin)}`);
|
|
196
|
+
await write(current, compiled, begin);
|
|
182
197
|
first = false;
|
|
183
|
-
await write(current, compiled);
|
|
184
198
|
},
|
|
185
|
-
onError
|
|
199
|
+
onError(error) {
|
|
200
|
+
printDivider();
|
|
201
|
+
log.error(error);
|
|
202
|
+
}
|
|
186
203
|
});
|
|
187
204
|
for (const file of current.loaded.dependencies) try {
|
|
188
205
|
const configWatcher = watch(file, () => {
|
|
@@ -262,45 +279,103 @@ async function prepareOutDir({ outDir, clean }) {
|
|
|
262
279
|
* Writes the compiled module and the rendered template, validated and
|
|
263
280
|
* formatted after rendering when enabled.
|
|
264
281
|
*/
|
|
265
|
-
async function write(current, compiled) {
|
|
266
|
-
const { outDir, moduleFile, templateFile
|
|
267
|
-
|
|
268
|
-
|
|
282
|
+
async function write(current, compiled, begin) {
|
|
283
|
+
const { outDir, moduleFile, templateFile } = current;
|
|
284
|
+
const written = [];
|
|
285
|
+
let theme;
|
|
286
|
+
if (moduleFile) {
|
|
287
|
+
const file = path.join(outDir, moduleFile);
|
|
288
|
+
await fs.writeFile(file, compiled.source);
|
|
289
|
+
written.push({
|
|
290
|
+
path: path.relative(process.cwd(), file),
|
|
291
|
+
content: compiled.source
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
if (templateFile) {
|
|
295
|
+
theme = await writeTheme(current, compiled, templateFile);
|
|
296
|
+
written.unshift(theme.file);
|
|
297
|
+
}
|
|
298
|
+
const stats = await collectStats(compiled, written, theme?.info && {
|
|
299
|
+
...theme.file,
|
|
300
|
+
info: theme.info
|
|
301
|
+
});
|
|
302
|
+
console.log(formatStats(stats, current.sizes, { previousTheme: current.theme }));
|
|
303
|
+
current.sizes = new Map(stats.files.map(({ path, size }) => [path, size]));
|
|
304
|
+
current.theme = stats.theme;
|
|
305
|
+
log.success(`Built in ${elapsed(begin)}`);
|
|
306
|
+
}
|
|
307
|
+
/** `─── 14:32:05 · src/header.hbs +2 ───────`, dim. */
|
|
308
|
+
function formatDivider(files) {
|
|
309
|
+
const time = (/* @__PURE__ */ new Date()).toLocaleTimeString("en-GB", { hour12: false });
|
|
310
|
+
const [file, ...others] = files.map((item) => path.relative(process.cwd(), item));
|
|
311
|
+
const text = `─── ${time}${file ? ` · ${file}${others.length > 0 ? ` +${others.length}` : ""}` : ""} `;
|
|
312
|
+
return `\n${styleText("dim", text + "─".repeat(Math.max(3, 50 - text.length)))}`;
|
|
313
|
+
}
|
|
314
|
+
/** Renders, validates and formats the theme, as enabled, and writes it. */
|
|
315
|
+
async function writeTheme(current, compiled, templateFile) {
|
|
316
|
+
const { outDir, context } = current;
|
|
269
317
|
const file = path.join(outDir, templateFile);
|
|
270
318
|
const shown = path.relative(process.cwd(), file);
|
|
271
319
|
let start = performance.now();
|
|
272
320
|
const rendered = await createRenderer(compiled).render(context);
|
|
273
321
|
log.success(`Rendered in ${elapsed(start)}`);
|
|
322
|
+
if (!current.validate) {
|
|
323
|
+
await fs.writeFile(file, rendered);
|
|
324
|
+
return { file: {
|
|
325
|
+
path: shown,
|
|
326
|
+
content: rendered
|
|
327
|
+
} };
|
|
328
|
+
}
|
|
274
329
|
start = performance.now();
|
|
275
|
-
let
|
|
330
|
+
let result;
|
|
276
331
|
try {
|
|
277
|
-
|
|
332
|
+
result = processXml(rendered, {
|
|
333
|
+
path: shown,
|
|
334
|
+
format: current.format
|
|
335
|
+
});
|
|
278
336
|
} catch (error) {
|
|
279
337
|
await fs.writeFile(file, rendered);
|
|
280
|
-
throw new CompileError(
|
|
338
|
+
throw new CompileError("The rendered template is not valid XML", {
|
|
339
|
+
cause: error,
|
|
340
|
+
loc: error.loc
|
|
341
|
+
});
|
|
281
342
|
}
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
343
|
+
for (const { message, loc } of result.warnings) log.warn(withLocation(message, loc));
|
|
344
|
+
log.success(`${current.format ? "Formatted" : "Validated"} in ${elapsed(start)}`);
|
|
345
|
+
await fs.writeFile(file, result.xml);
|
|
346
|
+
return {
|
|
347
|
+
file: {
|
|
348
|
+
path: shown,
|
|
349
|
+
content: result.xml
|
|
350
|
+
},
|
|
351
|
+
info: result.info
|
|
352
|
+
};
|
|
285
353
|
}
|
|
286
|
-
/**
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
354
|
+
/**
|
|
355
|
+
* A blank line, `blogger-hbs v0.0.4` right-aligned on a cyan line under it,
|
|
356
|
+
* before what a build prints.
|
|
357
|
+
*/
|
|
358
|
+
function printHeader() {
|
|
359
|
+
const text = `blogger-hbs v${version}`;
|
|
360
|
+
const width = text.length + 2;
|
|
361
|
+
console.log(`\n${" ".repeat(width - text.length)}${styleText("bold", "blogger-hbs")} ${styleText("dim", `v${version}`)}\n${styleText("cyan", "─".repeat(width))}`);
|
|
294
362
|
}
|
|
295
363
|
function elapsed(start) {
|
|
296
364
|
return styleText("yellow", `${Math.round(performance.now() - start)}ms`);
|
|
297
365
|
}
|
|
298
|
-
/**
|
|
366
|
+
/**
|
|
367
|
+
* The message of the error and of everything that caused it, a cause whose
|
|
368
|
+
* message is already in the one before is not repeated. The lines of a
|
|
369
|
+
* message are indented under its first.
|
|
370
|
+
*/
|
|
299
371
|
function formatError(error) {
|
|
300
372
|
const lines = [];
|
|
373
|
+
let previous = "";
|
|
301
374
|
let current = error;
|
|
302
375
|
while (current !== void 0) {
|
|
303
|
-
|
|
376
|
+
const message = current instanceof Error ? current.message : String(current);
|
|
377
|
+
if (lines.length === 0 || !previous.includes(message)) lines.push(`${lines.length === 0 ? "" : "Caused by: "}${message.replaceAll("\n", "\n ")}`);
|
|
378
|
+
previous = message;
|
|
304
379
|
current = current instanceof Error ? current.cause : void 0;
|
|
305
380
|
}
|
|
306
381
|
return lines.join("\n ");
|
package/dist/cli/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../src/cli/index.ts"],"sourcesContent":["import { type FSWatcher, watch } from 'node:fs';\nimport * as fs from 'node:fs/promises';\nimport { createRequire } from 'node:module';\nimport * as path from 'node:path';\nimport { styleText } from 'node:util';\nimport { cac } from 'cac';\nimport {\n\ttype CompiledTemplate,\n\tCompileError,\n\ttype CompileTemplateOptions,\n\tcompileTemplate,\n\ttype TemplateWatcher,\n\twatchTemplate,\n} from '../compiler';\nimport {\n\tassertCompileOptions,\n\tassertDirectories,\n\tassertEntry,\n\tCOMPILE_OPTION_KEYS,\n\tresolvePaths,\n} from '../compiler/options';\nimport { type LoadedConfig, loadConfig } from '../config';\nimport { createRenderer } from '../runtime';\nimport { didYouMean } from '../utils/suggest';\nimport { formatXml, validateXml } from '../xml';\n\nconst { version } = createRequire(import.meta.url)('../../package.json') as {\n\tversion: string;\n};\n\ninterface BuildFlags {\n\tconfig?: string;\n\tentry?: string;\n\toutDir?: string;\n\tcontext?: string;\n\twatch?: boolean;\n\tclean?: boolean;\n\tvalidate?: boolean;\n\tformat?: boolean;\n}\n\n/** Everything a build needs, from the config file and the flags. */\ninterface BuildSetup {\n\toptions: CompileTemplateOptions;\n\tloaded: LoadedConfig;\n\toutDir: string;\n\tmoduleFile: string | false;\n\ttemplateFile: string | false;\n\tclean: boolean;\n\tcontext: unknown;\n\t/** Whether the rendered template is validated. */\n\tvalidate: boolean;\n\t/** Whether the rendered template is formatted, only when it is validated. */\n\tformat: boolean;\n\t/** Absolute path of the public directory, undefined when nothing is copied. */\n\tpublicDir?: string;\n}\n\nconst log = {\n\tsuccess: (message: string) =>\n\t\tconsole.log(`${styleText('green', '✓')} ${message}`),\n\tinfo: (message: string) =>\n\t\tconsole.log(`${styleText('cyan', '●')} ${message}`),\n\twarn: (message: string) =>\n\t\tconsole.warn(`${styleText('yellow', '⚠')} ${message}`),\n\terror: (error: unknown) =>\n\t\tconsole.error(`${styleText('red', '✗')} ${formatError(error)}`),\n};\n\nconst cli = cac('blogger-hbs');\n\ncli\n\t.command('[root]', 'Compile the template and render it')\n\t.alias('build')\n\t.option('-c, --config <file>', 'Path of the config file')\n\t.option('--entry <file>', 'Entry template, relative to the root')\n\t.option('-o, --out-dir <dir>', 'Output directory, relative to the root')\n\t.option('--context <file>', 'JSON file with the context to render with')\n\t.option('-w, --watch', 'Build again when a file changes')\n\t.option('--no-clean', 'Keep the files in the output directory')\n\t.option(\n\t\t'--no-validate',\n\t\t'Do not validate the rendered template as XML, nor format it (templates are always validated when compiling)',\n\t)\n\t.option('--no-format', 'Do not format the rendered template')\n\t.example('blogger-hbs')\n\t.example('blogger-hbs --watch')\n\t.example('blogger-hbs ./theme --entry src/index.hbs --context context.json')\n\t.action(async (rootArg: unknown, rawFlags: BuildFlags) => {\n\t\t// cac turns values that look like numbers into numbers, `-o 2024`\n\t\tconst text = (value: unknown) =>\n\t\t\tvalue === undefined ? undefined : String(value);\n\t\tconst root = text(rootArg);\n\t\tconst flags: BuildFlags = {\n\t\t\t...rawFlags,\n\t\t\tconfig: text(rawFlags.config),\n\t\t\tentry: text(rawFlags.entry),\n\t\t\toutDir: text(rawFlags.outDir),\n\t\t\tcontext: text(rawFlags.context),\n\t\t};\n\n\t\tif (flags.watch) {\n\t\t\tawait watchBuild(root, flags);\n\t\t} else {\n\t\t\tawait build(root, flags);\n\t\t}\n\t});\n\ncli.help();\ncli.version(version);\n\ntry {\n\tcli.parse(process.argv, { run: false });\n\tawait cli.runMatchedCommand();\n} catch (error) {\n\tlog.error(describeCliError(error));\n\tprocess.exitCode = 1;\n}\n\n/** Adds a suggestion and a pointer to `--help` to the errors of the arguments. */\nfunction describeCliError(error: unknown): unknown {\n\tif (!(error instanceof Error) || error.name !== 'CACError') {\n\t\treturn error;\n\t}\n\n\tconst flags = [...cli.commands, cli.globalCommand].flatMap((command) =>\n\t\tcommand.options.flatMap(\n\t\t\t(option) => option.rawName.match(/--[\\w-]+/g) ?? [],\n\t\t),\n\t);\n\tconst unknown = /^Unknown option `(.+)`$/.exec(error.message)?.[1];\n\tconst hint = unknown ? didYouMean(unknown, flags, '`') : '';\n\n\treturn new Error(\n\t\t`${error.message}${hint}\\n Run 'blogger-hbs --help' to see the available options`,\n\t);\n}\n\nasync function setup(\n\troot: string | undefined,\n\tflags: BuildFlags,\n): Promise<BuildSetup> {\n\tconst cwd = process.cwd();\n\tconst rootFlag = root === undefined ? undefined : path.resolve(cwd, root);\n\n\t// the config is looked for in the root, which has to exist for that\n\tif (rootFlag !== undefined && !(await isDirectory(rootFlag))) {\n\t\tthrow new CompileError(\n\t\t\t(await exists(rootFlag))\n\t\t\t\t? `Root '${root}' is not a directory`\n\t\t\t\t: `Root directory '${root}' does not exist`,\n\t\t);\n\t}\n\n\tconst loaded = await loadConfig({\n\t\tcwd: rootFlag ?? cwd,\n\t\tconfigFile: flags.config && path.resolve(cwd, flags.config),\n\t\twatch: flags.watch,\n\t});\n\tconst { config } = loaded;\n\n\tconst resolvedRoot = rootFlag ?? config.root ?? cwd;\n\tconst output = config.output ?? {};\n\n\t// the config has more than the compile options\n\tconst options: CompileTemplateOptions = {};\n\tfor (const key of COMPILE_OPTION_KEYS) {\n\t\tif (key in config) {\n\t\t\tObject.assign(options, { [key]: config[key as keyof typeof config] });\n\t\t}\n\t}\n\toptions.root = resolvedRoot;\n\toptions.entry = flags.entry ?? config.entry;\n\toptions.onWarn ??= log.warn;\n\n\tassertCompileOptions(options);\n\tawait assertDirectories(options);\n\n\tconst outDir = path.resolve(\n\t\tresolvedRoot,\n\t\tflags.outDir ?? output.dir ?? 'dist',\n\t);\n\tconst clean = flags.clean === false ? false : (output.clean ?? true);\n\tif (clean) {\n\t\tassertCleanable(outDir, options);\n\t}\n\n\treturn {\n\t\toptions,\n\t\tloaded,\n\t\toutDir,\n\t\tmoduleFile: output.module ?? 'compiled.js',\n\t\ttemplateFile: output.template ?? 'theme.xml',\n\t\tvalidate: flags.validate === false ? false : (output.validate ?? true),\n\t\tformat: flags.format === false ? false : (output.format ?? true),\n\t\tclean,\n\t\tcontext: flags.context\n\t\t\t? await readContext(path.resolve(cwd, flags.context), flags.context)\n\t\t\t: (config.context ?? {}),\n\t\tpublicDir: await resolvePublicDir(resolvedRoot, config.publicDir, outDir),\n\t};\n}\n\n/** The public directory, `public` when it exists unless set otherwise. */\nasync function resolvePublicDir(\n\troot: string,\n\tvalue: string | false | undefined,\n\toutDir: string,\n): Promise<string | undefined> {\n\tif (value === false) {\n\t\treturn;\n\t}\n\n\tconst directory = path.resolve(root, value ?? 'public');\n\tconst shown = path.relative(process.cwd(), directory) || '.';\n\n\tif (!(await isDirectory(directory))) {\n\t\tif (value === undefined) {\n\t\t\treturn;\n\t\t}\n\t\tthrow new CompileError(\n\t\t\t(await exists(directory))\n\t\t\t\t? `Public directory '${shown}' is not a directory`\n\t\t\t\t: `Public directory '${shown}' does not exist, set 'publicDir: false' to not copy anything`,\n\t\t);\n\t}\n\n\tif (isInside(outDir, directory) || isInside(directory, outDir)) {\n\t\tthrow new CompileError(\n\t\t\t`Public directory '${shown}' and output directory '${path.relative(process.cwd(), outDir) || '.'}' overlap, they must be separate`,\n\t\t);\n\t}\n\n\treturn directory;\n}\n\n/** Copies the public directory into the output directory. */\nasync function copyPublic({\n\tpublicDir,\n\toutDir,\n\tmoduleFile,\n\ttemplateFile,\n}: BuildSetup): Promise<void> {\n\tif (publicDir === undefined) {\n\t\treturn;\n\t}\n\n\tfor (const name of await fs.readdir(publicDir)) {\n\t\tif (name === moduleFile || name === templateFile) {\n\t\t\tthrow new CompileError(\n\t\t\t\t`'${name}' in the public directory has the same name as the ${name === moduleFile ? 'compiled module' : 'rendered template'} and would be overwritten, rename it or set 'output.${name === moduleFile ? 'module' : 'template'}'`,\n\t\t\t);\n\t\t}\n\t}\n\n\tawait fs.cp(publicDir, outDir, { recursive: true, force: true });\n}\n\n/**\n * Cleaning removes everything in the output directory, which must not hold the\n * project: the root, the working directory, the templates or an alias target.\n */\nfunction assertCleanable(outDir: string, options: CompileTemplateOptions) {\n\tconst { root, entry } = resolvePaths(options);\n\tconst shown = path.relative(process.cwd(), outDir) || '.';\n\tconst kept: [string, string][] = [\n\t\t[root, 'the root'],\n\t\t[process.cwd(), 'the working directory'],\n\t\t[path.dirname(entry), 'the entry template'],\n\t\t...Object.entries(options.alias ?? {}).map(\n\t\t\t([name, target]): [string, string] => [\n\t\t\t\tpath.resolve(root, target),\n\t\t\t\t`the target of the alias '${name}'`,\n\t\t\t],\n\t\t),\n\t];\n\n\tfor (const [directory, what] of kept) {\n\t\tif (isInside(directory, outDir)) {\n\t\t\tthrow new CompileError(\n\t\t\t\t`Refusing to clean the output directory '${shown}', it contains ${what}. Use another output directory, or --no-clean / 'output.clean: false' to keep its files`,\n\t\t\t);\n\t\t}\n\t}\n}\n\nasync function readContext(file: string, shown: string): Promise<unknown> {\n\tlet text: string;\n\ttry {\n\t\ttext = await fs.readFile(file, 'utf-8');\n\t} catch (cause) {\n\t\tif ((cause as NodeJS.ErrnoException).code === 'ENOENT') {\n\t\t\tthrow new CompileError(`Context file '${shown}' not found`);\n\t\t}\n\t\tthrow new CompileError(`Failed to read the context file '${shown}'`, {\n\t\t\tcause,\n\t\t});\n\t}\n\n\ttry {\n\t\treturn JSON.parse(text);\n\t} catch (cause) {\n\t\tthrow new CompileError(\n\t\t\t`Context file '${shown}' is not valid JSON: ${(cause as Error).message}`,\n\t\t);\n\t}\n}\n\n/** Whether `child` is `parent` or inside of it. */\nfunction isInside(child: string, parent: string): boolean {\n\tconst relative = path.relative(parent, child);\n\treturn (\n\t\trelative === '' ||\n\t\t(!relative.startsWith('..') && !path.isAbsolute(relative))\n\t);\n}\n\nasync function exists(file: string): Promise<boolean> {\n\treturn fs.stat(file).then(\n\t\t() => true,\n\t\t() => false,\n\t);\n}\n\nasync function isDirectory(file: string): Promise<boolean> {\n\treturn fs.stat(file).then(\n\t\t(stats) => stats.isDirectory(),\n\t\t() => false,\n\t);\n}\n\nasync function build(root: string | undefined, flags: BuildFlags) {\n\tconst current = await setup(root, flags);\n\t// nothing is written when there is nothing to build, the watcher waits\n\t// for the entry instead\n\tawait assertEntry(current.options);\n\tawait prepareOutDir(current);\n\tawait copyPublic(current);\n\n\tconst start = performance.now();\n\tconst compiled = await compileTemplate(current.options);\n\tlog.success(`Compiled in ${elapsed(start)}`);\n\n\tawait write(current, compiled);\n}\n\n/** Watches the template and restarts when the config file changes. */\nasync function watchBuild(root: string | undefined, flags: BuildFlags) {\n\tlet current = await setup(root, flags);\n\tawait prepareOutDir(current);\n\n\tlet watcher: TemplateWatcher | undefined;\n\tlet watchers: FSWatcher[] = [];\n\tlet restarting = false;\n\n\tconst start = async () => {\n\t\tlet begin = performance.now();\n\t\tlet first = true;\n\n\t\ttry {\n\t\t\tawait copyPublic(current);\n\t\t} catch (error) {\n\t\t\tlog.error(error);\n\t\t}\n\n\t\twatcher = await watchTemplate({\n\t\t\t...current.options,\n\t\t\tonStart() {\n\t\t\t\tbegin = performance.now();\n\t\t\t},\n\t\t\tasync onCompile(compiled) {\n\t\t\t\tlog.success(`${first ? 'Compiled' : 'Rebuilt'} in ${elapsed(begin)}`);\n\t\t\t\tfirst = false;\n\t\t\t\tawait write(current, compiled);\n\t\t\t},\n\t\t\tonError: log.error,\n\t\t});\n\n\t\tfor (const file of current.loaded.dependencies) {\n\t\t\ttry {\n\t\t\t\tconst configWatcher = watch(file, () => {\n\t\t\t\t\t// saving fires more than once, a restart is enough\n\t\t\t\t\tif (!restarting) {\n\t\t\t\t\t\trestarting = true;\n\t\t\t\t\t\trestart().finally(() => {\n\t\t\t\t\t\t\trestarting = false;\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t\tconfigWatcher.on('error', () => configWatcher.close());\n\t\t\t\twatchers.push(configWatcher);\n\t\t\t} catch {\n\t\t\t\t// a dependency that can not be watched does not restart\n\t\t\t}\n\t\t}\n\n\t\tif (current.publicDir !== undefined) {\n\t\t\twatchers.push(watchPublic(current));\n\t\t}\n\t};\n\n\tconst stopWatchers = () => {\n\t\tfor (const fileWatcher of watchers) {\n\t\t\tfileWatcher.close();\n\t\t}\n\t\twatchers = [];\n\t};\n\n\tconst restart = async () => {\n\t\tlog.info(\n\t\t\t`Config changed, restarting ${styleText('dim', path.relative(process.cwd(), current.loaded.file ?? ''))}`,\n\t\t);\n\t\tstopWatchers();\n\t\tawait watcher?.close();\n\t\ttry {\n\t\t\tcurrent = await setup(root, flags);\n\t\t} catch (error) {\n\t\t\tlog.error(error);\n\t\t}\n\t\tawait start();\n\t};\n\n\tawait start();\n\tlog.info(\n\t\t`Watching for changes ${styleText('dim', '(press Ctrl+C to stop)')}`,\n\t);\n\n\tconst stop = async () => {\n\t\tstopWatchers();\n\t\tawait watcher?.close();\n\t\t// the process ends once nothing is left running: `process.exit` would skip\n\t\t// the cleanup of rspack's native bindings, which then warn about leaks,\n\t\t// so it is only a fallback for something left running, a plugin's timer\n\t\tsetTimeout(() => process.exit(0), 3000).unref();\n\t};\n\tprocess.once('SIGINT', stop);\n\tprocess.once('SIGTERM', stop);\n}\n\n/** Copies the public directory again when something in it changes. */\nfunction watchPublic(current: BuildSetup): FSWatcher {\n\tconst publicDir = current.publicDir as string;\n\tconst changed = new Set<string>();\n\tlet timer: NodeJS.Timeout | undefined;\n\n\tconst sync = async () => {\n\t\tconst names = [...changed];\n\t\tchanged.clear();\n\t\ttry {\n\t\t\t// what was deleted from the public directory goes from the output too\n\t\t\tfor (const name of names) {\n\t\t\t\tif (!(await exists(path.join(publicDir, name)))) {\n\t\t\t\t\tawait fs.rm(path.join(current.outDir, name), {\n\t\t\t\t\t\trecursive: true,\n\t\t\t\t\t\tforce: true,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\t\t\tawait copyPublic(current);\n\t\t\tlog.success(\n\t\t\t\t`Copied ${styleText('dim', path.relative(process.cwd(), publicDir))}`,\n\t\t\t);\n\t\t} catch (error) {\n\t\t\tlog.error(error);\n\t\t}\n\t};\n\n\tconst publicWatcher = watch(\n\t\tpublicDir,\n\t\t{ recursive: true },\n\t\t(_event, name) => {\n\t\t\tif (name) {\n\t\t\t\tchanged.add(name);\n\t\t\t}\n\t\t\tclearTimeout(timer);\n\t\t\ttimer = setTimeout(sync, 50);\n\t\t},\n\t);\n\tpublicWatcher.on('error', () => publicWatcher.close());\n\tpublicWatcher.on('close', () => clearTimeout(timer));\n\treturn publicWatcher;\n}\n\nasync function prepareOutDir({ outDir, clean }: BuildSetup) {\n\tif (clean) {\n\t\tawait fs.rm(outDir, { recursive: true, force: true });\n\t}\n\tawait fs.mkdir(outDir, { recursive: true });\n}\n\n/**\n * Writes the compiled module and the rendered template, validated and\n * formatted after rendering when enabled.\n */\nasync function write(current: BuildSetup, compiled: CompiledTemplate) {\n\tconst { outDir, moduleFile, templateFile, context } = current;\n\n\tif (moduleFile) {\n\t\tawait fs.writeFile(path.join(outDir, moduleFile), compiled.source);\n\t}\n\tif (!templateFile) {\n\t\treturn;\n\t}\n\n\tconst file = path.join(outDir, templateFile);\n\tconst shown = path.relative(process.cwd(), file);\n\n\t// the same as anywhere else the compiled module is rendered\n\tlet start = performance.now();\n\tconst renderer = createRenderer(compiled);\n\tconst rendered = await renderer.render(context);\n\tlog.success(`Rendered in ${elapsed(start)}`);\n\n\tstart = performance.now();\n\tlet output: string;\n\ttry {\n\t\toutput = finalizeXml(current, rendered);\n\t} catch (error) {\n\t\t// written anyway, to look at where it is invalid\n\t\tawait fs.writeFile(file, rendered);\n\t\tthrow new CompileError(\n\t\t\t`The rendered template ${shown} is not valid XML: ${(error as Error).message}`,\n\t\t);\n\t}\n\tif (current.validate) {\n\t\tlog.success(\n\t\t\t`${current.format ? 'Formatted' : 'Validated'} in ${elapsed(start)}`,\n\t\t);\n\t}\n\n\tawait fs.writeFile(file, output);\n\tlog.success(`Written ${styleText('dim', shown)}`);\n}\n\n/** Validates and formats the rendered template, as enabled. */\nfunction finalizeXml({ validate, format }: BuildSetup, xml: string): string {\n\tif (!validate) {\n\t\treturn xml;\n\t}\n\tif (!format) {\n\t\tvalidateXml(xml);\n\t\treturn xml;\n\t}\n\treturn formatXml(xml);\n}\n\nfunction elapsed(start: number): string {\n\treturn styleText('yellow', `${Math.round(performance.now() - start)}ms`);\n}\n\n/** The message of the error and of everything that caused it. */\nfunction formatError(error: unknown): string {\n\tconst lines: string[] = [];\n\tlet current: unknown = error;\n\n\twhile (current !== undefined) {\n\t\tlines.push(\n\t\t\tcurrent instanceof Error\n\t\t\t\t? `${lines.length === 0 ? '' : 'Caused by: '}${current.message}`\n\t\t\t\t: String(current),\n\t\t);\n\t\tcurrent = current instanceof Error ? current.cause : undefined;\n\t}\n\n\treturn lines.join('\\n ');\n}\n"],"mappings":";;;;;;;;;;;;;;;AA0BA,MAAM,EAAE,YAAY,cAAc,YAAY,GAAG,CAAC,CAAC,oBAAoB;AAgCvE,MAAM,MAAM;CACX,UAAU,YACT,QAAQ,IAAI,GAAG,UAAU,SAAS,GAAG,EAAE,GAAG,SAAS;CACpD,OAAO,YACN,QAAQ,IAAI,GAAG,UAAU,QAAQ,GAAG,EAAE,GAAG,SAAS;CACnD,OAAO,YACN,QAAQ,KAAK,GAAG,UAAU,UAAU,GAAG,EAAE,GAAG,SAAS;CACtD,QAAQ,UACP,QAAQ,MAAM,GAAG,UAAU,OAAO,GAAG,EAAE,GAAG,YAAY,KAAK,GAAG;AAChE;AAEA,MAAM,MAAM,IAAI,aAAa;AAE7B,IACE,QAAQ,UAAU,oCAAoC,CAAC,CACvD,MAAM,OAAO,CAAC,CACd,OAAO,uBAAuB,yBAAyB,CAAC,CACxD,OAAO,kBAAkB,sCAAsC,CAAC,CAChE,OAAO,uBAAuB,wCAAwC,CAAC,CACvE,OAAO,oBAAoB,2CAA2C,CAAC,CACvE,OAAO,eAAe,iCAA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,MAAM,QAAkB,CAAC;CACzB,IAAI,UAAmB;CAEvB,OAAO,YAAY,KAAA,GAAW;EAC7B,MAAM,KACL,mBAAmB,QAChB,GAAG,MAAM,WAAW,IAAI,KAAK,gBAAgB,QAAQ,YACrD,OAAO,OAAO,CAClB;EACA,UAAU,mBAAmB,QAAQ,QAAQ,QAAQ,KAAA;CACtD;CAEA,OAAO,MAAM,KAAK,MAAM;AACzB"}
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../src/cli/index.ts"],"sourcesContent":["import { type FSWatcher, watch } from 'node:fs';\nimport * as fs from 'node:fs/promises';\nimport * as path from 'node:path';\nimport { styleText } from 'node:util';\nimport { cac } from 'cac';\nimport {\n\ttype CompiledTemplate,\n\tCompileError,\n\ttype CompileTemplateOptions,\n\tcompileTemplate,\n\ttype TemplateWatcher,\n\twatchTemplate,\n} from '../compiler';\nimport {\n\tassertCompileOptions,\n\tassertDirectories,\n\tassertEntry,\n\tCOMPILE_OPTION_KEYS,\n\tresolvePaths,\n} from '../compiler/options';\nimport { type LoadedConfig, loadConfig } from '../config';\nimport { withLocation } from '../plugins';\nimport { createRenderer } from '../runtime';\nimport { didYouMean } from '../utils/suggest';\nimport {\n\tprocessXml,\n\ttype XmlError,\n\ttype XmlInfo,\n\ttype XmlResult,\n} from '../xml';\nimport {\n\ttype BuildStats,\n\tcollectStats,\n\tformatStats,\n\ttype WrittenFile,\n} from './stats';\n\nconst { version } = JSON.parse(\n\tawait fs.readFile(new URL('../../package.json', import.meta.url), 'utf-8'),\n) as { version: string };\n\ninterface BuildFlags {\n\tconfig?: string;\n\tentry?: string;\n\toutDir?: string;\n\tcontext?: string;\n\twatch?: boolean;\n\tclean?: boolean;\n\tvalidate?: boolean;\n\tformat?: boolean;\n}\n\n/** Everything a build needs, from the config file and the flags. */\ninterface BuildSetup {\n\toptions: CompileTemplateOptions;\n\tloaded: LoadedConfig;\n\toutDir: string;\n\tmoduleFile: string | false;\n\ttemplateFile: string | false;\n\tclean: boolean;\n\tcontext: unknown;\n\t/** Whether the rendered template is validated. */\n\tvalidate: boolean;\n\t/** Whether the rendered template is formatted, only when it is validated. */\n\tformat: boolean;\n\t/** Absolute path of the public directory, undefined when nothing is copied. */\n\tpublicDir?: string;\n\t/** Sizes of the files written last, by path, to show their changes when watching. */\n\tsizes: Map<string, number>;\n\t/** What the theme was made of at the last build, when watching. */\n\ttheme?: BuildStats['theme'];\n}\n\nconst log = {\n\tsuccess: (message: string) =>\n\t\tconsole.log(`${styleText('green', '✓')} ${message}`),\n\tinfo: (message: string) =>\n\t\tconsole.log(`${styleText('cyan', '●')} ${message}`),\n\twarn: (message: string) =>\n\t\tconsole.warn(`${styleText('yellow', '⚠')} ${message}`),\n\terror: (error: unknown) =>\n\t\tconsole.error(`${styleText('red', '✗')} ${formatError(error)}`),\n};\n\nconst cli = cac('blogger-hbs');\n\ncli\n\t.command('[root]', 'Compile the template and render it')\n\t.alias('build')\n\t.option('-c, --config <file>', 'Path of the config file')\n\t.option('--entry <file>', 'Entry template, relative to the root')\n\t.option('-o, --out-dir <dir>', 'Output directory, relative to the root')\n\t.option('--context <file>', 'JSON file with the context to render with')\n\t.option('-w, --watch', 'Build again when a file changes')\n\t.option('--no-clean', 'Keep the files in the output directory')\n\t.option(\n\t\t'--no-validate',\n\t\t'Do not validate the rendered template as XML, nor format it (templates are always validated when compiling)',\n\t)\n\t.option('--no-format', 'Do not format the rendered template')\n\t.example('blogger-hbs')\n\t.example('blogger-hbs --watch')\n\t.example('blogger-hbs ./theme --entry src/index.hbs --context context.json')\n\t.action(async (rootArg: unknown, rawFlags: BuildFlags) => {\n\t\tprintHeader();\n\t\t// cac turns values that look like numbers into numbers, `-o 2024`\n\t\tconst text = (value: unknown) =>\n\t\t\tvalue === undefined ? undefined : String(value);\n\t\tconst root = text(rootArg);\n\t\tconst flags: BuildFlags = {\n\t\t\t...rawFlags,\n\t\t\tconfig: text(rawFlags.config),\n\t\t\tentry: text(rawFlags.entry),\n\t\t\toutDir: text(rawFlags.outDir),\n\t\t\tcontext: text(rawFlags.context),\n\t\t};\n\n\t\tif (flags.watch) {\n\t\t\tawait watchBuild(root, flags);\n\t\t} else {\n\t\t\tawait build(root, flags);\n\t\t}\n\t});\n\ncli.help();\ncli.version(version);\n\ntry {\n\tcli.parse(process.argv, { run: false });\n\tawait cli.runMatchedCommand();\n} catch (error) {\n\tlog.error(describeCliError(error));\n\tprocess.exitCode = 1;\n}\n\n/** Adds a suggestion and a pointer to `--help` to the errors of the arguments. */\nfunction describeCliError(error: unknown): unknown {\n\tif (!(error instanceof Error) || error.name !== 'CACError') {\n\t\treturn error;\n\t}\n\n\tconst flags = [...cli.commands, cli.globalCommand].flatMap((command) =>\n\t\tcommand.options.flatMap(\n\t\t\t(option) => option.rawName.match(/--[\\w-]+/g) ?? [],\n\t\t),\n\t);\n\tconst unknown = /^Unknown option `(.+)`$/.exec(error.message)?.[1];\n\tconst hint = unknown ? didYouMean(unknown, flags, '`') : '';\n\n\treturn new Error(\n\t\t`${error.message}${hint}\\nRun 'blogger-hbs --help' to see the available options`,\n\t);\n}\n\nasync function setup(\n\troot: string | undefined,\n\tflags: BuildFlags,\n): Promise<BuildSetup> {\n\tconst cwd = process.cwd();\n\tconst rootFlag = root === undefined ? undefined : path.resolve(cwd, root);\n\n\t// the config is looked for in the root, which has to exist for that\n\tif (rootFlag !== undefined && !(await isDirectory(rootFlag))) {\n\t\tthrow new CompileError(\n\t\t\t(await exists(rootFlag))\n\t\t\t\t? `Root '${root}' is not a directory`\n\t\t\t\t: `Root directory '${root}' does not exist`,\n\t\t);\n\t}\n\n\tconst loaded = await loadConfig({\n\t\tcwd: rootFlag ?? cwd,\n\t\tconfigFile: flags.config && path.resolve(cwd, flags.config),\n\t\twatch: flags.watch,\n\t});\n\tconst { config } = loaded;\n\n\tconst resolvedRoot = rootFlag ?? config.root ?? cwd;\n\tconst output = config.output ?? {};\n\n\t// the config has more than the compile options\n\tconst options: CompileTemplateOptions = {};\n\tfor (const key of COMPILE_OPTION_KEYS) {\n\t\tif (key in config) {\n\t\t\tObject.assign(options, { [key]: config[key as keyof typeof config] });\n\t\t}\n\t}\n\toptions.root = resolvedRoot;\n\toptions.entry = flags.entry ?? config.entry;\n\toptions.onWarn ??= log.warn;\n\n\tassertCompileOptions(options);\n\tawait assertDirectories(options);\n\n\tconst outDir = path.resolve(\n\t\tresolvedRoot,\n\t\tflags.outDir ?? output.dir ?? 'dist',\n\t);\n\tconst clean = flags.clean === false ? false : (output.clean ?? true);\n\tif (clean) {\n\t\tassertCleanable(outDir, options);\n\t}\n\n\treturn {\n\t\toptions,\n\t\tloaded,\n\t\toutDir,\n\t\tmoduleFile: output.module ?? 'compiled.js',\n\t\ttemplateFile: output.template ?? 'theme.xml',\n\t\tvalidate: flags.validate === false ? false : (output.validate ?? true),\n\t\tformat: flags.format === false ? false : (output.format ?? true),\n\t\tclean,\n\t\tcontext: flags.context\n\t\t\t? await readContext(path.resolve(cwd, flags.context), flags.context)\n\t\t\t: (config.context ?? {}),\n\t\tpublicDir: await resolvePublicDir(resolvedRoot, config.publicDir, outDir),\n\t\tsizes: new Map(),\n\t};\n}\n\n/** The public directory, `public` when it exists unless set otherwise. */\nasync function resolvePublicDir(\n\troot: string,\n\tvalue: string | false | undefined,\n\toutDir: string,\n): Promise<string | undefined> {\n\tif (value === false) {\n\t\treturn;\n\t}\n\n\tconst directory = path.resolve(root, value ?? 'public');\n\tconst shown = path.relative(process.cwd(), directory) || '.';\n\n\tif (!(await isDirectory(directory))) {\n\t\tif (value === undefined) {\n\t\t\treturn;\n\t\t}\n\t\tthrow new CompileError(\n\t\t\t(await exists(directory))\n\t\t\t\t? `Public directory '${shown}' is not a directory`\n\t\t\t\t: `Public directory '${shown}' does not exist, set 'publicDir: false' to not copy anything`,\n\t\t);\n\t}\n\n\tif (isInside(outDir, directory) || isInside(directory, outDir)) {\n\t\tthrow new CompileError(\n\t\t\t`Public directory '${shown}' and output directory '${path.relative(process.cwd(), outDir) || '.'}' overlap, they must be separate`,\n\t\t);\n\t}\n\n\treturn directory;\n}\n\n/** Copies the public directory into the output directory. */\nasync function copyPublic({\n\tpublicDir,\n\toutDir,\n\tmoduleFile,\n\ttemplateFile,\n}: BuildSetup): Promise<void> {\n\tif (publicDir === undefined) {\n\t\treturn;\n\t}\n\n\tfor (const name of await fs.readdir(publicDir)) {\n\t\tif (name === moduleFile || name === templateFile) {\n\t\t\tthrow new CompileError(\n\t\t\t\t`'${name}' in the public directory has the same name as the ${name === moduleFile ? 'compiled module' : 'rendered template'} and would be overwritten, rename it or set 'output.${name === moduleFile ? 'module' : 'template'}'`,\n\t\t\t);\n\t\t}\n\t}\n\n\tawait fs.cp(publicDir, outDir, { recursive: true, force: true });\n}\n\n/**\n * Cleaning removes everything in the output directory, which must not hold the\n * project: the root, the working directory, the templates or an alias target.\n */\nfunction assertCleanable(outDir: string, options: CompileTemplateOptions) {\n\tconst { root, entry } = resolvePaths(options);\n\tconst shown = path.relative(process.cwd(), outDir) || '.';\n\tconst kept: [string, string][] = [\n\t\t[root, 'the root'],\n\t\t[process.cwd(), 'the working directory'],\n\t\t[path.dirname(entry), 'the entry template'],\n\t\t...Object.entries(options.alias ?? {}).map(\n\t\t\t([name, target]): [string, string] => [\n\t\t\t\tpath.resolve(root, target),\n\t\t\t\t`the target of the alias '${name}'`,\n\t\t\t],\n\t\t),\n\t];\n\n\tfor (const [directory, what] of kept) {\n\t\tif (isInside(directory, outDir)) {\n\t\t\tthrow new CompileError(\n\t\t\t\t`Refusing to clean the output directory '${shown}', it contains ${what}. Use another output directory, or --no-clean / 'output.clean: false' to keep its files`,\n\t\t\t);\n\t\t}\n\t}\n}\n\nasync function readContext(file: string, shown: string): Promise<unknown> {\n\tlet text: string;\n\ttry {\n\t\ttext = await fs.readFile(file, 'utf-8');\n\t} catch (cause) {\n\t\tif ((cause as NodeJS.ErrnoException).code === 'ENOENT') {\n\t\t\tthrow new CompileError(`Context file '${shown}' not found`);\n\t\t}\n\t\tthrow new CompileError(`Failed to read the context file '${shown}'`, {\n\t\t\tcause,\n\t\t});\n\t}\n\n\ttry {\n\t\treturn JSON.parse(text);\n\t} catch (cause) {\n\t\tthrow new CompileError(\n\t\t\t`Context file '${shown}' is not valid JSON: ${(cause as Error).message}`,\n\t\t);\n\t}\n}\n\n/** Whether `child` is `parent` or inside of it. */\nfunction isInside(child: string, parent: string): boolean {\n\tconst relative = path.relative(parent, child);\n\treturn (\n\t\trelative === '' ||\n\t\t(!relative.startsWith('..') && !path.isAbsolute(relative))\n\t);\n}\n\nasync function exists(file: string): Promise<boolean> {\n\treturn fs.stat(file).then(\n\t\t() => true,\n\t\t() => false,\n\t);\n}\n\nasync function isDirectory(file: string): Promise<boolean> {\n\treturn fs.stat(file).then(\n\t\t(stats) => stats.isDirectory(),\n\t\t() => false,\n\t);\n}\n\nasync function build(root: string | undefined, flags: BuildFlags) {\n\tconst current = await setup(root, flags);\n\t// nothing is written when there is nothing to build, the watcher waits\n\t// for the entry instead\n\tawait assertEntry(current.options);\n\tawait prepareOutDir(current);\n\tawait copyPublic(current);\n\n\tconst start = performance.now();\n\tconst compiled = await compileTemplate(current.options);\n\tlog.success(`Compiled in ${elapsed(start)}`);\n\n\tawait write(current, compiled, start);\n}\n\n/** Watches the template and restarts when the config file changes. */\nasync function watchBuild(root: string | undefined, flags: BuildFlags) {\n\tlet current = await setup(root, flags);\n\tawait prepareOutDir(current);\n\n\tlet watcher: TemplateWatcher | undefined;\n\tlet watchers: FSWatcher[] = [];\n\tlet restarting = false;\n\n\tconst start = async () => {\n\t\tlet begin = performance.now();\n\t\tlet first = true;\n\t\t/** Shown before what a rebuild prints, after the first build. */\n\t\tlet divider = '';\n\n\t\t/** Once, before the first thing a rebuild prints, its output can be the same. */\n\t\tconst printDivider = () => {\n\t\t\tif (divider) {\n\t\t\t\tconsole.log(divider);\n\t\t\t\tdivider = '';\n\t\t\t}\n\t\t};\n\n\t\ttry {\n\t\t\tawait copyPublic(current);\n\t\t} catch (error) {\n\t\t\tlog.error(error);\n\t\t}\n\n\t\twatcher = await watchTemplate({\n\t\t\t...current.options,\n\t\t\tonStart({ files }) {\n\t\t\t\tbegin = performance.now();\n\t\t\t\tdivider = first ? '' : formatDivider(files);\n\t\t\t},\n\t\t\tasync onCompile(compiled) {\n\t\t\t\tprintDivider();\n\t\t\t\tlog.success(`${first ? 'Compiled' : 'Rebuilt'} in ${elapsed(begin)}`);\n\t\t\t\tawait write(current, compiled, begin);\n\t\t\t\tfirst = false;\n\t\t\t},\n\t\t\tonError(error) {\n\t\t\t\tprintDivider();\n\t\t\t\tlog.error(error);\n\t\t\t},\n\t\t});\n\n\t\tfor (const file of current.loaded.dependencies) {\n\t\t\ttry {\n\t\t\t\tconst configWatcher = watch(file, () => {\n\t\t\t\t\t// saving fires more than once, a restart is enough\n\t\t\t\t\tif (!restarting) {\n\t\t\t\t\t\trestarting = true;\n\t\t\t\t\t\trestart().finally(() => {\n\t\t\t\t\t\t\trestarting = false;\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t\tconfigWatcher.on('error', () => configWatcher.close());\n\t\t\t\twatchers.push(configWatcher);\n\t\t\t} catch {\n\t\t\t\t// a dependency that can not be watched does not restart\n\t\t\t}\n\t\t}\n\n\t\tif (current.publicDir !== undefined) {\n\t\t\twatchers.push(watchPublic(current));\n\t\t}\n\t};\n\n\tconst stopWatchers = () => {\n\t\tfor (const fileWatcher of watchers) {\n\t\t\tfileWatcher.close();\n\t\t}\n\t\twatchers = [];\n\t};\n\n\tconst restart = async () => {\n\t\tlog.info(\n\t\t\t`Config changed, restarting ${styleText('dim', path.relative(process.cwd(), current.loaded.file ?? ''))}`,\n\t\t);\n\t\tstopWatchers();\n\t\tawait watcher?.close();\n\t\ttry {\n\t\t\tcurrent = await setup(root, flags);\n\t\t} catch (error) {\n\t\t\tlog.error(error);\n\t\t}\n\t\tawait start();\n\t};\n\n\tawait start();\n\tlog.info(\n\t\t`Watching for changes ${styleText('dim', '(press Ctrl+C to stop)')}`,\n\t);\n\n\tconst stop = async () => {\n\t\tstopWatchers();\n\t\tawait watcher?.close();\n\t\t// the process ends once nothing is left running: `process.exit` would skip\n\t\t// the cleanup of rspack's native bindings, which then warn about leaks,\n\t\t// so it is only a fallback for something left running, a plugin's timer\n\t\tsetTimeout(() => process.exit(0), 3000).unref();\n\t};\n\tprocess.once('SIGINT', stop);\n\tprocess.once('SIGTERM', stop);\n}\n\n/** Copies the public directory again when something in it changes. */\nfunction watchPublic(current: BuildSetup): FSWatcher {\n\tconst publicDir = current.publicDir as string;\n\tconst changed = new Set<string>();\n\tlet timer: NodeJS.Timeout | undefined;\n\n\tconst sync = async () => {\n\t\tconst names = [...changed];\n\t\tchanged.clear();\n\t\ttry {\n\t\t\t// what was deleted from the public directory goes from the output too\n\t\t\tfor (const name of names) {\n\t\t\t\tif (!(await exists(path.join(publicDir, name)))) {\n\t\t\t\t\tawait fs.rm(path.join(current.outDir, name), {\n\t\t\t\t\t\trecursive: true,\n\t\t\t\t\t\tforce: true,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\t\t\tawait copyPublic(current);\n\t\t\tlog.success(\n\t\t\t\t`Copied ${styleText('dim', path.relative(process.cwd(), publicDir))}`,\n\t\t\t);\n\t\t} catch (error) {\n\t\t\tlog.error(error);\n\t\t}\n\t};\n\n\tconst publicWatcher = watch(\n\t\tpublicDir,\n\t\t{ recursive: true },\n\t\t(_event, name) => {\n\t\t\tif (name) {\n\t\t\t\tchanged.add(name);\n\t\t\t}\n\t\t\tclearTimeout(timer);\n\t\t\ttimer = setTimeout(sync, 50);\n\t\t},\n\t);\n\tpublicWatcher.on('error', () => publicWatcher.close());\n\tpublicWatcher.on('close', () => clearTimeout(timer));\n\treturn publicWatcher;\n}\n\nasync function prepareOutDir({ outDir, clean }: BuildSetup) {\n\tif (clean) {\n\t\tawait fs.rm(outDir, { recursive: true, force: true });\n\t}\n\tawait fs.mkdir(outDir, { recursive: true });\n}\n\n/**\n * Writes the compiled module and the rendered template, validated and\n * formatted after rendering when enabled.\n */\nasync function write(\n\tcurrent: BuildSetup,\n\tcompiled: CompiledTemplate,\n\tbegin: number,\n) {\n\tconst { outDir, moduleFile, templateFile } = current;\n\tconst written: WrittenFile[] = [];\n\tlet theme: WrittenTheme | undefined;\n\n\tif (moduleFile) {\n\t\tconst file = path.join(outDir, moduleFile);\n\t\tawait fs.writeFile(file, compiled.source);\n\t\twritten.push({\n\t\t\tpath: path.relative(process.cwd(), file),\n\t\t\tcontent: compiled.source,\n\t\t});\n\t}\n\tif (templateFile) {\n\t\ttheme = await writeTheme(current, compiled, templateFile);\n\t\twritten.unshift(theme.file);\n\t}\n\n\tconst stats = await collectStats(\n\t\tcompiled,\n\t\twritten,\n\t\ttheme?.info && { ...theme.file, info: theme.info },\n\t);\n\tconsole.log(\n\t\tformatStats(stats, current.sizes, { previousTheme: current.theme }),\n\t);\n\tcurrent.sizes = new Map(stats.files.map(({ path, size }) => [path, size]));\n\tcurrent.theme = stats.theme;\n\tlog.success(`Built in ${elapsed(begin)}`);\n}\n\n/** `─── 14:32:05 · src/header.hbs +2 ───────`, dim. */\nfunction formatDivider(files: readonly string[]): string {\n\tconst time = new Date().toLocaleTimeString('en-GB', { hour12: false });\n\tconst [file, ...others] = files.map((item) =>\n\t\tpath.relative(process.cwd(), item),\n\t);\n\tconst what = file\n\t\t? ` · ${file}${others.length > 0 ? ` +${others.length}` : ''}`\n\t\t: '';\n\tconst text = `─── ${time}${what} `;\n\treturn `\\n${styleText('dim', text + '─'.repeat(Math.max(3, 50 - text.length)))}`;\n}\n\ninterface WrittenTheme {\n\tfile: WrittenFile;\n\t/** What it is made of, when it is validated. */\n\tinfo?: XmlInfo;\n}\n\n/** Renders, validates and formats the theme, as enabled, and writes it. */\nasync function writeTheme(\n\tcurrent: BuildSetup,\n\tcompiled: CompiledTemplate,\n\ttemplateFile: string,\n): Promise<WrittenTheme> {\n\tconst { outDir, context } = current;\n\tconst file = path.join(outDir, templateFile);\n\tconst shown = path.relative(process.cwd(), file);\n\n\t// the same as anywhere else the compiled module is rendered\n\tlet start = performance.now();\n\tconst renderer = createRenderer(compiled);\n\tconst rendered = await renderer.render(context);\n\tlog.success(`Rendered in ${elapsed(start)}`);\n\n\tif (!current.validate) {\n\t\tawait fs.writeFile(file, rendered);\n\t\treturn { file: { path: shown, content: rendered } };\n\t}\n\n\tstart = performance.now();\n\tlet result: XmlResult;\n\ttry {\n\t\tresult = processXml(rendered, { path: shown, format: current.format });\n\t} catch (error) {\n\t\t// written anyway, to look at where it is invalid\n\t\tawait fs.writeFile(file, rendered);\n\t\tthrow new CompileError('The rendered template is not valid XML', {\n\t\t\tcause: error,\n\t\t\tloc: (error as XmlError).loc,\n\t\t});\n\t}\n\tfor (const { message, loc } of result.warnings) {\n\t\tlog.warn(withLocation(message, loc));\n\t}\n\tlog.success(\n\t\t`${current.format ? 'Formatted' : 'Validated'} in ${elapsed(start)}`,\n\t);\n\n\tawait fs.writeFile(file, result.xml);\n\treturn { file: { path: shown, content: result.xml }, info: result.info };\n}\n\n/**\n * A blank line, `blogger-hbs v0.0.4` right-aligned on a cyan line under it,\n * before what a build prints.\n */\nfunction printHeader(): void {\n\tconst text = `blogger-hbs v${version}`;\n\tconst width = text.length + 2;\n\tconsole.log(\n\t\t`\\n${' '.repeat(width - text.length)}${styleText('bold', 'blogger-hbs')} ${styleText('dim', `v${version}`)}\\n${styleText('cyan', '─'.repeat(width))}`,\n\t);\n}\n\nfunction elapsed(start: number): string {\n\treturn styleText('yellow', `${Math.round(performance.now() - start)}ms`);\n}\n\n/**\n * The message of the error and of everything that caused it, a cause whose\n * message is already in the one before is not repeated. The lines of a\n * message are indented under its first.\n */\nfunction formatError(error: unknown): string {\n\tconst lines: string[] = [];\n\tlet previous = '';\n\tlet current: unknown = error;\n\n\twhile (current !== undefined) {\n\t\tconst message =\n\t\t\tcurrent instanceof Error ? current.message : String(current);\n\t\tif (lines.length === 0 || !previous.includes(message)) {\n\t\t\tlines.push(\n\t\t\t\t`${lines.length === 0 ? '' : 'Caused by: '}${message.replaceAll('\\n', '\\n ')}`,\n\t\t\t);\n\t\t}\n\t\tprevious = message;\n\t\tcurrent = current instanceof Error ? current.cause : undefined;\n\t}\n\n\treturn lines.join('\\n ');\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAqCA,MAAM,EAAE,YAAY,KAAK,MACxB,MAAM,GAAG,SAAS,IAAI,IAAI,sBAAsB,YAAY,GAAG,GAAG,OAAO,CAC1E;AAkCA,MAAM,MAAM;CACX,UAAU,YACT,QAAQ,IAAI,GAAG,UAAU,SAAS,GAAG,EAAE,GAAG,SAAS;CACpD,OAAO,YACN,QAAQ,IAAI,GAAG,UAAU,QAAQ,GAAG,EAAE,GAAG,SAAS;CACnD,OAAO,YACN,QAAQ,KAAK,GAAG,UAAU,UAAU,GAAG,EAAE,GAAG,SAAS;CACtD,QAAQ,UACP,QAAQ,MAAM,GAAG,UAAU,OAAO,GAAG,EAAE,GAAG,YAAY,KAAK,GAAG;AAChE;AAEA,MAAM,MAAM,IAAI,aAAa;AAE7B,IACE,QAAQ,UAAU,oCAAoC,CAAC,CACvD,MAAM,OAAO,CAAC,CACd,OAAO,uBAAuB,yBAAyB,CAAC,CACxD,OAAO,kBAAkB,sCAAsC,CAAC,CAChE,OAAO,uBAAuB,wCAAwC,CAAC,CACvE,OAAO,oBAAoB,2CAA2C,CAAC,CACvE,OAAO,eAAe,iCAAiC,CAAC,CACxD,OAAO,cAAc,wCAAwC,CAAC,CAC9D,OACA,iBACA,6GACD,CAAC,CACA,OAAO,eAAe,qCAAqC,CAAC,CAC5D,QAAQ,aAAa,CAAC,CACtB,QAAQ,qBAAqB,CAAC,CAC9B,QAAQ,kEAAkE,CAAC,CAC3E,OAAO,OAAO,SAAkB,aAAyB;CACzD,YAAY;CAEZ,MAAM,QAAQ,UACb,UAAU,KAAA,IAAY,KAAA,IAAY,OAAO,KAAK;CAC/C,MAAM,OAAO,KAAK,OAAO;CACzB,MAAM,QAAoB;EAC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QAAQ,OAAuB;CACvC,OAAO,UAAU,UAAU,GAAG,KAAK,MAAM,YAAY,IAAI,IAAI,KAAK,EAAE,GAAG;AACxE;;;;;;AAOA,SAAS,YAAY,OAAwB;CAC5C,MAAM,QAAkB,CAAC;CACzB,IAAI,WAAW;CACf,IAAI,UAAmB;CAEvB,OAAO,YAAY,KAAA,GAAW;EAC7B,MAAM,UACL,mBAAmB,QAAQ,QAAQ,UAAU,OAAO,OAAO;EAC5D,IAAI,MAAM,WAAW,KAAK,CAAC,SAAS,SAAS,OAAO,GACnD,MAAM,KACL,GAAG,MAAM,WAAW,IAAI,KAAK,gBAAgB,QAAQ,WAAW,MAAM,MAAM,GAC7E;EAED,WAAW;EACX,UAAU,mBAAmB,QAAQ,QAAQ,QAAQ,KAAA;CACtD;CAEA,OAAO,MAAM,KAAK,MAAM;AACzB"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { CompiledTemplate } from "../compiler/compile.js";
|
|
2
|
+
import "../compiler/index.js";
|
|
3
|
+
import { XmlInfo } from "../xml/info.js";
|
|
4
|
+
import "../xml/index.js";
|
|
5
|
+
//#region src/cli/stats.d.ts
|
|
6
|
+
export interface WrittenFile {
|
|
7
|
+
/** As shown, relative to the working directory. */
|
|
8
|
+
path: string;
|
|
9
|
+
content: string;
|
|
10
|
+
}
|
|
11
|
+
export interface BuildStats {
|
|
12
|
+
files: {
|
|
13
|
+
path: string;
|
|
14
|
+
size: number;
|
|
15
|
+
gzip: number;
|
|
16
|
+
}[];
|
|
17
|
+
/** What the rendered theme is made of, when it is validated. */
|
|
18
|
+
theme?: {
|
|
19
|
+
path: string;
|
|
20
|
+
scripts: {
|
|
21
|
+
count: number;
|
|
22
|
+
size: number;
|
|
23
|
+
};
|
|
24
|
+
styles: {
|
|
25
|
+
count: number;
|
|
26
|
+
size: number;
|
|
27
|
+
};
|
|
28
|
+
markup: number;
|
|
29
|
+
templates: number;
|
|
30
|
+
partials: number;
|
|
31
|
+
sections: number;
|
|
32
|
+
widgets: number;
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* The sizes of the files written, and what the theme is made of when it is
|
|
37
|
+
* validated: its scripts and styles from the chunks, its sections and
|
|
38
|
+
* widgets from `processXml`.
|
|
39
|
+
*/
|
|
40
|
+
export declare function collectStats(compiled: CompiledTemplate, files: readonly WrittenFile[], theme?: WrittenFile & {
|
|
41
|
+
info: XmlInfo;
|
|
42
|
+
}): Promise<BuildStats>;
|
|
43
|
+
/** `950 B`, `82.4 kB`, `1.20 MB`, in units of 1000 bytes. */
|
|
44
|
+
export declare function formatSize(size: number): string;
|
|
45
|
+
/**
|
|
46
|
+
* The tables of the files written and of what the theme is made of. A size
|
|
47
|
+
* is followed by its change since `previous`, by path.
|
|
48
|
+
*/
|
|
49
|
+
export declare function formatStats({ files, theme }: BuildStats, previous?: ReadonlyMap<string, number>,
|
|
50
|
+
/**
|
|
51
|
+
* What the theme was made of at the last build, for the change of every
|
|
52
|
+
* count and size since.
|
|
53
|
+
*/
|
|
54
|
+
{ previousTheme }?: {
|
|
55
|
+
previousTheme?: BuildStats['theme'];
|
|
56
|
+
}): string;
|
|
57
|
+
//#endregion
|
|
58
|
+
//# sourceMappingURL=stats.d.ts.map
|