-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit-templates.ts
More file actions
56 lines (48 loc) · 1.55 KB
/
init-templates.ts
File metadata and controls
56 lines (48 loc) · 1.55 KB
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
import * as fs from "fs";
import * as path from "path";
import { fileURLToPath } from "url";
const __dirname = path.dirname(fileURLToPath(import.meta.url));
function getDtsContent(): string {
return fs.readFileSync(path.join(__dirname, "../../../chadscript.d.ts"), "utf8");
}
function getSkillContent(): string {
return fs.readFileSync(path.join(__dirname, "../../../lib/skill.md"), "utf8");
}
const TSCONFIG_CONTENT = `{
"compilerOptions": {
"target": "ES2020",
"module": "ES2020",
"lib": ["ES2020"],
"noEmit": true,
"skipLibCheck": true,
"strict": true
}
}
`;
const HELLO_CONTENT = `console.log("Hello from ChadScript!");
`;
export function runInit(): void {
const skillDir = path.join(".claude", "skills", "chadscript");
const files: Array<{ name: string; content: string }> = [
{ name: "chadscript.d.ts", content: getDtsContent() },
{ name: "tsconfig.json", content: TSCONFIG_CONTENT },
{ name: "hello.ts", content: HELLO_CONTENT },
{ name: path.join(skillDir, "SKILL.md"), content: getSkillContent() },
];
for (const file of files) {
if (fs.existsSync(file.name)) {
console.log(` skip ${file.name} (already exists)`);
} else {
const dir = path.dirname(file.name);
if (dir !== "." && !fs.existsSync(dir)) {
fs.mkdirSync(dir, { recursive: true });
}
fs.writeFileSync(file.name, file.content);
console.log(` created ${file.name}`);
}
}
console.log("");
console.log("\x1b[32mReady!\x1b[0m");
console.log("");
console.log(" Try: chad run hello.ts");
}