sftp-zip-deploy 0.0.6 → 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/dist/index.js +3 -3
- package/dist/utils.d.ts +1 -1
- package/dist/utils.js +9 -3
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -5,12 +5,12 @@
|
|
|
5
5
|
Simple and efficient way to auto-deploy your project to a server:
|
|
6
6
|
|
|
7
7
|
- It zips your distribution folder and sends the archive to your server via SFTP
|
|
8
|
-
- It optionally runs remote commands, before / after zip deployment, via
|
|
8
|
+
- It optionally runs remote commands, before / after zip deployment, via SSH2
|
|
9
9
|
- It provides detailed data about what is going on all the way
|
|
10
10
|
|
|
11
11
|
**IMPORTANT:**
|
|
12
12
|
|
|
13
|
-
This library relies on Node-native support for
|
|
13
|
+
This library relies on Node-native support for SSH2 and ZIP, and therefore requires Node v26 as minimum.
|
|
14
14
|
|
|
15
15
|
## Install
|
|
16
16
|
|
|
@@ -53,7 +53,7 @@ So avoid running commands that may trigger an input prompt.
|
|
|
53
53
|
|
|
54
54
|
## API
|
|
55
55
|
|
|
56
|
-
The library shares connection options for SFTP /
|
|
56
|
+
The library shares connection options for SFTP / SSH2, and reuses the standard `ConnectOptions` / `ConnectConfig`
|
|
57
57
|
types from the underlying modules.
|
|
58
58
|
|
|
59
59
|
The main interface [ISftpZipDeployConfig] has a number of options, including events for providing progress details:
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import SftpClient from 'ssh2-sftp-client';
|
|
2
2
|
import { Client as SSH2Client } from 'ssh2';
|
|
3
|
-
import { connectSSH2Client,
|
|
3
|
+
import { connectSSH2Client, execSSH2Command, fixWindowsPath, zipFiles } from './utils.js';
|
|
4
4
|
import { globSync } from 'glob';
|
|
5
5
|
import path from 'node:path';
|
|
6
6
|
export { default as ConnectOptions } from 'ssh2-sftp-client';
|
|
@@ -20,7 +20,7 @@ export async function zipAndDeploy(cfg) {
|
|
|
20
20
|
const { before = '', after = '' } = cfg.cmd ?? {};
|
|
21
21
|
if (before || after) {
|
|
22
22
|
await connectSSH2Client(ssh2Client, cfg.cn);
|
|
23
|
-
await
|
|
23
|
+
await execSSH2Command(ssh2Client, before, (err, std) => cfg.onCmdOutput?.(before, err, std));
|
|
24
24
|
}
|
|
25
25
|
let files = globSync('**/{*.*,.*}', { cwd: cfg.srcDir })
|
|
26
26
|
.map(f => fixWindowsPath(f));
|
|
@@ -37,7 +37,7 @@ export async function zipAndDeploy(cfg) {
|
|
|
37
37
|
await sftp.connect(cfg.cn);
|
|
38
38
|
await sftp.put(zipLocalPath, zipRemotePath);
|
|
39
39
|
if (after) {
|
|
40
|
-
await
|
|
40
|
+
await execSSH2Command(ssh2Client, after, (err, std) => cfg.onCmdOutput?.(after, err, std));
|
|
41
41
|
}
|
|
42
42
|
await sftp.end();
|
|
43
43
|
ssh2Client.end();
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Client as SSH2Client, ConnectConfig } from 'ssh2';
|
|
2
2
|
export declare function connectSSH2Client(client: SSH2Client, cn: ConnectConfig): Promise<SSH2Client>;
|
|
3
|
-
export declare function
|
|
3
|
+
export declare function execSSH2Command(client: SSH2Client, cmd: string, output: (err?: Buffer, std?: Buffer) => void): Promise<void>;
|
|
4
4
|
/**
|
|
5
5
|
* Zips list of files, and resolves with the size of the resulting archive (in bytes).
|
|
6
6
|
*/
|
package/dist/utils.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createZipArchive, ZipEntry } from 'node:zlib';
|
|
1
|
+
import { createZipArchive, ZipEntry, createGzip, constants } from 'node:zlib';
|
|
2
2
|
import { readFile } from 'node:fs/promises';
|
|
3
3
|
import { createWriteStream } from 'node:fs';
|
|
4
4
|
import { pipeline } from 'node:stream/promises';
|
|
@@ -10,7 +10,7 @@ export function connectSSH2Client(client, cn) {
|
|
|
10
10
|
client.connect(cn);
|
|
11
11
|
});
|
|
12
12
|
}
|
|
13
|
-
export function
|
|
13
|
+
export function execSSH2Command(client, cmd, output) {
|
|
14
14
|
return new Promise((resolve, reject) => {
|
|
15
15
|
client.exec(cmd, (err, stream) => {
|
|
16
16
|
if (err) {
|
|
@@ -33,7 +33,13 @@ export async function zipFiles(dir, files, zipPath) {
|
|
|
33
33
|
}
|
|
34
34
|
const archive = createZipArchive(entries);
|
|
35
35
|
const ws = createWriteStream(zipPath);
|
|
36
|
-
|
|
36
|
+
const maxCompressionOptions = {
|
|
37
|
+
level: constants.Z_BEST_COMPRESSION, // 9 (default is 6)
|
|
38
|
+
windowBits: 15, // Max 32KB history window (default is 15)
|
|
39
|
+
memLevel: 9, // Max internal hash table memory (default is 8)
|
|
40
|
+
strategy: constants.Z_DEFAULT_STRATEGY,
|
|
41
|
+
};
|
|
42
|
+
await pipeline(archive, createGzip(maxCompressionOptions), ws);
|
|
37
43
|
return ws.bytesWritten;
|
|
38
44
|
}
|
|
39
45
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sftp-zip-deploy",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.8",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
},
|
|
23
23
|
"keywords": [
|
|
24
24
|
"sftp",
|
|
25
|
-
"
|
|
25
|
+
"ssh2",
|
|
26
26
|
"zip",
|
|
27
27
|
"deploy"
|
|
28
28
|
],
|