From 6ca85b8be3b3a81d000d30672dcc58ca18bf73b1 Mon Sep 17 00:00:00 2001 From: Joao Moreno Date: Fri, 3 May 2019 13:05:04 +0200 Subject: [PATCH] unpublish extension --- src/main.ts | 8 +++++++- src/publish.ts | 23 +++++++++++++++++++++-- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/main.ts b/src/main.ts index 0632688..3bbde9a 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,6 +1,6 @@ import * as program from 'commander'; import { packageCommand, ls } from './package'; -import { publish, unpublish } from './publish'; +import { publish, deleteExtension, unpublish } from './publish'; import { show } from './show'; import { search } from './search'; import { listPublishers, createPublisher, deletePublisher, loginPublisher, logoutPublisher } from './store'; @@ -88,6 +88,12 @@ module.exports = function (argv: string[]): void { .option('-p, --pat ', 'Personal Access Token') .action((id, { pat }) => main(unpublish({ id, pat }))); + program + .command('delete []') + .description('Deletes an extension. Example extension id: microsoft.csharp.') + .option('-p, --pat ', 'Personal Access Token') + .action((id, { pat }) => main(deleteExtension({ id, pat }))); + program .command('ls-publishers') .description('List all known publishers') diff --git a/src/publish.ts b/src/publish.ts index e050dc0..cfafc6c 100644 --- a/src/publish.ts +++ b/src/publish.ts @@ -1,5 +1,5 @@ import * as fs from 'fs'; -import { ExtensionQueryFlags, PublishedExtension, ExtensionQueryFilterType, PagingDirection, SortByType, SortOrderType } from 'azure-devops-node-api/interfaces/GalleryInterfaces'; +import { ExtensionQueryFlags, PublishedExtension, ExtensionQueryFilterType, PagingDirection, SortByType, SortOrderType, PublishedExtensionFlags } from 'azure-devops-node-api/interfaces/GalleryInterfaces'; import { pack, readManifest, IPackage } from './package'; import * as tmp from 'tmp'; import { getPublisher } from './store'; @@ -168,7 +168,26 @@ export interface IUnpublishOptions extends IPublishOptions { id?: string; } -export function unpublish(options: IUnpublishOptions = {}): Promise { +export async function unpublish(options: IUnpublishOptions = {}): Promise { + let publisher: string, name: string; + + if (options.id) { + [publisher, name] = options.id.split('.'); + } else { + const manifest = await readManifest(options.cwd); + publisher = manifest.publisher; + name = manifest.name; + } + + const fullName = `${publisher}.${name}`; + const pat = options.pat || (await getPublisher(publisher)).pat; + const api = await getGalleryAPI(pat); + const ext = await api.getExtension(null, publisher, name); + await api.updateExtensionProperties(publisher, name, ext.flags | PublishedExtensionFlags.Unpublished); // https://github.com/Microsoft/vscode-vsce/issues/318 + log.done(`Unpublished extension: ${fullName}!`); +} + +export function deleteExtension(options: IUnpublishOptions = {}): Promise { let promise: Promise<{ publisher: string; name: string; }>; if (options.id) {