Spaces:
Sleeping
Sleeping
File size: 2,411 Bytes
7f81110 | 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 | import * as esbuild from "esbuild";
import { execSync } from "child_process";
import fs from "fs";
import path from "path";
async function build() {
const start = Date.now();
console.log("π Starting build...");
// Ensure dist directory exists
if (!fs.existsSync("dist")) {
fs.mkdirSync("dist");
}
try {
console.log("π¦ Bundling with esbuild...");
await esbuild.build({
entryPoints: ["server/index.ts"],
bundle: true,
platform: "node",
target: "node20",
outfile: "dist/index.cjs",
format: "cjs",
sourcemap: true,
minify: false, // Keep it readable for debugging in production for now
// We keep most heavy dependencies external if they have native bindings
external: [
"whatsapp-web.js",
"pg",
"express",
"canvas",
"bufferutil",
"utf-8-validate",
"fsevents",
"@playwright/test",
"vitest"
],
loader: {
".ts": "ts",
},
alias: {
"@shared": path.resolve(__dirname, "../src/libs/shared"),
},
});
const end = Date.now();
console.log(`β
Build completed in ${((end - start) / 1000).toFixed(2)}s`);
// Copy GraphQL queries to dist
console.log("π Copying GraphQL queries...");
const queriesSrc = path.resolve(__dirname, "../src/modules/shopify/infrastructure/shopify/graphql/queries");
const queriesDist = path.resolve(process.cwd(), "dist/queries");
if (!fs.existsSync(queriesDist)) {
fs.mkdirSync(queriesDist, { recursive: true });
}
if (fs.existsSync(queriesSrc)) {
fs.readdirSync(queriesSrc).forEach(file => {
const srcFile = path.join(queriesSrc, file);
const destFile = path.join(queriesDist, file);
fs.copyFileSync(srcFile, destFile);
console.log(` π Copied ${file}`);
});
} else {
console.warn("β οΈ Warning: Queries source directory not found:", queriesSrc);
}
} catch (error) {
console.error("β Build failed:", error);
process.exit(1);
}
}
build();
|