-
Notifications
You must be signed in to change notification settings - Fork 2
/
normalize-asset-path.js
46 lines (44 loc) · 1.21 KB
/
normalize-asset-path.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
41
42
43
44
45
46
const path = require('path')
const fs = require('fs')
const walk = function (dir, done) {
let results = []
fs.readdir(dir, function (err, list) {
if (err) return done(err)
let pending = list.length
if (!pending) return done(null, results)
list.forEach(function (file) {
file = path.resolve(dir, file)
fs.stat(file, function (err, stat) {
if (stat && stat.isDirectory()) {
walk(file, function (err, res) {
results = results.concat(res)
if (!--pending) done(null, results)
})
} else {
results.push(file)
if (!--pending) done(null, results)
}
})
})
})
}
async function run() {
const dirPath = path.resolve(__dirname, './out')
walk(dirPath, function (err, results) {
if (err) throw err
results.forEach(file => {
if (file.endsWith('.html')) {
fs.readFile(file, 'utf8', function (err, data) {
if (err) {
return console.log(err)
}
const result = data.replace(/%5Blocale%5D/g, '[locale]')
fs.writeFile(file, result, 'utf8', function (err) {
if (err) return console.log(err)
})
})
}
})
})
}
run()