sftp-zip-deploy 0.0.3 → 0.0.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 +23 -4
- package/dist/config.d.ts +45 -21
- package/dist/index.d.ts +11 -0
- package/dist/index.js +11 -0
- package/package.json +8 -3
package/README.md
CHANGED
|
@@ -9,6 +9,7 @@ Simple and efficient way to auto-deploy your project to a server:
|
|
|
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 SHH2 and ZIP, and therefore requires Node v26 as minimum.
|
|
13
14
|
|
|
14
15
|
## Install
|
|
@@ -19,10 +20,10 @@ npm i sftp-zip-deploy
|
|
|
19
20
|
|
|
20
21
|
## Usage
|
|
21
22
|
|
|
22
|
-
In the example below we deploy a NodeJS project into `/root/web` on our remote server.
|
|
23
|
+
In the example below, we deploy a NodeJS project into `/root/web` on our remote server.
|
|
23
24
|
|
|
24
|
-
Once zip file is deployed, we run commands to set that folder as active, unpack
|
|
25
|
-
the archive
|
|
25
|
+
Once zip file is deployed, we run commands to set that folder as active, then unpack
|
|
26
|
+
the archive and install project's dependencies.
|
|
26
27
|
|
|
27
28
|
```ts
|
|
28
29
|
import {zipAndDeploy} from 'sftp-zip-deploy';
|
|
@@ -31,7 +32,8 @@ await zipAndDeploy({
|
|
|
31
32
|
srcDir: './dist', // folder with content to deploy
|
|
32
33
|
destDir: '/root/web/', // remote folder to copy our zip file
|
|
33
34
|
zipFile: {
|
|
34
|
-
name: 'release.zip' // set custom name for the archive
|
|
35
|
+
name: 'release.zip', // set custom name for the archive
|
|
36
|
+
dir: './' // we can change where zip is created
|
|
35
37
|
},
|
|
36
38
|
cn: {
|
|
37
39
|
host: '1.2.3.4',
|
|
@@ -48,3 +50,20 @@ await zipAndDeploy({
|
|
|
48
50
|
Note that we use option `-o` (overwrite) with `unzip`, because otherwise the command may prompt for input,
|
|
49
51
|
if files are already there, and this library does not deal with remote prompts, it will just get stuck.
|
|
50
52
|
So avoid running commands that may trigger an input prompt.
|
|
53
|
+
|
|
54
|
+
## API
|
|
55
|
+
|
|
56
|
+
The library shares connection options for SFTP / SHH2, and reuses the standard `ConnectOptions` / `ConnectConfig`
|
|
57
|
+
types from the underlying modules.
|
|
58
|
+
|
|
59
|
+
The main interface [ISftpZipDeployConfig] has a number of options, including events for providing progress details:
|
|
60
|
+
|
|
61
|
+
* [onZipReady] - notifies when zip is ready
|
|
62
|
+
* [onFilter] - to let you filter files inside distribution folder
|
|
63
|
+
* [onCmdOutput] - to get all output from remote commands
|
|
64
|
+
|
|
65
|
+
[onZipReady]:https://github.com/vitaly-t/sftp-zip-deploy/blob/main/src/config.ts#L67
|
|
66
|
+
[onFilter]:https://github.com/vitaly-t/sftp-zip-deploy/blob/main/src/config.ts#L61
|
|
67
|
+
[onCmdOutput]:https://github.com/vitaly-t/sftp-zip-deploy/blob/main/src/config.ts#L81
|
|
68
|
+
|
|
69
|
+
[ISftpZipDeployConfig]:https://github.com/vitaly-t/sftp-zip-deploy/blob/main/src/config.ts#L6
|
package/dist/config.d.ts
CHANGED
|
@@ -1,22 +1,7 @@
|
|
|
1
1
|
import { ConnectOptions } from 'ssh2-sftp-client';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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
|
-
}
|
|
2
|
+
/**
|
|
3
|
+
* Configuration structure, to be passed into `zipAndDeploy`.
|
|
4
|
+
*/
|
|
20
5
|
export interface ISftpZipDeployConfig {
|
|
21
6
|
/**
|
|
22
7
|
* Connection parameters.
|
|
@@ -39,22 +24,31 @@ export interface ISftpZipDeployConfig {
|
|
|
39
24
|
zipFile?: {
|
|
40
25
|
/**
|
|
41
26
|
* Local directory where zip file is to be created.
|
|
27
|
+
* Default is './'
|
|
42
28
|
*/
|
|
43
29
|
dir?: string;
|
|
44
30
|
/**
|
|
45
|
-
* Name for the local zip file.
|
|
31
|
+
* Name for the local zip file. Default is 'release.zip'
|
|
46
32
|
*/
|
|
47
33
|
name?: string;
|
|
48
34
|
};
|
|
49
35
|
/**
|
|
50
|
-
* Optional
|
|
36
|
+
* Optional commands to execute before / after deploying zip file.
|
|
51
37
|
*/
|
|
52
38
|
cmd?: {
|
|
39
|
+
/**
|
|
40
|
+
* Command(s) to be executed before creating zip file.
|
|
41
|
+
*/
|
|
53
42
|
before?: string;
|
|
43
|
+
/**
|
|
44
|
+
* Command(s) to be executed after zip has been deployed.
|
|
45
|
+
*/
|
|
54
46
|
after?: string;
|
|
55
47
|
};
|
|
56
48
|
/**
|
|
57
|
-
* Optional filter on file enumeration,
|
|
49
|
+
* Optional filter on file enumeration (found in `srcDir`),
|
|
50
|
+
* returning:
|
|
51
|
+
*
|
|
58
52
|
* - true for files to be added;
|
|
59
53
|
* - false for files to be skipped.
|
|
60
54
|
*/
|
|
@@ -66,6 +60,36 @@ export interface ISftpZipDeployConfig {
|
|
|
66
60
|
onZipReady?: (zd: IZipDetails) => void;
|
|
67
61
|
/**
|
|
68
62
|
* Notification of every output produced by a remote command.
|
|
63
|
+
*
|
|
64
|
+
* @param cmd
|
|
65
|
+
* Command that produced an output.
|
|
66
|
+
*
|
|
67
|
+
* @param err
|
|
68
|
+
* Set when the output was sent into StdErr, i.e. an error is reported.
|
|
69
|
+
*
|
|
70
|
+
* @param std
|
|
71
|
+
* Set when normal/standard output is generated (not an error).
|
|
69
72
|
*/
|
|
70
73
|
onCmdOutput?: (cmd: string, err?: Buffer, std?: Buffer) => void;
|
|
71
74
|
}
|
|
75
|
+
/**
|
|
76
|
+
* For use with onZipReady event.
|
|
77
|
+
*/
|
|
78
|
+
export interface IZipDetails {
|
|
79
|
+
/**
|
|
80
|
+
* All files placed into zip.
|
|
81
|
+
*/
|
|
82
|
+
files: string[];
|
|
83
|
+
/**
|
|
84
|
+
* Local path to the zip file.
|
|
85
|
+
*/
|
|
86
|
+
zipLocalPath: string;
|
|
87
|
+
/**
|
|
88
|
+
* Remote path to the zip file.
|
|
89
|
+
*/
|
|
90
|
+
zipRemotePath: string;
|
|
91
|
+
/**
|
|
92
|
+
* Zip file size, in bytes.
|
|
93
|
+
*/
|
|
94
|
+
zipSize: number;
|
|
95
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,15 @@
|
|
|
1
1
|
import { ISftpZipDeployConfig } from './config.js';
|
|
2
2
|
export { IZipDetails, ISftpZipDeployConfig } from './config.js';
|
|
3
3
|
export { ConnectOptions } from 'ssh2-sftp-client';
|
|
4
|
+
/**
|
|
5
|
+
* From the configuration object, it implements the following steps:
|
|
6
|
+
*
|
|
7
|
+
* 1. Executes `cmd.before` commands, if such were specified
|
|
8
|
+
* 2. Enumerates all files inside `srcDir`, plus filters them via `onFilter` (if used)
|
|
9
|
+
* 3. Produces zip file with all the resulting files and triggers `onZipReady` (if used)
|
|
10
|
+
* 4. Uploads zip file to the remote machine
|
|
11
|
+
* 5. Executes `cmd.after` commands, if such were specified
|
|
12
|
+
* 6. Resolves with `true`, if at least one file was found and zip was created,
|
|
13
|
+
* or `false` otherwise (i.e. it does not create an empty zip)
|
|
14
|
+
*/
|
|
4
15
|
export declare function zipAndDeploy(cfg: ISftpZipDeployConfig): Promise<boolean>;
|
package/dist/index.js
CHANGED
|
@@ -3,6 +3,17 @@ import { Client as SSH2Client } from 'ssh2';
|
|
|
3
3
|
import { connectSSH2Client, execSHH2Command, fixWindowsPath, zipFiles } from './utils.js';
|
|
4
4
|
import { globSync } from 'glob';
|
|
5
5
|
import path from 'node:path';
|
|
6
|
+
/**
|
|
7
|
+
* From the configuration object, it implements the following steps:
|
|
8
|
+
*
|
|
9
|
+
* 1. Executes `cmd.before` commands, if such were specified
|
|
10
|
+
* 2. Enumerates all files inside `srcDir`, plus filters them via `onFilter` (if used)
|
|
11
|
+
* 3. Produces zip file with all the resulting files and triggers `onZipReady` (if used)
|
|
12
|
+
* 4. Uploads zip file to the remote machine
|
|
13
|
+
* 5. Executes `cmd.after` commands, if such were specified
|
|
14
|
+
* 6. Resolves with `true`, if at least one file was found and zip was created,
|
|
15
|
+
* or `false` otherwise (i.e. it does not create an empty zip)
|
|
16
|
+
*/
|
|
6
17
|
export async function zipAndDeploy(cfg) {
|
|
7
18
|
const ssh2Client = new SSH2Client();
|
|
8
19
|
const { before = '', after = '' } = cfg.cmd ?? {};
|
package/package.json
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sftp-zip-deploy",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.5",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"scripts": {
|
|
9
|
-
"build": "tsc -p src"
|
|
10
|
-
"start": "tsc -p src && node --no-warnings=ExperimentalWarning=9820 ./dist/index.js"
|
|
9
|
+
"build": "tsc -p src"
|
|
11
10
|
},
|
|
12
11
|
"files": [
|
|
13
12
|
"dist"
|
|
@@ -21,6 +20,12 @@
|
|
|
21
20
|
"author": {
|
|
22
21
|
"name": "Vitaly Tomilov"
|
|
23
22
|
},
|
|
23
|
+
"keywords": [
|
|
24
|
+
"sftp",
|
|
25
|
+
"shh2",
|
|
26
|
+
"zip",
|
|
27
|
+
"deploy"
|
|
28
|
+
],
|
|
24
29
|
"engines": {
|
|
25
30
|
"node": ">=26"
|
|
26
31
|
},
|