storymaps 1.2.1 → 1.2.2

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.
@@ -7,7 +7,8 @@ import { resolve } from 'node:path';
7
7
  import chalk from 'chalk';
8
8
  import { password } from '@inquirer/prompts';
9
9
  import jsyaml from 'js-yaml';
10
- import { importFromYaml } from '../core/yaml.js';
10
+ import { exportToYaml, importFromYaml, yamlObjToJson } from '../core/yaml.js';
11
+ import { printChangeSummary } from '../util/summary.js';
11
12
  import { resolveTarget } from '../util/identity.js';
12
13
  import { getMap, putMap, postMap, ApiError } from '../util/api.js';
13
14
  import { detectFormat, readCache, writeCache } from '../util/file.js';
@@ -70,6 +71,14 @@ export async function pushCommand(target, opts) {
70
71
 
71
72
  const contentType = format === 'json' ? 'application/json' : 'text/yaml';
72
73
 
74
+ // Show a change summary before pushing
75
+ try {
76
+ const { data: remoteData } = await getMap(baseUrl, id, 'yaml');
77
+ const remoteNorm = exportToYaml(yamlObjToJson(jsyaml.load(remoteData)));
78
+ const localNorm = exportToYaml(yamlObjToJson(jsyaml.load(content)));
79
+ if (remoteNorm !== localNorm) printChangeSummary(remoteNorm, localNorm);
80
+ } catch { /* non-fatal */ }
81
+
73
82
  const cache = await readCache(id);
74
83
  let etag = opts.force ? undefined : cache.etag;
75
84
  let lockPasswordHash = cache.hash;
@@ -42,26 +42,43 @@ export function changeSummary(oldYaml, newYaml) {
42
42
  lines.push(chalk.red(` - slice: ${s}`));
43
43
  }
44
44
 
45
- // Count story-level changes per slice
46
- const countStories = (map) => {
47
- const counts = {};
45
+ // Detect card-level changes per slice (name-aware, handles renames)
46
+ const collectCardNames = (map) => {
47
+ const result = {};
48
48
  for (const slice of (map.slices || [])) {
49
- const stories = slice.stories || {};
50
- counts[slice.name] = Object.values(stories)
51
- .reduce((n, cards) => n + (Array.isArray(cards) ? cards.length : 0), 0);
49
+ const names = [];
50
+ for (const cards of Object.values(slice.stories || {})) {
51
+ if (Array.isArray(cards)) names.push(...cards.map(c => c.name).filter(Boolean));
52
+ }
53
+ result[slice.name] = names;
52
54
  }
53
- return counts;
55
+ return result;
54
56
  };
55
- const oldCounts = countStories(old);
56
- const newCounts = countStories(cur);
57
- for (const name of new Set([...Object.keys(oldCounts), ...Object.keys(newCounts)])) {
58
- const oc = oldCounts[name] || 0;
59
- const nc = newCounts[name] || 0;
60
- if (oc !== nc) {
61
- const delta = nc - oc;
62
- const word = Math.abs(delta) === 1 ? 'story' : 'stories';
63
- if (delta > 0) lines.push(chalk.green(` + ${name}: ${delta} ${word}`));
64
- else lines.push(chalk.red(` - ${name}: ${Math.abs(delta)} ${word}`));
57
+ const oldCards = collectCardNames(old);
58
+ const newCards = collectCardNames(cur);
59
+ for (const sliceName of new Set([...Object.keys(oldCards), ...Object.keys(newCards)])) {
60
+ const oldNames = oldCards[sliceName] || [];
61
+ const newNames = newCards[sliceName] || [];
62
+ const oldCounts = new Map();
63
+ const newCounts = new Map();
64
+ for (const n of oldNames) oldCounts.set(n, (oldCounts.get(n) || 0) + 1);
65
+ for (const n of newNames) newCounts.set(n, (newCounts.get(n) || 0) + 1);
66
+ const allNames = new Set([...oldCounts.keys(), ...newCounts.keys()]);
67
+ let added = 0, removed = 0;
68
+ for (const n of allNames) {
69
+ const o = oldCounts.get(n) || 0;
70
+ const c = newCounts.get(n) || 0;
71
+ if (c > o) added += c - o;
72
+ if (o > c) removed += o - c;
73
+ }
74
+ if (added === 0 && removed === 0) continue;
75
+ const net = newNames.length - oldNames.length;
76
+ if (net === 0) {
77
+ const word = added === 1 ? 'card' : 'cards';
78
+ lines.push(chalk.yellow(` ~ ${sliceName}: ${added} ${word} renamed`));
79
+ } else {
80
+ if (added) lines.push(chalk.green(` + ${sliceName}: ${added} ${added === 1 ? 'card' : 'cards'}`));
81
+ if (removed) lines.push(chalk.red(` - ${sliceName}: ${removed} ${removed === 1 ? 'card' : 'cards'}`));
65
82
  }
66
83
  }
67
84
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "storymaps",
3
- "version": "1.2.1",
3
+ "version": "1.2.2",
4
4
  "description": "CLI tool for storymaps.io - import, export, validate, and manage user story maps from the terminal",
5
5
  "type": "module",
6
6
  "bin": {