diff --git a/README.md b/README.md index e45b847..dd57bea 100644 --- a/README.md +++ b/README.md @@ -34,8 +34,9 @@ command. ## Installing -Copy (or symlink) `main.js`, `styles.css`, and `manifest.json` into -`VaultFolder/.obsidian/plugins/ablaze/`, then reload Obsidian. +`npm run install-plugin` builds and copies `main.js`, `styles.css`, and `manifest.json` +into `VaultFolder/.obsidian/plugins/ablaze/` (set `ABLAZE_VAULT` to target another vault), +then reload Obsidian. It must be a real directory, not a symlink — see the gotchas. ## Gotchas learnt the hard way @@ -43,3 +44,11 @@ Copy (or symlink) `main.js`, `styles.css`, and `manifest.json` into `onUserEnable()` only runs the one time the plugin is enabled in settings — registering the view there means that after any restart the persisted tab has no view and Obsidian shows "Plugin no longer active. The plugin that created this tab has gone away." +- Obsidian Sync only carries `main.js`, `manifest.json`, `styles.css`, and `data.json` to + other devices, and the only version a device shows (Settings → Community plugins) is the + one in `manifest.json` — bumping `package.json` alone proves nothing. Bump the manifest + (`npm version`) when you need to check that a device actually received a build; the panel + also prints its version at the bottom for the same reason. +- Don't symlink the plugin directory into the vault. Desktop Obsidian coped with it, but + Obsidian Sync never reliably pushed the rebuilt `main.js` to mobile, which kept running + a build from before the `onload()` fix above. `install.mjs` copies real files instead. diff --git a/install.mjs b/install.mjs new file mode 100644 index 0000000..11298d4 --- /dev/null +++ b/install.mjs @@ -0,0 +1,22 @@ +// Copies the built plugin into the vault. A real directory, not a symlink: Obsidian +// Sync would not reliably propagate main.js changes from a symlinked plugin folder, +// which left mobile running stale code for weeks. +import { copyFileSync, mkdirSync, lstatSync, rmSync } from "fs"; +import { join } from "path"; + +const vault = process.env.ABLAZE_VAULT || "/Users/robin/Data/Obsidian/Everything"; +const target = join(vault, ".obsidian", "plugins", "ablaze"); + +try { + if (lstatSync(target).isSymbolicLink()) { + rmSync(target); + console.log(`removed symlink ${target}`); + } +} catch (e) { + if (e.code !== "ENOENT") throw e; +} +mkdirSync(target, { recursive: true }); +for (const f of ["main.js", "manifest.json", "styles.css"]) { + copyFileSync(f, join(target, f)); + console.log(`${f} -> ${target}`); +} diff --git a/main.js b/main.js index eddf45b..4673c80 100644 --- a/main.js +++ b/main.js @@ -101,7 +101,7 @@ var templates_default = [ var VIEW_NAME = "ablaze-view"; var Ablaze = class extends import_obsidian.Plugin { async onload() { - this.registerView(VIEW_NAME, (leaf) => new AblazeView(leaf)); + this.registerView(VIEW_NAME, (leaf) => new AblazeView(leaf, this)); this.addRibbonIcon("book-template", "Open Ablaze", () => this.activateView()); this.addCommand({ id: "open-view", @@ -127,6 +127,10 @@ var Ablaze = class extends import_obsidian.Plugin { } }; var AblazeView = class extends import_obsidian.ItemView { + constructor(leaf, plugin) { + super(leaf); + this.plugin = plugin; + } async onOpen() { this.contentEl.empty(); this.contentEl.addClass("ablaze-root"); @@ -137,6 +141,7 @@ var AblazeView = class extends import_obsidian.ItemView { but.style.color = color; but.onclick = () => new AblazeModal(this.app, data).open(); }); + this.contentEl.createEl("div", { cls: "ablaze-version", text: `v${this.plugin.manifest.version}` }); } getViewType() { return VIEW_NAME; diff --git a/manifest.json b/manifest.json index 3fbd000..0f275c3 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "id": "ablaze", "name": "Ablaze", - "version": "1.0.0", + "version": "1.1.0", "minAppVersion": "0.15.0", "description": "My personal all-purpose plugin", "author": "Robin", diff --git a/package.json b/package.json index fb8463e..610f887 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,8 @@ "scripts": { "watch": "node esbuild.config.mjs", "build": "node esbuild.config.mjs production", - "version": "node version-bump.mjs && git add manifest.json versions.json" + "version": "node version-bump.mjs && git add manifest.json versions.json", + "install-plugin": "npm run build && node install.mjs" }, "keywords": [], "author": "", diff --git a/src/main.js b/src/main.js index 1aa1700..9616a4d 100644 --- a/src/main.js +++ b/src/main.js @@ -15,7 +15,7 @@ export default class Ablaze extends Plugin { // that only runs the one time the plugin is enabled in settings, so after // any app restart the persisted leaf has no view and Obsidian shows // "Plugin no longer active". - this.registerView(VIEW_NAME, leaf => new AblazeView(leaf)); + this.registerView(VIEW_NAME, leaf => new AblazeView(leaf, this)); this.addRibbonIcon('book-template', 'Open Ablaze', () => this.activateView()); this.addCommand({ id: 'open-view', @@ -49,6 +49,10 @@ export default class Ablaze extends Plugin { // - create in new tab class AblazeView extends ItemView { + constructor (leaf, plugin) { + super(leaf); + this.plugin = plugin; + } async onOpen () { this.contentEl.empty(); this.contentEl.addClass('ablaze-root'); @@ -59,6 +63,9 @@ class AblazeView extends ItemView { but.style.color = color; but.onclick = () => new AblazeModal(this.app, data).open(); }); + // So that a device can be checked at a glance for which build it is actually + // running (Sync propagating main.js to mobile has been a question). + this.contentEl.createEl('div', { cls: 'ablaze-version', text: `v${this.plugin.manifest.version}` }); } getViewType () { return VIEW_NAME; diff --git a/styles.css b/styles.css index 7e66354..51c3b94 100644 --- a/styles.css +++ b/styles.css @@ -15,3 +15,8 @@ input.ablaze-new-name { .ablaze-actions { text-align: right; } +.ablaze-version { + margin-top: 1rem; + color: var(--text-faint); + font-size: var(--font-smallest); +} diff --git a/versions.json b/versions.json index 26382a1..5934189 100644 --- a/versions.json +++ b/versions.json @@ -1,3 +1,4 @@ { - "1.0.0": "0.15.0" + "1.0.0": "0.15.0", + "1.1.0": "0.15.0" }