UNPKG

778 BPlain TextView Raw
1import { readFile } from 'fs-extra';
2import { join } from 'path';
3
4import { build } from './pubsub';
5
6const nconf = require.main.require('nconf');
7const baseDir = nconf.get('base_dir');
8
9// build when a plugin is (de)activated if that plugin is an emoji pack
10const toggle = async ({ id }: { id: string }) => {
11 let file;
12 try {
13 file = await readFile(join(baseDir, 'node_modules', id, 'plugin.json'), 'utf8');
14 } catch (err) {
15 if (err && err.code !== 'ENOENT') {
16 throw err;
17 }
18 return;
19 }
20
21 const plugin = JSON.parse(file);
22
23 const hasHook = plugin.hooks && plugin.hooks
24 .some((hook: { hook: string }) => hook.hook === 'filter:emoji.packs');
25
26 if (hasHook) {
27 await build();
28 }
29};
30
31export {
32 toggle as activation,
33 toggle as deactivation,
34};