nodebb-plugin-customize 4.0.0 → 4.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.eslintrc.js CHANGED
@@ -10,7 +10,7 @@ module.exports = {
10
10
  objects: 'always-multiline',
11
11
  imports: 'always-multiline',
12
12
  exports: 'always-multiline',
13
- functions: 'never'
13
+ functions: 'never',
14
14
  }],
15
15
  'import/no-unresolved': 'off',
16
16
  'import/prefer-default-export': 'off',
@@ -20,9 +20,9 @@ module.exports = {
20
20
  'object-curly-newline': ['error', {
21
21
  multiline: true,
22
22
  minProperties: 5,
23
- consistent: true
23
+ consistent: true,
24
24
  }],
25
25
  '@typescript-eslint/indent': ['error', 2],
26
- '@typescript-eslint/explicit-function-return-type': 'off'
26
+ '@typescript-eslint/explicit-function-return-type': 'off',
27
27
  },
28
28
  };
@@ -1,56 +1,56 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.build = void 0;
4
- const fs_extra_1 = require("fs-extra");
5
- const path_1 = require("path");
6
- const lodash_1 = require("lodash");
7
- const database_1 = require("./database");
8
- if (!require.main) {
9
- throw Error('[plugin-customize] `require.main` is wrong');
10
- }
11
- const translationsSrcDir = (0, path_1.join)(__dirname, '../../public/language');
12
- const templatesSrcDir = (0, path_1.join)(__dirname, '../../public/templates');
13
- const translationsDir = (0, path_1.join)(__dirname, '../public/language');
14
- const templatesDir = (0, path_1.join)(__dirname, '../public/templates');
15
- async function build() {
16
- const [translations, templates] = await Promise.all([
17
- (0, database_1.getTranslations)(),
18
- (0, database_1.getTemplates)(),
19
- ]);
20
- const translationTree = {};
21
- translations.forEach(({ language, namespace, key, value }) => {
22
- translationTree[language] = translationTree[language] || {};
23
- translationTree[language][namespace] = translationTree[language][namespace] || {};
24
- translationTree[language][namespace][key] = value;
25
- });
26
- // delete existing files
27
- await Promise.all([
28
- (0, fs_extra_1.remove)(translationsDir),
29
- (0, fs_extra_1.remove)(templatesDir),
30
- ]);
31
- await Promise.all([
32
- (0, fs_extra_1.mkdirp)(translationsDir),
33
- (0, fs_extra_1.mkdirp)(templatesDir),
34
- ]);
35
- // copy in own step to avoid conflicts
36
- await Promise.all([
37
- (0, fs_extra_1.copy)(translationsSrcDir, translationsDir),
38
- (0, fs_extra_1.copy)(templatesSrcDir, templatesDir),
39
- ]);
40
- const translationWrites = (0, lodash_1.flatMap)(Object.keys(translationTree), (language) => (0, lodash_1.flatMap)(Object.keys(translationTree[language]), async (namespace) => {
41
- const path = (0, path_1.join)(translationsDir, language, `${namespace}.json`);
42
- await (0, fs_extra_1.mkdirp)((0, path_1.dirname)(path));
43
- await (0, fs_extra_1.writeJson)(path, translationTree[language][namespace]);
44
- }));
45
- const templateWrites = templates.map(async ({ path, value }) => {
46
- const filePath = (0, path_1.join)(templatesDir, path);
47
- await (0, fs_extra_1.mkdirp)((0, path_1.dirname)(filePath));
48
- await (0, fs_extra_1.writeFile)(filePath, value);
49
- });
50
- await Promise.all([
51
- ...translationWrites,
52
- ...templateWrites,
53
- ]);
54
- }
55
- exports.build = build;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.build = void 0;
4
+ const fs_extra_1 = require("fs-extra");
5
+ const path_1 = require("path");
6
+ const lodash_1 = require("lodash");
7
+ const database_1 = require("./database");
8
+ if (!require.main) {
9
+ throw Error('[plugin-customize] `require.main` is wrong');
10
+ }
11
+ const translationsSrcDir = (0, path_1.join)(__dirname, '../../public/language');
12
+ const templatesSrcDir = (0, path_1.join)(__dirname, '../../public/templates');
13
+ const translationsDir = (0, path_1.join)(__dirname, '../public/language');
14
+ const templatesDir = (0, path_1.join)(__dirname, '../public/templates');
15
+ async function build() {
16
+ const [translations, templates] = await Promise.all([
17
+ (0, database_1.getTranslations)(),
18
+ (0, database_1.getTemplates)(),
19
+ ]);
20
+ const translationTree = {};
21
+ translations.forEach(({ language, namespace, key, value }) => {
22
+ translationTree[language] = translationTree[language] || {};
23
+ translationTree[language][namespace] = translationTree[language][namespace] || {};
24
+ translationTree[language][namespace][key] = value;
25
+ });
26
+ // delete existing files
27
+ await Promise.all([
28
+ (0, fs_extra_1.remove)(translationsDir),
29
+ (0, fs_extra_1.remove)(templatesDir),
30
+ ]);
31
+ await Promise.all([
32
+ (0, fs_extra_1.mkdirp)(translationsDir),
33
+ (0, fs_extra_1.mkdirp)(templatesDir),
34
+ ]);
35
+ // copy in own step to avoid conflicts
36
+ await Promise.all([
37
+ (0, fs_extra_1.copy)(translationsSrcDir, translationsDir),
38
+ (0, fs_extra_1.copy)(templatesSrcDir, templatesDir),
39
+ ]);
40
+ const translationWrites = (0, lodash_1.flatMap)(Object.keys(translationTree), (language) => (0, lodash_1.flatMap)(Object.keys(translationTree[language]), async (namespace) => {
41
+ const path = (0, path_1.join)(translationsDir, language, `${namespace}.json`);
42
+ await (0, fs_extra_1.mkdirp)((0, path_1.dirname)(path));
43
+ await (0, fs_extra_1.writeJson)(path, translationTree[language][namespace]);
44
+ }));
45
+ const templateWrites = templates.map(async ({ path, value }) => {
46
+ const filePath = (0, path_1.join)(templatesDir, path);
47
+ await (0, fs_extra_1.mkdirp)((0, path_1.dirname)(filePath));
48
+ await (0, fs_extra_1.writeFile)(filePath, value);
49
+ });
50
+ await Promise.all([
51
+ ...translationWrites,
52
+ ...templateWrites,
53
+ ]);
54
+ }
55
+ exports.build = build;
56
56
  //# sourceMappingURL=build.js.map
