storymaps 1.2.6 → 1.2.7

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.
@@ -29,14 +29,17 @@ export async function diffCommand(source, target, opts) {
29
29
  const sourcePath = resolve(source || 'storymap.yml');
30
30
  const sourceYaml = await readAndNormalise(sourcePath);
31
31
 
32
- let targetYaml;
33
- let targetLabel;
32
+ // Show changes from old to new. Two local files go from the first to the second. Against the
33
+ // remote, the local file is the new side, so the diff shows what a push would change.
34
+ let oldYaml, newYaml, oldLabel, newLabel;
34
35
 
35
36
  if (target) {
36
37
  // Two local files
37
38
  const targetPath = resolve(target);
38
- targetYaml = await readAndNormalise(targetPath);
39
- targetLabel = targetPath;
39
+ oldYaml = sourceYaml;
40
+ newYaml = await readAndNormalise(targetPath);
41
+ oldLabel = sourcePath;
42
+ newLabel = targetPath;
40
43
  } else {
41
44
  // Local vs remote
42
45
  const { id, baseUrl } = await resolveTarget(undefined, sourcePath);
@@ -44,11 +47,13 @@ export async function diffCommand(source, target, opts) {
44
47
  // Normalise remote YAML the same way
45
48
  const obj = jsyaml.load(data);
46
49
  const json = yamlObjToJson(obj);
47
- targetYaml = exportToYaml(json);
48
- targetLabel = `${baseUrl}/${id}`;
50
+ oldYaml = exportToYaml(json);
51
+ newYaml = sourceYaml;
52
+ oldLabel = `remote: ${baseUrl}/${id}`;
53
+ newLabel = `local: ${sourcePath}`;
49
54
  }
50
55
 
51
- const changes = diffLines(sourceYaml, targetYaml);
56
+ const changes = diffLines(oldYaml, newYaml);
52
57
  const hasChanges = changes.some(c => c.added || c.removed);
53
58
 
54
59
  if (!hasChanges) {
@@ -57,7 +62,7 @@ export async function diffCommand(source, target, opts) {
57
62
  }
58
63
 
59
64
  if (!opts.full) {
60
- printChangeSummary(sourceYaml, targetYaml);
65
+ printChangeSummary(oldYaml, newYaml);
61
66
  console.log(chalk.dim(`\nRun ${chalk.cyan('storymaps diff --full')} for the full file diff.`));
62
67
  return;
63
68
  }
@@ -65,25 +70,25 @@ export async function diffCommand(source, target, opts) {
65
70
  // --full: show line-level diff
66
71
  const CONTEXT = 3;
67
72
  const lines = [];
68
- let srcLine = 1;
69
- let dstLine = 1;
73
+ let oldLine = 1;
74
+ let newLine = 1;
70
75
  for (const part of changes) {
71
76
  for (const text of part.value.replace(/\n$/, '').split('\n')) {
72
77
  if (part.added) {
73
- lines.push({ tag: '+', text, src: null, dst: dstLine++ });
78
+ lines.push({ tag: '+', text, oldNum: null, newNum: newLine++ });
74
79
  } else if (part.removed) {
75
- lines.push({ tag: '-', text, src: srcLine++, dst: null });
80
+ lines.push({ tag: '-', text, oldNum: oldLine++, newNum: null });
76
81
  } else {
77
- lines.push({ tag: ' ', text, src: srcLine++, dst: dstLine++ });
82
+ lines.push({ tag: ' ', text, oldNum: oldLine++, newNum: newLine++ });
78
83
  }
79
84
  }
80
85
  }
81
86
 
82
- const width = String(Math.max(srcLine, dstLine)).length;
87
+ const width = String(Math.max(oldLine, newLine)).length;
83
88
  const pad = n => n === null ? ' '.repeat(width) : String(n).padStart(width);
84
89
 
85
- console.log(chalk.bold(`--- local: ${sourcePath}`));
86
- console.log(chalk.bold(`+++ remote: ${targetLabel}`));
90
+ console.log(chalk.bold(`--- ${oldLabel}`));
91
+ console.log(chalk.bold(`+++ ${newLabel}`));
87
92
 
88
93
  let lastPrinted = -1;
89
94
  for (let i = 0; i < lines.length; i++) {
@@ -92,8 +97,8 @@ export async function diffCommand(source, target, opts) {
92
97
  if (lastPrinted !== -1 && i - lastPrinted > 1) {
93
98
  console.log(chalk.dim(`${'·'.repeat(width * 2 + 5)}`));
94
99
  }
95
- const { tag, text, src, dst } = lines[i];
96
- const num = chalk.dim(`${pad(src)} ${pad(dst)}`);
100
+ const { tag, text, oldNum, newNum } = lines[i];
101
+ const num = chalk.dim(`${pad(oldNum)} ${pad(newNum)}`);
97
102
  if (tag === '+') console.log(`${num} ${chalk.green(`+ ${text}`)}`);
98
103
  else if (tag === '-') console.log(`${num} ${chalk.red(`- ${text}`)}`);
99
104
  else console.log(`${num} ${chalk.dim(` ${text}`)}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "storymaps",
3
- "version": "1.2.6",
3
+ "version": "1.2.7",
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": {