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

Commit

Permalink
fixed auto selection
Browse files Browse the repository at this point in the history
  • Loading branch information
mkloubert committed Dec 10, 2016
1 parent 16cdc63 commit fb962e4
Showing 1 changed file with 90 additions and 80 deletions.
170 changes: 90 additions & 80 deletions src/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,102 +244,112 @@ export class Deployer {

let packageQuickPicks = packages.map((x, i) => deploy_helpers.createPackageQuickPick(x, i));

vscode.window.showQuickPick(packageQuickPicks, {
placeHolder: 'Select a package...',
}).then((item) => {
if (!item) {
return;
}

let packageName = deploy_helpers.toStringSafe(item.package.name);
let selectTarget = (item: deploy_contracts.DeployPackageQuickPickItem) => {
if (!item) {
return;
}

// files in include
let allFilePatterns: string[] = [];
if (item.package.files) {
allFilePatterns = item.package.files
.map(x => deploy_helpers.toStringSafe(x))
.filter(x => x);
let packageName = deploy_helpers.toStringSafe(item.package.name);

allFilePatterns = deploy_helpers.distinctArray(allFilePatterns);
}
if (allFilePatterns.length < 1) {
allFilePatterns.push('**'); // include all by default
}
// files in include
let allFilePatterns: string[] = [];
if (item.package.files) {
allFilePatterns = item.package.files
.map(x => deploy_helpers.toStringSafe(x))
.filter(x => x);

// files to exclude
let allExcludePatterns: string[] = [];
if (item.package.exclude) {
allExcludePatterns = item.package.exclude
.map(x => deploy_helpers.toStringSafe(x))
.filter(x => x);

allExcludePatterns = deploy_helpers.distinctArray(allExcludePatterns);
}
allFilePatterns = deploy_helpers.distinctArray(allFilePatterns);
}
if (allFilePatterns.length < 1) {
allFilePatterns.push('**'); // include all by default
}

// collect files to deploy
let filesToDeploy: string[] = [];
allFilePatterns.forEach(x => {
let matchingFiles: string[] = Glob.sync(x, {
absolute: true,
cwd: vscode.workspace.rootPath,
dot: true,
ignore: allExcludePatterns,
nodir: true,
root: vscode.workspace.rootPath,
});

matchingFiles.forEach(x => filesToDeploy.push(x));
});
filesToDeploy = deploy_helpers.distinctArray(filesToDeploy);
// files to exclude
let allExcludePatterns: string[] = [];
if (item.package.exclude) {
allExcludePatterns = item.package.exclude
.map(x => deploy_helpers.toStringSafe(x))
.filter(x => x);

if (filesToDeploy.length < 1) {
vscode.window.showWarningMessage(`There are no files to deploy!`);
return;
}
allExcludePatterns = deploy_helpers.distinctArray(allExcludePatterns);
}

let fileQuickPicks = targets.map((x, i) => deploy_helpers.createTargetQuickPick(x, i));
// collect files to deploy
let filesToDeploy: string[] = [];
allFilePatterns.forEach(x => {
let matchingFiles: string[] = Glob.sync(x, {
absolute: true,
cwd: vscode.workspace.rootPath,
dot: true,
ignore: allExcludePatterns,
nodir: true,
root: vscode.workspace.rootPath,
});

let deploy = (item: deploy_contracts.DeployTargetQuickPickItem) => {
try {
if (!item) {
return;
}
matchingFiles.forEach(x => filesToDeploy.push(x));
});
filesToDeploy = deploy_helpers.distinctArray(filesToDeploy);

let targetName = deploy_helpers.toStringSafe(item.target.name);
if (filesToDeploy.length < 1) {
vscode.window.showWarningMessage(`There are no files to deploy!`);
return;
}

me.outputChannel.show();
me.outputChannel.appendLine('');
let fileQuickPicks = targets.map((x, i) => deploy_helpers.createTargetQuickPick(x, i));

let deployMsg = `Deploying package`;
if (packageName) {
deployMsg += ` '${packageName}'`;
}
if (targetName) {
deployMsg += ` to '${targetName}'`;
}
deployMsg += '...';
let deploy = (item: deploy_contracts.DeployTargetQuickPickItem) => {
try {
if (!item) {
return;
}

me.outputChannel.appendLine(deployMsg);
let targetName = deploy_helpers.toStringSafe(item.target.name);

me.deployWorkspaceTo(filesToDeploy, item.target);
}
catch (e) {
vscode.window.showErrorMessage(`Could not deploy files: ` + e);
}
};
me.outputChannel.show();
me.outputChannel.appendLine('');

if (fileQuickPicks.length > 1) {
vscode.window.showQuickPick(fileQuickPicks, {
placeHolder: 'Select the target to deploy to...'
}).then((item) => {
deploy(item);
});
let deployMsg = `Deploying package`;
if (packageName) {
deployMsg += ` '${packageName}'`;
}
else {
// auto select
deploy(fileQuickPicks[0]);
if (targetName) {
deployMsg += ` to '${targetName}'`;
}
deployMsg += '...';

me.outputChannel.appendLine(deployMsg);

me.deployWorkspaceTo(filesToDeploy, item.target);
}
catch (e) {
vscode.window.showErrorMessage(`Could not deploy files: ` + e);
}
};

if (fileQuickPicks.length > 1) {
vscode.window.showQuickPick(fileQuickPicks, {
placeHolder: 'Select the target to deploy to...'
}).then((item) => {
deploy(item);
});
}
else {
// auto select
deploy(fileQuickPicks[0]);
}
};

if (packageQuickPicks.length > 1) {
vscode.window.showQuickPick(packageQuickPicks, {
placeHolder: 'Select a package...',
}).then((item) => {
selectTarget(item);
});
}
else {
// auto select
selectTarget(packageQuickPicks[0]);
}
}

/**
Expand Down

0 comments on commit fb962e4

Please sign in to comment.