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

Commit

Permalink
added "fast file check" settings
Browse files Browse the repository at this point in the history
  • Loading branch information
mkloubert committed Jan 4, 2018
1 parent 777ddd0 commit 986d37d
Show file tree
Hide file tree
Showing 9 changed files with 216 additions and 67 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
[![Share via Facebook](https://raw.githubusercontent.com/mkloubert/vscode-deploy-reloaded/master/img/share/Facebook.png)](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fmarketplace.visualstudio.com%2Fitems%3FitemName%3Dmkloubert.vscode-deploy-reloaded&quote=vscode-deploy-reloaded) [![Share via Twitter](https://raw.githubusercontent.com/mkloubert/vscode-deploy-reloaded/master/img/share/Twitter.png)](https://twitter.com/intent/tweet?source=https%3A%2F%2Fmarketplace.visualstudio.com%2Fitems%3FitemName%3Dmkloubert.vscode-deploy-reloaded&text=vscode-deploy-reloaded:%20https%3A%2F%2Fmarketplace.visualstudio.com%2Fitems%3FitemName%3Dmkloubert.vscode-deploy-reloaded&via=mjkloubert) [![Share via Google+](https://raw.githubusercontent.com/mkloubert/vscode-deploy-reloaded/master/img/share/Google+.png)](https://plus.google.com/share?url=https%3A%2F%2Fmarketplace.visualstudio.com%2Fitems%3FitemName%3Dmkloubert.vscode-deploy-reloaded) [![Share via Pinterest](https://raw.githubusercontent.com/mkloubert/vscode-deploy-reloaded/master/img/share/Pinterest.png)](https://pinterest.com/pin/create/button/?url=https%3A%2F%2Fmarketplace.visualstudio.com%2Fitems%3FitemName%3Dmkloubert.vscode-deploy-reloaded&media=https://raw.githubusercontent.com/mkloubert/vscode-deploy-reloaded/master/img/demo1.gif&description=Recoded%20version%20of%20Visual%20Studio%20Code%20extension%20%27vs-deploy%27%2C%20which%20provides%20commands%20to%20deploy%20files%20to%20one%20or%20more%20destinations.) [![Share via Reddit](https://raw.githubusercontent.com/mkloubert/vscode-deploy-reloaded/master/img/share/Reddit.png)](https://www.reddit.com/submit?url=https%3A%2F%2Fmarketplace.visualstudio.com%2Fitems%3FitemName%3Dmkloubert.vscode-deploy-reloaded&title=vscode-deploy-reloaded) [![Share via LinkedIn](https://raw.githubusercontent.com/mkloubert/vscode-deploy-reloaded/master/img/share/LinkedIn.png)](https://www.linkedin.com/shareArticle?mini=true&url=https%3A%2F%2Fmarketplace.visualstudio.com%2Fitems%3FitemName%3Dmkloubert.vscode-deploy-reloaded&title=vscode-deploy-reloaded&summary=Recoded%20version%20of%20Visual%20Studio%20Code%20extension%20%27vs-deploy%27%2C%20which%20provides%20commands%20to%20deploy%20files%20to%20one%20or%20more%20destinations.&source=https%3A%2F%2Fmarketplace.visualstudio.com%2Fitems%3FitemName%3Dmkloubert.vscode-deploy-reloaded) [![Share via Wordpress](https://raw.githubusercontent.com/mkloubert/vscode-deploy-reloaded/master/img/share/Wordpress.png)](https://wordpress.com/press-this.php?u=https%3A%2F%2Fmarketplace.visualstudio.com%2Fitems%3FitemName%3Dmkloubert.vscode-deploy-reloaded&quote=vscode-deploy-reloaded&s=Recoded%20version%20of%20Visual%20Studio%20Code%20extension%20%27vs-deploy%27%2C%20which%20provides%20commands%20to%20deploy%20files%20to%20one%20or%20more%20destinations.&i=https://raw.githubusercontent.com/mkloubert/vscode-deploy-reloaded/master/img/demo1.gif) [![Share via Email](https://raw.githubusercontent.com/mkloubert/vscode-deploy-reloaded/master/img/share/Email.png)](mailto:?subject=vscode-deploy-reloaded&body=Recoded%20version%20of%20Visual%20Studio%20Code%20extension%20'vs-deploy'%2C%20which%20provides%20commands%20to%20deploy%20files%20to%20one%20or%20more%20destinations.:%20https%3A%2F%2Fmarketplace.visualstudio.com%2Fitems%3FitemName%3Dmkloubert.vscode-deploy-reloaded)


# 0.17.0 (January 4th, 2018; fast file checks for auto deploy)

* speed up file check in "auto deploy" features, by adding `fastCheckOnChange`, `fastCheckOnSave`, `fastCheckOnSync` and `fastFileCheck` flags in [global](https://github.com/mkloubert/vscode-deploy-reloaded/wiki#settings--) and [package](https://github.com/mkloubert/vscode-deploy-reloaded/wiki#packages-) settings ... s. [issue #9](https://github.com/mkloubert/vscode-deploy-reloaded/issues/9)

## 0.16.2 (January 3rd, 2018; deploy all opened files)

* added commands for deploying (`extension.deploy.reloaded.deployAllOpenFiles`) or pulling (`extension.deploy.reloaded.pullAllOpenFiles`) files of all opened text editors
Expand Down
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.

42 changes: 41 additions & 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.16.2",
"version": "0.17.0",
"publisher": "mkloubert",
"engines": {
"vscode": "^1.19.0"
Expand Down Expand Up @@ -334,6 +334,26 @@
]
}
},
"fastCheckOnChange": {
"description": "Value that indicates, if fast file check should be made for 'deploy on change' in all packages by default.",
"type": "boolean",
"default": false
},
"fastCheckOnSave": {
"description": "Value that indicates, if fast file check should be made for 'deploy on save' in all packages by default.",
"type": "boolean",
"default": false
},
"fastCheckOnSync": {
"description": "Value that indicates, if fast file check should be made for 'sync when open' in all packages by default.",
"type": "boolean",
"default": false
},
"fastFileCheck": {
"description": "Value that indicates, to do a fast file check for any 'auto deploy' settings in all packages by default.",
"type": "boolean",
"default": false
},
"globals": {
"description": "Global data to define, which can be access by scripts, e.g."
},
Expand Down Expand Up @@ -586,6 +606,26 @@
"type": "string"
}
},
"fastCheckOnChange": {
"description": "Value that indicates, if fast file check should be made for 'deploy on change' in that package.",
"type": "boolean",
"default": false
},
"fastCheckOnSave": {
"description": "Value that indicates, if fast file check should be made for 'deploy on save' in that package.",
"type": "boolean",
"default": false
},
"fastCheckOnSync": {
"description": "Value that indicates, if fast file check should be made for 'sync when open' in that package.",
"type": "boolean",
"default": false
},
"fastFileCheck": {
"description": "Value that indicates, to do a fast file check for any 'auto deploy' settings in that package by default.",
"type": "boolean",
"default": false
},
"files": {
"description": "A list of one or more (glob) patterns of files that should be deployed. By default ALL files will be deployed.",
"type": "array",
Expand Down
4 changes: 3 additions & 1 deletion src/contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,9 @@ export interface ConfigSource {
/**
* Deploy settings.
*/
export interface Configuration extends deploy_values.WithValueItems {
export interface Configuration extends deploy_packages.WithFastFileCheckSettings,
deploy_values.WithValueItems
{
/**
* One or more requirements to check.
*/
Expand Down
14 changes: 1 addition & 13 deletions src/delete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -528,19 +528,7 @@ export async function removeOnChange(file: string) {
deploy_packages.findTargetsForFileOfPackage, ME
)(file,
(pkg) => pkg.removeOnChange,
(filter, file) => {
const FILE_LIST: string[] = [];
const REL_PATH = ME.toRelativePath(file);
if (false !== REL_PATH) {
const DOES_MATCH = deploy_helpers.checkIfDoesMatchByFileFilter('/' + REL_PATH,
deploy_helpers.toMinimatchFileFilter(filter));
if (DOES_MATCH) {
FILE_LIST.push(file);
}
}

return FILE_LIST;
});
(pkg) => true);

if (false === TARGETS) {
return;
Expand Down
40 changes: 24 additions & 16 deletions src/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -544,14 +544,18 @@ export async function deployPackage(pkg: deploy_packages.Package) {
export async function deployOnChange(file: string) {
const ME: deploy_workspaces.Workspace = this;

const ARGS = [
file,
(pkg: deploy_packages.Package) => pkg.deployOnChange,
'deploy.onChange.failed',
];

return await deploy_packages.autoDeployFile
.apply(ME, ARGS);
return await deploy_helpers.applyFuncFor(
deploy_packages.autoDeployFile,
ME
)(file,
(pkg) => pkg.deployOnChange,
(pkg) => {
return deploy_packages.getFastFileCheckFlag(
pkg, (p) => p.fastCheckOnChange,
ME.config, (c) => c.fastCheckOnChange,
);
},
'deploy.onChange.failed');
}

/**
Expand All @@ -562,14 +566,18 @@ export async function deployOnChange(file: string) {
export async function deployOnSave(file: string) {
const ME: deploy_workspaces.Workspace = this;

const ARGS = [
file,
(pkg: deploy_packages.Package) => pkg.deployOnSave,
'deploy.onSave.failed',
];

return await deploy_packages.autoDeployFile
.apply(ME, ARGS);
return await deploy_helpers.applyFuncFor(
deploy_packages.autoDeployFile,
ME
)(file,
(pkg) => pkg.deployOnSave,
(pkg) => {
return deploy_packages.getFastFileCheckFlag(
pkg, (p) => p.fastCheckOnSave,
ME.config, (c) => c.fastCheckOnSave,
);
},
'deploy.onSave.failed');
}

/**
Expand Down
131 changes: 113 additions & 18 deletions src/packages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export interface Package extends deploy_values.Applyable,
deploy_contracts.PlatformItem,
deploy_contracts.WithOptionalName,
deploy_targets.TargetProvider,
WithFastFileCheckSettings,
deploy_workspaces.WorkspaceItemFromSettings {
/**
* [INTERNAL] DO NOT DEFINE OR OVERWRITE THIS PROPERTY BY YOUR OWN!
Expand Down Expand Up @@ -93,24 +94,26 @@ export interface PackageDeployFileFilter extends deploy_contracts.FileFilter,
export type PackageDeploySettings = boolean | string | string[] | PackageDeployFileFilter;

/**
* A function that resolves deploy settings for a package.
* A function that resolves the package flag, which indicates, if a "fast file check"
* should be made or not.
*
* @param {Package} pkg The underlying package.
*
* @return {PackageDeploySettings} The result with the settings.
* @return {boolean|PromiseLike<boolean>} The result with the flag.
*/
export type PackageDeploySettingsResolver = (pkg: Package) => PackageDeploySettings;
export type PackageFastFileCheckFlagResolver = (pkg: Package) => boolean | PromiseLike<boolean>;

/**
* A package file list resolver.
* A function that resolves deploy settings for a package.
*
* @param {deploy_contracts.FileFilter} The filter.
* @param {string} The scope file.
* @param {Package} pkg The underlying package.
*
* @return {PackageFileListResolverResult|PromiseLike<PackageFileListResolverResult>} The result.
* @return {PackageDeploySettings} The result with the settings.
*/
export type PackageFileListResolver = (filter: deploy_contracts.FileFilter, file: string) => PackageFileListResolverResult |
PromiseLike<PackageFileListResolverResult>;
export type PackageDeploySettingsResolver = (pkg: Package) => PackageDeploySettings;

type PackageFileListResolver = (filter: deploy_contracts.FileFilter, file: string) => PackageFileListResolverResult |
PromiseLike<PackageFileListResolverResult>;

/**
* Possible results of a package file list resolver.
Expand All @@ -123,6 +126,28 @@ export type PackageFileListResolverResult = string | string[];
export interface SyncWhenOpenSetting extends deploy_contracts.FileFilter {
}

/**
* Object that contains settings for "fast file checks".
*/
export interface WithFastFileCheckSettings {
/**
* Indicates if 'fast file check' should be used for 'deploy on change' in that package.
*/
readonly fastCheckOnChange?: boolean;
/**
* Indicates if 'fast file check' should be used for 'deploy on save' in that package.
*/
readonly fastCheckOnSave?: boolean;
/**
* Indicates if 'fast file check' should be used for 'sync when open' in that package.
*/
readonly fastCheckOnSync?: boolean;
/**
* Default value for other, not-set "fast file check" settings.
*/
readonly fastFileCheck?: boolean;
}


const KEY_PACKAGE_USAGE = 'vscdrLastExecutedPackageActions';

Expand All @@ -131,18 +156,21 @@ const KEY_PACKAGE_USAGE = 'vscdrLastExecutedPackageActions';
*
* @param {string} file The file to check.
* @param {PackageDeploySettingsResolver} settingsResolver The settings resolver.
* @param {PackageFastFileCheckFlagResolver} fastFileCheckFlagResolver A custom "fast file check" resolver.
* @param {string} errorMsgTemplate The template for an error message.
*/
export async function autoDeployFile(file: string,
settingsResolver: PackageDeploySettingsResolver,
fastFileCheckFlagResolver: PackageFastFileCheckFlagResolver,
errorMsgTemplate: string) {
const ME: deploy_workspaces.Workspace = this;

try {
const TARGETS = await deploy_helpers.applyFuncFor(
findTargetsForFileOfPackage, ME
)(file,
settingsResolver);
settingsResolver,
fastFileCheckFlagResolver);
if (false === TARGETS) {
return;
}
Expand Down Expand Up @@ -172,15 +200,16 @@ export async function autoDeployFile(file: string,
*
* @param {string} file The path to the file.
* @param {PackageDeploySettingsResolver} settingsResolver The resolver for the settings.
* @param {PackageFileListResolver} [fileListResolver] A custom file list resolver.
* @param {PackageFastFileCheckFlagResolver} fastFileCheckFlagResolver A custom "fast file check" resolver.
*
* @return {Promise<deploy_targets.Target[]>|false} The List of targets or (false) if at least one target name could not be resolved.
*/
export async function findTargetsForFileOfPackage(
file: string,
settingsResolver: PackageDeploySettingsResolver,
fileListResolver?: PackageFileListResolver,
): Promise<deploy_targets.Target[] | false> {
fastFileCheckFlagResolver: PackageFastFileCheckFlagResolver,
): Promise<deploy_targets.Target[] | false>
{
const ME: deploy_workspaces.Workspace = this;

file = deploy_helpers.toStringSafe(file);
Expand Down Expand Up @@ -246,11 +275,30 @@ export async function findTargetsForFileOfPackage(
return false;
}

let flr = fileListResolver;
if (!flr) {
// use default
const FAST_FILE_CHECK = deploy_helpers.toBooleanSafe(
await Promise.resolve(
fastFileCheckFlagResolver(pkg)
)
);

let fileListResolver: PackageFileListResolver;
if (FAST_FILE_CHECK) {
fileListResolver = () => {
const FILE_LIST: string[] = [];
const REL_PATH = ME.toRelativePath(file);
if (false !== REL_PATH) {
const DOES_MATCH = deploy_helpers.checkIfDoesMatchByFileFilter('/' + REL_PATH,
deploy_helpers.toMinimatchFileFilter(filter));
if (DOES_MATCH) {
FILE_LIST.push(file);
}
}

flr = async () => {
return FILE_LIST;
};
}
else {
fileListResolver = async () => {
let fileList = await ME.findFilesByFilter(pkg);
if (filter !== pkg) {
fileList = fileList.filter(f => {
Expand All @@ -270,7 +318,7 @@ export async function findTargetsForFileOfPackage(

const FILE_LIST = deploy_helpers.asArray(
await Promise.resolve(
flr(filter, file)
fileListResolver(filter, file)
)
);

Expand All @@ -283,6 +331,53 @@ export async function findTargetsForFileOfPackage(
return TARGETS;
}

/**
* Detects a "fast file check" flag value.
*
* @param {TObj} obj The child object.
* @param {Function} flagResolver The function that detects the flag value from the child object.
* @param {TParentObj} parentObj The parent object.
* @param {Function} parentFlagResolver The function that detects the flag value from the parent object.
*
* @return {boolean} The detected flag.
*/
export function getFastFileCheckFlag<TObj extends WithFastFileCheckSettings = WithFastFileCheckSettings,
TParentObj extends WithFastFileCheckSettings = WithFastFileCheckSettings>
(
obj: TObj, flagResolver: (o: TObj) => boolean,
parentObj: TParentObj, parentFlagResolver: (po: TParentObj) => boolean
)
{
if (!obj) {
obj = <any>{};
}

if (!flagResolver) {
flagResolver = () => undefined;
}

if (!parentObj) {
parentObj = <any>{};
}

if (!parentFlagResolver) {
parentFlagResolver = () => undefined;
}

const FAST_FILE_CHECK = deploy_helpers.toBooleanSafe(
flagResolver(obj),
deploy_helpers.toBooleanSafe(obj.fastFileCheck),
);

const PARENT_FAST_FILE_CHECK = deploy_helpers.toBooleanSafe(
parentFlagResolver(parentObj),
deploy_helpers.toBooleanSafe(parentObj.fastFileCheck),
);

return deploy_helpers.toBooleanSafe(FAST_FILE_CHECK,
PARENT_FAST_FILE_CHECK);
}

/**
* Returns the name for a package.
*
Expand Down
8 changes: 7 additions & 1 deletion src/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,13 @@ export async function syncDocumentWhenOpen(doc: vscode.TextDocument) {
const TARGETS = await deploy_helpers.applyFuncFor(
deploy_packages.findTargetsForFileOfPackage, ME
)(FILE,
(pkg) => pkg.syncWhenOpen);
(pkg) => pkg.syncWhenOpen,
(pkg) => {
return deploy_packages.getFastFileCheckFlag(
pkg, (p) => p.fastCheckOnSync,
ME.config, (c) => c.fastCheckOnSync,
);
});

if (false === TARGETS) {
return;
Expand Down
Loading

0 comments on commit 986d37d

Please sign in to comment.