@@ -1,120 +1,120 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const path_1 = require("path");
4
- const util_1 = require("util");
5
- const fs_extra_1 = require("fs-extra");
6
- const pubsub_1 = require("./pubsub");
7
- const db = require("./database");
8
- if (!require.main) {
9
- throw Error('[plugin-customize] `require.main` is undefined');
10
- }
11
- const nconf = require.main.require('nconf');
12
- const User = require.main.require('./src/user');
13
- const Languages = require.main.require('./src/languages');
14
- const File = require.main.require('./src/file');
15
- const Translator = require.main.require('./src/translator');
16
- const Utils = require.main.require('./src/utils');
17
- const { setupApiRoute, setupAdminPageRoute } = require.main.require('./src/routes/helpers');
18
- const { formatApiResponse } = require.main.require('./src/controllers/helpers');
19
- const escape = (dirty) => Translator.escape(Utils.escapeHTML(dirty));
20
- const listLanguages = (0, util_1.promisify)(Languages.list);
21
- const getSettings = (0, util_1.promisify)(User.getSettings);
22
- const walk = (0, util_1.promisify)(File.walk);
23
- // eslint-disable-next-line import/no-dynamic-require, @typescript-eslint/no-var-requires
24
- const version = require((0, path_1.join)(__dirname, '../../package.json')).version;
25
- let namespaceCache = [];
26
- async function listNamespaces() {
27
- if (namespaceCache.length) {
28
- return namespaceCache;
29
- }
30
- const metadataFile = (0, path_1.join)(nconf.get('base_dir'), 'build/public/language/metadata.json');
31
- const metadata = await (0, fs_extra_1.readJson)(metadataFile);
32
- namespaceCache = metadata.namespaces;
33
- return namespaceCache;
34
- }
35
- let templateCache = [];
36
- async function listTemplates() {
37
- if (templateCache.length) {
38
- return templateCache;
39
- }
40
- const viewsDir = nconf.get('views_dir');
41
- const templates = await walk(viewsDir);
42
- templateCache = templates
43
- .filter((path) => path.endsWith('.tpl'))
44
- .map((path) => (0, path_1.relative)(viewsDir, path).split(/\/\\/).join('/'));
45
- return templateCache;
46
- }
47
- const renderAdmin = async (req, res) => {
48
- const [templates, translations, languages, userLang, namespaces, templatePaths,] = await Promise.all([
49
- db.getTemplates(),
50
- db.getTranslations(),
51
- listLanguages(),
52
- getSettings(req.uid).then((data) => data.userLang),
53
- listNamespaces(),
54
- listTemplates(),
55
- ]);
56
- res.render('admin/plugins/customize', {
57
- version,
58
- templates: templates.map((x) => ({
59
- path: x.path,
60
- json: escape(JSON.stringify(x)),
61
- diff: escape(x.diff),
62
- })),
63
- translations,
64
- languages: languages.map(({ code, name }) => ({
65
- code,
66
- name,
67
- selected: code === userLang,
68
- })),
69
- namespaces: namespaces.map((name) => ({ name })),
70
- templatePaths,
71
- });
72
- };
73
- const adminBuild = async (req, res) => {
74
- await (0, pubsub_1.build)();
75
- formatApiResponse(200, res, 'OK');
76
- };
77
- const adminEditTranslation = async (req, res) => {
78
- const translation = req.body.translation;
79
- await db.editTranslation(translation);
80
- const translations = await db.getTranslations();
81
- formatApiResponse(200, res, { translations });
82
- };
83
- const adminRemoveTranslation = async (req, res) => {
84
- await db.removeTranslation(req.body.translation);
85
- const translations = await db.getTranslations();
86
- formatApiResponse(200, res, { translations });
87
- };
88
- const adminEditTemplate = async (req, res) => {
89
- const template = req.body.template;
90
- await db.editTemplate(template);
91
- const templates = await db.getTemplates();
92
- formatApiResponse(200, res, {
93
- templates: templates.map((x) => ({
94
- path: x.path,
95
- json: escape(JSON.stringify(x)),
96
- diff: escape(x.diff),
97
- })),
98
- });
99
- };
100
- const adminRemoveTemplate = async (req, res) => {
101
- await db.removeTemplate(req.body.template);
102
- const templates = await db.getTemplates();
103
- formatApiResponse(200, res, {
104
- templates: templates.map((x) => ({
105
- path: x.path,
106
- json: escape(JSON.stringify(x)),
107
- diff: escape(x.diff),
108
- })),
109
- });
110
- };
111
- function controllers({ router, middleware }) {
112
- setupAdminPageRoute(router, '/admin/plugins/customize', renderAdmin);
113
- setupApiRoute(router, 'put', '/api/v3/admin/plugins/customize/edit/template', [middleware.admin.checkPrivileges], adminEditTemplate);
114
- setupApiRoute(router, 'delete', '/api/v3/admin/plugins/customize/delete/template', [middleware.admin.checkPrivileges], adminRemoveTemplate);
115
- setupApiRoute(router, 'put', '/api/v3/admin/plugins/customize/edit/translation', [middleware.admin.checkPrivileges], adminEditTranslation);
116
- setupApiRoute(router, 'delete', '/api/v3/admin/plugins/customize/delete/translation', [middleware.admin.checkPrivileges], adminRemoveTranslation);
117
- setupApiRoute(router, 'put', '/api/v3/admin/plugins/customize/build', [middleware.admin.checkPrivileges], adminBuild);
118
- }
119
- exports.default = controllers;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const path_1 = require("path");
4
+ const util_1 = require("util");
5
+ const fs_extra_1 = require("fs-extra");
6
+ const pubsub_1 = require("./pubsub");
7
+ const db = require("./database");
8
+ if (!require.main) {
9
+ throw Error('[plugin-customize] `require.main` is undefined');
10
+ }
11
+ const nconf = require.main.require('nconf');
12
+ const User = require.main.require('./src/user');
13
+ const Languages = require.main.require('./src/languages');
14
+ const File = require.main.require('./src/file');
15
+ const Translator = require.main.require('./src/translator');
16
+ const Utils = require.main.require('./src/utils');
17
+ const { setupApiRoute, setupAdminPageRoute } = require.main.require('./src/routes/helpers');
18
+ const { formatApiResponse } = require.main.require('./src/controllers/helpers');
19
+ const escape = (dirty) => Translator.escape(Utils.escapeHTML(dirty));
20
+ const listLanguages = (0, util_1.promisify)(Languages.list);
21
+ const getSettings = (0, util_1.promisify)(User.getSettings);
22
+ const walk = (0, util_1.promisify)(File.walk);
23
+ // eslint-disable-next-line import/no-dynamic-require, @typescript-eslint/no-var-requires
24
+ const version = require((0, path_1.join)(__dirname, '../../package.json')).version;
25
+ let namespaceCache = [];
26
+ async function listNamespaces() {
27
+ if (namespaceCache.length) {
28
+ return namespaceCache;
29
+ }
30
+ const metadataFile = (0, path_1.join)(nconf.get('base_dir'), 'build/public/language/metadata.json');
31
+ const metadata = await (0, fs_extra_1.readJson)(metadataFile);
32
+ namespaceCache = metadata.namespaces;
33
+ return namespaceCache;
34
+ }
35
+ let templateCache = [];
36
+ async function listTemplates() {
37
+ if (templateCache.length) {
38
+ return templateCache;
39
+ }
40
+ const viewsDir = nconf.get('views_dir');
41
+ const templates = await walk(viewsDir);
42
+ templateCache = templates
43
+ .filter((path) => path.endsWith('.tpl'))
44
+ .map((path) => (0, path_1.relative)(viewsDir, path).split(/\/\\/).join('/'));
45
+ return templateCache;
46
+ }
47
+ const renderAdmin = async (req, res) => {
48
+ const [templates, translations, languages, userLang, namespaces, templatePaths,] = await Promise.all([
49
+ db.getTemplates(),
50
+ db.getTranslations(),
51
+ listLanguages(),
52
+ getSettings(req.uid).then((data) => data.userLang),
53
+ listNamespaces(),
54
+ listTemplates(),
55
+ ]);
56
+ res.render('admin/plugins/customize', {
57
+ version,
58
+ templates: templates.map((x) => ({
59
+ path: x.path,
60
+ json: escape(JSON.stringify(x)),
61
+ diff: escape(x.diff),
62
+ })),
63
+ translations,
64
+ languages: languages.map(({ code, name }) => ({
65
+ code,
66
+ name,
67
+ selected: code === userLang,
68
+ })),
69
+ namespaces: namespaces.map((name) => ({ name })),
70
+ templatePaths,
71
+ });
72
+ };
73
+ const adminBuild = async (req, res) => {
74
+ await (0, pubsub_1.build)();
75
+ formatApiResponse(200, res, 'OK');
76
+ };
77
+ const adminEditTranslation = async (req, res) => {
78
+ const translation = req.body.translation;
79
+ await db.editTranslation(translation);
80
+ const translations = await db.getTranslations();
81
+ formatApiResponse(200, res, { translations });
82
+ };
83
+ const adminRemoveTranslation = async (req, res) => {
84
+ await db.removeTranslation(req.body.translation);
85
+ const translations = await db.getTranslations();
86
+ formatApiResponse(200, res, { translations });
87
+ };
88
+ const adminEditTemplate = async (req, res) => {
89
+ const template = req.body.template;
90
+ await db.editTemplate(template);
91
+ const templates = await db.getTemplates();
92
+ formatApiResponse(200, res, {
93
+ templates: templates.map((x) => ({
94
+ path: x.path,
95
+ json: escape(JSON.stringify(x)),
96
+ diff: escape(x.diff),
97
+ })),
98
+ });
99
+ };
100
+ const adminRemoveTemplate = async (req, res) => {
101
+ await db.removeTemplate(req.body.template);
102
+ const templates = await db.getTemplates();
103
+ formatApiResponse(200, res, {
104
+ templates: templates.map((x) => ({
105
+ path: x.path,
106
+ json: escape(JSON.stringify(x)),
107
+ diff: escape(x.diff),
108
+ })),
109
+ });
110
+ };
111
+ function controllers({ router, middleware }) {
112
+ setupAdminPageRoute(router, '/admin/plugins/customize', middleware, [], renderAdmin);
113
+ setupApiRoute(router, 'put', '/api/v3/admin/plugins/customize/edit/template', [middleware.admin.checkPrivileges], adminEditTemplate);
114
+ setupApiRoute(router, 'delete', '/api/v3/admin/plugins/customize/delete/template', [middleware.admin.checkPrivileges], adminRemoveTemplate);
115
+ setupApiRoute(router, 'put', '/api/v3/admin/plugins/customize/edit/translation', [middleware.admin.checkPrivileges], adminEditTranslation);
116
+ setupApiRoute(router, 'delete', '/api/v3/admin/plugins/customize/delete/translation', [middleware.admin.checkPrivileges], adminRemoveTranslation);
117
+ setupApiRoute(router, 'put', '/api/v3/admin/plugins/customize/build', [middleware.admin.checkPrivileges], adminBuild);
118
+ }
119
+ exports.default = controllers;
120
120
  //# sourceMappingURL=controllers.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"controllers.js","sourceRoot":"","sources":["../../lib/controllers.ts"],"names":[],"mappings":";;AACA,+BAAsC;AACtC,+BAAiC;AACjC,uCAAoC;AAEpC,qCAAiC;AACjC,iCAAiC;AAEjC,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE;IAAE,MAAM,KAAK,CAAC,gDAAgD,CAAC,CAAC;CAAE;AACrF,MAAM,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;AAC5C,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;AAChD,MAAM,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,iBAAiB,CAAC,CAAC;AAC1D,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;AAChD,MAAM,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,kBAAkB,CAAC,CAAC;AAC5D,MAAM,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC;AAClD,MAAM,EAAE,aAAa,EAAE,mBAAmB,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,sBAAsB,CAAC,CAAC;AAC5F,MAAM,EAAE,iBAAiB,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,2BAA2B,CAAC,CAAC;AAEhF,MAAM,MAAM,GAAG,CAAC,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AE,kDAAkD,EAAE,CAAC,UAAU,CAAC,KAAK,CAAC,eAAe,CAAC,EAAE,oBAAoB,CAAC,CAAC;IAC3I,aAAa,CAAC,MAAM,EAAE,QAAQ,EAAE,oDAAoD,EAAE,CAAC,UAAU,CAAC,KAAK,CAAC,eAAe,CAAC,EAAE,sBAAsB,CAAC,CAAC;IAElJ,aAAa,CAAC,MAAM,EAAE,KAAK,EAAE,uCAAuC,EAAE,CAAC,UAAU,CAAC,KAAK,CAAC,eAAe,CAAC,EAAE,UAAU,CAAC,CAAC;AACxH,CAAC;AAVD,8BAUC"}
