Use constants for paths

This commit is contained in:
Idrees Hassan
2025-11-03 21:21:29 -05:00
parent 3d31a9c9a6
commit 3fe52e5492
7 changed files with 40 additions and 26 deletions

View File

@@ -2,7 +2,7 @@
"manifest_version": 3, "manifest_version": 3,
"name": "Pocket Bird", "name": "Pocket Bird",
"description": "It's a pet bird in your browser, what more could you want?", "description": "It's a pet bird in your browser, what more could you want?",
"version": "2025.11.3.10", "version": "2025.11.3.21",
"homepage_url": "https://idreesinc.com", "homepage_url": "https://idreesinc.com",
"icons": { "icons": {
"48": "images/icons/transparent/48x48x1.png", "48": "images/icons/transparent/48x48x1.png",

View File

@@ -4,20 +4,34 @@ import { rollup } from 'rollup';
import { readFileSync, writeFileSync, mkdirSync, unlinkSync, cpSync, createWriteStream } from 'fs'; import { readFileSync, writeFileSync, mkdirSync, unlinkSync, cpSync, createWriteStream } from 'fs';
import archiver from 'archiver'; import archiver from 'archiver';
// Path constants
const SRC_DIR = "./src";
const SPRITES_DIR = "./sprites";
const IMAGES_DIR = "./images";
const FONTS_DIR = "./fonts";
const DIST_DIR = "./dist";
const BROWSER_MANIFEST = "./browser-manifest.json";
const STYLESHEET_PATH = SRC_DIR + "/stylesheet.css";
const APPLICATION_ENTRY = SRC_DIR + "/application.js";
const BUNDLED_OUTPUT = DIST_DIR + "/birb.bundled.js";
const BIRB_OUTPUT = DIST_DIR + "/birb.js";
const USERSCRIPT_DIR = DIST_DIR + "/userscript";
const EXTENSION_DIR = DIST_DIR + "/extension";
const EXTENSION_ZIP = DIST_DIR + "/extension.zip";
const spriteSheets = [ const spriteSheets = [
{ {
key: "__SPRITE_SHEET__", key: "__SPRITE_SHEET__",
path: "./sprites/birb.png" path: SPRITES_DIR + "/birb.png"
}, },
{ {
key: "__FEATHER_SPRITE_SHEET__", key: "__FEATHER_SPRITE_SHEET__",
path: "./sprites/feather.png" path: SPRITES_DIR + "/feather.png"
} }
]; ];
const STYLESHEET_PATH = "./src/stylesheet.css";
const STYLESHEET_KEY = "___STYLESHEET___"; const STYLESHEET_KEY = "___STYLESHEET___";
const BROWSER_MANIFEST = "./browser-manifest.json";
const now = new Date(); const now = new Date();
const versionDate = `${now.getFullYear()}.${now.getMonth() + 1}.${now.getDate()}`; const versionDate = `${now.getFullYear()}.${now.getMonth() + 1}.${now.getDate()}`;
@@ -70,20 +84,20 @@ const userScriptHeader =
// Bundle with rollup // Bundle with rollup
const bundle = await rollup({ const bundle = await rollup({
input: 'src/application.js', input: APPLICATION_ENTRY,
}); });
await bundle.write({ await bundle.write({
file: 'dist/birb.bundled.js', file: BUNDLED_OUTPUT,
format: 'iife', format: 'iife',
}); });
await bundle.close(); await bundle.close();
let birbJs = readFileSync('dist/birb.bundled.js', 'utf8'); let birbJs = readFileSync(BUNDLED_OUTPUT, 'utf8');
// Delete bundled file // Delete bundled file
unlinkSync('./dist/birb.bundled.js'); unlinkSync(BUNDLED_OUTPUT);
// Replace version placeholder // Replace version placeholder
birbJs = birbJs.replaceAll('__VERSION__', version); birbJs = birbJs.replaceAll('__VERSION__', version);
@@ -99,33 +113,33 @@ const stylesheetContent = readFileSync(STYLESHEET_PATH, 'utf8');
birbJs = birbJs.replace(STYLESHEET_KEY, stylesheetContent); birbJs = birbJs.replace(STYLESHEET_KEY, stylesheetContent);
// Build standard javascript file // Build standard javascript file
writeFileSync('./dist/birb.js', birbJs); writeFileSync(BIRB_OUTPUT, birbJs);
// Build user script // Build user script
mkdirSync('./dist/userscript', { recursive: true }); mkdirSync(USERSCRIPT_DIR, { recursive: true });
const userScript = userScriptHeader + birbJs; const userScript = userScriptHeader + birbJs;
writeFileSync('./dist/userscript/birb.user.js', userScript); writeFileSync(USERSCRIPT_DIR + '/birb.user.js', userScript);
// Build browser extension // Build browser extension
mkdirSync('./dist/extension', { recursive: true }); mkdirSync(EXTENSION_DIR, { recursive: true });
// Copy birb.js // Copy birb.js
writeFileSync('./dist/extension/birb.js', birbJs); writeFileSync(EXTENSION_DIR + '/birb.js', birbJs);
// Copy manifest.json // Copy manifest.json
const manifestContent = readFileSync(BROWSER_MANIFEST, 'utf8'); const manifestContent = readFileSync(BROWSER_MANIFEST, 'utf8');
writeFileSync('./dist/extension/manifest.json', manifestContent); writeFileSync(EXTENSION_DIR + '/manifest.json', manifestContent);
// Copy icons folder // Copy icons folder
mkdirSync('./dist/extension/images/icons', { recursive: true }); mkdirSync(EXTENSION_DIR + '/images/icons', { recursive: true });
cpSync('./images/icons/transparent', './dist/extension/images/icons/transparent', { recursive: true }); cpSync(IMAGES_DIR + '/icons/transparent', EXTENSION_DIR + '/images/icons/transparent', { recursive: true });
// Copy fonts folder // Copy fonts folder
mkdirSync('./dist/extension/fonts', { recursive: true }); mkdirSync(EXTENSION_DIR + '/fonts', { recursive: true });
cpSync('./fonts', './dist/extension/fonts', { recursive: true }); cpSync(FONTS_DIR, EXTENSION_DIR + '/fonts', { recursive: true });
// Compress extension folder into zip // Compress extension folder into zip
const output = createWriteStream('./dist/extension.zip'); const output = createWriteStream(EXTENSION_ZIP);
const archive = archiver('zip'); const archive = archiver('zip');
output.on('close', () => { output.on('close', () => {
@@ -137,7 +151,7 @@ archive.on('error', (err) => {
}); });
archive.pipe(output); archive.pipe(output);
archive.directory('./dist/extension/', false); archive.directory(EXTENSION_DIR + '/', false);
archive.finalize(); archive.finalize();
console.log(`Build complete: ${version}`); console.log(`Build complete: ${version}`);

2
dist/birb.js vendored
View File

@@ -1867,7 +1867,7 @@
insertModal(`${birdBirb()} Mode`, message); insertModal(`${birdBirb()} Mode`, message);
}), }),
new Separator(), new Separator(),
new MenuItem("2025.11.3.10", () => { alert("Thank you for using Pocket Bird! You are on version: 2025.11.3.10"); }, false), new MenuItem("2025.11.3.21", () => { alert("Thank you for using Pocket Bird! You are on version: 2025.11.3.21"); }, false),
]; ];
const styleElement = document.createElement("style"); const styleElement = document.createElement("style");

