diff --git a/index.js b/index.js index 45ffb192fd3..25171fe113d 100644 --- a/index.js +++ b/index.js @@ -3,7 +3,7 @@ require('dotenv').config(); const cluster = require('node:cluster'); const { availableParallelism } = require('node:os'); const path = require('node:path'); -const createDir = require('./scripts/functions/createDir.js'); +const createDir = require('./scripts/utils/createDir.js'); if (!process.env.NODE_ENV || !process.env.DOMAIN || !process.env.PORT) { throw new Error('Environment variables are null or undefined'); diff --git a/package-lock.json b/package-lock.json index d9f61e4ab4c..827c47be6c6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "sefinek-blocklist-collection", - "version": "0.14.0", + "version": "1.0.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "sefinek-blocklist-collection", - "version": "0.14.0", + "version": "1.0.0", "license": "CC BY-NC 4.0", "dependencies": { "axios": "^1.6.7", diff --git a/package.json b/package.json index 3a7bc9096e9..bee1a4bb458 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "sefinek-blocklist-collection", - "version": "0.14.0", + "version": "1.0.0", "description": "The best lists for your DNS server or ad blocker (Pi-hole, AdGuard, etc.). Your first and last reliable source, with no false positives and its own whitelist.", "main": "index.js", "scripts": { diff --git a/scripts/create-everything-list.js b/scripts/create-everything-list.js index 1ae3de2538c..60b08a47e0c 100644 --- a/scripts/create-everything-list.js +++ b/scripts/create-everything-list.js @@ -7,7 +7,7 @@ const fs = require('fs').promises; const path = require('path'); -const date = require('./functions/date.js'); +const date = require('./utils/date.js'); const defaultFolder = path.join(__dirname, '..', 'blocklist', 'template'); const generatedFolder = path.join(__dirname, '..', 'blocklist', 'generated'); diff --git a/scripts/functions/process.js b/scripts/functions/process.js index 3d9b4f8e20b..c6dc8e0f198 100644 --- a/scripts/functions/process.js +++ b/scripts/functions/process.js @@ -1,8 +1,6 @@ -const path = require('node:path'); - -module.exports = async (convert, files, relativePath, folderPath) => { +module.exports = async (convert, allFiles, path, relativePath, folderPath) => { try { - const subdirectories = files.filter(file => file.isDirectory()); + const subdirectories = allFiles.filter(file => file.isDirectory()); await Promise.all(subdirectories.map(async subdirectory => { const nextRelativePath = path.join(relativePath, subdirectory.name); await convert(path.join(folderPath, subdirectory.name), nextRelativePath); diff --git a/scripts/functions/txtFilter.js b/scripts/functions/txtFilter.js new file mode 100644 index 00000000000..50f4c1d9d58 --- /dev/null +++ b/scripts/functions/txtFilter.js @@ -0,0 +1,18 @@ +module.exports = async (format, path, fs, relativePath, folderPath) => { + const generatedPath = path.join(__dirname, `../../blocklist/generated/${format}`, relativePath); + try { + await fs.access(generatedPath); + } catch (err) { + await fs.mkdir(generatedPath, { recursive: true }); + } + + const allFiles = await fs.readdir(folderPath, { withFileTypes: true }); + const txtFiles = allFiles.filter(file => file.isFile() && file.name.endsWith('.txt')); + + return { + format, + allFiles, + txtFiles, + generatedPath, + }; +}; \ No newline at end of file diff --git a/scripts/generate/0.0.0.0.js b/scripts/generate/0.0.0.0.js index f2c1cf6a913..c69a47c79ff 100644 --- a/scripts/generate/0.0.0.0.js +++ b/scripts/generate/0.0.0.0.js @@ -1,21 +1,12 @@ const { promises: fs } = require('node:fs'); const path = require('node:path'); -const date = require('../functions/date.js'); -const sha256 = require('../functions/sha512.js'); +const date = require('../utils/date.js'); +const sha256 = require('../utils/sha512.js'); +const txtFilter = require('../functions/txtFilter.js'); const process = require('../functions/process.js'); -const format = '0.0.0.0'; - const convert = async (folderPath = path.join(__dirname, '../../blocklist/template'), relativePath = '') => { - const generatedPath = path.join(__dirname, `../../blocklist/generated/${format}`, relativePath); - try { - await fs.access(generatedPath); - } catch (err) { - await fs.mkdir(generatedPath, { recursive: true }); - } - - const files = await fs.readdir(folderPath, { withFileTypes: true }); - const txtFiles = files.filter(file => file.isFile() && file.name.endsWith('.txt')); + const { format, allFiles, txtFiles, generatedPath } = await txtFilter('0.0.0.0', path, fs, relativePath, folderPath); await Promise.all(txtFiles.map(async file => { const thisFileName = path.join(folderPath, file.name); @@ -39,7 +30,7 @@ const convert = async (folderPath = path.join(__dirname, '../../blocklist/templa console.log(`✔️ ${cacheHash || file.name} ++ ${fullNewFile}`); })); - await process(convert, files, relativePath, folderPath); + await process(convert, allFiles, path, relativePath, folderPath); }; const run = async () => { diff --git a/scripts/generate/127.0.0.1.js b/scripts/generate/127.0.0.1.js index a882c8d4e59..58f7abf77b1 100644 --- a/scripts/generate/127.0.0.1.js +++ b/scripts/generate/127.0.0.1.js @@ -1,21 +1,12 @@ const { promises: fs } = require('node:fs'); const path = require('node:path'); -const date = require('../functions/date.js'); -const sha256 = require('../functions/sha512.js'); +const date = require('../utils/date.js'); +const sha256 = require('../utils/sha512.js'); +const txtFilter = require('../functions/txtFilter.js'); const process = require('../functions/process.js'); -const format = '127.0.0.1'; - const convert = async (folderPath = path.join(__dirname, '../../blocklist/template'), relativePath = '') => { - const generatedPath = path.join(__dirname, `../../blocklist/generated/${format}`, relativePath); - try { - await fs.access(generatedPath); - } catch (err) { - await fs.mkdir(generatedPath, { recursive: true }); - } - - const files = await fs.readdir(folderPath, { withFileTypes: true }); - const txtFiles = files.filter(file => file.isFile() && file.name.endsWith('.txt')); + const { format, allFiles, txtFiles, generatedPath } = await txtFilter('127.0.0.1', path, fs, relativePath, folderPath); await Promise.all(txtFiles.map(async file => { const thisFileName = path.join(folderPath, file.name); @@ -39,7 +30,7 @@ const convert = async (folderPath = path.join(__dirname, '../../blocklist/templa console.log(`✔️ ${cacheHash || file.name} ++ ${fullNewFile}`); })); - await process(convert, files, relativePath, folderPath); + await process(convert, allFiles, path, relativePath, folderPath); }; const run = async () => { diff --git a/scripts/generate/adguard.js b/scripts/generate/adguard.js index 8ab29c5d4a5..5764e825c4a 100644 --- a/scripts/generate/adguard.js +++ b/scripts/generate/adguard.js @@ -1,21 +1,12 @@ const { promises: fs } = require('node:fs'); const path = require('node:path'); -const date = require('../functions/date.js'); -const sha256 = require('../functions/sha512.js'); +const date = require('../utils/date.js'); +const sha256 = require('../utils/sha512.js'); +const txtFilter = require('../functions/txtFilter.js'); const process = require('../functions/process.js'); -const format = 'adguard'; - const convert = async (folderPath = path.join(__dirname, '../../blocklist/template'), relativePath = '') => { - const generatedPath = path.join(__dirname, `../../blocklist/generated/${format}`, relativePath); - try { - await fs.access(generatedPath); - } catch (err) { - await fs.mkdir(generatedPath, { recursive: true }); - } - - const files = await fs.readdir(folderPath, { withFileTypes: true }); - const txtFiles = files.filter(file => file.isFile() && file.name.endsWith('.txt')); + const { format, allFiles, txtFiles, generatedPath } = await txtFilter('adguard', path, fs, relativePath, folderPath); await Promise.all(txtFiles.map(async file => { const thisFileName = path.join(folderPath, file.name); @@ -45,7 +36,7 @@ const convert = async (folderPath = path.join(__dirname, '../../blocklist/templa console.log(`✔️ ${cacheHash || file.name} ++ ${fullNewFile}`); })); - await process(convert, files, relativePath, folderPath); + await process(convert, allFiles, path, relativePath, folderPath); }; const run = async () => { diff --git a/scripts/generate/dnsmasq.js b/scripts/generate/dnsmasq.js index b56d8f665ce..9e3b153f505 100644 --- a/scripts/generate/dnsmasq.js +++ b/scripts/generate/dnsmasq.js @@ -1,21 +1,12 @@ const { promises: fs } = require('node:fs'); const path = require('node:path'); -const date = require('../functions/date.js'); -const sha256 = require('../functions/sha512.js'); +const date = require('../utils/date.js'); +const sha256 = require('../utils/sha512.js'); +const txtFilter = require('../functions/txtFilter.js'); const process = require('../functions/process.js'); -const format = 'dnsmasq'; - const convert = async (folderPath = path.join(__dirname, '../../blocklist/template'), relativePath = '') => { - const generatedPath = path.join(__dirname, `../../blocklist/generated/${format}`, relativePath); - try { - await fs.access(generatedPath); - } catch (err) { - await fs.mkdir(generatedPath, { recursive: true }); - } - - const files = await fs.readdir(folderPath, { withFileTypes: true }); - const txtFiles = files.filter(file => file.isFile() && file.name.endsWith('.txt')); + const { format, allFiles, txtFiles, generatedPath } = await txtFilter('dnsmasq', path, fs, relativePath, folderPath); await Promise.all(txtFiles.map(async file => { const thisFileName = path.join(folderPath, file.name); @@ -46,7 +37,7 @@ const convert = async (folderPath = path.join(__dirname, '../../blocklist/templa console.log(`✔️ ${cacheHash || file.name} ++ ${fullNewFile}`); })); - await process(convert, files, relativePath, folderPath); + await process(convert, allFiles, path, relativePath, folderPath); }; const run = async () => { diff --git a/scripts/generate/noip.js b/scripts/generate/noip.js index b07efeb79b1..93d62d479f3 100644 --- a/scripts/generate/noip.js +++ b/scripts/generate/noip.js @@ -1,21 +1,12 @@ const { promises: fs } = require('node:fs'); const path = require('node:path'); -const date = require('../functions/date.js'); -const sha256 = require('../functions/sha512.js'); +const date = require('../utils/date.js'); +const sha256 = require('../utils/sha512.js'); +const txtFilter = require('../functions/txtFilter.js'); const process = require('../functions/process.js'); -const format = 'noip'; - const convert = async (folderPath = path.join(__dirname, '../../blocklist/template'), relativePath = '') => { - const generatedPath = path.join(__dirname, `../../blocklist/generated/${format}`, relativePath); - try { - await fs.access(generatedPath); - } catch (err) { - await fs.mkdir(generatedPath, { recursive: true }); - } - - const files = await fs.readdir(folderPath, { withFileTypes: true }); - const txtFiles = files.filter(file => file.isFile() && file.name.endsWith('.txt')); + const { format, allFiles, txtFiles, generatedPath } = await txtFilter('noip', path, fs, relativePath, folderPath); await Promise.all(txtFiles.map(async file => { const thisFileName = path.join(folderPath, file.name); @@ -46,7 +37,7 @@ const convert = async (folderPath = path.join(__dirname, '../../blocklist/templa console.log(`✔️ ${cacheHash || file.name} ++ ${fullNewFile}`); })); - await process(convert, files, relativePath, folderPath); + await process(convert, allFiles, path, fs, relativePath, folderPath); }; const run = async () => { diff --git a/scripts/functions/createDir.js b/scripts/utils/createDir.js similarity index 100% rename from scripts/functions/createDir.js rename to scripts/utils/createDir.js diff --git a/scripts/functions/date.js b/scripts/utils/date.js similarity index 100% rename from scripts/functions/date.js rename to scripts/utils/date.js diff --git a/scripts/functions/sha512.js b/scripts/utils/sha512.js similarity index 100% rename from scripts/functions/sha512.js rename to scripts/utils/sha512.js