@compact-design/html 0.1.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.
- package/LICENSE +373 -0
- package/README.md +44 -0
- package/dist/css.d.ts +31 -0
- package/dist/index.cjs +705 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +679 -0
- package/dist/render.d.ts +16 -0
- package/package.json +58 -0
- package/scripts/render.mjs +67 -0
package/dist/render.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type InternalDocument, type RepairIssue } from "@compact-design/core";
|
|
2
|
+
export interface RenderOptions {
|
|
3
|
+
title?: string;
|
|
4
|
+
background?: string;
|
|
5
|
+
}
|
|
6
|
+
export interface RenderResult {
|
|
7
|
+
html: string;
|
|
8
|
+
body: string;
|
|
9
|
+
css: string;
|
|
10
|
+
}
|
|
11
|
+
export declare class RenderError extends Error {
|
|
12
|
+
readonly issues: RepairIssue[];
|
|
13
|
+
constructor(message: string, issues?: RepairIssue[]);
|
|
14
|
+
}
|
|
15
|
+
export declare function render(input: unknown, options?: RenderOptions): RenderResult;
|
|
16
|
+
export declare function renderDocument(document: InternalDocument, options?: RenderOptions): RenderResult;
|
package/package.json
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@compact-design/html",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "HTML and CSS renderer for Compact Design JSON.",
|
|
5
|
+
"license": "MPL-2.0",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "./dist/index.cjs",
|
|
8
|
+
"module": "./dist/index.js",
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"bin": {
|
|
11
|
+
"compact-design-html": "./scripts/render.mjs"
|
|
12
|
+
},
|
|
13
|
+
"exports": {
|
|
14
|
+
".": {
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"import": "./dist/index.js",
|
|
17
|
+
"require": "./dist/index.cjs"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"files": [
|
|
21
|
+
"dist",
|
|
22
|
+
"README.md",
|
|
23
|
+
"LICENSE",
|
|
24
|
+
"scripts/render.mjs"
|
|
25
|
+
],
|
|
26
|
+
"publishConfig": {
|
|
27
|
+
"access": "public"
|
|
28
|
+
},
|
|
29
|
+
"repository": {
|
|
30
|
+
"type": "git",
|
|
31
|
+
"url": "git+https://github.com/Elliot727/compact-design.git",
|
|
32
|
+
"directory": "packages/html"
|
|
33
|
+
},
|
|
34
|
+
"homepage": "https://github.com/Elliot727/compact-design/tree/main/packages/html#readme",
|
|
35
|
+
"bugs": {
|
|
36
|
+
"url": "https://github.com/Elliot727/compact-design/issues"
|
|
37
|
+
},
|
|
38
|
+
"keywords": [
|
|
39
|
+
"compact-design",
|
|
40
|
+
"html",
|
|
41
|
+
"css",
|
|
42
|
+
"renderer"
|
|
43
|
+
],
|
|
44
|
+
"engines": {
|
|
45
|
+
"node": ">=18"
|
|
46
|
+
},
|
|
47
|
+
"scripts": {
|
|
48
|
+
"build": "node scripts/build.mjs",
|
|
49
|
+
"prepack": "npm run build",
|
|
50
|
+
"test": "node scripts/test.mjs",
|
|
51
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
52
|
+
"lint": "node scripts/lint.mjs",
|
|
53
|
+
"render": "node scripts/render.mjs"
|
|
54
|
+
},
|
|
55
|
+
"dependencies": {
|
|
56
|
+
"@compact-design/core": "0.1.0"
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { existsSync } from "node:fs";
|
|
3
|
+
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
|
4
|
+
import { dirname, isAbsolute, resolve } from "node:path";
|
|
5
|
+
import { fileURLToPath } from "node:url";
|
|
6
|
+
import { parseArgs } from "node:util";
|
|
7
|
+
|
|
8
|
+
const { values, positionals } = parseArgs({
|
|
9
|
+
allowPositionals: true,
|
|
10
|
+
options: {
|
|
11
|
+
out: { type: "string", short: "o" },
|
|
12
|
+
title: { type: "string" },
|
|
13
|
+
help: { type: "boolean", short: "h" }
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
if (values.help || positionals.length !== 1) {
|
|
18
|
+
console.error("Usage: compact-design-html <document.json> [-o out.html] [--title Title]");
|
|
19
|
+
process.exit(values.help ? 0 : 1);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const packageRoot = resolve(dirname(fileURLToPath(import.meta.url)), "..");
|
|
23
|
+
const repoRoot = resolve(packageRoot, "../..");
|
|
24
|
+
|
|
25
|
+
function resolveExistingPath(input) {
|
|
26
|
+
if (isAbsolute(input)) return input;
|
|
27
|
+
const candidates = [
|
|
28
|
+
resolve(process.cwd(), input),
|
|
29
|
+
process.env.INIT_CWD ? resolve(process.env.INIT_CWD, input) : "",
|
|
30
|
+
resolve(repoRoot, input)
|
|
31
|
+
].filter(Boolean);
|
|
32
|
+
return candidates.find((path) => existsSync(path)) || candidates[0];
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function resolveOutputPath(input) {
|
|
36
|
+
if (isAbsolute(input)) return input;
|
|
37
|
+
return resolve(process.env.INIT_CWD || process.cwd(), input);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const { render, RenderError } = await import("../dist/index.js");
|
|
41
|
+
const input = resolveExistingPath(positionals[0]);
|
|
42
|
+
const source = await readFile(input, "utf8");
|
|
43
|
+
let document;
|
|
44
|
+
try {
|
|
45
|
+
document = JSON.parse(source);
|
|
46
|
+
} catch (error) {
|
|
47
|
+
console.error(error instanceof Error ? error.message : error);
|
|
48
|
+
process.exit(1);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
try {
|
|
52
|
+
const result = render(document, { title: values.title });
|
|
53
|
+
if (values.out) {
|
|
54
|
+
const out = resolveOutputPath(values.out);
|
|
55
|
+
await mkdir(dirname(out), { recursive: true });
|
|
56
|
+
await writeFile(out, result.html);
|
|
57
|
+
} else {
|
|
58
|
+
process.stdout.write(result.html);
|
|
59
|
+
}
|
|
60
|
+
} catch (error) {
|
|
61
|
+
if (error instanceof RenderError) {
|
|
62
|
+
console.error(error.message);
|
|
63
|
+
for (const issue of error.issues) console.error(` ${issue.path}: ${issue.message}`);
|
|
64
|
+
process.exit(1);
|
|
65
|
+
}
|
|
66
|
+
throw error;
|
|
67
|
+
}
|