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

AddScriptlet build command #173

Open
wants to merge 2 commits into
base: master
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
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 1 addition & 3 deletions generateMetadataJsonFromScriptResources.js
Original file line number Diff line number Diff line change
@@ -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");
Expand All @@ -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!")
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Loading