-
Notifications
You must be signed in to change notification settings - Fork 3
/
generate.js
executable file
·33 lines (30 loc) · 1.07 KB
/
generate.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
#!/usr/bin/env node
'use strict'
const emojme = require('emojme');
const fs = require('fs');
const exec = require('child_process').execSync;
try {
let subdomain = process.argv[3];
let token = process.argv[4];
let options = {
save: process.argv[2],
output: true
};
return emojme.download(subdomain, token, options).then(results => {
if (!results || !results[subdomain] || !results[subdomain].saveResults) {
throw new Error(`unable to retrieve results for ${subdomain}`);
}
const savedEmoji = results[subdomain].saveResults;
const emojiList = savedEmoji.map(emojiPath => emojiPath.split('/').slice(-1));
const date = new Date().toISOString().slice(0,10);
fs.writeFileSync(date, emojiList.toString().split(',').join('\n'));
return savedEmoji[0].split('/').slice(0,-1).join('/');
}).then(srcPath => {
return exec(`mv ${srcPath.replace(/(\s+|\(|\))/g, "\\$1")}/* emoji/`);;
}).then(() => {
return exec(`sh update_readme.sh`);
});
} catch(err) {
console.log(err);
throw new Error('Usage: node generate.js USER SUBDOMAIN TOKEN');
}