forked from Sacura1/aztec-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcheck-aztec-version.js
More file actions
executable file
·65 lines (53 loc) · 1.97 KB
/
Copy pathcheck-aztec-version.js
File metadata and controls
executable file
·65 lines (53 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import { exec } from "child_process";
import { promisify } from "util";
import { readFileSync } from "fs";
import { fileURLToPath } from "url";
import { dirname, join } from "path";
const execAsync = promisify(exec);
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
/**
* Check if the installed Aztec CLI version matches the expected version in package.json
*/
async function checkAztecVersion() {
console.log("🔍 Checking Aztec CLI version");
// Read expected version from package.json
const packageJsonPath = join(__dirname, "..", "package.json");
const packageJson = JSON.parse(readFileSync(packageJsonPath, "utf8"));
const expectedVersion = packageJson.config?.aztecVersion;
if (!expectedVersion) {
throw new Error("❌ No aztecVersion found in package.json config");
}
console.log(`📋 Expected Aztec version: ${expectedVersion}`);
let installedVersion;
try {
// Check if aztec CLI is installed and get version
const { stdout } = await execAsync("aztec --version");
installedVersion = stdout.trim();
console.log("✅ Aztec CLI version check passed");
} catch (error) {
if (error.code === "ENOENT") {
throw new Error(
`❌ Aztec CLI not found!\n` +
` Please install aztec-up and run: VERSION=${expectedVersion} aztec-up`,
);
} else if (error.stdout) {
// Handle case where command exits with non-zero code (e.g., when sandbox is running)
// but version is still available in stdout
installedVersion = error.stdout.trim();
} else {
throw error;
}
}
console.log(`🔧 Installed Aztec version: ${installedVersion}`);
// Compare versions
if (installedVersion !== expectedVersion) {
throw new Error(
`❌ Version mismatch!\n` +
` Expected: ${expectedVersion}\n` +
` Installed: ${installedVersion}\n` +
` Please run: VERSION=${expectedVersion} aztec-up`,
);
}
}
export { checkAztecVersion };