#!/usr/bin/env node import { readFileSync, writeFileSync } from "node:fs"; import { execSync, spawnSync } from "node:child_process"; import { resolve } from "node:path"; import { parseArgs } from "node:util"; const skAzToolsPackagePath = resolve("package.json"); const skToolsPackagePath = resolve("../sk-tools", "package.json"); const skAzToolsPackage = JSON.parse(readFileSync(skAzToolsPackagePath, "utf-8")); const skToolsPackage = JSON.parse(readFileSync(skToolsPackagePath, "utf-8")); const { values } = parseArgs({ options: { update: { type: "boolean", short: "u", description: "Update @slawek/sk-tools to the latest version." } } }); // Package versions console.log(`SK Tools version: ${skToolsPackage.version}`); console.log(`SK Azure Tools version: ${skAzToolsPackage.version}`); if (values.update) { console.log(`\nUpdating package.json to use @slawek/sk-tools version ${skToolsPackage.version} or later...`); skAzToolsPackage.dependencies["@slawek/sk-tools"] = `>=${skToolsPackage.version}`; writeFileSync(skAzToolsPackagePath, JSON.stringify(skAzToolsPackage, null, 4)); // Install and link the updated package spawnSync("npm", ["install", "@slawek/sk-tools"], { stdio: "inherit" }); spawnSync("npm", ["link", "@slawek/sk-tools"], { stdio: "inherit" }); // Show the updated dependency tree spawnSync("npm", ["ls"], { stdio: "inherit" }); } else { console.log(`\nSK Tools version requested: ${skAzToolsPackage.dependencies["@slawek/sk-tools"] ?? "not found"}`); }