1 | import { access } from 'fs-extra';
|
2 |
|
3 | import * as settings from './settings';
|
4 | import * as plugins from './plugins';
|
5 | import * as parse from './parse';
|
6 | import { tableFile } from './build';
|
7 | import { build } from './pubsub';
|
8 | import controllers from './controllers';
|
9 | import './customizations';
|
10 |
|
11 | const nconf = require.main.require('nconf');
|
12 | const buster = require.main.require('./src/meta').config['cache-buster'];
|
13 |
|
14 | const init = async (params: any): Promise<void> => {
|
15 | controllers(params);
|
16 |
|
17 | const sets = await settings.get();
|
18 | const { parseAscii, parseNative } = sets as {
|
19 | parseAscii: boolean;
|
20 | parseNative: boolean;
|
21 | };
|
22 |
|
23 |
|
24 | parse.setOptions({
|
25 | ascii: parseAscii,
|
26 | native: parseNative,
|
27 | });
|
28 |
|
29 |
|
30 | const shouldBuild = nconf.any('build_emoji', 'BUILD_EMOJI') ||
|
31 |
|
32 | access(tableFile).catch((err) => {
|
33 | if (err && err.code !== 'ENOENT') {
|
34 | throw err;
|
35 | }
|
36 | return false;
|
37 | });
|
38 |
|
39 | if (shouldBuild) {
|
40 | await build();
|
41 | }
|
42 | };
|
43 |
|
44 | const adminMenu = (header: {
|
45 | plugins: { route: string; icon: string; name: string }[];
|
46 | }, callback: NodeBack) => {
|
47 | header.plugins.push({
|
48 | route: '/plugins/emoji',
|
49 | icon: 'fa-smile-o',
|
50 | name: 'Emoji',
|
51 | });
|
52 | callback(null, header);
|
53 | };
|
54 |
|
55 | const composerFormatting = (data: {
|
56 | options: { name: string; className: string; title: string }[];
|
57 | }, callback: NodeBack) => {
|
58 | data.options.push({
|
59 | name: 'emoji-add-emoji',
|
60 | className: 'fa fa-smile-o emoji-add-emoji',
|
61 | title: '[[emoji:composer.title]]',
|
62 | });
|
63 | callback(null, data);
|
64 | };
|
65 |
|
66 | const addStylesheet = (data: {
|
67 | links: {
|
68 | rel: string; type?: string; href: string;
|
69 | }[];
|
70 | }, callback: NodeBack) => {
|
71 | const rel = nconf.get('relative_path');
|
72 |
|
73 | data.links.push({
|
74 | rel: 'stylesheet',
|
75 | href: `${rel}/plugins/nodebb-plugin-emoji/emoji/styles.css?${buster}`,
|
76 | });
|
77 |
|
78 | callback(null, data);
|
79 | };
|
80 |
|
81 | const configGet = async (config: any): Promise<any> => {
|
82 | const customFirst = await settings.getOne('customFirst');
|
83 |
|
84 | config.emojiCustomFirst = customFirst;
|
85 | return config;
|
86 | };
|
87 |
|
88 | export {
|
89 | init,
|
90 | adminMenu,
|
91 | composerFormatting,
|
92 | plugins,
|
93 | parse,
|
94 | addStylesheet,
|
95 | configGet,
|
96 | };
|