1- import { readFileSync , writeFileSync } from "node:fs" ;
21import { glob } from "glob" ;
3- import { BuildOptions , OnLoadArgs , Plugin } from "esbuild" ;
4- import { pathClean , stripRelativePath } from "./path" ;
2+ import { BuildOptions } from "esbuild" ;
3+ import { pathClean } from "./path" ;
54
6- const defaultOutdir = "scripts" ;
7- const defaultOutbase = "src" ;
8-
9- const godotTsPlugin : Plugin = {
10- name : "godotTsPlugin" ,
11- setup ( build ) {
12- const absolutePaths : string [ ] = [ ] ;
13- build . onLoad ( { filter : / \. t s $ / } , ( args : OnLoadArgs ) => {
14- absolutePaths . push ( args . path ) ;
15- return undefined ;
16- } ) ;
17- // eslint-disable-next-line @typescript-eslint/no-unused-vars
18- build . onEnd ( async ( _ ) => {
19- const { outdir, outbase, outExtension } = build . initialOptions ;
20- const extension = outExtension ?. [ ".js" ] ?? ".js" ;
21- for ( const filePath of absolutePaths ) {
22- const genFilePath = filePath
23- // Workaround for windows
24- . replaceAll ( "\\" , "/" )
25- . replace ( stripRelativePath ( outbase ) , stripRelativePath ( outdir ) )
26- . replace ( ".ts" , extension ) ;
27- const content = readFileSync ( genFilePath ) ;
28- const genContent = `//generatedPath=${ filePath } \n${ content . toString ( "utf8" ) } ` ;
29- writeFileSync ( genFilePath , genContent ) ;
30- }
31- } ) ;
32- } ,
33- } ;
5+ const defaultOutdir = "./.godot/GodotJS" ;
6+ const defaultOutbase = "." ;
347
358const options : BuildOptions = {
369 format : "cjs" ,
3710 target : "esnext" ,
38- plugins : [ godotTsPlugin ] ,
3911} ;
4012
4113export type ESBuildType = {
@@ -55,9 +27,11 @@ export const getESBuildOptions = async ({
5527 const outdir = pathClean ( out ?? defaultOutdir ) ;
5628
5729 const entryPointsClasses = await glob ( `${ outbase } /**/*.ts` , {
58- ignore : [ `${ outbase } /**/*.bundle.ts` , `${ outbase } /**/*.d.ts` ] ,
30+ ignore : [ `${ outbase } /**/*.bundle.ts` , `**/*.d.ts` , `**/node_modules/**` ] ,
31+ } ) ;
32+ const entryPointsBundle = await glob ( `${ outbase } /**/*.bundle.ts` , {
33+ ignore : [ `**/*.d.ts` , `**/node_modules/**` ] ,
5934 } ) ;
60- const entryPointsBundle = await glob ( `${ outbase } /**/*.bundle.ts` ) ;
6135 const classOptions : BuildOptions = {
6236 entryPoints : entryPointsClasses ,
6337 outExtension : { ".js" : ".js" } ,
0 commit comments