vaultfs 1.0.6 → 1.0.8

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.
@@ -1,137 +1,82 @@
1
1
  #!/usr/bin/env node
2
- const { execSync } = require("child_process");
3
- const fs = require("fs");
4
- const path = require("path");
5
- const os = require("os");
2
+ const { execSync } = require('child_process');
3
+ const fs = require('fs');
4
+ const path = require('path');
5
+ const os = require('os');
6
6
 
7
- // ─── Colors ──────────────────────────────────────────────────
8
- const RESET = "\x1b[0m";
9
- const BOLD = "\x1b[1m";
10
- const RED = "\x1b[31m";
11
- const GREEN = "\x1b[32m";
12
- const CYAN = "\x1b[36m";
13
- const DIM = "\x1b[2m";
7
+ const isWin = process.platform === 'win32';
8
+ const installDir = path.join(os.homedir(), '.vaultfs');
14
9
 
15
- function success(msg) { console.log(` ${GREEN}✓${RESET} ${msg}`); }
16
- function error(msg) { console.log(` ${RED}✗${RESET} ${msg}`); }
17
- function info(msg) { console.log(` ${CYAN}→${RESET} ${msg}`); }
18
-
19
- // ─── Banner ──────────────────────────────────────────────────
20
- console.log("");
21
- console.log(`${CYAN}${BOLD} ╔══════════════════════════════════════════════╗${RESET}`);
22
- console.log(`${CYAN}${BOLD} ║ ║${RESET}`);
23
- console.log(`${CYAN}${BOLD} ║ ${GREEN}▓▓ VaultFS — Running post-install setup${CYAN} ║${RESET}`);
24
- console.log(`${CYAN}${BOLD} ║ ║${RESET}`);
25
- console.log(`${CYAN}${BOLD} ╚══════════════════════════════════════════════╝${RESET}`);
26
- console.log("");
10
+ console.log('\n \u2554\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2557');
11
+ console.log(' \u2551 VaultFS \u2014 Running post-install setup \u2551');
12
+ console.log(' \u255A\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u255D\n');
27
13
 
28
14
  try {
29
- // ─── Detect OS ─────────────────────────────────────────────
30
- const platform = process.platform; // win32, darwin, linux
31
- const platformName =
32
- platform === "win32" ? "Windows" :
33
- platform === "darwin" ? "macOS" : "Linux";
34
- success(`OS detected: ${BOLD}${platformName}${RESET}`);
35
-
36
- // ─── Check Java 11+ ───────────────────────────────────────
37
- let javaVersion;
38
- try {
39
- const javaOut = execSync("java -version 2>&1", { encoding: "utf8" });
40
- const match = javaOut.match(/"(\d+)/);
41
- javaVersion = match ? parseInt(match[1], 10) : 0;
42
- } catch {
43
- javaVersion = 0;
44
- }
45
-
46
- if (javaVersion < 11) {
47
- error(`${RED}Java 11+ is required${javaVersion > 0 ? ` (found Java ${javaVersion})` : " (not found)"}.${RESET}`);
48
- console.log("");
49
- console.log(` Download Java from: ${CYAN}https://adoptium.net${RESET}`);
50
- console.log("");
51
- process.exit(1);
52
- }
53
- success(`Java ${BOLD}${javaVersion}${RESET} found`);
54
-
55
- // ─── Install directory ─────────────────────────────────────
56
- const installDir = path.join(os.homedir(), ".vaultfs");
57
-
58
- if (fs.existsSync(installDir) && fs.existsSync(path.join(installDir, "out", "Main.class"))) {
59
- info("Already installed, skipping build.");
60
- console.log("");
61
- console.log(` ${GREEN}${BOLD}✅ VaultFS is ready!${RESET} Type ${CYAN}vaultfs${RESET} to launch.`);
62
- console.log("");
63
- process.exit(0);
64
- }
65
-
66
- // ─── Copy package contents into install dir ────────────────
67
- info(`Setting up ${DIM}${installDir}${RESET}...`);
15
+ // Step 1 — Detect OS
16
+ const os_name = isWin ? 'Windows' : process.platform === 'darwin' ? 'macOS' : 'Linux';
17
+ console.log(` \u2713 OS detected: ${os_name}`);
18
+
19
+ // Step 2 Check Java 11+
20
+ try {
21
+ execSync('java -version 2>&1', { shell: true });
22
+ console.log(' \u2713 Java found');
23
+ } catch (e) {
24
+ console.error(' \u2717 Java 11+ is required.');
25
+ console.error(' Download from: https://adoptium.net');
26
+ process.exit(1);
27
+ }
68
28
 
69
- if (!fs.existsSync(installDir)) {
70
- fs.mkdirSync(installDir, { recursive: true });
71
- }
29
+ // Step 3 — Copy files to ~/.vaultfs
30
+ console.log(` \u2192 Setting up ${installDir}...`);
31
+ if (!fs.existsSync(installDir)) {
32
+ fs.mkdirSync(installDir, { recursive: true });
33
+ }
72
34
 
73
- // Resolve the package root (one level up from bin/)
74
- const pkgRoot = path.resolve(__dirname, "..");
35
+ const pkgDir = path.join(__dirname, '..');
36
+ const itemsToCopy = ['src', 'frontend', 'version.txt', '.env.example'];
37
+ for (const item of itemsToCopy) {
38
+ const src = path.join(pkgDir, item);
39
+ const dest = path.join(installDir, item);
40
+ if (fs.existsSync(src)) {
41
+ if (fs.existsSync(dest)) {
42
+ fs.rmSync(dest, { recursive: true, force: true });
43
+ }
44
+ fs.cpSync(src, dest, { recursive: true });
45
+ }
46
+ }
47
+ console.log(' \u2713 Source files copied');
75
48
 
76
- const toCopy = ["src", "frontend", "version.txt", ".env.example"];
77
- for (const item of toCopy) {
78
- const src = path.join(pkgRoot, item);
79
- const dest = path.join(installDir, item);
80
- if (!fs.existsSync(src)) continue;
49
+ // Step 4 Create .env if missing
50
+ const envFile = path.join(installDir, '.env');
51
+ const envExample = path.join(installDir, '.env.example');
52
+ if (!fs.existsSync(envFile) && fs.existsSync(envExample)) {
53
+ fs.copyFileSync(envExample, envFile);
54
+ }
81
55
 
82
- const stat = fs.statSync(src);
83
- if (stat.isDirectory()) {
84
- fs.cpSync(src, dest, { recursive: true, force: true });
56
+ // Step 5 — Verify pre-built frontend dist exists
57
+ const distDir = path.join(installDir, 'frontend', 'dist');
58
+ if (fs.existsSync(distDir)) {
59
+ console.log(' \u2713 Frontend ready (pre-built)');
85
60
  } else {
86
- // Ensure parent dir exists
87
- const parent = path.dirname(dest);
88
- if (!fs.existsSync(parent)) fs.mkdirSync(parent, { recursive: true });
89
- fs.copyFileSync(src, dest);
61
+ console.log(' \u26A0 Frontend dist not found - login UI may not work');
90
62
  }
91
- }
92
- success("Source files copied");
93
-
94
- // ─── Platform-aware commands ───────────────────────────────
95
- const npmCmd = platform === "win32" ? "npm.cmd" : "npm";
96
- const npxCmd = platform === "win32" ? "npx.cmd" : "npx";
97
63
 
98
- // ─── Build frontend ────────────────────────────────────────
99
- info("Installing frontend dependencies...");
100
- const frontendDir = path.join(installDir, "frontend");
101
- execSync(`${npmCmd} install`, {
102
- cwd: frontendDir,
103
- stdio: "inherit",
104
- shell: true
105
- });
106
- success("Dependencies installed");
107
-
108
- info("Building React app...");
109
- execSync(`${npmCmd} run build`, {
110
- cwd: frontendDir,
111
- stdio: "inherit",
112
- shell: true
113
- });
114
- success("React app built");
115
-
116
- // ─── Compile Java ──────────────────────────────────────────
117
- info("Compiling Java sources...");
118
- execSync("javac -d out src/models/*.java src/datastructures/*.java src/utils/*.java src/auth/*.java src/sync/*.java src/filesystem/*.java src/Main.java", {
119
- cwd: installDir,
120
- stdio: "inherit",
121
- shell: true
122
- });
123
- success("All sources compiled");
64
+ // Step 6 Compile Java
65
+ console.log(' \u2192 Compiling Java sources...');
66
+ const outDir = path.join(installDir, 'out');
67
+ if (!fs.existsSync(outDir)) {
68
+ fs.mkdirSync(outDir, { recursive: true });
69
+ }
70
+ execSync(
71
+ 'javac -d out src/models/*.java src/datastructures/*.java src/utils/*.java src/auth/*.java src/sync/*.java src/filesystem/*.java src/Main.java',
72
+ { cwd: installDir, stdio: 'inherit', shell: true }
73
+ );
74
+ console.log(' \u2713 Java compiled');
124
75
 
125
- // ─── Done ──────────────────────────────────────────────────
126
- console.log("");
127
- console.log(` ${GREEN}${BOLD}✅ VaultFS is ready!${RESET} Type ${CYAN}vaultfs${RESET} to launch.`);
128
- console.log("");
76
+ console.log('\n \u2705 VaultFS is ready! Type vaultfs to launch.\n');
129
77
 
130
78
  } catch (err) {
131
- console.log("");
132
- error(`${RED}Post-install failed: ${err.message}${RESET}`);
133
- console.log("");
134
- console.log(` Run ${CYAN}vaultfs doctor${RESET} to diagnose the issue.`);
135
- console.log("");
136
- process.exit(1);
79
+ console.error(`\n \u2717 Post-install failed: ${err.message}`);
80
+ console.error(' Run vaultfs doctor to diagnose the issue.\n');
81
+ process.exit(1);
137
82
  }