Skip to content

Commit

Permalink
Export in TXT format (#198)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrmod authored Jan 5, 2024
1 parent 440480e commit e7fdc0d
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 2 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,13 @@ jobs:
asset_path: ./dist/trackerdb.engine
asset_name: trackerdb.engine
asset_content_type: application/octet-stream

- name: Upload TXT
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ github.token }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./dist/trackerdb.txt
asset_name: trackerdb.txt
asset_content_type: text/plain
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
"test": "node test/index.js",
"lint": "eslint --ignore-path .gitignore --ext .js,.ts .",
"update-docs": "node scripts/update-docs.js",
"export": "npm run export-json && npm run export-engine && npm run export-sql",
"export": "npm run export-json && npm run export-engine && npm run export-sql && npm run export-txt",
"export-sql": "node scripts/export-sql/index.js",
"export-engine": "node scripts/export-engine/index.js",
"export-json": "node scripts/export-json/index.js"
"export-json": "node scripts/export-json/index.js",
"export-txt": "node scripts/export-txt/index.js"
},
"main": "dist/cjs/index.js",
"module": "dist/mjs/index.js",
Expand Down
31 changes: 31 additions & 0 deletions scripts/export-txt/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { rmSync, existsSync, writeFileSync } from 'node:fs';
import path from 'node:path';
import { prepareDistFolder, BASE_PATH, getSpecs } from '../helpers.js';

(async () => {
prepareDistFolder();

const outputPath = path.join(BASE_PATH, 'dist', 'trackerdb.txt');

if (existsSync(outputPath)) {
rmSync(outputPath);
}

const FILTERS = [];

for (const [id, spec] of getSpecs('patterns')) {
const category = spec.field('category').requiredStringValue();
const filters = spec.field('filters').optionalStringValue();
if (filters) {
for (const line of filters.split(/[\r\n]+/g)) {
const trimmed = line.trim();
if (trimmed && !trimmed.startsWith('!')) {
FILTERS.push(`! trackerdb_id:${id} trackerdb_category:${category}`);
FILTERS.push(trimmed);
}
}
}
}

writeFileSync(outputPath, FILTERS.join('\n'));
})();

0 comments on commit e7fdc0d

Please sign in to comment.