design-embed 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.
Files changed (37) hide show
  1. package/LICENSE +9 -0
  2. package/README.md +5 -0
  3. package/dist/args.js +36 -0
  4. package/dist/cli.js +35 -0
  5. package/dist/commands/check.js +4 -0
  6. package/dist/commands/compile.js +157 -0
  7. package/dist/commands/generateTests.js +113 -0
  8. package/dist/commands/init.js +102 -0
  9. package/dist/commands/plugin.js +68 -0
  10. package/dist/index.js +2 -0
  11. package/node_modules/@design-embed/config/README.md +5 -0
  12. package/node_modules/@design-embed/config/dist/index.js +283 -0
  13. package/node_modules/@design-embed/config/package.json +19 -0
  14. package/node_modules/@design-embed/config/src/index.ts +518 -0
  15. package/node_modules/@design-embed/core/README.md +5 -0
  16. package/node_modules/@design-embed/core/dist/diagnostics/diagnostic.js +3 -0
  17. package/node_modules/@design-embed/core/dist/diagnostics/jsonDiagnostic.js +35 -0
  18. package/node_modules/@design-embed/core/dist/index.js +351 -0
  19. package/node_modules/@design-embed/core/dist/pipeline/checkMode.js +29 -0
  20. package/node_modules/@design-embed/core/dist/plugins/pluginApi.js +1 -0
  21. package/node_modules/@design-embed/core/dist/plugins/pluginRegistry.js +25 -0
  22. package/node_modules/@design-embed/core/package.json +19 -0
  23. package/node_modules/@design-embed/core/src/diagnostics/diagnostic.ts +18 -0
  24. package/node_modules/@design-embed/core/src/diagnostics/jsonDiagnostic.ts +51 -0
  25. package/node_modules/@design-embed/core/src/index.ts +591 -0
  26. package/node_modules/@design-embed/core/src/pipeline/checkMode.ts +46 -0
  27. package/node_modules/@design-embed/core/src/plugins/pluginApi.ts +78 -0
  28. package/node_modules/@design-embed/core/src/plugins/pluginRegistry.ts +37 -0
  29. package/package.json +42 -0
  30. package/src/args.ts +57 -0
  31. package/src/cli.ts +42 -0
  32. package/src/commands/check.ts +7 -0
  33. package/src/commands/compile.ts +198 -0
  34. package/src/commands/generateTests.ts +140 -0
  35. package/src/commands/init.ts +114 -0
  36. package/src/commands/plugin.ts +89 -0
  37. package/src/index.ts +2 -0
