Calendar/build.js
Janus C. H. Knudsen a0c0ef9e8d Refactor calendar V2 core with DI and new features
Introduces dependency injection container and composition root
Adds core services like DateService and NavigationAnimator
Simplifies CalendarOrchestrator with improved store handling
Implements mock stores and demo application for V2 calendar
2025-12-07 14:31:16 +01:00

86 lines
2.4 KiB
JavaScript

import * as esbuild from 'esbuild';
import { readdir, rename } from 'fs/promises';
import { join, dirname, basename, extname } from 'path';
import { NovadiUnplugin } from '@novadi/core/unplugin';
// 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 });
for (const entry of entries) {
const fullPath = join(dir, entry.name);
if (entry.isDirectory()) {
await renameFiles(fullPath);
} else if (entry.isFile() && extname(entry.name) === '.js') {
const baseName = basename(entry.name, '.js');
const kebabName = toKebabCase(baseName);
if (baseName !== kebabName) {
const newPath = join(dirname(fullPath), kebabName + '.js');
await rename(fullPath, newPath);
}
}
}
}
// Build with esbuild
async function build() {
try {
// Main calendar bundle (with DI)
await esbuild.build({
entryPoints: ['src/index.ts'],
bundle: true,
outfile: 'wwwroot/js/calendar.js',
format: 'esm',
sourcemap: 'inline',
target: 'es2020',
minify: false,
keepNames: true,
platform: 'browser',
plugins: [NovadiUnplugin.esbuild({ debug: false, enableAutowiring: true, performanceLogging: true })]
});
// V2 standalone bundle (no DI, no dependencies on main calendar)
await esbuild.build({
entryPoints: ['src/v2/entry.ts'],
bundle: true,
outfile: 'wwwroot/js/calendar-v2.js',
format: 'esm',
sourcemap: 'inline',
target: 'es2020',
minify: false,
keepNames: true,
platform: 'browser'
});
console.log('V2 bundle created: wwwroot/js/calendar-v2.js');
// V2 demo bundle (with DI transformer for autowiring)
await esbuild.build({
entryPoints: ['src/v2/demo/index.ts'],
bundle: true,
outfile: 'wwwroot/js/v2-demo.js',
format: 'esm',
sourcemap: 'inline',
target: 'es2020',
minify: false,
keepNames: true,
platform: 'browser',
plugins: [NovadiUnplugin.esbuild({ debug: false, enableAutowiring: true })]
});
console.log('V2 demo bundle created: wwwroot/js/v2-demo.js');
} catch (error) {
console.error('Build failed:', error);
process.exit(1);
}
}
build();