2019-03-28 18:52:22 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const fs = require('fs-extra');
|
|
|
|
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 getZoteroNoteEditor(signatures) {
|
|
|
|
const t1 = Date.now();
|
|
|
|
|
2021-02-11 19:48:27 +00:00
|
|
|
const { stdout } = await exec('git rev-parse HEAD', { cwd: './note-editor' });
|
2021-02-11 18:58:25 +00:00
|
|
|
const hash = stdout.trim();
|
2019-03-28 18:52:22 +00:00
|
|
|
|
2021-02-11 19:48:27 +00:00
|
|
|
if (!('note-editor' in signatures) || signatures['note-editor'].hash !== hash) {
|
|
|
|
const targetDir = 'build/resource/note-editor/';
|
2021-02-11 18:58:25 +00:00
|
|
|
try {
|
|
|
|
const filename = hash + '.zip';
|
2021-02-11 19:48:27 +00:00
|
|
|
const tmpDir = 'tmp/builds/note-editor/';
|
2021-02-11 18:58:25 +00:00
|
|
|
const url = buildsURL + 'client-note-editor/' + filename;
|
|
|
|
await exec(
|
|
|
|
`mkdir -p ${tmpDir}`
|
|
|
|
+ `&& cd ${tmpDir}`
|
|
|
|
+ `&& (test -f ${filename} || curl -f ${url} -o ${filename})`
|
|
|
|
+ `&& rm -rf ../../../${targetDir}`
|
|
|
|
+ `&& mkdir -p ../../../${targetDir}`
|
|
|
|
+ `&& unzip -o ${filename} -d ../../../${targetDir}`
|
|
|
|
);
|
|
|
|
}
|
|
|
|
catch (e) {
|
2022-03-16 21:50:45 +00:00
|
|
|
await exec('npm ci', { cwd: 'note-editor' });
|
|
|
|
await exec('npm run build', { cwd: 'note-editor' });
|
2021-02-11 19:48:27 +00:00
|
|
|
await fs.copy('note-editor/build/zotero', targetDir);
|
2021-02-11 18:58:25 +00:00
|
|
|
}
|
2021-02-11 19:48:27 +00:00
|
|
|
signatures['note-editor'] = { 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 {
|
2021-02-11 19:48:27 +00:00
|
|
|
action: 'note-editor',
|
2019-03-28 18:52:22 +00:00
|
|
|
count: 1,
|
|
|
|
totalCount: 1,
|
|
|
|
processingTime: t2 - t1
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = getZoteroNoteEditor;
|
|
|
|
|
|
|
|
if (require.main === module) {
|
|
|
|
(async () => {
|
|
|
|
try {
|
|
|
|
const signatures = await getSignatures();
|
|
|
|
onSuccess(await getZoteroNoteEditor(signatures));
|
|
|
|
await writeSignatures(signatures);
|
|
|
|
}
|
|
|
|
catch (err) {
|
|
|
|
process.exitCode = 1;
|
|
|
|
global.isError = true;
|
|
|
|
onError(err);
|
|
|
|
}
|
|
|
|
})();
|
|
|
|
}
|