<commit_before>/// <reference path="../../definitions/tsd.d.ts" />

import argm = require('../lib/arguments');
import cmdm = require('../lib/tfcommand');
import cm = require('../lib/common');
import createm = require('./extension-create');
import extinfom = require('../lib/extensioninfo');
import fs = require('fs');
import gallerym = require('vso-node-api/GalleryApi');
import galleryifm = require('vso-node-api/interfaces/GalleryInterfaces');
import os = require('os');
import Q = require('q');
import sharem = require('./extension-share');
var trace = require('../lib/trace');

export function describe(): string {
    return 'Publish a VSIX package to your account. Generates the VSIX using [package_settings_path] unless --vsix is specified.';
}

export function getCommand(): cmdm.TfCommand {
    // this just offers description for help and to offer sub commands
    return new ExtensionPublish;
}

// requires auth, connect etc...
export var isServerOperation: boolean = true;

// unless you have a good reason, should not hide
export var hideBanner: boolean = false;

export interface PublishResults {
    vsixPath: string,
    shareWith: string[]
}

export class ExtensionPublish extends cmdm.TfCommand {
    optionalArguments = [argm.VSIX_PATH, argm.SHARE_WITH];
    
    public exec(args: string[], options: cm.IOptions): Q.Promise<PublishResults> {
        trace.debug('extension-publish.exec');
        var galleryapi: gallerym.IQGalleryApi = this.getWebApi().getQGalleryApi(this.connection.galleryUrl);
        return this.checkArguments(args, options).then( (allArguments: cm.IStringIndexer) => {        
			return Q.Promise<string>((resolve, reject, notify) => {
                if (allArguments[argm.VSIX_PATH.name]) {
                    trace.debug("VSIX was manually specified. Skipping generation.");
                    resolve(allArguments[argm.VSIX_PATH.name]);
                } else {
                    trace.info("VSIX not specified. Creating new package.");
                    resolve(createm.getCommand().exec(args, options));
                }
            }).then((vsixPath: string) => {
                trace.debug("Begin publish to Gallery");
                return new PublisherManager(galleryapi).publish(vsixPath).then(() => {
                    trace.debug("Success");
                    return <PublishResults> {
                        vsixPath: vsixPath
                    };
                });            
            }).then((results: PublishResults) => {
                trace.debug("Begin sharing");
				if (allArguments[argm.SHARE_WITH.name]) {
                    var sharer: sharem.ExtensionShare = sharem.getCommand();
                    sharer.connection = this.connection;
                    options[argm.VSIX_PATH.name] = results.vsixPath;
                    return sharer.exec(args, options).then((accounts) => {
                        results.shareWith = accounts;
                        return results;
                    });
				}
                return results;
			});
        });
    }

    public output(results: PublishResults): void {
        if (!results) {
            throw new Error('no package supplied');
        }

        trace.println();
        trace.success("Successfully published VSIX from %s to the gallery.", results.vsixPath);
    }   
}

export class PublisherManager {
    protected galleryapi: gallerym.IQGalleryApi;
    protected cachedExtensionInfo: extinfom.CoreExtInfo;
    private static validationPending = "__validation_pending";
    private static validated = "__validated";
    private static validationInterval = 1000;
    private static validationRetries = 50;
    
    /**
    * Constructor
    * @param PublishSettings
    */
    constructor(galleryapi: gallerym.IQGalleryApi) {
        this.galleryapi = galleryapi;
    }
    
