diff --git a/CHANGELOG.md b/CHANGELOG.md index 97a840a..c3f56b2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ * code improvements * added [exec](https://github.com/mkloubert/vscode-deploy-reloaded/wiki/target_operations#exec-) target operation * 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) diff --git a/src/commands.ts b/src/commands.ts index 7aef8ff..f6798f2 100644 --- a/src/commands.ts +++ b/src/commands.ts @@ -309,14 +309,6 @@ export async function reloadCommands(newCfg: deploy_contracts.Configuration) { }, 'options' ), - new deploy_values.FunctionValue( - () => ME.name, - 'workspace' - ), - new deploy_values.FunctionValue( - () => ME.rootPath, - 'workspace_folder' - ) ]; btn.text = ME.replaceWithValues( diff --git a/src/delete.ts b/src/delete.ts index 9d3652a..090b8c1 100644 --- a/src/delete.ts +++ b/src/delete.ts @@ -449,7 +449,6 @@ export async function deletePackage(pkg: deploy_packages.Package, if (exclude.length < 1) { exclude = undefined; } - const ROOT_DIR = ME.folder.uri.fsPath; const FILES_TO_DELETE = await ME.findFilesByFilter(pkg); if (FILES_TO_DELETE.length < 1) { diff --git a/src/extension.ts b/src/extension.ts index 0aa9902..1f535a4 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -136,7 +136,7 @@ async function invokeForActiveEditor(placeHolder: string, } }, description: deploy_helpers.toStringSafe( t.description ).trim(), - detail: t.__workspace.folder.uri.fsPath, + detail: t.__workspace.rootPath, label: deploy_targets.getTargetName(t), }; }); @@ -1046,44 +1046,13 @@ async function activateExtension(context: vscode.ExtensionContext) { // select workspace vscode.commands.registerCommand('extension.deploy.reloaded.selectWorkspace', async () => { try { - const QUICK_PICKS: deploy_contracts.ActionQuickPick[] = WORKSPACES.map(ws => { - return { - label: ws.name, - description: Path.dirname( - ws.folder.uri.fsPath - ), - - action: async () => { - activeWorkspaces = [ ws ]; - } - }; - }); - - if (QUICK_PICKS.length < 1) { - deploy_helpers.showWarningMessage( - i18.t('workspaces.noneFound') - ); - - return; - } - - let selectedItem: deploy_contracts.ActionQuickPick; - if (1 === QUICK_PICKS.length) { - selectedItem = QUICK_PICKS[0]; - } - else { - selectedItem = await vscode.window.showQuickPick( - QUICK_PICKS, - { - placeHolder: i18.t('workspaces.active.selectWorkspace'), - } - ); - } + const SELECTED_WORKSPACE = await deploy_workspaces.showWorkspaceQuickPick( + context, + WORKSPACES + ); - if (selectedItem) { - await Promise.resolve( - selectedItem.action() - ); + if (SELECTED_WORKSPACE) { + activeWorkspaces = [ SELECTED_WORKSPACE ]; } } catch (e) { diff --git a/src/targets/operations/open.ts b/src/targets/operations/open.ts index 8e9e67e..412eee8 100644 --- a/src/targets/operations/open.ts +++ b/src/targets/operations/open.ts @@ -46,7 +46,7 @@ export async function execute(context: deploy_targets.TargetOperationExecutionCo const WAIT = deploy_helpers.toBooleanSafe(context.operation.wait, true); await deploy_helpers.open(TARGET_TO_OPEN, { - cwd: WORKSPACE.folder.uri.fsPath, + cwd: WORKSPACE.rootPath, wait: WAIT, }); } diff --git a/src/workspaces.ts b/src/workspaces.ts index cf34307..e027828 100644 --- a/src/workspaces.ts +++ b/src/workspaces.ts @@ -215,7 +215,7 @@ export type WorkspaceProvider = () => Workspace | Workspace[]; /** * Workspace settings. */ -export interface WorkspaceSettings extends deploy_contracts.Configuration, vscode.WorkspaceConfiguration { +export interface WorkspaceSettings extends deploy_contracts.Configuration { } @@ -262,7 +262,7 @@ export class Workspace extends deploy_objects.DisposableBase implements deploy_c private _OLD_ENV_VARS: deploy_contracts.KeyValuePairs = {}; private _PACKAGE_BUTTONS: PackageWithButton[] = []; private _packages: deploy_packages.Package[]; - private _rootPath: string; + private _rootPath: string | false; private _sessionState: deploy_contracts.KeyValuePairs; private _selectedSwitches: deploy_contracts.KeyValuePairs; /** @@ -288,10 +288,6 @@ export class Workspace extends deploy_objects.DisposableBase implements deploy_c public readonly context: WorkspaceContext) { super(); - this._rootPath = Path.resolve( - this.folder.uri.fsPath - ); - this.state = new WorkspaceMemento(this); } @@ -599,6 +595,15 @@ export class Workspace extends deploy_objects.DisposableBase implements deploy_c .apply(this, arguments); } + /** + * Gets the root path of the editor. + */ + public get editorRootPath() { + return Path.resolve( + this.folder.uri.fsPath, + ); + } + /** * Executes something for that workspace. * @@ -735,9 +740,9 @@ export class Workspace extends deploy_objects.DisposableBase implements deploy_c } const DEFAULT_OPTS: Glob.IOptions = { - cwd: this.folder.uri.fsPath, + cwd: this.rootPath, ignore: exclude, - root: this.folder.uri.fsPath, + root: this.rootPath, }; return await deploy_helpers.glob(patterns, @@ -1293,6 +1298,11 @@ export class Workspace extends deploy_objects.DisposableBase implements deploy_c deploy_values.getPredefinedValues() ); + // ${editorRoot} + values.push(new deploy_values.FunctionValue(() => { + return ME.editorRootPath; + }, 'editorRoot')); + // ${workspace} values.push(new deploy_values.FunctionValue(() => { return ME.name; @@ -1376,6 +1386,8 @@ export class Workspace extends deploy_objects.DisposableBase implements deploy_c return false; } + ME._rootPath = false; + // settings file { interface SettingsData { @@ -1451,6 +1463,14 @@ export class Workspace extends deploy_objects.DisposableBase implements deploy_c section: DEFAULT_SECTION_NAME, }; } + else { + this._rootPath = Path.resolve( + Path.join( + Path.dirname(settingsData.file), + '..' + ) + ); + } ME._configSource = { section: settingsData.section, @@ -1462,8 +1482,6 @@ export class Workspace extends deploy_objects.DisposableBase implements deploy_c { ME._gitFolder = false; - const DEFAULT_DIR = this.folder.uri.fsPath; - let searchForNextFolder: (dir: string) => Promise; searchForNextFolder = async (dir) => { try { @@ -1494,7 +1512,9 @@ export class Workspace extends deploy_objects.DisposableBase implements deploy_c return false; }; - ME._gitFolder = await searchForNextFolder(DEFAULT_DIR); + ME._gitFolder = await searchForNextFolder( + ME.folder.uri.fsPath + ); } await ME.reloadConfiguration(); @@ -1875,7 +1895,7 @@ export class Workspace extends deploy_objects.DisposableBase implements deploy_c * Gets the name of that workspace. */ public get name(): string { - return Path.basename(this.folder.uri.fsPath); + return Path.basename(this.rootPath); } /** @@ -2028,6 +2048,24 @@ export class Workspace extends deploy_objects.DisposableBase implements deploy_c ME.configSource.resource) || {}; loadedCfg = deploy_helpers.cloneObjectFlat(loadedCfg); + if (ME.editorRootPath !== ME.rootPath) { + if (await deploy_helpers.exists(ME.configSource.resource.fsPath)) { + const CONFIG_TO_MERGE: WorkspaceSettings = + JSON.parse( + (await deploy_helpers.readFile( + ME.configSource.resource.fsPath, + )).toString('utf8') + ); + + if (CONFIG_TO_MERGE) { + loadedCfg = MergeDeep( + loadedCfg, + CONFIG_TO_MERGE[ME.configSource.section], + ); + } + } + } + // runGitPullOnStartup await deploy_tasks.runGitPullOnStartup .apply(ME, [ loadedCfg ]); @@ -2660,7 +2698,18 @@ export class Workspace extends deploy_objects.DisposableBase implements deploy_c * Gets the root path of that workspace. */ public get rootPath(): string { - return this._rootPath; + let rp = this._rootPath; + if (false === rp) { + rp = this.folder.uri.fsPath; + } + + if (!Path.isAbsolute(rp)) { + rp = Path.join( + this.folder.uri.fsPath, rp + ); + } + + return Path.resolve(rp); } /** @@ -2799,7 +2848,7 @@ export class Workspace extends deploy_objects.DisposableBase implements deploy_c return; } - let workspaceDir = Path.resolve(this.folder.uri.fsPath); + let workspaceDir = this.rootPath; workspaceDir = deploy_helpers.replaceAllStrings(workspaceDir, Path.sep, '/'); if (!Path.isAbsolute(file)) { @@ -2847,7 +2896,7 @@ export class Workspace extends deploy_objects.DisposableBase implements deploy_c return Path.resolve( Path.join( - this.folder.uri.fsPath, + this.rootPath, RELATIVE_PATH ) ); @@ -2870,7 +2919,7 @@ export class Workspace extends deploy_objects.DisposableBase implements deploy_c ); const WORKSPACE_DIR = deploy_helpers.replaceAllStrings( - Path.resolve(this.folder.uri.fsPath), + this.rootPath, Path.sep, '/' );