forked from github/vscode-codeql
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpackaging.ts
More file actions
144 lines (140 loc) · 4.03 KB
/
packaging.ts
File metadata and controls
144 lines (140 loc) · 4.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
import { CodeQLCliServer } from './cli';
import * as fs from 'fs-extra';
import * as path from 'path';
import {
getOnDiskWorkspaceFolders,
showAndLogErrorMessage,
showAndLogInformationMessage,
} from './helpers';
import { window } from 'vscode';
import { ProgressCallback } from './commandRunner';
const CORE_PACKS = [
'codeql/cpp-all',
'codeql/csharp-all',
'codeql/go-all',
'codeql/java-all',
'codeql/javascript-all',
'codeql/python-all',
'codeql/ruby-all',
];
/**
* Lists all workspace folders that contain a qlpack.yml file.
*
* Note: This currently only finds packs at the root of a workspace folder.
* TODO: Add support for packs in subfolders.
*/
function getWorkspacePacks(): string[] {
const packs: string[] = [];
const workspaceFolders = getOnDiskWorkspaceFolders();
for (const folder of workspaceFolders) {
const qlpackYml = path.join(folder, 'qlpack.yml');
if (fs.pathExistsSync(qlpackYml)) {
packs.push(folder);
}
}
return packs;
}
/**
* Prompts user to choose packs to download, and downloads them.
*
* @param cliServer The CLI server.
* @param progress A progress callback.
*/
export async function handleDownloadPacks(
cliServer: CodeQLCliServer,
progress: ProgressCallback,
): Promise<void> {
progress({
message: 'Choose packs to download',
step: 1,
maxStep: 2,
});
let packsToDownload: string[] = [];
const corePackOption = 'Download core CodeQL packs';
const customPackOption = 'Download custom specified pack';
const quickpick = await window.showQuickPick(
[corePackOption, customPackOption],
{ ignoreFocusOut: true }
);
if (quickpick === corePackOption) {
packsToDownload = CORE_PACKS;
} else if (quickpick === customPackOption) {
const customPack = await window.showInputBox({
prompt:
'Enter the <package-scope/name[@version]> of the pack to download',
ignoreFocusOut: true,
});
if (customPack) {
packsToDownload.push(customPack);
} else {
void showAndLogErrorMessage('No pack specified.');
}
}
if (packsToDownload && packsToDownload.length > 0) {
progress({
message: `Downloading ${packsToDownload.join(', ')}`,
step: 2,
maxStep: 2,
});
for (const pack of packsToDownload) {
try {
await cliServer.packDownload(pack);
} catch (error) {
void showAndLogErrorMessage(`Unable to download pack ${pack}. See logs for more details.`);
}
}
void showAndLogInformationMessage('Finished downloading packs.');
}
}
/**
* Prompts user to choose packs to install, and installs them.
*
* @param cliServer The CLI server.
* @param progress A progress callback.
*/
export async function handleInstallPacks(
cliServer: CodeQLCliServer,
progress: ProgressCallback,
): Promise<void> {
progress({
message: 'Choose packs to install',
step: 1,
maxStep: 2,
});
let packsToInstall: string[] = [];
const workspacePackOption = 'Install workspace packs';
const customPackOption = 'Install custom specified pack';
const quickpick = await window.showQuickPick(
[workspacePackOption, customPackOption],
{ ignoreFocusOut: true }
);
if (quickpick === workspacePackOption) {
packsToInstall = getWorkspacePacks();
} else if (quickpick === customPackOption) {
const customPack = await window.showInputBox({
prompt:
'Enter the root directory of the pack to install (as an absolute path)',
ignoreFocusOut: true,
});
if (customPack) {
packsToInstall.push(customPack);
} else {
void showAndLogErrorMessage('No pack specified.');
}
}
if (packsToInstall && packsToInstall.length > 0) {
progress({
message: `Installing ${packsToInstall.join(', ')}`,
step: 2,
maxStep: 2,
});
for (const pack of packsToInstall) {
try {
await cliServer.packInstall(pack);
} catch (error) {
void showAndLogErrorMessage(`Unable to install pack ${pack}. See logs for more details.`);
}
}
void showAndLogInformationMessage('Finished installing packs.');
}
}