keeweb-plugins/scripts/update-plugins.js

68 lines
1.9 KiB
JavaScript
Raw Normal View History

2017-05-25 19:26:48 +02:00
/* eslint-disable no-console */
2017-05-13 20:32:11 +02:00
const fs = require('fs');
const crypto = require('crypto');
console.log('Welcome to plugins updater');
2017-05-20 12:07:59 +02:00
console.log('Loading...');
2017-05-13 20:32:11 +02:00
const data = JSON.parse(fs.readFileSync('docs/plugins.json', 'utf8'));
const privateKey = fs.readFileSync('keys/private-key.pem', 'binary');
2017-05-20 12:07:59 +02:00
data.signature = '';
data.date = '';
const oldData = JSON.stringify(data);
2017-05-13 20:32:11 +02:00
console.log('Adding translations...');
const allTranslations = JSON.parse(fs.readFileSync('docs/translations/meta.json', 'utf8'));
for (const translation of Object.keys(allTranslations)) {
const manifest = JSON.parse(fs.readFileSync(`docs/translations/${translation}/manifest.json`));
const url = `https://plugins.keeweb.info/translations/${translation}`;
2017-05-13 21:57:31 +02:00
const official = true;
const pluginMeta = { url, official, manifest };
2017-05-13 20:32:11 +02:00
const ix = data.plugins.findIndex(p => p.manifest.name === manifest.name);
if (ix >= 0) {
data.plugins.splice(ix, 1, pluginMeta);
} else {
data.plugins.push(pluginMeta);
}
}
2017-05-25 19:26:48 +02:00
console.log('Updating plugins...');
for (const plugin of data.plugins) {
if (plugin.manifest.locale) {
continue;
}
if (plugin.official) {
plugin.manifest = JSON.parse(fs.readFileSync(`docs/plugins/${plugin.manifest.name}/manifest.json`, 'utf8'));
}
}
2017-05-20 12:07:59 +02:00
console.log('Checking for changes...');
const newData = JSON.stringify(data);
if (newData === oldData) {
console.log('No changes');
process.exit(0);
}
console.log('Changes found, updating metadata...');
data.date = new Date().toISOString();
2017-05-13 20:32:11 +02:00
console.log('Signing...');
const dataToSign = JSON.stringify(data, null, 2);
const sign = crypto.createSign('RSA-SHA256');
sign.write(new Buffer(dataToSign));
sign.end();
data.signature = sign.sign(privateKey).toString('base64');
fs.writeFileSync('docs/plugins.json', JSON.stringify(data, null, 2));
console.log('Done');