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

Added npm scripts to ease building & testing on android platforms #1623

Merged
merged 7 commits into from
Dec 5, 2024
Merged
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
29 changes: 20 additions & 9 deletions dev/bin/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -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});
}
}
}
Expand Down Expand Up @@ -244,6 +250,9 @@ export async function main() {
type: 'string',
default: '0.0.0.0',
},
target: {
type: 'string',
},
};

const argv = process.argv.slice(2);
Expand All @@ -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 {
Expand Down
5 changes: 5 additions & 0 deletions dev/data/manifest-variants.json
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,11 @@
"js/background/offscreen-main.js"
]
},
{
"name": "firefox-android",
"inherit": "firefox",
"fileName": "yomitan-firefox-android"
},
{
"name": "safari",
"modifications": [
Expand Down
16 changes: 16 additions & 0 deletions docs/development/npm-scripts.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,22 @@ Scripts can be executed by running `npm run <name>`.
- `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.

Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down