sftp-zip-deploy 0.0.0-stage → 0.0.2

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 CHANGED
@@ -1,3 +1,2 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
1
+ # sftp-zip-deploy
2
+ Fast zip-deployment over SFTP
@@ -0,0 +1,59 @@
1
+ import { ConnectOptions } from 'ssh2-sftp-client';
2
+ export interface IZipDetails {
3
+ /**
4
+ * All files placed into zip.
5
+ */
6
+ files: string[];
7
+ /**
8
+ * Local path to the zip file.
9
+ */
10
+ zipLocalPath: string;
11
+ /**
12
+ * Remote path to the zip file.
13
+ */
14
+ zipRemotePath: string;
15
+ /**
16
+ * Zip file size, in bytes.
17
+ */
18
+ zipSize: number;
19
+ }
20
+ export interface ISftpZipDeployConfig {
21
+ /**
22
+ * Connection parameters.
23
+ */
24
+ cn: ConnectOptions;
25
+ /**
26
+ * Source directory.
27
+ */
28
+ srcDir: string;
29
+ /**
30
+ * Destination directory.
31
+ */
32
+ destDir: string;
33
+ /**
34
+ * Optional path for the zip file.
35
+ */
36
+ zipPath?: string;
37
+ /**
38
+ * Optional remote commands to run before or after zip file has been copied over.
39
+ */
40
+ commands?: {
41
+ before?: string | string[];
42
+ after?: string | string[];
43
+ };
44
+ /**
45
+ * Optional filter on file enumeration, returning:
46
+ * - true for files to be added;
47
+ * - false for files to be skipped.
48
+ */
49
+ onFilter?: (file: string) => boolean;
50
+ /**
51
+ * Notification when zip file has been built,
52
+ * and we are ready to start its transfer.
53
+ */
54
+ onZipReady?: (zd: IZipDetails) => void;
55
+ /**
56
+ * Notification of every output produced by a remote command.
57
+ */
58
+ onCmdOutput?: (cmd: string, err?: Buffer, std?: Buffer) => void;
59
+ }
package/dist/config.js ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,3 @@
1
+ import { ISftpZipDeployConfig } from './config';
2
+ export { default as ConnectOptions } from 'ssh2-sftp-client';
3
+ export declare function zipAndDeploy(cfg: ISftpZipDeployConfig): Promise<boolean>;
package/dist/index.js ADDED
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.ConnectOptions = void 0;
7
+ exports.zipAndDeploy = zipAndDeploy;
8
+ const ssh2_sftp_client_1 = __importDefault(require("ssh2-sftp-client"));
9
+ const ssh2_1 = require("ssh2");
10
+ const utils_1 = require("./utils");
11
+ const node_zlib_1 = require("node:zlib");
12
+ const node_fs_1 = require("node:fs");
13
+ const glob_1 = require("glob");
14
+ const promises_1 = require("node:fs/promises");
15
+ const promises_2 = require("node:stream/promises");
16
+ var ssh2_sftp_client_2 = require("ssh2-sftp-client");
17
+ Object.defineProperty(exports, "ConnectOptions", { enumerable: true, get: function () { return __importDefault(ssh2_sftp_client_2).default; } });
18
+ async function zipAndDeploy(cfg) {
19
+ const ac = cfg.commands?.after ?? [];
20
+ const afterCommands = (Array.isArray(ac) ? ac : [ac]);
21
+ const bc = cfg.commands?.before ?? [];
22
+ const beforeCommands = (Array.isArray(bc) ? bc : [bc]);
23
+ const ssh2Client = new ssh2_1.Client();
24
+ if (ac.length > 0 || bc.length > 0) {
25
+ await (0, utils_1.connectSSH2Client)(ssh2Client, cfg.cn);
26
+ for (const c of beforeCommands) {
27
+ await (0, utils_1.execSHH2Command)(ssh2Client, c, (err, std) => {
28
+ if (typeof cfg.onCmdOutput === 'function') {
29
+ cfg.onCmdOutput(c, err, std);
30
+ }
31
+ });
32
+ }
33
+ }
34
+ let allFiles = (0, glob_1.globSync)('**/{*.*,.*}', { cwd: cfg.srcDir })
35
+ .map(f => f.replace(/\\/g, '/'));
36
+ if (typeof cfg.onFilter === 'function') {
37
+ allFiles = allFiles.filter(cfg.onFilter);
38
+ }
39
+ if (allFiles.length === 0) {
40
+ return false; // nothing to deploy
41
+ }
42
+ const entries = [];
43
+ for (const src of allFiles) {
44
+ entries.push(await node_zlib_1.ZipEntry.create(src, await (0, promises_1.readFile)(src)));
45
+ }
46
+ const archive = (0, node_zlib_1.createZipArchive)(entries);
47
+ const ws = (0, node_fs_1.createWriteStream)('release.zip');
48
+ await (0, promises_2.pipeline)(archive, ws);
49
+ const sftp = new ssh2_sftp_client_1.default();
50
+ await sftp.connect(cfg.cn);
51
+ const p = `${cfg.destDir}/release.zip`;
52
+ await sftp.put('release.zip', p);
53
+ await sftp.end();
54
+ for (const c of afterCommands) {
55
+ await (0, utils_1.execSHH2Command)(ssh2Client, c, (err, std) => {
56
+ if (typeof cfg.onCmdOutput === 'function') {
57
+ cfg.onCmdOutput(c, err, std);
58
+ }
59
+ });
60
+ }
61
+ ssh2Client.end();
62
+ return true;
63
+ }
@@ -0,0 +1,3 @@
1
+ import { Client as SSH2Client, ConnectConfig } from 'ssh2';
2
+ export declare function connectSSH2Client(client: SSH2Client, cn: ConnectConfig): Promise<SSH2Client>;
3
+ export declare function execSHH2Command(client: SSH2Client, cmd: string, output: (err?: Buffer, std?: Buffer) => void): Promise<void>;
package/dist/utils.js ADDED
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.connectSSH2Client = connectSSH2Client;
4
+ exports.execSHH2Command = execSHH2Command;
5
+ function connectSSH2Client(client, cn) {
6
+ return new Promise((resolve, reject) => {
7
+ client.once('ready', () => resolve(client));
8
+ client.once('error', err => reject(err));
9
+ client.connect(cn);
10
+ });
11
+ }
12
+ function execSHH2Command(client, cmd, output) {
13
+ return new Promise((resolve, reject) => {
14
+ client.exec(cmd, (err, stream) => {
15
+ if (err) {
16
+ reject(err);
17
+ return;
18
+ }
19
+ stream.once('close', () => resolve());
20
+ stream.on('data', (chunk) => output(undefined, chunk));
21
+ stream.stderr.on('data', (chunk) => output(chunk, undefined));
22
+ });
23
+ });
24
+ }
package/package.json CHANGED
@@ -1,6 +1,35 @@
1
- {
2
- "name": "sftp-zip-deploy",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
1
+ {
2
+ "name": "sftp-zip-deploy",
3
+ "version": "0.0.2",
4
+ "description": "",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "scripts": {
8
+ "build": "tsc -p src",
9
+ "start": "tsc && node ./src/index.js"
10
+ },
11
+ "files": [
12
+ "dist"
13
+ ],
14
+ "homepage": "https://github.com/vitaly-t/sftp-zip-deploy",
15
+ "license": "MIT",
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "https://github.com/vitaly-t/sftp-zip-deploy.git"
19
+ },
20
+ "author": {
21
+ "name": "Vitaly Tomilov"
22
+ },
23
+ "engines": {
24
+ "node": ">=26"
25
+ },
26
+ "dependencies": {
27
+ "glob": "14.0.6",
28
+ "ssh2-sftp-client": "12.1.1"
29
+ },
30
+ "devDependencies": {
31
+ "@types/node": "26.6.6",
32
+ "@types/ssh2-sftp-client": "9.0.6",
33
+ "typescript": "6.0.3"
34
+ }
35
+ }