| 9 | const __dirname = path.dirname(__filename) |
| 10 | |
| 11 | async function main() { |
| 12 | const name = "extension-nightly" |
| 13 | const production = process.argv.includes("--production") |
| 14 | const minify = production |
| 15 | const sourcemap = !production |
| 16 | |
| 17 | const overrideJson = JSON.parse(fs.readFileSync(path.join(__dirname, "package.nightly.json"), "utf8")) |
| 18 | console.log(`[${name}] name: ${overrideJson.name}`) |
| 19 | console.log(`[${name}] version: ${overrideJson.version}`) |
| 20 | |
| 21 | const gitSha = getGitSha() |
| 22 | console.log(`[${name}] gitSha: ${gitSha}`) |
| 23 | |
| 24 | /** |
| 25 | * @type {import('esbuild').BuildOptions} |
| 26 | */ |
| 27 | const buildOptions = { |
| 28 | bundle: true, |
| 29 | minify, |
| 30 | sourcemap, |
| 31 | logLevel: "silent", |
| 32 | format: "cjs", |
| 33 | sourcesContent: false, |
| 34 | platform: "node", |
| 35 | define: { |
| 36 | "process.env.PKG_NAME": '"zoo-code-nightly"', |
| 37 | "process.env.PKG_VERSION": `"${overrideJson.version}"`, |
| 38 | "process.env.PKG_OUTPUT_CHANNEL": '"Zoo-Code-Nightly"', |
| 39 | "process.env.PKG_RELEASE_CHANNEL": '"prerelease"', |
| 40 | "process.env.POSTHOG_API_KEY": JSON.stringify(process.env.POSTHOG_API_KEY || ""), |
| 41 | ...(gitSha ? { "process.env.PKG_SHA": `"${gitSha}"` } : {}), |
| 42 | }, |
| 43 | } |
| 44 | |
| 45 | const srcDir = path.join(__dirname, "..", "..", "src") |
| 46 | const buildDir = path.join(__dirname, "build") |
| 47 | const distDir = path.join(buildDir, "dist") |
| 48 | |
| 49 | console.log(`[${name}] srcDir: ${srcDir}`) |
| 50 | console.log(`[${name}] buildDir: ${buildDir}`) |
| 51 | console.log(`[${name}] distDir: ${distDir}`) |
| 52 | |
| 53 | if (fs.existsSync(distDir)) { |
| 54 | console.log(`[${name}] Cleaning dist directory: ${distDir}`) |
| 55 | fs.rmSync(distDir, { recursive: true, force: true }) |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * @type {import('esbuild').Plugin[]} |
| 60 | */ |
| 61 | const plugins = [ |
| 62 | { |
| 63 | name: "copyPaths", |
| 64 | setup(build) { |
| 65 | build.onEnd(() => { |
| 66 | copyPaths( |
| 67 | [ |
| 68 | ["../README.md", "README.md"], |