-
Notifications
You must be signed in to change notification settings - Fork 3
/
import
executable file
·47 lines (37 loc) · 1.23 KB
/
import
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
#!/usr/bin/env node
const fs = require('fs');
const path = require('path');
const emojme = require('emojme');
const Slack = require('slack-node');
require('dotenv-safe').config()
const dir = 'emoji';
const subdomain = process.env.SLACK_SUBDOMAIN;
const token = process.env.SLACK_TOKEN;
const channel = process.env.SLACK_CHANNEL || '#general';
const slack = new Slack(token);
const isImage = f => new Set(['.png', '.jpg', '.jpeg', '.gif']).has(path.extname(f));
fs.readdir(dir, (err, files) => {
emojme.add(subdomain, token, {
bustCache: true,
src: files.filter(isImage).map(file => path.join(dir, file)),
}).then(results => {
const uploaded = results[subdomain].emojiList;
const errors = results[subdomain].errorList;
const successful = uploaded.filter(file => {
return !errors.find(errored => errored.name === file.name);
});
if (successful.length) {
const text = successful.map(e => `:${e.name}: (${e.name})`).join(' ');
slack.api('chat.postMessage', {
text: `New Emoji: ${text}`,
channel: channel
}, (err, response) => {
err && console.error(err);
});
}
if (errors.length) {
// This should cause the CI to fail
process.exit(1);
}
});
});