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

Commit

Permalink
requiredExtensions and bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mkloubert committed Jan 2, 2018
1 parent 119a2ab commit da734e5
Show file tree
Hide file tree
Showing 10 changed files with 250 additions and 2 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,18 @@

[![Share via Facebook](https://raw.githubusercontent.com/mkloubert/vscode-deploy-reloaded/master/img/share/Facebook.png)](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fmarketplace.visualstudio.com%2Fitems%3FitemName%3Dmkloubert.vscode-deploy-reloaded&quote=vscode-deploy-reloaded) [![Share via Twitter](https://raw.githubusercontent.com/mkloubert/vscode-deploy-reloaded/master/img/share/Twitter.png)](https://twitter.com/intent/tweet?source=https%3A%2F%2Fmarketplace.visualstudio.com%2Fitems%3FitemName%3Dmkloubert.vscode-deploy-reloaded&text=vscode-deploy-reloaded:%20https%3A%2F%2Fmarketplace.visualstudio.com%2Fitems%3FitemName%3Dmkloubert.vscode-deploy-reloaded&via=mjkloubert) [![Share via Google+](https://raw.githubusercontent.com/mkloubert/vscode-deploy-reloaded/master/img/share/Google+.png)](https://plus.google.com/share?url=https%3A%2F%2Fmarketplace.visualstudio.com%2Fitems%3FitemName%3Dmkloubert.vscode-deploy-reloaded) [![Share via Pinterest](https://raw.githubusercontent.com/mkloubert/vscode-deploy-reloaded/master/img/share/Pinterest.png)](https://pinterest.com/pin/create/button/?url=https%3A%2F%2Fmarketplace.visualstudio.com%2Fitems%3FitemName%3Dmkloubert.vscode-deploy-reloaded&media=https://raw.githubusercontent.com/mkloubert/vscode-deploy-reloaded/master/img/demo1.gif&description=Recoded%20version%20of%20Visual%20Studio%20Code%20extension%20%27vs-deploy%27%2C%20which%20provides%20commands%20to%20deploy%20files%20to%20one%20or%20more%20destinations.) [![Share via Reddit](https://raw.githubusercontent.com/mkloubert/vscode-deploy-reloaded/master/img/share/Reddit.png)](https://www.reddit.com/submit?url=https%3A%2F%2Fmarketplace.visualstudio.com%2Fitems%3FitemName%3Dmkloubert.vscode-deploy-reloaded&title=vscode-deploy-reloaded) [![Share via LinkedIn](https://raw.githubusercontent.com/mkloubert/vscode-deploy-reloaded/master/img/share/LinkedIn.png)](https://www.linkedin.com/shareArticle?mini=true&url=https%3A%2F%2Fmarketplace.visualstudio.com%2Fitems%3FitemName%3Dmkloubert.vscode-deploy-reloaded&title=vscode-deploy-reloaded&summary=Recoded%20version%20of%20Visual%20Studio%20Code%20extension%20%27vs-deploy%27%2C%20which%20provides%20commands%20to%20deploy%20files%20to%20one%20or%20more%20destinations.&source=https%3A%2F%2Fmarketplace.visualstudio.com%2Fitems%3FitemName%3Dmkloubert.vscode-deploy-reloaded) [![Share via Wordpress](https://raw.githubusercontent.com/mkloubert/vscode-deploy-reloaded/master/img/share/Wordpress.png)](https://wordpress.com/press-this.php?u=https%3A%2F%2Fmarketplace.visualstudio.com%2Fitems%3FitemName%3Dmkloubert.vscode-deploy-reloaded&quote=vscode-deploy-reloaded&s=Recoded%20version%20of%20Visual%20Studio%20Code%20extension%20%27vs-deploy%27%2C%20which%20provides%20commands%20to%20deploy%20files%20to%20one%20or%20more%20destinations.&i=https://raw.githubusercontent.com/mkloubert/vscode-deploy-reloaded/master/img/demo1.gif) [![Share via Email](https://raw.githubusercontent.com/mkloubert/vscode-deploy-reloaded/master/img/share/Email.png)](mailto:?subject=vscode-deploy-reloaded&body=Recoded%20version%20of%20Visual%20Studio%20Code%20extension%20'vs-deploy'%2C%20which%20provides%20commands%20to%20deploy%20files%20to%20one%20or%20more%20destinations.:%20https%3A%2F%2Fmarketplace.visualstudio.com%2Fitems%3FitemName%3Dmkloubert.vscode-deploy-reloaded)

## 0.13.0 (January 2nd, 2018; setting up requirements)

* added `requiredExtensions` [setting](https://github.com/mkloubert/vscode-deploy-reloaded/wiki/check_for_required_extensions), which checks if required VS Code extensions are installed or not
* bugfixes
* code improvements

## 0.12.0 (January 1st, 2018; quick executions)

* added `$err`, `$info`, `$ip`, `$now`, `$utc` and `$warn` functions for quick code executions

![Demo Quick execution function 20180101](https://raw.githubusercontent.com/mkloubert/vscode-deploy-reloaded/master/img/demo11.gif)

* bugfixes
* code improvements

Expand Down
Binary file added img/demo11.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

52 changes: 51 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "vscode-deploy-reloaded",
"displayName": "Deploy (Reloaded)",
"description": "Deploys files of a workspace to a destination.",
"version": "0.12.0",
"version": "0.13.0",
"publisher": "mkloubert",
"engines": {
"vscode": "^1.19.0"
Expand Down Expand Up @@ -667,6 +667,56 @@
"type": "boolean",
"default": true
},
"requiredExtensions": {
"description": "Defines one or more Visual Studio Code extensions, which are required.",
"type": "object",
"patternProperties": {
"\\S+": {
"description": "The ID of the extension.",
"oneOf": [
{
"description": "Shows a warning message, when the extension has not been found.",
"type": "null"
},
{
"description": "Show an error message (true) and skip loading the configuration, when extension has not been found, or show a warning message instead (false).",
"type": "boolean",
"default": false
},
{
"description": "Settings for a required extension.",
"type": "object",
"properties": {
"if": {
"description": "(JavaScript) Code, which indicates, if entry is available or not.",
"type": "string"
},
"isMustHave": {
"description": "Skip loading the configuration (true), when extension has not been found, or show a warning message instead (false).",
"type": "boolean",
"default": false
},
"platforms": {
"description": "One or more platform names the entry is available for.",
"type": "array",
"items": {
"description": "The name of the platform.",
"type": "string",
"enum": [
"darwin",
"freebsd",
"linux",
"sunos",
"win32"
]
}
}
}
}
]
}
}
},
"runBuildTaskOnStartup": {
"description": "Indicates if build task should be run on startup or not.",
"oneOf": [
Expand Down
15 changes: 15 additions & 0 deletions src/contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,10 @@ export interface Configuration extends deploy_values.WithValueItems {
* One or more package.
*/
readonly packages?: deploy_packages.Package | deploy_packages.Package[];
/**
* Checks for one or more required extensions.
*/
readonly requiredExtensions?: { [ id: string ]: null | boolean | RequiredExtensionSettings };
/**
* Activates or deactivates "remove on change" feature for all packages.
*/
Expand Down Expand Up @@ -373,6 +377,17 @@ export interface PlatformItem {
readonly platforms?: string | string[];
}

/**
* Settings for a required extension.
*/
export interface RequiredExtensionSettings extends ConditionalItem,
PlatformItem {
/**
* Do not continue (true), when extension has not been found, or show a warning message instead (false).
*/
readonly isMustHave?: boolean;
}

/**
* Arguments for a script.
*/
Expand Down
49 changes: 49 additions & 0 deletions src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -767,6 +767,55 @@ export function exists(path: string | Buffer) {
});
}

/**
* Filters items with 'if' code.
*
* @param {TItem | TItem[]} items The items to filter.
* @param {boolean} [throwOnError] Throw on error or not.
* @param {any} [errorResult] The custom result when an error occurred.
*
* @return {TItem[]} The filtered items.
*/
export function filterConditionalItems<TItem extends deploy_contracts.ConditionalItem = deploy_contracts.ConditionalItem>(
items: TItem | TItem[],
throwOnError = false,
errorResult: any = false,
) {
items = asArray(items);
throwOnError = toBooleanSafe(throwOnError);

return items.filter(i => {
return Enumerable.from( asArray(i.if) ).all(c => {
let res: any;

try {
const IF_CODE = toStringSafe(c);
if (!isEmptyString(IF_CODE)) {
res = deploy_code.exec({
code: IF_CODE,
context: {
i: i,
},
values: [],
});
}
}
catch (e) {
deploy_log.CONSOLE
.trace(e, 'helpers.filterConditionalItems()');

if (throwOnError) {
throw e;
}

return errorResult;
}

return toBooleanSafe(res, true);
});
});
}

/**
* Filters platform specific objects.
*
Expand Down
8 changes: 8 additions & 0 deletions src/i18.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export interface Translation {
};
notSupported?: string;
};
'continue'?: string;
DELETE?: {
askForCancelOperation?: string;
askIfDeleteLocalFile?: string;
Expand Down Expand Up @@ -299,6 +300,13 @@ export interface Translation {
selectSource?: string;
startOperation?: string;
};
requirements?: {
extensions?: {
mustBeInstalled?: string;
openInMarketplace?: string;
shouldBeInstalled?: string;
};
};
s3bucket?: {
credentialTypeNotSupported?: string;
};
Expand Down
8 changes: 8 additions & 0 deletions src/lang/de.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export const translation: Translation = {
},
notSupported: "Compiler{0:trim,surround,leading_space} wird nicht unterstützt!",
},
'continue': "Fortfahren",
DELETE: {
askForCancelOperation: "Sind Sie sicher, dass Sie das Löschen der Datei(en) in{0:trim,surround,leading_space} abbrechen wollen?",
askIfDeleteLocalFile: "Auch die lokale Datei löschen?",
Expand Down Expand Up @@ -293,6 +294,13 @@ export const translation: Translation = {
selectSource: "Wählen Sie die Quelle von der Sie die Datei(en) laden wollen ...",
startOperation: "Beginne Ladevorgang von{0:trim,surround,leading_space} ...",
},
requirements: {
extensions: {
mustBeInstalled: "Die Erweiterung{0:trim,surround,leading_space} ist nicht installiert und wird vorausgesetzt!",
openInMarketplace: "Abbrechen und Visual Studio Marketplace öffnen ...",
shouldBeInstalled: "Es wird empfohlen die Erweiterung{0:trim,surround,leading_space} zu installieren!",
},
},
s3bucket: {
credentialTypeNotSupported: "Das Anmeldeverfahren{0:trim,surround,leading_space} wird nicht unterstützt!",
},
Expand Down
8 changes: 8 additions & 0 deletions src/lang/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export const translation: Translation = {
},
notSupported: "Compiler{0:trim,surround,leading_space} is not supported!",
},
'continue': "Continue",
DELETE: {
askForCancelOperation: "You are about to cancel the delete operation in{0:trim,surround,leading_space}. Are you sure?",
askIfDeleteLocalFile: "Also delete local file?",
Expand Down Expand Up @@ -294,6 +295,13 @@ export const translation: Translation = {
selectSource: "Select the source from where to pull from ...",
startOperation: "Start pulling files from{0:trim,surround,leading_space} ...",
},
requirements: {
extensions: {
mustBeInstalled: "The extension{0:trim,surround,leading_space} is required, but not installed!",
openInMarketplace: "Cancel and open Visual Studio Marketplace ...",
shouldBeInstalled: "It is recommended to install the extension{0:trim,surround,leading_space}!",
},
},
s3bucket: {
credentialTypeNotSupported: "Credental type{0:trim,surround,leading_space} is not supported!",
},
Expand Down
102 changes: 102 additions & 0 deletions src/workspaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,100 @@ export class Workspace extends deploy_objects.DisposableBase implements deploy_c
await ME.updateSwitchButtons();
}

private async checkForRequiredExtensions(loadedCfg: WorkspaceSettings) {
if (!loadedCfg) {
return true;
}

const REQUIRED_EXTENSIONS = loadedCfg.requiredExtensions;
if (!deploy_helpers.isObject(REQUIRED_EXTENSIONS)) {
return true;
}

const ALL_EXTENSIONS = vscode.extensions.all.map(e => {
return deploy_helpers.normalizeString(e);
});
for (const EXT in REQUIRED_EXTENSIONS) {
const EXTENSION_ID = deploy_helpers.toStringSafe(EXT).trim();
if ('' === EXTENSION_ID) {
continue;
}

const OPEN_IN_MARKETPLACE = () => {
deploy_helpers.open(`https://marketplace.visualstudio.com/items?itemName=${encodeURIComponent(EXTENSION_ID)}`).then(() => {
}, (err) => {
deploy_log.CONSOLE
.trace(err, 'workspaces.Workspace.checkForRequiredExtensions().OPEN_IN_MARKETPLACE()');
});
};

let settings = REQUIRED_EXTENSIONS[EXT];
if (!deploy_helpers.isObject<deploy_contracts.RequiredExtensionSettings>(settings)) {
settings = {
isMustHave: deploy_helpers.toBooleanSafe(settings),
};
}

if (deploy_helpers.filterPlatformItems(settings).length < 1) {
continue; // not for platform
}
if (deploy_helpers.filterConditionalItems(settings).length < 1) {
continue; // condition failed
}

if (ALL_EXTENSIONS.indexOf(EXTENSION_ID.toLowerCase()) > -1) {
// found
continue;
}

if (deploy_helpers.toBooleanSafe(settings.isMustHave)) {
// must be installed

const SELECTED_ITEM = await this.showErrorMessage<deploy_contracts.MessageItemWithValue>(
i18.t('requirements.extensions.mustBeInstalled',
EXTENSION_ID),
{
isCloseAffordance: true,
title: i18.t('requirements.extensions.openInMarketplace'),
value: 0,
},
);

if (SELECTED_ITEM) {
if (0 === SELECTED_ITEM.value) {
OPEN_IN_MARKETPLACE();
}
}

return false;
}

const SELECTED_ITEM = await this.showWarningMessage<deploy_contracts.MessageItemWithValue>(
i18.t('requirements.extensions.shouldBeInstalled',
EXTENSION_ID),
{
isCloseAffordance: true,
title: i18.t('requirements.extensions.openInMarketplace'),
value: 0,
},
{
title: i18.t('continue'),
value: 1,
}
);

if (SELECTED_ITEM) {
if (0 === SELECTED_ITEM.value) {
OPEN_IN_MARKETPLACE();

return false;
}
}
}

return true;
}

private cleanupPackageButtons() {
while (this._PACKAGE_BUTTONS.length > 0) {
const PBTN = this._PACKAGE_BUTTONS.shift();
Expand Down Expand Up @@ -2301,6 +2395,11 @@ export class Workspace extends deploy_objects.DisposableBase implements deploy_c
delete (<any>loadedCfg).imports;
}

// check for requirements
if (!(await ME.checkForRequiredExtensions(loadedCfg))) {
return; // failed
}

await deploy_helpers.applyFuncFor(deploy_commands.reloadCommands, ME)(loadedCfg);

await ME.reloadTargets(loadedCfg);
Expand Down Expand Up @@ -2489,6 +2588,9 @@ export class Workspace extends deploy_objects.DisposableBase implements deploy_c
*/
public reloadEnvVars() {
const CFG = this.config;
if (!CFG) {
return;
}

try {
// restore old values
Expand Down

0 comments on commit da734e5

Please sign in to comment.