seomd-cli 1.4.0 → 2.0.0

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.
Files changed (37) hide show
  1. package/PROVIDER_SPEC.md +125 -0
  2. package/README.md +54 -190
  3. package/SKILL.md +44 -0
  4. package/bin/seomd.js +78 -31
  5. package/package.json +11 -7
  6. package/src/commands/analyze.js +90 -90
  7. package/src/commands/check.js +301 -0
  8. package/src/commands/doctor.js +109 -0
  9. package/src/commands/generate.js +202 -0
  10. package/src/commands/init.js +123 -62
  11. package/src/commands/status.js +92 -76
  12. package/src/commands/sync.js +84 -70
  13. package/src/commands/validate.js +52 -25
  14. package/src/generators/directory.js +43 -110
  15. package/src/generators/reverse.js +46 -56
  16. package/src/generators/seomd.js +197 -44
  17. package/src/providers/http.js +67 -0
  18. package/src/providers/index.js +194 -0
  19. package/src/utils/agent-wiring.js +97 -0
  20. package/src/utils/api-client.js +14 -56
  21. package/src/utils/constants.js +110 -12
  22. package/src/utils/parser.js +114 -25
  23. package/src/utils/repo-scanner.js +207 -0
  24. package/src/utils/writeback.js +171 -82
  25. package/src/validators/seomd.js +255 -93
  26. package/scripts/release-contributors.js +0 -196
  27. package/scripts/release-notes.js +0 -194
  28. package/src/templates/blog/SEO.REVERSE.md +0 -176
  29. package/src/templates/blog/SEO.md +0 -233
  30. package/src/templates/ecommerce/SEO.REVERSE.md +0 -199
  31. package/src/templates/ecommerce/SEO.md +0 -239
  32. package/src/templates/local/SEO.REVERSE.md +0 -222
  33. package/src/templates/local/SEO.md +0 -245
  34. package/src/templates/marketplace/SEO.REVERSE.md +0 -222
  35. package/src/templates/marketplace/SEO.md +0 -245
  36. package/src/templates/saas/SEO.REVERSE.md +0 -268
  37. package/src/templates/saas/SEO.md +0 -257
@@ -1,21 +1,229 @@
1
- import { SITE_TYPES, INTENT_CATEGORIES } from '../utils/constants.js';
1
+ import {
2
+ VALID_SITE_TYPES,
3
+ INTENT_CATEGORIES,
4
+ VALID_PRIORITIES,
5
+ VALID_PAGE_STATUSES,
6
+ } from '../utils/constants.js';
2
7
 
3
8
  /**
4
- * Validates a parsed seo.md configuration object against the spec.
5
- *
6
- * @param {any} data - The parsed seo.md JS object
7
- * @returns {{errors: Array<{path: string, message: string}>, warnings: Array<{path: string, message: string}>}} Validation results
9
+ * Validates a parsed SEO.md configuration object against spec v2.0 (or legacy v1.0).
10
+ *
11
+ * @param {any} data - Parsed YAML data (frontmatter in v2, full doc in v1)
12
+ * @param {{ format?: 'v2'|'v1', body?: string }} [meta] - Optional parser metadata
13
+ * @returns {{ errors: Array<{path: string, message: string}>, warnings: Array<{path: string, message: string}>, specVersion: string }}
8
14
  */
