Skip to content

Commit

Permalink
feat: add getInjectableScript() caching helper, add publishing
Browse files Browse the repository at this point in the history
  • Loading branch information
barjin committed May 26, 2023
1 parent 2d178de commit 793f36a
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 18 deletions.
13 changes: 7 additions & 6 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Build
name: Build & Publish

on:
push:
Expand All @@ -9,12 +9,11 @@ on:
jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- name: Use Node.js
uses: actions/setup-node@v2
uses: actions/setup-node@v3
with:
node-version: '19'

Expand All @@ -27,5 +26,7 @@ jobs:
- name: Run compile script
run: node scripts/compile.js

- name: Push to NPM
run: npm publish --dry-run
- name: Publish to NPM
run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.APIFY_SERVICE_ACCOUNT_NPM_TOKEN }}
13 changes: 12 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
const fs = require('fs');

function getExtensionPath () {
return __dirname + '/compiled.js';
}

let script = null;
function getInjectableScript() {
if (script === null) {
script = fs.readFileSync(getExtensionPath(), 'utf-8');
}
return script;
}

module.exports = {
getExtensionPath
getExtensionPath,
getInjectableScript,
}
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 8 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
{
"name": "idcac-playwright",
"version": "1.0.0",
"description": "",
"version": "0.1.0",
"description": "I Don't Care About Cookies for Playwright/Puppeteer",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"repository": {
"type": "git",
"url": "https://github.com/apify/idcac"
},
"homepage": "https://github.com/apify/idcac",
"keywords": ["playwright", "puppeteer", "cookies"],
"author": "",
"license": "ISC",
"devDependencies": {
Expand Down
8 changes: 4 additions & 4 deletions scripts/compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,16 @@ class AST {

(async () => {
const sink = fs.createWriteStream(__dirname + '/../compiled.js', { flags: 'w' });


sink.write('try {\n');

const rules = fs.readFileSync(__dirname + '/../extension/data/rules.js', 'utf-8');
const rulesUpdated = new AST(rules, { sourceType: 'module' })
.makeVariableDeclarationsConst()
.makeVariableDeclarationsConst() // make all `var` declarations `const`, so they are automatically dropped as soon as the script ends.
.dropSymbol('block_urls')
.generate();

sink.write('try {\n');
sink.write(rulesUpdated);

sink.write('\n');

sink.write('const files = {\n');
Expand Down

0 comments on commit 793f36a

Please sign in to comment.