this repo has no description
1#!/usr/bin/env bun
2// Build script for Google Apps Script
3
4import * as esbuild from "esbuild";
5import { readFileSync, writeFileSync, mkdirSync } from "fs";
6
7const command = process.argv[2] || "build";
8
9if (command === "build") {
10 console.log("🔨 Building for Apps Script (bundled from main classifier)...\n");
11
12 // Bundle with esbuild
13 console.log("1️⃣ Bundling with esbuild...");
14 try {
15 await esbuild.build({
16 entryPoints: ["src/apps-script/wrapper.ts"],
17 bundle: true,
18 outfile: "build/bundled.js",
19 format: "esm", // Use ES modules format
20 target: "es2015",
21 platform: "neutral",
22 });
23 console.log("✅ Bundled successfully\n");
24 } catch (e) {
25 console.error("❌ Bundling failed:", e);
26 process.exit(1);
27 }
28
29 // Post-process: Convert to Apps Script compatible format
30 console.log("2️⃣ Post-processing for Apps Script...");
31 mkdirSync("build", { recursive: true });
32 let js = readFileSync("build/bundled.js", "utf-8");
33
34 // Remove export statements - functions will be top-level
35 js = js.replace(/^export \{[^}]+\};?\s*$/gm, '');
36 js = js.replace(/^export (function|const|var|let) /gm, '$1 ');
37
38 const output = `// Auto-generated from TypeScript at: ${new Date().toISOString()}
39// Source: src/apps-script/wrapper.ts + src/classifier.ts
40// DO NOT EDIT THIS FILE DIRECTLY - Edit the TypeScript source instead
41// This file is bundled from the main classifier to ensure consistency
42
43${js}
44`;
45
46 writeFileSync("build/Code.gs", output);
47 console.log("✅ Created build/Code.gs\n");
48
49 console.log("🎉 Build complete!");
50 console.log("\n📋 Next steps:");
51 console.log(" 1. Open https://script.google.com");
52 console.log(" 2. Create a new project (or open existing)");
53 console.log(" 3. Copy build/Code.gs");
54 console.log(" 4. Paste into the Code.gs file in Apps Script editor");
55 console.log(" 5. Save and run setupTriggers()");
56} else {
57 console.log("Usage: bun run gas [build]");
58 console.log("\nCommands:");
59 console.log(" build - Bundle TypeScript to .gs file (default)");
60}