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

Commit

Permalink
added 'timeToWaitBeforeActivateDeployOnChange' setting
Browse files Browse the repository at this point in the history
  • Loading branch information
mkloubert committed Aug 11, 2017
1 parent 930a3d2 commit 4409f8d
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Change Log (vs-deploy)

## 9.29.0 (August 11th, 2017; deactivate deploy on change at startup)

* added `timeToWaitBeforeActivateDeployOnChange` setting, which can freeze 'deploy on change' feature for a specific number of milliseconds, after config has been (re)loaded

## 9.28.1 (July 21st, 2017; brazilian portuguese translation)

* added portuguese (brazilian) translation (thanks to [Celio Rodrigues](https://github.com/ItsMeCelio)!)
Expand Down
Binary file modified img/screenshot1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "vs-deploy",
"displayName": "Deploy",
"description": "Commands for deploying files of your workspace to a destination.",
"version": "9.28.1",
"version": "9.29.0",
"publisher": "mkloubert",
"engines": {
"vscode": "^1.6.0"
Expand Down Expand Up @@ -31473,6 +31473,10 @@
}
}
},
"timeToWaitBeforeActivateDeployOnChange": {
"type": "integer",
"description": "The time (in milliseconds) to wait before activating 'deploy on change' feature."
},
"useGitIgnoreStylePatterns": {
"type": "boolean",
"description": "Also check directory patterns, like in '.gitignore' files, in all packages by default or not.",
Expand Down
4 changes: 4 additions & 0 deletions src/contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -760,6 +760,10 @@ export interface DeployConfiguration extends vscode.WorkspaceConfiguration {
*/
sources?: string | string[] | TemplateSource | TemplateSource[];
};
/**
* The time (in milliseconds) to wait before activating 'deploy on change' feature.
*/
timeToWaitBeforeActivateDeployOnChange?: number;
/**
* Also check directory patterns, like in '.gitignore' files, in all packages by default or not.
*/
Expand Down
32 changes: 32 additions & 0 deletions src/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ export class Deployer extends Events.EventEmitter implements vscode.Disposable {
* Stores the underlying extension context.
*/
protected readonly _CONTEXT: vscode.ExtensionContext;
/**
* The timeout for freezing 'deploy on change' feature.
*/
protected _deployOnChangeFreezer: NodeJS.Timer;
/**
* Stores the current list of global events.
*/
Expand All @@ -138,6 +142,10 @@ export class Deployer extends Events.EventEmitter implements vscode.Disposable {
* Stores if 'deploy on change' feature is enabled or not.
*/
protected _isDeployOnChangeEnabled = true;
/**
* Stores if 'deploy on change' feature is freezed or not.
*/
protected _isDeployOnChangeFreezed = false;
/**
* Stores if 'deploy on save' feature is enabled or not.
*/
Expand Down Expand Up @@ -2559,6 +2567,11 @@ export class Deployer extends Events.EventEmitter implements vscode.Disposable {
protected onFileChange(e: vscode.Uri, type: string) {
let me = this;

if (deploy_helpers.toBooleanSafe(me._isDeployOnChangeFreezed)) {
// freezed
return;
}

if (!(deploy_helpers.toBooleanSafe(me.config.deployOnChange, true) &&
me._isDeployOnChangeEnabled)) {
// deactivated
Expand Down Expand Up @@ -4002,6 +4015,22 @@ export class Deployer extends Events.EventEmitter implements vscode.Disposable {
let next = (cfg: deploy_contracts.DeployConfiguration) => {
me._config = cfg;

try {
let timeToWaitBeforeActivateDeployOnChange = parseInt( deploy_helpers.toStringSafe(cfg.timeToWaitBeforeActivateDeployOnChange).trim() );
if (!isNaN(timeToWaitBeforeActivateDeployOnChange)) {
// deactivate 'deploy on change'
// for a while

me._isDeployOnChangeFreezed = true;
me._deployOnChangeFreezer = setTimeout(() => {
me._isDeployOnChangeFreezed = false;
}, timeToWaitBeforeActivateDeployOnChange);
}
}
catch (e) {
me._isDeployOnChangeFreezed = false;
}

deploy_values.reloadAdditionalValues
.apply(me, []);

Expand All @@ -4021,6 +4050,8 @@ export class Deployer extends Events.EventEmitter implements vscode.Disposable {
};

let applyCfg = (cfg: deploy_contracts.DeployConfiguration) => {
deploy_helpers.tryClearTimeout(me._deployOnChangeFreezer);

me._lastConfigUpdate = Moment();

me._allTargets = deploy_helpers.asArray(cfg.targets)
Expand All @@ -4033,6 +4064,7 @@ export class Deployer extends Events.EventEmitter implements vscode.Disposable {
});
me._globalScriptOperationState = {};
me._htmlDocs = [];
me._isDeployOnChangeFreezed = false;
me._scriptOperationStates = {};
me._targetCache = new deploy_objects.DeployTargetCache();

Expand Down
23 changes: 23 additions & 0 deletions src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2586,6 +2586,29 @@ export function toValidatorSafe<T>(validator: deploy_contracts.Validator<T>): de
return validator;
}

/**
* Tries to clear a timeout.
*
* @param {NodeJS.Timer} timeoutId The timeout (ID).
*
* @return {boolean} Operation was successful or not.
*/
export function tryClearTimeout(timeoutId: NodeJS.Timer): boolean {
try {
if (!isNullOrUndefined(timeoutId)) {
clearTimeout(timeoutId);
}

return true;
}
catch (e) {
log(i18.t('errors.withCategory',
'helpers.tryClearTimeout()', e));

return false;
}
}

/**
* Tries to dispose an object.
*
Expand Down

0 comments on commit 4409f8d

Please sign in to comment.