Skip to content

Commit f7b9149

Browse files
authored
Merge pull request #26 from SamKirkland/upgrade-dependencies
upgrade dependencies
2 parents cba6023 + 809c1b3 commit f7b9149

File tree

7 files changed

+1662
-3528
lines changed

7 files changed

+1662
-3528
lines changed

@types/global.d.ts

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// eslint-disable-next-line @typescript-eslint/no-empty-interface
2+
export interface global { }
3+
declare global {
4+
function reconnect(): Promise<void>;
5+
}

@types/vendor.d.ts

-5
This file was deleted.

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,4 @@ To list all commands with examples simply run `ftp-deploy` without any options.
7474
| `--exclude` | No | `nuclearLaunchCodes.txt` | `**/.git*` `**/.git*/**` `**/node_modules/**` | An array of glob patterns, these files will not be included in the publish/delete process |
7575
| `--log-level` | No | `info` | `info` | `minimal`: only important info, `standard`: important info and basic file changes, `verbose`: print everything the script is doing |
7676
| `--security` | No | `strict` | `loose` | `strict`: Reject any connection which is not authorized with the list of supplied CAs. `loose`: Allow connection even when the domain is not in certificate |
77+
| `--timeout` | No | `60000` | `30000` | Timeout in milliseconds for FTP operations |

package-lock.json

+1,547-3,501
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+17-17
Original file line numberDiff line numberDiff line change
@@ -26,31 +26,31 @@
2626
"author": "Sam Kirkland",
2727
"license": "MIT",
2828
"dependencies": {
29-
"basic-ftp": "^4.6.6",
29+
"basic-ftp": "^5.0.1",
3030
"lodash": "^4.17.21",
3131
"multimatch": "^5.0.0",
32-
"np": "^7.5.0",
32+
"np": "^7.6.2",
3333
"pretty-bytes": "^5.6.0",
3434
"pretty-ms": "^7.0.1",
3535
"readdir-enhanced": "^6.0.4",
36-
"yargs": "^17.2.1"
36+
"yargs": "^17.5.1"
3737
},
3838
"devDependencies": {
39-
"@types/jest": "^27.0.2",
40-
"@types/lodash": "^4.14.170",
39+
"@types/jest": "^28.1.7",
40+
"@types/lodash": "^4.14.184",
4141
"@types/minimatch": "^3.0.4",
42-
"@types/node": "^14.17.3",
43-
"@types/yargs": "^17.0.3",
44-
"@typescript-eslint/eslint-plugin": "^4.28.0",
45-
"@typescript-eslint/parser": "^4.28.0",
46-
"eslint": "^7.29.0",
47-
"eslint-plugin-jest": "^24.0.0",
48-
"ftp-srv": "^4.5.0",
49-
"jest": "^27.2.5",
50-
"js-yaml": "^3.14.0",
51-
"ts-jest": "^27.0.5",
52-
"ts-node-dev": "^1.1.8",
53-
"typescript": "^4.3.4"
42+
"@types/node": "^18.7.9",
43+
"@types/yargs": "^17.0.11",
44+
"@typescript-eslint/eslint-plugin": "^5.33.1",
45+
"@typescript-eslint/parser": "^5.33.1",
46+
"eslint": "^8.22.0",
47+
"eslint-plugin-jest": "^26.8.6",
48+
"ftp-srv": "^4.6.2",
49+
"jest": "^28.1.3",
50+
"js-yaml": "^4.1.0",
51+
"ts-jest": "^28.0.8",
52+
"ts-node-dev": "^2.0.0",
53+
"typescript": "^4.7.4"
5454
},
5555
"bugs": {
5656
"url": "https://github.com/SamKirkland/ftp-deploy/issues"

src/deploy.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -66,17 +66,19 @@ async function connect(client: ftp.Client, args: IFtpDeployArgumentsWithDefaults
6666
}
6767
}
6868

