mirror of
https://github.com/youfoundjk/TeXcore.git
synced 2026-07-22 07:33:31 +00:00
114 lines
3.3 KiB
JavaScript
114 lines
3.3 KiB
JavaScript
import esbuild from 'esbuild';
|
|
import process from 'process';
|
|
import { builtinModules } from 'node:module';
|
|
import fs from 'fs';
|
|
import path from 'path';
|
|
import inlineWorkerPlugin from 'esbuild-plugin-inline-worker';
|
|
import esbuildSvelte from 'esbuild-svelte';
|
|
|
|
const builtins = [
|
|
...new Set([...builtinModules, ...builtinModules.map(moduleName => `node:${moduleName}`)])
|
|
];
|
|
|
|
const banner = `/*
|
|
THIS IS A GENERATED/BUNDLED FILE BY ESBUILD
|
|
if you want to view the source, please visit the github repository of this plugin
|
|
*/
|
|
`;
|
|
|
|
const prod = process.argv[2] === 'production';
|
|
|
|
async function build() {
|
|
const context = await esbuild.context({
|
|
banner: {
|
|
js: banner
|
|
},
|
|
entryPoints: ['src/main.ts'],
|
|
bundle: true,
|
|
plugins: [
|
|
inlineWorkerPlugin(),
|
|
esbuildSvelte({ compilerOptions: { css: 'injected' } }),
|
|
{
|
|
name: 'copy-to-dev-vault-plugin',
|
|
setup(build) {
|
|
build.onEnd(() => {
|
|
const rootDir = process.cwd();
|
|
const devEnvDir = path.join(
|
|
rootDir,
|
|
'../plugin-full-calendar/obsidian-dev-vault/.obsidian/plugins/ObsiTeXcore'
|
|
);
|
|
|
|
// Ensure dev output directory exists
|
|
try {
|
|
if (!fs.existsSync(devEnvDir)) {
|
|
fs.mkdirSync(devEnvDir, { recursive: true });
|
|
}
|
|
} catch (err) {
|
|
console.warn('⚠️ Could not create output directory:', err.message);
|
|
}
|
|
|
|
// Copy build files
|
|
try {
|
|
if (fs.existsSync(path.join(rootDir, 'main.js'))) {
|
|
fs.copyFileSync(path.join(rootDir, 'main.js'), path.join(devEnvDir, 'main.js'));
|
|
console.log(' | Copied main.js to dev vault');
|
|
}
|
|
if (fs.existsSync(path.join(rootDir, 'styles.css'))) {
|
|
fs.copyFileSync(
|
|
path.join(rootDir, 'styles.css'),
|
|
path.join(devEnvDir, 'styles.css')
|
|
);
|
|
console.log(' | Copied styles.css to dev vault');
|
|
}
|
|
if (fs.existsSync(path.join(rootDir, 'manifest.json'))) {
|
|
fs.copyFileSync(
|
|
path.join(rootDir, 'manifest.json'),
|
|
path.join(devEnvDir, 'manifest.json')
|
|
);
|
|
console.log(' | Copied manifest.json to dev vault');
|
|
}
|
|
} catch (err) {
|
|
console.warn('⚠️ Could not copy files to dev vault:', err.message);
|
|
}
|
|
});
|
|
}
|
|
}
|
|
],
|
|
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',
|
|
...builtins
|
|
],
|
|
format: 'cjs',
|
|
target: 'es2020',
|
|
logLevel: 'info',
|
|
minify: prod,
|
|
sourcemap: prod ? false : 'inline',
|
|
treeShaking: true,
|
|
outfile: 'main.js'
|
|
});
|
|
|
|
if (!prod) {
|
|
await context.watch();
|
|
console.log('Watching for changes...');
|
|
} else {
|
|
await context.rebuild();
|
|
await context.dispose();
|
|
}
|
|
}
|
|
|
|
build().catch(err => {
|
|
console.error(err);
|
|
process.exit(1);
|
|
});
|