|
| 1 | +const fs = require('fs'); |
| 2 | +const path = require('path'); |
| 3 | + |
| 4 | +// Read the version from package.json |
| 5 | +const packageJson = require('../package.json'); |
| 6 | +const version = packageJson.version; |
| 7 | + |
| 8 | +// Define the path to build.gradle |
| 9 | +const gradleFilePath = path.join(__dirname, '..', 'android', 'app', 'build.gradle'); |
| 10 | + |
| 11 | +// Read the build.gradle file |
| 12 | +let gradleFileContent = fs.readFileSync(gradleFilePath, 'utf8'); |
| 13 | + |
| 14 | +// Update the versionCode and versionName |
| 15 | +const versionCodeDroid = version |
| 16 | + .split('.') |
| 17 | + .map((num) => num.padStart(2, '0')) |
| 18 | + .join(''); |
| 19 | + |
| 20 | +gradleFileContent = gradleFileContent.replace( |
| 21 | + /versionCode \d+/g, |
| 22 | + `versionCode ${versionCodeDroid}`, |
| 23 | +); |
| 24 | +gradleFileContent = gradleFileContent.replace( |
| 25 | + /versionName "[^"]+"/g, |
| 26 | + `versionName "${version}"`, |
| 27 | +); |
| 28 | + |
| 29 | +// Write the updated content back to build.gradle |
| 30 | +fs.writeFileSync(gradleFilePath, gradleFileContent, 'utf8'); |
| 31 | + |
| 32 | +console.log(`Updated build.gradle to version ${version}`); |
| 33 | + |
| 34 | +// CREATE fastlane changelog file |
| 35 | +// Define the paths |
| 36 | +const changelogPath = path.join(__dirname, '..', 'CHANGELOG.md'); |
| 37 | +const outputDir = path.join( |
| 38 | + __dirname, |
| 39 | + '..', |
| 40 | + 'fastlane', |
| 41 | + 'metadata', |
| 42 | + 'android', |
| 43 | + 'en-US', |
| 44 | + 'changelogs', |
| 45 | +); |
| 46 | +const outputFilePath = path.join(outputDir, `${versionCodeDroid}.txt`); |
| 47 | + |
| 48 | +// Read the changelog.md file |
| 49 | +const changelogContent = fs.readFileSync(changelogPath, 'utf8'); |
| 50 | + |
| 51 | +// Extract the latest changes |
| 52 | +const lines = changelogContent.split('\n').slice(2); // Remove the first two lines; |
| 53 | +let latestChanges = ''; |
| 54 | +let headerCount = 0; |
| 55 | + |
| 56 | +for (const line of lines) { |
| 57 | + if (line.startsWith('# [') || line.startsWith('## [')) { |
| 58 | + headerCount++; |
| 59 | + if (headerCount === 1) break; |
| 60 | + } |
| 61 | + latestChanges += line + '\n'; |
| 62 | +} |
| 63 | +// Remove all links from the extracted text |
| 64 | +latestChanges = latestChanges |
| 65 | + .replace(/\[([^\]]+)\]\([^\)]+\)/g, '$1') |
| 66 | + .replace(/\s*\([a-f0-9]{7}\)\s*$/gm, ''); |
| 67 | + |
| 68 | +// Ensure the output directory exists |
| 69 | +if (!fs.existsSync(outputDir)) { |
| 70 | + fs.mkdirSync(outputDir, { recursive: true }); |
| 71 | +} |
| 72 | + |
| 73 | +// Write the latest changes to the versioned changelog file |
| 74 | +fs.writeFileSync(outputFilePath, latestChanges, 'utf8'); |
| 75 | + |
| 76 | +console.log(`Wrote latest changes to ${outputFilePath}`); |
| 77 | +// console.log(latestChanges); |
0 commit comments