File size: 3,260 Bytes
51bdde0 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 | #!/usr/bin/env node
import fs from 'fs';
import path from 'path';
import { execSync } from 'child_process';
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const packageJsonPath = path.join(__dirname, '../package.json');
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
function getCurrentVersion() {
return packageJson.version;
}
function updateVersion(type) {
const currentVersion = getCurrentVersion();
const [major, minor, patch] = currentVersion.split('.').map(Number);
let newVersion;
switch (type) {
case 'major':
newVersion = `${major + 1}.0.0`;
break;
case 'minor':
newVersion = `${major}.${minor + 1}.0`;
break;
case 'patch':
default:
newVersion = `${major}.${minor}.${patch + 1}`;
break;
}
packageJson.version = newVersion;
fs.writeFileSync(
packageJsonPath,
JSON.stringify(packageJson, null, 2) + '\n'
);
return newVersion;
}
function createGitTag(version) {
const tagName = `v${version}`;
try {
// Check if tag already exists
execSync(`git rev-parse "v${version}" >/dev/null 2>&1`, {
stdio: 'ignore',
});
console.log(`β
Tag v${version} already exists`);
return tagName;
} catch {
// Tag doesn't exist, create it
execSync(`git tag -a "v${version}" -m "Release v${version}"`, {
stdio: 'inherit',
});
console.log(`β
Created tag v${version}`);
return tagName;
}
}
function main() {
const type = process.argv[2] || 'patch';
if (!['major', 'minor', 'patch'].includes(type)) {
console.error('β Invalid version type. Use: major, minor, or patch');
process.exit(1);
}
console.log(`π Releasing ${type} version...`);
// 1. Update version in package.json
const newVersion = updateVersion(type);
console.log(`π¦ Updated version to ${newVersion}`);
// 2. Update version in HTML files
console.log(`π Updating version in HTML files...`);
execSync('npm run update-version', { stdio: 'inherit' });
// 3. Add and commit changes
execSync('git add package.json *.html src/pages/*.html', {
stdio: 'inherit',
});
execSync(`git commit -m "Release v${newVersion}"`, { stdio: 'inherit' });
console.log(`πΎ Committed version change`);
// 4. Create git tag
const tagName = createGitTag(newVersion);
// 5. Build and package the distribution files
console.log(`π¦ Building and packaging distribution files...`);
execSync('npm run package', { stdio: 'inherit' });
console.log(`π¦ Distribution files packaged successfully`);
// 6. Push everything to main
console.log(`π€ Pushing to main...`);
execSync('git push origin main', { stdio: 'inherit' });
execSync(`git push origin ${tagName}`, { stdio: 'inherit' });
console.log(`π Release v${newVersion} complete!`);
console.log(`π¦ Docker image: bentopdfteam/bentopdf:${newVersion}`);
console.log(`π¦ Distribution: dist-${newVersion}.zip`);
console.log(
`π·οΈ GitHub release: https://github.com/alam00000/bentopdf/releases/tag/${tagName}`
);
console.log(
`π‘ Download dist-${newVersion}.zip from the release page for self-hosting.`
);
}
main();
|