2023-02-26 11:34:26 +00:00
|
|
|
import { Command } from "./dependencies.ts";
|
2023-06-07 13:43:02 +00:00
|
|
|
import { runAndReturnStdout, runCommand } from "./utilities.ts";
|
2022-12-09 11:26:08 +00:00
|
|
|
|
|
|
|
async function main(): Promise<void> {
|
|
|
|
const { options } = await new Command()
|
|
|
|
.name("codium-extensions")
|
|
|
|
.description("Small managing utility for VS Codium extensions!")
|
|
|
|
.option(
|
|
|
|
"-f, --file <file:file>",
|
|
|
|
"The file to use for storing data.",
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
new URL("../data/codium-extensions.txt", import.meta.url).pathname,
|
|
|
|
},
|
|
|
|
)
|
|
|
|
.option("--install", "Install saved extensions.")
|
|
|
|
.option("--list", "List installed extensions.")
|
|
|
|
.option("--list-saved", "List saved extensions.")
|
|
|
|
.option("--save", "Save installed extensions.")
|
|
|
|
.parse(Deno.args);
|
|
|
|
|
|
|
|
if (options.install) {
|
|
|
|
const extensions = await getSavedExtensions(options.file);
|
2023-06-07 13:43:02 +00:00
|
|
|
await runCommand("codium", {
|
2023-06-05 11:27:29 +00:00
|
|
|
args: [
|
2022-12-09 11:26:08 +00:00
|
|
|
...extensions.flatMap((id) => ["--install-extension", id]),
|
|
|
|
],
|
2023-06-07 13:43:02 +00:00
|
|
|
});
|
2022-12-09 11:26:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (options.list) {
|
|
|
|
const extensions = await getInstalledExtensions();
|
|
|
|
console.log(extensions.join("\n"));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (options.listSaved) {
|
|
|
|
const extensions = await getSavedExtensions(options.file);
|
|
|
|
console.log(extensions.join("\n"));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (options.save) {
|
|
|
|
const extensions = await getInstalledExtensions();
|
|
|
|
await Deno.writeTextFile(options.file, extensions.join("\n") + "\n");
|
|
|
|
console.log(`Wrote ${extensions.length} extensions to ${options.file}`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-07 13:20:51 +00:00
|
|
|
/** Run `codium --list-extensions` and return all the extensions as an array. */
|
2022-12-09 11:26:08 +00:00
|
|
|
async function getInstalledExtensions(): Promise<string[]> {
|
2023-06-05 11:27:29 +00:00
|
|
|
const extensions = await runAndReturnStdout("codium", {
|
|
|
|
args: ["--list-extensions"],
|
2022-12-09 11:26:08 +00:00
|
|
|
});
|
|
|
|
return extensions.trim().split("\n");
|
|
|
|
}
|
|
|
|
|
2023-08-07 13:20:51 +00:00
|
|
|
/** Get all the saved extensions from the codium-extensions data file. */
|
2022-12-09 11:26:08 +00:00
|
|
|
async function getSavedExtensions(file: string): Promise<string[]> {
|
|
|
|
const extensions = await Deno.readTextFile(file);
|
|
|
|
return extensions.trim().split("\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (import.meta.main) {
|
|
|
|
void main();
|
|
|
|
}
|