Skip to content

Commit

Permalink
homestead inclusion
Browse files Browse the repository at this point in the history
  • Loading branch information
juliangut committed Nov 22, 2015
1 parent 9668d49 commit 2936993
Show file tree
Hide file tree
Showing 13 changed files with 209 additions and 83 deletions.
17 changes: 3 additions & 14 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,9 @@
# Contributing

First ol all **Thank you** for contributing!
First of all **Thank you** for contributing!

Make your contributions through Pull Requests

Find here a few rules to follow in order to keep the code clean and easy to reviews and merge:
[Grunt](http://gruntjs.com/) task is provided to help you keep code quality

- Follow **[PSR-2](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)** coding standard
- **Unit test everything** and run the test suite
- Try not to bring **code coverage** down
- Keep documentation **updated**
- Just **one pull request per feature** at a time
- Check that **[Travis CI](https://travis-ci.org/juliangut/generator-barephp)** build passed

[Grunt](http://gruntjs.com/) tasks are provided to help you keep code quality and run the test suite

- `grunt check` will run PHP linting, [PHP Code Sniffer](https://github.com/squizlabs/PHP_CodeSniffer) for style guidelines, [PHPMD](https://github.com/phpmd/phpmd) for code smells and [PHPCPD](https://github.com/sebastianbergmann/phpcpd) for copy/paste detection
- `grunt test` will run [PHPUnit](https://github.com/sebastianbergmann/phpunit) for unit tests
- `grunt` will run previous commands at once
- `grunt` will run [jshint](http://jshint.com/) for coding style
13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,19 @@ If you're fed up creating the same files once and again every time you start a n

* Git ready
* Composer ready (non opinionated)
* Packagist ready
* Prepared for Packagist
* Laravel/Homestead integration
* Awesome Grunt integration
* Already configured Travis integration (PHP 5.5, 5.6 and 7)
* Already configured Travis integration (PHP 5.5, 5.6, 7 and HHVM)
* Coveralls integration (triggered by Travis)
* Scrutinizer integration
* Editorconfig integration
* Testing set up and integrated with Grunt
* QA utilities (PHP linting, PHPUnit, PHPCS, PHPMD, PHPCPD) configured and integrated with Grunt
* License selector
* Testing environment already set up and integrated with Grunt
* QA utilities (PHP linting, PHPUnit, PHPCS, PHPMD, PHPCPD, Clim, Security-checker) configured and integrated with Grunt
* Basic documentation structure in Markdown
* License selector

> And more to come
## Getting Started

Expand Down
150 changes: 90 additions & 60 deletions app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,6 @@ var BarePHP = module.exports = function BarePHP() {
return process.env.HOME || process.env.HOMEPATH || process.env.USERPROFILE;
};

this.dirs = {
src: 'src',
tests: 'tests',
dist: 'build'
};

this.owner = {
account: '',
name: '',
Expand All @@ -44,9 +38,17 @@ var BarePHP = module.exports = function BarePHP() {
license: true,
travis: false,
scrutinizer: false,
homestead: false,
docs: false
};

this.dirs = {
src: 'src',
tests: 'tests',
public: 'public',
dist: 'build'
};

this.underscoreString = _;

if (!shell.which('git')) {
Expand Down Expand Up @@ -113,7 +115,7 @@ BarePHP.prototype.askForProject = function () {
},
{
name: 'projectkeywords',
message: 'What are the project keywords? (separated by spaces)',
message: 'What are the project keywords?',
default: this.project.keywords
},
{
Expand All @@ -123,7 +125,7 @@ BarePHP.prototype.askForProject = function () {
];

this.prompt(prompts, function(props) {
props.projectkeywords = _.trim(props.projectkeywords).replace(/\s+/g, ' ');
props.projectkeywords = _.trim(_.trim(props.projectkeywords).replace(/,\s*/g, ' ').replace(/\s+/g, ' '));
this.project.keywords = props.projectkeywords.length ? props.projectkeywords.split(' ') : [];

this.project.name = _.trim(props.projectname).replace(/\s+/g, '_');
Expand All @@ -135,58 +137,7 @@ BarePHP.prototype.askForProject = function () {
}.bind(this));
};

BarePHP.prototype.askForChangeDirs = function() {
var done = this.async(),
prompts = [
{
type: 'confirm',
name: 'changeDirs',
message: 'Whould you like to change default directories?',
default: false
}
];

this.prompt(prompts, function(props) {
this.control.dirs = props.changeDirs;

done();
}.bind(this));
};

BarePHP.prototype.askForDirs = function() {
if (!this.control.dirs) {
return;
}

var done = this.async(),
prompts = [
{
name: 'src',
message: 'What is the source code directory?',
default: this.dirs.src
},
{
name: 'tests',
message: 'What is the tests directory?',
default: this.dirs.tests
},
{
name: 'dist',
message: 'What is the build directory?',
default: this.dirs.dist
}
];

this.prompt(prompts, function(props) {
this.dirs.src = props.src;
this.dirs.tests = props.tests;
this.dirs.dist = props.dist;

done();
}.bind(this));
};

BarePHP.prototype.askForUseLicense = function() {
BarePHP.prototype.askForLicenseUse = function() {
var done = this.async(),
prompts = [
{
Expand Down Expand Up @@ -274,6 +225,11 @@ BarePHP.prototype.askForInstall = function() {
name: 'Scrutinizer',
checked: true
},
{
value: 'homestead',
name: 'Homestead',
checked: true
},
{
value: 'docs',
name: 'Base documentation',
Expand All @@ -289,12 +245,76 @@ BarePHP.prototype.askForInstall = function() {
this.control.travis = hasMod('travis');
this.control.coveralls = hasMod('coveralls');
this.control.scrutinizer = hasMod('scrutinizer');
this.control.homestead = hasMod('homestead');
this.control.docs = hasMod('docs');

done();
}.bind(this));
};

BarePHP.prototype.askForChangeDirs = function() {
var done = this.async(),
prompts = [
{
type: 'confirm',
name: 'changeDirs',
message: 'Whould you like to change default directories?',
default: false
}
];

this.prompt(prompts, function(props) {
this.control.dirs = props.changeDirs;

done();
}.bind(this));
};

BarePHP.prototype.askForCustomDirs = function() {
if (!this.control.dirs) {
return;
}

var done = this.async(),
prompts = [
{
name: 'src',
message: 'What is the source code directory?',
default: this.dirs.src
},
{
name: 'tests',
message: 'What is the tests directory?',
default: this.dirs.tests
},
{
name: 'dist',
message: 'What is the build directory?',
default: this.dirs.dist
}
];

if (this.control.homestead) {
prompts.push({
name: 'public',
message: 'What is the public directory?',
default: this.dirs.public
});
}

this.prompt(prompts, function(props) {
this.dirs.src = props.src;
this.dirs.tests = props.tests;
this.dirs.dist = props.dist;

if (this.control.homestead) {
this.dirs.public = props.public;
}

done();
}.bind(this));
};

BarePHP.prototype.writing = {
createDirs: function() {
mkdirp(this.dirs.src);
Expand Down Expand Up @@ -327,6 +347,16 @@ BarePHP.prototype.writing = {
if (this.control.scrutinizer) {
this.template('_scrutinizer.yml', '.scrutinizer.yml');
}
if (this.control.homestead) {
mkdirp(this.dirs.public);
this.template('_index.php', this.dirs.public + '/index.php');

mkdirp('.vagrant');
this.template('_Homestead.yml', '.vagrant/Homestead.yml');
this.copy('aliases', '.vagrant/aliases');
this.copy('after.sh', '.vagrant/after.sh');
this.copy('Vagrantfile', 'Vagrantfile');
}
if (this.control.docs) {
this.template('_CONTRIBUTING.md', 'CONTRIBUTING.md');
this.template('_README.md', 'README.md');
Expand Down
28 changes: 28 additions & 0 deletions app/templates/Vagrantfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
require 'json'
require 'yaml'

VAGRANTFILE_API_VERSION ||= "2"
confDir = $confDir ||= File.expand_path("vendor/laravel/homestead", File.dirname(__FILE__))

homesteadYamlPath = ".vagrant/Homestead.yml"
homesteadJsonPath = ".vagrant/Homestead.json"
afterScriptPath = ".vagrant/after.sh"
aliasesPath = ".vagrant/aliases"

require File.expand_path(confDir + '/scripts/homestead.rb')

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
if File.exists? aliasesPath then
config.vm.provision "file", source: aliasesPath, destination: "~/.bash_aliases"
end

if File.exists? homesteadYamlPath then
Homestead.configure(config, YAML::load(File.read(homesteadYamlPath)))
elsif File.exists? homesteadJsonPath then
Homestead.configure(config, JSON.parse(File.read(homesteadJsonPath)))
end

if File.exists? afterScriptPath then
config.vm.provision "shell", path: afterScriptPath
end
end
40 changes: 40 additions & 0 deletions app/templates/_Homestead.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
---
ip: "192.168.100.100"
memory: 2048
cpus: 1
hostname: <%= project.name %>
name: <%= project.name %>
provider: virtualbox

authorize: ~/.ssh/id_rsa.pub

keys:
- ~/.ssh/id_rsa

folders:
- map: "./"
to: "/home/vagrant/<%= project.name %>"

sites:
- map: <%= project.name %>.app
to: "/home/vagrant/<%= project.name %>/<%= dirs.public %>"

databases:
- <%= project.name %>

variables:
- key: APP_ENV
value: local

# blackfire:
# - id: foo
# token: bar
# client-id: foo
# client-token: bar

# ports:
# - send: 93000
# to: 9300
# - send: 7777
# to: 777
# protocol: udp
8 changes: 7 additions & 1 deletion app/templates/_composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,14 @@
"phpmd/phpmd": "^2.0",
"sebastian/phpcpd": "^2.0",
"vinkla/climb": "^0.6",
"sensiolabs/security-checker": "^3.0"
"sensiolabs/security-checker": "^3.0"<% if (control.homestead) { -%>,

"laravel/homestead": "^2.1"
},
<% } else { -%>

},
<% } -%>
"autoload": {
"psr-4": {
"<%= project.namespace.replace('\\', '\\\\') %>\\": "src"
Expand Down
4 changes: 4 additions & 0 deletions app/templates/_gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,9 @@
<% if (control.scrutinizer) { -%>
.scrutinizer.yml export-ignore
<% } -%>
<% if (control.homestead) { -%>
Vagrantfile export-ignore
.vagrant/ export-ignore
<% } -%>
Gruntfile.js export-ignore
phpunit.xml export-ignore
5 changes: 4 additions & 1 deletion app/templates/_gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@
composer.phar
vendor/
!composer.lock
<%= dirs.dist %>/
node_modules/
<%= dirs.dist %>/
<% if (control.homestead) { -%>
.vagrant/
<% } -%>
14 changes: 14 additions & 0 deletions app/templates/_index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php
/**
<% if (project.desc || project.homepage) { -%>
* <%= project.desc %><% if (project.homepage) { -%> (<%= project.homepage %>)<% } -%>
*
<% } -%>
* @link https://github.com/<%= owner.account %>/<%= project.name %> for the canonical source repository
<% if (control.license) { -%>
* @license https://github.com/<%= owner.account %>/<%= project.name %>/blob/master/LICENSE
<% } -%>
*/

phpinfo();
3 changes: 3 additions & 0 deletions app/templates/after.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

apt-get update
4 changes: 4 additions & 0 deletions app/templates/aliases
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
alias ..="cd .."
alias ...="cd ../.."
alias ls="ls -l --color"
alias ll="ls -a"
Loading

0 comments on commit 2936993

Please sign in to comment.