远程执行命令 Flightplan
- 授权协议: MIT
- 开发语言: JavaScript
- 操作系统: 跨平台
- 软件首页: https://github.com/pstadler/flightplan
- 软件文档: https://github.com/pstadler/flightplan
软件介绍
Flightplan 可以在本地或者远程主机上运行一序列的命令。这是一个 Node.js 库,用于执行应用发布和系统管理任务,类似 Python 的 Fabric。
示例代码:
// flightplan.js
var Flightplan = require('flightplan');
var tmpDir = 'pstadler-sh-' + new Date().getTime();
// configuration
plan.briefing({
debug: false,
destinations: {
'staging': {
host: 'staging.pstadler.sh',
username: 'pstadler',
agent: process.env.SSH_AUTH_SOCK
},
'production': [
{
host: 'www1.pstadler.sh',
username: 'pstadler',
agent: process.env.SSH_AUTH_SOCK
},
{
host: 'www2.pstadler.sh',
username: 'pstadler',
agent: process.env.SSH_AUTH_SOCK
}
]
}
});
// run commands on localhost
plan.domestic(function(local) {
local.log('Run build');
local.exec('gulp build');
local.log('Copy files to remote host');
var filesToCopy = '(git ls-files -z;find assets/public -type f -print0)';
local.exec(filesToCopy + '|rsync --files-from - -avz0 --rsh="ssh"'
+ ' ./ pstadler@pstadler.sh:/tmp/' + tmpDir);
});
// run commands on remote hosts (destinations)
plan.international(function(remote) {
remote.log('Move folder to web root');
remote.sudo('cp -R /tmp/' + tmpDir + ' ~', { user: 'www' });
remote.rm('-rf /tmp/' + tmpDir);
remote.log('Install dependencies');
remote.sudo('npm --production --silent --prefix ~/'
+ tmpDir + ' install ~/' + tmpDir, { user: 'www' });
remote.log('Reload application');
remote.sudo('ln -snf ~/' + tmpDir + ' ~/pstadler-sh', { user: 'www' });
remote.sudo('pm2 reload pstadler-sh', { user: 'www' });
});
// run more commands on localhost afterwards
plan.domestic(function(local) { /* ... */ });
// ...or on remote hosts
plan.international(function(remote) { /* ... */ });
// executed if flightplan succeeded
plan.success(function() {
});
// executed if flightplan failed
plan.disaster(function() {
});
// always executed after flightplan finished
plan.debriefing(function() {
});
JavaScript设计模式与开发实践
曾探 / 人民邮电出版社 / 2015-5 / 59.00元
本书在尊重《设计模式》原意的同时,针对JavaScript语言特性全面介绍了更适合JavaScript程序员的了16个常用的设计模式,讲解了JavaScript面向对象和函数式编程方面的基础知识,介绍了面向对象的设计原则及其在设计模式中的体现,还分享了面向对象编程技巧和日常开发中的代码重构。本书将教会你如何把经典的设计模式应用到JavaScript语言中,编写出优美高效、结构化和可维护的代码。一起来看看 《JavaScript设计模式与开发实践》 这本书的介绍吧!
