-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathreplace.js
40 lines (32 loc) · 1.18 KB
/
replace.js
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
const fs = require('fs')
const path = require('path')
const replaceTextInFiles = (dir, from, to) => {
const files = fs.readdirSync(dir)
for (const file of files) {
const filePath = path.join(dir, file)
const fileExtension = path.extname(file)
if (
file === 'node_modules' ||
file === '.git' ||
file === 'replace.js' ||
['.png', '.img', '.ico', 'jpg'].includes(fileExtension)
) {
continue
}
const stats = fs.statSync(filePath)
if (stats.isDirectory()) {
replaceTextInFiles(filePath, from, to)
} else {
let content = fs.readFileSync(filePath, 'utf-8')
const updatedContent = content.replace(new RegExp(from, 'g'), to)
fs.writeFileSync(filePath, updatedContent)
}
}
}
const main = () => {
const from = '@npm.piece/constants-frontend-frontend' // Замените на текст, который нужно заменить
const to = '@npm.piece/constants-frontend' // Замените на текст, на который нужно заменить
const startDir = '.' // Замените на папку, в которой нужно начать
replaceTextInFiles(startDir, from, to)
}
main()