diff --git a/CHANGELOG.md b/CHANGELOG.md index 3612baf35f..113b85aa23 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,5 @@ ### 9.0.0-beta.2: TBD +* Add option to add Font Awesome ([#1812](https://github.com/roots/sage/pull/1812)) * Add option to change theme file headers ([#1811](https://github.com/roots/sage/pull/1811)) * Add option to remove Bootstrap ([#1810](https://github.com/roots/sage/pull/1810)) * Remove Font Awesome ([#1809](https://github.com/roots/sage/pull/1809)) diff --git a/composer.json b/composer.json index b516d75698..17a4e2875e 100644 --- a/composer.json +++ b/composer.json @@ -43,7 +43,8 @@ ], "post-create-project-cmd": [ "Roots\\Sage\\PostCreateProject::updateHeaders", - "Roots\\Sage\\PostCreateProject::removeBootstrap" + "Roots\\Sage\\PostCreateProject::removeBootstrap", + "Roots\\Sage\\PostCreateProject::addFontAwesome" ] } } diff --git a/src/lib/Sage/PostCreateProject.php b/src/lib/Sage/PostCreateProject.php index 37489cbfec..dd8e959c48 100755 --- a/src/lib/Sage/PostCreateProject.php +++ b/src/lib/Sage/PostCreateProject.php @@ -42,7 +42,6 @@ public static function removeBootstrap(Event $event) if ($io->isInteractive()) { if ($io->askConfirmation('Remove Bootstrap? [y,N]? ', false)) { file_put_contents('package.json', str_replace(' "bootstrap": "^4.0.0-alpha.6",' . "\n", '', file_get_contents('package.json'))); - file_put_contents('assets/styles/main.scss', str_replace('// Import npm dependencies' . "\n", '', file_get_contents('assets/styles/main.scss'))); file_put_contents('assets/styles/main.scss', str_replace('@import "~bootstrap/scss/bootstrap";' . "\n", '', file_get_contents('assets/styles/main.scss'))); file_put_contents('assets/scripts/main.js', str_replace('import \'bootstrap/dist/js/bootstrap\';' . "\n", '', file_get_contents('assets/scripts/main.js'))); file_put_contents('assets/styles/components/_comments.scss', ''); @@ -52,5 +51,24 @@ public static function removeBootstrap(Event $event) } } } + + public static function addFontAwesome(Event $event) + { + $io = $event->getIO(); + + if ($io->isInteractive()) { + if ($io->askConfirmation('Add Font Awesome? [y,N]? ', false)) { + $package = json_decode(file_get_contents('package.json'), true); + $dependencies = $package['dependencies']; + $dependencies = array_merge($dependencies, ['font-awesome' => '^4.7.0']); + $package['dependencies'] = $dependencies; + $package = str_replace(' ', ' ', json_encode($package, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) . "\n"); + + $import_dep_str = '// Import npm dependencies' . "\n"; + file_put_contents('assets/styles/main.scss', str_replace($import_dep_str, $import_dep_str . '@import "~font-awesome/scss/font-awesome";' . "\n", file_get_contents('assets/styles/main.scss'))); + file_put_contents('assets/styles/common/_variables.scss', "\n" . '$fa-font-path: \'~font-awesome/fonts\';' . "\n", FILE_APPEND); + } + } + } // @codingStandardsIgnoreEnd }