@shinagawa-web/gomarklint 2.7.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/cli.js +14 -0
- package/install.js +132 -0
- package/package.json +31 -0
package/cli.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
|
|
4
|
+
const { execFileSync } = require("child_process");
|
|
5
|
+
const path = require("path");
|
|
6
|
+
|
|
7
|
+
const ext = process.platform === "win32" ? ".exe" : "";
|
|
8
|
+
const bin = path.join(__dirname, "gomarklint" + ext);
|
|
9
|
+
|
|
10
|
+
try {
|
|
11
|
+
execFileSync(bin, process.argv.slice(2), { stdio: "inherit" });
|
|
12
|
+
} catch (e) {
|
|
13
|
+
process.exitCode = e.status || 1;
|
|
14
|
+
}
|
package/install.js
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const https = require("https");
|
|
4
|
+
const fs = require("fs");
|
|
5
|
+
const path = require("path");
|
|
6
|
+
const crypto = require("crypto");
|
|
7
|
+
const { execSync } = require("child_process");
|
|
8
|
+
|
|
9
|
+
const REPO = "shinagawa-web/gomarklint";
|
|
10
|
+
|
|
11
|
+
const PLATFORM_MAP = {
|
|
12
|
+
darwin: "Darwin",
|
|
13
|
+
linux: "Linux",
|
|
14
|
+
win32: "Windows",
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const ARCH_MAP = {
|
|
18
|
+
x64: "x86_64",
|
|
19
|
+
arm64: "arm64",
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
function getPlatformInfo() {
|
|
23
|
+
const platform = PLATFORM_MAP[process.platform];
|
|
24
|
+
const arch = ARCH_MAP[process.arch];
|
|
25
|
+
|
|
26
|
+
if (!platform || !arch) {
|
|
27
|
+
throw new Error(
|
|
28
|
+
`Unsupported platform: ${process.platform}-${process.arch}\n` +
|
|
29
|
+
`Supported: darwin-x64, darwin-arm64, linux-x64, linux-arm64, win32-x64, win32-arm64`
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const ext = process.platform === "win32" ? "zip" : "tar.gz";
|
|
34
|
+
const archiveName = `gomarklint_${platform}_${arch}.${ext}`;
|
|
35
|
+
|
|
36
|
+
return { platform, arch, ext, archiveName };
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function download(url) {
|
|
40
|
+
return new Promise((resolve, reject) => {
|
|
41
|
+
const request = (url) => {
|
|
42
|
+
https
|
|
43
|
+
.get(url, { headers: { "User-Agent": "gomarklint-npm" } }, (res) => {
|
|
44
|
+
if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
|
|
45
|
+
request(res.headers.location);
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
if (res.statusCode !== 200) {
|
|
49
|
+
reject(new Error(`Download failed: HTTP ${res.statusCode} for ${url}`));
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
const chunks = [];
|
|
53
|
+
res.on("data", (chunk) => chunks.push(chunk));
|
|
54
|
+
res.on("end", () => resolve(Buffer.concat(chunks)));
|
|
55
|
+
res.on("error", reject);
|
|
56
|
+
})
|
|
57
|
+
.on("error", reject);
|
|
58
|
+
};
|
|
59
|
+
request(url);
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function verifyChecksum(data, expected) {
|
|
64
|
+
const actual = crypto.createHash("sha256").update(data).digest("hex");
|
|
65
|
+
if (actual !== expected) {
|
|
66
|
+
throw new Error(
|
|
67
|
+
`Checksum mismatch!\n Expected: ${expected}\n Actual: ${actual}`
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
async function main() {
|
|
73
|
+
const pkg = JSON.parse(
|
|
74
|
+
fs.readFileSync(path.join(__dirname, "package.json"), "utf8")
|
|
75
|
+
);
|
|
76
|
+
const version = pkg.version;
|
|
77
|
+
|
|
78
|
+
if (version === "0.0.0") {
|
|
79
|
+
console.log("Skipping binary download for development version.");
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const { archiveName } = getPlatformInfo();
|
|
84
|
+
const baseUrl = `https://github.com/${REPO}/releases/download/v${version}`;
|
|
85
|
+
|
|
86
|
+
console.log(`Downloading gomarklint v${version} (${archiveName})...`);
|
|
87
|
+
|
|
88
|
+
// Download checksums and archive in parallel
|
|
89
|
+
const [checksumsText, archiveData] = await Promise.all([
|
|
90
|
+
download(`${baseUrl}/checksums.txt`).then((buf) => buf.toString("utf8")),
|
|
91
|
+
download(`${baseUrl}/${archiveName}`),
|
|
92
|
+
]);
|
|
93
|
+
|
|
94
|
+
// Verify checksum
|
|
95
|
+
const checksumLine = checksumsText
|
|
96
|
+
.split("\n")
|
|
97
|
+
.find((line) => line.includes(archiveName));
|
|
98
|
+
|
|
99
|
+
if (!checksumLine) {
|
|
100
|
+
throw new Error(`Checksum not found for ${archiveName}`);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const expectedHash = checksumLine.split(/\s+/)[0];
|
|
104
|
+
verifyChecksum(archiveData, expectedHash);
|
|
105
|
+
console.log("Checksum verified.");
|
|
106
|
+
|
|
107
|
+
// Write archive to temp file and extract
|
|
108
|
+
const archivePath = path.join(__dirname, archiveName);
|
|
109
|
+
fs.writeFileSync(archivePath, archiveData);
|
|
110
|
+
|
|
111
|
+
try {
|
|
112
|
+
execSync(`tar -xf "${archiveName}"`, { cwd: __dirname, stdio: "pipe" });
|
|
113
|
+
} catch (e) {
|
|
114
|
+
throw new Error(`Failed to extract archive: ${e.message}`);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// Clean up archive
|
|
118
|
+
fs.unlinkSync(archivePath);
|
|
119
|
+
|
|
120
|
+
// Set executable permission on non-Windows
|
|
121
|
+
if (process.platform !== "win32") {
|
|
122
|
+
const binPath = path.join(__dirname, "gomarklint");
|
|
123
|
+
fs.chmodSync(binPath, 0o755);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
console.log("gomarklint installed successfully.");
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
main().catch((err) => {
|
|
130
|
+
console.error(`Error: ${err.message}`);
|
|
131
|
+
process.exit(1);
|
|
132
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@shinagawa-web/gomarklint",
|
|
3
|
+
"version": "2.7.0",
|
|
4
|
+
"description": "A fast, extensible Markdown linter written in Go",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/shinagawa-web/gomarklint.git",
|
|
9
|
+
"directory": "npm"
|
|
10
|
+
},
|
|
11
|
+
"homepage": "https://github.com/shinagawa-web/gomarklint",
|
|
12
|
+
"keywords": [
|
|
13
|
+
"markdown",
|
|
14
|
+
"linter",
|
|
15
|
+
"lint",
|
|
16
|
+
"gomarklint"
|
|
17
|
+
],
|
|
18
|
+
"bin": {
|
|
19
|
+
"gomarklint": "cli.js"
|
|
20
|
+
},
|
|
21
|
+
"scripts": {
|
|
22
|
+
"postinstall": "node install.js"
|
|
23
|
+
},
|
|
24
|
+
"files": [
|
|
25
|
+
"cli.js",
|
|
26
|
+
"install.js"
|
|
27
|
+
],
|
|
28
|
+
"engines": {
|
|
29
|
+
"node": ">=16"
|
|
30
|
+
}
|
|
31
|
+
}
|