-
Notifications
You must be signed in to change notification settings - Fork 0
/
addSuffixJs.js
59 lines (52 loc) · 1.95 KB
/
addSuffixJs.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
47
48
49
50
51
52
53
54
55
56
57
58
59
const fs = require("fs").promises
const path = require("path")
void async function () {
try {
let p = path.resolve(__dirname, "../dist-esmodule")
let paths = await fs.readdir(p)
// console.log(paths)
let stack = [... paths]
while (stack.length) {
let top = stack.pop()
let pat = path.resolve(p, top)
let stat = await fs.stat(pat)
if (stat.isDirectory()) {
let temp = await fs.readdir(pat)
if (temp) {
for (let i of temp) {
stack.push(path.join(top, i))
}
}
} else {
// console.log(pat)
let personList = await fs.readFile(pat, {encoding: "utf8"})
var regexpNames = /(?:export|import)(?:\s)*?(?:\{)??.*?(?:\})??(?:\s)*?from(?:\s)*?"(.+?)"/gm
var match = personList.matchAll(regexpNames);
let count = 0
for (let item of match) {
if (/.js$/.test(item[1])) {
continue
}
let temp = item[0]
let index = item.index + count
let now = temp.replace(item[1], `${
item[1]
}.js`)
let past = personList.slice(0, index)
let feature = personList.slice(index + temp.length, personList.length)
personList = `${past}${now}${feature}`
count = count + 3
}
await fs.writeFile(pat, personList, {encoding: "utf8"})
}
}
// for (let item of paths) {
// let pat = path.resolve(p, item)
// console.log(pat)
// let stat = await fs.stat(pat)
// console.log(stat.isDirectory())
// }
} catch (error) {
console.log(error)
}
}()