dekit-cli 0.2.3 → 0.4.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/README.md +16 -0
- package/bin/dekit.ts +12 -12
- package/dist/editor/assets/{index-yt1AtkL3.js → index-D16Bm-Rw.js} +13 -13
- package/dist/editor/assets/{index-Bx5YsS46.css → index-HLKs1tz-.css} +1 -1
- package/dist/editor/index.html +2 -2
- package/editor/src/App.tsx +33 -7
- package/editor/src/styles/editor.css +4 -2
- package/editor/vite.config.ts +6 -0
- package/package.json +3 -2
- package/src/cli/add.test.ts +14 -12
- package/src/cli/init.test.ts +15 -17
- package/src/cli/init.ts +7 -5
- package/src/cli/ls.test.ts +1 -1
- package/src/cli/resolve.test.ts +3 -3
- package/src/cli/screenshot.test.ts +4 -4
- package/src/design-server.ts +5 -4
- package/src/injected/inspector.ts +37 -3
- package/src/parser.test.ts +8 -8
- package/src/server.ts +32 -6
- package/src/types.ts +1 -1
- package/src/vite-plugin-dekit.test.ts +21 -14
- package/src/vite-plugin-dekit.ts +1 -0
package/src/server.ts
CHANGED
|
@@ -1,27 +1,53 @@
|
|
|
1
1
|
import type { DesignConfig } from "./types.js";
|
|
2
2
|
import { startDesignServer } from "./design-server.js";
|
|
3
3
|
import { startEditorServer } from "./editor-server.js";
|
|
4
|
+
import { createServer } from "node:net";
|
|
5
|
+
|
|
6
|
+
const DEFAULT_PORT = 7980;
|
|
4
7
|
|
|
5
8
|
export interface ServerOptions {
|
|
6
9
|
config: DesignConfig;
|
|
7
|
-
port
|
|
8
|
-
designPort: number;
|
|
10
|
+
port?: number;
|
|
9
11
|
noOpen?: boolean;
|
|
10
12
|
}
|
|
11
13
|
|
|
14
|
+
async function findAvailablePort(preferred: number): Promise<number> {
|
|
15
|
+
return new Promise((resolve, reject) => {
|
|
16
|
+
const srv = createServer();
|
|
17
|
+
srv.listen(preferred, () => {
|
|
18
|
+
srv.close(() => resolve(preferred));
|
|
19
|
+
});
|
|
20
|
+
srv.on("error", () => {
|
|
21
|
+
// Preferred port taken, use random
|
|
22
|
+
const srv2 = createServer();
|
|
23
|
+
srv2.listen(0, () => {
|
|
24
|
+
const addr = srv2.address();
|
|
25
|
+
const port = typeof addr === "object" && addr ? addr.port : 0;
|
|
26
|
+
srv2.close(() => resolve(port));
|
|
27
|
+
});
|
|
28
|
+
srv2.on("error", reject);
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
|
|
12
33
|
export async function startServers(options: ServerOptions) {
|
|
13
34
|
const configRef = { current: options.config };
|
|
14
35
|
|
|
15
36
|
console.log("\n Dekit Dev Server\n");
|
|
16
37
|
|
|
17
|
-
const designServer = await startDesignServer(configRef
|
|
38
|
+
const designServer = await startDesignServer(configRef);
|
|
39
|
+
const designAddr = designServer.httpServer!.address();
|
|
40
|
+
const designPort =
|
|
41
|
+
typeof designAddr === "object" && designAddr ? designAddr.port : 0;
|
|
42
|
+
|
|
43
|
+
const editorPort = await findAvailablePort(options.port ?? DEFAULT_PORT);
|
|
18
44
|
const editorServer = await startEditorServer(
|
|
19
45
|
configRef,
|
|
20
|
-
|
|
21
|
-
|
|
46
|
+
editorPort,
|
|
47
|
+
designPort
|
|
22
48
|
);
|
|
23
49
|
|
|
24
|
-
const editorUrl = `http://localhost:${
|
|
50
|
+
const editorUrl = `http://localhost:${editorPort}`;
|
|
25
51
|
console.log(`\n Open ${editorUrl} in your browser\n`);
|
|
26
52
|
|
|
27
53
|
// Try to open browser
|
package/src/types.ts
CHANGED
|
@@ -13,7 +13,7 @@ export interface DesignConfig {
|
|
|
13
13
|
globalStyle: string;
|
|
14
14
|
components: Record<string, ComponentDef>;
|
|
15
15
|
pages: Record<string, PageDef>;
|
|
16
|
-
baseDir: string; // absolute path to directory
|
|
16
|
+
baseDir: string; // absolute path to .dekit/ directory (where dekit.yaml lives)
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
export interface PageRef {
|
|
@@ -3,21 +3,29 @@ import { assemblePageHtml } from "./vite-plugin-dekit.js";
|
|
|
3
3
|
import type { DesignConfig } from "./types.js";
|
|
4
4
|
import { join } from "node:path";
|
|
5
5
|
|
|
6
|
-
const DESIGN_DIR = join(import.meta.dirname, "../example");
|
|
6
|
+
const DESIGN_DIR = join(import.meta.dirname, "../example/.dekit");
|
|
7
7
|
|
|
8
8
|
const mockConfig: DesignConfig = {
|
|
9
9
|
version: 1.0,
|
|
10
10
|
globalStyle: "global.css",
|
|
11
11
|
components: {
|
|
12
|
-
"
|
|
13
|
-
template: "components/
|
|
14
|
-
style: "components/
|
|
12
|
+
"ui-card": {
|
|
13
|
+
template: "components/ui-card/ui-card.html",
|
|
14
|
+
style: "components/ui-card/ui-card.css",
|
|
15
|
+
},
|
|
16
|
+
"ui-button": {
|
|
17
|
+
template: "components/ui-button/ui-button.html",
|
|
18
|
+
style: "components/ui-button/ui-button.css",
|
|
15
19
|
},
|
|
16
20
|
},
|
|
17
21
|
pages: {
|
|
18
|
-
|
|
19
|
-
template: "pages/
|
|
20
|
-
style: "pages/
|
|
22
|
+
home: {
|
|
23
|
+
template: "pages/home/home.html",
|
|
24
|
+
style: "pages/home/home.css",
|
|
25
|
+
},
|
|
26
|
+
showcase: {
|
|
27
|
+
template: "pages/showcase/showcase.html",
|
|
28
|
+
style: "pages/showcase/showcase.css",
|
|
21
29
|
},
|
|
22
30
|
},
|
|
23
31
|
baseDir: DESIGN_DIR,
|
|
@@ -25,13 +33,12 @@ const mockConfig: DesignConfig = {
|
|
|
25
33
|
|
|
26
34
|
describe("assemblePageHtml", () => {
|
|
27
35
|
test("generates valid HTML for a page", async () => {
|
|
28
|
-
const html = await assemblePageHtml(mockConfig, "
|
|
36
|
+
const html = await assemblePageHtml(mockConfig, "home");
|
|
29
37
|
expect(html).toContain("<!DOCTYPE html>");
|
|
30
38
|
expect(html).toContain("global.css");
|
|
31
|
-
expect(html).toContain("pages/
|
|
32
|
-
expect(html).toContain("Welcome to Dekit");
|
|
39
|
+
expect(html).toContain("pages/home/home.css");
|
|
33
40
|
expect(html).toContain("customElements.define");
|
|
34
|
-
expect(html).toContain("
|
|
41
|
+
expect(html).toContain("ui-card");
|
|
35
42
|
});
|
|
36
43
|
|
|
37
44
|
test("throws for unknown page", async () => {
|
|
@@ -41,14 +48,14 @@ describe("assemblePageHtml", () => {
|
|
|
41
48
|
});
|
|
42
49
|
|
|
43
50
|
test("includes inspector script", async () => {
|
|
44
|
-
const html = await assemblePageHtml(mockConfig, "
|
|
51
|
+
const html = await assemblePageHtml(mockConfig, "home");
|
|
45
52
|
expect(html).toContain("postMessage");
|
|
46
53
|
expect(html).toContain("NODE_SELECTED");
|
|
47
54
|
});
|
|
48
55
|
|
|
49
56
|
test("extracts template inner content for component registration", async () => {
|
|
50
|
-
const html = await assemblePageHtml(mockConfig, "
|
|
51
|
-
expect(html).toContain("class=\"
|
|
57
|
+
const html = await assemblePageHtml(mockConfig, "showcase");
|
|
58
|
+
expect(html).toContain("class=\"card\"");
|
|
52
59
|
expect(html).toContain("<slot></slot>");
|
|
53
60
|
expect(html).not.toMatch(/innerHTML\s*=\s*`\s*<template>/);
|
|
54
61
|
});
|
package/src/vite-plugin-dekit.ts
CHANGED
|
@@ -34,6 +34,7 @@ export async function assemblePageHtml(
|
|
|
34
34
|
<head>
|
|
35
35
|
<meta charset="UTF-8">
|
|
36
36
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
37
|
+
<script type="module" src="/@vite/client"></script>
|
|
37
38
|
<link rel="stylesheet" href="/@design/${config.globalStyle}">
|
|
38
39
|
<link rel="stylesheet" href="/@design/${pageDef.style}">
|
|
39
40
|
</head>
|