publisher delete

This commit is contained in:
Joao Moreno 2015-10-07 15:02:35 +02:00
parent 993559e130
commit 9965f058be
3 changed files with 26 additions and 9 deletions

View file

@ -14,6 +14,7 @@ Commands:
unpublish [<publisher> <name>] Unpublishes an extension
list <publisher> Lists all extensions published by the given publisher
publisher create <publisher> Creates a new publisher
publisher delete <publisher> Deletes a publisher
publisher add <publisher> Add a publisher
publisher rm <publisher> Remove a publisher
publisher list List all added publishers

View file

@ -71,7 +71,7 @@ export function unpublish(publisher?: string, name?: string, cwd = process.cwd()
return details.then(({ publisher, name }) => {
const fullName = `${ publisher }.${ name }`;
return read(`This will FOREVER delete ${ fullName }! Are you sure? [y/N] `)
return read(`This will FOREVER delete '${ fullName }'! Are you sure? [y/N] `)
.then(answer => /^y$/i.test(answer) ? null : reject('Aborted'))
.then(() => getPublisher(publisher))
.then(p => p.pat)

View file

@ -1,9 +1,9 @@
import * as fs from 'fs';
import * as path from 'path';
import { exec } from 'child_process';
import { Promise, nfcall, resolve, reject } from 'q';
import { Promise, nfcall, resolve, reject, ninvoke } from 'q';
import { home } from 'osenv';
import { read, getGalleryAPI } from './util';
import { read, getGalleryAPI, getRawGalleryAPI } from './util';
import { validatePublisher } from './validation';
const storePath = path.join(home(), '.vsce');
@ -55,6 +55,11 @@ function addPublisherToStore(store: IStore, publisher: IPublisher): Promise<IPub
return save(store).then(() => publisher);
}
function removePublisherFromStore(store: IStore, publisherName: string): Promise<any> {
store.publishers = store.publishers.filter(p => p.name !== publisherName);
return save(store);
}
function requestPAT(store: IStore, publisherName: string): Promise<IPublisher> {
return read(`Personal Access Token for publisher '${ publisherName }':`, { silent: true, replace: '*' })
.then(pat => {
@ -105,8 +110,7 @@ function rmPublisher(publisherName: string): Promise<any> {
return reject(`Unknown publisher '${ publisherName }'`);
}
store.publishers = store.publishers.filter(p => p.name !== publisherName);
return save(store);
return removePublisherFromStore(store, publisherName);
});
}
@ -130,6 +134,17 @@ function createPublisher(publisherName: string): Promise<any> {
.then(() => ({ name: publisherName, pat }));
})
.then(publisher => load().then(store => addPublisherToStore(store, publisher)));
})
.then(() => console.log(`Successfully created publisher '${ publisherName }'.`));
}
function deletePublisher(publisherName: string): Promise<any> {
return getPublisher(publisherName).then(({ pat }) => {
return read(`This will FOREVER delete '${ publisherName }'! Are you sure? [y/N] `)
.then(answer => /^y$/i.test(answer) ? null : reject('Aborted'))
.then(() => ninvoke(getRawGalleryAPI(pat), 'deletePublisher', publisherName))
.then(() => load().then(store => removePublisherFromStore(store, publisherName)))
.then(() => console.log(`Successfully deleted publisher '${ publisherName }'.`));
});
}
@ -137,11 +152,12 @@ function listPublishers(): Promise<IPublisher[]> {
return load().then(store => store.publishers);
}
export function publisher(action: string, publisher: string): Promise<any> {
export function publisher(action: string, publisherName: string): Promise<any> {
switch (action) {
case 'create': return createPublisher(publisher);
case 'add': return addPublisher(publisher);
case 'rm': return rmPublisher(publisher);
case 'create': return createPublisher(publisherName);
case 'delete': return deletePublisher(publisherName);
case 'add': return addPublisher(publisherName);
case 'rm': return rmPublisher(publisherName);
case 'list': default: return listPublishers().then(publishers => publishers.forEach(p => console.log(p.name)));
}
}