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

Commit

Permalink
finished multi workspace support
Browse files Browse the repository at this point in the history
  • Loading branch information
mkloubert committed Nov 19, 2017
1 parent 2c574e5 commit 0351bf4
Show file tree
Hide file tree
Showing 7 changed files with 123 additions and 74 deletions.
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)

## 11.0.0 (November 20th, 2017; finished multi root support)

* added `extension.deploy.selectWorkspace`, which can change between workspaces now

## 10.0.0 (October 14th, 2017; multi root support)

* according to [that issue](https://github.com/mkloubert/vs-deploy/issues/112), started to refactor to new, upcoming [Multi Root Workspace API](https://github.com/Microsoft/vscode/wiki/Extension-Authoring:-Adopting-Multi-Root-Workspace-APIs)
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -324,4 +324,5 @@ Press `F1` to open the list of commands and enter one of the following commands:
| `Deploy: Open example / template` | Opens a [template](https://github.com/mkloubert/vs-deploy/wiki/templates) from one or more offical and/or custom repository. | This command does not have a default key binding. If you want to setup a shortcut for `extension.deploy.openTemplate`, you can update `keybindings.json` as described [here](https://code.visualstudio.com/docs/getstarted/keybindings#_advanced-customization). |
| `Deploy: Pull current file / folder` | Pulls the current opened file. | `CTRL+ALT+P, F` |
| `Deploy: Pull workspace` | Pulls a specific package. | `CTRL+ALT+P, W` |
| `Deploy: Select workspace` | Changes the current workspace, s. [Multi-root Workspaces](https://code.visualstudio.com/docs/editor/multi-root-workspaces). | This command does not have a default key binding. If you want to setup a shortcut for `extension.deploy.selectWorkspace`, you can update `keybindings.json` as described [here](https://code.visualstudio.com/docs/getstarted/keybindings#_advanced-customization). |
| `Deploy: Start/stop listening for files` | Start/stop listening for files from a remote machine. | `CTRL+ALT+L` |
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
"name": "vs-deploy",
"displayName": "Deploy",
"description": "Commands for deploying files of your workspace to a destination.",
"version": "10.0.0",
"version": "11.0.0",
"publisher": "mkloubert",
"engines": {
"vscode": "^1.17.0"
"vscode": "^1.18.0"
},
"license": "MIT",
"categories": [
Expand Down Expand Up @@ -102,6 +102,11 @@
"command": "extension.deploy.pullWorkspace",
"title": "Pull workspace",
"category": "Deploy"
},
{
"command": "extension.deploy.selectWorkspace",
"title": "Select workspace",
"category": "Deploy"
}
],
"keybindings": [
Expand Down Expand Up @@ -140,6 +145,7 @@
"properties": {
"deploy": {
"type": "object",
"scope": "resource",
"properties": {
"alwaysShowPackageList": {
"type": "boolean",
Expand Down
150 changes: 79 additions & 71 deletions src/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3966,191 +3966,199 @@ export class Deployer extends Events.EventEmitter implements vscode.Disposable {
* Reloads configuration.
*/
public reloadConfiguration() {
let me = this;
const ME = this;

if (!me.isActive) {
me._config = null;
if (!ME.isActive) {
ME._config = null;
return;
}

let loadedCfg = <deploy_contracts.DeployConfiguration>vscode.workspace.getConfiguration("deploy");
const SETTINGS_FILE = Path.join(
deploy_workspace.getRootPath(),
'./.vscode/settings.json',
);

const LOADED_CFG: deploy_contracts.DeployConfiguration = vscode.workspace.getConfiguration('deploy',
vscode.Uri.file(SETTINGS_FILE)) || <any>{};

let finished = (err: any, cfg: deploy_contracts.DeployConfiguration) => {
const FINISHED = (err: any, cfg: deploy_contracts.DeployConfiguration) => {
let showDefaultTemplateRepos = true;
if (cfg.templates) {
showDefaultTemplateRepos = deploy_helpers.toBooleanSafe(cfg.templates.showDefaults, true);
}

me.displayNetworkInfo();
me.showExtensionInfoPopups();
me.clearOutputOrNot();
ME.displayNetworkInfo();
ME.showExtensionInfoPopups();
ME.clearOutputOrNot();

// deploy.config.reloaded
deploy_globals.EVENTS.emit(deploy_contracts.EVENT_CONFIG_RELOADED, cfg);

me.executeStartupCommands();
me.openFiles();
ME.executeStartupCommands();
ME.openFiles();

deploy_buttons.reloadPackageButtons
.apply(me, []);
.apply(ME, []);

if (cfg.host) {
if (deploy_helpers.toBooleanSafe(cfg.host.autoStart)) {
// auto start host

let autoStartCompleted = (err: any) => {
const AUTOSTART_COMPLETED = (err: any) => {
if (err) {
vscode.window.showErrorMessage(`[vs-deploy]: ${deploy_helpers.toStringSafe(err)}`);
}
};

try {
let startListening = () => {
const START_LISTENING = () => {
try {
me.listen();
ME.listen();

autoStartCompleted(null);
AUTOSTART_COMPLETED(null);
}
catch (e) {
autoStartCompleted(e);
AUTOSTART_COMPLETED(e);
}
};

let host = me._host;
if (host) {
host.stop().then(() => {
me._host = null;
const CURRENT_HOST = ME._host;
if (CURRENT_HOST) {
CURRENT_HOST.stop().then(() => {
ME._host = null;

startListening();
START_LISTENING();
}).catch((err) => {
autoStartCompleted(err);
AUTOSTART_COMPLETED(err);
});
}
else {
startListening();
START_LISTENING();
}
}
catch (e) {
autoStartCompleted(e);
AUTOSTART_COMPLETED(e);
}
}
}

let afterGitPull = (err: any) => {
const AFTER_GIT_PULL = (err: any) => {
deploy_config.runBuildTask
.apply(me);
.apply(ME);

if (showDefaultTemplateRepos) {
// check official repo version
deploy_templates.checkOfficialRepositoryVersions
.apply(me, []);
.apply(ME, []);
}
};

deploy_config.runGitPull.apply(me).then(() => {
afterGitPull(null);
deploy_config.runGitPull.apply(ME).then(() => {
AFTER_GIT_PULL(null);
}).catch((err) => {
afterGitPull(err);
AFTER_GIT_PULL(err);
});
};

let next = (cfg: deploy_contracts.DeployConfiguration) => {
me._config = cfg;
const NEXT = (cfg: deploy_contracts.DeployConfiguration) => {
ME._config = cfg;

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

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

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

me.reloadEnvironmentVars();
ME.reloadEnvironmentVars();

me.reloadEvents();
me.reloadPlugins();
me.reloadCommands();
ME.reloadEvents();
ME.reloadPlugins();
ME.reloadCommands();

deploy_operations.resetOperations();

me.startExternalExtensions().then(() => {
finished(null, cfg);
ME.startExternalExtensions().then(() => {
FINISHED(null, cfg);
}).catch((err) => {
finished(err, cfg);
FINISHED(err, cfg);
});
};

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

me._lastConfigUpdate = Moment();
ME._lastConfigUpdate = Moment();

me._allTargets = deploy_helpers.asArray(cfg.targets)
ME._allTargets = deploy_helpers.asArray(cfg.targets)
.filter(x => x)
.map((x, i) => {
let clonedTarget = deploy_helpers.cloneObject(x);
clonedTarget.__id = i;

return clonedTarget;
});
me._globalScriptOperationState = {};
me._htmlDocs = [];
me._isDeployOnChangeFreezed = false;
me._scriptOperationStates = {};
me._targetCache = new deploy_objects.DeployTargetCache();
ME._globalScriptOperationState = {};
ME._htmlDocs = [];
ME._isDeployOnChangeFreezed = false;
ME._scriptOperationStates = {};
ME._targetCache = new deploy_objects.DeployTargetCache();

deploy_values.resetScriptStates();

me._QUICK_DEPLOY_STATUS_ITEM.text = 'Quick deploy!';
me._QUICK_DEPLOY_STATUS_ITEM.tooltip = 'Start a quick deploy...';
ME._QUICK_DEPLOY_STATUS_ITEM.text = 'Quick deploy!';
ME._QUICK_DEPLOY_STATUS_ITEM.tooltip = 'Start a quick deploy...';
i18.init(cfg.language).then(() => {
if (cfg.button) {
let txt = deploy_helpers.toStringSafe(cfg.button.text);
txt = me.replaceWithValues(txt).trim();
txt = ME.replaceWithValues(txt).trim();
if ('' === txt) {
txt = i18.t('quickDeploy.caption');
}
me._QUICK_DEPLOY_STATUS_ITEM.text = txt;
ME._QUICK_DEPLOY_STATUS_ITEM.text = txt;
}

me._QUICK_DEPLOY_STATUS_ITEM.tooltip = i18.t('quickDeploy.start');
ME._QUICK_DEPLOY_STATUS_ITEM.tooltip = i18.t('quickDeploy.start');

next(cfg);
NEXT(cfg);
}).catch((err) => {
me.log(`[ERROR :: vs-deploy] Deploy.reloadConfiguration(1): ${deploy_helpers.toStringSafe(err)}`);
ME.log(`[ERROR :: vs-deploy] Deploy.reloadConfiguration(1): ${deploy_helpers.toStringSafe(err)}`);

next(cfg);
NEXT(cfg);
});

me._QUICK_DEPLOY_STATUS_ITEM.hide();
ME._QUICK_DEPLOY_STATUS_ITEM.hide();
if (cfg.button) {
if (deploy_helpers.toBooleanSafe(cfg.button.enabled)) {
me._QUICK_DEPLOY_STATUS_ITEM.show();
ME._QUICK_DEPLOY_STATUS_ITEM.show();
}
}

if (deploy_helpers.toBooleanSafe(cfg.openOutputOnStartup)) {
me.outputChannel.show();
ME.outputChannel.show();
}
}

deploy_config.mergeConfig(loadedCfg).then((cfg) => {
applyCfg(cfg);
deploy_config.mergeConfig(LOADED_CFG).then((cfg) => {
APPLY_CONFIG(cfg);
}).catch((err) => {
me.log(`[ERROR :: vs-deploy] Deploy.reloadConfiguration(2): ${deploy_helpers.toStringSafe(err)}`);
ME.log(`[ERROR :: vs-deploy] Deploy.reloadConfiguration(2): ${deploy_helpers.toStringSafe(err)}`);

applyCfg(loadedCfg);
APPLY_CONFIG(LOADED_CFG);
});
}

Expand Down
16 changes: 16 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,21 @@ export function activate(context: vscode.ExtensionContext) {
});
});

// select workspace
let selectWorkspace = vscode.commands.registerCommand('extension.deploy.selectWorkspace', async () => {
try {
const FOLDER = await deploy_workspace.selectWorkspace();
if (FOLDER) {
await Promise.resolve(
deployer.onDidChangeConfiguration()
);
}
}
catch (e) {
vscode.window.showErrorMessage(`[SELECT WORKSPACE ERROR]: ${deploy_helpers.toStringSafe(e)}`);
}
});

let htmlViewer = vscode.workspace.registerTextDocumentContentProvider('vs-deploy-html',
new deploy_content.HtmlTextDocumentContentProvider(deployer));

Expand All @@ -243,6 +258,7 @@ export function activate(context: vscode.ExtensionContext) {
htmlViewer,
listen,
pull, pullFileOrFolder,
selectWorkspace,
openHtmlDoc, openOutputAfterDeploment, openTemplate,
quickDeploy);

Expand Down
14 changes: 14 additions & 0 deletions src/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,17 @@ export function getRootPath() {
export function resetSelectedWorkspaceFolder() {
currentFolder = false;
}

/**
* Selects the workspace.
*
* @return {Promise<vscode.WorkspaceFolder>} The promise with the folder (if selected).
*/
export async function selectWorkspace() {
const FOLDER = await vscode.window.showWorkspaceFolderPick();
if (FOLDER) {
currentFolder = FOLDER;
}

return FOLDER;
}

0 comments on commit 0351bf4

Please sign in to comment.