Update pdf-reader and note-editor, use specific prebuilds, tweak code

This commit is contained in:
Martynas Bagdonas 2022-06-17 16:47:53 +03:00 committed by Dan Stillman
parent 3ff650f046
commit 4de31ebb85
5 changed files with 59 additions and 37 deletions

View file

@ -1,6 +1,7 @@
'use strict';
const fs = require('fs-extra');
const path = require('path');
const util = require('util');
const exec = util.promisify(require('child_process').exec);
const { getSignatures, writeSignatures, onSuccess, onError } = require('./utils');
@ -9,28 +10,35 @@ const { buildsURL } = require('./config');
async function getZoteroNoteEditor(signatures) {
const t1 = Date.now();
const { stdout } = await exec('git rev-parse HEAD', { cwd: './note-editor' });
const modulePath = path.join(__dirname, '..', 'note-editor');
const { stdout } = await exec('git rev-parse HEAD', { cwd: modulePath });
const hash = stdout.trim();
if (!('note-editor' in signatures) || signatures['note-editor'].hash !== hash) {
const targetDir = 'build/resource/note-editor/';
const targetDir = path.join(__dirname, '..', 'build', 'resource', 'note-editor');
try {
const filename = hash + '.zip';
const tmpDir = 'tmp/builds/note-editor/';
const tmpDir = path.join(__dirname, '..', 'tmp', 'builds', 'note-editor');
const url = buildsURL + 'client-note-editor/' + filename;
await fs.remove(targetDir);
await fs.ensureDir(targetDir);
await fs.ensureDir(tmpDir);
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}`
`cd ${tmpDir}`
+ ` && (test -f ${filename} || curl -f ${url} -o ${filename})`
+ ` && unzip ${filename} zotero/* -d ${targetDir}`
+ ` && mv ${path.join(targetDir, 'zotero', '*')} ${targetDir}`
);
await fs.remove(path.join(targetDir, 'zotero'));
}
catch (e) {
await exec('npm ci', { cwd: 'note-editor' });
await exec('npm run build', { cwd: 'note-editor' });
await fs.copy('note-editor/build/zotero', targetDir);
await exec('npm ci', { cwd: modulePath });
await exec('npm run build', { cwd: modulePath });
await fs.copy(path.join(modulePath, 'build', 'zotero'), targetDir);
}
signatures['note-editor'] = { hash };
}