ShtukbaseStandard
файл пакета→ .shtukbase/packages/std-semver/checks/version.ts

checks/version.ts

23 строки, 1.6 КБ.

Файл как есть в пакете: код и комментарии в нём не переводятся.

  1. // Action `next`: prints the project's version, the last release tag and the bump the commits since it ask for
  2. // (major for a breaking change, minor for feat, patch for the rest). Not a check: always exits 0.
  3. import { compare, config, parse, projectVersion, releaseTags } from './semverlib.ts';
  4. import { git } from './lib/std.ts';
  5. const cfg = config();
  6. const cur = projectVersion(cfg);
  7. const tags = releaseTags(cfg).filter((t) => t.ver).sort((a, b) => compare(b.ver!, a.ver!));
  8. console.log(`project version: ${cur ? `${cur.version} (${cur.file})` : 'not found'}`);
  9. if (!tags.length) {
  10. console.log('there are no releases (tags)');
  11. process.exit(0);
  12. }
  13. const last = tags[0];
  14. const msgs = (git(['log', '--no-merges', '--format=%B%x1e', `${last.tag}..HEAD`]) ?? '').split('\x1e').map((s) => s.trim()).filter(Boolean);
  15. const breaking = msgs.some((m) => /^[A-Za-z][\w-]*(\([^()\n]*\))?!: /.test(m) || /^BREAKING[ -]CHANGE: /m.test(m));
  16. const feat = msgs.some((m) => /^feat(\([^()\n]*\))?: /i.test(m));
  17. const v = last.ver!;
  18. const zero = v.major === 0 && cfg.zeroMajor === 'minor';
  19. const next = !msgs.length ? null : breaking ? (zero ? `${v.major}.${v.minor + 1}.0` : `${v.major + 1}.0.0`) : feat ? `${v.major}.${v.minor + 1}.0` : `${v.major}.${v.minor}.${v.patch + 1}`;
  20. console.log(`last release: ${last.tag}; commits after it: ${msgs.length}${breaking ? ', there are breaking ones' : ''}${feat ? ', there is a feat' : ''}`);
  21. console.log(next ? `next version by the commits: ${next}` : 'there are no commits after the release');
  22. if (cur && parse(cur.version) === null) console.log(`attention: ${cur.version} is not SemVer`);