From 8030fa7fb818982ad4b8a19e65bdc885f074039f Mon Sep 17 00:00:00 2001 From: Marcel Kloubert Date: Fri, 29 Dec 2017 23:56:44 +0100 Subject: [PATCH] added initComposer setting --- CHANGELOG.md | 5 ++-- package.json | 7 +++++- src/contracts.ts | 6 ++++- src/i18.ts | 8 +++++++ src/lang/de.ts | 8 +++++++ src/lang/en.ts | 8 +++++++ src/workspaces.ts | 59 +++++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 97 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7efad88..207a0a7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,9 +1,10 @@ # Change Log (vscode-deploy-reloaded) -## 0.9.0 (December 30th, 2017; scripts) +## 0.9.0 (December 30th, 2017; [composer](https://getcomposer.org/)) * bugfixes * code improvements +* added `initComposer` [setting](https://github.com/mkloubert/vscode-deploy-reloaded/wiki#settings--), which runs `composer install` inside the workspace folder on startup, if a `composer.json` file exists and NO `vendor` sub folder has been found * added `extension`, `folder` and `sessionState` properties to [ScriptArguments](https://mkloubert.github.io/vscode-deploy-reloaded/interfaces/_contracts_.scriptarguments.html) ## 0.8.0 (December 29th, 2017; target operations) @@ -14,7 +15,7 @@ * improved use of `if` properties and [placeholders](https://github.com/mkloubert/vscode-deploy-reloaded/wiki/values) * fixed loading settings from parent folder -## 0.7.0 (December 29th, 2017; npm) +## 0.7.0 (December 29th, 2017; [npm](https://www.npmjs.com/package/npm)) * bugfixes * code improvements diff --git a/package.json b/package.json index 4afbe43..87505b4 100644 --- a/package.json +++ b/package.json @@ -298,8 +298,13 @@ } ] }, + "initComposer": { + "description": "Runs 'composer install' inside the workspace folder on startup, if a 'composer.json' file exists and NO 'vendor' folder has been found.", + "type": "boolean", + "default": false + }, "initNodeModules": { - "description": "Runs 'npm install' inside the workspace folder on startup, if a 'package.json' file exists and NO 'node_modules' has been found.", + "description": "Runs 'npm install' inside the workspace folder on startup, if a 'package.json' file exists and NO 'node_modules' folder has been found.", "type": "boolean", "default": false }, diff --git a/src/contracts.ts b/src/contracts.ts index a0ceda0..4772d80 100644 --- a/src/contracts.ts +++ b/src/contracts.ts @@ -162,7 +162,11 @@ export interface Configuration extends deploy_values.WithValueItems { */ readonly imports?: ImportType | ImportType[]; /** - * Runs 'npm install' inside the workspace folder on startup, if a 'package.json' file exists and NO 'node_modules' has been found. + * Runs 'composer install' inside the workspace folder on startup, if a 'composer.json' file exists and NO 'vendor' folder has been found. + */ + readonly initComposer?: boolean; + /** + * Runs 'npm install' inside the workspace folder on startup, if a 'package.json' file exists and NO 'node_modules' folder has been found. */ readonly initNodeModules?: boolean; /** diff --git a/src/i18.ts b/src/i18.ts index 5ab4237..3b75e16 100644 --- a/src/i18.ts +++ b/src/i18.ts @@ -474,6 +474,14 @@ export interface Translation { noneFound?: string; selectWorkspace?: string; }; + composer?: { + install?: { + errors?: { + failed?: string; + }; + running?: string; + } + }; errors?: { cannotDetectMappedPathInfoForFile?: string; cannotDetectPathInfoForFile?: string; diff --git a/src/lang/de.ts b/src/lang/de.ts index f956cdc..683ff1c 100644 --- a/src/lang/de.ts +++ b/src/lang/de.ts @@ -468,6 +468,14 @@ export const translation: Translation = { noneFound: "Keine aktiven Arbeitsbereiche gefunden!", selectWorkspace: "Wählen Sie den aktiven Arbeitsbereich aus ...", }, + composer: { + install: { + errors: { + failed: "'composer install' konnte nicht ausgeführt werden:{0:trim,surround,leading_space}", + }, + running: "Führe 'composer install' in{0:trim,surround,leading_space} aus ...", + } + }, errors: { cannotDetectMappedPathInfoForFile: "Gemappte Pfad-Informationen konnten für die Datei{0:trim,surround,leading_space} nicht ermittelt werden!", cannotDetectPathInfoForFile: "Pfad-Informationen konnten für die Datei{0:trim,surround,leading_space} nicht ermittelt werden!", diff --git a/src/lang/en.ts b/src/lang/en.ts index 50ea0b3..35660d2 100644 --- a/src/lang/en.ts +++ b/src/lang/en.ts @@ -469,6 +469,14 @@ export const translation: Translation = { noneFound: "No active workspaces found!", selectWorkspace: "Select the active workspace ...", }, + composer: { + install: { + errors: { + failed: "'composer install' failed:{0:trim,surround,leading_space}", + }, + running: "Running 'composer install' in{0:trim,surround,leading_space} ...", + } + }, errors: { cannotDetectMappedPathInfoForFile: "Cannot detect mapped path information for file{0:trim,surround,leading_space}!", cannotDetectPathInfoForFile: "Cannot detect path information for file{0:trim,surround,leading_space}!", diff --git a/src/workspaces.ts b/src/workspaces.ts index 2d3f9a9..aa13da0 100644 --- a/src/workspaces.ts +++ b/src/workspaces.ts @@ -1375,6 +1375,64 @@ export class Workspace extends deploy_objects.DisposableBase implements deploy_c return deploy_helpers.cloneObject(this.config.globals); } + private async initComposer(cfg: WorkspaceSettings) { + if (!cfg) { + return; + } + + if (!deploy_helpers.toBooleanSafe(cfg.initComposer)) { + return; + } + + const ME = this; + + try { + const COMPOSER_JSON = Path.resolve( + Path.join( + ME.rootPath, 'composer.json', + ) + ); + + const VENDOR = Path.resolve( + Path.join( + ME.rootPath, 'vendor', + ) + ); + + if (!(await deploy_helpers.exists(COMPOSER_JSON))) { + return; // no 'composer.json' + } + + if (await deploy_helpers.exists(VENDOR)) { + return; // 'vendor' already exist + } + + ME.context.outputChannel.appendLine(''); + ME.context.outputChannel.append( + ME.t('workspaces.composer.install.running', + ME.rootPath) + ' ' + ); + try { + await ME.exec('composer install'); + + ME.context.outputChannel.appendLine( + `[${ME.t('ok')}]` + ); + } + catch (e) { + ME.context.outputChannel.appendLine( + `[${ME.t('error', e)}]` + ); + } + } + catch (e) { + ME.showErrorMessage( + ME.t('workspaces.composer.install.errors.failed', + e) + ); + } + } + /** * Initializes that workspace. * @@ -2173,6 +2231,7 @@ export class Workspace extends deploy_objects.DisposableBase implements deploy_c finalizer = async () => { await ME.initNodeModules(loadedCfg); + await ME.initComposer(loadedCfg); // runBuildTaskOnStartup try {