1+ /*-----------------------------------------------------------------------------------------------
2+ * Copyright (c) Red Hat, Inc. All rights reserved.
3+ * Licensed under the MIT License. See LICENSE file in the project root for license information.
4+ *-----------------------------------------------------------------------------------------------*/
5+
6+ const { execSync } = require ( 'child_process' ) ;
7+ const esbuild = require ( 'esbuild' ) ;
8+ const { esmAliasPlugin, esbuildProblemMatcherPlugin, nativeNodeModulesPlugin, svgrPlugin, verbosePlugin } = require ( './esbuild.plugins.cjs' ) ;
9+ const { webviews, srcDir, outDir } = require ( './esbuild.settings.cjs' ) ;
10+ const { sassPlugin } = require ( 'esbuild-sass-plugin' ) ;
11+ const { cp, mkdir, stat } = require ( 'node:fs/promises' ) ;
12+ const path = require ( 'path' ) ;
13+ const { sync } = require ( 'fast-glob' ) ;
14+ const { buildWebviews } = require ( './esbuild.webviews.cjs' ) ;
15+
16+ const production = process . argv . includes ( '--production' ) ;
17+
18+ // eslint-disable no-console
19+
20+ // Run type-checking
21+
22+ /// Verify the extension
23+ try {
24+ // execSync('tsc --noEmit', { stdio: 'inherit' });
25+ execSync ( 'tsc --noEmit -p tsconfig.json' , { stdio : 'inherit' } ) ;
26+ } catch ( err ) {
27+ console . error ( '❌ TypeScript type-checking failed.' ) ;
28+ process . exit ( 1 ) ;
29+ }
30+
31+ console . log ( `esbuild: building for production: ${ production ? 'Yes' : 'No' } ` ) ;
32+
33+ const baseConfig = {
34+ bundle : true ,
35+ target : 'chrome108' ,
36+ minify : production ,
37+ sourcemap : ! production ,
38+ logLevel : 'warning' ,
39+ } ;
40+
41+ async function buildExtension ( ) {
42+ console . log ( `📦 Building the extension for ${ production ? 'Production' : 'Development' } ...` ) ;
43+
44+ if ( production ) {
45+ // Build the extension.js
46+ const extConfig = {
47+ ...baseConfig ,
48+ platform : 'node' ,
49+ format : 'cjs' ,
50+ entryPoints : [ `./${ srcDir } /extension.ts` ] ,
51+ outfile : `${ outDir } /${ srcDir } /extension.js` ,
52+ external : [ 'vscode' , 'shelljs' , 'jsonc-parser' ] ,
53+ plugins : [
54+ nativeNodeModulesPlugin ( ) ,
55+ esbuildProblemMatcherPlugin ( production ) // this one is to be added to the end of plugins array
56+ ]
57+ } ;
58+ await esbuild . build ( extConfig ) ;
59+ console . log ( '✅ Extension build completed' ) ;
60+ } else {
61+ // Build the Extension for development
62+ const srcFiles = sync ( `${ srcDir } /**/*.{js,ts}` , { absolute : false } ) ;
63+ const devExtConfig = {
64+ ...baseConfig ,
65+ platform : 'node' ,
66+ format : 'cjs' ,
67+ entryPoints : srcFiles . map ( f => `./${ f } ` ) ,
68+ outbase : srcDir ,
69+ outdir : `${ outDir } /${ srcDir } ` ,
70+ external : [ 'vscode' , 'shelljs' , 'jsonc-parser' , '@aws-sdk/client-s3' ] ,
71+ plugins : [
72+ // verbosePlugin(),
73+ esmAliasPlugin ( ) ,
74+ nativeNodeModulesPlugin ( ) ,
75+ esbuildProblemMatcherPlugin ( production ) // this one is to be added to the end of plugins array
76+ ]
77+ } ;
78+
79+ await esbuild . build ( devExtConfig ) ;
80+
81+ const jsonFiles = sync ( 'src/**/*.json' , { absolute : false } ) ;
82+ for ( const file of jsonFiles ) {
83+ const dest = path . join ( 'out' , file ) ;
84+ await cp ( file , dest , { recursive : false , force : true } ) ;
85+ }
86+ await cp ( 'package.json' , 'out/package.json' ) ;
87+ console . log ( '✅ Extension build completed' ) ;
88+ }
89+ }
90+
91+ async function buildAll ( ) {
92+ await buildExtension ( ) ;
93+ await buildWebviews ( ) ;
94+ }
95+
96+ buildAll ( ) . catch ( err => {
97+ console . error ( '❌ Build failed:' , err ) ;
98+ process . exit ( 1 ) ;
99+ } ) ;
0 commit comments