@@ -1,92 +1,92 @@
1
- "use strict";
2
- // types and helper functions for database
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.removeTemplate = exports.editTemplate = exports.getTemplates = exports.removeTranslation = exports.editTranslation = exports.getTranslations = void 0;
5
- const util_1 = require("util");
6
- const path_1 = require("path");
7
- const fs_extra_1 = require("fs-extra");
8
- const diff_1 = require("diff");
9
- if (!require.main) {
10
- throw Error('[plugin-customize] `require.main` is undefined');
11
- }
12
- const db = require.main.require('./src/database');
13
- const nconf = require.main.require('nconf');
14
- const getSortedSetRange = (0, util_1.promisify)(db.getSortedSetRange);
15
- const getObjects = (0, util_1.promisify)(db.getObjects);
16
- const sortedSetAdd = (0, util_1.promisify)(db.sortedSetAdd);
17
- const setObject = (0, util_1.promisify)(db.setObject);
18
- const remove = (0, util_1.promisify)(db.delete);
19
- const sortedSetRemove = (0, util_1.promisify)(db.sortedSetRemove);
20
- const languagesDir = (0, path_1.join)(nconf.get('base_dir'), 'build/public/language');
21
- const viewsDir = nconf.get('views_dir');
22
- const translationsSet = 'plugin-customize:translations';
23
- const translationHashKey = (key) => `${translationsSet}:${key}`;
24
- const templatesSet = 'plugin-customize:templates';
25
- const templateHashKey = (key) => `${templatesSet}:${key}`;
26
- // translation id looks like `<language>:<namespace>:<key>`
27
- async function getTranslations() {
28
- const ids = await getSortedSetRange(translationsSet, 0, -1);
29
- const [hashes, currentValues] = await Promise.all([
30
- getObjects(ids.map(translationHashKey)),
31
- Promise.all(ids.map(async (id) => {
32
- const [language, namespace, key] = id.split(':');
33
- const filePath = (0, path_1.join)(languagesDir, language, `${namespace}.json`);
34
- const translations = await (0, fs_extra_1.readJson)(filePath).catch(() => ({}));
35
- return translations[key] || '';
36
- })),
37
- ]);
38
- return currentValues.map((current, i) => (Object.assign({ current }, hashes[i])));
39
- }
40
- exports.getTranslations = getTranslations;
41
- async function editTranslation({ language, namespace, key, old, value, }) {
42
- const id = `${language}:${namespace}:${key}`;
43
- await Promise.all([
44
- setObject(translationHashKey(id), {
45
- language,
46
- namespace,
47
- key,
48
- old,
49
- value,
50
- }),
51
- sortedSetAdd(translationsSet, Date.now(), id),
52
- ]);
53
- }
54
- exports.editTranslation = editTranslation;
55
- async function removeTranslation(id) {
56
- await Promise.all([
57
- remove(translationHashKey(id)),
58
- sortedSetRemove(translationsSet, id),
59
- ]);
60
- }
61
- exports.removeTranslation = removeTranslation;
62
- async function getTemplates() {
63
- const paths = await getSortedSetRange(templatesSet, 0, -1);
64
- const [hashes, currentValues] = await Promise.all([
65
- getObjects(paths.map(templateHashKey)),
66
- Promise.all(paths.map(async (path) => {
67
- const filePath = (0, path_1.join)(viewsDir, path);
68
- return await (0, fs_extra_1.readFile)(filePath, 'utf-8');
69
- })),
70
- ]);
71
- return currentValues.map((current, i) => (Object.assign(Object.assign({}, hashes[i]), { path: paths[i], value: (0, diff_1.applyPatch)(hashes[i].old, hashes[i].diff) })));
72
- }
73
- exports.getTemplates = getTemplates;
74
- async function editTemplate({ path, diff, old, }) {
75
- await Promise.all([
76
- setObject(templateHashKey(path), {
77
- path,
78
- diff,
79
- old,
80
- }),
81
- sortedSetAdd(templatesSet, Date.now(), path),
82
- ]);
83
- }
84
- exports.editTemplate = editTemplate;
85
- async function removeTemplate(path) {
86
- await Promise.all([
87
- remove(templateHashKey(path)),
88
- sortedSetRemove(templatesSet, path),
89
- ]);
90
- }
91
- exports.removeTemplate = removeTemplate;
1
+ "use strict";
2
+ // types and helper functions for database
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.removeTemplate = exports.editTemplate = exports.getTemplates = exports.removeTranslation = exports.editTranslation = exports.getTranslations = void 0;
5
+ const util_1 = require("util");
6
+ const path_1 = require("path");
7
+ const fs_extra_1 = require("fs-extra");
8
+ const diff_1 = require("diff");
9
+ if (!require.main) {
10
+ throw Error('[plugin-customize] `require.main` is undefined');
11
+ }
12
+ const db = require.main.require('./src/database');
13
+ const nconf = require.main.require('nconf');
14
+ const getSortedSetRange = (0, util_1.promisify)(db.getSortedSetRange);
15
+ const getObjects = (0, util_1.promisify)(db.getObjects);
16
+ const sortedSetAdd = (0, util_1.promisify)(db.sortedSetAdd);
17
+ const setObject = (0, util_1.promisify)(db.setObject);
18
+ const remove = (0, util_1.promisify)(db.delete);
19
+ const sortedSetRemove = (0, util_1.promisify)(db.sortedSetRemove);
20
+ const languagesDir = (0, path_1.join)(nconf.get('base_dir'), 'build/public/language');
21
+ const viewsDir = nconf.get('views_dir');
22
+ const translationsSet = 'plugin-customize:translations';
23
+ const translationHashKey = (key) => `${translationsSet}:${key}`;
24
+ const templatesSet = 'plugin-customize:templates';
25
+ const templateHashKey = (key) => `${templatesSet}:${key}`;
26
+ // translation id looks like `<language>:<namespace>:<key>`
27
+ async function getTranslations() {
28
+ const ids = await getSortedSetRange(translationsSet, 0, -1);
29
+ const [hashes, currentValues] = await Promise.all([
30
+ getObjects(ids.map(translationHashKey)),
31
+ Promise.all(ids.map(async (id) => {
32
+ const [language, namespace, key] = id.split(':');
33
+ const filePath = (0, path_1.join)(languagesDir, language, `${namespace}.json`);
34
+ const translations = await (0, fs_extra_1.readJson)(filePath).catch(() => ({}));
35
+ return translations[key] || '';
36
+ })),
37
+ ]);
38
+ return currentValues.map((current, i) => (Object.assign({ current }, hashes[i])));
39
+ }
40
+ exports.getTranslations = getTranslations;
41
+ async function editTranslation({ language, namespace, key, old, value, }) {
42
+ const id = `${language}:${namespace}:${key}`;
43
+ await Promise.all([
44
+ setObject(translationHashKey(id), {
45
+ language,
46
+ namespace,
47
+ key,
48
+ old,
49
+ value,
50
+ }),
51
+ sortedSetAdd(translationsSet, Date.now(), id),
52
+ ]);
53
+ }
54
+ exports.editTranslation = editTranslation;
55
+ async function removeTranslation(id) {
56
+ await Promise.all([
57
+ remove(translationHashKey(id)),
58
+ sortedSetRemove(translationsSet, id),
59
+ ]);
60
+ }
61
+ exports.removeTranslation = removeTranslation;
62
+ async function getTemplates() {
63
+ const paths = await getSortedSetRange(templatesSet, 0, -1);
64
+ const [hashes, currentValues] = await Promise.all([
65
+ getObjects(paths.map(templateHashKey)),
66
+ Promise.all(paths.map(async (path) => {
67
+ const filePath = (0, path_1.join)(viewsDir, path);
68
+ return await (0, fs_extra_1.readFile)(filePath, 'utf-8');
69
+ })),
70
+ ]);
71
+ return currentValues.map((current, i) => (Object.assign(Object.assign({}, hashes[i]), { path: paths[i], value: (0, diff_1.applyPatch)(hashes[i].old, hashes[i].diff) })));
72
+ }
73
+ exports.getTemplates = getTemplates;
74
+ async function editTemplate({ path, diff, old, }) {
75
+ await Promise.all([
76
+ setObject(templateHashKey(path), {
77
+ path,
78
+ diff,
79
+ old,
80
+ }),
81
+ sortedSetAdd(templatesSet, Date.now(), path),
82
+ ]);
83
+ }
84
+ exports.editTemplate = editTemplate;
85
+ async function removeTemplate(path) {
86
+ await Promise.all([
87
+ remove(templateHashKey(path)),
88
+ sortedSetRemove(templatesSet, path),
89
+ ]);
90
+ }
91
+ exports.removeTemplate = removeTemplate;
92
92
  //# sourceMappingURL=database.js.map
@@ -1,19 +1,19 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.adminMenu = exports.init = void 0;
4
- const controllers_1 = require("./controllers");
5
- const init = (params, callback) => {
6
- (0, controllers_1.default)(params);
7
- callback();
8
- };
9
- exports.init = init;
10
- const adminMenu = (header, callback) => {
11
- header.plugins.push({
12
- route: '/plugins/customize',
13
- icon: 'fa-wrench',
14
- name: 'Customize',
15
- });
16
- callback(null, header);
17
- };
18
- exports.adminMenu = adminMenu;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.adminMenu = exports.init = void 0;
4
+ const controllers_1 = require("./controllers");
5
+ const init = (params, callback) => {
6
+ (0, controllers_1.default)(params);
7
+ callback();
8
+ };
9
+ exports.init = init;
10
+ const adminMenu = (header, callback) => {
11
+ header.plugins.push({
12
+ route: '/plugins/customize',
13
+ icon: 'fa-wrench',
14
+ name: 'Customize',
15
+ });
16
+ callback(null, header);
17
+ };
18
+ exports.adminMenu = adminMenu;
19
19
  //# sourceMappingURL=index.js.map