-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathesbuild.ts
More file actions
240 lines (219 loc) · 6.67 KB
/
Copy pathesbuild.ts
File metadata and controls
240 lines (219 loc) · 6.67 KB
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
/// <reference lib="deno.ns" />
import * as esbuild from "esbuild";
import { denoPlugin, } from "@deno/esbuild-plugin";
import {
buildEsbuildOptions,
copyStaticFiles,
currentVersion,
incrementVersion,
listAssetsForCache,
parseArgs,
processTarget,
} from "@syntaxmesh/utils/build";
import type { GlobalTargetConfig, } from "@syntaxmesh/utils/interfaces";
const DENO_JSONC_PATH = "deno.jsonc";
// ============================================================================
// 🔌 WRAPPER ESBUILD COM PLUGIN DENO
// ============================================================================
// deno-lint-ignore no-explicit-any
const buildWithDenoPlugin = (options: any,): Promise<any> => {
options.plugins = [
...(options.plugins || []),
denoPlugin({ "configPath": DENO_JSONC_PATH, },),
];
return esbuild.build(options,);
};
// ============================================================================
// 📦 CONFIGURAÇÃO DECLARATIVA DE BUILDS (específica do SyntaxMesh)
// ============================================================================
const CONFIG: GlobalTargetConfig = {
// ------------------------------------------------------------------
// 🎯 ALVOS DE BUILD (rodam por padrão)
// ------------------------------------------------------------------
ui: {
mode: "build",
default: true,
srcdir: "packages/ui/src",
distdir: "packages/server/build/dist",
publicdir: "packages/ui/public",
indexHtml: true,
clean: [".",],
entryPoints: ["app.tsx",],
platform: "browser",
format: "esm",
bundle: true,
minify: false,
sourcemap: "linked",
conditions: ["browser",],
drop: ["debugger",],
jsx: "automatic",
jsxImportSource: "preact",
metafile: true,
write: true,
legalComments: "none",
keepNames: true,
splitting: false,
banner: {
js: `/* SyntaxMesh v__APP_VERSION__ */\n`,
},
},
workerdb: {
mode: "build",
default: true,
srcdir: "packages/worker-db/src",
distdir: "packages/server/build/dist",
clean: ["worker-db.js", "worker-db.js.map",],
entryPoints: ["worker.ts",],
platform: "browser",
format: "esm",
bundle: true,
minify: false,
sourcemap: "linked",
drop: ["debugger",],
conditions: ["worker",],
metafile: true,
write: true,
legalComments: "none",
keepNames: true,
splitting: false,
banner: {
js: `/* SyntaxMesh v__APP_VERSION__ */\n`,
},
},
sw: {
mode: "build",
default: true,
srcdir: "packages/service-worker/src",
distdir: "packages/server/build/dist",
clean: ["service-worker.js", "service-worker.js.map",],
entryPoints: ["service-worker.ts",],
platform: "browser",
format: "esm",
bundle: true,
minify: false,
sourcemap: "linked",
drop: ["debugger",],
conditions: ["worker",],
metafile: true,
write: true,
legalComments: "none",
keepNames: true,
splitting: false,
banner: {
js: `/* SyntaxMesh v__APP_VERSION__ */\n`,
},
},
// ------------------------------------------------------------------
// 👀 ALVOS WATCH (modo de desenvolvimento contínuo)
// ------------------------------------------------------------------
"watch": {
mode: "watch",
default: false,
srcdir: "packages/ui/src",
distdir: "packages/server/build/dist",
publicdir: "packages/ui/public",
indexHtml: true,
entryPoints: ["app.tsx",],
platform: "browser",
format: "esm",
bundle: true,
minify: false,
sourcemap: "inline",
conditions: ["browser",],
jsx: "automatic",
jsxImportSource: "preact",
write: true,
legalComments: "none",
// 🔥 CORREÇÃO: outfile agora é RELATIVO ao distdir
outfile: "app.js",
banner: {
js: `/* SyntaxMesh v__APP_VERSION__ */\n`,
},
},
};
// ============================================================================
// 🚀 PIPELINE PRINCIPAL
// ============================================================================
async function build() {
const start = performance.now();
const { targets, globalNoVersion, watchTarget, } = parseArgs(
Deno.args,
CONFIG,
);
console.log(
"\n🚀 Iniciando Orquestrador de Build SyntaxMesh (esbuild nativo + @deno/esbuild-plugin)",
);
if (watchTarget) {
console.log(`👀 Modo Watch ativo: ${watchTarget}`,);
} else {
console.log(
`📋 Alvos de build (ordem segura do CONFIG): ${
targets.join(", ",) || "(nenhum)"
}`,
);
}
console.log(`🔒 Noversion: ${globalNoVersion}\n`,);
try {
const currentVer = await currentVersion(DENO_JSONC_PATH,);
if (watchTarget) {
await startWatchMode(watchTarget, currentVer,);
return;
}
const finalVersion = globalNoVersion
? currentVer
: await incrementVersion(currentVer, DENO_JSONC_PATH,);
for (const targetName of targets) {
const targetConfig = CONFIG[targetName];
if (!targetConfig) {
console.warn(
`⚠️ Alvo '${targetName}' não encontrado no CONFIG. Pulando.`,
);
continue;
}
await processTarget(
targetName,
targetConfig,
finalVersion,
buildWithDenoPlugin,
listAssetsForCache,
);
}
console.log(`\n${"=".repeat(60,)}`,);
console.log(`🎉 ORQUESTRAÇÃO CONCLUÍDA COM SUCESSO!`,);
console.log(`${"=".repeat(60,)}`,);
} catch (error) {
console.error("\n🛑 Pipeline de build falhou:", error,);
Deno.exit(1,);
} finally {
const elapsed = (performance.now() - start).toFixed(0,);
console.log(`\n⏱️ Tempo total: ${elapsed}ms\n`,);
}
}
async function startWatchMode(watchTargetName: string, currentVer: string,) {
const config = CONFIG[watchTargetName];
if (!config) {
throw new Error(
`❌ Alvo watch '${watchTargetName}' não encontrado no CONFIG`,
);
}
console.log(`\n👀 Iniciando Watch Mode: ${watchTargetName}\n`,);
await copyStaticFiles(config, currentVer,);
const esbuildOptions = await buildEsbuildOptions(
watchTargetName,
config,
currentVer,
);
esbuildOptions.plugins = [...(esbuildOptions.plugins || []), denoPlugin(),];
const ctx = await esbuild.context(esbuildOptions,);
await ctx.watch();
console.log("\n✅ Watch mode ativo!",);
console.log(`📁 Monitorando: ${config.srcdir}/`,);
// 🔥 CORREÇÃO: Mostra o outfile resolvido (relativo ao distdir)
const resolvedOutfile = esbuildOptions.outfile ||
(config.distdir ? `${config.distdir}/` : "N/A");
console.log(`📦 Output: ${resolvedOutfile}`,);
console.log(`📌 Versão: v${currentVer}`,);
console.log("\n💡 Pressione Ctrl+C para parar.\n",);
await new Promise(() => {},);
}
await build();