import { confirm } from "@inquirer/prompts";
import { printDiagnosticsToConsole, printResultToConsoleAndExitGracefully, } from "../../common/output.js";
import { PackageJsonUpgrader } from "../../common/upgraders/package-json-upgrader.js";
import { TSConfigUpgrader } from "../../common/upgraders/tsconfig-upgrader.js";
import { VsCodeSettingsJsonUpgrader } from "../../common/upgraders/vscode-settings-json-upgrader.js";
export async function update(argv) {
    let answer = false;
    if (argv.prompt === true) {
        printDiagnosticsToConsole("This command will make changes to your source code. Please commit your changes to version control before continuing.");
        answer = await confirm({ message: "Continue?", default: true });
    }
    if (answer || argv.prompt === false) {
        const u = new PackageJsonUpgrader(argv.dir);
        if ((await u.isApplicable()).ok) {
            printDiagnosticsToConsole("Updating your package.json...");
            await u.upgrade();
        }
        const v = new VsCodeSettingsJsonUpgrader(argv.dir);
        if ((await v.isApplicable()).ok) {
            printDiagnosticsToConsole("Updating your .vscode settings...");
            await v.upgrade();
        }
        const t = new TSConfigUpgrader(argv.dir);
        if ((await t.isApplicable()).ok) {
            printDiagnosticsToConsole("Rewriting your tsconfig.json...");
            await t.upgrade();
        }
        await printResultToConsoleAndExitGracefully("Update completed");
    }
}
//# sourceMappingURL=handler.js.map