Skip to content
This repository was archived by the owner on Nov 14, 2019. It is now read-only.

Commit b85c9de

Browse files
committed
Clean up Symfony-related stuff after creating the project
1 parent 07e93d9 commit b85c9de

File tree

1 file changed

+63
-6
lines changed

1 file changed

+63
-6
lines changed

src/Symfony/Installer/NewCommand.php

Lines changed: 63 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
7878
->cleanUp()
7979
->updateParameters()
8080
->updateComposerJson()
81+
->createGitIgnore()
8182
->checkSymfonyRequirements()
8283
->displayInstallationResult()
8384
;
@@ -348,14 +349,31 @@ private function extract()
348349

349350
/**
350351
* Removes all the temporary files and directories created to
351-
* download and extract Symfony.
352+
* download the project and removes Symfony-related files that don't make
353+
* sense in a proprietary project.
352354
*
353355
* @return NewCommand
354356
*/
355357
private function cleanUp()
356358
{
357359
$this->fs->remove(dirname($this->compressedFilePath));
358360

361+
try {
362+
$licenseFile = array($this->projectDir.'/LICENSE');
363+
$upgradeFiles = glob($this->projectDir.'/UPGRADE*.md');
364+
$changelogFiles = glob($this->projectDir.'/CHANGELOG*.md');
365+
366+
$filesToRemove = array_merge($licenseFile, $upgradeFiles, $changelogFiles);
367+
$this->fs->remove($filesToRemove);
368+
369+
$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'));
370+
$this->fs->dumpFile($this->projectDir.'/README.md', $readmeContents);
371+
} catch (\Exception $e) {
372+
// don't throw an exception in case any of the Symfony-related files cannot
373+
// be removed, because this is just an enhancement, not something mandatory
374+
// for the project
375+
}
376+
359377
return $this;
360378
}
361379

@@ -476,12 +494,51 @@ private function updateComposerJson()
476494
return $this;
477495
}
478496

479-
$ret = str_replace(
480-
'"name": "symfony/framework-standard-edition",',
481-
sprintf('"name": "%s",', $this->generateComposerProjectName()),
482-
file_get_contents($filename)
497+
$contents = json_decode(file_get_contents($filename), true);
498+
499+
$contents['name'] = $this->generateComposerProjectName();
500+
$contents['license'] = 'proprietary';
501+
502+
if (isset($contents['description'])) {
503+
unset($contents['description']);
504+
}
505+
506+
if (isset($contents['extra']['branch-alias'])) {
507+
unset($contents['extra']['branch-alias']);
508+
}
509+
510+
file_put_contents($filename, json_encode($contents, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)."\n");
511+
512+
return $this;
513+
}
514+
515+
/**
516+
* Creates the appropriate .gitignore file for a Symfony project.
517+
*
518+
* @return NewCommand
519+
*/
520+
private function createGitIgnore()
521+
{
522+
$gitIgnoreEntries = array(
523+
'/app/bootstrap.php.cache',
524+
'/app/cache/*',
525+
'!app/cache/.gitkeep',
526+
'/app/config/parameters.yml',
527+
'/app/logs/*',
528+
'!app/logs/.gitkeep',
529+
'/app/phpunit.xml',
530+
'/bin/',
531+
'/composer.phar',
532+
'/vendor/',
533+
'/web/bundles/',
483534
);
484-
file_put_contents($filename, $ret);
535+
536+
try {
537+
$this->fs->dumpFile($this->projectDir.'/.gitignore', implode("\n", $gitIgnoreEntries)."\n");
538+
} catch (\Exception $e) {
539+
// don't throw an exception in case the .gitignore file cannot be created,
540+
// because this is just an enhancement, not something mandatory for the project
541+
}
485542

486543
return $this;
487544
}

0 commit comments

Comments
 (0)