1- import { web } from './esbuild-configs/web.esbuild.js' ;
2- import { desktop } from './esbuild-configs/desktop.esbuild.js' ;
1+ import { web , webTest } from './esbuild-configs/web.esbuild.js' ;
2+ import { desktop , desktopTest } from './esbuild-configs/desktop.esbuild.js' ;
33import * as fs from 'fs' ;
44import chalk from 'chalk' ;
55
@@ -44,6 +44,7 @@ function determineProductionMode() {
4444const production = determineProductionMode ( ) ;
4545const watch = process . argv . includes ( '--watch' ) ;
4646const modeArgIndex = process . argv . indexOf ( '--mode' ) ;
47+ const test = process . argv . includes ( '--test' ) ;
4748const mode = modeArgIndex !== - 1 && process . argv [ modeArgIndex + 1 ] ? process . argv [ modeArgIndex + 1 ] : 'default' ;
4849
4950// Log the build configuration
@@ -53,15 +54,29 @@ if (process.env.NODE_ENV) {
5354}
5455
5556let outDir ;
56- switch ( mode . toLowerCase ( ) ) {
57- case 'web' :
58- outDir = './out/web' ;
59- break ;
60- case 'desktop' :
61- outDir = './out/desktop' ;
62- break ;
63- default :
64- outDir = './out' ;
57+ if ( test ) {
58+ switch ( mode . toLowerCase ( ) ) {
59+ case 'web' :
60+ outDir = [ './out/web/test.js' ] ;
61+ break ;
62+ case 'desktop' :
63+ outDir = [ './out/desktop/test.js' ] ;
64+ break ;
65+ default :
66+ outDir = [ './out/desktop/test.js' , './out/web/test.js' ] ;
67+ break ;
68+ }
69+ } else {
70+ switch ( mode . toLowerCase ( ) ) {
71+ case 'web' :
72+ outDir = [ './out/web/extension.js' ] ;
73+ break ;
74+ case 'desktop' :
75+ outDir = [ './out/desktop/extension.js' ] ;
76+ break ;
77+ default :
78+ outDir = [ './out/desktop/extension.js' , './out/web/extension.js' ] ;
79+ }
6580}
6681if ( fs . existsSync ( outDir ) ) {
6782 console . log ( chalk . yellow ( `🗑️ Output directory ${ outDir } already exists, removing dir...` ) ) ;
@@ -73,38 +88,70 @@ if (fs.existsSync(outDir)) {
7388try {
7489 switch ( mode . toLowerCase ( ) ) {
7590 case 'web' :
76- console . log ( chalk . blue ( `🌐 ${ watch ? 'Watching' : 'Running' } web build...` ) ) ;
77- await web ( production , watch ) . catch ( erm => {
78- console . error ( chalk . red . bold ( `💥 Web build failed: ${ erm } ` ) ) ;
79- process . exit ( 1 ) ;
80- } ) ;
81- console . log ( chalk . green . bold . underline ( '🧰 Web build completed successfully!' ) ) ;
91+ if ( test ) {
92+ console . log ( chalk . blue ( `🌐 ${ watch ? 'Watching' : 'Running' } web test build...` ) ) ;
93+ await webTest ( production , watch ) . catch ( erm => {
94+ console . error ( chalk . red . bold ( `💥 Web test build failed: ${ erm } ` ) ) ;
95+ process . exit ( 1 ) ;
96+ } ) ;
97+ console . log ( chalk . green . bold . underline ( '🧪 Web tests compiled successfully!' ) ) ;
98+ } else {
99+ console . log ( chalk . blue ( `🌐 ${ watch ? 'Watching' : 'Running' } web build...` ) ) ;
100+ await web ( production , watch ) . catch ( erm => {
101+ console . error ( chalk . red . bold ( `💥 Web build failed: ${ erm } ` ) ) ;
102+ process . exit ( 1 ) ;
103+ } ) ;
104+ console . log ( chalk . green . bold . underline ( '🧰 Web build completed successfully!' ) ) ;
105+ }
82106 break ;
83107 case 'desktop' :
84- console . log ( chalk . blue ( `🖥️ ${ watch ? 'Watching' : 'Running' } desktop build...` ) ) ;
85- await desktop ( production , watch ) . catch ( erm => {
86- console . error ( chalk . red . bold ( `💥 Desktop build failed: ${ erm } ` ) ) ;
87- process . exit ( 1 ) ;
88- } ) ;
89- console . log ( chalk . green . bold . underline ( '🧰 Desktop build completed successfully!' ) ) ;
108+ if ( test ) {
109+ console . log ( chalk . blue ( `🖥️ ${ watch ? 'Watching' : 'Running' } desktop test build...` ) ) ;
110+ await desktopTest ( production , watch ) . catch ( erm => {
111+ console . error ( chalk . red . bold ( `💥 Desktop test build failed: ${ erm } ` ) ) ;
112+ process . exit ( 1 ) ;
113+ } ) ;
114+ console . log ( chalk . green . bold . underline ( '🧪 Desktop tests compiled successfully!' ) ) ;
115+ } else {
116+ console . log ( chalk . blue ( `🖥️ ${ watch ? 'Watching' : 'Running' } desktop build...` ) ) ;
117+ await desktop ( production , watch ) . catch ( erm => {
118+ console . error ( chalk . red . bold ( `💥 Desktop build failed: ${ erm } ` ) ) ;
119+ process . exit ( 1 ) ;
120+ } ) ;
121+ console . log ( chalk . green . bold . underline ( '🧰 Desktop build completed successfully!' ) ) ;
122+ }
90123 break ;
91124 case 'default' :
92125 // Can't use watch while building both.
93126 if ( watch ) {
94127 console . error ( chalk . yellow . bold ( '⚠️ Cannot use flag --watch while building both desktop and web' ) ) ;
95128 //process.exit(1); we'll just continue building it normally ig
96129 }
97- console . log ( chalk . blue ( '🖥️ Running desktop build...' ) ) ;
98- await desktop ( production , false ) . catch ( erm => {
99- console . error ( chalk . red . bold ( `💥 Desktop build failed: ${ erm } ` ) ) ;
100- process . exit ( 1 ) ;
101- } ) ;
102- console . log ( chalk . blue ( '🌐 Running web build...' ) ) ;
103- await web ( production , false ) . catch ( erm => {
104- console . error ( chalk . red . bold ( `💥 Web build failed: ${ erm } ` ) ) ;
105- process . exit ( 1 ) ;
106- } ) ;
107- console . log ( chalk . green . bold . underline ( '🎉 Builds completed successfully!' ) ) ;
130+ if ( test ) {
131+ console . log ( chalk . blue ( '🖥️🧪 Running desktop test build...' ) ) ;
132+ await desktopTest ( production , false ) . catch ( erm => {
133+ console . error ( chalk . red . bold ( `💥 Desktop test build failed: ${ erm } ` ) ) ;
134+ process . exit ( 1 ) ;
135+ } ) ;
136+ console . log ( chalk . blue ( '🌐🧪 Running web test build...' ) ) ;
137+ await webTest ( production , false ) . catch ( erm => {
138+ console . error ( chalk . red . bold ( `💥 Web test build failed: ${ erm } ` ) ) ;
139+ process . exit ( 1 ) ;
140+ } ) ;
141+ console . log ( chalk . green . bold . underline ( '🎉🧪 Tests compiled successfully!' ) ) ;
142+ } else {
143+ console . log ( chalk . blue ( '🖥️ Running desktop build...' ) ) ;
144+ await desktop ( production , false ) . catch ( erm => {
145+ console . error ( chalk . red . bold ( `💥 Desktop build failed: ${ erm } ` ) ) ;
146+ process . exit ( 1 ) ;
147+ } ) ;
148+ console . log ( chalk . blue ( '🌐 Running web build...' ) ) ;
149+ await web ( production , false ) . catch ( erm => {
150+ console . error ( chalk . red . bold ( `💥 Web build failed: ${ erm } ` ) ) ;
151+ process . exit ( 1 ) ;
152+ } ) ;
153+ console . log ( chalk . green . bold . underline ( '🎉 Builds completed successfully!' ) ) ;
154+ }
108155 break ;
109156 default :
110157 console . error ( chalk . red . bold ( `❌ Unknown mode: ${ mode } ` ) ) ;
0 commit comments