1 | import { readFile } from 'fs-extra';
|
2 | import { join } from 'path';
|
3 |
|
4 | import { build } from './pubsub';
|
5 |
|
6 | const nconf = require.main.require('nconf');
|
7 | const baseDir = nconf.get('base_dir');
|
8 |
|
9 |
|
10 | const 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 |
|
31 | export {
|
32 | toggle as activation,
|
33 | toggle as deactivation,
|
34 | };
|