@lumeland/core 0.0.0-stage → 1.0.0-beta-3
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/LICENSE +21 -0
- package/build/deps/cli.d.ts +1 -0
- package/build/deps/cli.js +1 -0
- package/build/deps/colors.d.ts +1 -0
- package/build/deps/colors.js +1 -0
- package/build/deps/crypto.d.ts +1 -0
- package/build/deps/crypto.js +1 -0
- package/build/deps/dom.d.ts +1 -0
- package/build/deps/dom.js +1 -0
- package/build/deps/esbuild.d.ts +1 -0
- package/build/deps/esbuild.js +1 -0
- package/build/deps/front_matter.d.ts +2 -0
- package/build/deps/front_matter.js +2 -0
- package/build/deps/jsonc.d.ts +1 -0
- package/build/deps/jsonc.js +1 -0
- package/build/deps/lightningcss.d.ts +1 -0
- package/build/deps/lightningcss.js +1 -0
- package/build/deps/media_types.d.ts +2 -0
- package/build/deps/media_types.js +2 -0
- package/build/deps/module.d.ts +1 -0
- package/build/deps/module.js +1 -0
- package/build/deps/path.d.ts +4 -0
- package/build/deps/path.js +11 -0
- package/build/deps/remove-markdown.d.ts +17 -0
- package/build/deps/remove-markdown.js +4 -0
- package/build/deps/resvg.d.ts +3 -0
- package/build/deps/resvg.js +6 -0
- package/build/deps/semver.d.ts +1 -0
- package/build/deps/semver.js +1 -0
- package/build/deps/sharp.d.ts +5 -0
- package/build/deps/sharp.js +16 -0
- package/build/deps/toml.d.ts +1 -0
- package/build/deps/toml.js +1 -0
- package/build/deps/yaml.d.ts +2 -0
- package/build/deps/yaml.js +2 -0
- package/build/src/archetypes.d.ts +20 -0
- package/build/src/archetypes.js +152 -0
- package/build/src/cache.d.ts +22 -0
- package/build/src/cache.js +64 -0
- package/build/src/components.d.ts +61 -0
- package/build/src/components.js +233 -0
- package/build/src/data_loader.d.ts +22 -0
- package/build/src/data_loader.js +63 -0
- package/build/src/debugbar.d.ts +160 -0
- package/build/src/debugbar.js +128 -0
- package/build/src/events.d.ts +33 -0
- package/build/src/events.js +39 -0
- package/build/src/file.d.ts +65 -0
- package/build/src/file.js +143 -0
- package/build/src/formats.d.ts +34 -0
- package/build/src/formats.js +62 -0
- package/build/src/fs.d.ts +39 -0
- package/build/src/fs.js +216 -0
- package/build/src/loaders/binary.d.ts +3 -0
- package/build/src/loaders/binary.js +6 -0
- package/build/src/loaders/json.d.ts +3 -0
- package/build/src/loaders/json.js +18 -0
- package/build/src/loaders/module.d.ts +5 -0
- package/build/src/loaders/module.js +33 -0
- package/build/src/loaders/text.d.ts +3 -0
- package/build/src/loaders/text.js +13 -0
- package/build/src/loaders/toml.d.ts +3 -0
- package/build/src/loaders/toml.js +15 -0
- package/build/src/loaders/yaml.d.ts +3 -0
- package/build/src/loaders/yaml.js +15 -0
- package/build/src/logger.d.ts +29 -0
- package/build/src/logger.js +139 -0
- package/build/src/processors.d.ts +22 -0
- package/build/src/processors.js +55 -0
- package/build/src/renderer.d.ts +66 -0
- package/build/src/renderer.js +212 -0
- package/build/src/scopes.d.ts +11 -0
- package/build/src/scopes.js +51 -0
- package/build/src/scripts.d.ts +22 -0
- package/build/src/scripts.js +66 -0
- package/build/src/searcher.d.ts +53 -0
- package/build/src/searcher.js +334 -0
- package/build/src/server.d.ts +67 -0
- package/build/src/server.js +165 -0
- package/build/src/services/fs.d.ts +60 -0
- package/build/src/services/fs.js +199 -0
- package/build/src/services/global.d.ts +1 -0
- package/build/src/services/global.js +1 -0
- package/build/src/services/hmr.d.ts +13 -0
- package/build/src/services/hmr.js +63 -0
- package/build/src/services/net.d.ts +29 -0
- package/build/src/services/net.js +116 -0
- package/build/src/services/process.d.ts +19 -0
- package/build/src/services/process.js +68 -0
- package/build/src/site.d.ts +369 -0
- package/build/src/site.js +879 -0
- package/build/src/slugifier.d.ts +32 -0
- package/build/src/slugifier.js +60 -0
- package/build/src/source.d.ts +76 -0
- package/build/src/source.js +416 -0
- package/build/src/types.d.ts +66 -0
- package/build/src/types.js +1 -0
- package/build/src/utils/browsers.d.ts +16 -0
- package/build/src/utils/browsers.js +28 -0
- package/build/src/utils/cdn.d.ts +6 -0
- package/build/src/utils/cdn.js +128 -0
- package/build/src/utils/concurrent.d.ts +2 -0
- package/build/src/utils/concurrent.js +15 -0
- package/build/src/utils/css_urls.d.ts +3 -0
- package/build/src/utils/css_urls.js +85 -0
- package/build/src/utils/data_values.d.ts +9 -0
- package/build/src/utils/data_values.js +69 -0
- package/build/src/utils/date.d.ts +9 -0
- package/build/src/utils/date.js +30 -0
- package/build/src/utils/digest.d.ts +4 -0
- package/build/src/utils/digest.js +18 -0
- package/build/src/utils/dom.d.ts +5 -0
- package/build/src/utils/dom.js +33 -0
- package/build/src/utils/dom_links.d.ts +7 -0
- package/build/src/utils/dom_links.js +28 -0
- package/build/src/utils/env.d.ts +4 -0
- package/build/src/utils/env.js +28 -0
- package/build/src/utils/format.d.ts +3 -0
- package/build/src/utils/format.js +45 -0
- package/build/src/utils/fs.d.ts +4 -0
- package/build/src/utils/fs.js +33 -0
- package/build/src/utils/generator.d.ts +4 -0
- package/build/src/utils/generator.js +10 -0
- package/build/src/utils/image.d.ts +3 -0
- package/build/src/utils/image.js +28 -0
- package/build/src/utils/log.d.ts +8 -0
- package/build/src/utils/log.js +22 -0
- package/build/src/utils/lume_config.d.ts +4 -0
- package/build/src/utils/lume_config.js +105 -0
- package/build/src/utils/merge_data.d.ts +7 -0
- package/build/src/utils/merge_data.js +91 -0
- package/build/src/utils/object.d.ts +11 -0
- package/build/src/utils/object.js +36 -0
- package/build/src/utils/page_content.d.ts +1 -0
- package/build/src/utils/page_content.js +9 -0
- package/build/src/utils/page_date.d.ts +3 -0
- package/build/src/utils/page_date.js +38 -0
- package/build/src/utils/page_url.d.ts +9 -0
- package/build/src/utils/page_url.js +72 -0
- package/build/src/utils/path.d.ts +28 -0
- package/build/src/utils/path.js +83 -0
- package/build/src/utils/read.d.ts +14 -0
- package/build/src/utils/read.js +56 -0
- package/build/src/utils/serve_file.d.ts +1 -0
- package/build/src/utils/serve_file.js +164 -0
- package/build/src/utils/tokens.d.ts +2 -0
- package/build/src/utils/tokens.js +19 -0
- package/build/src/watcher.d.ts +60 -0
- package/build/src/watcher.js +130 -0
- package/build/src/writer.d.ts +53 -0
- package/build/src/writer.js +163 -0
- package/package.json +30 -3
- package/README.md +0 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 - Oscar Otero
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { parseArgs } from "deno-std/cli/parse_args.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { parseArgs } from "deno-std/cli/parse_args.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "deno-std/fmt/colors.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "deno-std/fmt/colors.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { createHash } from "node:crypto";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { createHash } from "node:crypto";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "@lumeland/dom";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "@lumeland/dom";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "esbuild";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "esbuild";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { parse } from "deno-std/jsonc/parse.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { parse } from "deno-std/jsonc/parse.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "lightningcss";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "lightningcss";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { registerHooks } from "node:module";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { registerHooks } from "node:module";
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { posix, sep as SEPARATOR } from "node:path";
|
|
2
|
+
export { basename, dirname, extname, join, relative } from "node:path";
|
|
3
|
+
export { globToRegExp } from "deno-std/path/glob_to_regexp.js";
|
|
4
|
+
export { fileURLToPath as fromFileUrl, pathToFileURL as toFileUrl } from "node:url";
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export { posix, sep as SEPARATOR } from "node:path";
|
|
2
|
+
export { basename, dirname, extname, join, relative } from "node:path";
|
|
3
|
+
export { globToRegExp } from "deno-std/path/glob_to_regexp.js";
|
|
4
|
+
export { fileURLToPath as fromFileUrl, pathToFileURL as toFileUrl } from "node:url";
|
|
5
|
+
// posix.dirname
|
|
6
|
+
// posix.join
|
|
7
|
+
// posix.basename
|
|
8
|
+
// posix.extname
|
|
9
|
+
// posix.normalize
|
|
10
|
+
// posix.relative
|
|
11
|
+
// posix.resolve
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export declare function plainText(md: string, options?: RemoveMarkdownOptions): string;
|
|
2
|
+
export interface RemoveMarkdownOptions {
|
|
3
|
+
/** strip list leaders (default: true) */
|
|
4
|
+
stripListLeaders?: boolean;
|
|
5
|
+
/** char to insert instead of stripped list leaders (default: '') */
|
|
6
|
+
listUnicodeChar?: string;
|
|
7
|
+
/** support GitHub-Flavored Markdown (default: true) */
|
|
8
|
+
gfm?: boolean;
|
|
9
|
+
/** replace images with alt-text, if present (default: true) */
|
|
10
|
+
useImgAltText?: boolean;
|
|
11
|
+
/** remove abbreviations, if present (default: false) */
|
|
12
|
+
abbr?: boolean;
|
|
13
|
+
/** replace links with URLs instead anchor text (default: false) */
|
|
14
|
+
replaceLinksWithURL?: boolean;
|
|
15
|
+
/** HTML tags to skip, if present */
|
|
16
|
+
htmlTagsToSkip?: string[];
|
|
17
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { canParse, format, maxSatisfying, parse, parseRange } from "deno-std/semver/mod.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { canParse, format, maxSatisfying, parse, parseRange } from "deno-std/semver/mod.js";
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export type { FormatEnum, ResizeOptions, Sharp } from "sharp";
|
|
2
|
+
import type { Sharp, SharpOptions } from "sharp";
|
|
3
|
+
import { type ResvgRenderOptions } from "./resvg.ts";
|
|
4
|
+
export declare function sharpsToIco(...images: Sharp[]): Promise<any>;
|
|
5
|
+
export declare function create(content: Uint8Array | string, config?: SharpOptions, svgOptions?: ResvgRenderOptions): Sharp;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import sharp from "sharp";
|
|
2
|
+
// @ts-expect-error: no types for ico-endec
|
|
3
|
+
import icoEndec from "ico-endec";
|
|
4
|
+
import { toPng } from "./resvg.js";
|
|
5
|
+
export async function sharpsToIco(...images) {
|
|
6
|
+
const buffers = await Promise.all(images.map((image) => image.toFormat("png").toBuffer()));
|
|
7
|
+
// deno-lint-ignore no-explicit-any
|
|
8
|
+
return icoEndec.encode(buffers.map((buffer) => buffer.buffer));
|
|
9
|
+
}
|
|
10
|
+
export function create(content, config = {}, svgOptions) {
|
|
11
|
+
// It's a SVG
|
|
12
|
+
if (typeof content === "string") {
|
|
13
|
+
return sharp(toPng(content, svgOptions));
|
|
14
|
+
}
|
|
15
|
+
return sharp(content, config);
|
|
16
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { parse } from "deno-std/toml/parse.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { parse } from "deno-std/toml/parse.js";
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export interface Options {
|
|
2
|
+
src: string;
|
|
3
|
+
root: string;
|
|
4
|
+
}
|
|
5
|
+
export default class Archetypes {
|
|
6
|
+
archetypes: Map<string, string | Archetype>;
|
|
7
|
+
src: string;
|
|
8
|
+
root: string;
|
|
9
|
+
constructor(options: Options);
|
|
10
|
+
register(name: string, archetype: string | Archetype): void;
|
|
11
|
+
run(name: string, args?: string[]): Promise<void>;
|
|
12
|
+
save(file: ArchetypeFile): Promise<void>;
|
|
13
|
+
load(name: string): Promise<Archetype>;
|
|
14
|
+
}
|
|
15
|
+
export type Archetype = (...args: string[]) => void | ArchetypeFile | Generator<ArchetypeFile> | AsyncGenerator<ArchetypeFile>;
|
|
16
|
+
export interface ArchetypeFile<T = unknown> {
|
|
17
|
+
base?: "src" | "root";
|
|
18
|
+
path: string;
|
|
19
|
+
content: T | ((prev?: T) => T | Promise<T>);
|
|
20
|
+
}
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExtension) || function (path, preserveJsx) {
|
|
2
|
+
if (typeof path === "string" && /^\.\.?\//.test(path)) {
|
|
3
|
+
return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) {
|
|
4
|
+
return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : (d + ext + "." + cm.toLowerCase() + "js");
|
|
5
|
+
});
|
|
6
|
+
}
|
|
7
|
+
return path;
|
|
8
|
+
};
|
|
9
|
+
import { parse, stringify } from "../deps/yaml.js";
|
|
10
|
+
import { extract, test } from "../deps/front_matter.js";
|
|
11
|
+
import { ensureDir } from "./utils/fs.js";
|
|
12
|
+
import { dirname, join, toFileUrl } from "../deps/path.js";
|
|
13
|
+
import { isGenerator } from "./utils/generator.js";
|
|
14
|
+
import { log } from "./utils/log.js";
|
|
15
|
+
import { isUrl } from "./utils/path.js";
|
|
16
|
+
import { cwd } from "./services/process.js";
|
|
17
|
+
import { readTextFile, writeFile, writeTextFile } from "./services/fs.js";
|
|
18
|
+
export default class Archetypes {
|
|
19
|
+
archetypes = new Map();
|
|
20
|
+
src;
|
|
21
|
+
root;
|
|
22
|
+
constructor(options) {
|
|
23
|
+
this.src = options.src;
|
|
24
|
+
this.root = options.root;
|
|
25
|
+
}
|
|
26
|
+
register(name, archetype) {
|
|
27
|
+
this.archetypes.set(name, archetype);
|
|
28
|
+
}
|
|
29
|
+
async run(name, args = []) {
|
|
30
|
+
let archetype;
|
|
31
|
+
try {
|
|
32
|
+
archetype = await this.load(name);
|
|
33
|
+
}
|
|
34
|
+
catch (cause) {
|
|
35
|
+
log.fatal(`[archetype] Archetype "${name}" not found or is errored.: ${cause.message}`);
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
if (typeof archetype !== "function") {
|
|
39
|
+
log.fatal(`[archetype] Archetype "${name}" is not a valid function.`);
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
if (isGenerator(archetype)) {
|
|
43
|
+
for await (const file of archetype(...args)) {
|
|
44
|
+
await this.save(file);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
const file = archetype(...args);
|
|
49
|
+
if (file) {
|
|
50
|
+
await this.save(file);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
async save(file) {
|
|
55
|
+
const { path, base = "src", content } = file;
|
|
56
|
+
if (!path) {
|
|
57
|
+
throw new Error("Archetype path is required.");
|
|
58
|
+
}
|
|
59
|
+
if (!content) {
|
|
60
|
+
throw new Error("Archetype content is required.");
|
|
61
|
+
}
|
|
62
|
+
const fullPath = join(base === "root" ? this.root : this.src, path);
|
|
63
|
+
if (typeof content === "string" || content instanceof Uint8Array) {
|
|
64
|
+
return await saveFile(fullPath, content);
|
|
65
|
+
}
|
|
66
|
+
if (path.endsWith(".json")) {
|
|
67
|
+
return await runObjectArchetype(fullPath, content, JSON.parse, (o) => JSON.stringify(o, null, 2));
|
|
68
|
+
}
|
|
69
|
+
if (path.endsWith(".yaml") || path.endsWith(".yml")) {
|
|
70
|
+
return await runObjectArchetype(fullPath, content, parse, stringify);
|
|
71
|
+
}
|
|
72
|
+
return await runObjectArchetype(fullPath, content, (content) => {
|
|
73
|
+
if (test(content)) {
|
|
74
|
+
const { attrs, body } = extract(content);
|
|
75
|
+
return { ...attrs, content: body };
|
|
76
|
+
}
|
|
77
|
+
return { content };
|
|
78
|
+
}, (data) => {
|
|
79
|
+
const { content: body, ...frontmatter } = data;
|
|
80
|
+
return `---\n${stringify(frontmatter)}---\n${body || ""}\n`;
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
async load(name) {
|
|
84
|
+
const registered = this.archetypes.get(name);
|
|
85
|
+
if (registered) {
|
|
86
|
+
if (typeof registered === "string") {
|
|
87
|
+
return (await import(__rewriteRelativeImportExtension(registered))).default;
|
|
88
|
+
}
|
|
89
|
+
return registered;
|
|
90
|
+
}
|
|
91
|
+
if (name.startsWith(".")) {
|
|
92
|
+
return (await import(__rewriteRelativeImportExtension(toFileUrl(join(cwd(), name)).href))).default;
|
|
93
|
+
}
|
|
94
|
+
if (isUrl(name)) {
|
|
95
|
+
return (await import(__rewriteRelativeImportExtension(name))).default;
|
|
96
|
+
}
|
|
97
|
+
return (await Promise.any([
|
|
98
|
+
import(__rewriteRelativeImportExtension(toFileUrl(join(this.root, `_archetypes/${name}.ts`)).href)),
|
|
99
|
+
import(__rewriteRelativeImportExtension(toFileUrl(join(this.root, `_archetypes/${name}.js`)).href)),
|
|
100
|
+
])).default;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
async function saveFile(path, content, overwrite = false) {
|
|
104
|
+
ensureDir(dirname(path));
|
|
105
|
+
try {
|
|
106
|
+
if (content instanceof Uint8Array) {
|
|
107
|
+
await writeFile(path, content, !overwrite);
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
await writeTextFile(path, content, !overwrite);
|
|
111
|
+
}
|
|
112
|
+
if (overwrite) {
|
|
113
|
+
log.info(`✔️ Updated file: <gray>${path}</gray>`);
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
log.info(`✔️ Created file: <gray>${path}</gray>`);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
catch (error) {
|
|
120
|
+
if (error.code === "exists") {
|
|
121
|
+
log.warn(`⚠️ File already exists: <gray>${path}</gray>`);
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
throw error;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
async function runObjectArchetype(fullPath, content, parse, stringify) {
|
|
129
|
+
let newContent;
|
|
130
|
+
let overwrite = false;
|
|
131
|
+
if (typeof content === "function") {
|
|
132
|
+
const fn = content;
|
|
133
|
+
const previousContent = await readFile(fullPath);
|
|
134
|
+
newContent = previousContent ? await fn(parse(previousContent)) : await fn();
|
|
135
|
+
overwrite = true;
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
newContent = content;
|
|
139
|
+
}
|
|
140
|
+
return await saveFile(fullPath, stringify(newContent) + "\n", overwrite);
|
|
141
|
+
}
|
|
142
|
+
async function readFile(path) {
|
|
143
|
+
try {
|
|
144
|
+
return await readTextFile(path);
|
|
145
|
+
}
|
|
146
|
+
catch (error) {
|
|
147
|
+
if (error.code === "not-found") {
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
throw error;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export interface Options {
|
|
2
|
+
/** The folder to load the files from */
|
|
3
|
+
folder: string;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Class to manage cache in the _cache folder
|
|
7
|
+
*/
|
|
8
|
+
export default class Cache {
|
|
9
|
+
#private;
|
|
10
|
+
constructor(options: Options);
|
|
11
|
+
/** Save some content in the cache folder */
|
|
12
|
+
set(key: unknown[], value: string | Uint8Array): void;
|
|
13
|
+
/** Remove content from the cache folder */
|
|
14
|
+
remove(key: unknown[]): void;
|
|
15
|
+
getPath(key: unknown[]): string;
|
|
16
|
+
/** Get the content from the cache folder as Uint8Array */
|
|
17
|
+
getBytes(key: unknown[]): Uint8Array<ArrayBuffer> | undefined;
|
|
18
|
+
/** Get the content from the cache folder as string */
|
|
19
|
+
getText(key: unknown[]): string | undefined;
|
|
20
|
+
/** Empty the cache folder */
|
|
21
|
+
clear(): void;
|
|
22
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { emptyDir, ensureDir } from "./utils/fs.js";
|
|
2
|
+
import { posix } from "../deps/path.js";
|
|
3
|
+
import { readFileSync, readTextFileSync, removeSync, writeFileSync, writeTextFileSync, } from "./services/fs.js";
|
|
4
|
+
import { md5 } from "./utils/digest.js";
|
|
5
|
+
/**
|
|
6
|
+
* Class to manage cache in the _cache folder
|
|
7
|
+
*/
|
|
8
|
+
export default class Cache {
|
|
9
|
+
#folder;
|
|
10
|
+
constructor(options) {
|
|
11
|
+
this.#folder = options.folder;
|
|
12
|
+
}
|
|
13
|
+
/** Save some content in the cache folder */
|
|
14
|
+
set(key, value) {
|
|
15
|
+
const path = this.getPath(key);
|
|
16
|
+
ensureDir(posix.dirname(path));
|
|
17
|
+
if (typeof value === "string") {
|
|
18
|
+
writeTextFileSync(path, value);
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
writeFileSync(path, value);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
/** Remove content from the cache folder */
|
|
25
|
+
remove(key) {
|
|
26
|
+
try {
|
|
27
|
+
removeSync(this.getPath(key));
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
// Ignore
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
getPath(key) {
|
|
34
|
+
const paths = key.map((value) => {
|
|
35
|
+
if (value instanceof Uint8Array || typeof value === "string") {
|
|
36
|
+
return md5(value);
|
|
37
|
+
}
|
|
38
|
+
return md5(JSON.stringify(value));
|
|
39
|
+
});
|
|
40
|
+
return posix.join(this.#folder, ...paths);
|
|
41
|
+
}
|
|
42
|
+
/** Get the content from the cache folder as Uint8Array */
|
|
43
|
+
getBytes(key) {
|
|
44
|
+
try {
|
|
45
|
+
return readFileSync(this.getPath(key));
|
|
46
|
+
}
|
|
47
|
+
catch {
|
|
48
|
+
// Ignore
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
/** Get the content from the cache folder as string */
|
|
52
|
+
getText(key) {
|
|
53
|
+
try {
|
|
54
|
+
return readTextFileSync(this.getPath(key));
|
|
55
|
+
}
|
|
56
|
+
catch {
|
|
57
|
+
// Ignore
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
/** Empty the cache folder */
|
|
61
|
+
clear() {
|
|
62
|
+
emptyDir(this.#folder);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { Entry } from "./fs.ts";
|
|
2
|
+
import type { DirectoryData } from "./types.ts";
|
|
3
|
+
import type Formats from "./formats.ts";
|
|
4
|
+
export interface Options {
|
|
5
|
+
/** The registered file formats */
|
|
6
|
+
formats: Formats;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Class to load components from the _components folder.
|
|
10
|
+
*/
|
|
11
|
+
export declare class ComponentLoader {
|
|
12
|
+
#private;
|
|
13
|
+
/** List of loaders and engines used by extensions */
|
|
14
|
+
formats: Formats;
|
|
15
|
+
constructor(options: Options);
|
|
16
|
+
/** Load a directory of components */
|
|
17
|
+
load(dirEntry: Entry, data: DirectoryData, components?: Components): Promise<Components>;
|
|
18
|
+
}
|
|
19
|
+
export type Components = Map<string, Component | Components>;
|
|
20
|
+
export interface Component {
|
|
21
|
+
/** Name of the component (used to get it from templates) */
|
|
22
|
+
name: string;
|
|
23
|
+
/** The function to render the component */
|
|
24
|
+
render: (props: Record<string, unknown>) => string | Promise<string>;
|
|
25
|
+
/** Optional CSS and JS code needed to style the component (global, only inserted once) */
|
|
26
|
+
assets: Map<string, string | Entry>;
|
|
27
|
+
}
|
|
28
|
+
/** Component defined directly by the user */
|
|
29
|
+
export interface UserComponent {
|
|
30
|
+
/** Name of the component (used to get it from templates) */
|
|
31
|
+
name: string;
|
|
32
|
+
/** The function to render the component */
|
|
33
|
+
render: (props: Record<string, unknown>) => string | Promise<string>;
|
|
34
|
+
/** Optional CSS code needed to style the component (global, only inserted once) */
|
|
35
|
+
css?: string;
|
|
36
|
+
/** Optional JS code needed for the component interactivity (global, only inserted once) */
|
|
37
|
+
js?: string;
|
|
38
|
+
}
|
|
39
|
+
export interface ComponentFile {
|
|
40
|
+
/** The content of the component */
|
|
41
|
+
content: unknown;
|
|
42
|
+
/** Optional CSS code needed to style the component (global, only inserted once) */
|
|
43
|
+
css?: string;
|
|
44
|
+
/** Optional JS code needed for the component interactivity (global, only inserted once) */
|
|
45
|
+
js?: string;
|
|
46
|
+
/** If false, the data from the parent directory will not be inherited */
|
|
47
|
+
inheritData?: boolean;
|
|
48
|
+
/** Extra default data stored in the component */
|
|
49
|
+
[key: string]: unknown;
|
|
50
|
+
}
|
|
51
|
+
export declare function compileCSS(filename: string, imports: Map<string, string | Entry>, entries: Map<string, Entry>): Promise<string>;
|
|
52
|
+
export declare function compileJS(filename: string, imports: Map<string, string | Entry>, entries: Map<string, Entry>): Promise<string>;
|
|
53
|
+
export interface ProxyComponents {
|
|
54
|
+
(props?: Record<string, unknown>): any;
|
|
55
|
+
[key: string]: ProxyComponents;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Create and returns a proxy to use the components
|
|
59
|
+
* as comp.name() instead of components.get("name").render()
|
|
60
|
+
*/
|
|
61
|
+
export declare function toProxy(components: Components, extraCode: Map<string, string | Entry>): ProxyComponents;
|