    /**
     * Publish the VSIX extension given by vsixPath
     * @param string path to a VSIX extension to publish
     * @return Q.Promise that is resolved when publish is complete
     */
    public publish(vsixPath: string): Q.Promise<any> {
        trace.debug('publish.publish');
        
        let extPackage: galleryifm.ExtensionPackage = {<commit_msg>better success output for publishing extension<commit_after>/// <reference path="../../definitions/tsd.d.ts" />

import argm = require('../lib/arguments');
import cmdm = require('../lib/tfcommand');
import cm = require('../lib/common');
import createm = require('./extension-create');
import extinfom = require('../lib/extensioninfo');
import fs = require('fs');
import gallerym = require('vso-node-api/GalleryApi');
import galleryifm = require('vso-node-api/interfaces/GalleryInterfaces');
import os = require('os');
import Q = require('q');
import sharem = require('./extension-share');
var trace = require('../lib/trace');

export function describe(): string {
    return 'Publish a VSIX package to your account. Generates the VSIX using [package_settings_path] unless --vsix is specified.';
}

export function getCommand(): cmdm.TfCommand {
    // this just offers description for help and to offer sub commands
    return new ExtensionPublish;
}

// requires auth, connect etc...
export var isServerOperation: boolean = true;

// unless you have a good reason, should not hide
export var hideBanner: boolean = false;

export interface PublishResults {
    vsixPath: string,
    shareWith: string[]
}

export class ExtensionPublish extends cmdm.TfCommand {
    optionalArguments = [argm.VSIX_PATH, argm.SHARE_WITH];
    
    public exec(args: string[], options: cm.IOptions): Q.Promise<PublishResults> {
        trace.debug('extension-publish.exec');
        var galleryapi: gallerym.IQGalleryApi = this.getWebApi().getQGalleryApi(this.connection.galleryUrl);
        return this.checkArguments(args, options).then( (allArguments: cm.IStringIndexer) => {        
			return Q.Promise<string>((resolve, reject, notify) => {
                if (allArguments[argm.VSIX_PATH.name]) {
                    trace.debug("VSIX was manually specified. Skipping generation.");
                    resolve(allArguments[argm.VSIX_PATH.name]);
                } else {
                    trace.info("VSIX not specified. Creating new package.");
                    resolve(createm.getCommand().exec(args, options));
                }
            }).then((vsixPath: string) => {
                trace.debug("Begin publish to Gallery");
                return new PublisherManager(galleryapi).publish(vsixPath).then(() => {
                    trace.debug("Success");
                    return <PublishResults> {
                        vsixPath: vsixPath
                    };
                });            
            }).then((results: PublishResults) => {
                trace.debug("Begin sharing");
				if (allArguments[argm.SHARE_WITH.name]) {
                    var sharer: sharem.ExtensionShare = sharem.getCommand();
                    sharer.connection = this.connection;
                    options[argm.VSIX_PATH.name] = results.vsixPath;
                    return sharer.exec(args, options).then((accounts) => {
                        results.shareWith = accounts;
                        return results;
                    });
				}
                return results;
			});
        });
    }

    public output(results: PublishResults): void {
        if (!results) {
            throw new Error('no package supplied');
        }

        trace.println();
        trace.success("Successfully published VSIX from %s to the gallery.", results.vsixPath);
        if (results.shareWith) {
            trace.success('Extension shared successfully with:%s', results.shareWith.map((account) => " " + account));
        }
    }   
}

export class PublisherManager {
    protected galleryapi: gallerym.IQGalleryApi;
    protected cachedExtensionInfo: extinfom.CoreExtInfo;
    private static validationPending = "__validation_pending";
    private static validated = "__validated";
    private static validationInterval = 1000;
    private static validationRetries = 50;
    
    /**
    * Constructor
    * @param PublishSettings
    */
    constructor(galleryapi: gallerym.IQGalleryApi) {
        this.galleryapi = galleryapi;
    }
    
    /**
     * Publish the VSIX extension given by vsixPath
     * @param string path to a VSIX extension to publish
     * @return Q.Promise that is resolved when publish is complete
     */
    public publish(vsixPath: string): Q.Promise<any> {
        trace.debug('publish.publish');
        
        let extPackage: galleryifm.ExtensionPackage = {
{'fraction_non_alphanumeric': 0.1165444172779136, 'fraction_numerical': 0.0013971358714634998, 'mean_word_length': 2.4087301587301586, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 26, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7293565', 'n_tokens_mistral': 2334, 'n_tokens_neox': 2248, 'n_words': 567}