9
- export function validateSeoMd(data) {
15
+ export function validateSeoMd(data, meta = {}) {
10
16
  const errors = [];
11
17
  const warnings = [];
12
18
 
13
19
  if (!data || typeof data !== 'object') {
14
20
  errors.push({ path: '', message: 'Specification must be a valid YAML object' });
15
- return { errors, warnings };
21
+ return { errors, warnings, specVersion: 'unknown' };
16
22
  }
17
23
 
18
- // 1. Required top-level sections
24
+ const isV2 =
25
+ meta.format === 'v2' ||
26
+ (typeof data.spec === 'string' && data.spec.startsWith('2')) ||
27
+ Array.isArray(data.pages);
28
+
29
+ if (isV2) {
30
+ validateV2(data, meta.body || '', errors, warnings);
31
+ return { errors, warnings, specVersion: String(data.spec || '2.0.0') };
32
+ }
33
+
34
+ validateV1(data, errors, warnings);
35
+ return { errors, warnings, specVersion: '1.0' };
36
+ }
37
+
38
+ function validatePageEntry(page, prefix, seenIds, errors) {
39
+ if (!page || typeof page !== 'object') {
40
+ errors.push({ path: prefix, message: `Page entry at ${prefix} must be an object` });
41
+ return;
42
+ }
43
+
44
+ if (!page.id || typeof page.id !== 'string') {
45
+ errors.push({ path: `${prefix}.id`, message: `Page at ${prefix} is missing a valid 'id'` });
46
+ } else if (seenIds.has(page.id)) {
47
+ errors.push({ path: `${prefix}.id`, message: `Duplicate page id '${page.id}'` });
48
+ } else {
49
+ seenIds.add(page.id);
50
+ }
51
+
52
+ if (!page.url || typeof page.url !== 'string') {
53
+ errors.push({ path: `${prefix}.url`, message: `Page '${page.id || prefix}' is missing 'url'` });
54
+ } else if (!page.url.startsWith('/')) {
55
+ errors.push({ path: `${prefix}.url`, message: `Page '${page.id || prefix}' url '${page.url}' must start with '/'` });
56
+ }
57
+
58
+ if (!page.status) {
59
+ errors.push({ path: `${prefix}.status`, message: `Page '${page.id || prefix}' is missing 'status'` });
60
+ } else if (!VALID_PAGE_STATUSES.includes(page.status)) {
61
+ errors.push({
62
+ path: `${prefix}.status`,
63
+ message: `Invalid status '${page.status}' for page '${page.id || prefix}'. Must be one of: ${VALID_PAGE_STATUSES.join(', ')}`,
64
+ });
65
+ }
66
+
67
+ if (page.priority === undefined || page.priority === null) {
68
+ errors.push({ path: `${prefix}.priority`, message: `Page '${page.id || prefix}' is missing 'priority'` });
69
+ } else if (typeof page.priority !== 'number') {
70
+ errors.push({ path: `${prefix}.priority`, message: `Priority for page '${page.id || prefix}' must be a number` });
71
+ }
72
+ }
73
+
74
+ function validateDomain(domain, errors, warnings) {
75
+ if (!domain) {
76
+ errors.push({ path: 'site.domain', message: 'site.domain is required' });
77
+ } else if (typeof domain !== 'string') {
78
+ errors.push({ path: 'site.domain', message: 'site.domain must be a string' });
79
+ } else if (/^https?:\/\//i.test(domain) || domain.includes('/')) {
80
+ warnings.push({
81
+ path: 'site.domain',
82
+ message: `site.domain '${domain}' should be a bare hostname (e.g. 'example.com') without protocol or path`,
83
+ });
84
+ }
85
+ }
86
+
87
+ function validateCanonical(canonical, errors) {
88
+ if (canonical === undefined || canonical === null) return;
89
+ if (typeof canonical !== 'string') {
90
+ errors.push({ path: 'site.canonical', message: 'site.canonical must be a string' });
91
+ } else if (!/^https?:\/\/.+/i.test(canonical)) {
92
+ errors.push({ path: 'site.canonical', message: `site.canonical '${canonical}' must be a full http(s) URL` });
93
+ }
94
+ }
95
+
96
+ function validateV2(data, body, errors, warnings) {
97
+ if (!data.spec) {
98
+ warnings.push({ path: 'spec', message: "Missing 'spec' version field in frontmatter (recommended: '2.0.0')" });
99
+ }
100
+
101
+ // 1. Required top-level keys
102
+ for (const section of ['site', 'keywords', 'pages']) {
103
+ if (!(section in data) || data[section] === null || data[section] === undefined) {
104
+ errors.push({ path: section, message: `Missing required frontmatter section: '${section}'` });
105
+ }
106
+ }
107
+
108
+ if (errors.some((e) => ['site', 'keywords', 'pages'].includes(e.path))) {
109
+ return;
110
+ }
111
+
112
+ // 2. site
113
+ const site = data.site;
114
+ if (typeof site !== 'object') {
115
+ errors.push({ path: 'site', message: 'site must be an object' });
116
+ } else {
117
+ const brand = site.brand || data.identity?.brand;
118
+ if (!brand || typeof brand !== 'string') {
119
+ errors.push({ path: 'site.brand', message: 'site.brand is required' });
120
+ }
121
+
122
+ if (!site.type) {
123
+ errors.push({ path: 'site.type', message: 'site.type is required' });
124
+ } else if (!VALID_SITE_TYPES.includes(site.type)) {
125
+ errors.push({
126
+ path: 'site.type',
127
+ message: `Invalid site.type '${site.type}'. Must be one of: ${VALID_SITE_TYPES.join(', ')}`,
128
+ });
129
+ }
130
+
131
+ validateDomain(site.domain, errors, warnings);
132
+ validateCanonical(site.canonical, errors);
133
+ }
134
+
135
+ // 3. keywords
136
+ const keywords = data.keywords;
137
+ if (typeof keywords !== 'object') {
138
+ errors.push({ path: 'keywords', message: 'keywords must be an object' });
139
+ } else {
140
+ if (!keywords.primary || typeof keywords.primary !== 'string' || !keywords.primary.trim()) {
141
+ errors.push({ path: 'keywords.primary', message: 'keywords.primary is required' });
142
+ }
143
+ if (keywords.secondary !== undefined && !Array.isArray(keywords.secondary)) {
144
+ errors.push({ path: 'keywords.secondary', message: 'keywords.secondary must be an array' });
145
+ } else if (!keywords.secondary || keywords.secondary.length === 0) {
146
+ warnings.push({ path: 'keywords.secondary', message: 'keywords.secondary is empty. Consider adding secondary terms.' });
147
+ }
148
+ if (keywords.negative !== undefined && !Array.isArray(keywords.negative)) {
149
+ errors.push({ path: 'keywords.negative', message: 'keywords.negative must be an array' });
150
+ }
151
+ }
152
+
153
+ // 4. pages
154
+ const seenIds = new Set();
155
+ if (!Array.isArray(data.pages)) {
156
+ errors.push({ path: 'pages', message: 'pages must be an array in spec v2' });
157
+ } else if (data.pages.length === 0) {
158
+ errors.push({ path: 'pages', message: 'pages array cannot be empty' });
159
+ } else {
160
+ data.pages.forEach((page, index) => {
161
+ validatePageEntry(page, `pages[${index}]`, seenIds, errors);
162
+ });
163
+ }
164
+
165
+ // 5. intent (optional in v2, validated if present)
166
+ if (data.intent !== undefined && data.intent !== null) {
167
+ if (typeof data.intent !== 'object') {
168
+ errors.push({ path: 'intent', message: 'intent must be an object' });
169
+ } else {
170
+ for (const [cat, catData] of Object.entries(data.intent)) {
171
+ if (cat === '_analysis') continue;
172
+ if (!INTENT_CATEGORIES.includes(cat)) {
173
+ warnings.push({
174
+ path: `intent.${cat}`,
175
+ message: `Unrecognized intent category '${cat}'. Standard categories: ${INTENT_CATEGORIES.join(', ')}`,
176
+ });
177
+ }
178
+ if (!catData || typeof catData !== 'object') {
179
+ errors.push({ path: `intent.${cat}`, message: `intent.${cat} must be an object` });
180
+ continue;
181
+ }
182
+ if (catData.priority && !VALID_PRIORITIES.includes(String(catData.priority).toLowerCase())) {
183
+ errors.push({
184
+ path: `intent.${cat}.priority`,
185
+ message: `Invalid priority '${catData.priority}' for intent.${cat}. Must be one of: ${VALID_PRIORITIES.join(', ')}`,
186
+ });
187
+ }
188
+ if (catData.queries !== undefined && !Array.isArray(catData.queries)) {
189
+ errors.push({ path: `intent.${cat}.queries`, message: `intent.${cat}.queries must be an array` });
190
+ } else if (!catData.queries || catData.queries.length === 0) {
191
+ warnings.push({ path: `intent.${cat}.queries`, message: `intent.${cat}.queries is empty.` });
192
+ }
193
+ }
194
+ }
195
+ }
196
+
197
+ // 6. crawl (optional)
198
+ if (data.crawl && typeof data.crawl === 'object') {
199
+ const robots = data.crawl.robots ?? data.crawl.robots_txt;
200
+ if (robots !== undefined && robots !== null && typeof robots !== 'string') {
201
+ errors.push({ path: 'crawl.robots', message: 'crawl.robots must be a string' });
202
+ }
203
+ if (data.crawl.sitemap !== undefined && data.crawl.sitemap !== null && typeof data.crawl.sitemap !== 'string') {
204
+ errors.push({ path: 'crawl.sitemap', message: 'crawl.sitemap must be a string' });
205
+ }
206
+ if (data.crawl.llms_txt !== undefined && data.crawl.llms_txt !== null && typeof data.crawl.llms_txt !== 'string') {
207
+ errors.push({ path: 'crawl.llms_txt', message: 'crawl.llms_txt must be a string' });
208
+ }
209
+ }
210
+
211
+ // 7. provider (optional)
212
+ const provider = data.provider || data.platform || {};
213
+ if (provider.endpoint && typeof provider.endpoint === 'string' && !/^https?:\/\/.+/i.test(provider.endpoint)) {
214
+ errors.push({ path: 'provider.endpoint', message: 'provider.endpoint must be a valid http(s) URL' });
215
+ }
216
+
217
+ // 8. Markdown body check
218
+ if (!body || body.trim().length < 20) {
219
+ warnings.push({
220
+ path: 'body',
221
+ message: 'Markdown body is empty or very short. Add canonical product facts and agent rules so coding agents can act on SEO.md.',
222
+ });
223
+ }
224
+ }
225
+
226
+ function validateV1(data, errors, warnings) {
19
227
  const requiredSections = [
20
228
  'site',
21
229
  'identity',
@@ -25,7 +233,7 @@ export function validateSeoMd(data) {
25
233
  'schema',
26
234
  'crawl',
27
235
  'performance',
28
- 'monitoring'
236
+ 'monitoring',
29
237
  ];
30
238
 
31
239
  for (const section of requiredSections) {
@@ -34,67 +242,52 @@ export function validateSeoMd(data) {
34
242
  }
35
243
  }
36
244
 
37
- // If critical sections are missing, stop early to avoid nested property access errors
38
- if (errors.some(e => ['site', 'identity', 'keywords', 'intent', 'pages'].includes(e.path))) {
39
- return { errors, warnings };
245
+ if (errors.some((e) => ['site', 'identity', 'keywords', 'intent', 'pages'].includes(e.path))) {
246
+ return;
40
247
  }
41
248
 
42
- // 2. Validate 'site' section
249
+ // site
43
250
  const site = data.site || {};
44
- const validSiteTypes = SITE_TYPES.map(t => t.value);
45
-
46
251
  if (!site.type) {
47
252
  errors.push({ path: 'site.type', message: 'site.type is required' });
48
- } else if (!validSiteTypes.includes(site.type)) {
49
- errors.push({
50
- path: 'site.type',
51
- message: `Invalid site.type '${site.type}'. Must be one of: ${validSiteTypes.join(', ')}`
253
+ } else if (!VALID_SITE_TYPES.includes(site.type)) {
254
+ errors.push({
255
+ path: 'site.type',
256
+ message: `Invalid site.type '${site.type}'. Must be one of: ${VALID_SITE_TYPES.join(', ')}`,
52
257
  });
53
258
  }
259
+ validateDomain(site.domain, errors, warnings);
260
+ validateCanonical(site.canonical, errors);
54
261
 
55
- if (!site.domain) {
56
- errors.push({ path: 'site.domain', message: 'site.domain is required' });
57
- } else if (typeof site.domain !== 'string') {
58
- errors.push({ path: 'site.domain', message: 'site.domain must be a string' });
59
- }
60
-
61
- if (site.canonical && typeof site.canonical !== 'string') {
62
- errors.push({ path: 'site.canonical', message: 'site.canonical must be a string' });
63
- }
64
-
65
- // 3. Validate 'identity' section
262
+ // identity
66
263
  const identity = data.identity || {};
67
264
  if (!identity.brand) {
68
265
  errors.push({ path: 'identity.brand', message: 'identity.brand is required' });
69
266
  } else if (typeof identity.brand !== 'string') {
70
267
  errors.push({ path: 'identity.brand', message: 'identity.brand must be a string' });
71
268
  }
72
-
73
269
  if (!identity.tagline) {
74
270
  warnings.push({ path: 'identity.tagline', message: 'identity.tagline is missing or empty' });
75
271
  }
76
272
 
77
- // 4. Validate 'keywords' section
273
+ // keywords
78
274
  const keywords = data.keywords || {};
79
275
  if (!keywords.primary) {
80
276
  errors.push({ path: 'keywords.primary', message: 'keywords.primary is required' });
81
277
  } else if (typeof keywords.primary !== 'string') {
82
278
  errors.push({ path: 'keywords.primary', message: 'keywords.primary must be a string' });
83
279
  }
84
-
85
280
  if (!keywords.secondary || !Array.isArray(keywords.secondary) || keywords.secondary.length === 0) {
86
281
  warnings.push({ path: 'keywords.secondary', message: 'keywords.secondary is empty. Consider adding target secondary terms.' });
87
282
  }
88
-
89
283
  if (!keywords.negative || !Array.isArray(keywords.negative)) {
90
284
  warnings.push({ path: 'keywords.negative', message: 'keywords.negative should be an array of terms to filter out' });
91
285
  }
92
-
93
286
  if (!keywords.long_tail || !Array.isArray(keywords.long_tail) || keywords.long_tail.length === 0) {
94
287
  warnings.push({ path: 'keywords.long_tail', message: 'keywords.long_tail is empty. Consider adding long-tail variations.' });
95
288
  }
96
289
 
97
- // 5. Validate 'intent' section
290
+ // intent
98
291
  const intent = data.intent || {};
99
292
  for (const cat of INTENT_CATEGORIES) {
100
293
  const catData = intent[cat];
@@ -102,17 +295,14 @@ export function validateSeoMd(data) {
102
295
  errors.push({ path: `intent.${cat}`, message: `Missing or invalid intent category: 'intent.${cat}'` });
103
296
  continue;
104
297
  }
105
-
106
- const validPriorities = ['low', 'medium', 'high', 'critical'];
107
298
  if (!catData.priority) {
108
299
  errors.push({ path: `intent.${cat}.priority`, message: `intent.${cat}.priority is required` });
109
- } else if (!validPriorities.includes(String(catData.priority).toLowerCase())) {
110
- errors.push({
111
- path: `intent.${cat}.priority`,
112
- message: `Invalid priority '${catData.priority}' for intent.${cat}. Must be one of: ${validPriorities.join(', ')}`
300
+ } else if (!VALID_PRIORITIES.includes(String(catData.priority).toLowerCase())) {
301
+ errors.push({
302
+ path: `intent.${cat}.priority`,
303
+ message: `Invalid priority '${catData.priority}' for intent.${cat}. Must be one of: ${VALID_PRIORITIES.join(', ')}`,
113
304
  });
114
305
  }
115
-
116
306
  if (!catData.queries || !Array.isArray(catData.queries)) {
117
307
  errors.push({ path: `intent.${cat}.queries`, message: `intent.${cat}.queries must be an array` });
118
308
  } else if (catData.queries.length === 0) {
@@ -120,52 +310,31 @@ export function validateSeoMd(data) {
120
310
  }
121
311
  }
122
312
 
123
- // 6. Validate 'pages' section
313
+ // pages
124
314
  const pages = data.pages || {};
315
+ const seenIds = new Set();
125
316
  if (!pages.required || !Array.isArray(pages.required)) {
126
317
  errors.push({ path: 'pages.required', message: 'pages.required must be an array' });
127
318
  } else if (pages.required.length === 0) {
128
319
  errors.push({ path: 'pages.required', message: 'pages.required array cannot be empty' });
129
320
  } else {
130
321
  pages.required.forEach((page, index) => {
131
- const prefix = `pages.required[${index}]`;
132
- if (!page || typeof page !== 'object') {
133
- errors.push({ path: prefix, message: `Page entry at index ${index} must be an object` });
134
- return;
135
- }
136
-
137
- if (!page.id) {
138
- errors.push({ path: `${prefix}.id`, message: `Page at index ${index} is missing 'id'` });
139
- }
140
- if (!page.url) {
141
- errors.push({ path: `${prefix}.url`, message: `Page '${page.id || index}' is missing 'url'` });
142
- }
143
-
144
- const validStatus = ['live', 'draft', 'planned'];
145
- if (!page.status) {
146
- errors.push({ path: `${prefix}.status`, message: `Page '${page.id || index}' is missing 'status'` });
147
- } else if (!validStatus.includes(page.status)) {
148
- errors.push({
149
- path: `${prefix}.status`,
150
- message: `Invalid status '${page.status}' for page '${page.id || index}'. Must be one of: ${validStatus.join(', ')}`
151
- });
152
- }
153
-
154
- if (page.priority === undefined || page.priority === null) {
155
- errors.push({ path: `${prefix}.priority`, message: `Page '${page.id || index}' is missing 'priority'` });
156
- } else if (typeof page.priority !== 'number') {
157
- errors.push({ path: `${prefix}.priority`, message: `Priority for page '${page.id || index}' must be a number` });
158
- }
322
+ validatePageEntry(page, `pages.required[${index}]`, seenIds, errors);
323
+ });
324
+ }
325
+ if (Array.isArray(pages.optional)) {
326
+ pages.optional.forEach((page, index) => {
327
+ validatePageEntry(page, `pages.optional[${index}]`, seenIds, errors);
159
328
  });
160
329
  }
161
330
 
162
- // 7. Validate 'schema' section
331
+ // schema
163
332
  const schema = data.schema || {};
164
333
  if (schema.types && !Array.isArray(schema.types)) {
165
334
  errors.push({ path: 'schema.types', message: 'schema.types must be an array' });
166
335
  }
167
336
 
168
- // 8. Validate 'crawl' section
337
+ // crawl
169
338
  const crawl = data.crawl || {};
170
339
  if (crawl.sitemap && typeof crawl.sitemap !== 'string') {
171
340
  errors.push({ path: 'crawl.sitemap', message: 'crawl.sitemap must be a string' });
@@ -174,38 +343,31 @@ export function validateSeoMd(data) {
174
343
  errors.push({ path: 'crawl.robots_txt', message: 'crawl.robots_txt must be a string' });
175
344
  }
176
345
 
177
- // 9. Validate 'performance' section
346
+ // performance
178
347
  const perf = data.performance || {};
179
- const stringFields = ['lcp', 'cls', 'fid', 'page_size', 'ttfb'];
180
- for (const field of stringFields) {
348
+ for (const field of ['lcp', 'cls', 'fid', 'inp', 'page_size', 'ttfb']) {
181
349
  if (perf[field] !== undefined && perf[field] !== null && typeof perf[field] !== 'string' && typeof perf[field] !== 'number') {
182
350
  errors.push({ path: `performance.${field}`, message: `performance.${field} must be a string or number` });
183
351
  }
184
352
  }
185
353
 
186
- // 10. Validate 'authority' section
354
+ // authority
187
355
  const authority = data.authority || {};
188
- if (authority.eeat_signals) {
189
- const eeat = authority.eeat_signals;
190
- if (typeof eeat === 'object') {
191
- const fields = ['experience', 'expertise', 'authority', 'trust'];
192
- const missingEeat = fields.filter(f => !eeat[f]);
193
- if (missingEeat.length > 0) {
194
- warnings.push({
195
- path: 'authority.eeat_signals',
196
- message: `EEAT signals are missing values for: ${missingEeat.join(', ')}`
197
- });
198
- }
356
+ if (authority.eeat_signals && typeof authority.eeat_signals === 'object') {
357
+ const missingEeat = ['experience', 'expertise', 'authority', 'trust'].filter((f) => !authority.eeat_signals[f]);
358
+ if (missingEeat.length > 0) {
359
+ warnings.push({
360
+ path: 'authority.eeat_signals',
361
+ message: `EEAT signals are missing values for: ${missingEeat.join(', ')}`,
362
+ });
199
363
  }
200
364
  } else {
201
365
  warnings.push({ path: 'authority.eeat_signals', message: 'authority.eeat_signals section is missing. Highly recommended for AEO.' });
202
366
  }
203
367
 
204
- // 11. Validate 'platform' section
368
+ // platform
205
369
  const platform = data.platform || {};
206
370
  if (!platform.provider) {
207
- warnings.push({ path: 'platform.provider', message: 'platform.provider is null. CLI requires connection for analyze/sync.' });
371
+ warnings.push({ path: 'platform.provider', message: 'platform.provider is null. Configure a provider for analyze/sync.' });
208
372
  }
209
-
210
- return { errors, warnings };
211
373
  }
@@ -1,196 +0,0 @@
1
- import fs from 'fs';
2
- import path from 'path';
3
- import { execSync } from 'child_process';
4
- import YAML from 'yaml';
5
-
6
- function parseArgs(argv) {
7
- const out = { from: null, to: null, outFile: null };
8
- for (let i = 2; i < argv.length; i += 1) {
9
- const arg = argv[i];
10
- const next = argv[i + 1];
11
- if (arg === '--from' && next) {
12
- out.from = next;
13
- i += 1;
14
- } else if (arg === '--to' && next) {
15
- out.to = next;
16
- i += 1;
17
- } else if (arg === '--out' && next) {
18
- out.outFile = next;
19
- i += 1;
20
- }
21
- }
22
- return out;
23
- }
24
-
25
- function readContributorsMap(repoRoot) {
26
- const filePath = path.join(repoRoot, '.github', 'contributors.yml');
27
- if (!fs.existsSync(filePath)) {
28
- return { version: 1, contributors: [] };
29
- }
30
- const parsed = YAML.parse(fs.readFileSync(filePath, 'utf8')) || {};
31
- return {
32
- version: parsed.version || 1,
33
- contributors: Array.isArray(parsed.contributors) ? parsed.contributors : []
34
- };
35
- }
36
-
37
- function normalizeEmail(email) {
38
- return String(email || '').trim().toLowerCase();
39
- }
40
-
41
- function normalizeName(name) {
42
- return String(name || '').trim().toLowerCase();
43
- }
44
-
45
- function resolveHandle(map, { name, email }) {
46
- const nEmail = normalizeEmail(email);
47
- const nName = normalizeName(name);
48
-
49
- for (const c of map.contributors) {
50
- if (!c || typeof c !== 'object') continue;
51
- if (!c.github) continue;
52
- const emails = Array.isArray(c.emails) ? c.emails.map(normalizeEmail) : [];
53
- if (nEmail && emails.includes(nEmail)) return c.github;
54
- const names = Array.isArray(c.names) ? c.names.map(normalizeName) : [];
55
- if (nName && names.includes(nName)) return c.github;
56
- }
57
- return null;
58
- }
59
-
60
- function git(repoRoot, args) {
61
- return execSync(`git ${args}`, { cwd: repoRoot, stdio: ['ignore', 'pipe', 'pipe'] }).toString('utf8');
62
- }
63
-
64
- function getRepoRoot() {
65
- return execSync('git rev-parse --show-toplevel', { stdio: ['ignore', 'pipe', 'pipe'] }).toString('utf8').trim();
66
- }
67
-
68
- function getCommitBodies(repoRoot, range) {
69
- const sepCommit = '\u001e';
70
- const sepField = '\u001f';
71
- const out = git(repoRoot, `log ${range} --no-color --format=%H${sepField}%an${sepField}%ae${sepField}%B${sepCommit}`);
72
- const rawCommits = out.split(sepCommit).map(s => s.trim()).filter(Boolean);
73
- return rawCommits.map(entry => {
74
- const parts = entry.split(sepField);
75
- const [sha, authorName, authorEmail] = parts;
76
- const body = parts.slice(3).join(sepField);
77
- return { sha, authorName, authorEmail, body };
78
- });
79
- }
80
-
81
- function extractCoAuthors(commitBody) {
82
- const out = [];
83
- const lines = String(commitBody || '').split('\n');
84
- for (const line of lines) {
85
- const m = line.match(/^Co-authored-by:\s*(.+?)\s*<(.+?)>\s*$/i);
86
- if (m) out.push({ name: m[1], email: m[2] });
87
- }
88
- return out;
89
- }
90
-
91
- function bumpCounter(map, key, display) {
92
- const existing = map.get(key);
93
- if (existing) {
94
- existing.count += 1;
95
- return;
96
- }
97
- map.set(key, { count: 1, display });
98
- }
99
-
100
- function fmtHandle(handle) {
101
- if (!handle) return null;
102
- return handle.startsWith('@') ? handle : `@${handle}`;
103
- }
104
-
105
- function buildContribMarkdown({ from, to, resolvedCounts, unresolvedCounts }) {
106
- const lines = [];
107
- const rangeLabel = from && to ? `${from}..${to}` : 'range';
108
-
109
- lines.push(`## Contributors`);
110
- lines.push('');
111
- lines.push(`Commit range: ${rangeLabel}`);
112
- lines.push('');
113
-
114
- const resolved = Array.from(resolvedCounts.entries())
115
- .sort((a, b) => b[1].count - a[1].count || a[0].localeCompare(b[0]));
116
-
117
- if (resolved.length > 0) {
118
- for (const [handle, info] of resolved) {
119
- lines.push(`- ${fmtHandle(handle)} (${info.count})`);
120
- }
121
- lines.push('');
122
- } else {
123
- lines.push(`- None`);
124
- lines.push('');
125
- }
126
-
127
- const unresolved = Array.from(unresolvedCounts.entries())
128
- .sort((a, b) => b[1].count - a[1].count || a[0].localeCompare(b[0]));
129
-
130
- if (unresolved.length > 0) {
131
- lines.push(`## Unmapped Contributors`);
132
- lines.push('');
133
- for (const [key, info] of unresolved) {
134
- lines.push(`- ${info.display} (${info.count})`);
135
- }
136
- lines.push('');
137
- lines.push(`To tag these contributors, add their name/email to .github/contributors.yml.`);
138
- lines.push('');
139
- }
140
-
141
- return lines.join('\n');
142
- }
143
-
144
- function main() {
145
- const args = parseArgs(process.argv);
146
- if (!args.from || !args.to) {
147
- process.stderr.write('Usage: node scripts/release-contributors.js --from <tag> --to <tag> [--out <file>]\n');
148
- process.exit(1);
149
- }
150
-
151
- const repoRoot = getRepoRoot();
152
- const contribMap = readContributorsMap(repoRoot);
153
- const range = `${args.from}..${args.to}`;
154
- const commits = getCommitBodies(repoRoot, range);
155
-
156
- const resolvedCounts = new Map();
157
- const unresolvedCounts = new Map();
158
-
159
- for (const c of commits) {
160
- const authorHandle = resolveHandle(contribMap, { name: c.authorName, email: c.authorEmail });
161
- if (authorHandle) {
162
- bumpCounter(resolvedCounts, authorHandle, fmtHandle(authorHandle));
163
- } else {
164
- bumpCounter(unresolvedCounts, `${normalizeName(c.authorName)}|${normalizeEmail(c.authorEmail)}`, `${c.authorName} <${c.authorEmail}>`);
165
- }
166
-
167
- for (const co of extractCoAuthors(c.body)) {
168
- const coHandle = resolveHandle(contribMap, co);
169
- if (coHandle) {
170
- bumpCounter(resolvedCounts, coHandle, fmtHandle(coHandle));
171
- } else {
172
- bumpCounter(unresolvedCounts, `${normalizeName(co.name)}|${normalizeEmail(co.email)}`, `${co.name} <${co.email}>`);
173
- }
174
- }
175
- }
176
-
177
- const md = buildContribMarkdown({
178
- from: args.from,
179
- to: args.to,
180
- resolvedCounts,
181
- unresolvedCounts
182
- });
183
-
184
- if (args.outFile) {
185
- const outPath = path.isAbsolute(args.outFile) ? args.outFile : path.join(repoRoot, args.outFile);
186
- fs.mkdirSync(path.dirname(outPath), { recursive: true });
187
- fs.writeFileSync(outPath, md, 'utf8');
188
- process.stdout.write(`${outPath}\n`);
189
- return;
190
- }
191
-
192
- process.stdout.write(md + '\n');
193
- }
194
-
195
- main();
196
-