Skip to content

Commit 133b8fa

Browse files
committed
Add installation tests
1 parent 1738209 commit 133b8fa

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+3630
-49
lines changed

src/command/install/cmd.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ export const installCommand = new Command()
1313
.hidden() // TODO: unhide when ready
1414
.name("install")
1515
.arguments("[target:string]")
16+
.option(
17+
"--no-prompt",
18+
"Do not prompt to confirm installation extension",
19+
)
1620
.description(
1721
"Installs a Quarto Extension into the current directory or Project directory.",
1822
)
@@ -28,12 +32,12 @@ export const installCommand = new Command()
2832
"Install extension from url",
2933
"quarto install https://github.com/quarto-dev/quarto-extensions/releases/download/latest/my-extension.tar.gz",
3034
)
31-
.action(async (_options: unknown, target?: string) => {
35+
.action(async (options: { prompt?: boolean }, target?: string) => {
3236
await initYamlIntelligenceResourcesFromFilesystem();
3337
const temp = createTempContext();
3438
try {
3539
if (target) {
36-
await installExtension(target, temp, true);
40+
await installExtension(target, temp, options.prompt !== false);
3741
}
3842
} finally {
3943
temp.cleanup();

src/extension/install.ts

Lines changed: 7 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import { ensureDirSync, existsSync } from "fs/mod.ts";
99
import { Confirm } from "cliffy/prompt/mod.ts";
1010
import { Table } from "cliffy/table/mod.ts";
11-
import { writeAllSync } from "streams/mod.ts";
1211
import { basename, dirname, join } from "path/mod.ts";
1312

1413
import { projectContext } from "../project/project-context.ts";
@@ -19,6 +18,7 @@ import { Extension, kExtensionDir } from "./extension-shared.ts";
1918
import { withSpinner } from "../core/console.ts";
2019
import { downloadWithProgress } from "../core/download.ts";
2120
import { readExtensions } from "./extension.ts";
21+
import { info } from "log/mod.ts";
2222

2323
export interface ExtensionSource {
2424
type: "remote" | "local";
@@ -73,10 +73,7 @@ export async function installExtension(
7373

7474
// Cancels the installation, providing user feedback that the installation is canceled
7575
function cancelInstallation() {
76-
writeAllSync(
77-
Deno.stdout,
78-
new TextEncoder().encode("Installation canceled\n"),
79-
);
76+
info("Installation canceled\n");
8077
}
8178

8279
// Determines whether the user trusts the extension
@@ -88,7 +85,7 @@ async function isTrusted(
8885
// Write the preamble
8986
const preamble =
9087
`\nQuarto extensions may execute code when documents are rendered. If you do not \ntrust the authors of the extension, we recommend that you do not install or \nuse the extension.\n\n`;
91-
writeAllSync(Deno.stdout, new TextEncoder().encode(preamble));
88+
info(preamble);
9289

9390
// Ask for trust
9491
const question = "Do you trust the authors of this extension";
@@ -210,11 +207,7 @@ async function unzipAndStage(
210207
// them to a destination directory
211208
function readAndCopyExtensions(extensionsDir: string, targetDir: string) {
212209
const extensions = readExtensions(extensionsDir);
213-
214-
writeAllSync(
215-
Deno.stdout,
216-
new TextEncoder().encode(` Found ${extensions.length} extensions.`),
217-
);
210+
info(` Found ${extensions.length} extensions.`);
218211

219212
for (const extension of extensions) {
220213
copyTo(
@@ -395,33 +388,18 @@ async function confirmInstallation(
395388

396389
if (extensionRows.length > 0) {
397390
const table = new Table(...extensionRows);
398-
writeAllSync(
399-
Deno.stdout,
400-
new TextEncoder().encode(
401-
`\nThe following changes will be made:\n${table.toString()}\n\n`,
402-
),
403-
);
404-
391+
info(`\nThe following changes will be made:\n${table.toString()}\n\n`);
405392
const question = "Would you like to continue";
406393
return !allowPrompt || await Confirm.prompt(question);
407394
} else {
408-
writeAllSync(
409-
Deno.stdout,
410-
new TextEncoder().encode(
411-
`\nNo changes required - extensions already installed.\n\n`,
412-
),
413-
);
395+
info(`\nNo changes required - extensions already installed.\n\n`);
414396
return true;
415397
}
416398
}
417399

418400
// Copy the extension files into place
419401
async function completeInstallation(downloadDir: string, installDir: string) {
420-
writeAllSync(
421-
Deno.stdout,
422-
new TextEncoder().encode("\n"),
423-
);
424-
402+
info("\n");
425403
await withSpinner({
426404
message: `Copying`,
427405
doneMessage: `Extension installation complete`,
41 KB
Binary file not shown.

0 commit comments

Comments
 (0)