2019-03-26 18:08:50 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
2022-04-17 05:07:16 +00:00
|
|
|
const fs = require('@npmcli/fs')
|
2019-03-28 11:27:44 +00:00
|
|
|
const util = require('util');
|
|
|
|
|
const exec = util.promisify(require('child_process').exec);
|
2019-03-26 18:08:50 +00:00
|
|
|
const zaf = require('zip-a-folder');
|
|
|
|
|
|
|
|
|
|
const DEST = 'keepassxc-browser';
|
|
|
|
|
const DEFAULT = 'manifest_default.json';
|
|
|
|
|
const BROWSERS = {
|
|
|
|
|
'Firefox': 'manifest_firefox.json',
|
|
|
|
|
'Chromium': 'manifest_chromium.json',
|
|
|
|
|
};
|
|
|
|
|
|
2022-04-17 05:07:16 +00:00
|
|
|
async function adjustManifest(manifest) {
|
|
|
|
|
const manifestFile = await fs.readFile(DEFAULT, { encoding: 'utf8' });
|
2019-03-26 18:08:50 +00:00
|
|
|
const data = JSON.parse(manifestFile);
|
|
|
|
|
const browser = manifest.substring(manifest.indexOf('_') + 1, manifest.indexOf('.'));
|
|
|
|
|
|
|
|
|
|
if (manifest.includes('firefox')) {
|
|
|
|
|
for (const elem in data['icons']) {
|
|
|
|
|
data['icons'][elem] = 'icons/keepassxc.svg';
|
|
|
|
|
}
|
|
|
|
|
for (const elem in data['browser_action']['default_icon']) {
|
|
|
|
|
data['browser_action']['default_icon'][elem] = 'icons/keepassxc.svg';
|
|
|
|
|
}
|
2020-07-09 14:52:16 +00:00
|
|
|
delete data['version_name'];
|
2019-03-26 18:08:50 +00:00
|
|
|
} else if (manifest.includes('chromium')) {
|
|
|
|
|
delete data['applications'];
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-17 05:07:16 +00:00
|
|
|
await fs.writeFile(manifest, JSON.stringify(data, null, 4));
|
2019-03-26 18:08:50 +00:00
|
|
|
return `keepassxc-browser_${data['version']}_${browser}.zip`;
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-28 11:27:44 +00:00
|
|
|
async function updateTranslations() {
|
|
|
|
|
console.log('Pulling translations from Transifex, please wait...');
|
|
|
|
|
const { stdout } = await exec('tx pull -af');
|
|
|
|
|
console.log(stdout);
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-26 18:08:50 +00:00
|
|
|
(async() => {
|
2019-03-28 11:27:44 +00:00
|
|
|
await updateTranslations();
|
2022-04-17 05:07:16 +00:00
|
|
|
await fs.copyFile(`${DEST}/manifest.json`, `./${DEFAULT}`);
|
2019-03-26 18:08:50 +00:00
|
|
|
|
|
|
|
|
for (const browser in BROWSERS) {
|
|
|
|
|
console.log(`KeePassXC-Browser: Creating extension package for ${browser}`);
|
2022-04-17 05:07:16 +00:00
|
|
|
|
|
|
|
|
const fileName = await adjustManifest(BROWSERS[browser]);
|
|
|
|
|
await fs.copyFile(BROWSERS[browser], `${DEST}/manifest.json`);
|
|
|
|
|
|
|
|
|
|
if (await fs.exists(fileName)) {
|
|
|
|
|
await fs.rm(fileName);
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-26 18:08:50 +00:00
|
|
|
await zaf.zip(DEST, fileName);
|
2022-04-17 05:07:16 +00:00
|
|
|
await fs.rm(BROWSERS[browser], { recursive: true });
|
2019-03-26 18:08:50 +00:00
|
|
|
console.log('Done');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fs.renameSync(DEFAULT, `${DEST}/manifest.json`);
|
2019-03-28 11:27:44 +00:00
|
|
|
})();
|