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

Commit

Permalink
improvements and bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mkloubert committed Dec 27, 2017
1 parent ac139df commit 832fc69
Show file tree
Hide file tree
Showing 8 changed files with 240 additions and 194 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Change Log (vscode-deploy-reloaded)

## 0.1.1 (December 27th, 2017; initial release)
## 0.2.0 (December 27th, 2017; improvements and bugfixes)

* bugfixes
* improved displaying [packages](https://github.com/mkloubert/vscode-deploy-reloaded/wiki#packages-) and [targets](https://github.com/mkloubert/vscode-deploy-reloaded/wiki#targets-) in the GUI

## 0.1.2 (December 27th, 2017; initial release)

For more information about the extension, that a look at the [project page](https://github.com/mkloubert/vscode-deploy-reloaded) or the [wiki](https://github.com/mkloubert/vscode-deploy-reloaded/wiki).
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.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "vscode-deploy-reloaded",
"displayName": "Deploy (Reloaded)",
"description": "Deploys files of a workspace to a destination.",
"version": "0.1.2",
"version": "0.2.0",
"publisher": "mkloubert",
"engines": {
"vscode": "^1.19.0"
Expand Down
156 changes: 78 additions & 78 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,40 @@ function getActiveWorkspacesOrAll() {
return listOfWorkspaces.map(ws => ws);
}

function getAllWorkspacesSorted() {
return Enumerable.from( WORKSPACES ).orderBy(ws => {
return ws.isActive ? 0 : 1;
}).thenBy(ws => {
return deploy_helpers.normalizeString(ws.name);
}).thenBy(ws => {
return deploy_helpers.normalizeString(ws.rootPath);
}).toArray();
}

function getAllPackagesSorted() {
return Enumerable.from( getAllWorkspacesSorted() ).selectMany(ws => {
return Enumerable.from( ws.getPackages() ).orderBy(pkg => {
return deploy_helpers.normalizeString(
deploy_packages.getPackageName(pkg)
);
}).thenBy(pkg => {
return pkg.__index;
});
}).toArray();
}

function getAllTargetsSorted() {
return Enumerable.from( getAllWorkspacesSorted() ).selectMany(ws => {
return Enumerable.from( ws.getTargets() ).orderBy(t => {
return deploy_helpers.normalizeString(
deploy_targets.getTargetName(t)
);
}).thenBy(t => {
return t.__index;
});
}).toArray();
}

async function invokeForActiveEditor(placeHolder: string,
action: (file: string, target: deploy_targets.Target) => any) {
const ACTIVE_EDITOR = vscode.window.activeTextEditor;
Expand Down Expand Up @@ -134,50 +168,6 @@ async function invokeForActiveEditor(placeHolder: string,
}
}

async function invokeForActivePackage(placeHolder: string,
action: (pkg: deploy_packages.Package) => any) {
const PACKAGES = getActivePackages();

const QUICK_PICK_ITEMS: deploy_contracts.ActionQuickPick[] = PACKAGES.map((p, i) => {
return {
action: async () => {
if (action) {
await Promise.resolve(
action(p)
);
}
},
description: deploy_helpers.toStringSafe( p.description ).trim(),
detail: p.__workspace.folder.uri.fsPath,
label: deploy_packages.getPackageName(p),
};
});

if (QUICK_PICK_ITEMS.length < 1) {
deploy_helpers.showWarningMessage(
i18.t('packages.noneFound')
);

return;
}

let selectedItem: deploy_contracts.ActionQuickPick;
if (1 === QUICK_PICK_ITEMS.length) {
selectedItem = QUICK_PICK_ITEMS[0];
}
else {
selectedItem = await vscode.window.showQuickPick(QUICK_PICK_ITEMS, {
placeHolder: placeHolder,
});
}

if (selectedItem) {
await Promise.resolve(
selectedItem.action()
);
}
}

function normalizeActiveWorkspaces(aws: deploy_workspaces.Workspace | deploy_workspaces.Workspace[]) {
aws = deploy_helpers.asArray(aws);

Expand Down Expand Up @@ -299,6 +289,7 @@ async function reloadWorkspaceFolders(added: vscode.WorkspaceFolder[], removed?:
for (let i = 0; i < WORKSPACES.length; ) {
const WS = WORKSPACES[i];
let removeWorkspace = false;
let hasBeenRemoved = false;

for (let rws of removed) {
if (Path.resolve(rws.uri.fsPath) === Path.resolve(WS.folder.uri.fsPath)) {
Expand All @@ -310,8 +301,13 @@ async function reloadWorkspaceFolders(added: vscode.WorkspaceFolder[], removed?:
if (removeWorkspace) {
if (deploy_helpers.tryDispose(WS)) {
WORKSPACES.splice(i, 1);
hasBeenRemoved = true;
}
}

if (!hasBeenRemoved) {
++i;
}
}
}

Expand Down Expand Up @@ -679,7 +675,7 @@ async function activateExtension(context: vscode.ExtensionContext) {
outputChannel.appendLine('');
outputChannel.appendLine(`GitHub : https://github.com/mkloubert/vscode-deploy-reloaded`);
outputChannel.appendLine(`Twitter: https://twitter.com/mjkloubert`);
outputChannel.appendLine(`Donate : [PayPal] https://paypal.me/MarcelKloubert`);
outputChannel.appendLine(`Donate : https://paypal.me/MarcelKloubert`);
});

// commands
Expand Down Expand Up @@ -755,13 +751,17 @@ async function activateExtension(context: vscode.ExtensionContext) {
// deploy workspace
vscode.commands.registerCommand('extension.deploy.reloaded.deployWorkspace', async () => {
try {
await invokeForActivePackage(
i18.t('packages.selectPackage'),
async (pkg) => {
await pkg.__workspace
.deployPackage(pkg);
const PKG = await deploy_packages.showPackageQuickPick(
getAllPackagesSorted(),
{
placeHolder: i18.t('packages.selectPackage'),
}
);

if (PKG) {
await PKG.__workspace
.deployPackage(PKG);
}
}
catch (e) {
deploy_log.CONSOLE
Expand Down Expand Up @@ -835,13 +835,17 @@ async function activateExtension(context: vscode.ExtensionContext) {
// pull workspace
vscode.commands.registerCommand('extension.deploy.reloaded.pullWorkspace', async () => {
try {
await invokeForActivePackage(
i18.t('packages.selectPackage'),
async (pkg) => {
await pkg.__workspace
.pullPackage(pkg);
const PKG = await deploy_packages.showPackageQuickPick(
getAllPackagesSorted(),
{
placeHolder: i18.t('packages.selectPackage'),
}
);

if (PKG) {
await PKG.__workspace
.pullPackage(PKG);
}
}
catch (e) {
deploy_log.CONSOLE
Expand Down Expand Up @@ -914,13 +918,17 @@ async function activateExtension(context: vscode.ExtensionContext) {
// delete package
vscode.commands.registerCommand('extension.deploy.reloaded.deletePackage', async () => {
try {
await invokeForActivePackage(
i18.t('packages.selectPackage'),
async (pkg) => {
await pkg.__workspace
.deletePackage(pkg);
const PKG = await deploy_packages.showPackageQuickPick(
getAllPackagesSorted(),
{
placeHolder: i18.t('packages.selectPackage'),
}
);

if (PKG) {
await PKG.__workspace
.deletePackage(PKG);
}
}
catch (e) {
deploy_log.CONSOLE
Expand Down Expand Up @@ -956,25 +964,17 @@ async function activateExtension(context: vscode.ExtensionContext) {
// list directory
vscode.commands.registerCommand('extension.deploy.reloaded.listDirectory', async () => {
try {
let workspacesWithTargets = activeWorkspaces;
if (workspacesWithTargets.length < 1) {
workspacesWithTargets = WORKSPACES;
}

const TARGETS = Enumerable.from(workspacesWithTargets).selectMany(ws => {
return ws.getTargets();
}).where(t => {
return t.__workspace.getListPlugins(t).length > 0;
}).toArray();

await deploy_targets.showTargetQuickPick(
TARGETS,
i18.t('listDirectory.selectSource'),
async (target) => {
await target.__workspace
.listDirectory(target);
const TARGET = await deploy_targets.showTargetQuickPick(
getAllTargetsSorted(),
{
placeHolder: i18.t('listDirectory.selectSource'),
}
);

if (TARGET) {
await TARGET.__workspace
.listDirectory(TARGET);
}
}
catch (e) {
deploy_log.CONSOLE
Expand All @@ -991,7 +991,7 @@ async function activateExtension(context: vscode.ExtensionContext) {
try {
await deploy_tools_quick_execution._1b87f2ee_b636_45b6_807c_0e2d25384b02_1409614337(
currentContext,
WORKSPACES.map(ws => ws),
getAllWorkspacesSorted(),
activeWorkspaces.map(aws => aws),
);
}
Expand Down
46 changes: 46 additions & 0 deletions src/packages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import * as deploy_log from './log';
import * as deploy_targets from './targets';
import * as deploy_workspaces from './workspaces';
import * as Enumerable from 'node-enumerable';
import * as i18 from './i18';
import * as Moment from 'moment';
import * as Path from 'path';
import * as UUID from 'uuid';
Expand Down Expand Up @@ -345,3 +346,48 @@ export function getTargetsOfPackage(pkg: Package): deploy_targets.Target[] | fal

return targets;
}

/**
* Shows a quick pick for a list of packages.
*
* @param {Package|Package[]} packages One or more packages.
* @param {vscode.QuickPickOptions} [opts] Custom options for the quick picks.
*
* @return {Promise<Package|false>} The promise that contains the selected package (if selected)
* or (false) if no package is available.
*/
export async function showPackageQuickPick(packages: Package | Package[],
opts?: vscode.QuickPickOptions): Promise<Package | false> {
const QUICK_PICKS: deploy_contracts.ActionQuickPick<Package>[] = deploy_helpers.asArray(packages).map(pkg => {
const WORKSPACE = pkg.__workspace;

return {
label: getPackageName(pkg),
description: deploy_helpers.toStringSafe(pkg.description),
detail: WORKSPACE.rootPath,
state: pkg,
};
});

if (QUICK_PICKS.length < 1) {
deploy_helpers.showWarningMessage(
i18.t('packages.noneFound')
);

return false;
}

let selectedItem: deploy_contracts.ActionQuickPick<Package>;
if (1 === QUICK_PICKS.length) {
selectedItem = QUICK_PICKS[0];
}
else {
selectedItem = await vscode.window.showQuickPick(
QUICK_PICKS, opts
);
}

if (selectedItem) {
return selectedItem.state;
}
}
Loading

0 comments on commit 832fc69

Please sign in to comment.