BIN
dist/extension.zip vendored

Binary file not shown.

View File

@@ -1867,7 +1867,7 @@
insertModal(`${birdBirb()} Mode`, message); insertModal(`${birdBirb()} Mode`, message);
}), }),
new Separator(), new Separator(),
new MenuItem("2025.11.3.10", () => { alert("Thank you for using Pocket Bird! You are on version: 2025.11.3.10"); }, false), new MenuItem("2025.11.3.21", () => { alert("Thank you for using Pocket Bird! You are on version: 2025.11.3.21"); }, false),
]; ];
const styleElement = document.createElement("style"); const styleElement = document.createElement("style");

View File

@@ -2,7 +2,7 @@
"manifest_version": 3, "manifest_version": 3,
"name": "Pocket Bird", "name": "Pocket Bird",
"description": "It's a pet bird in your browser, what more could you want?", "description": "It's a pet bird in your browser, what more could you want?",
"version": "2025.11.3.10", "version": "2025.11.3.21",
"homepage_url": "https://idreesinc.com", "homepage_url": "https://idreesinc.com",
"icons": { "icons": {
"48": "images/icons/transparent/48x48x1.png", "48": "images/icons/transparent/48x48x1.png",

View File

@@ -1,7 +1,7 @@
// ==UserScript== // ==UserScript==
// @name Pocket Bird // @name Pocket Bird
// @namespace https://idreesinc.com // @namespace https://idreesinc.com
// @version 2025.11.3.10 // @version 2025.11.3.21
// @description It's a bird that hops around your web browser, the future is here // @description It's a bird that hops around your web browser, the future is here
// @author Idrees // @author Idrees
// @downloadURL https://github.com/IdreesInc/Pocket-Bird/raw/refs/heads/main/dist/userscript/birb.user.js // @downloadURL https://github.com/IdreesInc/Pocket-Bird/raw/refs/heads/main/dist/userscript/birb.user.js
@@ -1881,7 +1881,7 @@
insertModal(`${birdBirb()} Mode`, message); insertModal(`${birdBirb()} Mode`, message);
}), }),
new Separator(), new Separator(),
new MenuItem("2025.11.3.10", () => { alert("Thank you for using Pocket Bird! You are on version: 2025.11.3.10"); }, false), new MenuItem("2025.11.3.21", () => { alert("Thank you for using Pocket Bird! You are on version: 2025.11.3.21"); }, false),
]; ];
const styleElement = document.createElement("style"); const styleElement = document.createElement("style");