Skip to content

Commit

Permalink
Better .gitignore flow
Browse files Browse the repository at this point in the history
If .gitignore file is found in project folder it is not overwritten, and
at the end of the process a message is printed, to recommend the
presence there of sensible files. If .gitignore is created by WP
Starter, a message is printed to inform of that. When created,
.gitignore contains also plugins and themes folder.
  • Loading branch information
gmazzap committed Mar 5, 2015
1 parent 7add02c commit 9d7a9f1
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 15 deletions.
43 changes: 36 additions & 7 deletions src/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ class Builder
*/
private $salter;

/**
* @var bool|int
*/
private $gitignoreDone = false;

/**
* Construct. Just for DI.
*
Expand Down Expand Up @@ -80,20 +85,24 @@ public function build(ArrayAccess $paths)
} else {
return $this->error('error');
}
if ($this->moveContent($paths) === true) {
$this->progress('move_done');
}
foreach (self::$files as $file) {
if ($file === '.gitignore' && is_file($paths['root'].DIRECTORY_SEPARATOR.$file)) {
$this->gitignoreDone = 0;
continue;
}
if ($this->saveFile($this->buildFile($paths, $file), $paths['root'], $file)) {
if ($file === '.gitignore') {
$this->gitignoreDone = true;
}
$this->progress('file_done', $file);
}
}
if ($this->copy($paths, '.env.example')) {
$this->progress('env_done');
}
if ($this->moveContent($paths) === true) {
$this->progress('move_done');
}

return $this->errors > 0
? $this->error($this->errors === 1 ? 'error' : 'errors')
Expand Down Expand Up @@ -139,10 +148,23 @@ private function buildFile(ArrayAccess $paths, $fileName)
static $vars;
if (is_null($vars)) {
$vars = array(
'VENDOR_PATH' => $paths['vendor'],
'WP_INSTALL_PATH' => $paths['wp'],
'WP_CONTENT_PATH' => $paths['content'],
'VENDOR_PATH' => $paths['vendor'],
'WP_INSTALL_PATH' => $paths['wp'],
'WP_CONTENT_PATH' => $paths['content'],
'VENDOR_PATH_IGNORE' => str_replace(array('\\', '/'), '/', $paths['vendor']).'/',
);
if ($paths['content']) {
$content = str_replace(array('\\', '/'), '/', $paths['content']).'/';
$vars['THEMES_PATH_IGNORE'] = is_dir($paths['root'].'/'.$content.'/themes')
? $content.'themes/'
: '';
$vars['PLUGINS_PATH_IGNORE'] = is_dir($paths['root'].'/'.$content.'/plugins')
? $content.'plugins/'
: '';
$vars['MUPLUGINS_PATH_IGNORE'] = is_dir($paths['root'].'/'.$content.'/mu-plugins')
? $content.'mu-plugins/'
: '';
}
}
$template = implode(
DIRECTORY_SEPARATOR,
Expand Down Expand Up @@ -334,8 +356,15 @@ private function progress()
'same_content_folder' => ' - <comment>Your content folder is WP content folder.</comment>',
'done' => ' WP Starter finished successfully!'.str_repeat(' ', 20),
'end' => ' <comment>Remember you need an .env file with -at least- DB settings'
.PHP_EOL.' to make your site fully functional.</comment>',
.PHP_EOL.' to make your site fully functional.</comment>'.PHP_EOL,
);
if ($this->gitignoreDone === true) {
$messages['end'] .= PHP_EOL.' <comment>A .gitignore file has been created with common to-be-ignored'.
PHP_EOL.' files and files generated by WP Starter.</comment>';
} elseif ($this->gitignoreDone === 0) {
$messages['end'] .= PHP_EOL.' <comment>A .gitignore was found in your project folder, please'.
PHP_EOL.' be sure it contains .env and wp-config.php files.</comment>';
}
$args = func_get_args();
$msg = array_shift($args);
$txt = $messages[$msg];
Expand Down
14 changes: 6 additions & 8 deletions templates/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,10 @@ sftp-config.json
### Vagrant
.vagrant/

### Composer
{{{VENDOR_PATH_SUBDIR}}}/

### DO NOT REMOVE FOLLOWING LINES
### GENERATED FILES
.env
.env.development
.env.production
.env.staging
/wp-config.php
/wp-config.php
{{{VENDOR_PATH_IGNORE}}}
{{{THEMES_PATH_IGNORE}}}
{{{PLUGINS_PATH_IGNORE}}}
{{{MUPLUGINS_PATH_IGNORE}}}

0 comments on commit 9d7a9f1

Please sign in to comment.