@@ -0,0 +1,37 @@
1
+ import type { SourcePlugin, TransformerPlugin } from "./pluginApi.ts";
2
+
3
+ export class PluginRegistry {
4
+ #sourcePlugins = new Map<string, SourcePlugin>();
5
+ #transformers: TransformerPlugin[] = [];
6
+
7
+ registerSource(plugin: SourcePlugin): void {
8
+ this.#sourcePlugins.set(plugin.name, plugin);
9
+ }
10
+
11
+ getSource(name: string): SourcePlugin | undefined {
12
+ return this.#sourcePlugins.get(name);
13
+ }
14
+
15
+ listSources(): SourcePlugin[] {
16
+ return [...this.#sourcePlugins.values()].sort((left, right) =>
17
+ left.name.localeCompare(right.name),
18
+ );
19
+ }
20
+
21
+ registerTransformer(plugin: TransformerPlugin): void {
22
+ this.#transformers.push(plugin);
23
+ }
24
+
25
+ listTransformers(): TransformerPlugin[] {
26
+ return sortTransformers(this.#transformers);
27
+ }
28
+ }
29
+
30
+ export function sortTransformers(
31
+ transformers: TransformerPlugin[],
32
+ ): TransformerPlugin[] {
33
+ return [...transformers].sort((left, right) => {
34
+ const orderDelta = (left.order ?? 0) - (right.order ?? 0);
35
+ return orderDelta || left.name.localeCompare(right.name);
36
+ });
37
+ }
package/package.json ADDED
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "design-embed",
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "private": false,
6
+ "publishConfig": {
7
+ "access": "public"
8
+ },
9
+ "exports": {
10
+ ".": {
11
+ "types": "./src/index.ts",
12
+ "development": "./src/index.ts",
13
+ "default": "./dist/index.js"
14
+ }
15
+ },
16
+ "files": [
17
+ "dist",
18
+ "src",
19
+ "!src/**/*.test.ts",
20
+ "README.md"
21
+ ],
22
+ "bin": {
23
+ "design-embed": "./dist/cli.js"
24
+ },
25
+ "dependencies": {
26
+ "@design-embed/config": "0.1.0",
27
+ "@design-embed/core": "0.1.0",
28
+ "@design-embed/target-html": "0.1.0",
29
+ "@design-embed/target-react": "0.1.0"
30
+ },
31
+ "bundledDependencies": [
32
+ "@design-embed/config",
33
+ "@design-embed/core"
34
+ ],
35
+ "scripts": {
36
+ "dev": "node src/cli.ts",
37
+ "compile:react": "node src/cli.ts react",
38
+ "compile:html": "node src/cli.ts html",
39
+ "compile:vanjs": "node src/cli.ts vanjs",
40
+ "get-raw": "node src/cli.ts raw"
41
+ }
42
+ }
package/src/args.ts ADDED
@@ -0,0 +1,57 @@
1
+ export interface ParsedArgs {
2
+ command: string;
3
+ positionals: string[];
4
+ flags: Record<string, string | boolean>;
5
+ }
6
+
7
+ export function parseArgs(args: string[]): ParsedArgs {
8
+ const positionals: string[] = [];
9
+ const flags: Record<string, string | boolean> = {};
10
+
11
+ for (let index = 0; index < args.length; index += 1) {
12
+ const value = args[index];
13
+ if (!value?.startsWith("--")) {
14
+ if (value) {
15
+ positionals.push(value);
16
+ }
17
+ continue;
18
+ }
19
+
20
+ const next = args[index + 1];
21
+ if (!next || next.startsWith("--")) {
22
+ flags[value] = true;
23
+ continue;
24
+ }
25
+
26
+ flags[value] = next;
27
+ index += 1;
28
+ }
29
+
30
+ const [command = "compile", ...rest] = positionals;
31
+ return {
32
+ command,
33
+ positionals: rest,
34
+ flags,
35
+ };
36
+ }
37
+
38
+ export function getStringFlag(
39
+ flags: Record<string, string | boolean>,
40
+ name: string,
41
+ ): string | undefined {
42
+ const value = flags[name];
43
+ return typeof value === "string" ? value : undefined;
44
+ }
45
+
46
+ export function getBooleanFlag(
47
+ flags: Record<string, string | boolean>,
48
+ name: string,
49
+ ): boolean {
50
+ return flags[name] === true;
51
+ }
52
+
53
+ export function getFormat(
54
+ flags: Record<string, string | boolean>,
55
+ ): "json" | "text" {
56
+ return flags["--format"] === "json" ? "json" : "text";
57
+ }
package/src/cli.ts ADDED
@@ -0,0 +1,42 @@
1
+ #!/usr/bin/env node
2
+ import { parseArgs } from "./args.ts";
3
+ import { runCheckCommand } from "./commands/check.ts";
4
+ import { runCompileCommand } from "./commands/compile.ts";
5
+ import { runGenerateTestsCommand } from "./commands/generateTests.ts";
6
+ import { runInitCommand } from "./commands/init.ts";
7
+ import { runPluginCommand } from "./commands/plugin.ts";
8
+
9
+ async function main(): Promise<number> {
10
+ const args = process.argv.slice(2);
11
+ const parsed = parseArgs(args);
12
+
13
+ if (args[0] === "check") {
14
+ return runCheckCommand(parsed.flags);
15
+ }
16
+
17
+ if (args[0] === "plugin") {
18
+ return runPluginCommand(parsed.positionals[0], parsed.flags);
19
+ }
20
+
21
+ if (args[0] === "generate-tests") {
22
+ return runGenerateTestsCommand(parsed.flags);
23
+ }
24
+
25
+ if (args[0] === "init") {
26
+ return runInitCommand(parsed.flags);
27
+ }
28
+
29
+ return runCompileCommand(parsed.flags);
30
+ }
31
+
32
+ main()
33
+ .then((code) => {
34
+ if (code !== 0) {
35
+ process.exit(code);
36
+ }
37
+ })
38
+ .catch((error) => {
39
+ const message = error instanceof Error ? error.message : String(error);
40
+ console.error(`Pipeline failed: ${message}`);
41
+ process.exit(1);
42
+ });
@@ -0,0 +1,7 @@
1
+ import { runCompileCommand } from "./compile.ts";
2
+
3
+ export async function runCheckCommand(
4
+ flags: Record<string, string | boolean>,
5
+ ): Promise<number> {
6
+ return runCompileCommand(flags, { check: true });
7
+ }
@@ -0,0 +1,198 @@
1
+ import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
2
+ import { dirname, isAbsolute, resolve } from "node:path";
3
+ import { type DesignEmbedConfig, loadConfig } from "@design-embed/config";
4
+ import {
5
+ checkGeneratedFiles,
6
+ type Diagnostic,
7
+ embed,
8
+ formatDiagnosticText,
9
+ type TransformerPlugin,
10
+ toJsonDiagnostics,
11
+ } from "@design-embed/core";
12
+ import { htmlEmitter } from "@design-embed/target-html";
13
+ import { reactEmitter } from "@design-embed/target-react";
14
+ import { getBooleanFlag, getFormat, getStringFlag } from "../args.ts";
15
+
16
+ export interface CompileCommandOptions {
17
+ check?: boolean;
18
+ }
19
+
20
+ export async function runCompileCommand(
21
+ flags: Record<string, string | boolean>,
22
+ options: CompileCommandOptions = {},
23
+ ): Promise<number> {
24
+ const cwd = resolve(process.cwd(), getStringFlag(flags, "--cwd") ?? ".");
25
+ const inputPath = getStringFlag(flags, "--input");
26
+ const configPath = getStringFlag(flags, "--config");
27
+ const quiet = getBooleanFlag(flags, "--quiet");
28
+ const format = getFormat(flags);
29
+ const diagnostics: Diagnostic[] = [];
30
+
31
+ if (!inputPath) {
32
+ diagnostics.push({
33
+ code: "INPUT_REQUIRED",
34
+ message: "--input is required.",
35
+ severity: "error",
36
+ });
37
+ printDiagnostics(diagnostics, format, quiet);
38
+ return 2;
39
+ }
40
+
41
+ const resolvedInputPath = resolve(cwd, inputPath);
42
+ if (!existsSync(resolvedInputPath)) {
43
+ diagnostics.push({
44
+ code: "INPUT_NOT_FOUND",
45
+ message: `Input file not found: ${resolvedInputPath}`,
46
+ severity: "error",
47
+ file: inputPath,
48
+ });
49
+ printDiagnostics(diagnostics, format, quiet);
50
+ return 2;
51
+ }
52
+
53
+ let config: DesignEmbedConfig | undefined;
54
+ let transformers: TransformerPlugin[] = [];
55
+ if (configPath) {
56
+ const configResult = await loadConfig(configPath, cwd);
57
+ diagnostics.push(...configResult.diagnostics);
58
+ config = configResult.config;
59
+
60
+ if (hasErrors(diagnostics)) {
61
+ printDiagnostics(diagnostics, format, quiet);
62
+ return 2;
63
+ }
64
+
65
+ transformers = await loadTransformers(config, configPath, cwd, diagnostics);
66
+ if (hasErrors(diagnostics)) {
67
+ printDiagnostics(diagnostics, format, quiet);
68
+ return 2;
69
+ }
70
+ }
71
+
72
+ const target = config?.output?.target ?? "html";
73
+ const targetEmitter = target === "react" ? reactEmitter : htmlEmitter;
74
+
75
+ const cssPath = getStringFlag(flags, "--css");
76
+ const result = await embed({
77
+ html: readFileSync(resolvedInputPath, "utf-8"),
78
+ css: cssPath ? readFileSync(resolve(cwd, cssPath), "utf-8") : undefined,
79
+ configPath,
80
+ config,
81
+ cwd,
82
+ transformers,
83
+ targetEmitter,
84
+ });
85
+ diagnostics.push(...result.diagnostics);
86
+
87
+ if (hasErrors(diagnostics)) {
88
+ printDiagnostics(diagnostics, format, quiet);
89
+ return 2;
90
+ }
91
+
92
+ if (options.check && !getBooleanFlag(flags, "--write")) {
93
+ const checkResult = checkGeneratedFiles({
94
+ cwd,
95
+ files: result.files,
96
+ readFile(path) {
97
+ return existsSync(path) ? readFileSync(path, "utf-8") : undefined;
98
+ },
99
+ });
100
+ const checkDiagnostics = checkResult.diagnostics;
101
+ diagnostics.push(...checkDiagnostics);
102
+ printDiagnostics(diagnostics, format, quiet);
103
+ return checkResult.ok ? 0 : 3;
104
+ }
105
+
106
+ for (const file of result.files) {
107
+ const outPath = resolve(cwd, file.path);
108
+ mkdirSync(dirname(outPath), { recursive: true });
109
+ writeFileSync(outPath, file.contents, "utf-8");
110
+ if (!quiet && format === "text") {
111
+ console.log(`Wrote ${file.path}`);
112
+ }
113
+ }
114
+
115
+ printDiagnostics(diagnostics, format, quiet);
116
+ if (!quiet && format === "text") {
117
+ console.log(`Success. Generated ${result.files.length} file(s).`);
118
+ }
119
+ return 0;
120
+ }
121
+
122
+ export function printDiagnostics(
123
+ diagnostics: Diagnostic[],
124
+ format: "json" | "text",
125
+ quiet: boolean,
126
+ ): void {
127
+ if (format === "json") {
128
+ console.log(
129
+ JSON.stringify({ diagnostics: toJsonDiagnostics(diagnostics) }, null, 2),
130
+ );
131
+ return;
132
+ }
133
+ if (quiet) {
134
+ return;
135
+ }
136
+ for (const diagnostic of diagnostics) {
137
+ const output = formatDiagnosticText(diagnostic);
138
+ if (diagnostic.severity === "error") {
139
+ console.error(output);
140
+ } else {
141
+ console.warn(output);
142
+ }
143
+ }
144
+ }
145
+
146
+ function isPackageName(path: string): boolean {
147
+ return !path.startsWith(".") && !isAbsolute(path);
148
+ }
149
+
150
+ async function loadTransformers(
151
+ config: DesignEmbedConfig | undefined,
152
+ configPath: string,
153
+ cwd: string,
154
+ diagnostics: Diagnostic[],
155
+ ): Promise<TransformerPlugin[]> {
156
+ const configDir = dirname(resolve(cwd, configPath));
157
+ const loaded: TransformerPlugin[] = [];
158
+
159
+ for (const transformer of config?.transformers ?? []) {
160
+ const specifier = isPackageName(transformer.path)
161
+ ? transformer.path
162
+ : isAbsolute(transformer.path)
163
+ ? transformer.path
164
+ : resolve(configDir, transformer.path);
165
+ try {
166
+ const module = await import(specifier);
167
+ const plugin = module.default ?? module.transformer;
168
+ if (!plugin?.transform) {
169
+ diagnostics.push({
170
+ code: "TRANSFORMER_INVALID",
171
+ message: `Transformer ${transformer.path} must export a plugin object with transform().`,
172
+ severity: "error",
173
+ file: transformer.path,
174
+ });
175
+ continue;
176
+ }
177
+ loaded.push({
178
+ name: plugin.name ?? transformer.path,
179
+ order: transformer.order ?? plugin.order,
180
+ transform: plugin.transform,
181
+ });
182
+ } catch (error) {
183
+ const message = error instanceof Error ? error.message : String(error);
184
+ diagnostics.push({
185
+ code: "TRANSFORMER_LOAD_FAILED",
186
+ message: `Failed to load transformer ${transformer.path}: ${message}`,
187
+ severity: "error",
188
+ file: transformer.path,
189
+ });
190
+ }
191
+ }
192
+
193
+ return loaded;
194
+ }
195
+
196
+ function hasErrors(diagnostics: Diagnostic[]): boolean {
197
+ return diagnostics.some((diagnostic) => diagnostic.severity === "error");
198
+ }
@@ -0,0 +1,140 @@
1
+ import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
2
+ import { dirname, isAbsolute, resolve } from "node:path";
3
+ import { type DesignEmbedConfig, loadConfig } from "@design-embed/config";
4
+ import type { Diagnostic } from "@design-embed/core";
5
+ import { reactTestGenerator } from "@design-embed/target-react";
6
+ import { getBooleanFlag, getFormat, getStringFlag } from "../args.ts";
7
+ import { printDiagnostics } from "./compile.ts";
8
+
9
+ export async function runGenerateTestsCommand(
10
+ flags: Record<string, string | boolean>,
11
+ ): Promise<number> {
12
+ const cwd = resolve(process.cwd(), getStringFlag(flags, "--cwd") ?? ".");
13
+ const configPath = getStringFlag(flags, "--config");
14
+ const quiet = getBooleanFlag(flags, "--quiet");
15
+ const format = getFormat(flags);
16
+ const diagnostics: Diagnostic[] = [];
17
+
18
+ if (!configPath) {
19
+ diagnostics.push({
20
+ code: "CONFIG_REQUIRED",
21
+ message: "--config is required for generate-tests.",
22
+ severity: "error",
23
+ });
24
+ printDiagnostics(diagnostics, format, quiet);
25
+ return 2;
26
+ }
27
+
28
+ const configResult = await loadConfig(configPath, cwd);
29
+ diagnostics.push(...configResult.diagnostics);
30
+ const config = configResult.config;
31
+ if (!config || hasErrors(diagnostics)) {
32
+ printDiagnostics(diagnostics, format, quiet);
33
+ return 2;
34
+ }
35
+
36
+ const source = readConfiguredSource(config, configPath, cwd, diagnostics);
37
+ if (!source || hasErrors(diagnostics)) {
38
+ printDiagnostics(diagnostics, format, quiet);
39
+ return 2;
40
+ }
41
+
42
+ const target = config.output?.target ?? "html";
43
+ if (target !== "react") {
44
+ diagnostics.push({
45
+ code: "TEST_TARGET_UNSUPPORTED",
46
+ message: `generate-tests currently supports target "react"; received "${target}".`,
47
+ severity: "error",
48
+ });
49
+ printDiagnostics(diagnostics, format, quiet);
50
+ return 2;
51
+ }
52
+
53
+ const result = reactTestGenerator.generateTests({
54
+ html: source.html,
55
+ css: source.css,
56
+ config,
57
+ diagnostics,
58
+ });
59
+ if (hasErrors(diagnostics)) {
60
+ printDiagnostics(diagnostics, format, quiet);
61
+ return 2;
62
+ }
63
+
64
+ for (const file of result.files) {
65
+ const outPath = resolve(cwd, file.path);
66
+ mkdirSync(dirname(outPath), { recursive: true });
67
+ writeFileSync(outPath, file.contents, "utf-8");
68
+ if (!quiet && format === "text") {
69
+ console.log(`Wrote ${file.path}`);
70
+ }
71
+ }
72
+
73
+ printDiagnostics(diagnostics, format, quiet);
74
+ if (!quiet && format === "text") {
75
+ console.log(`Success. Generated ${result.files.length} test file(s).`);
76
+ }
77
+ return 0;
78
+ }
79
+
80
+ interface SourceContents {
81
+ html: string;
82
+ css?: string;
83
+ }
84
+
85
+ function readConfiguredSource(
86
+ config: DesignEmbedConfig,
87
+ configPath: string,
88
+ cwd: string,
89
+ diagnostics: Diagnostic[],
90
+ ): SourceContents | undefined {
91
+ const source = config.tests?.source;
92
+ if (!source?.html) {
93
+ diagnostics.push({
94
+ code: "TEST_SOURCE_HTML_REQUIRED",
95
+ message: "tests.source.html is required for generate-tests.",
96
+ severity: "error",
97
+ });
98
+ return undefined;
99
+ }
100
+
101
+ const configDir = dirname(resolve(cwd, configPath));
102
+ const htmlPath = resolveConfigPath(source.html, configDir);
103
+ if (!existsSync(htmlPath)) {
104
+ diagnostics.push({
105
+ code: "TEST_SOURCE_HTML_NOT_FOUND",
106
+ message: `Test source HTML not found: ${htmlPath}`,
107
+ severity: "error",
108
+ file: source.html,
109
+ });
110
+ return undefined;
111
+ }
112
+
113
+ let css: string | undefined;
114
+ if (source.css) {
115
+ const cssPath = resolveConfigPath(source.css, configDir);
116
+ if (!existsSync(cssPath)) {
117
+ diagnostics.push({
118
+ code: "TEST_SOURCE_CSS_NOT_FOUND",
119
+ message: `Test source CSS not found: ${cssPath}`,
120
+ severity: "error",
121
+ file: source.css,
122
+ });
123
+ return undefined;
124
+ }
125
+ css = readFileSync(cssPath, "utf-8");
126
+ }
127
+
128
+ return {
129
+ html: readFileSync(htmlPath, "utf-8"),
130
+ css,
131
+ };
132
+ }
133
+
134
+ function resolveConfigPath(path: string, configDir: string): string {
135
+ return isAbsolute(path) ? path : resolve(configDir, path);
136
+ }
137
+
138
+ function hasErrors(diagnostics: Diagnostic[]): boolean {
139
+ return diagnostics.some((diagnostic) => diagnostic.severity === "error");
140
+ }
@@ -0,0 +1,114 @@
1
+ import { existsSync, mkdirSync, writeFileSync } from "node:fs";
2
+ import { dirname, resolve } from "node:path";
3
+ import type { Diagnostic } from "@design-embed/core";
4
+ import { getBooleanFlag, getFormat, getStringFlag } from "../args.ts";
5
+ import { printDiagnostics } from "./compile.ts";
6
+
7
+ export async function runInitCommand(
8
+ flags: Record<string, string | boolean>,
9
+ ): Promise<number> {
10
+ const cwd = resolve(process.cwd(), getStringFlag(flags, "--cwd") ?? ".");
11
+ const quiet = getBooleanFlag(flags, "--quiet");
12
+ const force = getBooleanFlag(flags, "--force");
13
+ const format = getFormat(flags);
14
+ const viewName = getStringFlag(flags, "--view-name") ?? "WelcomeHero";
15
+ const diagnostics: Diagnostic[] = [];
16
+
17
+ const files = [
18
+ {
19
+ path: "design-embed.config.ts",
20
+ contents: configTemplate(viewName),
21
+ },
22
+ {
23
+ path: "design.html",
24
+ contents: designHtmlTemplate(),
25
+ },
26
+ {
27
+ path: "playwright-ct.config.ts",
28
+ contents: playwrightConfigTemplate(),
29
+ },
30
+ ];
31
+
32
+ let written = 0;
33
+ for (const file of files) {
34
+ const outPath = resolve(cwd, file.path);
35
+ if (existsSync(outPath) && !force) {
36
+ diagnostics.push({
37
+ code: "INIT_FILE_EXISTS",
38
+ message: `Skipped existing file: ${file.path}. Pass --force to overwrite it.`,
39
+ severity: "warning",
40
+ file: file.path,
41
+ });
42
+ continue;
43
+ }
44
+ mkdirSync(dirname(outPath), { recursive: true });
45
+ writeFileSync(outPath, file.contents, "utf-8");
46
+ written += 1;
47
+ if (!quiet && format === "text") {
48
+ console.log(`Wrote ${file.path}`);
49
+ }
50
+ }
51
+
52
+ printDiagnostics(diagnostics, format, quiet);
53
+ if (!quiet && format === "text") {
54
+ console.log(`Success. Initialized design-embed with ${written} file(s).`);
55
+ console.log(
56
+ "Next: pnpm exec design-embed --input ./design.html --config ./design-embed.config.ts",
57
+ );
58
+ }
59
+ return 0;
60
+ }
61
+
62
+ function configTemplate(viewName: string): string {
63
+ return `import { defineConfig } from "design-embed";
64
+
65
+ export default defineConfig({
66
+ \toutput: {
67
+ \t\ttarget: "react",
68
+ \t\tviewName: "${viewName}",
69
+ \t\tviewsDir: "src/generated/views",
70
+ \t\tstyleMode: "inline",
71
+ \t},
72
+ \ttests: {
73
+ \t\toutputDir: "tests/generated/design-embed",
74
+ \t\trunner: "playwright",
75
+ \t\tsource: {
76
+ \t\t\thtml: "./design.html",
77
+ \t\t},
78
+ \t\tviewports: [
79
+ \t\t\t{ name: "mobile", width: 390, height: 844 },
80
+ \t\t\t{ name: "desktop", width: 1440, height: 900 },
81
+ \t\t],
82
+ \t\tstates: [{ name: "default" }],
83
+ \t\tassertions: {
84
+ \t\t\tscreenshot: true,
85
+ \t\t\tlayout: true,
86
+ \t\t\tlayoutTolerance: 1,
87
+ \t\t\tselectors: [":scope", ":scope *"],
88
+ \t\t},
89
+ \t},
90
+ });
91
+ `;
92
+ }
93
+
94
+ function designHtmlTemplate(): string {
95
+ return `<section style="box-sizing: border-box; width: 320px; padding: 24px; border-radius: 16px; background: #f8fafc; color: #0f172a; font-family: Arial, sans-serif;">
96
+ \t<p style="margin: 0 0 8px; color: #2563eb; font-size: 14px; font-weight: 700;">Design Embed</p>
97
+ \t<h1 style="margin: 0 0 12px; font-size: 32px; line-height: 1.1;">Welcome hero</h1>
98
+ \t<p style="margin: 0 0 20px; font-size: 16px; line-height: 1.5;">Replace this file with HTML exported from your design source.</p>
99
+ \t<button data-role="primary" style="border: 0; border-radius: 999px; padding: 12px 18px; background: #2563eb; color: white; font-size: 14px; font-weight: 700;">Get started</button>
100
+ </section>
101
+ `;
102
+ }
103
+
104
+ function playwrightConfigTemplate(): string {
105
+ return `import { defineConfig } from "@playwright/experimental-ct-react";
106
+
107
+ export default defineConfig({
108
+ \ttestDir: ".",
109
+ \tuse: {
110
+ \t\tctPort: 3100,
111
+ \t},
112
+ });
113
+ `;
114
+ }