@nocobase/plugin-client 0.10.0-alpha.5 → 0.11.0-alpha.1
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/client.d.ts +3 -0
- package/client.js +1 -0
- package/lib/client/index.d.ts +5 -0
- package/lib/client/index.js +22 -0
- package/lib/{cronstrue.js → server/cronstrue.js} +1 -1
- package/lib/server/index.d.ts +1 -0
- package/lib/server/index.js +13 -0
- package/lib/{migrations → server/migrations}/20230620203216-admin-ui-schema-uid.js +1 -1
- package/lib/{server.js → server/server.js} +13 -13
- package/package.json +23 -5
- package/server.d.ts +3 -0
- package/server.js +1 -0
- package/src/client/index.ts +7 -0
- package/src/index.ts +1 -0
- package/src/server/antd.ts +9 -0
- package/src/server/cron.ts +16 -0
- package/src/server/cronstrue.ts +111 -0
- package/src/server/index.ts +1 -0
- package/src/server/locale/en-US.json +1289 -0
- package/src/server/locale/es-ES.json +1462 -0
- package/src/server/locale/index.ts +4 -0
- package/src/server/locale/pt-BR.json +1385 -0
- package/src/server/locale/uk-UA.json +1289 -0
- package/src/server/locale/zh-CN.json +1388 -0
- package/src/server/migrations/20230620203216-admin-ui-schema-uid.ts +26 -0
- package/src/server/moment-locale.ts +141 -0
- package/src/server/resource.ts +69 -0
- package/src/server/server.ts +277 -0
- /package/lib/{antd.d.ts → server/antd.d.ts} +0 -0
- /package/lib/{antd.js → server/antd.js} +0 -0
- /package/lib/{cron.d.ts → server/cron.d.ts} +0 -0
- /package/lib/{cron.js → server/cron.js} +0 -0
- /package/lib/{cronstrue.d.ts → server/cronstrue.d.ts} +0 -0
- /package/lib/{locale → server/locale}/en-US.json +0 -0
- /package/lib/{locale → server/locale}/es-ES.json +0 -0
- /package/lib/{locale → server/locale}/index.d.ts +0 -0
- /package/lib/{locale → server/locale}/index.js +0 -0
- /package/lib/{locale → server/locale}/pt-BR.json +0 -0
- /package/lib/{locale → server/locale}/uk-UA.json +0 -0
- /package/lib/{locale → server/locale}/zh-CN.json +0 -0
- /package/lib/{migrations → server/migrations}/20230620203216-admin-ui-schema-uid.d.ts +0 -0
- /package/lib/{moment-locale.d.ts → server/moment-locale.d.ts} +0 -0
- /package/lib/{moment-locale.js → server/moment-locale.js} +0 -0
- /package/lib/{resource.d.ts → server/resource.d.ts} +0 -0
- /package/lib/{resource.js → server/resource.js} +0 -0
- /package/lib/{server.d.ts → server/server.d.ts} +0 -0
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Model } from '@nocobase/database';
|
|
2
|
+
import { Migration } from '@nocobase/server';
|
|
3
|
+
|
|
4
|
+
export default class extends Migration {
|
|
5
|
+
async up() {
|
|
6
|
+
const systemSettings = this.db.getRepository('systemSettings');
|
|
7
|
+
let instance: Model = await systemSettings.findOne();
|
|
8
|
+
const uiRoutes = this.db.getRepository('uiRoutes');
|
|
9
|
+
const routes = await uiRoutes.find();
|
|
10
|
+
for (const route of routes) {
|
|
11
|
+
if (route.uiSchemaUid && route?.options?.component === 'AdminLayout') {
|
|
12
|
+
const options = instance.options || {};
|
|
13
|
+
options['adminSchemaUid'] = route.uiSchemaUid;
|
|
14
|
+
instance.set('options', options);
|
|
15
|
+
instance.changed('options', true);
|
|
16
|
+
await instance.save();
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
instance = await systemSettings.findOne();
|
|
21
|
+
if (!instance?.options?.adminSchemaUid) {
|
|
22
|
+
throw new Error('adminSchemaUid invalid');
|
|
23
|
+
}
|
|
24
|
+
this.app.log.info('systemSettings.options', instance.toJSON());
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
const locales = {
|
|
2
|
+
af: 'af',
|
|
3
|
+
'ar-dz': 'ar-dz',
|
|
4
|
+
'ar-kw': 'ar-kw',
|
|
5
|
+
'ar-ly': 'ar-ly',
|
|
6
|
+
'ar-ma': 'ar-ma',
|
|
7
|
+
'ar-sa': 'ar-sa',
|
|
8
|
+
'ar-tn': 'ar-tn',
|
|
9
|
+
ar: 'ar',
|
|
10
|
+
az: 'az',
|
|
11
|
+
be: 'be',
|
|
12
|
+
bg: 'bg',
|
|
13
|
+
bm: 'bm',
|
|
14
|
+
'bn-bd': 'bn-bd',
|
|
15
|
+
bn: 'bn',
|
|
16
|
+
bo: 'bo',
|
|
17
|
+
br: 'br',
|
|
18
|
+
bs: 'bs',
|
|
19
|
+
ca: 'ca',
|
|
20
|
+
cs: 'cs',
|
|
21
|
+
cv: 'cv',
|
|
22
|
+
cy: 'cy',
|
|
23
|
+
da: 'da',
|
|
24
|
+
'de-at': 'de-at',
|
|
25
|
+
'de-ch': 'de-ch',
|
|
26
|
+
de: 'de',
|
|
27
|
+
dv: 'dv',
|
|
28
|
+
el: 'el',
|
|
29
|
+
'en-au': 'en-au',
|
|
30
|
+
'en-ca': 'en-ca',
|
|
31
|
+
'en-gb': 'en-gb',
|
|
32
|
+
'en-ie': 'en-ie',
|
|
33
|
+
'en-il': 'en-il',
|
|
34
|
+
'en-in': 'en-in',
|
|
35
|
+
'en-nz': 'en-nz',
|
|
36
|
+
'en-sg': 'en-sg',
|
|
37
|
+
eo: 'eo',
|
|
38
|
+
'es-do': 'es-do',
|
|
39
|
+
'es-mx': 'es-mx',
|
|
40
|
+
'es-us': 'es-us',
|
|
41
|
+
es: 'es',
|
|
42
|
+
et: 'et',
|
|
43
|
+
eu: 'eu',
|
|
44
|
+
fa: 'fa',
|
|
45
|
+
fi: 'fi',
|
|
46
|
+
fil: 'fil',
|
|
47
|
+
fo: 'fo',
|
|
48
|
+
'fr-ca': 'fr-ca',
|
|
49
|
+
'fr-ch': 'fr-ch',
|
|
50
|
+
fr: 'fr',
|
|
51
|
+
fy: 'fy',
|
|
52
|
+
ga: 'ga',
|
|
53
|
+
gd: 'gd',
|
|
54
|
+
gl: 'gl',
|
|
55
|
+
'gom-deva': 'gom-deva',
|
|
56
|
+
'gom-latn': 'gom-latn',
|
|
57
|
+
gu: 'gu',
|
|
58
|
+
he: 'he',
|
|
59
|
+
hi: 'hi',
|
|
60
|
+
hr: 'hr',
|
|
61
|
+
hu: 'hu',
|
|
62
|
+
'hy-am': 'hy-am',
|
|
63
|
+
id: 'id',
|
|
64
|
+
is: 'is',
|
|
65
|
+
'it-ch': 'it-ch',
|
|
66
|
+
it: 'it',
|
|
67
|
+
'ja-JP': 'ja',
|
|
68
|
+
jv: 'jv',
|
|
69
|
+
ka: 'ka',
|
|
70
|
+
kk: 'kk',
|
|
71
|
+
km: 'km',
|
|
72
|
+
kn: 'kn',
|
|
73
|
+
ko: 'ko',
|
|
74
|
+
ku: 'ku',
|
|
75
|
+
ky: 'ky',
|
|
76
|
+
lb: 'lb',
|
|
77
|
+
lo: 'lo',
|
|
78
|
+
lt: 'lt',
|
|
79
|
+
lv: 'lv',
|
|
80
|
+
me: 'me',
|
|
81
|
+
mi: 'mi',
|
|
82
|
+
mk: 'mk',
|
|
83
|
+
ml: 'ml',
|
|
84
|
+
mn: 'mn',
|
|
85
|
+
mr: 'mr',
|
|
86
|
+
'ms-my': 'ms-my',
|
|
87
|
+
ms: 'ms',
|
|
88
|
+
mt: 'mt',
|
|
89
|
+
my: 'my',
|
|
90
|
+
nb: 'nb',
|
|
91
|
+
ne: 'ne',
|
|
92
|
+
'nl-be': 'nl-be',
|
|
93
|
+
nl: 'nl',
|
|
94
|
+
nn: 'nn',
|
|
95
|
+
'oc-lnc': 'oc-lnc',
|
|
96
|
+
'pa-in': 'pa-in',
|
|
97
|
+
pl: 'pl',
|
|
98
|
+
'pt-br': 'pt-br',
|
|
99
|
+
pt: 'pt',
|
|
100
|
+
ro: 'ro',
|
|
101
|
+
'ru-RU': 'ru',
|
|
102
|
+
sd: 'sd',
|
|
103
|
+
se: 'se',
|
|
104
|
+
si: 'si',
|
|
105
|
+
sk: 'sk',
|
|
106
|
+
sl: 'sl',
|
|
107
|
+
sq: 'sq',
|
|
108
|
+
'sr-cyrl': 'sr-cyrl',
|
|
109
|
+
sr: 'sr',
|
|
110
|
+
ss: 'ss',
|
|
111
|
+
sv: 'sv',
|
|
112
|
+
sw: 'sw',
|
|
113
|
+
ta: 'ta',
|
|
114
|
+
te: 'te',
|
|
115
|
+
tet: 'tet',
|
|
116
|
+
tg: 'tg',
|
|
117
|
+
'th-TH': 'th',
|
|
118
|
+
tk: 'tk',
|
|
119
|
+
'tl-ph': 'tl-ph',
|
|
120
|
+
tlh: 'tlh',
|
|
121
|
+
'tr-TR': 'tr',
|
|
122
|
+
tzl: 'tzl',
|
|
123
|
+
'tzm-latn': 'tzm-latn',
|
|
124
|
+
tzm: 'tzm',
|
|
125
|
+
'ug-cn': 'ug-cn',
|
|
126
|
+
uk: 'uk',
|
|
127
|
+
ur: 'ur',
|
|
128
|
+
'uz-latn': 'uz-latn',
|
|
129
|
+
uz: 'uz',
|
|
130
|
+
vi: 'vi',
|
|
131
|
+
'x-pseudo': 'x-pseudo',
|
|
132
|
+
yo: 'yo',
|
|
133
|
+
'zh-CN': 'zh-cn',
|
|
134
|
+
'zh-hk': 'zh-hk',
|
|
135
|
+
'zh-mo': 'zh-mo',
|
|
136
|
+
'zh-TW': 'zh-tw',
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
export const getMomentLocale = (lang: string) => {
|
|
140
|
+
return locales[lang] || 'en';
|
|
141
|
+
};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { PluginManager } from '@nocobase/server';
|
|
2
|
+
|
|
3
|
+
const arr2obj = (items: any[]) => {
|
|
4
|
+
const obj = {};
|
|
5
|
+
for (const item of items) {
|
|
6
|
+
Object.assign(obj, item);
|
|
7
|
+
}
|
|
8
|
+
return obj;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
const getResource = (packageName: string, lang: string) => {
|
|
12
|
+
const resources = [];
|
|
13
|
+
const prefixes = ['src', 'lib'];
|
|
14
|
+
const localeKeys = ['locale', 'client/locale', 'server/locale'];
|
|
15
|
+
for (const prefix of prefixes) {
|
|
16
|
+
for (const localeKey of localeKeys) {
|
|
17
|
+
try {
|
|
18
|
+
const file = `${packageName}/${prefix}/${localeKey}/${lang}`;
|
|
19
|
+
require.resolve(file);
|
|
20
|
+
const resource = require(file).default;
|
|
21
|
+
resources.push(resource);
|
|
22
|
+
} catch (error) {}
|
|
23
|
+
}
|
|
24
|
+
if (resources.length) {
|
|
25
|
+
break;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
if (resources.length === 0 && lang.replace('-', '_') !== lang) {
|
|
29
|
+
return getResource(packageName, lang.replace('-', '_'));
|
|
30
|
+
}
|
|
31
|
+
return arr2obj(resources);
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export const getResourceLocale = async (lang: string, db: any) => {
|
|
35
|
+
const resources = {};
|
|
36
|
+
const res = getResource('@nocobase/client', lang);
|
|
37
|
+
const defaults = getResource('@nocobase/client', 'zh-CN');
|
|
38
|
+
for (const key in defaults) {
|
|
39
|
+
if (Object.prototype.hasOwnProperty.call(defaults, key)) {
|
|
40
|
+
defaults[key] = key;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
if (res) {
|
|
44
|
+
resources['client'] = { ...defaults, ...res };
|
|
45
|
+
} else {
|
|
46
|
+
resources['client'] = defaults;
|
|
47
|
+
}
|
|
48
|
+
const plugins = await db.getRepository('applicationPlugins').find({
|
|
49
|
+
filter: {
|
|
50
|
+
'name.$ne': 'client',
|
|
51
|
+
},
|
|
52
|
+
});
|
|
53
|
+
for (const plugin of plugins) {
|
|
54
|
+
const packageName = PluginManager.getPackageName(plugin.get('name'));
|
|
55
|
+
const res = getResource(packageName, lang);
|
|
56
|
+
const defaults = getResource(packageName, 'zh-CN');
|
|
57
|
+
for (const key in defaults) {
|
|
58
|
+
if (Object.prototype.hasOwnProperty.call(defaults, key)) {
|
|
59
|
+
defaults[key] = key;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
if (res) {
|
|
63
|
+
resources[plugin.get('name')] = { ...defaults, ...res };
|
|
64
|
+
} else {
|
|
65
|
+
resources['client'] = defaults;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return resources;
|
|
69
|
+
};
|
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
import { Plugin, PluginManager } from '@nocobase/server';
|
|
2
|
+
import { lodash } from '@nocobase/utils';
|
|
3
|
+
import fs from 'fs';
|
|
4
|
+
import send from 'koa-send';
|
|
5
|
+
import serve from 'koa-static';
|
|
6
|
+
import { isAbsolute, resolve } from 'path';
|
|
7
|
+
import { getAntdLocale } from './antd';
|
|
8
|
+
import { getCronLocale } from './cron';
|
|
9
|
+
import { getCronstrueLocale } from './cronstrue';
|
|
10
|
+
import { getMomentLocale } from './moment-locale';
|
|
11
|
+
import { getResourceLocale } from './resource';
|
|
12
|
+
|
|
13
|
+
async function getReadMe(name: string, locale: string) {
|
|
14
|
+
const packageName = PluginManager.getPackageName(name);
|
|
15
|
+
const dir = resolve(process.cwd(), 'node_modules', packageName);
|
|
16
|
+
const files = [resolve(dir, `README.${locale}.md`), resolve(dir, `README.md`)];
|
|
17
|
+
const file = files.find((file) => {
|
|
18
|
+
return fs.existsSync(file);
|
|
19
|
+
});
|
|
20
|
+
return file ? (await fs.promises.readFile(file)).toString() : '';
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
async function getTabs(name: string, locale: string) {
|
|
24
|
+
const packageName = PluginManager.getPackageName(name);
|
|
25
|
+
const dir = resolve(process.cwd(), 'node_modules', packageName);
|
|
26
|
+
const file = resolve(dir, 'docs', locale, 'tabs.json');
|
|
27
|
+
if (!fs.existsSync(file)) {
|
|
28
|
+
// TODO: compatible README, remove it in all plugin has tabs.json
|
|
29
|
+
return [
|
|
30
|
+
{
|
|
31
|
+
title: 'README',
|
|
32
|
+
path: '__README__',
|
|
33
|
+
},
|
|
34
|
+
];
|
|
35
|
+
}
|
|
36
|
+
return JSON.parse((await fs.promises.readFile(file)).toString());
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
interface TabInfoParams {
|
|
40
|
+
filterByTk: string;
|
|
41
|
+
path: string;
|
|
42
|
+
locale: string;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
async function getTabInfo({ filterByTk, path, locale }: TabInfoParams) {
|
|
46
|
+
const packageName = PluginManager.getPackageName(filterByTk);
|
|
47
|
+
const dir = resolve(process.cwd(), 'node_modules', packageName);
|
|
48
|
+
if (path === '__README__') {
|
|
49
|
+
return await getReadMe(filterByTk, locale);
|
|
50
|
+
}
|
|
51
|
+
const files = [
|
|
52
|
+
resolve(dir, 'docs', locale, `${path}.md`),
|
|
53
|
+
// default
|
|
54
|
+
resolve(dir, 'docs', 'en-US', `${path}.md`),
|
|
55
|
+
resolve(dir, 'docs', 'zh-CN', `${path}.md`),
|
|
56
|
+
];
|
|
57
|
+
const file = files.find((file) => {
|
|
58
|
+
return fs.existsSync(file);
|
|
59
|
+
});
|
|
60
|
+
return file ? (await fs.promises.readFile(file)).toString() : '';
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
async function getLang(ctx) {
|
|
64
|
+
const SystemSetting = ctx.db.getRepository('systemSettings');
|
|
65
|
+
const systemSetting = await SystemSetting.findOne();
|
|
66
|
+
const enabledLanguages: string[] = systemSetting.get('enabledLanguages') || [];
|
|
67
|
+
const currentUser = ctx.state.currentUser;
|
|
68
|
+
let lang = enabledLanguages?.[0] || process.env.APP_LANG || 'en-US';
|
|
69
|
+
if (enabledLanguages.includes(currentUser?.appLang)) {
|
|
70
|
+
lang = currentUser?.appLang;
|
|
71
|
+
}
|
|
72
|
+
if (ctx.request.query.locale) {
|
|
73
|
+
lang = ctx.request.query.locale;
|
|
74
|
+
}
|
|
75
|
+
return lang;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export class ClientPlugin extends Plugin {
|
|
79
|
+
async beforeLoad() {
|
|
80
|
+
// const cmd = this.app.findCommand('install');
|
|
81
|
+
// if (cmd) {
|
|
82
|
+
// cmd.option('--import-demo');
|
|
83
|
+
// }
|
|
84
|
+
this.app.on('afterInstall', async (app, options) => {
|
|
85
|
+
const [opts] = options?.cliArgs || [{}];
|
|
86
|
+
if (opts?.importDemo) {
|
|
87
|
+
//
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
this.db.on('systemSettings.beforeCreate', async (instance, { transaction }) => {
|
|
92
|
+
const uiSchemas = this.db.getRepository<any>('uiSchemas');
|
|
93
|
+
const schema = await uiSchemas.insert(
|
|
94
|
+
{
|
|
95
|
+
type: 'void',
|
|
96
|
+
'x-component': 'Menu',
|
|
97
|
+
'x-designer': 'Menu.Designer',
|
|
98
|
+
'x-initializer': 'MenuItemInitializers',
|
|
99
|
+
'x-component-props': {
|
|
100
|
+
mode: 'mix',
|
|
101
|
+
theme: 'dark',
|
|
102
|
+
// defaultSelectedUid: 'u8',
|
|
103
|
+
onSelect: '{{ onSelect }}',
|
|
104
|
+
sideMenuRefScopeKey: 'sideMenuRef',
|
|
105
|
+
},
|
|
106
|
+
properties: {},
|
|
107
|
+
},
|
|
108
|
+
{ transaction },
|
|
109
|
+
);
|
|
110
|
+
instance.set('options.adminSchemaUid', schema['x-uid']);
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
async load() {
|
|
115
|
+
this.db.addMigrations({
|
|
116
|
+
namespace: 'client',
|
|
117
|
+
directory: resolve(__dirname, './migrations'),
|
|
118
|
+
context: {
|
|
119
|
+
plugin: this,
|
|
120
|
+
},
|
|
121
|
+
});
|
|
122
|
+
this.app.acl.allow('app', 'getLang');
|
|
123
|
+
this.app.acl.allow('app', 'getInfo');
|
|
124
|
+
this.app.acl.allow('app', 'getPlugins');
|
|
125
|
+
this.app.acl.allow('plugins', '*', 'public');
|
|
126
|
+
this.app.acl.registerSnippet({
|
|
127
|
+
name: 'app',
|
|
128
|
+
actions: ['app:reboot', 'app:clearCache'],
|
|
129
|
+
});
|
|
130
|
+
const dialect = this.app.db.sequelize.getDialect();
|
|
131
|
+
const locales = require('./locale').default;
|
|
132
|
+
const restartMark = resolve(process.cwd(), 'storage', 'restart');
|
|
133
|
+
this.app.on('beforeStart', async () => {
|
|
134
|
+
if (fs.existsSync(restartMark)) {
|
|
135
|
+
fs.unlinkSync(restartMark);
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
this.app.resource({
|
|
139
|
+
name: 'app',
|
|
140
|
+
actions: {
|
|
141
|
+
async getInfo(ctx, next) {
|
|
142
|
+
const SystemSetting = ctx.db.getRepository('systemSettings');
|
|
143
|
+
const systemSetting = await SystemSetting.findOne();
|
|
144
|
+
const enabledLanguages: string[] = systemSetting.get('enabledLanguages') || [];
|
|
145
|
+
const currentUser = ctx.state.currentUser;
|
|
146
|
+
let lang = enabledLanguages?.[0] || process.env.APP_LANG || 'en-US';
|
|
147
|
+
if (enabledLanguages.includes(currentUser?.appLang)) {
|
|
148
|
+
lang = currentUser?.appLang;
|
|
149
|
+
}
|
|
150
|
+
ctx.body = {
|
|
151
|
+
database: {
|
|
152
|
+
dialect,
|
|
153
|
+
},
|
|
154
|
+
version: await ctx.app.version.get(),
|
|
155
|
+
lang,
|
|
156
|
+
theme: currentUser?.systemSettings?.theme || systemSetting?.options?.theme || 'default',
|
|
157
|
+
};
|
|
158
|
+
await next();
|
|
159
|
+
},
|
|
160
|
+
async getLang(ctx, next) {
|
|
161
|
+
const lang = await getLang(ctx);
|
|
162
|
+
if (lodash.isEmpty(locales[lang])) {
|
|
163
|
+
locales[lang] = {};
|
|
164
|
+
}
|
|
165
|
+
if (lodash.isEmpty(locales[lang].resources)) {
|
|
166
|
+
locales[lang].resources = await getResourceLocale(lang, ctx.db);
|
|
167
|
+
}
|
|
168
|
+
if (lodash.isEmpty(locales[lang].antd)) {
|
|
169
|
+
locales[lang].antd = getAntdLocale(lang);
|
|
170
|
+
}
|
|
171
|
+
if (lodash.isEmpty(locales[lang].cronstrue)) {
|
|
172
|
+
locales[lang].cronstrue = getCronstrueLocale(lang);
|
|
173
|
+
}
|
|
174
|
+
if (lodash.isEmpty(locales[lang].cron)) {
|
|
175
|
+
locales[lang].cron = getCronLocale(lang);
|
|
176
|
+
}
|
|
177
|
+
ctx.body = {
|
|
178
|
+
lang,
|
|
179
|
+
moment: getMomentLocale(lang),
|
|
180
|
+
...locales[lang],
|
|
181
|
+
};
|
|
182
|
+
await next();
|
|
183
|
+
},
|
|
184
|
+
async getPlugins(ctx, next) {
|
|
185
|
+
const pm = ctx.db.getRepository('applicationPlugins');
|
|
186
|
+
const items = await pm.find({
|
|
187
|
+
filter: {
|
|
188
|
+
enabled: true,
|
|
189
|
+
},
|
|
190
|
+
});
|
|
191
|
+
ctx.body = items
|
|
192
|
+
.filter((item) => {
|
|
193
|
+
try {
|
|
194
|
+
const packageName = PluginManager.getPackageName(item.name);
|
|
195
|
+
require.resolve(`${packageName}/client`);
|
|
196
|
+
return true;
|
|
197
|
+
} catch (error) {}
|
|
198
|
+
return false;
|
|
199
|
+
})
|
|
200
|
+
.map((item) => item.name);
|
|
201
|
+
await next();
|
|
202
|
+
},
|
|
203
|
+
async clearCache(ctx, next) {
|
|
204
|
+
await ctx.cache.reset();
|
|
205
|
+
await next();
|
|
206
|
+
},
|
|
207
|
+
reboot(ctx) {
|
|
208
|
+
const RESTART_CODE = 100;
|
|
209
|
+
process.on('exit', (code) => {
|
|
210
|
+
if (code === RESTART_CODE && process.env.APP_ENV === 'production') {
|
|
211
|
+
fs.writeFileSync(restartMark, '1');
|
|
212
|
+
console.log('Restart mark created.');
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
ctx.app.on('afterStop', () => {
|
|
216
|
+
// Exit with code 100 will restart the process
|
|
217
|
+
process.exit(RESTART_CODE);
|
|
218
|
+
});
|
|
219
|
+
ctx.app.stop();
|
|
220
|
+
},
|
|
221
|
+
},
|
|
222
|
+
});
|
|
223
|
+
this.app.resource({
|
|
224
|
+
name: 'plugins',
|
|
225
|
+
actions: {
|
|
226
|
+
async getInfo(ctx, next) {
|
|
227
|
+
const lang = await getLang(ctx);
|
|
228
|
+
const { filterByTk } = ctx.action.params;
|
|
229
|
+
ctx.body = {
|
|
230
|
+
filterByTk,
|
|
231
|
+
readMe: await getReadMe(filterByTk, lang),
|
|
232
|
+
};
|
|
233
|
+
await next();
|
|
234
|
+
},
|
|
235
|
+
async getTabs(ctx, next) {
|
|
236
|
+
const lang = await getLang(ctx);
|
|
237
|
+
const { filterByTk } = ctx.action.params;
|
|
238
|
+
ctx.body = {
|
|
239
|
+
filterByTk,
|
|
240
|
+
tabs: await getTabs(filterByTk, lang),
|
|
241
|
+
};
|
|
242
|
+
await next();
|
|
243
|
+
},
|
|
244
|
+
async getTabInfo(ctx, next) {
|
|
245
|
+
const locale = await getLang(ctx);
|
|
246
|
+
const { filterByTk } = ctx.action.params;
|
|
247
|
+
ctx.body = {
|
|
248
|
+
filterByTk,
|
|
249
|
+
content: await getTabInfo({ ...(ctx.action.params as any), locale }),
|
|
250
|
+
};
|
|
251
|
+
await next();
|
|
252
|
+
},
|
|
253
|
+
},
|
|
254
|
+
});
|
|
255
|
+
let root = this.options.dist || `./packages/app/client/dist`;
|
|
256
|
+
if (!isAbsolute(root)) {
|
|
257
|
+
root = resolve(process.cwd(), root);
|
|
258
|
+
}
|
|
259
|
+
if (process.env.APP_ENV !== 'production' && root) {
|
|
260
|
+
this.app.use(
|
|
261
|
+
async (ctx, next) => {
|
|
262
|
+
if (ctx.path.startsWith(this.app.resourcer.options.prefix)) {
|
|
263
|
+
return next();
|
|
264
|
+
}
|
|
265
|
+
await serve(root)(ctx, next);
|
|
266
|
+
// console.log('koa-send', root, ctx.status);
|
|
267
|
+
if (ctx.status == 404) {
|
|
268
|
+
return send(ctx, 'index.html', { root });
|
|
269
|
+
}
|
|
270
|
+
},
|
|
271
|
+
{ tag: 'clientStatic', before: 'cors' },
|
|
272
|
+
);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
export default ClientPlugin;
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|