2020-10-03 11:10:05 +08:00
|
|
|
const path = require("path");
|
|
|
|
const fs = require("fs");
|
|
|
|
const fetch = require("node-fetch");
|
|
|
|
const randomUa = require("random-ua");
|
2018-10-04 19:07:24 +08:00
|
|
|
|
|
|
|
// get the latest github version
|
2020-10-03 11:10:05 +08:00
|
|
|
fetch("https://api.github.com/emojis", {
|
2018-10-04 19:07:24 +08:00
|
|
|
headers: {
|
2020-10-03 11:10:05 +08:00
|
|
|
"User-Agent": randomUa.generate(),
|
|
|
|
"Content-Type": "application/json",
|
2018-10-04 19:07:24 +08:00
|
|
|
},
|
2020-10-03 11:10:05 +08:00
|
|
|
})
|
|
|
|
.then((t) => t.json())
|
|
|
|
.then((json) => {
|
|
|
|
const latestEmojis = Object.keys(json).reduce((emojis, name) => {
|
|
|
|
emojis[name] = { src: json[name] };
|
2018-10-04 19:07:24 +08:00
|
|
|
|
2020-10-03 11:10:05 +08:00
|
|
|
const match = /\/unicode\/(\S+)\./.exec(json[name]);
|
|
|
|
if (match) {
|
|
|
|
emojis[name].codepoints = match[1].split("-");
|
|
|
|
}
|
2018-10-04 19:07:24 +08:00
|
|
|
|
2020-10-03 11:10:05 +08:00
|
|
|
return emojis;
|
|
|
|
}, {});
|
2018-10-04 19:07:24 +08:00
|
|
|
|
2020-10-03 11:10:05 +08:00
|
|
|
// update local backup
|
|
|
|
fs.writeFile(
|
|
|
|
path.join(__dirname, "emojis.json"),
|
|
|
|
JSON.stringify(latestEmojis, null, " "),
|
|
|
|
function (err) {
|
|
|
|
if (err) {
|
|
|
|
console.warn(err);
|
|
|
|
process.exit(1);
|
|
|
|
} else {
|
|
|
|
console.log(`Update ${Object.keys(latestEmojis).length} emojis`);
|
|
|
|
}
|
2018-10-04 19:07:24 +08:00
|
|
|
}
|
2020-10-03 11:10:05 +08:00
|
|
|
);
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
console.error(error);
|
|
|
|
});
|