|
| 1 | +import { execaSync } from 'execa'; |
| 2 | +import { |
| 3 | + releaseChangelog, |
| 4 | + releasePublish, |
| 5 | + releaseVersion, |
| 6 | +} from 'nx/src/command-line/release'; |
| 7 | +import yargs from 'yargs'; |
| 8 | + |
| 9 | +const options = await yargs |
| 10 | + .version(false) |
| 11 | + .option('version', { |
| 12 | + description: |
| 13 | + 'Explicit version specifier to use, if overriding conventional commits', |
| 14 | + type: 'string', |
| 15 | + }) |
| 16 | + .option('dryRun', { |
| 17 | + alias: 'd', |
| 18 | + description: |
| 19 | + 'Whether to perform a dry-run of the release process, defaults to true', |
| 20 | + type: 'boolean', |
| 21 | + default: true, |
| 22 | + }) |
| 23 | + .option('verbose', { |
| 24 | + description: 'Whether or not to enable verbose logging, defaults to false', |
| 25 | + type: 'boolean', |
| 26 | + default: false, |
| 27 | + }) |
| 28 | + .parseAsync(); |
| 29 | + |
| 30 | +const { workspaceVersion, projectsVersionData } = await releaseVersion({ |
| 31 | + specifier: options.version, |
| 32 | + // stage package.json updates to be committed later by the changelog command |
| 33 | + stageChanges: true, |
| 34 | + dryRun: options.dryRun, |
| 35 | + verbose: options.verbose, |
| 36 | +}); |
| 37 | + |
| 38 | +// Update the lock file after the version bumps and stage it ready to be committed by the changelog step |
| 39 | +if (!options.dryRun) { |
| 40 | + console.log('⏳ Updating yarn.lock...'); |
| 41 | + execaSync(`yarn`, [`install`], { |
| 42 | + env: { ...process.env, SKIP_POSTINSTALL: 'true' }, |
| 43 | + }); |
| 44 | + execaSync(`git`, [`add`, `yarn.lock`]); |
| 45 | + console.log('✅ Updated and staged yarn.lock\n'); |
| 46 | +} |
| 47 | + |
| 48 | +// This will create a release on GitHub |
| 49 | +await releaseChangelog({ |
| 50 | + versionData: projectsVersionData, |
| 51 | + version: workspaceVersion, |
| 52 | + dryRun: options.dryRun, |
| 53 | + verbose: options.verbose, |
| 54 | +}); |
| 55 | + |
| 56 | +// An explicit null value here means that no changes were detected across any package |
| 57 | +// eslint-disable-next-line eqeqeq |
| 58 | +if (workspaceVersion === null) { |
| 59 | + console.log( |
| 60 | + '⏭️ No changes detected across any package, skipping publish step altogether', |
| 61 | + ); |
| 62 | +} else { |
| 63 | + await releasePublish({ |
| 64 | + dryRun: options.dryRun, |
| 65 | + verbose: options.verbose, |
| 66 | + }); |
| 67 | +} |
0 commit comments