|
1 | 1 | 'use strict';
|
2 | 2 | var util = require('util');
|
3 | 3 | var ScriptBase = require('../script-base.js');
|
4 |
| - |
| 4 | +var exec = require('child_process').exec; |
| 5 | +var chalk = require('chalk'); |
5 | 6 |
|
6 | 7 | var Generator = module.exports = function Generator() {
|
7 | 8 | ScriptBase.apply(this, arguments);
|
8 | 9 | };
|
9 | 10 |
|
10 | 11 | util.inherits(Generator, ScriptBase);
|
11 | 12 |
|
12 |
| -Generator.prototype.deployHeroku = function deployHeroku() { |
| 13 | +Generator.prototype.checkInstallation = function checkInstallation() { |
| 14 | + if(this.name.toLowerCase() != "heroku") return; |
| 15 | + var done = this.async(); |
| 16 | + |
| 17 | + this.herokuInstalled = false; |
| 18 | + exec('heroku --version', function (err) { |
| 19 | + if (err) { |
| 20 | + this.log.error('You don\'t have the Heroku Toolbelt installed. ' + |
| 21 | + 'Grab it from https://toolbelt.heroku.com/'); |
| 22 | + } else { |
| 23 | + this.herokuInstalled = true; |
| 24 | + } |
| 25 | + done(); |
| 26 | + }.bind(this)); |
| 27 | +}; |
| 28 | + |
| 29 | +Generator.prototype.copyProcfile = function copyProcfile() { |
13 | 30 | if(this.name.toLowerCase() != "heroku") return;
|
14 | 31 | this.template('../deploy/heroku/Procfile', 'heroku/Procfile');
|
15 | 32 | };
|
| 33 | + |
| 34 | +Generator.prototype.gruntBuild = function gruntBuild() { |
| 35 | + if(this.name.toLowerCase() != "heroku") return; |
| 36 | + var done = this.async(); |
| 37 | + |
| 38 | + console.log(chalk.bold('Building heroku folder, please wait...')); |
| 39 | + exec('grunt heroku', function (err, stdout) { |
| 40 | + console.log('stdout: ' + stdout); |
| 41 | + |
| 42 | + if (err) { |
| 43 | + this.log.error(err); |
| 44 | + } |
| 45 | + done(); |
| 46 | + }.bind(this)); |
| 47 | +}; |
| 48 | + |
| 49 | +Generator.prototype.gitInit = function gitInit() { |
| 50 | + if(this.name.toLowerCase() != "heroku") return; |
| 51 | + var done = this.async(); |
| 52 | + |
| 53 | + exec('git init && git add -A && git commit -m "Initial commit"', { cwd: 'heroku' }, function (err) { |
| 54 | + if (err) { |
| 55 | + this.log.error(err); |
| 56 | + } |
| 57 | + done(); |
| 58 | + }.bind(this)); |
| 59 | +}; |
| 60 | + |
| 61 | +Generator.prototype.herokuCreate = function herokuCreate() { |
| 62 | + if(this.name.toLowerCase() != "heroku") return; |
| 63 | + var done = this.async(); |
| 64 | + |
| 65 | + exec('heroku apps:create && heroku config:set NODE_ENV=production"', { cwd: 'heroku' }, function (err, stdout, stderr) { |
| 66 | + if (err) { |
| 67 | + this.log.error(err); |
| 68 | + } else { |
| 69 | + console.log('stdout: ' + stdout); |
| 70 | + console.log(chalk.green('You\'re all set! Now push to heroku with\n\t' + chalk.bold('git push heroku master') + |
| 71 | + '\nfrom your new heroku folder')); |
| 72 | + console.log(chalk.yellow('After app modification\n\t' + chalk.bold('grunt heroku') + |
| 73 | + '\nthen commit and push the heroku folder')); |
| 74 | + } |
| 75 | + done(); |
| 76 | + }.bind(this)); |
| 77 | +}; |
0 commit comments