From b4eb0e4868add3acfd17ec56e7f46af7893942b6 Mon Sep 17 00:00:00 2001 From: vorotamoroz Date: Sat, 4 Oct 2025 17:12:37 +0900 Subject: [PATCH] Improved: copy a dev build to vault folder --- .gitignore | 3 +++ esbuild.config.mjs | 27 +++++++++++++++++++++++++++ example.env | 1 + package.json | 2 +- 4 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 example.env diff --git a/.gitignore b/.gitignore index 67e1847..8432f68 100644 --- a/.gitignore +++ b/.gitignore @@ -17,3 +17,6 @@ meta-*.json # obsidian data.json .vscode + +# environment variables +.env diff --git a/esbuild.config.mjs b/esbuild.config.mjs index 05990de..284a35a 100644 --- a/esbuild.config.mjs +++ b/esbuild.config.mjs @@ -19,6 +19,18 @@ const manifestJson = JSON.parse(fs.readFileSync("./manifest.json") + ""); const packageJson = JSON.parse(fs.readFileSync("./package.json") + ""); const updateInfo = JSON.stringify(fs.readFileSync("./updates.md") + ""); +const PATHS_TEST_INSTALL = process.env?.PATHS_TEST_INSTALL || ""; +const PATH_TEST_INSTALL = PATHS_TEST_INSTALL.split(path.delimiter).map(p => p.trim()).filter(p => p.length); +if (!prod) { + if (PATH_TEST_INSTALL) { + console.log(`Built files will be copied to ${PATH_TEST_INSTALL}`); + } else { + console.log("Development build: You can install the plug-in to Obsidian for testing by exporting the PATHS_TEST_INSTALL environment variable with the paths to your vault plugins directories separated by your system path delimiter (':' on Unix, ';' on Windows)."); + } +} else { + console.log("Production build"); +} + const moduleAliasPlugin = { name: "module-alias", setup(build) { @@ -95,6 +107,21 @@ const plugins = [ } else { fs.copyFileSync("./main_org.js", "./main.js"); } + if (PATH_TEST_INSTALL) { + for (const installPath of PATH_TEST_INSTALL) { + const realPath = path.resolve(installPath); + console.log(`Copying built files to ${realPath}`); + if (!fs.existsSync(realPath)) { + console.warn(`Test install path ${installPath} does not exist`); + continue; + } + const manifestX = JSON.parse(fs.readFileSync("./manifest.json") + ""); + manifestX.version = manifestJson.version + "." + Date.now(); + fs.writeFileSync(path.join(installPath, "manifest.json"), JSON.stringify(manifestX, null, 2)); + fs.copyFileSync("./main.js", path.join(installPath, "main.js")); + fs.copyFileSync("./styles.css", path.join(installPath, "styles.css")); + } + } }); }, }, diff --git a/example.env b/example.env new file mode 100644 index 0000000..b55874d --- /dev/null +++ b/example.env @@ -0,0 +1 @@ +PATHS_TEST_INSTALL=your-vault-plugin-path:and-another-path \ No newline at end of file diff --git a/package.json b/package.json index 5015f3f..6ba0878 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ "postbakei18n": "prettier --config ./.prettierrc ./src/lib/src/common/messages/*.ts --write --log-level error", "posti18n:yaml2json": "npm run prettyjson", "predev": "npm run bakei18n", - "dev": "node esbuild.config.mjs", + "dev": "node --env-file=.env esbuild.config.mjs", "prebuild": "npm run bakei18n", "build": "node esbuild.config.mjs production", "buildDev": "node esbuild.config.mjs dev",