Created
January 14, 2023 03:32
-
-
Save blhack/c47607196a50e6be087a171f2c08e3b6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//import fs | |
const fs = require('fs').promises; | |
//this opens a file called app.json, parses it as json, changes a value, and then saves it. | |
//put this in an async function | |
const increment = async () => { | |
//first open the file | |
const appJson = await fs.readFile('app.json', 'utf8'); | |
//parse it as json | |
const appJsonParsed = JSON.parse(appJson); | |
//get the current version | |
const currentVersion = appJsonParsed.expo.version; | |
//split it into an array | |
const currentVersionArray = currentVersion.split('.'); | |
//increment the last number | |
const newVersion = currentVersionArray.map((n, i) => i === 2 ? parseInt(n) + 1 : n).join('.'); | |
//put this into the json | |
appJsonParsed.expo.version = newVersion; | |
//stringify it | |
const appJsonStringified = JSON.stringify(appJsonParsed, null, 2); | |
//write it back to the file | |
await fs.writeFile('app.json', appJsonStringified); | |
//say goodbye | |
console.log('Version incremented to ' + newVersion); | |
} | |
increment(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment