Skip to content

Commit

Permalink
async function unpublish
Browse files Browse the repository at this point in the history
  • Loading branch information
joaomoreno committed Dec 2, 2019
1 parent aa73aac commit 3bcc603
Showing 1 changed file with 22 additions and 24 deletions.
46 changes: 22 additions & 24 deletions src/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ export interface IPublishOptions {
commitMessage?: string;
cwd?: string;
pat?: string;
force?: boolean;
baseContentUrl?: string;
baseImagesUrl?: string;
useYarn?: boolean;
Expand Down Expand Up @@ -175,34 +174,33 @@ export function publish(options: IPublishOptions = {}): Promise<any> {

export interface IUnpublishOptions extends IPublishOptions {
id?: string;
force?: boolean;
}

export function unpublish(options: IUnpublishOptions = {}): Promise<any> {
let promise: Promise<{ publisher: string; name: string; }>;
export async function unpublish(options: IUnpublishOptions = {}): Promise<any> {
let publisher: string, name: string;

if (options.id) {
const [publisher, name] = options.id.split('.');
promise = Promise.resolve(({ publisher, name }));
[publisher, name] = options.id.split('.');
} else {
promise = readManifest(options.cwd);
const manifest = await readManifest(options.cwd);
publisher = manifest.publisher;
name = manifest.name;
}

return promise.then(({ publisher, name }) => {

const fullName = `${publisher}.${name}`;
const pat = options.pat
? Promise.resolve(options.pat)
: getPublisher(publisher).then(p => p.pat);

const force = options.force;

return (!force ? (
read(`This will FOREVER delete '${fullName}'! Are you sure? [y/N] `)
.then(answer => /^y$/i.test(answer) ? pat : Promise.reject('Aborted'))
//.then(() => pat)
) : pat)
.then(getGalleryAPI)
.then(api => api.deleteExtension(publisher, name))
.then(() => log.done(`Deleted extension: ${fullName}!`));
});
const fullName = `${publisher}.${name}`;

if (!options.force) {
const answer = await read(`This will FOREVER delete '${fullName}'! Are you sure? [y/N] `);

if (!/^y$/i.test(answer)) {
throw new Error('Aborted');
}
}

const pat = options.pat || (await getPublisher(publisher).then(p => p.pat));
const api = await getGalleryAPI(pat);

await api.deleteExtension(publisher, name);
log.done(`Deleted extension: ${fullName}!`);
}

0 comments on commit 3bcc603

Please sign in to comment.