MCPcopy Create free account
hub / github.com/Zoo-Code-Org/Zoo-Code / createRule

Function createRule

src/services/rules/rules.ts:90–108  ·  view source on GitHub ↗
(cwd: string, input: CreateRuleInput)

Source from the content-addressed store, hash-verified

88}
89
90export async function createRule(cwd: string, input: CreateRuleInput): Promise<string> {
91 const directoryPath = getTargetRuleDirectory(cwd, input)
92 const fileName = normalizeRuleFileName(input.fileName)
93 const filePath = path.join(directoryPath, fileName)
94
95 assertPathInsideDirectory(filePath, directoryPath)
96
97 try {
98 await fs.mkdir(directoryPath, { recursive: true })
99 await fs.writeFile(filePath, createRuleTemplate(fileName, input), { encoding: "utf-8", flag: "wx" })
100 return filePath
101 } catch (error) {
102 if ((error as NodeJS.ErrnoException).code === "EEXIST") {
103 throw new Error(`Rule file already exists: ${fileName}`)
104 }
105
106 throw error
107 }
108}
109
110export async function deleteRule(cwd: string, input: DeleteRuleInput): Promise<void> {
111 const filePath = await resolveRuleFile(cwd, input)

Callers 2

handleCreateRuleFunction · 0.90
rules.spec.tsFile · 0.85

Calls 5

getTargetRuleDirectoryFunction · 0.85
normalizeRuleFileNameFunction · 0.85
createRuleTemplateFunction · 0.85
writeFileMethod · 0.80

Tested by

no test coverage detected