@jackchuka/mdschema 0.0.1

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/bin/cli.js ADDED
@@ -0,0 +1,26 @@
1
+ #!/usr/bin/env node
2
+
3
+ "use strict";
4
+
5
+ const { spawnSync } = require("child_process");
6
+ const { getBinaryPath } = require("../lib/platform");
7
+
8
+ const binary = getBinaryPath();
9
+ const result = spawnSync(binary, process.argv.slice(2), {
10
+ stdio: "inherit",
11
+ env: process.env,
12
+ });
13
+
14
+ if (result.error) {
15
+ if (result.error.code === "ENOENT") {
16
+ console.error(
17
+ `mdschema binary not found at ${binary}.\n` +
18
+ "Try reinstalling: npm install @jackchuka/mdschema"
19
+ );
20
+ } else {
21
+ console.error(`Failed to run mdschema: ${result.error.message}`);
22
+ }
23
+ process.exit(1);
24
+ }
25
+
26
+ process.exit(result.status ?? 1);
package/install.js ADDED
@@ -0,0 +1,96 @@
1
+ "use strict";
2
+
3
+ const https = require("https");
4
+ const fs = require("fs");
5
+ const path = require("path");
6
+ const { execSync } = require("child_process");
7
+
8
+ const { getBinaryPath, getGoReleaserTarget } = require("./lib/platform");
9
+
10
+ // Check if binary already exists from optionalDependencies
11
+ try {
12
+ const existing = getBinaryPath();
13
+ if (fs.existsSync(existing)) {
14
+ process.exit(0);
15
+ }
16
+ } catch {
17
+ // Expected when platform package not installed — continue to download
18
+ }
19
+
20
+ const pkg = require("./package.json");
21
+ const version = pkg.version;
22
+
23
+ const target = getGoReleaserTarget();
24
+ const ext = process.platform === "win32" ? ".exe" : "";
25
+ const archiveName = `mdschema_${version}_${target.os}_${target.arch}${target.ext}`;
26
+ const url = `https://github.com/jackchuka/mdschema/releases/download/v${version}/${archiveName}`;
27
+ const binDir = path.join(__dirname, "bin");
28
+ const binaryPath = path.join(binDir, `mdschema${ext}`);
29
+
30
+ function fetch(url, redirectsLeft = 5) {
31
+ return new Promise((resolve, reject) => {
32
+ https
33
+ .get(url, (res) => {
34
+ if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
35
+ if (redirectsLeft <= 0) {
36
+ reject(new Error("Too many redirects"));
37
+ return;
38
+ }
39
+ fetch(res.headers.location, redirectsLeft - 1).then(resolve, reject);
40
+ return;
41
+ }
42
+ if (res.statusCode !== 200) {
43
+ reject(new Error(`Download failed: HTTP ${res.statusCode} for ${url}`));
44
+ return;
45
+ }
46
+ const chunks = [];
47
+ res.on("data", (chunk) => chunks.push(chunk));
48
+ res.on("end", () => resolve(Buffer.concat(chunks)));
49
+ res.on("error", reject);
50
+ })
51
+ .on("error", reject);
52
+ });
53
+ }
54
+
55
+ function extractTarGz(buffer) {
56
+ fs.mkdirSync(binDir, { recursive: true });
57
+ const tmpFile = path.join(binDir, "download.tar.gz");
58
+ fs.writeFileSync(tmpFile, buffer);
59
+ // GoReleaser archives place the binary at the root (no subdirectory wrapper)
60
+ execSync(`tar xzf "${tmpFile}" -C "${binDir}" mdschema`, { stdio: "pipe" });
61
+ fs.unlinkSync(tmpFile);
62
+ }
63
+
64
+ function extractZip(buffer) {
65
+ fs.mkdirSync(binDir, { recursive: true });
66
+ const tmpFile = path.join(binDir, "download.zip");
67
+ fs.writeFileSync(tmpFile, buffer);
68
+ execSync(`powershell -command "Expand-Archive -Force '${tmpFile}' '${binDir}'"`, {
69
+ stdio: "pipe",
70
+ });
71
+ fs.unlinkSync(tmpFile);
72
+ }
73
+
74
+ async function main() {
75
+ console.log(`Downloading mdschema v${version} for ${target.os}/${target.arch}...`);
76
+
77
+ const buffer = await fetch(url);
78
+
79
+ if (target.ext === ".zip") {
80
+ extractZip(buffer);
81
+ } else {
82
+ extractTarGz(buffer);
83
+ }
84
+
85
+ if (process.platform !== "win32") {
86
+ fs.chmodSync(binaryPath, 0o755);
87
+ }
88
+
89
+ console.log(`mdschema v${version} installed successfully.`);
90
+ }
91
+
92
+ main().catch((err) => {
93
+ console.error(`Failed to install mdschema: ${err.message}`);
94
+ console.error("Try installing manually: https://github.com/jackchuka/mdschema/releases");
95
+ process.exit(1);
96
+ });
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+
3
+ const path = require("path");
4
+
5
+ const PLATFORMS = {
6
+ darwin: {
7
+ arm64: "@jackchuka/mdschema-darwin-arm64",
8
+ x64: "@jackchuka/mdschema-darwin-x64",
9
+ },
10
+ linux: {
11
+ arm64: "@jackchuka/mdschema-linux-arm64",
12
+ x64: "@jackchuka/mdschema-linux-x64",
13
+ },
14
+ win32: {
15
+ arm64: "@jackchuka/mdschema-windows-arm64",
16
+ x64: "@jackchuka/mdschema-windows-x64",
17
+ },
18
+ };
19
+
20
+ function getPackageName() {
21
+ const platform = process.platform;
22
+ const arch = process.arch;
23
+
24
+ const archMap = PLATFORMS[platform];
25
+ if (!archMap) {
26
+ throw new Error(
27
+ `Unsupported platform: ${platform}. mdschema supports darwin, linux, and win32.`
28
+ );
29
+ }
30
+
31
+ const pkg = archMap[arch];
32
+ if (!pkg) {
33
+ throw new Error(
34
+ `Unsupported architecture: ${arch} on ${platform}. mdschema supports arm64 and x64.`
35
+ );
36
+ }
37
+
38
+ return pkg;
39
+ }
40
+
41
+ function getBinaryPath() {
42
+ const ext = process.platform === "win32" ? ".exe" : "";
43
+ const pkg = getPackageName();
44
+
45
+ // Try to resolve from optionalDependencies first
46
+ try {
47
+ return require.resolve(`${pkg}/bin/mdschema${ext}`);
48
+ } catch {
49
+ // Fall back to locally downloaded binary (from postinstall)
50
+ return path.join(__dirname, "..", "bin", `mdschema${ext}`);
51
+ }
52
+ }
53
+
54
+ // Map Node.js platform/arch to GoReleaser naming for download URLs
55
+ function getGoReleaserTarget() {
56
+ const platform = process.platform;
57
+ const arch = process.arch;
58
+
59
+ const osMap = { darwin: "darwin", linux: "linux", win32: "windows" };
60
+ const archMap = { arm64: "arm64", x64: "amd64" };
61
+
62
+ const os = osMap[platform];
63
+ const goarch = archMap[arch];
64
+
65
+ if (!os || !goarch) {
66
+ throw new Error(`Unsupported platform: ${platform}/${arch}`);
67
+ }
68
+
69
+ return { os, arch: goarch, ext: platform === "win32" ? ".zip" : ".tar.gz" };
70
+ }
71
+
72
+ module.exports = { getBinaryPath, getPackageName, getGoReleaserTarget };
package/package.json ADDED
@@ -0,0 +1,40 @@
1
+ {
2
+ "name": "@jackchuka/mdschema",
3
+ "version": "0.0.1",
4
+ "description": "A declarative schema-based Markdown documentation validator",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/jackchuka/mdschema.git"
9
+ },
10
+ "homepage": "https://github.com/jackchuka/mdschema",
11
+ "keywords": [
12
+ "markdown",
13
+ "validator",
14
+ "schema",
15
+ "documentation",
16
+ "lint"
17
+ ],
18
+ "engines": {
19
+ "node": ">=14"
20
+ },
21
+ "files": [
22
+ "bin/cli.js",
23
+ "lib/",
24
+ "install.js"
25
+ ],
26
+ "bin": {
27
+ "mdschema": "bin/cli.js"
28
+ },
29
+ "scripts": {
30
+ "postinstall": "node install.js"
31
+ },
32
+ "optionalDependencies": {
33
+ "@jackchuka/mdschema-darwin-arm64": "0.0.0",
34
+ "@jackchuka/mdschema-darwin-x64": "0.0.0",
35
+ "@jackchuka/mdschema-linux-arm64": "0.0.0",
36
+ "@jackchuka/mdschema-linux-x64": "0.0.0",
37
+ "@jackchuka/mdschema-windows-arm64": "0.0.0",
38
+ "@jackchuka/mdschema-windows-x64": "0.0.0"
39
+ }
40
+ }