@mdsmith/cli 0.13.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 (3) hide show
  1. package/README.md +45 -0
  2. package/bin/mdsmith.js +98 -0
  3. package/package.json +41 -0
package/README.md ADDED
@@ -0,0 +1,45 @@
1
+ # @mdsmith/cli
2
+
3
+ Fast, auto-fixing Markdown linter and formatter for docs, READMEs,
4
+ and AI-generated content. This is the npm distribution of the Go
5
+ binary published at
6
+ <https://github.com/jeduden/mdsmith>.
7
+
8
+ The npm root is `@mdsmith/cli` because the unscoped `mdsmith`
9
+ name on npm is owned by another project. The installed binary
10
+ is still called `mdsmith` (via the package's `bin` field).
11
+
12
+ ## Install
13
+
14
+ ```bash
15
+ npm install -g @mdsmith/cli
16
+ # or, without a global install:
17
+ npx @mdsmith/cli --help
18
+ ```
19
+
20
+ The package ships a small Node.js shim (`bin/mdsmith.js`) that locates
21
+ the prebuilt binary from one of these platform sub-packages and execs
22
+ it:
23
+
24
+ - `@mdsmith/linux-x64`
25
+ - `@mdsmith/linux-arm64`
26
+ - `@mdsmith/darwin-x64`
27
+ - `@mdsmith/darwin-arm64`
28
+ - `@mdsmith/win32-x64`
29
+
30
+ npm installs only the sub-package matching `process.platform` and
31
+ `process.arch`. There is no postinstall network call, so the package
32
+ works in offline / air-gapped CI.
33
+
34
+ ## Versioning
35
+
36
+ Every npm release matches a `vX.Y.Z` git tag in the upstream repo.
37
+ `mdsmith version` reports the same value on every distribution
38
+ channel (npm, PyPI, asdf, mise, the GitHub release, the VS Code
39
+ marketplaces).
40
+
41
+ ## Other channels
42
+
43
+ See [docs/guides/install.md](https://github.com/jeduden/mdsmith/blob/main/docs/guides/install.md)
44
+ for the full list (PyPI / pip / uvx, asdf, mise, direct download,
45
+ VS Code Marketplace, Open VSX).
package/bin/mdsmith.js ADDED
@@ -0,0 +1,98 @@
1
+ #!/usr/bin/env node
2
+ // mdsmith npm shim — resolves the prebuilt binary from the platform
3
+ // optional-dependency that npm installed alongside this package, then
4
+ // execs it with the user's argv. No postinstall hook runs, so the
5
+ // shim works in offline / air-gapped CI and on hosts that ban network
6
+ // calls during npm install. The Go binary embeds the same tag at
7
+ // build time, so `mdsmith version` reports the published version on
8
+ // every channel.
9
+
10
+ "use strict";
11
+
12
+ const PLATFORM_PACKAGES = Object.freeze({
13
+ "linux-x64": "@mdsmith/linux-x64",
14
+ "linux-arm64": "@mdsmith/linux-arm64",
15
+ "darwin-x64": "@mdsmith/darwin-x64",
16
+ "darwin-arm64": "@mdsmith/darwin-arm64",
17
+ "win32-x64": "@mdsmith/win32-x64",
18
+ });
19
+
20
+ function platformPackage(platform, arch) {
21
+ return PLATFORM_PACKAGES[`${platform}-${arch}`];
22
+ }
23
+
24
+ function binaryRelativePath(platform) {
25
+ return `bin/mdsmith${platform === "win32" ? ".exe" : ""}`;
26
+ }
27
+
28
+ function unsupportedMessage(platform, arch) {
29
+ const supported = Object.keys(PLATFORM_PACKAGES).join(", ");
30
+ return (
31
+ `mdsmith: unsupported platform ${platform}-${arch}. ` +
32
+ `Supported: ${supported}. ` +
33
+ `Direct downloads are available at ` +
34
+ `https://github.com/jeduden/mdsmith/releases.`
35
+ );
36
+ }
37
+
38
+ function resolveBinary(platform, arch, resolve) {
39
+ const pkg = platformPackage(platform, arch);
40
+ if (!pkg) {
41
+ const err = new Error(unsupportedMessage(platform, arch));
42
+ err.code = "MDSMITH_UNSUPPORTED_PLATFORM";
43
+ throw err;
44
+ }
45
+ try {
46
+ return resolve(`${pkg}/${binaryRelativePath(platform)}`);
47
+ } catch (cause) {
48
+ // optionalDependencies install best-effort, so a host whose
49
+ // platform-arch combo wasn't picked up by npm sees a clear
50
+ // diagnostic instead of a require-resolve stack trace.
51
+ const err = new Error(
52
+ `mdsmith: missing platform package ${pkg}. ` +
53
+ `Reinstall with --force or download a binary from ` +
54
+ `https://github.com/jeduden/mdsmith/releases.`
55
+ );
56
+ err.code = "MDSMITH_PLATFORM_PACKAGE_MISSING";
57
+ err.cause = cause;
58
+ throw err;
59
+ }
60
+ }
61
+
62
+ function main() {
63
+ const { spawnSync } = require("child_process");
64
+ let bin;
65
+ try {
66
+ bin = resolveBinary(process.platform, process.arch, require.resolve);
67
+ } catch (err) {
68
+ process.stderr.write(`${err.message}\n`);
69
+ process.exit(1);
70
+ return;
71
+ }
72
+ const result = spawnSync(bin, process.argv.slice(2), { stdio: "inherit" });
73
+ if (result.error) {
74
+ process.stderr.write(`mdsmith: ${result.error.message}\n`);
75
+ process.exit(1);
76
+ return;
77
+ }
78
+ // spawnSync sets `signal` instead of `status` when the child was
79
+ // killed; mirror node-style exit codes (128 + signum) so users can
80
+ // chain mdsmith inside a shell pipeline that distinguishes signals
81
+ // from natural exits.
82
+ if (result.signal) {
83
+ process.exit(128);
84
+ return;
85
+ }
86
+ process.exit(result.status === null ? 1 : result.status);
87
+ }
88
+
89
+ module.exports = {
90
+ PLATFORM_PACKAGES,
91
+ platformPackage,
92
+ binaryRelativePath,
93
+ resolveBinary,
94
+ };
95
+
96
+ if (require.main === module) {
97
+ main();
98
+ }
package/package.json ADDED
@@ -0,0 +1,41 @@
1
+ {
2
+ "name": "@mdsmith/cli",
3
+ "version": "0.13.0",
4
+ "description": "Fast, auto-fixing Markdown linter and formatter for docs, READMEs, and AI-generated content.",
5
+ "license": "MIT",
6
+ "homepage": "https://github.com/jeduden/mdsmith",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/jeduden/mdsmith"
10
+ },
11
+ "keywords": [
12
+ "markdown",
13
+ "linter",
14
+ "formatter",
15
+ "mdsmith",
16
+ "docs"
17
+ ],
18
+ "bin": {
19
+ "mdsmith": "bin/mdsmith.js"
20
+ },
21
+ "files": [
22
+ "bin/mdsmith.js"
23
+ ],
24
+ "engines": {
25
+ "node": ">=18"
26
+ },
27
+ "optionalDependencies": {
28
+ "@mdsmith/linux-x64": "0.13.0",
29
+ "@mdsmith/linux-arm64": "0.13.0",
30
+ "@mdsmith/darwin-x64": "0.13.0",
31
+ "@mdsmith/darwin-arm64": "0.13.0",
32
+ "@mdsmith/win32-x64": "0.13.0"
33
+ },
34
+ "scripts": {
35
+ "test": "bun test"
36
+ },
37
+ "devDependencies": {
38
+ "@types/bun": "^1.1.0",
39
+ "@types/node": "^20.11.0"
40
+ }
41
+ }