Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
quarto-dev
GitHub Repository: quarto-dev/quarto-cli
Path: blob/main/src/tools/types.ts
6438 views
1
/*
2
* types.ts
3
*
4
* Copyright (C) 2020-2022 Posit Software, PBC
5
*/
6
7
import { SpinnerOptions } from "../core/console-types.ts";
8
9
export const kUpdatePath = "update-path";
10
11
// Installable Tool interface
12
export interface InstallableTool {
13
name: string;
14
prereqs: InstallPreReq[];
15
installed: () => Promise<boolean>;
16
installDir: () => Promise<string | undefined>;
17
binDir?: () => Promise<string | undefined>;
18
installedVersion: () => Promise<string | undefined>;
19
latestRelease: () => Promise<RemotePackageInfo>;
20
preparePackage: (ctx: InstallContext) => Promise<PackageInfo>;
21
verifyConfiguration?: () => Promise<ToolConfigurationState>;
22
install: (pkgInfo: PackageInfo, ctx: InstallContext) => Promise<void>;
23
afterInstall: (ctx: InstallContext) => Promise<boolean>; // return true if restart is required, false if not
24
uninstall: (ctx: InstallContext) => Promise<void>;
25
}
26
27
// Prerequisites to installation. These will be checked before installation
28
// and if any return false, the message will be displaed and installation will be
29
// halted
30
export interface InstallPreReq {
31
check: (context: InstallContext) => Promise<boolean>;
32
os: string[];
33
message: string;
34
}
35
36
// Locally accessible Package information
37
export interface PackageInfo {
38
filePath: string;
39
version: string;
40
}
41
42
// Remove package information
43
export interface RemotePackageInfo {
44
url: string;
45
version: string;
46
assets: Array<{ name: string; url: string }>;
47
}
48
49
// Tool Remote information
50
export interface ToolInfo {
51
version?: string;
52
latest: GitHubRelease;
53
}
54
55
export interface ToolConfigurationState {
56
status: "ok" | "warning" | "error";
57
message?: string;
58
}
59
60
// InstallContext provides the API for installable tools
61
// InstallableTools can use the context to show progress, show info, etc...
62
export interface InstallContext {
63
workingDir: string;
64
info: (msg: string) => void;
65
withSpinner: (
66
options: SpinnerOptions,
67
op: () => Promise<void>,
68
) => Promise<void>;
69
error: (msg: string) => void;
70
confirm: (msg: string, def?: boolean) => Promise<boolean>;
71
download: (name: string, url: string, target: string) => Promise<void>;
72
props: { [key: string]: unknown };
73
flags: {
74
[kUpdatePath]?: boolean;
75
};
76
}
77
78
export interface ToolSummaryData {
79
installed: boolean;
80
installedVersion?: string;
81
latestRelease: RemotePackageInfo;
82
configuration: ToolConfigurationState;
83
}
84
85
export interface GitHubRelease {
86
html_url: string;
87
tag_name: string;
88
assets: GitHubAsset[];
89
}
90
91
// A Downloadable Github Asset
92
export interface GitHubAsset {
93
name: string;
94
browser_download_url: string;
95
}
96
97