File size: 1,138 Bytes
b39afbe
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
/**
 * Copyright (c) 2023 MERCENARIES.AI PTE. LTD.
 * All rights reserved.
 */

import esbuild from 'esbuild';
import assert from 'node:assert';
import { execSync } from 'node:child_process';

const environment = process.argv[2];
assert(environment === 'production' || environment === 'development', 'Invalid environment ' + environment);

console.log(`Building omni-server (${environment})...`);
switch(environment) {
    case 'production':
        esbuild
        .build({
          entryPoints: ['src/run.ts'],
          outdir: 'dist',
          color: true,
          bundle: true,
          platform: 'node',
          format: 'esm',
          tsconfig: 'tsconfig.json',
          logLevel: 'warning',
          packages: 'external',
          define: {
            'process.env.NODE_ENV': `"${environment}"`
          },
          sourcemap: false,
          external: ['sharp', 'better-sqlite3']
        })
        .then(() => console.log('Building omni-server done'))
        .catch(() => process.exit(1));
        break;      
    case 'development':
        execSync('tsc --build', { stdio: 'inherit' });
        break;      
}