Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use NodeJS build script #12

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
build
node_modules
25 changes: 19 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,24 @@

A sample plugin for Zotero 7

* [src-1.0](src-1.0): Overlay plugin for Zotero 6
* [src-1.1](src-1.1): Overlay plugin for Zotero 6 and bootstrapped plugin for Zotero 7
* [src-1.2](src-1.2): Bootstrapped plugin for Zotero 6 and 7
* [src-2.0](src-2.0): Bootstrapped plugin for Zotero 7
To test, run

To test, run `./make-zips` and install the XPIs in the Zotero Add-ons window, or see [Setting Up a Plugin Development Environment](https://www.zotero.org/support/dev/client_coding/plugin_development#setting_up_a_plugin_development_environment) to run from source.
```bash
npm install
npm run build
```

The update manifests are set up to demonstrate upgrading across all versions, but normally a plugin would point to a single update manifest that was updated as new versions were available. The update manifests for versions 1.1 and 1.2 are set up to allow upgrading directly to 2.0 from Zotero 7.
and install the XPIs in the Zotero Plugins window, or see [Setting Up a Plugin Development Environment](https://www.zotero.org/support/dev/client_coding/plugin_development#setting_up_a_plugin_development_environment) to run from source.

The update manifests are set up to demonstrate upgrading across all versions, but normally a plugin would point to a single update manifest that was updated as new versions were available. The update manifests for versions 1.1 and 1.2 are set up to allow upgrading directly to 2.0 from Zotero 7.

<details>
<summary>Archived Old Versions</summary>

* [src-1.0](old/src-1.0): Overlay plugin for Zotero 6
* [src-1.1](old/src-1.1): Overlay plugin for Zotero 6 and bootstrapped plugin for Zotero 7
* [src-1.2](old/src-1.2): Bootstrapped plugin for Zotero 6 and 7

To test, run `./old/make-zips`

</details>
25 changes: 15 additions & 10 deletions make-zips → old/make-zips
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,28 @@ set -euo pipefail
rm -rf build
mkdir build

cd old

cd src-1.0
zip -r ../build/make-it-red-1.0.xpi *
zip -r ../../build/make-it-red-1.0.xpi *
cd ../src-1.1
zip -r ../build/make-it-red-1.1.xpi *
zip -r ../../build/make-it-red-1.1.xpi *
cd ../src-1.2
zip -r ../build/make-it-red-1.2.xpi *
cd ../src-2.0
zip -r ../build/make-it-red-2.0.xpi *
cd ../build
zip -r ../../build/make-it-red-1.2.xpi *


cd ../../
node ./scripts/build.js

cd build

jq ".addons[\"[email protected]\"].updates[0].update_hash = \"sha256:`shasum -a 256 make-it-red-1.1.xpi | cut -d' ' -f1`\"" ../updates-1.0.json.tmpl > updates-1.0.json
jq ".addons[\"[email protected]\"].updates[0].update_hash = \"sha256:`shasum -a 256 make-it-red-1.1.xpi | cut -d' ' -f1`\"" ../old/updates-1.0.json.tmpl > updates-1.0.json
cp updates-1.0.json update.rdf

jq ".addons[\"[email protected]\"].updates[0].update_hash = \"sha256:`shasum -a 256 make-it-red-1.2.xpi | cut -d' ' -f1`\"" ../updates-1.1.json.tmpl | \
jq ".addons[\"[email protected]\"].updates[0].update_hash = \"sha256:`shasum -a 256 make-it-red-1.2.xpi | cut -d' ' -f1`\"" ../old/updates-1.1.json.tmpl | \
jq ".addons[\"[email protected]\"].updates[1].update_hash = \"sha256:`shasum -a 256 make-it-red-2.0.xpi | cut -d' ' -f1`\"" > updates-1.1.json

jq ".addons[\"[email protected]\"].updates[0].update_hash = \"sha256:`shasum -a 256 make-it-red-1.2.xpi | cut -d' ' -f1`\"" ../updates-1.2.json.tmpl | \
jq ".addons[\"[email protected]\"].updates[0].update_hash = \"sha256:`shasum -a 256 make-it-red-1.2.xpi | cut -d' ' -f1`\"" ../old/updates-1.2.json.tmpl | \
jq ".addons[\"[email protected]\"].updates[1].update_hash = \"sha256:`shasum -a 256 make-it-red-2.0.xpi | cut -d' ' -f1`\"" > updates-1.2.json

jq ".addons[\"[email protected]\"].updates[0].update_hash = \"sha256:`shasum -a 256 make-it-red-2.0.xpi | cut -d' ' -f1`\"" ../updates-2.0.json.tmpl > updates-2.0.json
# jq ".addons[\"[email protected]\"].updates[0].update_hash = \"sha256:`shasum -a 256 make-it-red-2.0.xpi | cut -d' ' -f1`\"" ../old/updates-2.0.json.tmpl > updates-2.0.json
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
139 changes: 139 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "make-it-red",
"version": "2.0.0",
"description": "A sample plugin for Zotero 7",
"main": "index.js",
"scripts": {
"build": "node scripts/build.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"devDependencies": {
"crypto": "^1.0.1",
"zip-dir": "^2.0.0"
}
}
57 changes: 57 additions & 0 deletions scripts/build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
const fs = require('fs').promises;
const path = require('path');
const crypto = require('crypto');
const zipDir = require('zip-dir');

async function main() {
const sourceDir = 'src';
const buildDir = 'build';
const xpiFile = 'make-it-red-2.0.xpi';
const updateJSONFile = 'updates-2.0.json';
await build(sourceDir, buildDir, xpiFile);
const hash = await generateHash(path.join(buildDir, xpiFile), "sha256");
await writeUpdateJSON(path.join(buildDir, updateJSONFile), hash);
}

async function build(sourceDir, buildDir, filename) {
try {
await fs.access(buildDir);
} catch (e) {
await fs.mkdir(buildDir);
}

await zipDir(sourceDir, { saveTo: path.join(buildDir, filename) });
}

async function generateHash(filePath, algorithm) {
const data = await fs.readFile(filePath);
const hash = crypto.createHash(algorithm).update(data).digest("hex");
return `${algorithm}:${hash}`;
}

async function writeUpdateJSON(filePath, hash) {
const updateJSON = {
"addons": {
"[email protected]": {
"updates": [
{
"version": "2.0",
"update_link": "https://zotero-download.s3.amazonaws.com/tmp/make-it-red/make-it-red-2.0.xpi",
"update_hash": hash,
"applications": {
"zotero": {
"strict_min_version": "6.999"
}
}
}
]
}
}
}
await fs.writeFile(
filePath,
JSON.stringify(updateJSON, null, 2)
);
}

main();
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
18 changes: 0 additions & 18 deletions updates-2.0.json.tmpl

This file was deleted.