1+ import { readFile , writeFile } from 'fs' ;
2+ import { execSync } from "child_process" ;
3+ // Define the package semver and app version
4+ const packageSemver = "3.0.1" ; // Replace with your desired package semver
5+ const appVersion = "1.8.4" ; // Replace with your desired app version
6+
7+ // Paths to the JSON files
8+ const versionsFilePath = './versions.json' ;
9+ const manifestFilePath = './manifest.json' ;
10+ const packageFilePath = './package.json' ;
11+
12+ // Function to update versions.json
13+ function updateVersionsFile ( ) {
14+ readFile ( versionsFilePath , 'utf8' , ( err , data ) => {
15+ if ( err ) {
16+ console . error ( 'Error reading versions.json:' , err ) ;
17+ return ;
18+ }
19+
20+ try {
21+ const versions = JSON . parse ( data ) ;
22+ versions [ packageSemver ] = appVersion ;
23+
24+ const updatedJson = JSON . stringify ( versions , null , '\t' ) ;
25+ writeFile ( versionsFilePath , updatedJson , 'utf8' , ( writeErr ) => {
26+ if ( writeErr ) {
27+ console . error ( 'Error writing to versions.json:' , writeErr ) ;
28+ } else {
29+ console . log ( `Successfully added "${ packageSemver } : ${ appVersion } " to versions.json` ) ;
30+ }
31+ } ) ;
32+ } catch ( parseErr ) {
33+ console . error ( 'Error parsing versions.json:' , parseErr ) ;
34+ }
35+ } ) ;
36+ }
37+
38+ // Function to update manifest.json
39+ function updateManifestFile ( ) {
40+ readFile ( manifestFilePath , 'utf8' , ( err , data ) => {
41+ if ( err ) {
42+ console . error ( 'Error reading manifest.json:' , err ) ;
43+ return ;
44+ }
45+
46+ try {
47+ const manifest = JSON . parse ( data ) ;
48+ manifest . version = packageSemver ; // Update the version field
49+ manifest . minAppVersion = appVersion ; // Update the minAppVersion field
50+
51+ const updatedJson = JSON . stringify ( manifest , null , '\t' ) ;
52+ writeFile ( manifestFilePath , updatedJson , 'utf8' , ( writeErr ) => {
53+ if ( writeErr ) {
54+ console . error ( 'Error writing to manifest.json:' , writeErr ) ;
55+ } else {
56+ console . log ( `Successfully updated manifest.json: version="${ packageSemver } ", minAppVersion="${ appVersion } "` ) ;
57+ }
58+ } ) ;
59+ } catch ( parseErr ) {
60+ console . error ( 'Error parsing manifest.json:' , parseErr ) ;
61+ }
62+ } ) ;
63+ }
64+ // Function to update package.json
65+ function updatePackageJsonFile ( ) {
66+ readFile ( packageFilePath , 'utf8' , ( err , data ) => {
67+ if ( err ) {
68+ console . error ( 'Error reading package.json:' , err ) ;
69+ return ;
70+ }
71+
72+ try {
73+ const packageJson = JSON . parse ( data ) ;
74+ packageJson . version = packageSemver ; // Update the version field
75+
76+ const updatedJson = JSON . stringify ( packageJson , null , '\t' ) ;
77+ writeFile ( packageFilePath , updatedJson , 'utf8' , ( writeErr ) => {
78+ if ( writeErr ) {
79+ console . error ( 'Error writing to package.json:' , writeErr ) ;
80+ } else {
81+ console . log ( `Successfully updated package.json: version="${ packageSemver } "` ) ;
82+ }
83+ } ) ;
84+ } catch ( parseErr ) {
85+ console . error ( 'Error parsing manifest.json:' , parseErr ) ;
86+ }
87+ } ) ;
88+ }
89+
90+ // Function to perform Git operations
91+ function gitCommitAndTag ( ) {
92+ try {
93+ // Stage all changes
94+ execSync ( 'git add .' ) ;
95+ console . log ( 'Successfully staged all changes.' ) ;
96+
97+ // Commit with the packageSemver as the message
98+ execSync ( `git commit -m "v${ packageSemver } "` ) ;
99+ console . log ( `Successfully committed changes with message: "v${ packageSemver } ".` ) ;
100+
101+ // Create a Git tag with the packageSemver
102+ execSync ( `git tag v${ packageSemver } ` ) ;
103+ console . log ( `Successfully created Git tag: v${ packageSemver } .` ) ;
104+
105+ console . log ( 'Bump process completed successfully!' ) ;
106+ } catch ( gitErr ) {
107+ console . error ( 'Error during Git operations:' , gitErr . message || gitErr ) ;
108+ }
109+ }
110+
111+ // Run both functions
112+ updateVersionsFile ( ) ;
113+ updateManifestFile ( ) ;
114+ updatePackageJsonFile ( ) ;
115+ gitCommitAndTag ( ) ;
0 commit comments