forked from zhheo/Sticker-Heo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
100 lines (92 loc) · 2.26 KB
/
index.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
const fs = require('fs')
const imagePath = './Sticker-100'
const pjson = require('./package.json')
const version = pjson.version
const baseUrl = 'https://cdn.jsdelivr.net/npm/sticker-heo@'+version+'/Sticker-100'
/**
* 获取文件名
* @param {string} name
*/
function getName(name) {
return name.split('.')[0]
}
/**
* 生成twikoo格式json文件
* @param {Array<string>} nameList
*/
function twikoo(nameList) {
const key = `<img src="${baseUrl}/害羞.png" style="width: 30px;top: 4px;position: relative;" title="Heo">`
const result = {
[key]: {
type: 'image',
container: []
}
}
nameList.forEach((name) => {
result[key].container.push({
icon: `<img src="${baseUrl}/${name}">`,
text: `heo-${getName(name)}`
})
})
return result
}
/**
* 生成valine格式json文件
* @param {Array<string>} nameList
*/
function valine(nameList) {
const result = {}
nameList.forEach((name) => {
result[`${getName(name)}`] = `${baseUrl}/${name}`
})
return result
}
/**
* 生成valine格式json文件
* @param {Array<string>} nameList
*/
function artalk(nameList) {
const result = {
name: 'Heo',
type: 'image',
items: []
}
nameList.forEach((item) => {
result.items.push({
key: `heo-${getName(item)}`,
val: `${baseUrl}/${item}`
})
})
return result
}
/**
* 生成waline格式json文件
* @param {Array<string>} nameList
*/
function waline(nameList) {
const result = {
name: 'Heo',
type: 'png',
icon: '亲亲',
items: []
}
nameList.forEach((item) => {
result.items.push(`${getName(item)}`)
})
return result
}
const fileNameListAll = fs.readdirSync(imagePath)
// 筛选png
const path = require('path');
const EXTENSION = '.png';
const fileNameList = fileNameListAll.filter(file => {
return path.extname(file).toLowerCase() === EXTENSION;
});
const twikooObject = twikoo(fileNameList)
fs.writeFileSync('./twikoo.json', JSON.stringify(twikooObject))
const valineObject = valine(fileNameList)
fs.writeFileSync('./valine.json', JSON.stringify(valineObject))
const artalkObject = artalk(fileNameList)
fs.writeFileSync('./artalk.json', JSON.stringify(artalkObject))
const walineObject = waline(fileNameList)
fs.writeFileSync('./Sticker-100/info.json', JSON.stringify(walineObject))