From 82e579afa602c70b6923e2a51dea243b3bbcd023 Mon Sep 17 00:00:00 2001 From: Shivan Kaul Sahib Date: Wed, 1 May 2024 11:14:50 -0700 Subject: [PATCH 1/2] AddScriptlet build command --- README.md | 17 +++++++++++++++++ generateMetadataJsonFromScriptResources.js | 4 +--- package.json | 3 ++- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 375274a4..5d14a853 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,22 @@ Custom resources should be added to the `resources` directory, and a correspondi ## Using +Make sure to run `npm install`. + +### Adding a new scriptlet + +If you just want to add a new scriptlet, simply add it under `resources/`, and then run: + +``` +npm run addScriptlet +``` + +Git add your new scriptlet, and also commit the changes generated in `dist/resources.json` (this is the file that actually contains the resource and gets loaded into the browser) and `metadata.json` (which describes the resources). The `resourcePath` for your resource is what you will use to insert the scriptlet via an adblock rule. + +See https://github.com/brave/adblock-resources/pull/131 and https://github.com/brave/adblock-lists/pull/1310 for an example of adding a resource and using it via an adblock rule. + +### Advanced use + This package can be imported as a library, exposing the function `readResources` which will produce the correctly formatted list of resources for use with [adblock-rust](https://github.com/brave/adblock-rust). Alternatively, `npm run build` will write all resources to `dist/resources.json` for future use. @@ -14,6 +30,7 @@ To generate `metadata.json` automatically from files in `resources/`, run `npm r Use `npm run test` after modifying the resources or metadata file to ensure the format can be accepted by `adblock-rust`. + ## Metadata format `metadata.json` is a list of elements of the following format: diff --git a/generateMetadataJsonFromScriptResources.js b/generateMetadataJsonFromScriptResources.js index 7dc9e4f9..89e32ee2 100644 --- a/generateMetadataJsonFromScriptResources.js +++ b/generateMetadataJsonFromScriptResources.js @@ -1,7 +1,5 @@ /** * Helper script that takes resources in /resources and generates the metadata.json - * Note that this does not add the alias - please edit those manually. - * For instance - brave-fix script needs the "bf" alias */ const fs = require("fs"); @@ -24,4 +22,4 @@ const metadataList = resources.map((file) => { console.debug(`Writing ${metadataJsonFile}... `); // Pretty print out fs.writeFileSync(metadataJsonFile, JSON.stringify(metadataList, null, 4)); -console.debug(`Done! IMPORTANT: Please edit ${metadataJsonFile} to have the right aliases for the resources`); +console.log("Done!") diff --git a/package.json b/package.json index 27320367..7f4d53d4 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,8 @@ "scripts": { "build": "node build", "test": "node verify", - "generateMetadata": "node generateMetadataJsonFromScriptResources.js" + "generateMetadata": "node generateMetadataJsonFromScriptResources.js", + "addScriptlet": "npm run generateMetadata && npm run build && npm run test" }, "repository": { "type": "git", From 9521fe48b1d22c7f27a8d61afe91d63b167a0cbe Mon Sep 17 00:00:00 2001 From: Shivan Kaul Sahib Date: Wed, 1 May 2024 11:16:31 -0700 Subject: [PATCH 2/2] nit: remove extra line --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 5d14a853..450f1076 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,6 @@ To generate `metadata.json` automatically from files in `resources/`, run `npm r Use `npm run test` after modifying the resources or metadata file to ensure the format can be accepted by `adblock-rust`. - ## Metadata format `metadata.json` is a list of elements of the following format: