From 374cc41e1a6aa9f5d0be588e8df5c5953f6d8a3e Mon Sep 17 00:00:00 2001 From: Matttttt <18152455+martholomew@users.noreply.github.com> Date: Thu, 5 Dec 2024 18:42:26 +0000 Subject: [PATCH] Added npm scripts to ease building & testing on android platforms (#1623) * Added npm scripts to easily test builds on firefox for android and kiwibrowser * removed new dependency (was causing issues) * fixed md * fixed md part 2 * revert package-lock.json * re-added newline --------- Co-authored-by: martholomew --- dev/bin/build.js | 29 ++++++++++++++++++++--------- dev/data/manifest-variants.json | 5 +++++ docs/development/npm-scripts.md | 16 ++++++++++++++++ package.json | 2 ++ 4 files changed, 43 insertions(+), 9 deletions(-) diff --git a/dev/bin/build.js b/dev/bin/build.js index c03391600d..0ec7cc020d 100644 --- a/dev/bin/build.js +++ b/dev/bin/build.js @@ -191,14 +191,20 @@ async function build(buildDir, extDir, manifestUtil, variantNames, manifestPath, fs.writeFileSync(manifestPath, ManifestUtil.createManifestString(modifiedManifest).replace('$YOMITAN_VERSION', yomitanVersion)); } - if (!dryRun || dryRunBuildZip) { - await createZip(extDir, excludeFiles, fullFileName, sevenZipExes, onUpdate, dryRun); - } + if (fileName.endsWith('.zip')) { + if (!dryRun || dryRunBuildZip) { + await createZip(extDir, excludeFiles, fullFileName, sevenZipExes, onUpdate, dryRun); + } - if (!dryRun && Array.isArray(fileCopies)) { - for (const fileName2 of fileCopies) { - const fileName2Safe = path.basename(fileName2); - fs.copyFileSync(fullFileName, path.join(buildDir, fileName2Safe)); + if (!dryRun && Array.isArray(fileCopies)) { + for (const fileName2 of fileCopies) { + const fileName2Safe = path.basename(fileName2); + fs.copyFileSync(fullFileName, path.join(buildDir, fileName2Safe)); + } + } + } else { + if (!dryRun) { + fs.cpSync(extDir, fullFileName, {recursive: true}); } } } @@ -244,6 +250,9 @@ export async function main() { type: 'string', default: '0.0.0.0', }, + target: { + type: 'string', + }, }; const argv = process.argv.slice(2); @@ -263,9 +272,11 @@ export async function main() { try { await buildLibs(); const variantNames = /** @type {string[]} */ (( - argv.length === 0 || args.all ? + args.target ? + [args.target] : + (argv.length === 0 || args.all ? manifestUtil.getVariants().filter(({buildable}) => buildable !== false).map(({name}) => name) : - targets + targets) )); await build(buildDir, extDir, manifestUtil, variantNames, manifestPath, dryRun, dryRunBuildZip, yomitanVersion); } finally { diff --git a/dev/data/manifest-variants.json b/dev/data/manifest-variants.json index 00543e21db..f1b491405a 100644 --- a/dev/data/manifest-variants.json +++ b/dev/data/manifest-variants.json @@ -319,6 +319,11 @@ "js/background/offscreen-main.js" ] }, + { + "name": "firefox-android", + "inherit": "firefox", + "fileName": "yomitan-firefox-android" + }, { "name": "safari", "modifications": [ diff --git a/docs/development/npm-scripts.md b/docs/development/npm-scripts.md index 802e9f5d1a..e4aaa15c45 100644 --- a/docs/development/npm-scripts.md +++ b/docs/development/npm-scripts.md @@ -12,6 +12,22 @@ Scripts can be executed by running `npm run `. - `build:libs` Rebuilds all of the third-party dependencies that the extension uses. +- `build:serve:firefox-android` + + > `adb` and `web-ext` are required to be installed on your computer for this command to work! + + Builds for Firefox and then uses `web-ext` to serve the extension through `adb` to Firefox for Android. Prepend the environment variables WEB_EXT_TARGET and WEB_EXT_ADB_DEVICE for the command to succeed (example: `WEB_EXT_TARGET="firefox-android" WEB_EXT_ADB_DEVICE="emulator-5554" npm run build:serve:firefox-android`). WEB_EXT_TARGET will be "firefox-android" for vanilla Firefox, and you can find the value for WEB_EXT_ADB_DEVICE by running the command `adb devices`. + + [Get started debugging Firefox for Android (recommended)](https://extensionworkshop.com/documentation/develop/getting-started-with-web-ext/#test-and-degug-an-extention) + + [`web-ext run` documentation](https://extensionworkshop.com/documentation/develop/web-ext-command-reference/#web-ext-run) + +- `build:serve:kiwi-browser` + + > `adb` is required to be installed on your computer for this command to work! + + Builds for Chromium and then uses `adb` to `push` the built zip file over to `/sdcard/yomitan`. You can then open up Kiwi Browser on the target phone and install the extension through that zip file. + - `test` Runs all of the tests. diff --git a/package.json b/package.json index 045b96b772..23b8669aa6 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,8 @@ "bench": "vitest bench", "build": "node ./dev/bin/build.js", "build:libs": "node ./dev/bin/build-libs.js", + "build:serve:firefox-android": "node ./dev/bin/build.js --target firefox-android && web-ext run -s ./builds/yomitan-firefox-android", + "build:serve:kiwi-browser": "node ./dev/bin/build.js --target chrome-dev && adb shell mkdir -p /sdcard/yomitan && adb push ./builds/yomitan-chrome-dev.zip /sdcard/yomitan/yomitan-kiwi-browser.zip", "test": "npm run test:js && npm run test:ts && npm run test:css && npm run test:html && npm run test:unit && npm run test:unit:options && npm run test:json && npm run test:md && npm run test:build", "test:fast": "npm run test:js && npm run test:ts && npm run test:unit && npm run test:json:format", "test:static-analysis": "npm run test:js && npm run test:ts && npm run test:css && npm run test:html && npm run test:md",