11#!/usr/bin/env node
22
33const { execSync } = require ( 'child_process' ) ;
4+ const fs = require ( 'fs' ) ;
45const path = require ( 'path' ) ;
56
67console . log ( '📦 Publishing JetStart packages to npm...\n' ) ;
@@ -11,12 +12,35 @@ const packages = [
1112 { name : '@jetstart/cli' , dir : 'packages/cli' }
1213] ;
1314
15+ // Get the current version from root package.json
16+ const rootPkg = JSON . parse ( fs . readFileSync ( path . join ( __dirname , '../package.json' ) , 'utf8' ) ) ;
17+ const version = rootPkg . version ;
18+
1419for ( const pkg of packages ) {
1520 console . log ( `\n🚀 Publishing ${ pkg . name } ...` ) ;
1621
1722 try {
1823 const pkgPath = path . join ( __dirname , '..' , pkg . dir ) ;
24+ const pkgJsonPath = path . join ( pkgPath , 'package.json' ) ;
25+
26+ // Read package.json
27+ const pkgJson = JSON . parse ( fs . readFileSync ( pkgJsonPath , 'utf8' ) ) ;
28+ const originalPkgJson = JSON . stringify ( pkgJson , null , 2 ) ;
29+
30+ // Replace file: dependencies with version numbers
31+ if ( pkgJson . dependencies ) {
32+ for ( const [ depName , depVersion ] of Object . entries ( pkgJson . dependencies ) ) {
33+ if ( depVersion . startsWith ( 'file:' ) ) {
34+ pkgJson . dependencies [ depName ] = `^${ version } ` ;
35+ console . log ( ` → Updated ${ depName } : ${ depVersion } → ^${ version } ` ) ;
36+ }
37+ }
38+ }
1939
40+ // Write updated package.json
41+ fs . writeFileSync ( pkgJsonPath , JSON . stringify ( pkgJson , null , 2 ) + '\n' ) ;
42+
43+ // Publish
2044 execSync ( 'npm publish --access public' , {
2145 cwd : pkgPath ,
2246 stdio : 'inherit' ,
@@ -26,6 +50,9 @@ for (const pkg of packages) {
2650 }
2751 } ) ;
2852
53+ // Restore original package.json
54+ fs . writeFileSync ( pkgJsonPath , originalPkgJson + '\n' ) ;
55+
2956 console . log ( `✅ Successfully published ${ pkg . name } ` ) ;
3057 } catch ( error ) {
3158 console . error ( `❌ Failed to publish ${ pkg . name } ` ) ;
0 commit comments