UNPKG

@ptbarnum/color-tools

Version:
65 lines (52 loc) 1.7 kB
import fs from 'fs/promises'; import path from 'path'; import prompts from 'prompts'; const main = async () => { try { const packagePath = path.join(__dirname, 'package.json'); const pkg = await fs.readFile(packagePath, 'utf8'); const packageJson = JSON.parse(pkg); const currentVersion = packageJson.version; const [major, minor, patch] = currentVersion.split('.').map(Number); const newVersions = { patch: `${major}.${minor}.${patch + 1}`, minor: `${major}.${minor + 1}.0`, major: `${major + 1}.0.0`, }; console.info(`Current version: ${currentVersion}`); const { versionType } = await prompts({ type: 'select', name: 'versionType', message: 'Select the version type to update:', choices: [ { title: `No Change`, value: 'none' }, { title: `Patch (${newVersions.patch})`, value: 'patch' }, { title: `Minor (${newVersions.minor})`, value: 'minor' }, { title: `Major (${newVersions.major})`, value: 'major' }, ], initial: 0, }); if (versionType === 'none') { console.info('No version change selected.'); return; } const version = newVersions[versionType]; if (!version) { console.error('Invalid version type selected. Exiting.'); return; } console.info(`Updating version to: ${version}`); packageJson.version = version; await fs.writeFile( packagePath, JSON.stringify(packageJson, null, 2), 'utf8', ); console.info('Version updated successfully.'); process.exit(0); } catch (error) { console.error('Error reading package.json:', error); return; } }; main();