vize 0.0.1-alpha.99 → 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 +1 -1
- package/bin/vize +1 -29
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +107 -0
- package/dist/cli.js.map +1 -0
- package/package.json +11 -4
- package/src/cli.ts +193 -0
- package/scripts/postinstall.js +0 -137
package/README.md
CHANGED
package/bin/vize
CHANGED
|
@@ -1,30 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
import { spawn } from "child_process";
|
|
4
|
-
import { dirname, join } from "path";
|
|
5
|
-
import { fileURLToPath } from "url";
|
|
6
|
-
import { existsSync } from "fs";
|
|
7
|
-
|
|
8
|
-
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
9
|
-
const binaryName = process.platform === "win32" ? "vize.exe" : "vize";
|
|
10
|
-
const binaryPath = join(__dirname, binaryName);
|
|
11
|
-
|
|
12
|
-
if (!existsSync(binaryPath)) {
|
|
13
|
-
console.error("Vize binary not found. Please reinstall the package.");
|
|
14
|
-
console.error("npm uninstall -g vize && npm install -g vize");
|
|
15
|
-
process.exit(1);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
const child = spawn(binaryPath, process.argv.slice(2), {
|
|
19
|
-
stdio: "inherit",
|
|
20
|
-
env: process.env,
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
child.on("error", (err) => {
|
|
24
|
-
console.error(`Failed to start Vize: ${err.message}`);
|
|
25
|
-
process.exit(1);
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
child.on("close", (code) => {
|
|
29
|
-
process.exit(code ?? 0);
|
|
30
|
-
});
|
|
2
|
+
import "../dist/cli.js";
|
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { createRequire } from "module";
|
|
2
|
+
import { readFileSync } from "fs";
|
|
3
|
+
|
|
4
|
+
//#region src/cli.ts
|
|
5
|
+
const require = createRequire(import.meta.url);
|
|
6
|
+
function isMusl() {
|
|
7
|
+
const report = process.report?.getReport();
|
|
8
|
+
if (typeof report === "object" && report !== null && "header" in report) {
|
|
9
|
+
const header = report.header;
|
|
10
|
+
return !header.glibcVersionRuntime;
|
|
11
|
+
}
|
|
12
|
+
try {
|
|
13
|
+
const lddPath = require("child_process").execSync("which ldd").toString().trim();
|
|
14
|
+
return readFileSync(lddPath, "utf8").includes("musl");
|
|
15
|
+
} catch {
|
|
16
|
+
return true;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
function getBindingPackageName() {
|
|
20
|
+
const { platform, arch } = process;
|
|
21
|
+
switch (platform) {
|
|
22
|
+
case "darwin": switch (arch) {
|
|
23
|
+
case "x64": return "@vizejs/native-darwin-x64";
|
|
24
|
+
case "arm64": return "@vizejs/native-darwin-arm64";
|
|
25
|
+
default: throw new Error(`Unsupported architecture on macOS: ${arch}`);
|
|
26
|
+
}
|
|
27
|
+
case "win32": switch (arch) {
|
|
28
|
+
case "x64": return "@vizejs/native-win32-x64-msvc";
|
|
29
|
+
case "arm64": return "@vizejs/native-win32-arm64-msvc";
|
|
30
|
+
default: throw new Error(`Unsupported architecture on Windows: ${arch}`);
|
|
31
|
+
}
|
|
32
|
+
case "linux": switch (arch) {
|
|
33
|
+
case "x64": return isMusl() ? "@vizejs/native-linux-x64-musl" : "@vizejs/native-linux-x64-gnu";
|
|
34
|
+
case "arm64": return isMusl() ? "@vizejs/native-linux-arm64-musl" : "@vizejs/native-linux-arm64-gnu";
|
|
35
|
+
default: throw new Error(`Unsupported architecture on Linux: ${arch}`);
|
|
36
|
+
}
|
|
37
|
+
default: throw new Error(`Unsupported OS: ${platform}, architecture: ${arch}`);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
function loadNative() {
|
|
41
|
+
const pkg = getBindingPackageName();
|
|
42
|
+
try {
|
|
43
|
+
return require(pkg);
|
|
44
|
+
} catch (e) {
|
|
45
|
+
console.error(`Failed to load native binding: ${pkg}`);
|
|
46
|
+
console.error("Try reinstalling: npm install vize");
|
|
47
|
+
throw e;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
function runLint(args) {
|
|
51
|
+
const patterns = [];
|
|
52
|
+
const options = {};
|
|
53
|
+
for (let i = 0; i < args.length; i++) {
|
|
54
|
+
const arg = args[i];
|
|
55
|
+
if (arg === "--format" || arg === "-f") options.format = args[++i];
|
|
56
|
+
else if (arg === "--max-warnings") options.maxWarnings = Number.parseInt(args[++i], 10);
|
|
57
|
+
else if (arg === "--quiet" || arg === "-q") options.quiet = true;
|
|
58
|
+
else if (arg === "--fix") options.fix = true;
|
|
59
|
+
else if (arg === "--help-level") options.helpLevel = args[++i];
|
|
60
|
+
else if (!arg.startsWith("-")) patterns.push(arg);
|
|
61
|
+
}
|
|
62
|
+
if (patterns.length === 0) patterns.push(".");
|
|
63
|
+
const native = loadNative();
|
|
64
|
+
const result = native.lint(patterns, {
|
|
65
|
+
format: options.format,
|
|
66
|
+
max_warnings: options.maxWarnings,
|
|
67
|
+
quiet: options.quiet,
|
|
68
|
+
fix: options.fix,
|
|
69
|
+
help_level: options.helpLevel
|
|
70
|
+
});
|
|
71
|
+
if (result.output) {
|
|
72
|
+
process.stdout.write(result.output);
|
|
73
|
+
if (!result.output.endsWith("\n")) process.stdout.write("\n");
|
|
74
|
+
}
|
|
75
|
+
if (options.fix) process.stderr.write("\nNote: --fix is not yet implemented\n");
|
|
76
|
+
if (result.errorCount > 0) process.exit(1);
|
|
77
|
+
if (options.maxWarnings !== void 0 && result.warningCount > options.maxWarnings) {
|
|
78
|
+
process.stderr.write(`\nToo many warnings (${result.warningCount} > max ${options.maxWarnings})\n`);
|
|
79
|
+
process.exit(1);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
const NAPI_COMMANDS = new Set(["lint"]);
|
|
83
|
+
function main() {
|
|
84
|
+
const args = process.argv.slice(2);
|
|
85
|
+
const command = args[0];
|
|
86
|
+
if (!command) {
|
|
87
|
+
console.error("Usage: vize <command> [options]");
|
|
88
|
+
console.error("Commands: lint");
|
|
89
|
+
process.exit(1);
|
|
90
|
+
}
|
|
91
|
+
if (NAPI_COMMANDS.has(command)) {
|
|
92
|
+
const commandArgs = args.slice(1);
|
|
93
|
+
switch (command) {
|
|
94
|
+
case "lint":
|
|
95
|
+
runLint(commandArgs);
|
|
96
|
+
break;
|
|
97
|
+
}
|
|
98
|
+
} else {
|
|
99
|
+
console.error(`Unknown command: ${command}`);
|
|
100
|
+
console.error("For commands not yet available via NAPI, install from source: cargo install vize");
|
|
101
|
+
process.exit(1);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
main();
|
|
105
|
+
|
|
106
|
+
//#endregion
|
|
107
|
+
//# sourceMappingURL=cli.js.map
|
package/dist/cli.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.js","names":["args: string[]","patterns: string[]","options: LintOptions"],"sources":["../src/cli.ts"],"sourcesContent":["import { createRequire } from \"module\";\nimport { readFileSync } from \"fs\";\n\nconst require = createRequire(import.meta.url);\n\n// ============================================================================\n// Native binding loader (oxlint pattern)\n// ============================================================================\n\nfunction isMusl(): boolean {\n const report = process.report?.getReport();\n if (typeof report === \"object\" && report !== null && \"header\" in report) {\n const header = (report as { header: { glibcVersionRuntime?: string } }).header;\n return !header.glibcVersionRuntime;\n }\n try {\n const lddPath = require(\"child_process\").execSync(\"which ldd\").toString().trim();\n return readFileSync(lddPath, \"utf8\").includes(\"musl\");\n } catch {\n return true;\n }\n}\n\nfunction getBindingPackageName(): string {\n const { platform, arch } = process;\n\n switch (platform) {\n case \"darwin\":\n switch (arch) {\n case \"x64\":\n return \"@vizejs/native-darwin-x64\";\n case \"arm64\":\n return \"@vizejs/native-darwin-arm64\";\n default:\n throw new Error(`Unsupported architecture on macOS: ${arch}`);\n }\n case \"win32\":\n switch (arch) {\n case \"x64\":\n return \"@vizejs/native-win32-x64-msvc\";\n case \"arm64\":\n return \"@vizejs/native-win32-arm64-msvc\";\n default:\n throw new Error(`Unsupported architecture on Windows: ${arch}`);\n }\n case \"linux\":\n switch (arch) {\n case \"x64\":\n return isMusl() ? \"@vizejs/native-linux-x64-musl\" : \"@vizejs/native-linux-x64-gnu\";\n case \"arm64\":\n return isMusl() ? \"@vizejs/native-linux-arm64-musl\" : \"@vizejs/native-linux-arm64-gnu\";\n default:\n throw new Error(`Unsupported architecture on Linux: ${arch}`);\n }\n default:\n throw new Error(`Unsupported OS: ${platform}, architecture: ${arch}`);\n }\n}\n\ninterface NativeBinding {\n lint: (\n patterns: string[],\n options?: {\n format?: string;\n max_warnings?: number;\n quiet?: boolean;\n fix?: boolean;\n help_level?: string;\n },\n ) => LintResult;\n}\n\nfunction loadNative(): NativeBinding {\n const pkg = getBindingPackageName();\n try {\n return require(pkg);\n } catch (e) {\n console.error(`Failed to load native binding: ${pkg}`);\n console.error(\"Try reinstalling: npm install vize\");\n throw e;\n }\n}\n\n// ============================================================================\n// Lint command\n// ============================================================================\n\ninterface LintOptions {\n format?: string;\n maxWarnings?: number;\n quiet?: boolean;\n fix?: boolean;\n helpLevel?: string;\n}\n\ninterface LintResult {\n output: string;\n errorCount: number;\n warningCount: number;\n fileCount: number;\n timeMs: number;\n}\n\nfunction runLint(args: string[]): void {\n const patterns: string[] = [];\n const options: LintOptions = {};\n\n for (let i = 0; i < args.length; i++) {\n const arg = args[i];\n if (arg === \"--format\" || arg === \"-f\") {\n options.format = args[++i];\n } else if (arg === \"--max-warnings\") {\n options.maxWarnings = Number.parseInt(args[++i], 10);\n } else if (arg === \"--quiet\" || arg === \"-q\") {\n options.quiet = true;\n } else if (arg === \"--fix\") {\n options.fix = true;\n } else if (arg === \"--help-level\") {\n options.helpLevel = args[++i];\n } else if (!arg.startsWith(\"-\")) {\n patterns.push(arg);\n }\n }\n\n if (patterns.length === 0) {\n patterns.push(\".\");\n }\n\n const native = loadNative();\n const result = native.lint(patterns, {\n format: options.format,\n max_warnings: options.maxWarnings,\n quiet: options.quiet,\n fix: options.fix,\n help_level: options.helpLevel,\n });\n\n if (result.output) {\n process.stdout.write(result.output);\n if (!result.output.endsWith(\"\\n\")) {\n process.stdout.write(\"\\n\");\n }\n }\n\n if (options.fix) {\n process.stderr.write(\"\\nNote: --fix is not yet implemented\\n\");\n }\n\n if (result.errorCount > 0) {\n process.exit(1);\n }\n\n if (options.maxWarnings !== undefined && result.warningCount > options.maxWarnings) {\n process.stderr.write(\n `\\nToo many warnings (${result.warningCount} > max ${options.maxWarnings})\\n`,\n );\n process.exit(1);\n }\n}\n\n// ============================================================================\n// Command router\n// ============================================================================\n\nconst NAPI_COMMANDS = new Set([\"lint\"]);\n\nfunction main(): void {\n const args = process.argv.slice(2);\n const command = args[0];\n\n if (!command) {\n console.error(\"Usage: vize <command> [options]\");\n console.error(\"Commands: lint\");\n process.exit(1);\n }\n\n if (NAPI_COMMANDS.has(command)) {\n const commandArgs = args.slice(1);\n switch (command) {\n case \"lint\":\n runLint(commandArgs);\n break;\n }\n } else {\n console.error(`Unknown command: ${command}`);\n console.error(\n \"For commands not yet available via NAPI, install from source: cargo install vize\",\n );\n process.exit(1);\n }\n}\n\nmain();\n"],"mappings":";;;;AAGA,MAAM,UAAU,cAAc,OAAO,KAAK,IAAI;AAM9C,SAAS,SAAkB;CACzB,MAAM,SAAS,QAAQ,QAAQ,WAAW;AAC1C,YAAW,WAAW,YAAY,WAAW,QAAQ,YAAY,QAAQ;EACvE,MAAM,SAAU,OAAwD;AACxE,UAAQ,OAAO;CAChB;AACD,KAAI;EACF,MAAM,UAAU,QAAQ,gBAAgB,CAAC,SAAS,YAAY,CAAC,UAAU,CAAC,MAAM;AAChF,SAAO,aAAa,SAAS,OAAO,CAAC,SAAS,OAAO;CACtD,QAAO;AACN,SAAO;CACR;AACF;AAED,SAAS,wBAAgC;CACvC,MAAM,EA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
5
|
"publishConfig": {
|
|
6
|
-
"provenance": false,
|
|
7
6
|
"access": "public"
|
|
8
7
|
},
|
|
9
8
|
"type": "module",
|
|
@@ -24,7 +23,6 @@
|
|
|
24
23
|
},
|
|
25
24
|
"files": [
|
|
26
25
|
"bin",
|
|
27
|
-
"scripts",
|
|
28
26
|
"dist",
|
|
29
27
|
"src"
|
|
30
28
|
],
|
|
@@ -45,6 +43,16 @@
|
|
|
45
43
|
"engines": {
|
|
46
44
|
"node": ">=18"
|
|
47
45
|
},
|
|
46
|
+
"optionalDependencies": {
|
|
47
|
+
"@vizejs/native-darwin-x64": "0.1.0",
|
|
48
|
+
"@vizejs/native-darwin-arm64": "0.1.0",
|
|
49
|
+
"@vizejs/native-win32-x64-msvc": "0.1.0",
|
|
50
|
+
"@vizejs/native-win32-arm64-msvc": "0.1.0",
|
|
51
|
+
"@vizejs/native-linux-x64-gnu": "0.1.0",
|
|
52
|
+
"@vizejs/native-linux-x64-musl": "0.1.0",
|
|
53
|
+
"@vizejs/native-linux-arm64-gnu": "0.1.0",
|
|
54
|
+
"@vizejs/native-linux-arm64-musl": "0.1.0"
|
|
55
|
+
},
|
|
48
56
|
"dependencies": {
|
|
49
57
|
"oxc-transform": "^0.56.0"
|
|
50
58
|
},
|
|
@@ -55,7 +63,6 @@
|
|
|
55
63
|
},
|
|
56
64
|
"scripts": {
|
|
57
65
|
"build": "tsdown",
|
|
58
|
-
"postinstall": "node scripts/postinstall.js",
|
|
59
66
|
"lint": "oxlint --deny-warnings --type-aware --tsconfig tsconfig.json",
|
|
60
67
|
"lint:fix": "oxlint --type-aware --tsconfig tsconfig.json --fix",
|
|
61
68
|
"fmt": "oxfmt --write src",
|
package/src/cli.ts
ADDED
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import { createRequire } from "module";
|
|
2
|
+
import { readFileSync } from "fs";
|
|
3
|
+
|
|
4
|
+
const require = createRequire(import.meta.url);
|
|
5
|
+
|
|
6
|
+
// ============================================================================
|
|
7
|
+
// Native binding loader (oxlint pattern)
|
|
8
|
+
// ============================================================================
|
|
9
|
+
|
|
10
|
+
function isMusl(): boolean {
|
|
11
|
+
const report = process.report?.getReport();
|
|
12
|
+
if (typeof report === "object" && report !== null && "header" in report) {
|
|
13
|
+
const header = (report as { header: { glibcVersionRuntime?: string } }).header;
|
|
14
|
+
return !header.glibcVersionRuntime;
|
|
15
|
+
}
|
|
16
|
+
try {
|
|
17
|
+
const lddPath = require("child_process").execSync("which ldd").toString().trim();
|
|
18
|
+
return readFileSync(lddPath, "utf8").includes("musl");
|
|
19
|
+
} catch {
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function getBindingPackageName(): string {
|
|
25
|
+
const { platform, arch } = process;
|
|
26
|
+
|
|
27
|
+
switch (platform) {
|
|
28
|
+
case "darwin":
|
|
29
|
+
switch (arch) {
|
|
30
|
+
case "x64":
|
|
31
|
+
return "@vizejs/native-darwin-x64";
|
|
32
|
+
case "arm64":
|
|
33
|
+
return "@vizejs/native-darwin-arm64";
|
|
34
|
+
default:
|
|
35
|
+
throw new Error(`Unsupported architecture on macOS: ${arch}`);
|
|
36
|
+
}
|
|
37
|
+
case "win32":
|
|
38
|
+
switch (arch) {
|
|
39
|
+
case "x64":
|
|
40
|
+
return "@vizejs/native-win32-x64-msvc";
|
|
41
|
+
case "arm64":
|
|
42
|
+
return "@vizejs/native-win32-arm64-msvc";
|
|
43
|
+
default:
|
|
44
|
+
throw new Error(`Unsupported architecture on Windows: ${arch}`);
|
|
45
|
+
}
|
|
46
|
+
case "linux":
|
|
47
|
+
switch (arch) {
|
|
48
|
+
case "x64":
|
|
49
|
+
return isMusl() ? "@vizejs/native-linux-x64-musl" : "@vizejs/native-linux-x64-gnu";
|
|
50
|
+
case "arm64":
|
|
51
|
+
return isMusl() ? "@vizejs/native-linux-arm64-musl" : "@vizejs/native-linux-arm64-gnu";
|
|
52
|
+
default:
|
|
53
|
+
throw new Error(`Unsupported architecture on Linux: ${arch}`);
|
|
54
|
+
}
|
|
55
|
+
default:
|
|
56
|
+
throw new Error(`Unsupported OS: ${platform}, architecture: ${arch}`);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
interface NativeBinding {
|
|
61
|
+
lint: (
|
|
62
|
+
patterns: string[],
|
|
63
|
+
options?: {
|
|
64
|
+
format?: string;
|
|
65
|
+
max_warnings?: number;
|
|
66
|
+
quiet?: boolean;
|
|
67
|
+
fix?: boolean;
|
|
68
|
+
help_level?: string;
|
|
69
|
+
},
|
|
70
|
+
) => LintResult;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function loadNative(): NativeBinding {
|
|
74
|
+
const pkg = getBindingPackageName();
|
|
75
|
+
try {
|
|
76
|
+
return require(pkg);
|
|
77
|
+
} catch (e) {
|
|
78
|
+
console.error(`Failed to load native binding: ${pkg}`);
|
|
79
|
+
console.error("Try reinstalling: npm install vize");
|
|
80
|
+
throw e;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// ============================================================================
|
|
85
|
+
// Lint command
|
|
86
|
+
// ============================================================================
|
|
87
|
+
|
|
88
|
+
interface LintOptions {
|
|
89
|
+
format?: string;
|
|
90
|
+
maxWarnings?: number;
|
|
91
|
+
quiet?: boolean;
|
|
92
|
+
fix?: boolean;
|
|
93
|
+
helpLevel?: string;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
interface LintResult {
|
|
97
|
+
output: string;
|
|
98
|
+
errorCount: number;
|
|
99
|
+
warningCount: number;
|
|
100
|
+
fileCount: number;
|
|
101
|
+
timeMs: number;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function runLint(args: string[]): void {
|
|
105
|
+
const patterns: string[] = [];
|
|
106
|
+
const options: LintOptions = {};
|
|
107
|
+
|
|
108
|
+
for (let i = 0; i < args.length; i++) {
|
|
109
|
+
const arg = args[i];
|
|
110
|
+
if (arg === "--format" || arg === "-f") {
|
|
111
|
+
options.format = args[++i];
|
|
112
|
+
} else if (arg === "--max-warnings") {
|
|
113
|
+
options.maxWarnings = Number.parseInt(args[++i], 10);
|
|
114
|
+
} else if (arg === "--quiet" || arg === "-q") {
|
|
115
|
+
options.quiet = true;
|
|
116
|
+
} else if (arg === "--fix") {
|
|
117
|
+
options.fix = true;
|
|
118
|
+
} else if (arg === "--help-level") {
|
|
119
|
+
options.helpLevel = args[++i];
|
|
120
|
+
} else if (!arg.startsWith("-")) {
|
|
121
|
+
patterns.push(arg);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
if (patterns.length === 0) {
|
|
126
|
+
patterns.push(".");
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
const native = loadNative();
|
|
130
|
+
const result = native.lint(patterns, {
|
|
131
|
+
format: options.format,
|
|
132
|
+
max_warnings: options.maxWarnings,
|
|
133
|
+
quiet: options.quiet,
|
|
134
|
+
fix: options.fix,
|
|
135
|
+
help_level: options.helpLevel,
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
if (result.output) {
|
|
139
|
+
process.stdout.write(result.output);
|
|
140
|
+
if (!result.output.endsWith("\n")) {
|
|
141
|
+
process.stdout.write("\n");
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
if (options.fix) {
|
|
146
|
+
process.stderr.write("\nNote: --fix is not yet implemented\n");
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
if (result.errorCount > 0) {
|
|
150
|
+
process.exit(1);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
if (options.maxWarnings !== undefined && result.warningCount > options.maxWarnings) {
|
|
154
|
+
process.stderr.write(
|
|
155
|
+
`\nToo many warnings (${result.warningCount} > max ${options.maxWarnings})\n`,
|
|
156
|
+
);
|
|
157
|
+
process.exit(1);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// ============================================================================
|
|
162
|
+
// Command router
|
|
163
|
+
// ============================================================================
|
|
164
|
+
|
|
165
|
+
const NAPI_COMMANDS = new Set(["lint"]);
|
|
166
|
+
|
|
167
|
+
function main(): void {
|
|
168
|
+
const args = process.argv.slice(2);
|
|
169
|
+
const command = args[0];
|
|
170
|
+
|
|
171
|
+
if (!command) {
|
|
172
|
+
console.error("Usage: vize <command> [options]");
|
|
173
|
+
console.error("Commands: lint");
|
|
174
|
+
process.exit(1);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
if (NAPI_COMMANDS.has(command)) {
|
|
178
|
+
const commandArgs = args.slice(1);
|
|
179
|
+
switch (command) {
|
|
180
|
+
case "lint":
|
|
181
|
+
runLint(commandArgs);
|
|
182
|
+
break;
|
|
183
|
+
}
|
|
184
|
+
} else {
|
|
185
|
+
console.error(`Unknown command: ${command}`);
|
|
186
|
+
console.error(
|
|
187
|
+
"For commands not yet available via NAPI, install from source: cargo install vize",
|
|
188
|
+
);
|
|
189
|
+
process.exit(1);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
main();
|
package/scripts/postinstall.js
DELETED
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
import { createWriteStream, chmodSync, existsSync, mkdirSync, unlinkSync } from "fs";
|
|
4
|
-
import { dirname, join } from "path";
|
|
5
|
-
import { fileURLToPath } from "url";
|
|
6
|
-
import { pipeline } from "stream/promises";
|
|
7
|
-
|
|
8
|
-
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
9
|
-
const packageJson = await import("../package.json", { with: { type: "json" } });
|
|
10
|
-
const version = packageJson.default.version;
|
|
11
|
-
|
|
12
|
-
const REPO = "vizejs/vize";
|
|
13
|
-
|
|
14
|
-
const PLATFORMS = {
|
|
15
|
-
"darwin-x64": {
|
|
16
|
-
target: "x86_64-apple-darwin",
|
|
17
|
-
filename: "vize-x86_64-apple-darwin.tar.gz",
|
|
18
|
-
},
|
|
19
|
-
"darwin-arm64": {
|
|
20
|
-
target: "aarch64-apple-darwin",
|
|
21
|
-
filename: "vize-aarch64-apple-darwin.tar.gz",
|
|
22
|
-
},
|
|
23
|
-
"linux-x64": {
|
|
24
|
-
target: "x86_64-unknown-linux-gnu",
|
|
25
|
-
filename: "vize-x86_64-unknown-linux-gnu.tar.gz",
|
|
26
|
-
},
|
|
27
|
-
"linux-arm64": {
|
|
28
|
-
target: "aarch64-unknown-linux-gnu",
|
|
29
|
-
filename: "vize-aarch64-unknown-linux-gnu.tar.gz",
|
|
30
|
-
},
|
|
31
|
-
"win32-x64": {
|
|
32
|
-
target: "x86_64-pc-windows-msvc",
|
|
33
|
-
filename: "vize-x86_64-pc-windows-msvc.zip",
|
|
34
|
-
},
|
|
35
|
-
"win32-arm64": {
|
|
36
|
-
target: "aarch64-pc-windows-msvc",
|
|
37
|
-
filename: "vize-aarch64-pc-windows-msvc.zip",
|
|
38
|
-
},
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
async function main() {
|
|
42
|
-
// Skip in CI environment - binary is built separately and not available during pnpm install
|
|
43
|
-
if (process.env.CI) {
|
|
44
|
-
console.log("CI environment detected, skipping binary download.");
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
const platform = `${process.platform}-${process.arch}`;
|
|
49
|
-
const config = PLATFORMS[platform];
|
|
50
|
-
|
|
51
|
-
if (!config) {
|
|
52
|
-
console.error(`Unsupported platform: ${platform}`);
|
|
53
|
-
console.error(`Supported platforms: ${Object.keys(PLATFORMS).join(", ")}`);
|
|
54
|
-
console.error(
|
|
55
|
-
"\nYou can install the CLI from source using: cargo install vize"
|
|
56
|
-
);
|
|
57
|
-
process.exit(1);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
const binDir = join(__dirname, "..", "bin");
|
|
61
|
-
const binaryName = process.platform === "win32" ? "vize.exe" : "vize";
|
|
62
|
-
const binaryPath = join(binDir, binaryName);
|
|
63
|
-
|
|
64
|
-
// Skip if binary already exists (for local development)
|
|
65
|
-
if (existsSync(binaryPath)) {
|
|
66
|
-
console.log("Vize binary already exists, skipping download.");
|
|
67
|
-
return;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
if (!existsSync(binDir)) {
|
|
71
|
-
mkdirSync(binDir, { recursive: true });
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
const tag = `v${version}`;
|
|
75
|
-
const downloadUrl = `https://github.com/${REPO}/releases/download/${tag}/${config.filename}`;
|
|
76
|
-
|
|
77
|
-
console.log(`Downloading Vize ${version} for ${platform}...`);
|
|
78
|
-
console.log(`URL: ${downloadUrl}`);
|
|
79
|
-
|
|
80
|
-
try {
|
|
81
|
-
const response = await fetch(downloadUrl);
|
|
82
|
-
|
|
83
|
-
if (!response.ok) {
|
|
84
|
-
throw new Error(`Failed to download: ${response.status} ${response.statusText}`);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
const tempFile = join(binDir, config.filename);
|
|
88
|
-
|
|
89
|
-
// Download to temp file
|
|
90
|
-
const fileStream = createWriteStream(tempFile);
|
|
91
|
-
await pipeline(response.body, fileStream);
|
|
92
|
-
|
|
93
|
-
// Extract based on file type
|
|
94
|
-
if (config.filename.endsWith(".tar.gz")) {
|
|
95
|
-
await extractTarGz(tempFile, binDir, binaryName);
|
|
96
|
-
} else if (config.filename.endsWith(".zip")) {
|
|
97
|
-
await extractZip(tempFile, binDir, binaryName);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
// Clean up temp file
|
|
101
|
-
unlinkSync(tempFile);
|
|
102
|
-
|
|
103
|
-
// Make executable on Unix
|
|
104
|
-
if (process.platform !== "win32") {
|
|
105
|
-
chmodSync(binaryPath, 0o755);
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
console.log(`Vize ${version} installed successfully!`);
|
|
109
|
-
} catch (error) {
|
|
110
|
-
console.error(`Failed to install Vize: ${error.message}`);
|
|
111
|
-
console.error(
|
|
112
|
-
"\nYou can install the CLI from source using: cargo install vize"
|
|
113
|
-
);
|
|
114
|
-
process.exit(1);
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
async function extractTarGz(archivePath, destDir, binaryName) {
|
|
119
|
-
const { execSync } = await import("child_process");
|
|
120
|
-
execSync(`tar -xzf "${archivePath}" -C "${destDir}"`, { stdio: "inherit" });
|
|
121
|
-
|
|
122
|
-
// The archive contains a 'vize' binary directly
|
|
123
|
-
// If not in place, move it
|
|
124
|
-
const extractedPath = join(destDir, "vize");
|
|
125
|
-
const targetPath = join(destDir, binaryName);
|
|
126
|
-
if (extractedPath !== targetPath && existsSync(extractedPath)) {
|
|
127
|
-
const { renameSync } = await import("fs");
|
|
128
|
-
renameSync(extractedPath, targetPath);
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
async function extractZip(archivePath, destDir, _binaryName) {
|
|
133
|
-
const { execSync } = await import("child_process");
|
|
134
|
-
execSync(`unzip -o "${archivePath}" -d "${destDir}"`, { stdio: "inherit" });
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
void main();
|