Merge pull request #160 from Microsoft/vso-stream-api

Adopt the latest vso-node-api
This commit is contained in:
João Moreno 2017-03-31 08:42:09 +02:00 committed by GitHub
commit 12e138b13c
3 changed files with 21 additions and 22 deletions

View file

@ -42,7 +42,7 @@
"semver": "^5.1.0",
"tmp": "0.0.29",
"url-join": "^1.1.0",
"vso-node-api": "^5.0.5",
"vso-node-api": "^6.1.2-preview",
"yauzl": "^2.3.1",
"yazl": "^2.2.2"
},

View file

@ -11,7 +11,6 @@ import * as yauzl from 'yauzl';
import * as semver from 'semver';
const tmpName = denodeify<string>(tmp.tmpName);
const readFile = denodeify<string, string, string>(fs.readFile);
function readManifestFromPackage(packagePath: string): Promise<Manifest> {
return new Promise<Manifest>((c, e) => {
@ -54,26 +53,26 @@ function readManifestFromPackage(packagePath: string): Promise<Manifest> {
function _publish(packagePath: string, pat: string, manifest: Manifest): Promise<void> {
const api = getGalleryAPI(pat);
return readFile(packagePath, 'base64').then(extensionManifest => {
const fullName = `${manifest.publisher}.${manifest.name}@${manifest.version}`;
console.log(`Publishing ${fullName}...`);
const packageStream = fs.createReadStream(packagePath);
return api.getExtension(manifest.publisher, manifest.name, null, ExtensionQueryFlags.IncludeVersions)
.catch<PublishedExtension>(err => err.statusCode === 404 ? null : Promise.reject(err))
.then(extension => {
if (extension && extension.versions.some(v => v.version === manifest.version)) {
return Promise.reject(`${fullName} already exists. Version number cannot be the same.`);
}
const fullName = `${manifest.publisher}.${manifest.name}@${manifest.version}`;
console.log(`Publishing ${fullName}...`);
var promise = extension
? api.updateExtension({ extensionManifest }, manifest.publisher, manifest.name)
: api.createExtension({ extensionManifest });
return api.getExtension(manifest.publisher, manifest.name, null, ExtensionQueryFlags.IncludeVersions)
.catch<PublishedExtension>(err => err.statusCode === 404 ? null : Promise.reject(err))
.then(extension => {
if (extension && extension.versions.some(v => v.version === manifest.version)) {
return Promise.reject(`${fullName} already exists. Version number cannot be the same.`);
}
return promise
.catch(err => Promise.reject(err.statusCode === 409 ? `${fullName} already exists.` : err))
.then(() => console.log(`Successfully published ${fullName}!`));
});
});
var promise = extension
? api.updateExtension(undefined, packageStream, manifest.publisher, manifest.name)
: api.createExtension(undefined, packageStream);
return promise
.catch(err => Promise.reject(err.statusCode === 409 ? `${fullName} already exists.` : err))
.then(() => console.log(`Successfully published ${fullName}!`));
});
}
export interface IPublishOptions {

View file

@ -4,7 +4,7 @@ import { WebApi, getBasicHandler } from 'vso-node-api/WebApi';
import { IGalleryApi } from 'vso-node-api/GalleryApi';
import * as denodeify from 'denodeify';
const __read = denodeify<_read.Options,string>(_read);
const __read = denodeify<_read.Options, string>(_read);
export function read(prompt: string, options: _read.Options = {}): Promise<string> {
return __read(assign({ prompt }, options));
}
@ -19,7 +19,7 @@ export function normalize(path: string): string {
return path.replace(/\\/g, '/');
}
function chain2<A,B>(a: A, b: B[], fn: (a: A, b: B)=>Promise<A>, index = 0): Promise<A> {
function chain2<A, B>(a: A, b: B[], fn: (a: A, b: B) => Promise<A>, index = 0): Promise<A> {
if (index >= b.length) {
return Promise.resolve(a);
}
@ -27,7 +27,7 @@ function chain2<A,B>(a: A, b: B[], fn: (a: A, b: B)=>Promise<A>, index = 0): Pro
return fn(a, b[index]).then(a => chain2(a, b, fn, index + 1));
}
export function chain<T,P>(initial: T, processors: P[], process: (a: T, b: P)=>Promise<T>): Promise<T> {
export function chain<T, P>(initial: T, processors: P[], process: (a: T, b: P) => Promise<T>): Promise<T> {
return chain2(initial, processors, process);
}