forked from qitoqito/kedaya
-
Notifications
You must be signed in to change notification settings - Fork 0
/
creatAll.js
83 lines (81 loc) · 2.57 KB
/
creatAll.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
let fs = require("fs")
let dirname = process.mainModule.path
let dir = fs.readdirSync(`${dirname}/parse`);
let dicts = {}
let prefix = process.env.QITOQITO_PREFIX || ''
let map = process.env.QITOQITO_MAP || ''
dir.forEach(function(item, index) {
let stat = fs.lstatSync(`${dirname}/parse/` + item)
if (stat.isDirectory() === true) {
dicts[item] = fs.readdirSync(`${dirname}/parse/${item}`)
}
})
let pathFile = fs.readdirSync(dirname)
let change = {}
if (map) {
for (let k of map.replace(/\&/g, "\|").split("|")) {
let a = k.split("=")
for (let i of a[0].split(',')) {
change[i] = {
map: a[1],
type: a[1].split("_")[0]
}
}
}
console.log(change)
}
dicts['extra'] = Object.keys(change)
let content = `
!(async () => {
let prefix = process.env.QITOQITO_PREFIX ||''
let filename = process.mainModule.filename.replace(prefix,'').match(/(\\w+)\\.js/)[1]
let dirname = process.mainModule.path
let type = filename.split('_')[0]
if (['js', 'jx', 'jr', 'jw'].includes(type)) {
type = 'jd'
}
let qitoqito = require(\`\${dirname}/parse/\${type}/\${filename}\`)
let kedaya = new qitoqito()
await kedaya.init({})
}
)().catch((e) => {
console.log(e.message)
})
`
for (let i in dicts) {
for (let j of dicts[i]) {
let filename = `${prefix}${j}`
if (i == 'extra') {
let exc = `
!(async () => {
let prefix = process.env.QITOQITO_PREFIX ||''
let filename = process.mainModule.filename.replace(prefix,'').match(/(\\w+)\\.js/)[1]
let dirname = process.mainModule.path
let type = filename.split('_')[0]
if (['js', 'jx', 'jr', 'jw'].includes(type)) {
type = 'jd'
}
let qitoqito = require(\`\${dirname}/parse/${change[j].type}/${change[j].map}\`)
let kedaya = new qitoqito()
await kedaya.init({"filename":"${j}"})
}
)().catch((e) => {
console.log(e.message)
})
`;
fs.writeFile(`${dirname}/${filename}.js`, exc, function(err, data) {
if (err) {
throw err;
}
console.log(`🐯❄️ 写入成功: ${filename}.js 写入目录成功`)
})
} else {
fs.writeFile(`${dirname}/${filename}`, content, function(err, data) {
if (err) {
throw err;
}
console.log(`🐯❄️ 写入成功: ${filename}.js 写入目录成功`)
})
}
}
}