Skip to content

Commit

Permalink
v1.2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
SamKirkland committed Jan 31, 2022
1 parent 4526c6c commit f79bd10
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 33 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@samkirkland/ftp-deploy",
"version": "1.2.0",
"version": "1.2.1",
"private": false,
"description": "Deploy files to a ftp server",
"main": "dist/module.js",
Expand Down
30 changes: 8 additions & 22 deletions src/main.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { HashDiff } from "./HashDiff";
import { IFileList, currentSyncFileVersion, IFile } from "./types";
import { Record } from "./types";
import { applyExcludeFilter, applyFolderFiltersToSubItems, getDefaultSettings, ILogger, Timings } from "./utilities";
import { applyExcludeFilter, getDefaultSettings, ILogger, Timings } from "./utilities";
import path from "path";
import FtpSrv from "ftp-srv";
import { getLocalFiles } from "./localFiles";
Expand Down Expand Up @@ -615,7 +615,7 @@ describe("getLocalFiles", () => {
new MockedStats("node_modules/@samkirkland/"),
];

const filteredStats = files.filter(file => applyExcludeFilter(file, applyFolderFiltersToSubItems(excludeDefaults)));
const filteredStats = files.filter(file => applyExcludeFilter(file, excludeDefaults));

expect(filteredStats.map(f => f.path)).toStrictEqual(["test/sam"]);
});
Expand All @@ -632,7 +632,7 @@ describe("getLocalFiles", () => {
new MockedStats("test/.git/workflows/main.yml"),
];

const filteredStats = files.filter(file => applyExcludeFilter(file, applyFolderFiltersToSubItems(excludeDefaults)));
const filteredStats = files.filter(file => applyExcludeFilter(file, excludeDefaults));

expect(filteredStats.map(f => f.path)).toStrictEqual(["test/sam"]);
});
Expand All @@ -652,7 +652,7 @@ describe("getLocalFiles", () => {
new MockedStats("node_modules/@samkirkland/"),
];

const filteredStats = files.filter(file => applyExcludeFilter(file, applyFolderFiltersToSubItems([])));
const filteredStats = files.filter(file => applyExcludeFilter(file, []));

expect(filteredStats.length).toBe(11);
});
Expand All @@ -663,7 +663,7 @@ describe("getLocalFiles", () => {
new MockedStats("test/folder/"),
];

const filteredStats = files.filter(file => applyExcludeFilter(file, applyFolderFiltersToSubItems(["*.js"])));
const filteredStats = files.filter(file => applyExcludeFilter(file, ["*.js"]));

expect(filteredStats.map(f => f.path)).toStrictEqual(["test/folder/"]);
});
Expand All @@ -674,7 +674,7 @@ describe("getLocalFiles", () => {
new MockedStats("test/folder/"),
];

const filteredStats = files.filter(file => applyExcludeFilter(file, applyFolderFiltersToSubItems(["**/folder/**"])));
const filteredStats = files.filter(file => applyExcludeFilter(file, ["**/folder/**"]));

expect(filteredStats.map(f => f.path)).toStrictEqual(["test/test.js"]);
});
Expand All @@ -685,7 +685,7 @@ describe("getLocalFiles", () => {
new MockedStats("test/folder/"),
];

const filteredStats = files.filter(file => applyExcludeFilter(file, applyFolderFiltersToSubItems(["**/folder/**"])));
const filteredStats = files.filter(file => applyExcludeFilter(file, ["**/folder/**"]));

expect(filteredStats.map(f => f.path)).toStrictEqual(["test/test.js"]);
});
Expand All @@ -697,21 +697,7 @@ describe("getLocalFiles", () => {
new MockedStats("test/folder/newfile.js"),
];

const filteredStats = files.filter(file => applyExcludeFilter(file, applyFolderFiltersToSubItems(["test/folder/**"])));

expect(filteredStats.map(f => f.path)).toStrictEqual(["test/test.js"]);
});

test("exclude existing folder while adding new file", async () => {
const files: MockedStats[] = [
new MockedStats("test/test.js"),
new MockedStats("test/folder/"),
new MockedStats("test/folder/subFolder/"),
new MockedStats("test/folder/newfile.js"),
new MockedStats("test/folder/sub/sub/sub/sub/newfile.js"),
];

const filteredStats = files.filter(file => applyExcludeFilter(file, applyFolderFiltersToSubItems(["test/folder/"])));
const filteredStats = files.filter(file => applyExcludeFilter(file, ["test/folder/**"]));

expect(filteredStats.map(f => f.path)).toStrictEqual(["test/test.js"]);
});
Expand Down
11 changes: 1 addition & 10 deletions src/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,21 +185,12 @@ export function getDefaultSettings(withoutDefaults: IFtpDeployArguments): IFtpDe
"state-name": withoutDefaults["state-name"] ?? ".ftp-deploy-sync-state.json",
"dry-run": withoutDefaults["dry-run"] ?? false,
"dangerous-clean-slate": withoutDefaults["dangerous-clean-slate"] ?? false,
"exclude": applyFolderFiltersToSubItems(withoutDefaults.exclude ?? excludeDefaults),
"exclude": withoutDefaults.exclude ?? excludeDefaults,
"log-level": withoutDefaults["log-level"] ?? "standard",
"security": withoutDefaults.security ?? "loose",
};
}

/**
* automatically exclude all sub-files/sub-folders if we exclude a folder.
* For example "test/" should also exclude "test/file.txt"
* to do this we add "**" to all folder paths
*/
export function applyFolderFiltersToSubItems(excludeFilters: Readonly<string[]>) {
return excludeFilters.map(filter => filter.endsWith("/") ? `${filter}**` : filter);
}

interface IStats {
path: string;
isDirectory(): boolean;
Expand Down

0 comments on commit f79bd10

Please sign in to comment.