drft-cli 0.1.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.
- package/README.md +30 -0
- package/bin/drft +23 -0
- package/install.js +110 -0
- package/package.json +26 -0
package/README.md
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# drft
|
|
2
|
+
|
|
3
|
+
A structural integrity checker for markdown directories.
|
|
4
|
+
|
|
5
|
+
This is the npm distribution of [drft](https://github.com/johnmdonahue/drft-cli). It downloads the prebuilt binary for your platform.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install drft-cli
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npx drft check
|
|
17
|
+
npx drft lock
|
|
18
|
+
npx drft graph
|
|
19
|
+
npx drft impact setup.md
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
See the [full documentation](https://github.com/johnmdonahue/drft-cli) for all commands and options.
|
|
23
|
+
|
|
24
|
+
## Supported platforms
|
|
25
|
+
|
|
26
|
+
- macOS (arm64, x64)
|
|
27
|
+
- Linux (arm64, x64)
|
|
28
|
+
- Windows (x64)
|
|
29
|
+
|
|
30
|
+
For other platforms, install from source: `cargo install drft-cli`
|
package/bin/drft
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// Thin wrapper that exec's the downloaded drft binary.
|
|
4
|
+
|
|
5
|
+
const { execFileSync } = require("child_process");
|
|
6
|
+
const path = require("path");
|
|
7
|
+
const fs = require("fs");
|
|
8
|
+
|
|
9
|
+
const ext = process.platform === "win32" ? ".exe" : "";
|
|
10
|
+
const binPath = path.join(__dirname, `drft${ext}`);
|
|
11
|
+
|
|
12
|
+
if (!fs.existsSync(binPath)) {
|
|
13
|
+
console.error(
|
|
14
|
+
"drft: binary not found. Run `npm rebuild drft` or install from source: cargo install drft-cli"
|
|
15
|
+
);
|
|
16
|
+
process.exit(2);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
try {
|
|
20
|
+
execFileSync(binPath, process.argv.slice(2), { stdio: "inherit" });
|
|
21
|
+
} catch (err) {
|
|
22
|
+
process.exit(err.status || 1);
|
|
23
|
+
}
|
package/install.js
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// Downloads the correct drft binary for the current platform from GitHub Releases.
|
|
4
|
+
// Runs as a postinstall script.
|
|
5
|
+
|
|
6
|
+
const { execSync } = require("child_process");
|
|
7
|
+
const fs = require("fs");
|
|
8
|
+
const path = require("path");
|
|
9
|
+
const https = require("https");
|
|
10
|
+
|
|
11
|
+
const VERSION = require("./package.json").version;
|
|
12
|
+
const REPO = "johnmdonahue/drft-cli";
|
|
13
|
+
|
|
14
|
+
const PLATFORMS = {
|
|
15
|
+
"darwin-arm64": `drft-cli-aarch64-apple-darwin.tar.xz`,
|
|
16
|
+
"darwin-x64": `drft-cli-x86_64-apple-darwin.tar.xz`,
|
|
17
|
+
"linux-arm64": `drft-cli-aarch64-unknown-linux-gnu.tar.xz`,
|
|
18
|
+
"linux-x64": `drft-cli-x86_64-unknown-linux-gnu.tar.xz`,
|
|
19
|
+
"win32-x64": `drft-cli-x86_64-pc-windows-msvc.zip`,
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
function getPlatformKey() {
|
|
23
|
+
const platform = process.platform;
|
|
24
|
+
const arch = process.arch;
|
|
25
|
+
return `${platform}-${arch}`;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function getDownloadUrl(assetName) {
|
|
29
|
+
return `https://github.com/${REPO}/releases/download/v${VERSION}/${assetName}`;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function download(url) {
|
|
33
|
+
return new Promise((resolve, reject) => {
|
|
34
|
+
const follow = (url) => {
|
|
35
|
+
https.get(url, { headers: { "User-Agent": "drft-npm" } }, (res) => {
|
|
36
|
+
if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
|
|
37
|
+
follow(res.headers.location);
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
if (res.statusCode !== 200) {
|
|
41
|
+
reject(new Error(`Download failed: HTTP ${res.statusCode} from ${url}`));
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
const chunks = [];
|
|
45
|
+
res.on("data", (chunk) => chunks.push(chunk));
|
|
46
|
+
res.on("end", () => resolve(Buffer.concat(chunks)));
|
|
47
|
+
res.on("error", reject);
|
|
48
|
+
}).on("error", reject);
|
|
49
|
+
};
|
|
50
|
+
follow(url);
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
async function main() {
|
|
55
|
+
const platformKey = getPlatformKey();
|
|
56
|
+
const assetName = PLATFORMS[platformKey];
|
|
57
|
+
|
|
58
|
+
if (!assetName) {
|
|
59
|
+
console.error(
|
|
60
|
+
`drft: unsupported platform ${platformKey}. ` +
|
|
61
|
+
`Supported: ${Object.keys(PLATFORMS).join(", ")}. ` +
|
|
62
|
+
`Install from source: cargo install drft-cli`
|
|
63
|
+
);
|
|
64
|
+
process.exit(0); // Don't fail the install — just won't have the binary
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const binDir = path.join(__dirname, "bin");
|
|
68
|
+
const binPath = path.join(binDir, process.platform === "win32" ? "drft.exe" : "drft");
|
|
69
|
+
|
|
70
|
+
// Skip if binary already exists (e.g., reinstall)
|
|
71
|
+
if (fs.existsSync(binPath)) {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const url = getDownloadUrl(assetName);
|
|
76
|
+
console.log(`drft: downloading ${platformKey} binary...`);
|
|
77
|
+
|
|
78
|
+
try {
|
|
79
|
+
const data = await download(url);
|
|
80
|
+
|
|
81
|
+
// Write archive to temp file
|
|
82
|
+
const tmpFile = path.join(binDir, assetName);
|
|
83
|
+
fs.writeFileSync(tmpFile, data);
|
|
84
|
+
|
|
85
|
+
// Extract
|
|
86
|
+
if (assetName.endsWith(".tar.xz")) {
|
|
87
|
+
execSync(`tar xf "${tmpFile}" -C "${binDir}" --strip-components=1`, { stdio: "pipe" });
|
|
88
|
+
} else if (assetName.endsWith(".zip")) {
|
|
89
|
+
execSync(`unzip -o "${tmpFile}" -d "${binDir}"`, { stdio: "pipe" });
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// Clean up archive
|
|
93
|
+
fs.unlinkSync(tmpFile);
|
|
94
|
+
|
|
95
|
+
// Ensure executable
|
|
96
|
+
if (process.platform !== "win32") {
|
|
97
|
+
fs.chmodSync(binPath, 0o755);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
console.log("drft: installed successfully");
|
|
101
|
+
} catch (err) {
|
|
102
|
+
console.error(
|
|
103
|
+
`drft: failed to download binary (${err.message}). ` +
|
|
104
|
+
`Install from source: cargo install drft-cli`
|
|
105
|
+
);
|
|
106
|
+
process.exit(0); // Don't fail the install
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
main();
|
package/package.json
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "drft-cli",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "A structural integrity checker for markdown directories",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/johnmdonahue/drft-cli"
|
|
9
|
+
},
|
|
10
|
+
"homepage": "https://github.com/johnmdonahue/drft-cli",
|
|
11
|
+
"keywords": ["markdown", "linter", "dependency-graph", "documentation"],
|
|
12
|
+
"bin": {
|
|
13
|
+
"drft": "bin/drft"
|
|
14
|
+
},
|
|
15
|
+
"scripts": {
|
|
16
|
+
"postinstall": "node install.js"
|
|
17
|
+
},
|
|
18
|
+
"engines": {
|
|
19
|
+
"node": ">=18"
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"bin/",
|
|
23
|
+
"install.js",
|
|
24
|
+
"README.md"
|
|
25
|
+
]
|
|
26
|
+
}
|