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

Commit

Permalink
fixed loading settings from parent folder
Browse files Browse the repository at this point in the history
  • Loading branch information
mkloubert committed Dec 29, 2017
1 parent dff6a5f commit 6925d82
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 64 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
8 changes: 0 additions & 8 deletions src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
1 change: 0 additions & 1 deletion src/delete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
45 changes: 7 additions & 38 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
};
});
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/targets/operations/open.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
}
81 changes: 65 additions & 16 deletions src/workspaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
}


Expand Down Expand Up @@ -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;
/**
Expand All @@ -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);
}

Expand Down Expand Up @@ -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.
*
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -1376,6 +1386,8 @@ export class Workspace extends deploy_objects.DisposableBase implements deploy_c
return false;
}

ME._rootPath = false;

// settings file
{
interface SettingsData {
Expand Down Expand Up @@ -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,
Expand All @@ -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<string | false>;
searchForNextFolder = async (dir) => {
try {
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -2028,6 +2048,24 @@ export class Workspace extends deploy_objects.DisposableBase implements deploy_c
ME.configSource.resource) || <any>{};
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 ]);
Expand Down Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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
)
);
Expand All @@ -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,
'/'
);
Expand Down

0 comments on commit 6925d82

Please sign in to comment.