sftp-zip-deploy 0.2.3 → 0.2.5
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 +0 -3
- package/dist/config.d.ts +1 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.js +32 -27
- package/dist/utils.d.ts +4 -1
- package/dist/utils.js +4 -3
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -54,9 +54,6 @@ So avoid running commands that may trigger an input prompt.
|
|
|
54
54
|
|
|
55
55
|
## API
|
|
56
56
|
|
|
57
|
-
The library shares connection options for SFTP / SSH2, and reuses `ConnectOptions` from `ssh2-sftp-client` module.
|
|
58
|
-
To use that type explicitly, you will need to add `@types/ssh2-sftp-client` as a DEV dependency.
|
|
59
|
-
|
|
60
57
|
The main interface [ISftpZipDeployConfig] has a number of options, including events for providing progress details:
|
|
61
58
|
|
|
62
59
|
* [onZipReady] - notifies when zip is ready
|
package/dist/config.d.ts
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ISftpZipDeployConfig } from './config.js';
|
|
2
2
|
export { IZipDetails, ISftpZipDeployConfig } from './config.js';
|
|
3
|
-
export {
|
|
3
|
+
export type { ConnectOptions } from 'ssh2-sftp-client';
|
|
4
4
|
/**
|
|
5
5
|
* From the configuration object, it implements the following steps:
|
|
6
6
|
*
|
package/dist/index.js
CHANGED
|
@@ -3,7 +3,6 @@ import { Client as SSH2Client } from 'ssh2';
|
|
|
3
3
|
import { connectSSH2Client, execSSH2Command, fixWindowsPath, zipFiles } from './utils.js';
|
|
4
4
|
import { glob } from 'glob';
|
|
5
5
|
import path from 'node:path';
|
|
6
|
-
export { default as ConnectOptions } from 'ssh2-sftp-client';
|
|
7
6
|
/**
|
|
8
7
|
* From the configuration object, it implements the following steps:
|
|
9
8
|
*
|
|
@@ -16,34 +15,40 @@ export { default as ConnectOptions } from 'ssh2-sftp-client';
|
|
|
16
15
|
* or `false` otherwise (i.e. it does not create an empty zip)
|
|
17
16
|
*/
|
|
18
17
|
export async function zipAndDeploy(cfg) {
|
|
19
|
-
const
|
|
18
|
+
const sftp = new SftpClient();
|
|
19
|
+
const ssh2 = new SSH2Client();
|
|
20
20
|
const { before = '', after = '' } = cfg.cmd ?? {};
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
21
|
+
let hasFiles = false;
|
|
22
|
+
try {
|
|
23
|
+
if (before || after) {
|
|
24
|
+
await connectSSH2Client(ssh2, cfg.cn);
|
|
25
|
+
}
|
|
26
|
+
if (before) {
|
|
27
|
+
await execSSH2Command(ssh2, before, (err, std) => cfg.onCmdOutput?.(before, err, std));
|
|
28
|
+
}
|
|
29
|
+
let files = await glob('**/{*.*,*}', { cwd: cfg.srcDir, nodir: true, dot: true })
|
|
30
|
+
.then(a => a.map(f => fixWindowsPath(f)));
|
|
31
|
+
if (typeof cfg.onFilter === 'function') {
|
|
32
|
+
files = files.filter(cfg.onFilter);
|
|
33
|
+
}
|
|
34
|
+
hasFiles = files.length > 0;
|
|
35
|
+
if (hasFiles) {
|
|
36
|
+
const zipFileDir = cfg.zipFile?.dir ?? './';
|
|
37
|
+
const zipFileName = cfg.zipFile?.name ?? 'release.zip';
|
|
38
|
+
const zipLocalPath = fixWindowsPath(path.join(zipFileDir, zipFileName));
|
|
39
|
+
const zipRemotePath = fixWindowsPath(path.join(cfg.destDir, zipFileName));
|
|
40
|
+
const zipSize = await zipFiles(cfg.srcDir, files, { dir: zipFileDir, name: zipFileName });
|
|
41
|
+
cfg.onZipReady?.({ files, zipLocalPath, zipRemotePath, zipSize });
|
|
42
|
+
await sftp.connect(cfg.cn);
|
|
43
|
+
await sftp.put(zipLocalPath, zipRemotePath);
|
|
44
|
+
if (after) {
|
|
45
|
+
await execSSH2Command(ssh2, after, (err, std) => cfg.onCmdOutput?.(after, err, std));
|
|
46
|
+
}
|
|
47
|
+
}
|
|
31
48
|
}
|
|
32
|
-
|
|
33
|
-
const zipFileDir = cfg.zipFile?.dir ?? './';
|
|
34
|
-
const zipFileName = cfg.zipFile?.name ?? 'release.zip';
|
|
35
|
-
const zipLocalPath = fixWindowsPath(path.join(zipFileDir, zipFileName));
|
|
36
|
-
const zipRemotePath = fixWindowsPath(path.join(cfg.destDir, zipFileName));
|
|
37
|
-
const zipSize = await zipFiles(cfg.srcDir, files, zipLocalPath);
|
|
38
|
-
cfg.onZipReady?.({ files, zipLocalPath, zipRemotePath, zipSize });
|
|
39
|
-
const sftp = new SftpClient();
|
|
40
|
-
await sftp.connect(cfg.cn);
|
|
41
|
-
await sftp.put(zipLocalPath, zipRemotePath);
|
|
49
|
+
finally {
|
|
42
50
|
await sftp.end();
|
|
43
|
-
|
|
44
|
-
await execSSH2Command(ssh2Client, after, (err, std) => cfg.onCmdOutput?.(after, err, std));
|
|
45
|
-
}
|
|
51
|
+
ssh2.end();
|
|
46
52
|
}
|
|
47
|
-
|
|
48
|
-
return files.length > 0;
|
|
53
|
+
return hasFiles;
|
|
49
54
|
}
|
package/dist/utils.d.ts
CHANGED
|
@@ -5,7 +5,10 @@ export declare function execSSH2Command(client: SSH2Client, cmd: string, output:
|
|
|
5
5
|
/**
|
|
6
6
|
* Zips list of files, and resolves with the size of the resulting archive (in bytes).
|
|
7
7
|
*/
|
|
8
|
-
export declare function zipFiles(dir: string, files: string[],
|
|
8
|
+
export declare function zipFiles(dir: string, files: string[], zip: {
|
|
9
|
+
dir: string;
|
|
10
|
+
name: string;
|
|
11
|
+
}): Promise<number>;
|
|
9
12
|
/**
|
|
10
13
|
* Fixes Windows paths, by replacing every '\' with '/'
|
|
11
14
|
*/
|
package/dist/utils.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createZipArchive, ZipEntry } from 'node:zlib';
|
|
2
|
-
import { readFile } from 'node:fs/promises';
|
|
2
|
+
import { readFile, mkdir, access } from 'node:fs/promises';
|
|
3
3
|
import { createWriteStream } from 'node:fs';
|
|
4
4
|
import { pipeline } from 'node:stream/promises';
|
|
5
5
|
import path from 'node:path';
|
|
@@ -38,14 +38,15 @@ export function execSSH2Command(client, cmd, output) {
|
|
|
38
38
|
/**
|
|
39
39
|
* Zips list of files, and resolves with the size of the resulting archive (in bytes).
|
|
40
40
|
*/
|
|
41
|
-
export async function zipFiles(dir, files,
|
|
41
|
+
export async function zipFiles(dir, files, zip) {
|
|
42
42
|
const entries = [];
|
|
43
43
|
for (const f of files) {
|
|
44
44
|
const p = path.join(dir, f);
|
|
45
45
|
entries.push(await ZipEntry.create(f, await readFile(p)));
|
|
46
46
|
}
|
|
47
47
|
const archive = createZipArchive(entries);
|
|
48
|
-
|
|
48
|
+
await access(zip.dir).catch(() => mkdir(zip.dir, { recursive: true }));
|
|
49
|
+
const ws = createWriteStream(path.join(zip.dir, zip.name));
|
|
49
50
|
await pipeline(archive, ws);
|
|
50
51
|
return ws.bytesWritten;
|
|
51
52
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sftp-zip-deploy",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.5",
|
|
4
4
|
"description": "Zip and deploy folder over SFTP",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -32,12 +32,12 @@
|
|
|
32
32
|
"node": ">=26"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
+
"@types/node": "26.6.6",
|
|
36
|
+
"@types/ssh2-sftp-client": "9.0.6",
|
|
35
37
|
"glob": "14.0.6",
|
|
36
38
|
"ssh2-sftp-client": "12.1.1"
|
|
37
39
|
},
|
|
38
40
|
"devDependencies": {
|
|
39
|
-
"@types/node": "26.6.6",
|
|
40
|
-
"@types/ssh2-sftp-client": "9.0.6",
|
|
41
41
|
"typescript": "7.0.2"
|
|
42
42
|
}
|
|
43
43
|
}
|