Skip to content
This repository has been archived by the owner on Jul 1, 2021. It is now read-only.

Commit

Permalink
better handling of extension's package file
Browse files Browse the repository at this point in the history
  • Loading branch information
mkloubert committed Dec 13, 2016
1 parent 1d40e3f commit 984edef
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 14 deletions.
22 changes: 22 additions & 0 deletions src/contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,10 @@ export interface DeployContext {
* Gets the global output channel.
*/
outputChannel(): vscode.OutputChannel;
/**
* Returns the package file of that extension.
*/
packageFile(): PackageFile;
/**
* Returns the list of packages.
*
Expand Down Expand Up @@ -459,6 +463,24 @@ export interface DeployWorkspaceOptions {
onFileCompleted?: FileDeployedCompletedEventHandler;
}

/**
* Describes the structure of the package file of that extenstion.
*/
export interface PackageFile {
/**
* The display name.
*/
displayName: string;
/**
* The (internal) name.
*/
name: string;
/**
* The version string.
*/
version: string;
}

/**
* Event handler for a completed "deploy workspace" operation.
*
Expand Down
19 changes: 17 additions & 2 deletions src/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ export class Deployer {
* Stores the underlying extension context.
*/
protected _CONTEXT: vscode.ExtensionContext;
/**
* Stores the package file of that extension.
*/
protected _PACKAGE_FILE: deploy_contracts.PackageFile;
/**
* Loaded plugins.
*/
Expand All @@ -75,11 +79,14 @@ export class Deployer {
*
* @param {vscode.ExtensionContext} context The underlying extension context.
* @param {vscode.OutputChannel} outputChannel The global output channel to use.
* @param {deploy_contracts.PackageFile} pkgFile The package file of that extension.
*/
constructor(context: vscode.ExtensionContext,
outputChannel: vscode.OutputChannel) {
outputChannel: vscode.OutputChannel,
pkgFile: deploy_contracts.PackageFile) {
this._CONTEXT = context;
this._OUTPUT_CHANNEL = outputChannel;
this._PACKAGE_FILE = pkgFile;

this.reloadConfiguration();
this.reloadPlugins();
Expand Down Expand Up @@ -1074,6 +1081,13 @@ export class Deployer {
return this._OUTPUT_CHANNEL;
}

/**
* Gets the package file of that extension.
*/
public get packageFile(): deploy_contracts.PackageFile {
return this._PACKAGE_FILE;
}

/**
* Gets the list of plugins.
*/
Expand Down Expand Up @@ -1171,6 +1185,7 @@ export class Deployer {
return this;
},
outputChannel: () => me.outputChannel,
packageFile: () => me.packageFile,
packages: () => me.getPackages(),
plugins: null,
targets: () => me.getTargets(),
Expand Down Expand Up @@ -1224,7 +1239,7 @@ export class Deployer {
if (loadedPlugins.length > 0) {
loadedPlugins.forEach(x => {
try {
me.outputChannel.append(`- '${x.__file}'`);
me.outputChannel.append(`- ${x.__file}`);
}
catch (e) {
me.log(`[ERROR] Deployer.reloadPlugins(3): ${deploy_helpers.toStringSafe(e)}`);
Expand Down
24 changes: 12 additions & 12 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,30 +30,30 @@ import * as FS from 'fs';
import * as Moment from 'moment';
import * as Path from 'path';
import * as vscode from 'vscode';
import * as vs_contracts from './contracts';
import * as vs_deploy from './deploy';


export function activate(context: vscode.ExtensionContext) {
let now = Moment();

// version
let appVersion: string;
let appName: string;
let displayName: string;
let pkgFile: vs_contracts.PackageFile;
try {
let packageFile = JSON.parse(FS.readFileSync(Path.join(__dirname, '../../package.json'), 'utf8'));

appName = packageFile.name;
appVersion = packageFile.version;
displayName = packageFile.displayName;
pkgFile = JSON.parse(FS.readFileSync(Path.join(__dirname, '../../package.json'), 'utf8'));
}
catch (e) {
deploy_helpers.log(`[ERROR] ${deploy_helpers.toStringSafe(e)}`);
deploy_helpers.log(`[ERROR] extension.activate(): ${deploy_helpers.toStringSafe(e)}`);
}

let outputChannel = vscode.window.createOutputChannel("Deploy");
if (appName) {
outputChannel.appendLine(`${displayName} (${appName}) - v${appVersion}`);

// show infos about the app
{
if (pkgFile) {
outputChannel.appendLine(`${pkgFile.displayName} (${pkgFile.name}) - v${pkgFile.version}`);
}

outputChannel.appendLine(`Copyright (c) ${now.format('YYYY')} Marcel Joachim Kloubert <[email protected]>`);
outputChannel.appendLine('');
outputChannel.appendLine(`GitHub : https://github.com/mkloubert/vs-deploy`);
Expand All @@ -65,7 +65,7 @@ export function activate(context: vscode.ExtensionContext) {
outputChannel.show();
}

let deployer = new vs_deploy.Deployer(context, outputChannel);
let deployer = new vs_deploy.Deployer(context, outputChannel, pkgFile);

// deploy workspace
let deploy = vscode.commands.registerCommand('extension.deploy', () => {
Expand Down

0 comments on commit 984edef

Please sign in to comment.