@@ -52,46 +52,55 @@ const nativeNodeModulesPlugin = {
52
52
} ,
53
53
} ;
54
54
55
+ const config = {
56
+ entryPoints : [ "src/bin/cdktf.ts" , "src/bin/cmds/handlers.ts" ] ,
57
+ outbase : "src" ,
58
+ bundle : true ,
59
+ outdir : "./bundle" ,
60
+ format : "cjs" ,
61
+ target : "node14" ,
62
+ minify : enableWatch ? false : true ,
63
+ sourcemap : enableWatch ? false : true ,
64
+ platform : "node" ,
65
+ external : [
66
+ "jsii" ,
67
+ "jsii-pacmak" ,
68
+ "@cdktf/hcl2json" ,
69
+ "@cdktf/hcl-tools" ,
70
+ "yargs" ,
71
+ "cdktf" ,
72
+ "@cdktf/hcl2cdk" ,
73
+ "constructs" ,
74
+ "yoga-layout-prebuilt" ,
75
+ "@cdktf/node-pty-prebuilt-multiarch" ,
76
+ ] ,
77
+ plugins : [ nativeNodeModulesPlugin , {
78
+ name : 'rebuild-log' ,
79
+ setup ( { onStart, onEnd } ) {
80
+ let t ;
81
+ onStart ( ( ) => {
82
+ t = Date . now ( )
83
+ } )
84
+ onEnd ( ( ) => {
85
+ console . log ( 'build finished in' , Date . now ( ) - t , 'ms' )
86
+ } )
87
+ }
88
+ } ] ,
89
+ define : {
90
+ "process.env.SENTRY_DSN" : JSON . stringify ( process . env . SENTRY_DSN || "" ) ,
91
+ } ,
92
+ tsconfig : "tsconfig.json" ,
93
+ } ;
94
+
55
95
( async ( ) => {
56
- await esbuild . build ( {
57
- entryPoints : [ "src/bin/cdktf.ts" , "src/bin/cmds/handlers.ts" ] ,
58
- outbase : "src" ,
59
- bundle : true ,
60
- outdir : "./bundle" ,
61
- format : "cjs" ,
62
- target : "node14" ,
63
- minify : enableWatch ? false : true ,
64
- sourcemap : enableWatch ? false : true ,
65
- watch : enableWatch && {
66
- onRebuild ( error : Error ) {
67
- if ( error ) console . error ( "Watch build failed: " , error ) ;
68
- else console . log ( "Rebuilt" , new Date ( ) . toTimeString ( ) ) ;
69
- } ,
70
- } ,
71
- platform : "node" ,
72
- external : [
73
- "jsii" ,
74
- "jsii-pacmak" ,
75
- "@cdktf/hcl2json" ,
76
- "@cdktf/hcl-tools" ,
77
- "yargs" ,
78
- "cdktf" ,
79
- "@cdktf/hcl2cdk" ,
80
- "constructs" ,
81
- "yoga-layout-prebuilt" ,
82
- "@cdktf/node-pty-prebuilt-multiarch" ,
83
- ] ,
84
- plugins : [ nativeNodeModulesPlugin ] ,
85
- define : {
86
- "process.env.SENTRY_DSN" : JSON . stringify ( process . env . SENTRY_DSN ) ,
87
- } ,
88
- tsconfig : "tsconfig.json" ,
89
- } ) ;
96
+ console . log ( "Building…" ) ;
97
+ await esbuild . build ( config ) ;
98
+ fs . copySync ( "src/bin/cdktf" , "./bundle/bin/cdktf" ) ;
99
+ fs . copySync ( "../@cdktf/cli-core/templates" , "./bundle/templates" ) ;
90
100
91
101
if ( enableWatch ) {
102
+ const ctx = await esbuild . context ( config ) ;
92
103
console . log ( "Watching…" ) ;
104
+ await ctx . watch ( ) ;
93
105
}
94
-
95
- fs . copySync ( "src/bin/cdktf" , "./bundle/bin/cdktf" ) ;
96
- fs . copySync ( "../@cdktf/cli-core/templates" , "./bundle/templates" ) ;
97
106
} ) ( ) ;
0 commit comments