| 1 | #!/usr/bin/env node |
| 2 | |
| 3 | /** |
| 4 | * Copyright (c) Meta Platforms, Inc. and affiliates. |
| 5 | * |
| 6 | * This source code is licensed under the MIT license found in the |
| 7 | * LICENSE file in the root directory of this source tree. |
| 8 | */ |
| 9 | |
| 10 | import * as esbuild from 'esbuild'; |
| 11 | import yargs from 'yargs'; |
| 12 | import * as Server from './server.mjs'; |
| 13 | import * as Client from './client.mjs'; |
| 14 | import path from 'path'; |
| 15 | import {fileURLToPath} from 'url'; |
| 16 | |
| 17 | const IS_DEV = process.env.NODE_ENV === 'development'; |
| 18 | const __filename = fileURLToPath(import.meta.url); |
| 19 | const __dirname = path.dirname(__filename); |
| 20 | |
| 21 | const argv = yargs(process.argv.slice(2)) |
| 22 | .choices('t', ['client', 'server']) |
| 23 | .options('w', { |
| 24 | alias: 'watch', |
| 25 | default: false, |
| 26 | type: 'boolean', |
| 27 | }) |
| 28 | .parse(); |
| 29 | |
| 30 | async function main() { |
| 31 | if (argv.w) { |
| 32 | const serverCtx = await esbuild.context(Server.config); |
| 33 | const clientCtx = await esbuild.context(Client.config); |
| 34 | await Promise.all([serverCtx.watch(), clientCtx.watch()]); |
| 35 | console.log('watching for changes...'); |
| 36 | } else { |
| 37 | switch (argv.t) { |
| 38 | case 'server': { |
| 39 | await esbuild.build({ |
| 40 | sourcemap: IS_DEV, |
| 41 | minify: IS_DEV === false, |
| 42 | ...Server.config, |
| 43 | }); |
| 44 | break; |
| 45 | } |
| 46 | case 'client': { |
| 47 | await esbuild.build({ |
| 48 | sourcemap: IS_DEV, |
| 49 | minify: IS_DEV === false, |
| 50 | ...Client.config, |
| 51 | }); |
| 52 | break; |
| 53 | } |
| 54 | } |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | main(); |