MCPcopy Create free account
hub / github.com/bilibili/http-service / modifyFile

Function modifyFile

scripts/create.ts:28–41  ·  view source on GitHub ↗
(filePath: string, replaces: Array<string[]>)

Source from the content-addressed store, hash-verified

26}
27
28const modifyFile = (filePath: string, replaces: Array<string[]>) => {
29 // 1. 读取文件内容
30 const oFilePath = filePath + '.txt'
31 const data = fs.readFileSync(oFilePath, 'utf8');
32
33 // 2. 修改文件内容
34 let modifiedData = data
35 replaces.forEach(([o, n]) => {
36 modifiedData = modifiedData.replace(new RegExp(`{{${o}}}`, 'g'), n)
37 })
38 // 3. 将修改后的内容写回文件
39 fs.writeFileSync(filePath, modifiedData, 'utf8');
40 fs.unlinkSync(oFilePath)
41}
42
43;(async () => {
44 const { name } = await inquirer.prompt([

Callers 1

create.tsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected