@logicseek/hello-cc 0.1.2 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,8 +3,10 @@
3
3
  import fs from 'node:fs';
4
4
  import path from 'node:path';
5
5
  import process from 'node:process';
6
+ import { packageRoot, readPackageJson } from '../lib/package-meta.mjs';
7
+ import { normalizeVersion, releaseSection, validateReleaseSection } from '../lib/release-notes.mjs';
6
8
 
7
- const repoRoot = path.resolve(import.meta.dirname, '..');
9
+ const repoRoot = packageRoot(import.meta.url);
8
10
 
9
11
  function usage() {
10
12
  console.log(`release-notes
@@ -24,10 +26,6 @@ package release descriptions.
24
26
  `);
25
27
  }
26
28
 
27
- function readJson(file) {
28
- return JSON.parse(fs.readFileSync(file, 'utf8'));
29
- }
30
-
31
29
  function parseArgs(argv) {
32
30
  const opts = { check: false, help: false, version: null };
33
31
  for (let i = 0; i < argv.length; i += 1) {
@@ -48,36 +46,6 @@ function parseArgs(argv) {
48
46
  return opts;
49
47
  }
50
48
 
51
- function releaseSection(markdown, version) {
52
- const lines = markdown.split(/\r?\n/);
53
- const heading = `## ${version}`;
54
- const start = lines.findIndex((line) => line.trim() === heading);
55
- if (start < 0) return null;
56
-
57
- let end = lines.length;
58
- for (let i = start + 1; i < lines.length; i += 1) {
59
- if (/^##\s+/.test(lines[i])) {
60
- end = i;
61
- break;
62
- }
63
- }
64
- return lines.slice(start, end).join('\n').trimEnd();
65
- }
66
-
67
- function validateSection(section, version) {
68
- const problems = [];
69
- if (!section) {
70
- problems.push(`CHANGELOG.md is missing section ## ${version}`);
71
- return problems;
72
- }
73
- if (!section.includes('### Summary')) problems.push(`## ${version} is missing ### Summary`);
74
- if (!section.includes('### Highlights')) problems.push(`## ${version} is missing ### Highlights`);
75
- if (section.includes('TODO') || section.includes('TBD')) problems.push(`## ${version} still contains TODO/TBD text`);
76
- const bulletCount = (section.match(/^- /gm) || []).length;
77
- if (bulletCount < 2) problems.push(`## ${version} should include at least two release-note bullets`);
78
- return problems;
79
- }
80
-
81
49
  function main() {
82
50
  const opts = parseArgs(process.argv.slice(2));
83
51
  if (opts.help) {
@@ -85,11 +53,11 @@ function main() {
85
53
  return;
86
54
  }
87
55
 
88
- const pkg = readJson(path.join(repoRoot, 'package.json'));
89
- const version = opts.version || pkg.version;
56
+ const pkg = readPackageJson(repoRoot);
57
+ const version = normalizeVersion(opts.version || pkg.version);
90
58
  const changelog = fs.readFileSync(path.join(repoRoot, 'CHANGELOG.md'), 'utf8');
91
59
  const section = releaseSection(changelog, version);
92
- const problems = validateSection(section, version);
60
+ const problems = validateReleaseSection(section, version);
93
61
 
94
62
  if (opts.check) {
95
63
  if (problems.length) {