From ea0a14f08c58242e143dab097c8feac283782faf Mon Sep 17 00:00:00 2001 From: Idrees Hassan Date: Mon, 3 Nov 2025 22:05:25 -0500 Subject: [PATCH] Update build to use build cache --- .gitignore | 1 + browser-manifest.json | 2 +- build.js | 99 ++++++++++++++++------------------- dist/birb.js | 2 +- dist/extension.zip | Bin 147808 -> 147808 bytes dist/extension/birb.js | 2 +- dist/extension/manifest.json | 2 +- dist/obsidian/main.js | 2 +- dist/obsidian/manifest.json | 2 +- dist/userscript/birb.user.js | 4 +- obsidian-manifest.json | 2 +- package.json | 2 +- 12 files changed, 56 insertions(+), 64 deletions(-) diff --git a/.gitignore b/.gitignore index 6be2695..a3eebd7 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ .DS_Store /dist/birb.bundled.js obsidian-test.sh +build-cache.json diff --git a/browser-manifest.json b/browser-manifest.json index ab08464..c937aa8 100644 --- a/browser-manifest.json +++ b/browser-manifest.json @@ -2,7 +2,7 @@ "manifest_version": 3, "name": "Pocket Bird", "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", "icons": { "48": "images/icons/transparent/48x48x1.png", diff --git a/build.js b/build.js index 8fbfa16..0d83103 100644 --- a/build.js +++ b/build.js @@ -5,6 +5,7 @@ import { readFileSync, writeFileSync, mkdirSync, unlinkSync, cpSync, createWrite import archiver from 'archiver'; // Path constants +const BUILD_CACHE_PATH = "./build-cache.json"; const SRC_DIR = "./src"; const SPRITES_DIR = "./sprites"; const IMAGES_DIR = "./images"; @@ -22,6 +23,9 @@ const APPLICATION_ENTRY = SRC_DIR + "/application.js"; const BUNDLED_OUTPUT = DIST_DIR + "/birb.bundled.js"; const BIRB_OUTPUT = DIST_DIR + "/birb.js"; +const VERSION_KEY = "__VERSION__"; +const STYLESHEET_KEY = "___STYLESHEET___"; + const spriteSheets = [ { key: "__SPRITE_SHEET__", @@ -33,65 +37,34 @@ const spriteSheets = [ } ]; -const STYLESHEET_KEY = "___STYLESHEET___"; +/** @type {Record} */ +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 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; -try { - const manifest = JSON.parse(readFileSync(BROWSER_MANIFEST, 'utf8')); - if (manifest.version) { - if (manifest.version.startsWith(versionDate)) { - // Same day, increment build number - const parts = manifest.version.split('.'); - if (parts.length === 4) { - buildNumber = parseInt(parts[3], 10) + 1; - } - } + +if (buildCache.version && buildCache.version.startsWith(versionDate)) { + // Same day, increment build number + const parts = buildCache.version.split('.'); + 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}`; -// Update browser manifest with new version -try { - const manifest = JSON.parse(readFileSync(BROWSER_MANIFEST, '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== - -`; +// Update build cache +buildCache.version = version; +writeFileSync(BUILD_CACHE_PATH, JSON.stringify(buildCache), 'utf8'); // Bundle with rollup const bundle = await rollup({ @@ -111,7 +84,7 @@ let birbJs = readFileSync(BUNDLED_OUTPUT, 'utf8'); unlinkSync(BUNDLED_OUTPUT); // Replace version placeholder -birbJs = birbJs.replaceAll('__VERSION__', version); +birbJs = birbJs.replaceAll(VERSION_KEY, version); // Compile and insert sprite sheets for (const spriteSheet of spriteSheets) { @@ -127,6 +100,22 @@ birbJs = birbJs.replace(STYLESHEET_KEY, stylesheetContent); writeFileSync(BIRB_OUTPUT, birbJs); // 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 }); const userScript = userScriptHeader + birbJs; writeFileSync(USERSCRIPT_DIR + '/birb.user.js', userScript); @@ -138,8 +127,9 @@ mkdirSync(EXTENSION_DIR, { recursive: true }); writeFileSync(EXTENSION_DIR + '/birb.js', birbJs); // Copy manifest.json -const manifestContent = readFileSync(BROWSER_MANIFEST, 'utf8'); -writeFileSync(EXTENSION_DIR + '/manifest.json', manifestContent); +let browserManifest = readFileSync(BROWSER_MANIFEST, 'utf8'); +browserManifest = browserManifest.replace(VERSION_KEY, version); +writeFileSync(EXTENSION_DIR + '/manifest.json', browserManifest); // Copy icons folder mkdirSync(EXTENSION_DIR + '/images/icons', { recursive: true }); @@ -172,7 +162,8 @@ mkdirSync(OBSIDIAN_DIR, { recursive: true }); writeFileSync(OBSIDIAN_DIR + '/main.js', birbJs); // Copy manifest.json -const obsidianManifestContent = readFileSync(OBSIDIAN_MANIFEST, 'utf8'); -writeFileSync(OBSIDIAN_DIR + '/manifest.json', obsidianManifestContent); +let obsidianManifest = readFileSync(OBSIDIAN_MANIFEST, 'utf8'); +obsidianManifest = obsidianManifest.replace(/"version":\s*".*"/, `"version": "${version}"`); +writeFileSync(OBSIDIAN_DIR + '/manifest.json', obsidianManifest); console.log(`Build complete: ${version}`); \ No newline at end of file diff --git a/dist/birb.js b/dist/birb.js index 13a3c30..ce2a95a 100644 --- a/dist/birb.js +++ b/dist/birb.js @@ -1902,7 +1902,7 @@ insertModal(`${birdBirb()} Mode`, message); }), 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"); diff --git a/dist/extension.zip b/dist/extension.zip index 9fa6640143371baa9cbe4b220a76a5df6a8fae87..c720120a4022942599b9236c6889766ced7babd5 100644 GIT binary patch delta 1189 zcmaFR#QC6!bHfr=rnwTEm$9ZfGwB`Q%;z~nM&e!m3$w@Z3=Fawj0^$Z%q(0CATU>A z^1f6hpyK97soNi=GS;~O+0&C&F`5GD?K4*~vax{}3pX$>1Q|K)G^6(R{B4ZsEKtsL zActeRy%iJdc7ffD%R$1^9d0mcPw%#3;@;+70?2rfR-NtpE-+Stlz@5DwQQKUw&!1AJP#7u4pi_QCTF-k>JFnE!b*8tp!pjf zFiwCe(4GzyV%uK)gz+w1XnXAo#&iTv@D1Z71W(`tV-tu6_U8W2jHxg`PX}^1wnzSC zya;oq_V)1qjQ--h+b~ndvj}g>-O0U|7PTd2}LH`8l+w?m8=ikHjyp=S3`1{o&C)JXVNym zF^Qh@<-;kn2Tz2K+`7JTiRdEk>6Poe`31HF&fMgizh}{l zAhXxxpeH}u=c7NT?TdVNW)t_MJ$mQ9RmIN9efj%%w%PspJs)y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3G? f4-v0|(r2KwoC8F>07@TnV2T9$9vl|Rj!d=y)%mu+ diff --git a/dist/extension/birb.js b/dist/extension/birb.js index 13a3c30..ce2a95a 100644 --- a/dist/extension/birb.js +++ b/dist/extension/birb.js @@ -1902,7 +1902,7 @@ insertModal(`${birdBirb()} Mode`, message); }), 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"); diff --git a/dist/extension/manifest.json b/dist/extension/manifest.json index ab08464..09eb809 100644 --- a/dist/extension/manifest.json +++ b/dist/extension/manifest.json @@ -2,7 +2,7 @@ "manifest_version": 3, "name": "Pocket Bird", "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", "icons": { "48": "images/icons/transparent/48x48x1.png", diff --git a/dist/obsidian/main.js b/dist/obsidian/main.js index 13a3c30..ce2a95a 100644 --- a/dist/obsidian/main.js +++ b/dist/obsidian/main.js @@ -1902,7 +1902,7 @@ insertModal(`${birdBirb()} Mode`, message); }), 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"); diff --git a/dist/obsidian/manifest.json b/dist/obsidian/manifest.json index 4220a9a..34e3d99 100644 --- a/dist/obsidian/manifest.json +++ b/dist/obsidian/manifest.json @@ -1,7 +1,7 @@ { "id": "pocket-bird", "name": "Pocket Bird", - "version": "2025.11.3.37", + "version": "2025.11.3.40", "minAppVersion": "0.15.0", "description": "It's a pet bird in your Obsidian, what more could you want?", "author": "Idrees Hassan", diff --git a/dist/userscript/birb.user.js b/dist/userscript/birb.user.js index e64c82a..785482f 100644 --- a/dist/userscript/birb.user.js +++ b/dist/userscript/birb.user.js @@ -1,7 +1,7 @@ // ==UserScript== // @name Pocket Bird // @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 // @author Idrees // @downloadURL https://github.com/IdreesInc/Pocket-Bird/raw/refs/heads/main/dist/userscript/birb.user.js @@ -1916,7 +1916,7 @@ insertModal(`${birdBirb()} Mode`, message); }), 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"); diff --git a/obsidian-manifest.json b/obsidian-manifest.json index 4220a9a..1f45808 100644 --- a/obsidian-manifest.json +++ b/obsidian-manifest.json @@ -1,7 +1,7 @@ { "id": "pocket-bird", "name": "Pocket Bird", - "version": "2025.11.3.37", + "version": "__VERSION__", "minAppVersion": "0.15.0", "description": "It's a pet bird in your Obsidian, what more could you want?", "author": "Idrees Hassan", diff --git a/package.json b/package.json index 7c2c0c9..cb76cb6 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "type": "module", "scripts": { "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": { "archiver": "^7.0.1",