@dhruv2mars/mdv 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.
Files changed (2) hide show
  1. package/bin/mdv.js +45 -0
  2. package/package.json +16 -0
package/bin/mdv.js ADDED
@@ -0,0 +1,45 @@
1
+ #!/usr/bin/env node
2
+ import { existsSync } from 'node:fs';
3
+ import { homedir } from 'node:os';
4
+ import { join } from 'node:path';
5
+ import { spawnSync } from 'node:child_process';
6
+
7
+ const REPO = 'https://github.com/Dhruv2mars/mdv';
8
+ const args = process.argv.slice(2);
9
+ const envBin = process.env.MDV_BIN;
10
+
11
+ if (envBin) run(envBin, args);
12
+
13
+ const installRoot = process.env.MDV_INSTALL_ROOT || join(homedir(), '.mdv');
14
+ const binName = process.platform === 'win32' ? 'mdv-cli.exe' : 'mdv-cli';
15
+ const installedBin = join(installRoot, 'bin', binName);
16
+
17
+ if (!existsSync(installedBin)) {
18
+ ensureCargo();
19
+ console.error('mdv: installing rust binary (first run)...');
20
+ const install = spawnSync(
21
+ 'cargo',
22
+ ['install', 'mdv-cli', '--git', REPO, '--locked', '--root', installRoot],
23
+ { stdio: 'inherit' }
24
+ );
25
+
26
+ if (install.status !== 0 || !existsSync(installedBin)) {
27
+ console.error('mdv: install failed');
28
+ process.exit(1);
29
+ }
30
+ }
31
+
32
+ run(installedBin, args);
33
+
34
+ function ensureCargo() {
35
+ const probe = spawnSync('cargo', ['--version'], { stdio: 'ignore' });
36
+ if (probe.status === 0) return;
37
+
38
+ console.error('mdv: rust toolchain not found. install rustup/cargo first.');
39
+ process.exit(1);
40
+ }
41
+
42
+ function run(bin, binArgs) {
43
+ const res = spawnSync(bin, binArgs, { stdio: 'inherit' });
44
+ process.exit(res.status ?? 1);
45
+ }
package/package.json ADDED
@@ -0,0 +1,16 @@
1
+ {
2
+ "name": "@dhruv2mars/mdv",
3
+ "version": "0.0.1",
4
+ "description": "Terminal markdown visualizer",
5
+ "type": "module",
6
+ "bin": {
7
+ "mdv": "bin/mdv.js"
8
+ },
9
+ "files": [
10
+ "bin"
11
+ ],
12
+ "scripts": {
13
+ "mdv": "node bin/mdv.js"
14
+ },
15
+ "license": "MIT"
16
+ }