1 import { promisify } from "util";
2 import { exec } from "child_process";
3 import Logger from "../logger.mjs";
4 import { unlink } from "fs/promises";
6 const execAsync = promisify(exec);
9 * Initialize git submodules in downloaded Pico-SDK.
11 * @param sdkDirectory The directory of the downloaded Pico-SDK.
12 * @returns True if the submodules were initialized successfully, false otherwise.
14 export async function initSubmodules(
16 gitExecutable: string = "git"
19 // Use the "git submodule update --init" command in the specified directory
21 `cd "${sdkDirectory}" && ` +
23 process.env.ComSpec === "powershell.exe" ? "&" : ""
24 }"${gitExecutable}" submodule update --init`;
25 await execAsync(command);
35 export async function cloneRepository(
38 targetDirectory: string,
39 gitExecutable: string = "git"
41 // Clone the repository at the specified tag into the target directory
44 process.env.ComSpec === "powershell.exe" ? "&" : ""
45 }"${gitExecutable}" -c advice.detachedHead=false clone --branch ` +
46 `${branch} ${repository} "${targetDirectory}"`;
49 await execAsync(cloneCommand);
51 Logger.log(`SDK/Pyenv ${branch} has been cloned and installed.`);
56 await unlink(targetDirectory);
61 const err = error instanceof Error ? error.message : (error as string);
62 if (err.includes("already exists")) {
65 Logger.log(`Error while cloning repository: ${err}`);