@@ -53,16 +53,34 @@ function runQuiet(command, cwd) {
5353 }
5454}
5555
56+ function findTarball ( ) {
57+ const files = fs . readdirSync ( rootDir ) . filter ( f => f . startsWith ( 'optimizely-optimizely-sdk-' ) && f . endsWith ( '.tgz' ) ) ;
58+ if ( files . length === 0 ) {
59+ console . error ( 'No SDK tarball found. Run `npm pack` first.' ) ;
60+ process . exit ( 1 ) ;
61+ }
62+ return path . join ( rootDir , files [ 0 ] ) ;
63+ }
64+
5665function main ( ) {
66+ const skipBuild = process . argv . includes ( '--skip-build' ) ;
67+
5768 console . log ( '=== Building SDK and Running CommonJS Example ===\n' ) ;
5869
59- console . log ( 'Installing SDK dependencies...' ) ;
60- run ( 'npm install' , rootDir ) ;
70+ let tarballPath ;
71+
72+ if ( skipBuild ) {
73+ console . log ( 'Skipping build (--skip-build), using existing tarball...' ) ;
74+ tarballPath = findTarball ( ) ;
75+ } else {
76+ console . log ( 'Installing SDK dependencies...' ) ;
77+ run ( 'npm install' , rootDir ) ;
6178
62- console . log ( '\nPacking SDK tarball...' ) ;
63- const packOutput = runQuiet ( 'npm pack' , rootDir ) ;
64- const tarballPath = path . join ( rootDir , packOutput ) ;
65- console . log ( `Created: ${ packOutput } ` ) ;
79+ console . log ( '\nPacking SDK tarball...' ) ;
80+ const packOutput = runQuiet ( 'npm pack' , rootDir ) ;
81+ tarballPath = path . join ( rootDir , packOutput ) ;
82+ console . log ( `Created: ${ packOutput } ` ) ;
83+ }
6684
6785 console . log ( '\nInstalling SDK tarball in cjs-example...' ) ;
6886 run ( `npm install --no-save --no-package-lock ${ tarballPath } ` , exampleDir ) ;
@@ -72,7 +90,7 @@ function main() {
7290
7391 console . log ( '\nCleaning up tarball...' ) ;
7492 fs . unlinkSync ( tarballPath ) ;
75- console . log ( `Removed: ${ packOutput } ` ) ;
93+ console . log ( `Removed: ${ path . basename ( tarballPath ) } ` ) ;
7694
7795 console . log ( '\n=== Example completed successfully! ===\n' ) ;
7896}
0 commit comments