mirror of
https://github.com/NohamR/Pocket-Bird.git
synced 2026-05-24 19:59:36 +00:00
Update build to use build cache
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -2,3 +2,4 @@
|
|||||||
.DS_Store
|
.DS_Store
|
||||||
/dist/birb.bundled.js
|
/dist/birb.bundled.js
|
||||||
obsidian-test.sh
|
obsidian-test.sh
|
||||||
|
build-cache.json
|
||||||
|
|||||||
@@ -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.37",
|
"version": "__VERSION__",
|
||||||
"homepage_url": "https://idreesinc.com",
|
"homepage_url": "https://idreesinc.com",
|
||||||
"icons": {
|
"icons": {
|
||||||
"48": "images/icons/transparent/48x48x1.png",
|
"48": "images/icons/transparent/48x48x1.png",
|
||||||
|
|||||||
99
build.js
99
build.js
@@ -5,6 +5,7 @@ import { readFileSync, writeFileSync, mkdirSync, unlinkSync, cpSync, createWrite
|
|||||||
import archiver from 'archiver';
|
import archiver from 'archiver';
|
||||||
|
|
||||||
// Path constants
|
// Path constants
|
||||||
|
const BUILD_CACHE_PATH = "./build-cache.json";
|
||||||
const SRC_DIR = "./src";
|
const SRC_DIR = "./src";
|
||||||
const SPRITES_DIR = "./sprites";
|
const SPRITES_DIR = "./sprites";
|
||||||
const IMAGES_DIR = "./images";
|
const IMAGES_DIR = "./images";
|
||||||
@@ -22,6 +23,9 @@ const APPLICATION_ENTRY = SRC_DIR + "/application.js";
|
|||||||
const BUNDLED_OUTPUT = DIST_DIR + "/birb.bundled.js";
|
const BUNDLED_OUTPUT = DIST_DIR + "/birb.bundled.js";
|
||||||
const BIRB_OUTPUT = DIST_DIR + "/birb.js";
|
const BIRB_OUTPUT = DIST_DIR + "/birb.js";
|
||||||
|
|
||||||
|
const VERSION_KEY = "__VERSION__";
|
||||||
|
const STYLESHEET_KEY = "___STYLESHEET___";
|
||||||
|
|
||||||
const spriteSheets = [
|
const spriteSheets = [
|
||||||
{
|
{
|
||||||
key: "__SPRITE_SHEET__",
|
key: "__SPRITE_SHEET__",
|
||||||
@@ -33,65 +37,34 @@ const spriteSheets = [
|
|||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
const STYLESHEET_KEY = "___STYLESHEET___";
|
/** @type {Record<string, any>} */
|
||||||
|
let buildCache = {};
|
||||||
|
try {
|
||||||
|
const cacheContent = readFileSync(BUILD_CACHE_PATH, 'utf8');
|
||||||
|
buildCache = JSON.parse(cacheContent);
|
||||||
|
} catch (e) {
|
||||||
|
console.warn("No build cache found, starting fresh");
|
||||||
|
}
|
||||||
|
|
||||||
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()}`;
|
||||||
|
|
||||||
// Get current build number from the browser-manifest.json
|
// Get current build number from the build cache
|
||||||
let buildNumber = 0;
|
let buildNumber = 0;
|
||||||
try {
|
|
||||||
const manifest = JSON.parse(readFileSync(BROWSER_MANIFEST, 'utf8'));
|
if (buildCache.version && buildCache.version.startsWith(versionDate)) {
|
||||||
if (manifest.version) {
|
// Same day, increment build number
|
||||||
if (manifest.version.startsWith(versionDate)) {
|
const parts = buildCache.version.split('.');
|
||||||
// Same day, increment build number
|
if (parts.length === 4) {
|
||||||
const parts = manifest.version.split('.');
|
buildNumber = parseInt(parts[3], 10) + 1;
|
||||||
if (parts.length === 4) {
|
|
||||||
buildNumber = parseInt(parts[3], 10) + 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} catch (e) {
|
|
||||||
console.error("Could not read version from browser manifest");
|
|
||||||
throw e;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const version = `${versionDate}.${buildNumber}`;
|
const version = `${versionDate}.${buildNumber}`;
|
||||||
|
|
||||||
// Update browser manifest with new version
|
// Update build cache
|
||||||
try {
|
buildCache.version = version;
|
||||||
const manifest = JSON.parse(readFileSync(BROWSER_MANIFEST, 'utf8'));
|
writeFileSync(BUILD_CACHE_PATH, JSON.stringify(buildCache), 'utf8');
|
||||||
manifest.version = version;
|
|
||||||
writeFileSync(BROWSER_MANIFEST, JSON.stringify(manifest, null, 4), 'utf8');
|
|
||||||
} catch (e) {
|
|
||||||
console.error("Could not update version in browser manifest");
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
const obsidianManifest = JSON.parse(readFileSync(OBSIDIAN_MANIFEST, 'utf8'));
|
|
||||||
obsidianManifest.version = version;
|
|
||||||
writeFileSync(OBSIDIAN_MANIFEST, JSON.stringify(obsidianManifest, null, 4), 'utf8');
|
|
||||||
} catch (e) {
|
|
||||||
console.error("Could not update version in Obsidian manifest");
|
|
||||||
}
|
|
||||||
|
|
||||||
const userScriptHeader =
|
|
||||||
`// ==UserScript==
|
|
||||||
// @name Pocket Bird
|
|
||||||
// @namespace https://idreesinc.com
|
|
||||||
// @version ${version}
|
|
||||||
// @description It's a bird that hops around your web browser, the future is here
|
|
||||||
// @author Idrees
|
|
||||||
// @downloadURL https://github.com/IdreesInc/Pocket-Bird/raw/refs/heads/main/dist/userscript/birb.user.js
|
|
||||||
// @updateURL https://github.com/IdreesInc/Pocket-Bird/raw/refs/heads/main/dist/userscript/birb.user.js
|
|
||||||
// @match *://*/*
|
|
||||||
// @grant GM_setValue
|
|
||||||
// @grant GM_getValue
|
|
||||||
// @grant GM_deleteValue
|
|
||||||
// ==/UserScript==
|
|
||||||
|
|
||||||
`;
|
|
||||||
|
|
||||||
// Bundle with rollup
|
// Bundle with rollup
|
||||||
const bundle = await rollup({
|
const bundle = await rollup({
|
||||||
@@ -111,7 +84,7 @@ let birbJs = readFileSync(BUNDLED_OUTPUT, 'utf8');
|
|||||||
unlinkSync(BUNDLED_OUTPUT);
|
unlinkSync(BUNDLED_OUTPUT);
|
||||||
|
|
||||||
// Replace version placeholder
|
// Replace version placeholder
|
||||||
birbJs = birbJs.replaceAll('__VERSION__', version);
|
birbJs = birbJs.replaceAll(VERSION_KEY, version);
|
||||||
|
|
||||||
// Compile and insert sprite sheets
|
// Compile and insert sprite sheets
|
||||||
for (const spriteSheet of spriteSheets) {
|
for (const spriteSheet of spriteSheets) {
|
||||||
@@ -127,6 +100,22 @@ birbJs = birbJs.replace(STYLESHEET_KEY, stylesheetContent);
|
|||||||
writeFileSync(BIRB_OUTPUT, birbJs);
|
writeFileSync(BIRB_OUTPUT, birbJs);
|
||||||
|
|
||||||
// Build user script
|
// Build user script
|
||||||
|
const userScriptHeader =
|
||||||
|
`// ==UserScript==
|
||||||
|
// @name Pocket Bird
|
||||||
|
// @namespace https://idreesinc.com
|
||||||
|
// @version ${version}
|
||||||
|
// @description It's a bird that hops around your web browser, the future is here
|
||||||
|
// @author Idrees
|
||||||
|
// @downloadURL https://github.com/IdreesInc/Pocket-Bird/raw/refs/heads/main/dist/userscript/birb.user.js
|
||||||
|
// @updateURL https://github.com/IdreesInc/Pocket-Bird/raw/refs/heads/main/dist/userscript/birb.user.js
|
||||||
|
// @match *://*/*
|
||||||
|
// @grant GM_setValue
|
||||||
|
// @grant GM_getValue
|
||||||
|
// @grant GM_deleteValue
|
||||||
|
// ==/UserScript==
|
||||||
|
|
||||||
|
`;
|
||||||
mkdirSync(USERSCRIPT_DIR, { recursive: true });
|
mkdirSync(USERSCRIPT_DIR, { recursive: true });
|
||||||
const userScript = userScriptHeader + birbJs;
|
const userScript = userScriptHeader + birbJs;
|
||||||
writeFileSync(USERSCRIPT_DIR + '/birb.user.js', userScript);
|
writeFileSync(USERSCRIPT_DIR + '/birb.user.js', userScript);
|
||||||
@@ -138,8 +127,9 @@ mkdirSync(EXTENSION_DIR, { recursive: true });
|
|||||||
writeFileSync(EXTENSION_DIR + '/birb.js', birbJs);
|
writeFileSync(EXTENSION_DIR + '/birb.js', birbJs);
|
||||||
|
|
||||||
// Copy manifest.json
|
// Copy manifest.json
|
||||||
const manifestContent = readFileSync(BROWSER_MANIFEST, 'utf8');
|
let browserManifest = readFileSync(BROWSER_MANIFEST, 'utf8');
|
||||||
writeFileSync(EXTENSION_DIR + '/manifest.json', manifestContent);
|
browserManifest = browserManifest.replace(VERSION_KEY, version);
|
||||||
|
writeFileSync(EXTENSION_DIR + '/manifest.json', browserManifest);
|
||||||
|
|
||||||
// Copy icons folder
|
// Copy icons folder
|
||||||
mkdirSync(EXTENSION_DIR + '/images/icons', { recursive: true });
|
mkdirSync(EXTENSION_DIR + '/images/icons', { recursive: true });
|
||||||
@@ -172,7 +162,8 @@ mkdirSync(OBSIDIAN_DIR, { recursive: true });
|
|||||||
writeFileSync(OBSIDIAN_DIR + '/main.js', birbJs);
|
writeFileSync(OBSIDIAN_DIR + '/main.js', birbJs);
|
||||||
|
|
||||||
// Copy manifest.json
|
// Copy manifest.json
|
||||||
const obsidianManifestContent = readFileSync(OBSIDIAN_MANIFEST, 'utf8');
|
let obsidianManifest = readFileSync(OBSIDIAN_MANIFEST, 'utf8');
|
||||||
writeFileSync(OBSIDIAN_DIR + '/manifest.json', obsidianManifestContent);
|
obsidianManifest = obsidianManifest.replace(/"version":\s*".*"/, `"version": "${version}"`);
|
||||||
|
writeFileSync(OBSIDIAN_DIR + '/manifest.json', obsidianManifest);
|
||||||
|
|
||||||
console.log(`Build complete: ${version}`);
|
console.log(`Build complete: ${version}`);
|
||||||
2
dist/birb.js
vendored
2
dist/birb.js
vendored
@@ -1902,7 +1902,7 @@
|
|||||||
insertModal(`${birdBirb()} Mode`, message);
|
insertModal(`${birdBirb()} Mode`, message);
|
||||||
}),
|
}),
|
||||||
new Separator(),
|
new Separator(),
|
||||||
new MenuItem("2025.11.3.37", () => { alert("Thank you for using Pocket Bird! You are on version: 2025.11.3.37"); }, false),
|
new MenuItem("2025.11.3.40", () => { alert("Thank you for using Pocket Bird! You are on version: 2025.11.3.40"); }, false),
|
||||||
];
|
];
|
||||||
|
|
||||||
const styleElement = document.createElement("style");
|
const styleElement = document.createElement("style");
|
||||||
|
|||||||
BIN
dist/extension.zip
vendored
BIN
dist/extension.zip
vendored
Binary file not shown.
2
dist/extension/birb.js
vendored
2
dist/extension/birb.js
vendored
@@ -1902,7 +1902,7 @@
|
|||||||
insertModal(`${birdBirb()} Mode`, message);
|
insertModal(`${birdBirb()} Mode`, message);
|
||||||
}),
|
}),
|
||||||
new Separator(),
|
new Separator(),
|
||||||
new MenuItem("2025.11.3.37", () => { alert("Thank you for using Pocket Bird! You are on version: 2025.11.3.37"); }, false),
|
new MenuItem("2025.11.3.40", () => { alert("Thank you for using Pocket Bird! You are on version: 2025.11.3.40"); }, false),
|
||||||
];
|
];
|
||||||
|
|
||||||
const styleElement = document.createElement("style");
|
const styleElement = document.createElement("style");
|
||||||
|
|||||||
2
dist/extension/manifest.json
vendored
2
dist/extension/manifest.json
vendored
@@ -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.37",
|
"version": "2025.11.3.40",
|
||||||
"homepage_url": "https://idreesinc.com",
|
"homepage_url": "https://idreesinc.com",
|
||||||
"icons": {
|
"icons": {
|
||||||
"48": "images/icons/transparent/48x48x1.png",
|
"48": "images/icons/transparent/48x48x1.png",
|
||||||
|
|||||||
2
dist/obsidian/main.js
vendored
2
dist/obsidian/main.js
vendored
@@ -1902,7 +1902,7 @@
|
|||||||
insertModal(`${birdBirb()} Mode`, message);
|
insertModal(`${birdBirb()} Mode`, message);
|
||||||
}),
|
}),
|
||||||
new Separator(),
|
new Separator(),
|
||||||
new MenuItem("2025.11.3.37", () => { alert("Thank you for using Pocket Bird! You are on version: 2025.11.3.37"); }, false),
|
new MenuItem("2025.11.3.40", () => { alert("Thank you for using Pocket Bird! You are on version: 2025.11.3.40"); }, false),
|
||||||
];
|
];
|
||||||
|
|
||||||
const styleElement = document.createElement("style");
|
const styleElement = document.createElement("style");
|
||||||
|
|||||||
2
dist/obsidian/manifest.json
vendored
2
dist/obsidian/manifest.json
vendored
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"id": "pocket-bird",
|
"id": "pocket-bird",
|
||||||
"name": "Pocket Bird",
|
"name": "Pocket Bird",
|
||||||
"version": "2025.11.3.37",
|
"version": "2025.11.3.40",
|
||||||
"minAppVersion": "0.15.0",
|
"minAppVersion": "0.15.0",
|
||||||
"description": "It's a pet bird in your Obsidian, what more could you want?",
|
"description": "It's a pet bird in your Obsidian, what more could you want?",
|
||||||
"author": "Idrees Hassan",
|
"author": "Idrees Hassan",
|
||||||
|
|||||||
4
dist/userscript/birb.user.js
vendored
4
dist/userscript/birb.user.js
vendored
@@ -1,7 +1,7 @@
|
|||||||
// ==UserScript==
|
// ==UserScript==
|
||||||
// @name Pocket Bird
|
// @name Pocket Bird
|
||||||
// @namespace https://idreesinc.com
|
// @namespace https://idreesinc.com
|
||||||
// @version 2025.11.3.37
|
// @version 2025.11.3.40
|
||||||
// @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
|
||||||
@@ -1916,7 +1916,7 @@
|
|||||||
insertModal(`${birdBirb()} Mode`, message);
|
insertModal(`${birdBirb()} Mode`, message);
|
||||||
}),
|
}),
|
||||||
new Separator(),
|
new Separator(),
|
||||||
new MenuItem("2025.11.3.37", () => { alert("Thank you for using Pocket Bird! You are on version: 2025.11.3.37"); }, false),
|
new MenuItem("2025.11.3.40", () => { alert("Thank you for using Pocket Bird! You are on version: 2025.11.3.40"); }, false),
|
||||||
];
|
];
|
||||||
|
|
||||||
const styleElement = document.createElement("style");
|
const styleElement = document.createElement("style");
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"id": "pocket-bird",
|
"id": "pocket-bird",
|
||||||
"name": "Pocket Bird",
|
"name": "Pocket Bird",
|
||||||
"version": "2025.11.3.37",
|
"version": "__VERSION__",
|
||||||
"minAppVersion": "0.15.0",
|
"minAppVersion": "0.15.0",
|
||||||
"description": "It's a pet bird in your Obsidian, what more could you want?",
|
"description": "It's a pet bird in your Obsidian, what more could you want?",
|
||||||
"author": "Idrees Hassan",
|
"author": "Idrees Hassan",
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "node build.js",
|
"build": "node build.js",
|
||||||
"dev": "nodemon --watch src --watch stylesheet.css --watch build.js --exec \"npm run build\""
|
"dev": "nodemon --watch src --watch package.json --watch stylesheet.css --watch build.js --watch obsidian-manifest.json --watch browser-manifest.json --exec \"npm run build\""
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"archiver": "^7.0.1",
|
"archiver": "^7.0.1",
|
||||||
|
|||||||
Reference in New Issue
Block a user