Files

42 lines
1.3 KiB
TypeScript

import { defineConfig } from 'tsup';
import fs from 'fs';
import path from 'path';
export default defineConfig({
entry: ['src/main.ts'],
format: ['esm'], // пусть tsup генерит export {...}
outDir: '../luci-app-tachyon/htdocs/luci-static/resources/view/tachyon',
outExtension: () => ({ js: '.js' }),
dts: false,
clean: false,
sourcemap: false,
banner: {
js: `// This file is autogenerated, please don't change manually\n"use strict";`,
},
esbuildOptions(options) {
options.legalComments = 'none';
options.charset = 'utf8';
},
onSuccess: () => {
const outDir =
'../luci-app-tachyon/htdocs/luci-static/resources/view/tachyon';
const file = path.join(outDir, 'main.js');
let code = fs.readFileSync(file, 'utf8');
const originalCode = code;
code = code.replace(
/export\s*{([\s\S]*?)}/,
(match, group) => {
return `return baseclass.extend({${group}})`;
}
);
if (code === originalCode) {
throw new Error("Failed to patch LuCI build: 'export { ... }' block not found in main.js!");
}
fs.writeFileSync(file, code, 'utf8');
console.log(`✅ Patched LuCI build: ${file}`);
},
});