1- import { readFile , writeFile } from ' fs/promises' ; // Use promises version of fs methods
1+ import { readFile , writeFile } from " fs/promises" ; // Use promises version of fs methods
22import { execSync } from "child_process" ;
3- import chalk from "chalk" ; //chalk commonJs
3+ import chalk from "chalk" ; //chalk commonJs
44import type { ForegroundColorName , BackgroundColorName } from "chalk" ;
5- type Msg = [ string , ForegroundColorName | ' white' , BackgroundColorName | null ] ;
5+ type Msg = [ string , ForegroundColorName | " white" , BackgroundColorName | null ] ;
66
77// Define the package semver and app version
8- const packageSemver = "3.0.3 " ; // Replace with your desired package semver
9- const appVersion = "1.8.4" ; // Replace with your desired app version
8+ const packageSemver = "3.0.4 " ; // Replace with your desired package semver
9+ const appVersion = "1.8.4" ; // Replace with your desired app version
1010
1111// Paths to the JSON files
12- const versionsFilePath = ' ./versions.json' ;
13- const manifestFilePath = ' ./manifest.json' ;
14- const packageFilePath = ' ./package.json' ;
12+ const versionsFilePath = " ./versions.json" ;
13+ const manifestFilePath = " ./manifest.json" ;
14+ const packageFilePath = " ./package.json" ;
1515
1616// Function to update versions.json
1717async function updateVersionsFile ( ) {
18- try {
19- const data = await readFile ( versionsFilePath , 'utf8' ) ;
20- const versions = JSON . parse ( data ) ;
21- versions [ packageSemver ] = appVersion ;
22- const updatedJson = JSON . stringify ( versions , null , '\t' ) ;
23- await writeFile ( versionsFilePath , updatedJson , 'utf8' ) ;
24- console . log ( logInsert ( [ `>> added "${ packageSemver } : ${ appVersion } " to versions.json. ✓✓` , "blue" , null ] ) ) ;
25- } catch ( err ) {
26- console . error ( 'Error updating versions.json:' , err ) ;
27- }
18+ try {
19+ const data = await readFile ( versionsFilePath , "utf8" ) ;
20+ const versions = JSON . parse ( data ) ;
21+ versions [ packageSemver ] = appVersion ;
22+ const updatedJson = JSON . stringify ( versions , null , "\t" ) ;
23+ await writeFile ( versionsFilePath , updatedJson , "utf8" ) ;
24+ console . log (
25+ logInsert ( [
26+ `>> added "${ packageSemver } : ${ appVersion } " to versions.json. ✓✓` ,
27+ "blue" ,
28+ null ,
29+ ] ) ,
30+ ) ;
31+ } catch ( err ) {
32+ console . error ( "Error updating versions.json:" , err ) ;
33+ }
2834}
2935
3036// Function to update manifest.json
3137async function updateManifestFile ( ) {
32- try {
33- const data = await readFile ( manifestFilePath , 'utf8' ) ;
34- const manifest = JSON . parse ( data ) ;
35- manifest . version = packageSemver ; // Update the version field
36- manifest . minAppVersion = appVersion ; // Update the minAppVersion field
37- const updatedJson = JSON . stringify ( manifest , null , '\t' ) ;
38- await writeFile ( manifestFilePath , updatedJson , 'utf8' ) ;
39- console . log ( logInsert ( [ `>> updated manifest.json: version="${ packageSemver } ", minAppVersion="${ appVersion } ". ✓✓` , "blue" , null ] ) ) ;
40- } catch ( err ) {
41- console . error ( 'Error updating manifest.json:' , err ) ;
42- }
38+ try {
39+ const data = await readFile ( manifestFilePath , "utf8" ) ;
40+ const manifest = JSON . parse ( data ) ;
41+ manifest . version = packageSemver ; // Update the version field
42+ manifest . minAppVersion = appVersion ; // Update the minAppVersion field
43+ const updatedJson = JSON . stringify ( manifest , null , "\t" ) ;
44+ await writeFile ( manifestFilePath , updatedJson , "utf8" ) ;
45+ console . log (
46+ logInsert ( [
47+ `>> updated manifest.json: version="${ packageSemver } ", minAppVersion="${ appVersion } ". ✓✓` ,
48+ "blue" ,
49+ null ,
50+ ] ) ,
51+ ) ;
52+ } catch ( err ) {
53+ console . error ( "Error updating manifest.json:" , err ) ;
54+ }
4355}
4456
4557// Function to update package.json
4658async function updatePackageJsonFile ( ) {
47- try {
48- const data = await readFile ( packageFilePath , 'utf8' ) ;
49- const packageJson = JSON . parse ( data ) ;
50- packageJson . version = packageSemver ; // Update the version field
51- const updatedJson = JSON . stringify ( packageJson , null , '\t' ) ;
52- await writeFile ( packageFilePath , updatedJson , 'utf8' ) ;
53- console . log ( logInsert ( [ `>> updated package.json: version="${ packageSemver } . ✓✓"` , "blue" , null ] ) ) ;
54- } catch ( err ) {
55- console . error ( 'Error updating package.json:' , err ) ;
56- }
59+ try {
60+ const data = await readFile ( packageFilePath , "utf8" ) ;
61+ const packageJson = JSON . parse ( data ) ;
62+ packageJson . version = packageSemver ; // Update the version field
63+ const updatedJson = JSON . stringify ( packageJson , null , "\t" ) ;
64+ await writeFile ( packageFilePath , updatedJson , "utf8" ) ;
65+ console . log (
66+ logInsert ( [
67+ `>> updated package.json: version="${ packageSemver } . ✓✓"` ,
68+ "blue" ,
69+ null ,
70+ ] ) ,
71+ ) ;
72+ } catch ( err ) {
73+ console . error ( "Error updating package.json:" , err ) ;
74+ }
5775}
5876
5977// Function to perform Git operations
6078function gitCommitAndTag ( ) {
61- try {
62- // Stage all changes
63- execSync ( 'git add .' ) ;
64- console . log ( ) ;
65- console . log ( logInsert ( [ '-- staged all changes. ✓✓' , "greenBright" , null ] ) ) ;
66- // Commit with the packageSemver as the message
67- execSync ( `git commit -m "v${ packageSemver } "` ) ;
68- console . log ( logInsert ( [ `-- committed changes with message: "v${ packageSemver } ". ✓✓` , "greenBright" , null ] ) ) ;
79+ try {
80+ // Stage all changes
81+ execSync ( "git add ." ) ;
82+ console . log ( ) ;
83+ console . log ( logInsert ( [ "-- staged all changes. ✓✓" , "greenBright" , null ] ) ) ;
84+ // Commit with the packageSemver as the message
85+ execSync ( `git commit -m "v${ packageSemver } "` ) ;
86+ console . log (
87+ logInsert ( [
88+ `-- committed changes with message: "v${ packageSemver } ". ✓✓` ,
89+ "greenBright" ,
90+ null ,
91+ ] ) ,
92+ ) ;
6993
70- // Create a Git tag with the packageSemver
71- execSync ( `git tag ${ packageSemver } ` ) ;
72- console . log ( logInsert ( [ `-- created Git tag: ${ packageSemver } . ✓✓` , "greenBright" , null ] ) ) ;
73- console . log ( ) ;
74-
75- } catch ( gitErr ) {
76- console . error ( 'Error during Git operations:' , gitErr . message || gitErr ) ;
77- }
94+ // Create a Git tag with the packageSemver
95+ execSync ( `git tag ${ packageSemver } ` ) ;
96+ console . log (
97+ logInsert ( [
98+ `-- created Git tag: ${ packageSemver } . ✓✓` ,
99+ "greenBright" ,
100+ null ,
101+ ] ) ,
102+ ) ;
103+ console . log ( ) ;
104+ } catch ( gitErr ) {
105+ console . error ( "Error during Git operations:" , gitErr . message || gitErr ) ;
106+ }
78107}
79108
80109export function logInsert ( msgArr : Msg ) {
81- const msg = {
82- msg : msgArr [ 0 ] ,
83- color : msgArr [ 1 ] ,
84- bgColor : msgArr [ 2 ]
85- }
86- if ( msg . bgColor !== null ) {
87- return chalk [ msg . color ] [ msg . bgColor ] ( msg . msg )
88-
89- }
90- return chalk [ msg . color ] ( msg . msg )
110+ const msg = {
111+ msg : msgArr [ 0 ] ,
112+ color : msgArr [ 1 ] ,
113+ bgColor : msgArr [ 2 ] ,
114+ } ;
115+ if ( msg . bgColor !== null ) {
116+ return chalk [ msg . color ] [ msg . bgColor ] ( msg . msg ) ;
117+ }
118+ return chalk [ msg . color ] ( msg . msg ) ;
91119}
92120// Main function to run all steps in sequence
93121async function main ( ) {
94- await updateVersionsFile ( ) ;
95- await updateManifestFile ( ) ;
96- await updatePackageJsonFile ( ) ;
97- gitCommitAndTag ( ) ; // This will only run after all file updates are complete
122+ await updateVersionsFile ( ) ;
123+ await updateManifestFile ( ) ;
124+ await updatePackageJsonFile ( ) ;
125+ gitCommitAndTag ( ) ; // This will only run after all file updates are complete
98126}
99127
100128// Run the main function
101- main ( ) ;
129+ main ( ) ;
0 commit comments