Skip to content

Commit

Permalink
Merge pull request #15 from mnapoli/auto-add-bref-files
Browse files Browse the repository at this point in the history
Auto-deploy Bref internal files
  • Loading branch information
mnapoli authored Jun 9, 2018
2 parents 60a5c36 + 5b4d5b3 commit e549dbf
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 16 deletions.
2 changes: 0 additions & 2 deletions serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ package:
- '*'
- '**'
include:
- handler.js
- bref.php
- '.bref/**'
- 'src/**'
- 'vendor/**'

Expand Down
29 changes: 17 additions & 12 deletions src/Console/Deployer.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,10 @@ private function generateArchive(SymfonyStyle $io, ProgressBar $progress) : void
$this->fs->copy(__DIR__ . '/../../template/php.ini', '.bref/output/.bref/php.ini');
$progress->advance();

$progress->setMessage('Installing `handler.js`');
$progress->setMessage('Installing Bref files for NodeJS');
$progress->display();
$this->copyServerlessYml();
// Install `handler.js`
$this->fs->copy(__DIR__ . '/../../template/handler.js', '.bref/output/handler.js');
$progress->advance();

Expand All @@ -178,13 +180,6 @@ private function generateArchive(SymfonyStyle $io, ProgressBar $progress) : void
$this->runLocally('composer install --no-dev --classmap-authoritative --no-scripts');
$progress->advance();

/*
* TODO Edit the `serverless.yml` copy (in `.bref/output` to deploy these files:
* - bref.php
* - handler.js
* - .bref/**
*/

// Run build hooks defined in .bref.yml
$progress->setMessage('Running build hooks');
$progress->display();
Expand All @@ -204,10 +199,6 @@ private function runLocally(string $command) : void
$process->mustRun();
}

/**
* @param SymfonyStyle $io
* @return ProgressBar
*/
private function createProgressBar(SymfonyStyle $io, int $max) : ProgressBar
{
ProgressBar::setFormatDefinition('bref', "<comment>%message%</comment>\n %current%/%max% [%bar%] %elapsed:6s%\n");
Expand All @@ -221,4 +212,18 @@ private function createProgressBar(SymfonyStyle $io, int $max) : ProgressBar

return $progressBar;
}

/**
* Pre-process the `serverless.yml` file and copy it in the lambda directory.
*/
private function copyServerlessYml() : void
{
$serverlessYml = Yaml::parse(file_get_contents('serverless.yml'));

// Force deploying the files used by Bref without having the user know about them
$serverlessYml['package']['include'][] = 'handler.js';
$serverlessYml['package']['include'][] = '.bref/**';

file_put_contents('.bref/output/serverless.yml', Yaml::dump($serverlessYml, 10));
}
}
2 changes: 0 additions & 2 deletions template/serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ package:
- '*'
- '**'
include:
- handler.js
- bref.php
- '.bref/**'
- 'src/**'
- 'vendor/**'

Expand Down

0 comments on commit e549dbf

Please sign in to comment.