feat: Add automatic version.js generation
This commit is contained in:
26
generate-version.js
Normal file
26
generate-version.js
Normal file
@@ -0,0 +1,26 @@
|
||||
const { execSync } = require('child_process');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
try {
|
||||
// Run semantic-release to get the next version number
|
||||
const dryRunOutput = execSync('npx semantic-release --dry-run').toString();
|
||||
|
||||
// Extract the version number from the semantic-release output
|
||||
const versionMatch = dryRunOutput.match(/next version in .* is ([\d.]+)/);
|
||||
if (!versionMatch) {
|
||||
throw new Error('Version number not found in semantic-release output');
|
||||
}
|
||||
const version = versionMatch[1];
|
||||
|
||||
// Create version content
|
||||
const versionContent = `export const APP_VERSION = '${version}';\n`;
|
||||
const versionFilePath = path.resolve(__dirname, 'src/version.js');
|
||||
|
||||
// Write version to file
|
||||
fs.writeFileSync(versionFilePath, versionContent, 'utf8');
|
||||
console.log(`Version file generated with version: ${version}`);
|
||||
} catch (error) {
|
||||
console.error('Error generating version file:', error);
|
||||
process.exit(1);
|
||||
}
|
||||
Reference in New Issue
Block a user