Skip to content

Commit

Permalink
Fix couple of build issues
Browse files Browse the repository at this point in the history
  • Loading branch information
tnajdek committed May 8, 2024
1 parent e1fd4de commit 46db703
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 159 deletions.
10 changes: 4 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,23 @@
"postpack": "rimraf build",
"prebuild": "npm run clean -s && mkdir -p build/static/",
"clean": "rimraf build",
"clean:all": "rimraf build data src/static/fonts src/static/note-editor src/static/pdf-reader src/static/pdf-worker",
"build": "NODE_ENV=production run-s \"build:prepare\" \"build:all\" \"build:postprocess\"",
"clean:all": "rimraf build data tmp src/static/fonts src/static/note-editor src/static/pdf-reader src/static/pdf-worker",
"build": "npm run build:prepare && NODE_ENV=production npm run build:all && npm run build:postprocess",
"build:tests": "NODE_ENV=testing run-s \"build:prepare\" \"build:all\" \"build:postprocess\" \"build:layout-only-css\"",
"build:all": "run-p 'build:js -s' 'build:scss -s' 'build:html -s' 'build:static -s'",
"build:js": "mkdir -p build/static && rollup -c",
"build:scss": "for f in src/scss/*.scss; do sass --no-source-map $f build/static/`basename $f .scss`.css; done;",
"build:html": "mkdir -p build/ && rsync -vazL src/html/* build/",
"build:styles-json": "node scripts/build-styles-json.cjs",
"build:pdf-reader": "node scripts/fetch-pdf-reader.cjs",
"build:pdf-worker": "node scripts/fetch-pdf-worker.cjs",
"build:note-editor": "node scripts/fetch-note-editor.cjs",
"build:fetch-or-build-modules": "node scripts/fetch-or-build-modules.cjs",
"build:fonts": "node scripts/fetch-fonts.cjs",
"build:locale": "node scripts/fetch-locale.cjs",
"build:date-formats": "node scripts/fetch-date-formats.cjs",
"build:version": "node scripts/store-version.cjs",
"build:static": "mkdir -p build/static && rsync -vazL src/static/* build/static/",
"build:postprocess": "postcss build/static/zotero-web-library.css --use autoprefixer --no-map -r",
"build:check-icons": "node scripts/check-icons.js",
"build:prepare": "run-p \"build:version\" \"build:locale\" \"build:date-formats\" \"build:pdf-reader\" \"build:pdf-worker\" \"build:note-editor\" \"build:fonts\" \"build:styles-json\" \"build:check-icons\"",
"build:prepare": "run-p \"build:version\" \"build:locale\" \"build:date-formats\" \"build:fetch-or-build-modules\" \"build:fonts\" \"build:styles-json\" \"build:check-icons\"",
"build:layout-only-css": "node scripts/build-layout-only-css.js",
"devel": "run-p 'devel:js -s' 'devel:scss -s' 'devel:html -s' 'devel:static -s'",
"devel:js": "rollup -c -w",
Expand Down
51 changes: 0 additions & 51 deletions scripts/fetch-note-editor.cjs

This file was deleted.

91 changes: 91 additions & 0 deletions scripts/fetch-or-build-modules.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
const fs = require('fs-extra');
const path = require('path');
const util = require('util');
const exec = util.promisify(require('child_process').exec);

const buildsURL = 'https://zotero-download.s3.amazonaws.com/ci/';
const modulesFilePath = path.join(__dirname, '..', 'data', 'modules.json');

const modulesConfig = [
{
name: 'pdf-reader',
key: 'pdfReader',
URLpath: 'client-pdf-reader',
buildPath: ['build', 'web'],
exec: (url, filename, tmpDir, targetDir) => `cd ${tmpDir}`
+ ` && (test -f ${filename} || curl -f ${url} -o ${filename})`
+ ` && mkdir -p ${targetDir}`
+ ` && unzip ${filename} web/* -d ${targetDir}`
+ ` && mv ${targetDir}/web/* ${targetDir}/`
+ ` && rm -r ${targetDir}/web`
},
{
name: 'pdf-worker',
key: 'pdfWorker',
URLpath: 'client-pdf-worker',
buildPath: ['build'],
exec: (url, filename, tmpDir, targetDir) => `cd ${tmpDir}`
+ ` && (test -f ${filename} || curl -f ${url} -o ${filename})`
+ ` && mkdir -p ${targetDir}`
+ ` && unzip -o ${filename} -d ${targetDir}`
},
{
name: 'note-editor',
key: 'noteEditor',
URLpath: 'client-note-editor',
buildPath: ['build', 'web'],
exec: (url, filename, tmpDir, targetDir) => `cd ${tmpDir}`
+ ` && (test -f ${filename} || curl -f ${url} -o ${filename})`
+ ` && unzip ${filename} zotero/* -d ${targetDir}`
+ ` && mv ${path.join(targetDir, 'zotero', '*')} ${targetDir}`
}
];

(async () => {
let modulesData = {};
try {
modulesData = await fs.readJson(modulesFilePath);
} catch (_) {
// modules data file is missing or invalid json, ignore.
}

const promises = modulesConfig.map(async moduleConfig => {
const srcPath = path.join(__dirname, '..', 'modules', moduleConfig.name);
const storedHash = modulesData[moduleConfig.key];
const { stdout } = await exec('git rev-parse HEAD', { cwd: srcPath });
const actualHash = stdout.trim();
const targetDir = path.join(__dirname, '..', 'src', 'static', moduleConfig.name);
const targetDirExists = await fs.pathExists(targetDir);
const tmpDir = path.join(__dirname, '..', 'tmp', 'builds', moduleConfig.name);
if (!targetDirExists || !storedHash || storedHash !== actualHash) {
try {
const filename = actualHash + '.zip';
const url = buildsURL + moduleConfig.URLpath + '/' + filename;

await fs.remove(targetDir);
await fs.ensureDir(targetDir);
await fs.ensureDir(tmpDir);

await exec(moduleConfig.exec(url, filename, tmpDir, targetDir));
console.log(`Obtained ${moduleConfig.name} from ${url}`);
} catch (e) {
console.log(`Unable to fetch ${moduleConfig.name}, will build instead...`);
await exec('npm ci', { cwd: srcPath });
await exec('npm run build', { cwd: srcPath });
await fs.copy(path.join(srcPath, ...moduleConfig.buildPath), targetDir);
console.log(`${moduleConfig.name} build complete`);
} finally {
await fs.remove(tmpDir);
}
modulesData[moduleConfig.key] = actualHash;
} else {
console.log(`Skipping ${moduleConfig.name} fetch/build, already up to date`);
}
});

await Promise.all(promises);
await fs.ensureDir(path.dirname(modulesFilePath));
await fs.writeJson(modulesFilePath, modulesData);
})();


52 changes: 0 additions & 52 deletions scripts/fetch-pdf-reader.cjs

This file was deleted.

50 changes: 0 additions & 50 deletions scripts/fetch-pdf-worker.cjs

This file was deleted.

0 comments on commit 46db703

Please sign in to comment.