From 80f59c1c805ce1b4393ca243da24344f0ffdaecb Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Tue, 10 Feb 2015 10:38:38 +0100 Subject: [PATCH 1/6] Clean up Symfony-related stuff after creating the project --- src/Symfony/Installer/NewCommand.php | 72 +++++++++++++++++++++++++--- 1 file changed, 66 insertions(+), 6 deletions(-) diff --git a/src/Symfony/Installer/NewCommand.php b/src/Symfony/Installer/NewCommand.php index 3e698f7..7ee0da5 100755 --- a/src/Symfony/Installer/NewCommand.php +++ b/src/Symfony/Installer/NewCommand.php @@ -78,6 +78,7 @@ protected function execute(InputInterface $input, OutputInterface $output) ->cleanUp() ->updateParameters() ->updateComposerJson() + ->createGitIgnore() ->checkSymfonyRequirements() ->displayInstallationResult() ; @@ -348,7 +349,8 @@ private function extract() /** * Removes all the temporary files and directories created to - * download and extract Symfony. + * download the project and removes Symfony-related files that don't make + * sense in a proprietary project. * * @return NewCommand */ @@ -356,6 +358,30 @@ private function cleanUp() { $this->fs->remove(dirname($this->compressedFilePath)); + try { + $this->fs->remove(array( + $this->projectDir.'/LICENSE', + $this->projectDir.'/UPGRADE.md', + $this->projectDir.'/UPGRADE-2.2.md', + $this->projectDir.'/UPGRADE-2.3.md', + $this->projectDir.'/UPGRADE-2.4.md', + $this->projectDir.'/UPGRADE-2.5.md', + $this->projectDir.'/UPGRADE-2.6.md', + $this->projectDir.'/UPGRADE-2.7.md', + $this->projectDir.'/UPGRADE-3.0.md', + )); + + $now = new \DateTime('now'); + $this->fs->dumpFile( + $this->projectDir.'/README.md', + sprintf("%s\n%s\n\nA Symfony project created on %s.\n", $this->projectName, str_repeat('=', strlen($this->projectName)), $now->format('F j, Y, g:i a')) + ); + } catch (\Exception $e) { + // don't throw an exception in case any of the Symfony-related files cannot + // be removed, because this is just an enhancement, not something mandatory + // for the project + } + return $this; } @@ -476,12 +502,46 @@ private function updateComposerJson() return $this; } - $ret = str_replace( - '"name": "symfony/framework-standard-edition",', - sprintf('"name": "%s",', $this->generateComposerProjectName()), - file_get_contents($filename) + $contents = json_decode(file_get_contents($filename), true); + + $contents['name'] = $this->generateComposerProjectName(); + $contents['license'] = 'proprietary'; + unset($contents['description']); + unset($contents['extra']['branch-alias']); + + file_put_contents($filename, json_encode($contents, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)."\n"); + + return $this; + } + + /** + * Creates the appropriate .gitignore file for a Symfony project. + * + * @return NewCommand + */ + private function createGitIgnore() + { + $gitIgnoreEntries = array( + '/app/bootstrap.php.cache', + '/app/cache/*', + '!app/cache/.gitkeep', + '/app/config/parameters.yml', + '/app/logs/*', + '!app/logs/.gitkeep', + '/app/phpunit.xml', + '/bin/', + '/build/', + '/composer.phar', + '/vendor/', + '/web/bundles/', ); - file_put_contents($filename, $ret); + + try { + $this->fs->dumpFile($this->projectDir.'/.gitignore', implode("\n", $gitIgnoreEntries)."\n"); + } catch (\Exception $e) { + // don't throw an exception in case the .gitignore file cannot be created, + // because this is just an enhancement, not something mandatory for the project + } return $this; } From c47235823b4a5f3328569b7e4d09ffcade0d0be7 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Tue, 10 Feb 2015 11:14:11 +0100 Subject: [PATCH 2/6] Made more robust the code that decides which files should be removed --- src/Symfony/Installer/NewCommand.php | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/src/Symfony/Installer/NewCommand.php b/src/Symfony/Installer/NewCommand.php index 7ee0da5..0580421 100755 --- a/src/Symfony/Installer/NewCommand.php +++ b/src/Symfony/Installer/NewCommand.php @@ -359,17 +359,12 @@ private function cleanUp() $this->fs->remove(dirname($this->compressedFilePath)); try { - $this->fs->remove(array( - $this->projectDir.'/LICENSE', - $this->projectDir.'/UPGRADE.md', - $this->projectDir.'/UPGRADE-2.2.md', - $this->projectDir.'/UPGRADE-2.3.md', - $this->projectDir.'/UPGRADE-2.4.md', - $this->projectDir.'/UPGRADE-2.5.md', - $this->projectDir.'/UPGRADE-2.6.md', - $this->projectDir.'/UPGRADE-2.7.md', - $this->projectDir.'/UPGRADE-3.0.md', - )); + $commonFiles = array($this->projectDir.'/LICENSE', $this->projectDir.'/UPGRADE.md'); + $upgradeFiles = glob($this->projectDir.'/UPGRADE-*.*.md'); + $changelogFiles = glob($this->projectDir.'/CHANGELOG-*.*.md'); + + $filesToRemove = array_merge($commonFiles, $upgradeFiles, $changelogFiles); + $this->fs->remove($filesToRemove); $now = new \DateTime('now'); $this->fs->dumpFile( From 62ba9ec9b7795b4555696dad1fc1ab8f1b1b4413 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Tue, 10 Feb 2015 11:17:41 +0100 Subject: [PATCH 3/6] Minor code refactorization --- src/Symfony/Installer/NewCommand.php | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/Symfony/Installer/NewCommand.php b/src/Symfony/Installer/NewCommand.php index 0580421..38840b7 100755 --- a/src/Symfony/Installer/NewCommand.php +++ b/src/Symfony/Installer/NewCommand.php @@ -366,11 +366,8 @@ private function cleanUp() $filesToRemove = array_merge($commonFiles, $upgradeFiles, $changelogFiles); $this->fs->remove($filesToRemove); - $now = new \DateTime('now'); - $this->fs->dumpFile( - $this->projectDir.'/README.md', - sprintf("%s\n%s\n\nA Symfony project created on %s.\n", $this->projectName, str_repeat('=', strlen($this->projectName)), $now->format('F j, Y, g:i a')) - ); + $readmeContents = sprintf("%s\n%s\n\nA Symfony project created on %s.\n", $this->projectName, str_repeat('=', strlen($this->projectName)), date('F j, Y, g:i a')); + $this->fs->dumpFile($this->projectDir.'/README.md', $readmeContents); } catch (\Exception $e) { // don't throw an exception in case any of the Symfony-related files cannot // be removed, because this is just an enhancement, not something mandatory From e76e5bafe795c54e9625b10cff7233472ea68e84 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Wed, 11 Feb 2015 08:39:14 +0100 Subject: [PATCH 4/6] Simplified code --- src/Symfony/Installer/NewCommand.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Installer/NewCommand.php b/src/Symfony/Installer/NewCommand.php index 38840b7..5b6a46c 100755 --- a/src/Symfony/Installer/NewCommand.php +++ b/src/Symfony/Installer/NewCommand.php @@ -359,11 +359,11 @@ private function cleanUp() $this->fs->remove(dirname($this->compressedFilePath)); try { - $commonFiles = array($this->projectDir.'/LICENSE', $this->projectDir.'/UPGRADE.md'); - $upgradeFiles = glob($this->projectDir.'/UPGRADE-*.*.md'); - $changelogFiles = glob($this->projectDir.'/CHANGELOG-*.*.md'); + $licenseFile = array($this->projectDir.'/LICENSE'); + $upgradeFiles = glob($this->projectDir.'/UPGRADE*.md'); + $changelogFiles = glob($this->projectDir.'/CHANGELOG*.md'); - $filesToRemove = array_merge($commonFiles, $upgradeFiles, $changelogFiles); + $filesToRemove = array_merge($licenseFile, $upgradeFiles, $changelogFiles); $this->fs->remove($filesToRemove); $readmeContents = sprintf("%s\n%s\n\nA Symfony project created on %s.\n", $this->projectName, str_repeat('=', strlen($this->projectName)), date('F j, Y, g:i a')); From a8afd6e9f6b9c35fc420e089562a99cc33020a6a Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Wed, 11 Feb 2015 08:40:25 +0100 Subject: [PATCH 5/6] Made code more robust --- src/Symfony/Installer/NewCommand.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Installer/NewCommand.php b/src/Symfony/Installer/NewCommand.php index 5b6a46c..ba7c22b 100755 --- a/src/Symfony/Installer/NewCommand.php +++ b/src/Symfony/Installer/NewCommand.php @@ -498,8 +498,14 @@ private function updateComposerJson() $contents['name'] = $this->generateComposerProjectName(); $contents['license'] = 'proprietary'; - unset($contents['description']); - unset($contents['extra']['branch-alias']); + + if (isset($contents['description'])) { + unset($contents['description']); + } + + if (isset($contents['extra']['branch-alias'])) { + unset($contents['extra']['branch-alias']); + } file_put_contents($filename, json_encode($contents, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)."\n"); From 539bf1e8cd0c53c89273273b15130dd4472b51ed Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Thu, 12 Feb 2015 11:22:33 +0100 Subject: [PATCH 6/6] Removed an unneeded entry in the .gitignore file --- src/Symfony/Installer/NewCommand.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Symfony/Installer/NewCommand.php b/src/Symfony/Installer/NewCommand.php index ba7c22b..77f477a 100755 --- a/src/Symfony/Installer/NewCommand.php +++ b/src/Symfony/Installer/NewCommand.php @@ -528,7 +528,6 @@ private function createGitIgnore() '!app/logs/.gitkeep', '/app/phpunit.xml', '/bin/', - '/build/', '/composer.phar', '/vendor/', '/web/bundles/',