File size: 2,504 Bytes
311fa35
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import * as fs from "node:fs";
import * as path from "node:path";

const ARCHETYPES_SRC = path.resolve(
	import.meta.dirname,
	"../../src/config/archetypes",
);
const ARCHETYPES_DEST = path.resolve(import.meta.dirname, "../src/data/archetypes");

// Ensure destination exists
fs.mkdirSync(ARCHETYPES_DEST, { recursive: true });

// Required fields every archetype JSON must have
const REQUIRED_FIELDS = [
	"colorPalette",
	"artStyle",
	"lighting",
	"captionStyle",
	"defaultTransition",
	"transitionDurationFrames",
	"motionIntensity",
	"textCardFont",
	"compositionRules",
	"mood",
	"visualColorPalette",
];

const files = fs
	.readdirSync(ARCHETYPES_SRC)
	.filter((f) => f.endsWith(".json"));

if (files.length === 0) {
	throw new Error(`No archetype JSON files found in ${ARCHETYPES_SRC}`);
}

const archetypes: { slug: string; name: string }[] = [];

for (const file of files) {
	const src = path.join(ARCHETYPES_SRC, file);
	const dest = path.join(ARCHETYPES_DEST, file);

	const content = JSON.parse(fs.readFileSync(src, "utf-8"));

	// Validate required fields
	for (const field of REQUIRED_FIELDS) {
		if (!(field in content)) {
			throw new Error(`Archetype ${file} is missing required field: ${field}`);
		}
	}

	fs.copyFileSync(src, dest);

	const slug = file.replace(".json", "");
	const name = slug
		.split("-")
		.map((w) => w.charAt(0).toUpperCase() + w.slice(1))
		.join(" ");

	archetypes.push({ slug, name });
}

// Generate barrel file
const barrel = `// Auto-generated by sync-archetypes.ts — do not edit
${archetypes.map((a) => `import ${a.slug.replace(/-/g, "_")} from "./${a.slug}.json";`).join("\n")}

export interface ArchetypeConfig {
  scenePacing: string;
  defaultTransition: string;
  transitionDurationFrames: number;
  captionStyle: string;
  colorPalette: { background: string; accent: string; text: string };
  textCardFont: string;
  motionIntensity: number;
  artStyle: string;
  lighting: string;
  compositionRules: string;
  culturalMarkers: string;
  mood: string;
  antiArtifactGuidance: string;
  visualColorPalette: string[];
}

export interface Archetype {
  slug: string;
  name: string;
  config: ArchetypeConfig;
}

export const archetypes: Archetype[] = [
${archetypes.map((a) => `  { slug: "${a.slug}", name: "${a.name}", config: ${a.slug.replace(/-/g, "_")} as unknown as ArchetypeConfig },`).join("\n")}
];
`;

fs.writeFileSync(path.join(ARCHETYPES_DEST, "index.ts"), barrel);

console.log(`Synced ${files.length} archetypes to ${ARCHETYPES_DEST}`);