69-
async function getServerFiles(client: ftp.Client, logger: ILogger, timings: ITimings, args: IFtpDeployArgumentsWithDefaults): Promise<IFileList> {
69+
export async function getServerFiles(client: ftp.Client, logger: ILogger, timings: ITimings, args: IFtpDeployArgumentsWithDefaults): Promise<IFileList> {
7070
try {
7171
await ensureDir(client, logger, timings, args["server-dir"]);
7272

7373
if (args["dangerous-clean-slate"]) {
7474
logger.all(`----------------------------------------------------------------`);
7575
logger.all("🗑️ Removing all files on the server because 'dangerous-clean-slate' was set, this will make the deployment very slow...");
76-
await client.clearWorkingDir();
76+
if (args["dry-run"] === false) {
77+
await client.clearWorkingDir();
78+
}
7779
logger.all("Clear complete");
7880

79-
throw new Error("nope");
81+
throw new Error("dangerous-clean-slate was run");
8082
}
8183

8284
const serverFiles = await downloadFileList(client, logger, args["state-name"]);

src/main.test.ts

+87-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { HashDiff } from "./HashDiff";
2-
import { IFileList, currentSyncFileVersion, IFile, IFtpDeployArgumentsWithDefaults } from "./types";
2+
import { IFileList, currentSyncFileVersion, IFile, IFtpDeployArgumentsWithDefaults, DiffResult } from "./types";
33
import { Record } from "./types";
44
import { applyExcludeFilter, getDefaultSettings, ILogger, Timings } from "./utilities";
55
import path from "path";
66
import FtpSrv from "ftp-srv";
77
import { getLocalFiles } from "./localFiles";
88
import { FTPSyncProvider } from "./syncProvider";
9-
import { deploy } from "./deploy";
9+
import { deploy, getServerFiles } from "./deploy";
1010
import { Stats as readdirStats } from "@jsdevtools/readdir-enhanced";
1111
import { excludeDefaults } from "./module";
1212

@@ -787,6 +787,91 @@ describe("error handling", () => {
787787
}, 30000);
788788
});
789789

790+
describe("dry-run", () => {
791+
test("getServerFiles doesn't mutate server", async () => {
792+
const mockedLogger = new MockedLogger();
793+
const mockedTimings = new Timings();
794+
const mockClient = {
795+
clearWorkingDir() { },
796+
ensureDir() { },
797+
};
798+
const settings = getDefaultSettings({
799+
server: "a",
800+
username: "b",
801+
password: "c",
802+
"dry-run": true,
803+
"dangerous-clean-slate": true,
804+
});
805+
806+
const spyClearWorkingDir = jest.spyOn(mockClient, "clearWorkingDir");
807+
await getServerFiles(mockClient as any, mockedLogger, mockedTimings, settings);
808+
809+
expect(spyClearWorkingDir).toHaveBeenCalledTimes(0);
810+
});
811+
812+
test("doesn't mutate server", async () => {
813+
const mockedLogger = new MockedLogger();
814+
const mockedTimings = new Timings();
815+
const mockClient = {
816+
uploadFile() { },
817+
removeFile() { },
818+
uploadFrom() { },
819+
remove() { },
820+
};
821+
const mockedDiffs: DiffResult = {
822+
upload: [
823+
{
824+
type: "file",
825+
name: "path/upload.txt",
826+
size: 1000,
827+
hash: "hash2",
828+
}
829+
],
830+
delete: [
831+
{
832+
type: "file",
833+
name: "path/delete.txt",
834+
size: 1000,
835+
hash: "hash2",
836+
}
837+
],
838+
replace: [
839+
{
840+
type: "file",
841+
name: "path/replace.txt",
842+
size: 1000,
843+
hash: "hash2",
844+
}
845+
],
846+
same: [
847+
{
848+
type: "file",
849+
name: "path/same.txt",
850+
size: 1000,
851+
hash: "hash2",
852+
}
853+
],
854+
sizeUpload: 1000,
855+
sizeDelete: 1000,
856+
sizeReplace: 1000,
857+
};
858+
859+
// todo ensureDir
860+
861+
const syncProvider = new FTPSyncProvider(mockClient as any, mockedLogger, mockedTimings, "local-dir/", "server-dir/", "state-name", true);
862+
const spyUploadFile = jest.spyOn(mockClient, "uploadFile");
863+
const spyRemoveFile = jest.spyOn(mockClient, "removeFile");
864+
const spyUploadFrom = jest.spyOn(mockClient, "uploadFrom");
865+
const spyRemove = jest.spyOn(mockClient, "remove");
866+
await syncProvider.syncLocalToServer(mockedDiffs);
867+
868+
expect(spyUploadFile).toHaveBeenCalledTimes(0);
869+
expect(spyRemoveFile).toHaveBeenCalledTimes(0);
870+
expect(spyUploadFrom).toHaveBeenCalledTimes(0);
871+
expect(spyRemove).toHaveBeenCalledTimes(0);
872+
});
873+
});
874+
790875
describe("Deploy", () => {
791876
const port = 2121;
792877
const homeDir = path.join(__dirname, "../");

0 commit comments

Comments
 (0)