Skip to content

Commit

Permalink
Add node.js template.
Browse files Browse the repository at this point in the history
  • Loading branch information
antonmedv committed Mar 20, 2016
1 parent 1476ab9 commit 0c9ff20
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Console/InitCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Deployer\Initializer\Template\CommonTemplate;
use Deployer\Initializer\Template\ComposerTemplate;
use Deployer\Initializer\Template\LaravelTemplate;
use Deployer\Initializer\Template\NodeJsTemplate;
use Deployer\Initializer\Template\SymfonyTemplate;
use Deployer\Initializer\Template\YiiTemplate;
use Symfony\Component\Console\Command\Command;
Expand Down Expand Up @@ -106,6 +107,7 @@ private function createInitializer()
$initializer->addTemplate('symfony', new SymfonyTemplate());
$initializer->addTemplate('laravel', new LaravelTemplate());
$initializer->addTemplate('yii', new YiiTemplate());
$initializer->addTemplate('node.js', new NodeJsTemplate());

return $initializer;
}
Expand Down
1 change: 1 addition & 0 deletions src/Initializer/Template/CommonTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ protected function getTemplateContent()
'deploy:release',
'deploy:update_code',
'deploy:shared',
'deploy:writable',
'deploy:symlink',
'cleanup',
])->desc('Deploy your project');
Expand Down
90 changes: 90 additions & 0 deletions src/Initializer/Template/NodeJsTemplate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<?php
/* (c) Anton Medvedev <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Deployer\Initializer\Template;

/**
* Generate a node.js deployer configuration.
*
* @author Anton Medvedev <[email protected]>
*/
class NodeJsTemplate extends Template
{
/**
* {@inheritDoc}
*/
protected function getTemplateContent()
{
return <<<PHP
<?php
/*
* This file has been generated automatically.
* Please change the configuration for correct use deploy.
*/
require 'recipe/common.php';
// Set configurations
set('repository', '[email protected]:username/repository.git');
set('shared_files', []);
set('shared_dirs', []);
set('writable_dirs', []);
// Configure servers
server('production', 'prod.domain.com')
->user('username')
->password()
->env('deploy_path', '/var/www/prod.domain.com');
server('beta', 'beta.domain.com')
->user('username')
->password()
->env('deploy_path', '/var/www/beta.domain.com');
/**
* Install npm packages.
*/
task('deploy:npm', function () {
\$releases = env('releases_list');
if (isset(\$releases[1])) {
if(run("if [ -d {{deploy_path}}/releases/{\$releases[1]}/node_modules ]; then echo 'true'; fi")->toBool()) {
run("cp --recursive {{deploy_path}}/releases/{\$releases[1]}/node_modules {{release_path}}");
}
}
run("cd {{release_path}} && npm install");
});
/**
* Restart server on success deploy.
*/
task('pm2:restart', function () {
run("pm2 restart eightd");
})->desc('Restart pm2 service');
after('success', 'pm2:restart');
/**
* Main task
*/
task('deploy', [
'deploy:prepare',
'deploy:release',
'deploy:update_code',
'deploy:shared',
'deploy:writable',
'deploy:npm',
'deploy:symlink',
'cleanup',
])->desc('Deploy your project');
after('deploy', 'success');
PHP;
}
}

0 comments on commit 0c9ff20

Please sign in to comment.