Skip to content

Commit 8346ca8

Browse files
committed
Update readme 📘
1 parent 6c5c114 commit 8346ca8

3 files changed

Lines changed: 92 additions & 12 deletions

File tree

README.md

Lines changed: 80 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,84 @@
1-
21
# Deploy system for PM2
32

4-
Documentation: [https://pm2.io/doc/en/runtime/guide/easy-deploy-with-ssh/](https://pm2.io/doc/en/runtime/guide/easy-deploy-with-ssh/)
3+
Documentation: <https://pm2.io/doc/en/runtime/guide/easy-deploy-with-ssh/>
54

65
[![build status](https://badgen.net/travis/Unitech/pm2/master)](https://travis-ci.org/Unitech/pm2-deploy) [![npm package version](https://badgen.net/npm/v/pm2-deploy)](https://npm.im/pm2-deploy) [![install size](https://badgen.net/packagephobia/install/pm2-deploy)](https://packagephobia.now.sh/result?p=pm2-deploy) [![github license](https://badgen.net/github/license/Unitech/pm2-deploy)](https://github.com/Unitech/pm2-deploy/blob/master/LICENSE) [![js semistandard style](https://badgen.net/badge/code%20style/semistandard/pink)](https://github.com/Flet/semistandard)
6+
7+
## Instalation
8+
9+
$ npm install pm2-deploy
10+
11+
## Usage
12+
13+
```js
14+
var deployForEnv = require('pm2-deploy').deployForEnv;
15+
16+
// Define deploy configuration with target environments
17+
var deployConfig = {
18+
prod: {
19+
user: 'node',
20+
host: '212.83.163.168',
21+
ref: 'origin/master',
22+
repo: 'git@github.com:Unitech/eip-vitrine.git',
23+
path: '/var/www/test-deploy'
24+
},
25+
dev: {
26+
user: 'node',
27+
host: '212.83.163.168',
28+
ref: 'origin/master',
29+
repo: 'git@github.com:Unitech/eip-vitrine.git',
30+
path: '/var/www/test-dev'
31+
}
32+
};
33+
34+
// Invoke deployment for `dev` environment
35+
deployForEnv(deployConfig, 'dev', [], function (err, args) {
36+
if (err) {
37+
console.error('Deploy failed:', err.message);
38+
return console.error(err.stack);
39+
}
40+
console.log('Success!');
41+
});
42+
43+
// Rollback `prod` environment
44+
deployForEnv(deployConfig, 'prod', ['revert', 1], function (err, args) {
45+
if (err) {
46+
console.error('Rollback failed:', err.message);
47+
return console.error(err.stack);
48+
}
49+
console.log('Success!');
50+
});
51+
```
52+
53+
## API
54+
55+
<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
56+
57+
#### Table of Contents
58+
59+
- [deployForEnv](#deployforenv)
60+
- [Parameters](#parameters)
61+
- [DeployCallback](#deploycallback)
62+
- [Parameters](#parameters-1)
63+
64+
### deployForEnv
65+
66+
Deploy to a single environment
67+
68+
#### Parameters
69+
70+
- `deployConfig` **[object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** object containing deploy configs for all environments
71+
- `env` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** the name of the environment to deploy to
72+
- `args` **[array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)** custom deploy command-line arguments
73+
- `cb` **[DeployCallback](#deploycallback)** done callback
74+
75+
Returns **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** return value is always `false`
76+
77+
### DeployCallback
78+
79+
Type: [Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)
80+
81+
#### Parameters
82+
83+
- `error` **[Error](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error)** deployment error
84+
- `args` **[array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)** custom command-line arguments provided to deploy

deploy.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,11 @@ var schema = {
3333
required: ['host', 'repo', 'path', 'ref'],
3434
};
3535

36-
/**
37-
* @callback DeployCallback
38-
* @param {Error} error deployment error
39-
* @param {array} args custom command-line arguments provided to deploy
40-
*/
41-
4236
/**
4337
* Spawn a modified version of visionmedia/deploy
4438
* @private
4539
* @param {object} config config to be piped to deploy
46-
* @param {array} [args] custom deploy command-line arguments
40+
* @param {array} args custom deploy command-line arguments
4741
* @param {DeployCallback} cb done callback
4842
*/
4943
function spawn(config, args, cb) {
@@ -84,9 +78,9 @@ function castArray(arg) {
8478
* Deploy to a single environment
8579
* @param {object} deployConfig object containing deploy configs for all environments
8680
* @param {string} env the name of the environment to deploy to
87-
* @param {array} [args] custom deploy command-line arguments
81+
* @param {array} args custom deploy command-line arguments
8882
* @param {DeployCallback} cb done callback
89-
* @returns {boolean} always returns false
83+
* @returns {boolean} return value is always `false`
9084
*/
9185
function deployForEnv(deployConfig, env, args, cb) {
9286
if (!deployConfig[env]) {
@@ -160,3 +154,9 @@ function prependEnv(cmd, env) {
160154
module.exports = {
161155
deployForEnv: deployForEnv,
162156
};
157+
158+
/**
159+
* @callback DeployCallback
160+
* @param {Error} error deployment error
161+
* @param {array} args custom command-line arguments provided to deploy
162+
*/

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,16 @@
1616
},
1717
"scripts": {
1818
"lint": "eslint \"**/*.js\"",
19-
"test": "mocha"
19+
"test": "mocha",
20+
"docs": "documentation readme ./deploy.js --section=API"
2021
},
2122
"dependencies": {
2223
"run-series": "^1.1.8",
2324
"tv4": "^1.3.0"
2425
},
2526
"devDependencies": {
2627
"better-assert": "^1.0.2",
28+
"documentation": "^11.0.0",
2729
"eslint": "^5.16.0",
2830
"eslint-config-semistandard": "^13.0.0",
2931
"eslint-config-standard": "^12.0.0",

0 commit comments

Comments
 (0)