|
| 1 | +//@ts-check |
| 2 | + |
| 3 | +const fs = require('fs'); |
| 4 | +const path = require('path'); |
| 5 | +const semver = require('semver'); |
| 6 | + |
| 7 | +const targetVersion = process.argv.slice(2).shift(); |
| 8 | +const repoRootPath = path.join(__dirname, '..'); |
| 9 | +const { version: currentVersion } = require(path.join(repoRootPath, 'package.json')); |
| 10 | + |
| 11 | +if (!targetVersion) { |
| 12 | + console.error('Target version was not specified. Target version must be a valid semver. Use: `yarn update:version x.y.z` to update the versions.'); |
| 13 | + process.exit(1); |
| 14 | +} |
| 15 | + |
| 16 | +if (!semver.valid(targetVersion)) { |
| 17 | + console.error(`Target version '${targetVersion}' is not a valid semver. Use: \`yarn update:version x.y.z\` to update the versions.`); |
| 18 | + process.exit(1); |
| 19 | +} |
| 20 | + |
| 21 | +if (!semver.gt(targetVersion, currentVersion)) { |
| 22 | + console.error(`Target version '${targetVersion}' must be greater than the current version '${currentVersion}.'`); |
| 23 | + process.exit(1); |
| 24 | +} |
| 25 | + |
| 26 | +console.log(`🛠️ Updating current version from '${currentVersion}' to '${targetVersion}':`); |
| 27 | +for (const toUpdate of [ |
| 28 | + path.join(repoRootPath, 'package.json'), |
| 29 | + path.join(repoRootPath, 'electron-app', 'package.json'), |
| 30 | + path.join(repoRootPath, 'browser-app', 'package.json'), |
| 31 | + path.join(repoRootPath, 'arduino-ide-extension', 'package.json'), |
| 32 | + path.join(repoRootPath, 'arduino-debugger-extension', 'package.json') // Currently unused. The debugger functionality comes from the `cortex.debug` VS Code extension. |
| 33 | +]) { |
| 34 | + process.stdout.write(` Updating ${toUpdate}'...`); |
| 35 | + const pkg = require(toUpdate); |
| 36 | + pkg.version = targetVersion; |
| 37 | + if ('dependencies' in pkg) { |
| 38 | + for (const dep of Object.keys(pkg['dependencies'])) { |
| 39 | + if (dep.startsWith('arduino-')) { |
| 40 | + pkg['dependencies'][dep] = targetVersion; |
| 41 | + } |
| 42 | + } |
| 43 | + } |
| 44 | + fs.writeFileSync(toUpdate, JSON.stringify(pkg, null, 2) + '\n'); |
| 45 | + process.stdout.write(` ✅ Done.\n`); |
| 46 | +} |
| 47 | + |
| 48 | +console.log(`Done. The new version is '${targetVersion}' now. Commit your changes and tag the code for the release. 🚢`); |
0 commit comments