2025-07-24 22:17:38 +02:00
|
|
|
import * as esbuild from 'esbuild';
|
|
|
|
|
import { readdir, rename } from 'fs/promises';
|
|
|
|
|
import { join, dirname, basename, extname } from 'path';
|
2025-10-30 21:46:38 +01:00
|
|
|
import { NovadiUnplugin } from '@novadi/core/unplugin';
|
2025-07-24 22:17:38 +02:00
|
|
|
|
|
|
|
|
// Convert PascalCase to kebab-case
|
|
|
|
|
function toKebabCase(str) {
|
|
|
|
|
return str.replace(/([A-Z])/g, '-$1').toLowerCase().replace(/^-/, '');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Recursively rename files to kebab-case
|
|
|
|
|
async function renameFiles(dir) {
|
|
|
|
|
const entries = await readdir(dir, { withFileTypes: true });
|
2025-10-30 21:46:38 +01:00
|
|
|
|
2025-07-24 22:17:38 +02:00
|
|
|
for (const entry of entries) {
|
|
|
|
|
const fullPath = join(dir, entry.name);
|
2025-10-30 21:46:38 +01:00
|
|
|
|
2025-07-24 22:17:38 +02:00
|
|
|
if (entry.isDirectory()) {
|
|
|
|
|
await renameFiles(fullPath);
|
|
|
|
|
} else if (entry.isFile() && extname(entry.name) === '.js') {
|
|
|
|
|
const baseName = basename(entry.name, '.js');
|
|
|
|
|
const kebabName = toKebabCase(baseName);
|
2025-10-30 21:46:38 +01:00
|
|
|
|
2025-07-24 22:17:38 +02:00
|
|
|
if (baseName !== kebabName) {
|
|
|
|
|
const newPath = join(dirname(fullPath), kebabName + '.js');
|
|
|
|
|
await rename(fullPath, newPath);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Build with esbuild
|
|
|
|
|
async function build() {
|
|
|
|
|
try {
|
2025-10-30 21:46:38 +01:00
|
|
|
|
2025-07-24 22:17:38 +02:00
|
|
|
await esbuild.build({
|
|
|
|
|
entryPoints: ['src/index.ts'],
|
|
|
|
|
bundle: true,
|
|
|
|
|
outfile: 'wwwroot/js/calendar.js',
|
|
|
|
|
format: 'esm',
|
|
|
|
|
sourcemap: 'inline',
|
|
|
|
|
target: 'es2020',
|
|
|
|
|
minify: false,
|
|
|
|
|
keepNames: true,
|
2025-10-30 21:46:38 +01:00
|
|
|
platform: 'browser',
|
|
|
|
|
plugins: [NovadiUnplugin.esbuild({ debug: false, enableAutowiring: true, performanceLogging: true })]
|
2025-07-24 22:17:38 +02:00
|
|
|
});
|
2025-10-30 21:46:38 +01:00
|
|
|
|
|
|
|
|
|
2025-07-24 22:17:38 +02:00
|
|
|
} catch (error) {
|
|
|
|
|
console.error('Build failed:', error);
|
|
|
|
|
process.exit(1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-30 21:46:38 +01:00
|
|
|
build();
|