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 9fa6640..c720120 100644 Binary files a/dist/extension.zip and b/dist/extension.zip differ 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",