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.
- package/lib/commands/push.js +10 -1
- package/lib/util/summary.js +34 -17
- package/package.json +1 -1
package/lib/commands/push.js
CHANGED
|
@@ -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;
|
package/lib/util/summary.js
CHANGED
|
@@ -42,26 +42,43 @@ export function changeSummary(oldYaml, newYaml) {
|
|
|
42
42
|
lines.push(chalk.red(` - slice: ${s}`));
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
//
|
|
46
|
-
const
|
|
47
|
-
const
|
|
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
|
|
50
|
-
|
|
51
|
-
|
|
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
|
|
55
|
+
return result;
|
|
54
56
|
};
|
|
55
|
-
const
|
|
56
|
-
const
|
|
57
|
-
for (const
|
|
58
|
-
const
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
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
|
|