obsidian-voice-note/esbuild.config.mjs
Andrey Epifancev b15ae972ca build: test vault path from VOICE_NOTE_VAULT, warn when missing (M-3, #3)
Default stays the author's test vault. Without the vault the dev build used to skip copying silently; now it says so and names the variable.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-10 19:23:01 +04:00

63 lines
1.9 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import esbuild from 'esbuild';
import { copyFileSync, existsSync, mkdirSync } from 'node:fs';
import { builtinModules } from 'node:module';
import process from 'node:process';
const prod = process.argv[2] === 'production';
// Путь к тестовому vault: переменная окружения VOICE_NOTE_VAULT, иначе vault автора.
const VAULT =
process.env.VOICE_NOTE_VAULT ||
'/Users/andrey.epifancev/Library/Mobile Documents/iCloud~md~obsidian/Documents/voice-note-test';
const PLUGIN_DIR = `${VAULT}/.obsidian/plugins/voice-note`;
// В dev-режиме после каждой сборки копируем плагин в тестовый vault, если он есть на этой машине.
const copyToVault = {
name: 'copy-to-vault',
setup(build) {
build.onStart(() => {
if (!existsSync(VAULT)) console.warn(`[copy-to-vault] vault не найден, копирование пропущено: ${VAULT}. Задайте VOICE_NOTE_VAULT.`);
});
build.onEnd((result) => {
if (result.errors.length > 0 || !existsSync(VAULT)) return;
mkdirSync(PLUGIN_DIR, { recursive: true });
for (const file of ['main.js', 'manifest.json']) copyFileSync(file, `${PLUGIN_DIR}/${file}`);
});
},
};
const context = await esbuild.context({
entryPoints: ['src/main.ts'],
bundle: true,
external: [
'obsidian',
'electron',
'@codemirror/autocomplete',
'@codemirror/collab',
'@codemirror/commands',
'@codemirror/language',
'@codemirror/lint',
'@codemirror/search',
'@codemirror/state',
'@codemirror/view',
'@lezer/common',
'@lezer/highlight',
'@lezer/lr',
...builtinModules,
],
format: 'cjs',
target: 'es2018',
logLevel: 'info',
sourcemap: prod ? false : 'inline',
treeShaking: true,
outfile: 'main.js',
minify: prod,
plugins: prod ? [] : [copyToVault],
});
if (prod) {
await context.rebuild();
process.exit(0);
} else {
await context.watch();
}