From 3849192cc76a5d4109ac5c4607c577f278de7e24 Mon Sep 17 00:00:00 2001 From: Sam Rapaport Date: Tue, 13 Jun 2017 09:45:42 -0700 Subject: [PATCH 1/2] Don't remove comments when clearing files. --- app/lib/Sage/PostCreateProject.php | 35 +++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/app/lib/Sage/PostCreateProject.php b/app/lib/Sage/PostCreateProject.php index 19d78f8..8d1a632 100755 --- a/app/lib/Sage/PostCreateProject.php +++ b/app/lib/Sage/PostCreateProject.php @@ -12,7 +12,7 @@ class PostCreateProject $io = $event->getIO(); if ($io->isInteractive()) { - $io->write('Define theme headers. Press enter key for default.'); + $io->write('Define theme headers. Press enter key for default. (sam)'); $theme_headers_default = [ 'name' => 'Sage Starter Theme', @@ -64,30 +64,45 @@ class PostCreateProject file_put_contents('package.json', preg_replace("/{$default_framework_pattern}/", '"foundation-sites": "6.3.0"', file_get_contents('package.json'))); file_put_contents('resources/assets/styles/main.scss', str_replace('@import "~bootstrap/scss/bootstrap";' . "\n", '@import "~foundation-sites/scss/foundation";' . "\n" . '@include foundation-everything;' . "\n", file_get_contents('resources/assets/styles/main.scss'))); file_put_contents('resources/assets/scripts/main.js', str_replace("import 'bootstrap';\n", "import 'foundation-sites/dist/js/foundation';\n", file_get_contents('resources/assets/scripts/main.js'))); - foreach($files_to_clear as $file) { - file_put_contents($file, ''); - } + + static::clearFiles($files_to_clear); + break; case 2: file_put_contents('package.json', preg_replace("/{$default_framework_pattern}/", '"tachyons-sass": "^4.7.1"', file_get_contents('package.json'))); file_put_contents('resources/assets/styles/main.scss', str_replace('@import "~bootstrap/scss/bootstrap";' . "\n", '@import "~tachyons-sass/tachyons";' . "\n", file_get_contents('resources/assets/styles/main.scss'))); file_put_contents('resources/assets/scripts/main.js', str_replace("import 'bootstrap';\n", '', file_get_contents('resources/assets/scripts/main.js'))); - foreach($files_to_clear as $file) { - file_put_contents($file, ''); - } + + static::clearFiles($files_to_clear); + break; case 3: file_put_contents('package.json', preg_replace("/\s+{$default_framework_pattern},/", '', file_get_contents('package.json'))); file_put_contents('resources/assets/styles/main.scss', str_replace('@import "~bootstrap/scss/bootstrap";' . "\n", '', file_get_contents('resources/assets/styles/main.scss'))); file_put_contents('resources/assets/scripts/main.js', str_replace("import 'bootstrap';\n", '', file_get_contents('resources/assets/scripts/main.js'))); - foreach($files_to_clear as $file) { - file_put_contents($file, ''); - } + + static::clearFiles($files_to_clear); + break; } } } + public static function clearFiles(array $files) + { + foreach($files as $file) { + // First, we will pull the comment from the first line of each file + // we want to empty. Stylelint does not allow empty files. + if ($handle = fopen($file, 'r')) { + $comment = fgets($handle); + fclose($handle); + } + + // Finally, we will replace the file's contents with just the comment. + file_put_contents($file, $comment); + } + } + public static function addFontAwesome(Event $event) { $io = $event->getIO(); From 95acfe2ff565cdec03b7c5c31e27fa1f0d1e5293 Mon Sep 17 00:00:00 2001 From: Sam Rapaport Date: Tue, 13 Jun 2017 09:47:19 -0700 Subject: [PATCH 2/2] Remove test output. --- app/lib/Sage/PostCreateProject.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/lib/Sage/PostCreateProject.php b/app/lib/Sage/PostCreateProject.php index 8d1a632..e1d84f1 100755 --- a/app/lib/Sage/PostCreateProject.php +++ b/app/lib/Sage/PostCreateProject.php @@ -12,7 +12,7 @@ class PostCreateProject $io = $event->getIO(); if ($io->isInteractive()) { - $io->write('Define theme headers. Press enter key for default. (sam)'); + $io->write('Define theme headers. Press enter key for default.'); $theme_headers_default = [ 'name' => 'Sage Starter Theme',