domaingrep 0.0.1 → 0.2.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/domaingrep.js +159 -0
- package/package.json +14 -6
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const { spawnSync } = require("node:child_process");
|
|
4
|
+
const fs = require("node:fs");
|
|
5
|
+
const os = require("node:os");
|
|
6
|
+
const path = require("node:path");
|
|
7
|
+
|
|
8
|
+
const pkg = require("../package.json");
|
|
9
|
+
const REPO = "ysm-dev/domaingrep";
|
|
10
|
+
|
|
11
|
+
function releaseTarget() {
|
|
12
|
+
if (process.platform === "darwin") {
|
|
13
|
+
if (process.arch === "arm64") {
|
|
14
|
+
return { target: "aarch64-apple-darwin", executable: "domaingrep", archiveExt: "tar.gz" };
|
|
15
|
+
}
|
|
16
|
+
if (process.arch === "x64") {
|
|
17
|
+
return { target: "x86_64-apple-darwin", executable: "domaingrep", archiveExt: "tar.gz" };
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
if (process.platform === "linux") {
|
|
22
|
+
const libc = detectLinuxLibc();
|
|
23
|
+
if (process.arch === "arm64") {
|
|
24
|
+
return {
|
|
25
|
+
target: libc === "gnu" ? "aarch64-unknown-linux-gnu" : "aarch64-unknown-linux-musl",
|
|
26
|
+
executable: "domaingrep",
|
|
27
|
+
archiveExt: "tar.gz",
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
if (process.arch === "x64") {
|
|
31
|
+
return {
|
|
32
|
+
target: libc === "gnu" ? "x86_64-unknown-linux-gnu" : "x86_64-unknown-linux-musl",
|
|
33
|
+
executable: "domaingrep",
|
|
34
|
+
archiveExt: "tar.gz",
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (process.platform === "win32" && process.arch === "x64") {
|
|
40
|
+
return { target: "x86_64-pc-windows-msvc", executable: "domaingrep.exe", archiveExt: "zip" };
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function detectLinuxLibc() {
|
|
47
|
+
if (process.platform !== "linux") {
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (process.report && typeof process.report.getReport === "function") {
|
|
52
|
+
const report = process.report.getReport();
|
|
53
|
+
if (report && report.header && report.header.glibcVersionRuntime) {
|
|
54
|
+
return "gnu";
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return "musl";
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function cacheRoot() {
|
|
62
|
+
if (process.env.DOMAINGREP_NPM_BIN_DIR) {
|
|
63
|
+
return process.env.DOMAINGREP_NPM_BIN_DIR;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (process.platform === "win32" && process.env.LOCALAPPDATA) {
|
|
67
|
+
return path.join(process.env.LOCALAPPDATA, "domaingrep", "npm");
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return path.join(os.homedir(), ".domaingrep", "npm");
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function resolveBinary() {
|
|
74
|
+
const targetInfo = releaseTarget();
|
|
75
|
+
if (!targetInfo) {
|
|
76
|
+
console.error(
|
|
77
|
+
`error: unsupported platform ${process.platform}/${process.arch} for npm distribution`
|
|
78
|
+
);
|
|
79
|
+
process.exit(1);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const cachedBinary = path.join(cacheRoot(), pkg.version, targetInfo.target, targetInfo.executable);
|
|
83
|
+
if (fs.existsSync(cachedBinary)) {
|
|
84
|
+
return cachedBinary;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
try {
|
|
88
|
+
return ensureDownloadedBinary(targetInfo, cachedBinary);
|
|
89
|
+
} catch (error) {
|
|
90
|
+
console.error(`error: failed to prepare domaingrep binary: ${error.message}`);
|
|
91
|
+
console.error(" = help: check your network connection or use cargo/homebrew instead");
|
|
92
|
+
process.exit(1);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function ensureDownloadedBinary(targetInfo, binaryPath) {
|
|
97
|
+
fs.mkdirSync(path.dirname(binaryPath), { recursive: true });
|
|
98
|
+
|
|
99
|
+
const versionTag = `v${pkg.version}`;
|
|
100
|
+
const archiveName = `domaingrep-${targetInfo.target}.${targetInfo.archiveExt}`;
|
|
101
|
+
const archivePath = path.join(path.dirname(binaryPath), archiveName);
|
|
102
|
+
const assetUrl = `https://github.com/${REPO}/releases/download/${versionTag}/${archiveName}`;
|
|
103
|
+
|
|
104
|
+
if (!fs.existsSync(archivePath)) {
|
|
105
|
+
downloadToFile(assetUrl, archivePath);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
extractArchive(archivePath, path.dirname(binaryPath), targetInfo.archiveExt);
|
|
109
|
+
|
|
110
|
+
if (!fs.existsSync(binaryPath)) {
|
|
111
|
+
throw new Error(`binary was not extracted from ${archiveName}`);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
if (process.platform !== "win32") {
|
|
115
|
+
fs.chmodSync(binaryPath, 0o755);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
return binaryPath;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function downloadToFile(url, destination) {
|
|
122
|
+
const result = spawnSync("curl", ["-fL", url, "-o", destination], { stdio: "inherit" });
|
|
123
|
+
if (result.status !== 0) {
|
|
124
|
+
throw new Error("failed to download release asset");
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function extractArchive(archivePath, directory, archiveExt) {
|
|
129
|
+
if (archiveExt === "zip") {
|
|
130
|
+
const result = spawnSync(
|
|
131
|
+
"powershell.exe",
|
|
132
|
+
[
|
|
133
|
+
"-NoProfile",
|
|
134
|
+
"-Command",
|
|
135
|
+
`Expand-Archive -LiteralPath '${archivePath.replace(/'/g, "''")}' -DestinationPath '${directory.replace(/'/g, "''")}' -Force`,
|
|
136
|
+
],
|
|
137
|
+
{ stdio: "inherit" }
|
|
138
|
+
);
|
|
139
|
+
if (result.status !== 0) {
|
|
140
|
+
throw new Error("failed to extract zip archive");
|
|
141
|
+
}
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
const result = spawnSync("tar", ["-xzf", archivePath, "-C", directory], { stdio: "inherit" });
|
|
146
|
+
if (result.status !== 0) {
|
|
147
|
+
throw new Error("failed to extract tar.gz archive");
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
const binaryPath = resolveBinary();
|
|
152
|
+
const result = spawnSync(binaryPath, process.argv.slice(2), { stdio: "inherit" });
|
|
153
|
+
|
|
154
|
+
if (result.error) {
|
|
155
|
+
console.error(`error: failed to execute domaingrep binary: ${result.error.message}`);
|
|
156
|
+
process.exit(1);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
process.exit(result.status === null ? 1 : result.status);
|
package/package.json
CHANGED
|
@@ -1,12 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "domaingrep",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Bulk domain availability
|
|
5
|
-
"
|
|
3
|
+
"version": "0.2.1",
|
|
4
|
+
"description": "Bulk domain availability search CLI tool",
|
|
5
|
+
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
|
-
"url": "https://github.com/ysm-dev/domaingrep"
|
|
8
|
+
"url": "git+https://github.com/ysm-dev/domaingrep.git"
|
|
9
9
|
},
|
|
10
|
-
"
|
|
11
|
-
|
|
10
|
+
"bin": {
|
|
11
|
+
"domaingrep": "bin/domaingrep.js"
|
|
12
|
+
},
|
|
13
|
+
"files": [
|
|
14
|
+
"bin",
|
|
15
|
+
"README.md"
|
|
16
|
+
],
|
|
17
|
+
"engines": {
|
|
18
|
+
"node": ">=18"
|
|
19
|
+
}
|
|
12
20
|
}
|