diff --git a/package-lock.json b/package-lock.json index 67a0ed73..3f1c65ff 100644 --- a/package-lock.json +++ b/package-lock.json @@ -40,9 +40,9 @@ } }, "adblock-rs": { - "version": "0.1.28", - "resolved": "https://registry.npmjs.org/adblock-rs/-/adblock-rs-0.1.28.tgz", - "integrity": "sha512-5Jrn+Dddj7SzwECyyxByMiNQVEgne5IG+jAep/esgZnv+Z6JwnuEeHYeh/TziOMKQNJKe2tNh6wHY6T000e9Gg==", + "version": "0.1.32", + "resolved": "https://registry.npmjs.org/adblock-rs/-/adblock-rs-0.1.32.tgz", + "integrity": "sha512-Ad7gz3Z/2VnqkH+oh7XEZYnTNgSvVrb1gWlF/3uOZhhauO35mFT2jp4XaWF+4wIh4xzynUDrsFiYylf74XPwhw==", "requires": { "neon-cli": "^0.2.0" } @@ -1263,9 +1263,9 @@ "integrity": "sha512-jpSvDPV4Cq/bgtpndIWbI5hmYxhQGHPC4d4cqBPb4DLniCfhJokdXhwhaDuLBGLQdvvRum/UiX6ECVIPvDXqdg==" }, "handlebars": { - "version": "4.1.2", - "resolved": "https://registry.npmjs.org/handlebars/-/handlebars-4.1.2.tgz", - "integrity": "sha512-nvfrjqvt9xQ8Z/w0ijewdD/vvWDTOweBUm96NTr66Wfvo1mJenBLwcYmPs3TIBP5ruzYGD7Hx/DaM9RmhroGPw==", + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/handlebars/-/handlebars-4.2.0.tgz", + "integrity": "sha512-Kb4xn5Qh1cxAKvQnzNWZ512DhABzyFNmsaJf3OAkWNa4NkaqWcNI8Tao8Tasi0/F4JD9oyG0YxuFyvyR57d+Gw==", "requires": { "neo-async": "^2.6.0", "optimist": "^0.6.1", diff --git a/package.json b/package.json index 30db9e91..c6417e5e 100755 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "description": "Packages component and theme extensions used in the Brave browser", "dependencies": { "ad-block": "brave/ad-block", - "adblock-rs": "^0.1.28", + "adblock-rs": "^0.1.32", "ajv": "^6.10.0", "autoplay-whitelist": "github:brave/autoplay-whitelist", "aws-sdk": "^2.449.0", diff --git a/scripts/generateAdBlockRustDataFiles.js b/scripts/generateAdBlockRustDataFiles.js index 2d3f2b95..1820b415 100644 --- a/scripts/generateAdBlockRustDataFiles.js +++ b/scripts/generateAdBlockRustDataFiles.js @@ -6,6 +6,7 @@ const { Engine, lists } = require('adblock-rs') const path = require('path') const fs = require('fs') const request = require('request') +const uBlockResources = 'https://raw.githubusercontent.com/uBlockOrigin/uAssets/master/filters/resources.txt' /** * Returns a promise that which resolves with the list data @@ -14,7 +15,7 @@ const request = require('request') * @param filter The filter function to apply to the body * @return a promise that resolves with the content of the list or rejects with an error message. */ -const getListBufferFromURL = (listURL, filter) => { +const getBufferFromURL = (listURL, filter) => { return new Promise((resolve, reject) => { request.get(listURL, function (error, response, body) { if (error) { @@ -47,6 +48,25 @@ const getListFilterFunction = (uuid) => { return undefined } +/** + * Obtains the output path to store a file given the specied name and subdir + */ +const getOutPath = (outputFilename, outSubdir) => { + let outPath = path.join('build') + if (!fs.existsSync(outPath)) { + fs.mkdirSync(outPath) + } + outPath = path.join(outPath, 'ad-block-updater') + if (!fs.existsSync(outPath)) { + fs.mkdirSync(outPath) + } + outPath = path.join(outPath, outSubdir) + if (!fs.existsSync(outPath)) { + fs.mkdirSync(outPath) + } + return path.join(outPath, outputFilename) +} + /** * Parses the passed in filter rule data and serializes a data file to disk. * @@ -62,23 +82,22 @@ const generateDataFileFromString = (filterRuleData, outputDATFilename, outSubdir } const client = new Engine(rules.split('\n')) const arrayBuffer = client.serialize() - let outPath = path.join('build') - if (!fs.existsSync(outPath)) { - fs.mkdirSync(outPath) - } - outPath = path.join(outPath, 'ad-block-updater') - if (!fs.existsSync(outPath)) { - fs.mkdirSync(outPath) - } - outPath = path.join(outPath, outSubdir) - if (!fs.existsSync(outPath)) { - fs.mkdirSync(outPath) - } - fs.writeFileSync(path.join(outPath, outputDATFilename), Buffer.from(arrayBuffer)) + const outPath = getOutPath(outputDATFilename, outSubdir) + fs.writeFileSync(outPath, Buffer.from(arrayBuffer)) +} + +/** + * Generates a reosources.txt file for the specified buffer and subdir + * + * @param resourcesData The data to store in the resources.txt file + */ +const generateResourcesFileFromString = (resourcesData) => { + const outPath = getOutPath('resources.txt', 'default') + fs.writeFileSync(outPath, resourcesData, 'utf8') } /** - * Convenience function that uses getListBufferFromURL and generateDataFileFromString + * Convenience function that uses getBufferFromURL and generateDataFileFromString * to construct a DAT file from a URL while applying a specific filter. * * @param listURL the URL of the list to fetch. @@ -128,12 +147,14 @@ const generateDataFilesForList = (lists, filename) => { lists.forEach((l) => { console.log(`${l.url}...`) const filterFn = getListFilterFunction(l.uuid) - promises.push(getListBufferFromURL(l.url, filterFn)) + promises.push(getBufferFromURL(l.url, filterFn)) }) let p = Promise.all(promises) p = p.then((listBuffers) => { generateDataFileFromString(listBuffers, filename, 'default') }) + p = p.then(getBufferFromURL.bind(null, uBlockResources)) + .then(generateResourcesFileFromString) return p }