-
Notifications
You must be signed in to change notification settings - Fork 138
Expand file tree
/
Copy pathshare.ts
More file actions
75 lines (67 loc) · 2.32 KB
/
share.ts
File metadata and controls
75 lines (67 loc) · 2.32 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
import { TfCommand } from "../../lib/tfcommand";
import args = require("../../lib/arguments");
import colors = require("colors");
import extBase = require("./default");
import extInfo = require("./_lib/extensioninfo");
import trace = require("../../lib/trace");
import { SharingManager } from "./_lib/publish";
export function getCommand(args: string[]): TfCommand<extBase.ExtensionArguments, string[]> {
return new ExtensionShare(args);
}
export class ExtensionShare extends extBase.ExtensionBase<string[]> {
protected description = "Share an Azure DevOps Extension with Azure DevOps Organizations.";
protected serverCommand = true;
constructor(passedArgs: string[]) {
super(passedArgs);
this.registerCommandArgument(
"shareWith",
"Share with",
"List of organizations with which to share the extension.",
args.ArrayArgument,
);
this.registerCommandArgument(
"serviceUrl",
"Market URL",
"URL to the VSS Marketplace.",
args.StringArgument,
extBase.ExtensionBase.getMarketplaceUrl,
);
}
protected getHelpArgs(): string[] {
return ["publisher", "extensionId", "vsix", "shareWith"];
}
public async exec(): Promise<string[]> {
const galleryApi = await this.webApi.getGalleryApi(this.webApi.serverUrl);
return this.commandArgs.vsix.val(true).then(vsixPath => {
let extInfoPromise: Promise<extInfo.CoreExtInfo>;
if (vsixPath !== null) {
extInfoPromise = extInfo.getExtInfo(vsixPath[0], null, null);
} else {
extInfoPromise = Promise.all([this.commandArgs.publisher.val(), this.commandArgs.extensionId.val()]).then<
extInfo.CoreExtInfo
>(values => {
const [publisher, extension] = values;
return extInfo.getExtInfo(null, extension, publisher);
});
}
return extInfoPromise.then(extInfo => {
return this.commandArgs.shareWith.val().then(shareWith => {
let sharePromises: Promise<void>[] = [];
shareWith.forEach(account => {
sharePromises.push(SharingManager.shareExtension(galleryApi, extInfo.publisher, extInfo.id, account));
});
return Promise.all(sharePromises).then(() => {
return shareWith;
});
});
});
});
}
protected friendlyOutput(data: string[]): void {
trace.success("\n=== Completed operation: share extension ===");
trace.info(" - Shared with:");
data.forEach(acct => {
trace.info(" - " + acct);
});
}
}