All files / scripts build.js

0% Statements 0/133
0% Branches 0/1
0% Functions 0/1
0% Lines 0/133

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134                                                                                                                                                                                                                                                                           
// scripts/build.js
import { build } from 'esbuild';

const builds = [
    // Core server framework (ESM)
    {
        entryPoints: ['src/coherent.js'],
        format: 'esm',
        outfile: 'dist/coherent.js',
        platform: 'node',
        target: 'node16',
    },

    // Core server framework (CJS for compatibility)
    {
        entryPoints: ['src/coherent.js'],
        format: 'cjs',
        outfile: 'dist/coherent.cjs',
        platform: 'node',
        target: 'node16',
    },

    // Express integration
    {
        entryPoints: ['src/express/index.js'],
        format: 'esm',
        outfile: 'dist/express.js',
        platform: 'node',
        target: 'node16',
        external: ['express'],
    },
    {
        entryPoints: ['src/express/index.js'],
        format: 'cjs',
        outfile: 'dist/express.cjs',
        platform: 'node',
        target: 'node16',
        external: ['express'],
    },

    // Koa integration
    {
        entryPoints: ['src/koa/index.js'],
        format: 'esm',
        outfile: 'dist/koa.js',
        platform: 'node',
        target: 'node16',
        external: ['koa'],
    },
    {
        entryPoints: ['src/koa/index.js'],
        format: 'cjs',
        outfile: 'dist/koa.cjs',
        platform: 'node',
        target: 'node16',
        external: ['koa'],
    },

    // Fastify integration
    {
        entryPoints: ['src/fastify/coherent-fastify.js'],
        format: 'esm',
        outfile: 'dist/fastify.js',
        platform: 'node',
        target: 'node16',
        external: ['fastify'],
    },
    {
        entryPoints: ['src/fastify/coherent-fastify.js'],
        format: 'cjs',
        outfile: 'dist/fastify.cjs',
        platform: 'node',
        target: 'node16',
        external: ['fastify'],
    },

    // Next.js integration
    {
        entryPoints: ['src/nextjs/index.js'],
        format: 'esm',
        outfile: 'dist/nextjs.js',
        platform: 'node',
        target: 'node16',
        external: ['next'],
    },
    {
        entryPoints: ['src/nextjs/index.js'],
        format: 'cjs',
        outfile: 'dist/nextjs.cjs',
        platform: 'node',
        target: 'node16',
        external: ['next'],
    },

    // API framework
    {
        entryPoints: ['src/api/index.js'],
        format: 'esm',
        outfile: 'dist/api.js',
        platform: 'node',
        target: 'node16',
    },
    {
        entryPoints: ['src/api/index.js'],
        format: 'cjs',
        outfile: 'dist/api.cjs',
        platform: 'node',
        target: 'node16',
    },

    // Optional client-side hydration
    {
        entryPoints: ['src/client/hydration.js'],
        format: 'esm',
        outfile: 'dist/client.js',
        platform: 'browser',
        target: 'es2020',
        minify: true,
    },
];

console.log('šŸ—ļø  Building Coherent Server Framework...\n');

for (const config of builds) {
    await build({
        bundle: true,
        sourcemap: true,
        ...config,
    });
    console.log(`āœ… Built ${config.outfile}`);
}

console.log('\nšŸ“¦ Server framework build complete!');