diff --git a/src/Symfony/Installer/NewCommand.php b/src/Symfony/Installer/NewCommand.php index 3e698f7..77f477a 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,22 @@ private function cleanUp() { $this->fs->remove(dirname($this->compressedFilePath)); + try { + $licenseFile = array($this->projectDir.'/LICENSE'); + $upgradeFiles = glob($this->projectDir.'/UPGRADE*.md'); + $changelogFiles = glob($this->projectDir.'/CHANGELOG*.md'); + + $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')); + $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 + // for the project + } + return $this; } @@ -476,12 +494,51 @@ 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'; + + 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"); + + 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/', + '/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; }