@barmark/cli 0.1.0 → 0.1.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/CHANGELOG.md CHANGED
@@ -6,6 +6,28 @@ package uses [semantic versioning](https://semver.org/).
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [0.1.2] - 2026-11-03
10
+
11
+ Uses `barmark` 0.10.0 and `@barmark/render` 0.7.3, pinned exactly. No
12
+ change to the command.
13
+
14
+ ## [0.1.1] - 2026-11-02
15
+
16
+ Uses `barmark` 0.9.0 and `@barmark/render` 0.7.2, pinned exactly: charts
17
+ may now write a swing amount (`feel: swing 58%`), and `render` shows it.
18
+
19
+ ### Fixed
20
+
21
+ - **`format --write` replaces each file whole.** The new text goes to a
22
+ temporary file beside the chart, with its permissions, which then
23
+ takes its name; a failure part-way (a full disk, a folder it can't
24
+ write) leaves the chart as it was and reports "cannot write <file>".
25
+ - **`transpose --out` writes nothing when the chart has errors**, and
26
+ says "<file> not written: the chart has errors".
27
+ - **An unknown flag reads `unknown flag "--strct"`**, with how to pass a
28
+ file name that starts with `-`, instead of Node's message, which ended
29
+ on an unbalanced quote.
30
+
9
31
  ## [0.1.0] - 2026-11-02
10
32
 
11
33
  The first release of the `barmark` command. Uses `barmark` 0.8.0 and
@@ -16,5 +38,7 @@ The first release of the `barmark` command. Uses `barmark` 0.8.0 and
16
38
  - **The `barmark` command:** `check`, `format`, `render` and `transpose`
17
39
  for `.chart.md` files, on npm and as standalone binaries.
18
40
 
19
- [Unreleased]: https://github.com/kevinpeckham/barmark/compare/cli-v0.1.0...HEAD
41
+ [Unreleased]: https://github.com/kevinpeckham/barmark/compare/cli-v0.1.2...HEAD
42
+ [0.1.2]: https://github.com/kevinpeckham/barmark/compare/cli-v0.1.1...cli-v0.1.2
43
+ [0.1.1]: https://github.com/kevinpeckham/barmark/compare/cli-v0.1.0...cli-v0.1.1
20
44
  [0.1.0]: https://github.com/kevinpeckham/barmark/releases/tag/cli-v0.1.0
package/dist/args.js CHANGED
@@ -6,6 +6,10 @@ export function parseFlags(args, options) {
6
6
  return parseArgs({ args, options, allowPositionals: true, allowNegative: false, strict: true });
7
7
  }
8
8
  catch (error) {
9
+ // Node's own message for this one ends on an unbalanced quote.
10
+ const unknown = /^Unknown option '([^']+)'/.exec(String(error?.message));
11
+ if (unknown)
12
+ throw new UsageError(`unknown flag "${unknown[1]}"; a file name starting with - goes after --`);
9
13
  throw new UsageError(error instanceof Error ? (error.message.split("\n")[0] ?? "") : String(error));
10
14
  }
11
15
  }
package/dist/format.js CHANGED
@@ -1,10 +1,9 @@
1
1
  /** barmark format: charts in standard form, printed, rewritten in place, or checked. */
2
- import { writeFileSync } from "node:fs";
3
- import { resolve } from "node:path";
4
2
  import { printChart } from "barmark";
5
3
  import { parseFlags } from "./args.js";
6
4
  import { readCharts } from "./inputs.js";
7
5
  import { UsageError } from "./io.js";
6
+ import { replaceFile } from "./output.js";
8
7
  function refuseMisuse(flags, positionals) {
9
8
  if (flags.write && flags.check)
10
9
  throw new UsageError("--write and --check can't be used together");
@@ -20,7 +19,7 @@ function rewriteAll(charts, write, io) {
20
19
  continue;
21
20
  changed++;
22
21
  if (write)
23
- writeFileSync(resolve(io.cwd, path), canonical);
22
+ replaceFile(path, canonical, io);
24
23
  io.stdout(`${write ? "formatted" : "would format"} ${path}\n`);
25
24
  }
26
25
  return changed;
package/dist/output.js CHANGED
@@ -1,6 +1,7 @@
1
1
  /** Where a command's result goes: stdout, or the file named by --out. */
2
- import { writeFileSync } from "node:fs";
3
- import { resolve } from "node:path";
2
+ import { randomBytes } from "node:crypto";
3
+ import { renameSync, rmSync, statSync, writeFileSync } from "node:fs";
4
+ import { basename, dirname, join, resolve } from "node:path";
4
5
  import { UsageError } from "./io.js";
5
6
  export function writeOutput(text, out, io) {
6
7
  if (out === undefined) {
@@ -14,6 +15,28 @@ export function writeOutput(text, out, io) {
14
15
  throw new UsageError(`cannot write ${out}`);
15
16
  }
16
17
  }
18
+ /**
19
+ * Replaces a file whole: the text goes to a temporary file beside it, with
20
+ * its permissions, which then takes its name. A failure part-way leaves the
21
+ * old file as it was, never half-written. The temporary name is random and
22
+ * opened exclusively ("wx"), so nothing already there, a planted link
23
+ * included, is ever written through or removed.
24
+ */
25
+ export function replaceFile(path, text, io) {
26
+ const target = resolve(io.cwd, path);
27
+ const temp = join(dirname(target), `.${basename(target)}.${randomBytes(8).toString("hex")}.tmp`);
28
+ let created = false;
29
+ try {
30
+ writeFileSync(temp, text, { flag: "wx", mode: statSync(target).mode & 0o777 });
31
+ created = true;
32
+ renameSync(temp, target);
33
+ }
34
+ catch {
35
+ if (created)
36
+ rmSync(temp, { force: true });
37
+ throw new UsageError(`cannot write ${path}`);
38
+ }
39
+ }
17
40
  /** The one chart a single-chart command reads. */
18
41
  export function onlyChart(charts, command) {
19
42
  const [chart, ...rest] = charts;
package/dist/transpose.js CHANGED
@@ -33,6 +33,10 @@ export async function transpose(args, io) {
33
33
  const result = transposeChart(text, by);
34
34
  for (const d of result.diagnostics)
35
35
  io.stderr(`${textLine(path, d)}\n`);
36
- writeOutput(result.text, values.out, io);
37
- return result.diagnostics.some((d) => d.severity === "error") ? 1 : 0;
36
+ const failed = result.diagnostics.some((d) => d.severity === "error");
37
+ if (failed && values.out !== undefined)
38
+ io.stderr(`${values.out} not written: the chart has errors\n`);
39
+ else
40
+ writeOutput(result.text, values.out, io);
41
+ return failed ? 1 : 0;
38
42
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@barmark/cli",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "The barmark command: check, format, render and transpose barmark chord charts (.chart.md) from the terminal and in CI.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -37,8 +37,8 @@
37
37
  "url": "https://github.com/kevinpeckham/barmark/issues"
38
38
  },
39
39
  "dependencies": {
40
- "barmark": "0.8.0",
41
- "@barmark/render": "0.7.1"
40
+ "barmark": "0.10.0",
41
+ "@barmark/render": "0.7.3"
42
42
  },
43
43
  "scripts": {
44
44
  "build": "rm -rf dist && tsc -p tsconfig.build.json",