@@ -10,9 +10,11 @@ const execAsync = promisify(exec);
1010
1111// Helper function to load JSON
1212const loadJsonFile = ( filePath ) => {
13- return JSON . parse ( readFileSync ( filePath , { encoding : 'utf8' } ) ) ;
13+ const file = readFileSync ( filePath , { encoding : 'utf8' } ) ;
14+ return ( file ) ? JSON . parse ( file ) : { } ;
1415} ;
1516
17+
1618// Get the current version from npm
1719const getCurrentVersionFromNpm = async ( packageName ) => {
1820 try {
@@ -24,6 +26,29 @@ const getCurrentVersionFromNpm = async (packageName) => {
2426 process . exit ( 1 ) ;
2527 }
2628} ;
29+ // Load the main package.json to determine the version to set
30+ const mainPackageJsonPath = join ( process . cwd ( ) , 'package.json' ) ;
31+ const mainPackageJson = loadJsonFile ( mainPackageJsonPath ) ;
32+ const versionArg = process . argv [ 2 ] ;
33+ const dryRun = process . argv . includes ( '--dry-run' ) ;
34+ const ciOverride = process . argv . includes ( '--ci' ) ;
35+
36+ let npmVersion = await getCurrentVersionFromNpm ( mainPackageJson . name ) ;
37+ let newVersion = mainPackageJson . version ;
38+
39+ const updatedFiles = [ ] ;
40+
41+
42+ // Update the version in the main package.json if a new version is set
43+ mainPackageJson . version = newVersion ;
44+ updateDependencyVersions ( mainPackageJson , newVersion ) ; // Update dependency versions
45+ if ( ! dryRun ) {
46+ writeFileSync ( mainPackageJsonPath , JSON . stringify ( mainPackageJson , null , 2 ) + '\n' ) ;
47+ }
48+ console . log ( `Updated main package version to ${ newVersion } ` ) ;
49+ updatedFiles . push ( mainPackageJsonPath ) ;
50+
51+
2752
2853// determine if this dependency should have its version number updated
2954const isUpdateableDep = function ( dep ) {
@@ -32,7 +57,7 @@ const isUpdateableDep = function(dep) {
3257 return false ;
3358 }
3459 return dep . startsWith ( '@semantic-ui/' ) ;
35- }
60+ } ;
3661
3762// Function to update dependency versions in package.json
3863function updateDependencyVersions ( packageJson , newVersion ) {
@@ -43,7 +68,7 @@ function updateDependencyVersions(packageJson, newVersion) {
4368 const depVersion = `^${ newVersion } ` ;
4469 if ( isUpdateableDep ( dep ) && packageJson [ depType ] [ dep ] !== depVersion ) { // Simple scope check
4570 packageJson [ depType ] [ dep ] = depVersion ;
46- console . log ( `Updated ${ dep } in ${ packageJson . name } to ${ depVersion } ` )
71+ console . log ( `Updated ${ dep } in ${ packageJson . name } to ${ depVersion } ` ) ;
4772 }
4873 } ) ;
4974 }
@@ -107,29 +132,6 @@ async function updatePackageVersion(dir) {
107132 }
108133}
109134
110- // Load the main package.json to determine the version to set
111- const mainPackageJsonPath = join ( process . cwd ( ) , 'package.json' ) ;
112- const mainPackageJson = loadJsonFile ( mainPackageJsonPath ) ;
113- const versionArg = process . argv [ 2 ] ;
114- const dryRun = process . argv . includes ( '--dry-run' ) ;
115- const ciOverride = process . argv . includes ( '--ci' ) ;
116-
117- let npmVersion = await getCurrentVersionFromNpm ( mainPackageJson . name ) ;
118- let newVersion = mainPackageJson . version ;
119-
120- const updatedFiles = [ ] ;
121-
122- // Update the version in the main package.json if a new version is set
123- mainPackageJson . version = newVersion ;
124- updateDependencyVersions ( mainPackageJson , newVersion ) ; // Update dependency versions
125- if ( ! dryRun ) {
126- writeFileSync ( mainPackageJsonPath , JSON . stringify ( mainPackageJson , null , 2 ) + '\n' ) ;
127- }
128- console . log ( `Updated main package version to ${ newVersion } ` ) ;
129- updatedFiles . push ( mainPackageJsonPath ) ;
130-
131-
132-
133135// Read workspaces to publish from main package
134136// ignoring internal packages
135137const workspaceGlobs = mainPackageJson . workspaces . filter ( val => ! val . includes ( 'internal-packages' ) ) ;
0 commit comments