Skip to content

Commit

Permalink
Merge pull request #100 from arthurbolsoni/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
arthurbolsoni authored Jul 22, 2024
2 parents 0d931a7 + 46f0512 commit e2e962d
Show file tree
Hide file tree
Showing 18 changed files with 469 additions and 329 deletions.
Binary file added bun.lockb
Binary file not shown.
19 changes: 19 additions & 0 deletions cli/build.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { buildChrome } from './chrome_builder.js';
import { buildFirefox } from './firefox_builder.js';

async function main() {
const task = process.argv[2];
const dev = task === 'dev';

try {
await Promise.all([
buildChrome(dev),
buildFirefox(dev),
]);
} catch (error) {
console.error(error);
process.exit(1);
}
}

main();
58 changes: 30 additions & 28 deletions cli/chrome_builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,40 @@ const fs = require("fs");
var fs_Extra = require("fs-extra");
const archiver = require("archiver");

platform = "chromium";
fileType = ".zip";
const dirname = "./dist";
const package_name = "purple-adblock";
const name = package_name + "-" + package_name + "-" + platform;
export function buildChrome(dev) {
const platform = "chromium";
const fileType = ".zip";
const dirname = "./dist";
const package_name = "purple-adblock";
const name = package_name + "-" + package_name + "-" + platform;

console.log("===================================================================");
console.log("Building " + platform + " extension version: " + package_name);
console.log("===================================================================");
console.log("===================================================================");
console.log("Building " + platform + " extension version: " + package_name);
console.log("===================================================================");

//manifest build
const manifest = JSON.parse(fs.readFileSync("./platform/" + platform + "/manifest.json"));
manifest.version = require("../package.json").version;
//manifest build
const manifest = JSON.parse(fs.readFileSync("./platform/" + platform + "/manifest.json"));
manifest.version = require("../package.json").version;

if (!fs.existsSync(dirname)) fs.mkdirSync(dirname);
if (!fs.existsSync(dirname)) fs.mkdirSync(dirname);

//if production zip the content,
if (process.env.NODE_ENV === "development") {
if (!fs.existsSync(dirname + "/" + name)) fs.mkdirSync(dirname + "/" + name);
fs_Extra.copySync("./platform/src/", dirname + "/" + name);
fs_Extra.copySync("./platform/" + platform, dirname + "/" + name);
fs.copyFileSync("./serviceWorker/dist/bundle.js", dirname + "/" + name + "/app/bundle.js");
fs.writeFileSync(dirname + "/" + name + "/" + "manifest.json", JSON.stringify(manifest));
//if production zip the content,
if (dev) {
if (!fs.existsSync(dirname + "/" + name)) fs.mkdirSync(dirname + "/" + name);
fs_Extra.copySync("./platform/src/", dirname + "/" + name);
fs_Extra.copySync("./platform/" + platform, dirname + "/" + name);
fs.copyFileSync("./serviceWorker/dist/bundle.js", dirname + "/" + name + "/app/bundle.js");
fs.writeFileSync(dirname + "/" + name + "/" + "manifest.json", JSON.stringify(manifest));

console.log("Build packed to " + dirname + "/" + name);
} else {
const zipFile = archiver("zip", { zlib: { level: 9 } });
zipFile.pipe(fs.createWriteStream(dirname + "/" + name + fileType));
zipFile.directory("./platform/src", false);
zipFile.file("./serviceWorker/dist/bundle.js", { name: "app/bundle.js" });
zipFile.append(Buffer.from(JSON.stringify(manifest)), { name: "manifest.json" });
zipFile.finalize();
console.log("Build packed to " + dirname + "/" + name);
} else {
const zipFile = archiver("zip", { zlib: { level: 9 } });
zipFile.pipe(fs.createWriteStream(dirname + "/" + name + fileType));
zipFile.directory("./platform/src", false);
zipFile.file("./serviceWorker/dist/bundle.js", { name: "app/bundle.js" });
zipFile.append(Buffer.from(JSON.stringify(manifest)), { name: "manifest.json" });
zipFile.finalize();

console.log("Build packed to " + dirname + "/" + name + fileType);
console.log("Build packed to " + dirname + "/" + name + fileType);
}
}
Empty file removed cli/chrome_publish.mjs
Empty file.
58 changes: 30 additions & 28 deletions cli/firefox_builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,40 @@ const fs = require("fs");
var fs_Extra = require("fs-extra");
const archiver = require("archiver");

platform = "firefox";
fileType = ".zip";
const dirname = "./dist";
const package_name = "purple-adblock";
const name = package_name + "-" + package_name + "-" + platform;
export function buildFirefox(dev) {
const platform = "firefox";
const fileType = ".zip";
const dirname = "./dist";
const package_name = "purple-adblock";
const name = package_name + "-" + package_name + "-" + platform;

console.log("===================================================================");
console.log("Building " + platform + " extension version: " + package_name);
console.log("===================================================================");
console.log("===================================================================");
console.log("Building " + platform + " extension version: " + package_name);
console.log("===================================================================");

//manifest build
const manifest = JSON.parse(fs.readFileSync("./platform/" + platform + "/manifest.json"));
manifest.version = require("../package.json").version;
//manifest build
const manifest = JSON.parse(fs.readFileSync("./platform/" + platform + "/manifest.json"));
manifest.version = require("../package.json").version;

if (!fs.existsSync(dirname)) fs.mkdirSync(dirname);
if (!fs.existsSync(dirname)) fs.mkdirSync(dirname);

//if production zip the content,
if (process.env.NODE_ENV === "development") {
if (!fs.existsSync(dirname + "/" + name)) fs.mkdirSync(dirname + "/" + name);
fs_Extra.copySync("./platform/src/", dirname + "/" + name);
fs_Extra.copySync("./platform/" + platform, dirname + "/" + name);
fs.copyFileSync("./serviceWorker/dist/bundle.js", dirname + "/" + name + "/app/bundle.js");
fs.writeFileSync(dirname + "/" + name + "/" + "manifest.json", JSON.stringify(manifest));
//if production zip the content,
if(dev){
if (!fs.existsSync(dirname + "/" + name)) fs.mkdirSync(dirname + "/" + name);
fs_Extra.copySync("./platform/src/", dirname + "/" + name);
fs_Extra.copySync("./platform/" + platform, dirname + "/" + name);
fs.copyFileSync("./serviceWorker/dist/bundle.js", dirname + "/" + name + "/app/bundle.js");
fs.writeFileSync(dirname + "/" + name + "/" + "manifest.json", JSON.stringify(manifest));

console.log("Build packed to " + dirname + "/" + name);
} else {
const zipFile = archiver("zip", { zlib: { level: 9 } });
zipFile.pipe(fs.createWriteStream(dirname + "/" + name + fileType));
zipFile.directory("./platform/src", false);
zipFile.file("./serviceWorker/dist/bundle.js", { name: "app/bundle.js" });
zipFile.append(Buffer.from(JSON.stringify(manifest)), { name: "manifest.json" });
zipFile.finalize();
console.log("Build packed to " + dirname + "/" + name);
} else {
const zipFile = archiver("zip", { zlib: { level: 9 } });
zipFile.pipe(fs.createWriteStream(dirname + "/" + name + fileType));
zipFile.directory("./platform/src", false);
zipFile.file("./serviceWorker/dist/bundle.js", { name: "app/bundle.js" });
zipFile.append(Buffer.from(JSON.stringify(manifest)), { name: "manifest.json" });
zipFile.finalize();

console.log("Build packed to " + dirname + "/" + name + fileType);
console.log("Build packed to " + dirname + "/" + name + fileType);
}
}
36 changes: 0 additions & 36 deletions cli/firefox_publish.mjs

This file was deleted.

11 changes: 4 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
{
"name": "purple-adblock",
"version": "2.6.5",
"version": "2.6.6",
"description": "An adblocker for the Twitch.tv using server side signature and local m3u8 manipulation",
"scripts": {
"preinstall": "bun cli/preinstall.js",
"dev": "set NODE_ENV=development&& cd serviceWorker && node ./build.mjs && cd .. && concurrently \"bun run chrome:build && bun run firefox:build\" \"bun run userscript:build\"",
"build": "set NODE_ENV=production&& cd serviceWorker && node ./build.mjs && cd .. && concurrently \"bun run chrome:build && bun run firefox:build\" \"bun run userscript:build\"",
"chrome:build": "node cli/chrome_builder.js",
"firefox:build": "node cli/firefox_builder.js",
"userscript:build": "bun platform/tampermonkey/build.js",
"publish": "bun cli/firefox_publish.mjs --input-type=module && bun cli/chrome_publish.mjs --input-type=module",
"dev": "ts-node serviceWorker/build.ts && bun cli/build.ts dev",
"build": "ts-node serviceWorker/build.ts && bun cli/build.ts",
"lint": "eslint --ext .js,.ts && prettier --write **/*.{js,ts,css,html} --ignore-path .gitignore",
"test": "jest"
},
Expand Down Expand Up @@ -51,6 +47,7 @@
"dependencies": {
"bun": "^1.0.25",
"m3u8-parser": "^7.1.0",
"ts-node": "^10.9.2",
"vite": "^5.0.12"
}
}
4 changes: 2 additions & 2 deletions platform/tampermonkey/dist/purpleadblocker.user.js

Large diffs are not rendered by default.

16 changes: 10 additions & 6 deletions serviceWorker/build.mjs → serviceWorker/build.ts
Original file line number Diff line number Diff line change
@@ -1,45 +1,49 @@

import { defineConfig } from 'vite'
import { build } from 'vite'
import path from 'path'

const vitebuild = async () => {
export async function buildServiceWorker(dev: boolean) {
const worker = defineConfig({
root: __dirname,
define: {
global: 'self',
},
build: {
rollupOptions: {
input: {
app: './src/app.worker.ts',
app: path.resolve(__dirname, 'src/app.worker.ts'),
},
output: {
entryFileNames: 'app.worker.js',
},
},
minify: 'terser',
sourcemap: true
sourcemap: dev,
},
});

await build(worker);

const index = defineConfig({
root: __dirname,
define: {
global: 'self',
},
build: {
rollupOptions: {
input: {
index: './src/index.ts',
index: path.resolve(__dirname, 'src/index.ts'),
},
output: {
entryFileNames: 'bundle.js',
},
}
},
sourcemap: dev
},
});

await build(index);
}

vitebuild();
buildServiceWorker(false);
6 changes: 3 additions & 3 deletions serviceWorker/src/app.worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ import { Player } from "./modules/player/player";

declare global {
var request: any;
var logPrint: any;
var logger: any;
var routerList: { propertyKey: string; match: string; ignore: string | null }[];
var appController: any;
}

export default function app() {
global.logPrint = (x: any) => console.log("[Purple]: ", x);
global.logger = (x: any) => console.log("[Purple]: ", x);
global.appController = new AppController(new Player());

global.logPrint("Script running");
global.logger("Script running");
}

global.request = global.fetch;
Expand Down
Loading

0 comments on commit e2e962d

Please sign in to comment.