From 88fa327ca0c942672a83d221f9da4d870da1b634 Mon Sep 17 00:00:00 2001 From: Marcel Kloubert Date: Mon, 29 May 2017 21:27:21 +0200 Subject: [PATCH] added startBuildTask setting --- CHANGELOG.md | 3 ++- package.json | 14 ++++++++++++ src/config.ts | 55 ++++++++++++++++++++++++++++++++++++++++++++++++ src/contracts.ts | 5 +++++ src/deploy.ts | 3 +++ 5 files changed, 79 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 235de3e..5befc52 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,11 +1,12 @@ # Change Log (vs-deploy) -## 9.11.0 (May 29th, 2017; settings) +## 9.11.0 (May 29th, 2017; settings and placeholders) * added `alwaysShowPackageList` setting that indicates if package list is shown, even if there is only 1 entry * added `alwaysShowTargetList` setting that indicates if target list is shown, even if there is only 1 entry * added `username` and `password` settings for [HTTP target operations](https://github.com/mkloubert/vs-deploy/wiki/targetoperations#http-) * added build-in [placeholders](https://github.com/mkloubert/vs-deploy/wiki/values) `EOL`, `hostName` and `tempDir` +* added `startBuildTask` that can defines if `workbench.action.tasks.build` (build task) should be run on startup or not ## 9.10.0 (May 28th, 2017; new list target) diff --git a/package.json b/package.json index de5abbb..d7db788 100644 --- a/package.json +++ b/package.json @@ -1071,6 +1071,20 @@ "description": "Starts the REST API or not (s. https://github.com/mkloubert/vs-rest-api).", "default": false }, + "startBuildTask": { + "oneOf": [ + { + "type": "boolean", + "description": "Indicates if build task should be run on startup or not.", + "default": "false" + }, + { + "type": "integer", + "description": "Defines the number of milliseconds to wait before the build task is run.", + "minimum": 0 + } + ] + }, "startCronJobs": { "type": "boolean", "description": "Starts the cron jobs or not (s. https://github.com/mkloubert/vs-cron).", diff --git a/src/config.ts b/src/config.ts index 0a15ea3..e7e488a 100644 --- a/src/config.ts +++ b/src/config.ts @@ -35,6 +35,8 @@ import * as vscode from 'vscode'; import * as Workflows from 'node-workflows'; +let buildTaskTime: NodeJS.Timer; + /** * Returns a merged config object. * @@ -232,3 +234,56 @@ export function mergeConfig(cfg: deploy_contracts.DeployConfiguration): Promise< } }); } + +/** + * Runs the build task, if defined in config. + */ +export function runBuildTask() { + let me: vs_deploy.Deployer = this; + let cfg = me.config; + + // close old timer (if defined) + try { + let btt = buildTaskTime; + if (btt) { + clearTimeout(btt); + } + } + catch (e) { + me.log(i18.t('errors.withCategory', + 'config.runBuildTask(1)', e)); + } + finally { + buildTaskTime = null; + } + + let doRun = false; + let timeToWait: number; + if (!deploy_helpers.isNullOrUndefined(cfg.startBuildTask)) { + if ('boolean' === typeof cfg.startBuildTask) { + doRun = cfg.startBuildTask; + } + else { + timeToWait = parseInt(deploy_helpers.toStringSafe(cfg.startBuildTask)); + } + } + + let executeBuildTaskCommand = () => { + vscode.commands.executeCommand('workbench.action.tasks.build').then(() => { + }, (err) => { + me.log(i18.t('errors.withCategory', + 'config.runBuildTask(2)', err)); + }); + }; + + if (doRun) { + if (isNaN(timeToWait)) { + executeBuildTaskCommand(); + } + else { + buildTaskTime = setTimeout(() => { + executeBuildTaskCommand(); + }, timeToWait); + } + } +} diff --git a/src/contracts.ts b/src/contracts.ts index db6e874..390a04e 100644 --- a/src/contracts.ts +++ b/src/contracts.ts @@ -652,6 +652,11 @@ export interface DeployConfiguration extends vscode.WorkspaceConfiguration { * s. https://github.com/mkloubert/vs-rest-api */ startApi?: boolean; + /** + * Run build task on startup or define the wait time, in milliseconds, after + * the build task should be run after startup. + */ + startBuildTask?: boolean | number; /** * Starts the cron jobs or not. * s. https://github.com/mkloubert/vs-cron diff --git a/src/deploy.ts b/src/deploy.ts index 0a7a963..24ca068 100644 --- a/src/deploy.ts +++ b/src/deploy.ts @@ -3964,6 +3964,9 @@ export class Deployer extends Events.EventEmitter implements vscode.Disposable { } } + deploy_config.runBuildTask + .apply(me); + if (showDefaultTemplateRepos) { // check official repo version deploy_templates.checkOfficialRepositoryVersions