我试图自动化每次在服务器上测试应用程序和网站时所经历的过程。我目前正在nodejitsu上运行。当我测试了某些东西并且它可以在我的本地计算机上运行时,我要做的下一件事是......
- 打开我的 package.json 文件
- 删除域字段并将名称和子域更改为 staging。 (更改版本号也可能有意义)
- Then I
jitsu deploy
- 确认任何提示(例如批准版本号的增量)
- 应用程序启动后,我会检查我的应用程序在服务器上的工作情况,进行更改等
完成后,我的应用程序准备就绪,我会撤消 package.json 文件中的更改。我想自动化这个过程。我的想法是用一个很小的 node.js 文件来做到这一点。到此为止了...
/*
* Use this file to deploy an app to the staging server on nodejitsu
*/
var bash = require('child_process').spawn('bash');
var colors = require('colors');
var fs = require('fs');
// stdout setup
bash.stdout.on('data', function (data) {
console.log('stdout: ' + data);
});
bash.stdout.on('error', function (err) {
console.log('stdout error: '.red, err);
});
// on bash exit
bash.on('exit', function (code) {
console.log('Exiting... ', code);
});
// grab package.json
var package = '';
fs.readFile('package.json', {encoding: 'utf-8'}, function (err, data) { // grab the package.json file contents
if (err) throw err;
package = JSON.parse(data);
fs.rename('package.json', 'rename-me-before-deploying.json'); // rename the package.json file
package.name = 'stajing'; // alter json
package.subdomain = 'stajing'; // alter json
package.domains = []; // alter json
fs.writeFile('package.json', JSON.stringify(package, null, 2), function(err) { // write the new package to package.json
if (err) throw err;
bash.stdin.write('jitsu deploy\n'); // Deploy to staging app on nodejitsu.
setTimeout(function () { // this needs to be replaced
bash.stdin.write('yes\n');
}, 5000);
console.log("All done : )");
// bash.stdin.end(); // close out
});
});
我这里有几个问题。我很确定我需要知道完成它,就是当nodejitsu提示我增加版本号时触发的事件prompt: Is this ok?: (yes)
这样我就可以确认(如果发生这种情况)以及整个过程完成时触发的事件,以便我可以恢复对 package.json 文件的更改,使我的应用程序部署到暂存环境,并且我的文件基本上保持不变。