2020-11-05 18:58:23 +02:00
|
|
|
import { _ } from './locale';
|
2021-01-22 19:41:11 +02:00
|
|
|
import Setting from './models/Setting';
|
2021-01-29 20:45:11 +02:00
|
|
|
import { reg } from './registry';
|
2023-02-08 16:16:09 +02:00
|
|
|
import { Plugins } from './services/plugins/PluginService';
|
2020-08-02 17:21:30 +02:00
|
|
|
|
2023-02-08 16:16:09 +02:00
|
|
|
interface PluginList {
|
|
|
|
completeList: string;
|
|
|
|
summary: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getPluginLists(plugins: Plugins): PluginList {
|
|
|
|
const pluginList = [];
|
|
|
|
if (Object.keys(plugins).length > 0) {
|
|
|
|
for (const pluginId in plugins) {
|
|
|
|
pluginList.push(`${plugins[pluginId].manifest.name}: ${plugins[pluginId].manifest.version}`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let completeList = '';
|
|
|
|
let summary = '';
|
|
|
|
if (pluginList.length > 0) {
|
|
|
|
completeList = ['\n', ...pluginList].join('\n');
|
|
|
|
|
|
|
|
if (pluginList.length > 20) {
|
|
|
|
summary = [
|
|
|
|
'\n',
|
|
|
|
...[...pluginList].filter((_, index) => index < 20),
|
|
|
|
'...',
|
|
|
|
].join('\n');
|
|
|
|
} else {
|
|
|
|
summary = completeList;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
completeList,
|
|
|
|
summary,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export default function versionInfo(packageInfo: any, plugins: Plugins) {
|
2020-08-02 17:21:30 +02:00
|
|
|
const p = packageInfo;
|
|
|
|
let gitInfo = '';
|
|
|
|
if ('git' in p) {
|
|
|
|
gitInfo = _('Revision: %s (%s)', p.git.hash, p.git.branch);
|
2021-03-11 16:39:18 +02:00
|
|
|
if (p.git.branch === 'HEAD') gitInfo = gitInfo.slice(0, -7);
|
2020-08-02 17:21:30 +02:00
|
|
|
}
|
|
|
|
const copyrightText = 'Copyright © 2016-YYYY Laurent Cozic';
|
|
|
|
const now = new Date();
|
2020-10-21 11:10:18 +02:00
|
|
|
|
|
|
|
const header = [
|
2020-08-02 17:21:30 +02:00
|
|
|
p.description,
|
|
|
|
'',
|
|
|
|
copyrightText.replace('YYYY', `${now.getFullYear()}`),
|
2020-10-21 11:10:18 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
const body = [
|
2020-08-02 17:21:30 +02:00
|
|
|
_('%s %s (%s, %s)', p.name, p.version, Setting.value('env'), process.platform),
|
|
|
|
'',
|
|
|
|
_('Client ID: %s', Setting.value('clientId')),
|
|
|
|
_('Sync Version: %s', Setting.value('syncVersion')),
|
|
|
|
_('Profile Version: %s', reg.db().version()),
|
|
|
|
_('Keychain Supported: %s', Setting.value('keychain.supported') >= 1 ? _('Yes') : _('No')),
|
|
|
|
];
|
2020-10-21 11:10:18 +02:00
|
|
|
|
2020-08-02 17:21:30 +02:00
|
|
|
if (gitInfo) {
|
2020-10-21 11:10:18 +02:00
|
|
|
body.push(`\n${gitInfo}`);
|
2020-08-02 17:21:30 +02:00
|
|
|
}
|
|
|
|
|
2023-02-08 16:16:09 +02:00
|
|
|
const pluginList = getPluginLists(plugins);
|
|
|
|
|
2020-08-02 17:21:30 +02:00
|
|
|
return {
|
2020-10-21 11:10:18 +02:00
|
|
|
header: header.join('\n'),
|
2023-02-08 16:16:09 +02:00
|
|
|
body: body.join('\n').concat(pluginList.completeList),
|
|
|
|
message: header.concat(body).join('\n').concat(pluginList.summary),
|
2020-08-02 17:21:30 +02:00
|
|
|
};
|
|
|
|
}
|