forked from keepassxreboot/keepassxc-browser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.js
executable file
·72 lines (57 loc) · 2.19 KB
/
build.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/env node
'use strict';
const fs = require('@npmcli/fs');
const util = require('util');
const exec = util.promisify(require('child_process').exec);
const DEST = 'keepassxc-browser';
const DEFAULT = 'manifest_default.json';
const BROWSERS = {
'Firefox': 'manifest_firefox.json',
'Chromium': 'manifest_chromium.json',
};
const getVersion = async () => {
const manifestFile = await fs.readFile(DEFAULT, { encoding: 'utf8' });
const data = JSON.parse(manifestFile);
return data['version'];
};
const setVersion = async (manifest, version) => {
const manifestFile = await fs.readFile(manifest, { encoding: 'utf8' });
const data = JSON.parse(manifestFile);
data['version'] = version;
if (Object.hasOwn(data, 'version_name')) {
data['version_name'] = version;
}
fs.writeFile(manifest, JSON.stringify(data, null, 4));
};
const getDestinationFilename = async (manifest, version) => {
const browser = manifest.substring(manifest.indexOf('_') + 1, manifest.indexOf('.'));
return `keepassxc-browser_${version}_${browser}.zip`;
};
const updateTranslations = async () => {
console.log('Pulling translations from Transifex, please wait...');
const { stdout } = await exec('tx pull -af');
console.log(stdout);
};
const createZipFile = async (fileName, path) => {
await exec(`cd ${path} && tar -a -cf ../${fileName} * && cd ..`);
};
(async() => {
const params = process.argv.slice(2);
if (!params.includes('--skip-translations')) {
await updateTranslations();
}
await fs.copyFile(`${DEST}/manifest.json`, `./${DEFAULT}`);
const version = await getVersion();
for (const browser in BROWSERS) {
console.log(`KeePassXC-Browser: Creating extension package for ${browser}`);
const fileName = await getDestinationFilename(BROWSERS[browser], version);
setVersion(`./dist/${BROWSERS[browser]}`, version);
await fs.copyFile(`./dist/${BROWSERS[browser]}`, `${DEST}/manifest.json`);
if (await fs.exists(fileName)) {
await fs.rm(fileName);
}
await createZipFile(fileName, DEST);
console.log('Done');
}
fs.renameSync(DEFAULT, `${DEST}/manifest.json`);
})();