1 | "use strict";
|
2 | var __importDefault = (this && this.__importDefault) || function (mod) {
|
3 | return (mod && mod.__esModule) ? mod : { "default": mod };
|
4 | };
|
5 | Object.defineProperty(exports, "__esModule", { value: true });
|
6 | exports.patchOptionsWithManifest = exports.log = exports.sequence = exports.CancellationToken = exports.isCancelledError = exports.nonnull = exports.flatten = exports.chain = exports.normalize = exports.getPublicGalleryAPI = exports.getSecurityRolesAPI = exports.getGalleryAPI = exports.getHubUrl = exports.getPublishedUrl = exports.read = void 0;
|
7 | const util_1 = require("util");
|
8 | const read_1 = __importDefault(require("read"));
|
9 | const WebApi_1 = require("azure-devops-node-api/WebApi");
|
10 | const GalleryApi_1 = require("azure-devops-node-api/GalleryApi");
|
11 | const chalk_1 = __importDefault(require("chalk"));
|
12 | const publicgalleryapi_1 = require("./publicgalleryapi");
|
13 | const os_1 = require("os");
|
14 | const __read = (0, util_1.promisify)(read_1.default);
|
15 | function read(prompt, options = {}) {
|
16 | if (process.env['VSCE_TESTS'] || !process.stdout.isTTY) {
|
17 | return Promise.resolve('y');
|
18 | }
|
19 | return __read({ prompt, ...options });
|
20 | }
|
21 | exports.read = read;
|
22 | const marketplaceUrl = process.env['VSCE_MARKETPLACE_URL'] || 'https://marketplace.visualstudio.com';
|
23 | function getPublishedUrl(extension) {
|
24 | return `${marketplaceUrl}/items?itemName=${extension}`;
|
25 | }
|
26 | exports.getPublishedUrl = getPublishedUrl;
|
27 | function getHubUrl(publisher, name) {
|
28 | return `${marketplaceUrl}/manage/publishers/${publisher}/extensions/${name}/hub`;
|
29 | }
|
30 | exports.getHubUrl = getHubUrl;
|
31 | async function getGalleryAPI(pat) {
|
32 |
|
33 | const authHandler = (0, WebApi_1.getBasicHandler)('OAuth', pat);
|
34 | return new GalleryApi_1.GalleryApi(marketplaceUrl, [authHandler]);
|
35 |
|
36 |
|
37 | }
|
38 | exports.getGalleryAPI = getGalleryAPI;
|
39 | async function getSecurityRolesAPI(pat) {
|
40 | const authHandler = (0, WebApi_1.getBasicHandler)('OAuth', pat);
|
41 | const vsoapi = new WebApi_1.WebApi(marketplaceUrl, authHandler);
|
42 | return await vsoapi.getSecurityRolesApi();
|
43 | }
|
44 | exports.getSecurityRolesAPI = getSecurityRolesAPI;
|
45 | function getPublicGalleryAPI() {
|
46 | return new publicgalleryapi_1.PublicGalleryAPI(marketplaceUrl, '3.0-preview.1');
|
47 | }
|
48 | exports.getPublicGalleryAPI = getPublicGalleryAPI;
|
49 | function normalize(path) {
|
50 | return path.replace(/\\/g, '/');
|
51 | }
|
52 | exports.normalize = normalize;
|
53 | function chain2(a, b, fn, index = 0) {
|
54 | if (index >= b.length) {
|
55 | return Promise.resolve(a);
|
56 | }
|
57 | return fn(a, b[index]).then(a => chain2(a, b, fn, index + 1));
|
58 | }
|
59 | function chain(initial, processors, process) {
|
60 | return chain2(initial, processors, process);
|
61 | }
|
62 | exports.chain = chain;
|
63 | function flatten(arr) {
|
64 | return [].concat.apply([], arr);
|
65 | }
|
66 | exports.flatten = flatten;
|
67 | function nonnull(arg) {
|
68 | return !!arg;
|
69 | }
|
70 | exports.nonnull = nonnull;
|
71 | const CancelledError = 'Cancelled';
|
72 | function isCancelledError(error) {
|
73 | return error === CancelledError;
|
74 | }
|
75 | exports.isCancelledError = isCancelledError;
|
76 | class CancellationToken {
|
77 | constructor() {
|
78 | this.listeners = [];
|
79 | this._cancelled = false;
|
80 | }
|
81 | get isCancelled() {
|
82 | return this._cancelled;
|
83 | }
|
84 | subscribe(fn) {
|
85 | this.listeners.push(fn);
|
86 | return () => {
|
87 | const index = this.listeners.indexOf(fn);
|
88 | if (index > -1) {
|
89 | this.listeners.splice(index, 1);
|
90 | }
|
91 | };
|
92 | }
|
93 | cancel() {
|
94 | const emit = !this._cancelled;
|
95 | this._cancelled = true;
|
96 | if (emit) {
|
97 | this.listeners.forEach(l => l(CancelledError));
|
98 | this.listeners = [];
|
99 | }
|
100 | }
|
101 | }
|
102 | exports.CancellationToken = CancellationToken;
|
103 | async function sequence(promiseFactories) {
|
104 | for (const factory of promiseFactories) {
|
105 | await factory();
|
106 | }
|
107 | }
|
108 | exports.sequence = sequence;
|
109 | var LogMessageType;
|
110 | (function (LogMessageType) {
|
111 | LogMessageType[LogMessageType["DONE"] = 0] = "DONE";
|
112 | LogMessageType[LogMessageType["INFO"] = 1] = "INFO";
|
113 | LogMessageType[LogMessageType["WARNING"] = 2] = "WARNING";
|
114 | LogMessageType[LogMessageType["ERROR"] = 3] = "ERROR";
|
115 | })(LogMessageType || (LogMessageType = {}));
|
116 | const LogPrefix = {
|
117 | [LogMessageType.DONE]: chalk_1.default.bgGreen.black(' DONE '),
|
118 | [LogMessageType.INFO]: chalk_1.default.bgBlueBright.black(' INFO '),
|
119 | [LogMessageType.WARNING]: chalk_1.default.bgYellow.black(' WARNING '),
|
120 | [LogMessageType.ERROR]: chalk_1.default.bgRed.black(' ERROR '),
|
121 | };
|
122 | function _log(type, msg, ...args) {
|
123 | args = [LogPrefix[type], msg, ...args];
|
124 | if (type === LogMessageType.WARNING) {
|
125 | process.env['GITHUB_ACTIONS'] ? logToGitHubActions('warning', msg) : console.warn(...args);
|
126 | }
|
127 | else if (type === LogMessageType.ERROR) {
|
128 | process.env['GITHUB_ACTIONS'] ? logToGitHubActions('error', msg) : console.error(...args);
|
129 | }
|
130 | else {
|
131 | process.env['GITHUB_ACTIONS'] ? logToGitHubActions('info', msg) : console.log(...args);
|
132 | }
|
133 | }
|
134 | const EscapeCharacters = new Map([
|
135 | ['%', '%25'],
|
136 | ['\r', '%0D'],
|
137 | ['\n', '%0A'],
|
138 | ]);
|
139 | const EscapeRegex = new RegExp(`[${[...EscapeCharacters.keys()].join('')}]`, 'g');
|
140 | function escapeGitHubActionsMessage(message) {
|
141 | return message.replace(EscapeRegex, c => EscapeCharacters.get(c) ?? c);
|
142 | }
|
143 | function logToGitHubActions(type, message) {
|
144 | const command = type === 'info' ? message : `::${type}::${escapeGitHubActionsMessage(message)}`;
|
145 | process.stdout.write(command + os_1.EOL);
|
146 | }
|
147 | exports.log = {
|
148 | done: _log.bind(null, LogMessageType.DONE),
|
149 | info: _log.bind(null, LogMessageType.INFO),
|
150 | warn: _log.bind(null, LogMessageType.WARNING),
|
151 | error: _log.bind(null, LogMessageType.ERROR),
|
152 | };
|
153 | function patchOptionsWithManifest(options, manifest) {
|
154 | if (!manifest.vsce) {
|
155 | return;
|
156 | }
|
157 | for (const key of Object.keys(manifest.vsce)) {
|
158 | const optionsKey = key === 'yarn' ? 'useYarn' : key;
|
159 | if (options[optionsKey] === undefined) {
|
160 | options[optionsKey] = manifest.vsce[key];
|
161 | }
|
162 | }
|
163 | }
|
164 | exports.patchOptionsWithManifest = patchOptionsWithManifest;
|
165 |
|
\ | No newline at end of file |