2019-03-28 18:52:22 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const fs = require('fs-extra');
|
2022-06-17 13:47:53 +00:00
|
|
|
const path = require('path');
|
2019-03-28 18:52:22 +00:00
|
|
|
const util = require('util');
|
|
|
|
const exec = util.promisify(require('child_process').exec);
|
|
|
|
const { getSignatures, writeSignatures, onSuccess, onError } = require('./utils');
|
2021-02-11 18:58:25 +00:00
|
|
|
const { buildsURL } = require('./config');
|
2019-03-28 18:52:22 +00:00
|
|
|
|
|
|
|
async function getPDFReader(signatures) {
|
|
|
|
const t1 = Date.now();
|
2022-06-17 13:47:53 +00:00
|
|
|
|
2023-08-08 05:32:26 +00:00
|
|
|
const modulePath = path.join(__dirname, '..', 'reader');
|
2021-02-11 18:58:25 +00:00
|
|
|
|
2022-06-17 13:47:53 +00:00
|
|
|
const { stdout } = await exec('git rev-parse HEAD', { cwd: modulePath });
|
2021-02-11 18:58:25 +00:00
|
|
|
const hash = stdout.trim();
|
|
|
|
|
2023-08-08 05:32:26 +00:00
|
|
|
if (!('reader' in signatures) || signatures['reader'].hash !== hash) {
|
|
|
|
const targetDir = path.join(__dirname, '..', 'build', 'resource', 'reader');
|
2021-02-11 18:58:25 +00:00
|
|
|
try {
|
|
|
|
const filename = hash + '.zip';
|
2023-08-08 05:32:26 +00:00
|
|
|
const tmpDir = path.join(__dirname, '..', 'tmp', 'builds', 'reader');
|
|
|
|
const url = buildsURL + 'client-reader/' + filename;
|
2022-06-17 13:47:53 +00:00
|
|
|
|
|
|
|
await fs.remove(targetDir);
|
|
|
|
await fs.ensureDir(targetDir);
|
|
|
|
await fs.ensureDir(tmpDir);
|
|
|
|
|
2021-02-11 18:58:25 +00:00
|
|
|
await exec(
|
2022-06-17 13:47:53 +00:00
|
|
|
`cd ${tmpDir}`
|
|
|
|
+ ` && (test -f ${filename} || curl -f ${url} -o ${filename})`
|
|
|
|
+ ` && unzip ${filename} zotero/* -d ${targetDir}`
|
|
|
|
+ ` && mv ${path.join(targetDir, 'zotero', '*')} ${targetDir}`
|
2021-02-11 18:58:25 +00:00
|
|
|
);
|
2022-06-17 13:47:53 +00:00
|
|
|
|
|
|
|
await fs.remove(path.join(targetDir, 'zotero'));
|
2021-02-11 18:58:25 +00:00
|
|
|
}
|
|
|
|
catch (e) {
|
2022-06-17 13:47:53 +00:00
|
|
|
await exec('npm ci', { cwd: modulePath });
|
|
|
|
await exec('npm run build', { cwd: modulePath });
|
|
|
|
await fs.copy(path.join(modulePath, 'build', 'zotero'), targetDir);
|
2021-02-11 18:58:25 +00:00
|
|
|
}
|
2023-08-08 05:32:26 +00:00
|
|
|
signatures['reader'] = { hash };
|
2019-03-28 18:52:22 +00:00
|
|
|
}
|
2021-02-11 18:58:25 +00:00
|
|
|
|
2019-03-28 18:52:22 +00:00
|
|
|
const t2 = Date.now();
|
|
|
|
|
|
|
|
return {
|
2023-08-08 05:32:26 +00:00
|
|
|
action: 'reader',
|
2019-03-28 18:52:22 +00:00
|
|
|
count: 1,
|
|
|
|
totalCount: 1,
|
|
|
|
processingTime: t2 - t1
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = getPDFReader;
|
|
|
|
|
|
|
|
if (require.main === module) {
|
|
|
|
(async () => {
|
|
|
|
try {
|
|
|
|
const signatures = await getSignatures();
|
|
|
|
onSuccess(await getPDFReader(signatures));
|
|
|
|
await writeSignatures(signatures);
|
|
|
|
}
|
|
|
|
catch (err) {
|
|
|
|
process.exitCode = 1;
|
|
|
|
global.isError = true;
|
|
|
|
onError(err);
|
|
|
|
}
|
|
|
|
})();
|
|
|
|
}
|