From 37460f0ea495d142e80b00880ce4717835b81d9d Mon Sep 17 00:00:00 2001 From: Andrew Riddlestone Date: Tue, 7 Apr 2020 13:57:12 +0100 Subject: [PATCH] feat(sass): Allow modules to specify sass options, such as includePaths #7 --- README.md | 21 +++++++ src/Command/Gulpfile.php | 2 +- test/Command/GulpfileTest.php | 1 + test/data/test4.js | 111 ++++++++++++++++++++++++++++++++++ test/data/test4.json | 30 +++++++++ view/gulpfile.js.php | 28 +++++---- 6 files changed, 180 insertions(+), 13 deletions(-) create mode 100644 test/data/test4.js create mode 100644 test/data/test4.json diff --git a/README.md b/README.md index 800a7d7..1a1acec 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,27 @@ A gulpfile can now be created using the brokkr command `gulpfile`: vendor/bin/brokkr gulpfile ``` +## Setting SASS options + +To set SASS options, include them in the `sass_options` settings for your portal: +```php + [ + 'main' => [ + 'css' => [ + realpath(__DIR__ . '/../resources/css/**/*.scss'), + ], + 'sass_options' => [ + 'includePaths' => [ + 'vendor/someones/awesome-css-stuff/scss', + ], + ], + ], + ], +]; +``` + ## Changing the template To change the template for your gulpfile, just copy view/gulpfile.js.php somewhere, change it, and add the new path to your module/site's config: diff --git a/src/Command/Gulpfile.php b/src/Command/Gulpfile.php index deb943c..2204211 100644 --- a/src/Command/Gulpfile.php +++ b/src/Command/Gulpfile.php @@ -58,7 +58,7 @@ protected function getPortalConfig() $portalConfig = []; foreach($this->getPortalManager()->getPortalNames() as $portalName) { $portalConfig[$portalName] = []; - foreach(['css', 'js', 'other'] as $type) { + foreach(['css', 'js', 'other', 'sass_options'] as $type) { $portalConfig[$portalName][$type] = $this->getPortalManager()->getPortalConfig($portalName, $type); } } diff --git a/test/Command/GulpfileTest.php b/test/Command/GulpfileTest.php index fdd0b01..4bb00d9 100644 --- a/test/Command/GulpfileTest.php +++ b/test/Command/GulpfileTest.php @@ -22,6 +22,7 @@ public function getTestGulpfileDataProvider() 'test1', 'test2', 'test3', + 'test4', ]); } diff --git a/test/data/test4.js b/test/data/test4.js new file mode 100644 index 0000000..d0a2838 --- /dev/null +++ b/test/data/test4.js @@ -0,0 +1,111 @@ +const {src, dest, parallel, watch} = require("gulp"); +const sass = require("gulp-sass"); +const minifyCSS = require("gulp-csso"); +const concat = require("gulp-concat"); +const uglify = require('gulp-uglify'); + +const main_css_src = [ + "foo.scss", + "bar/baz.scss" +]; +exports.main_css = function () { + return src(main_css_src, {sourcemaps: true}) + .pipe(concat("main.min.css")) + .pipe(sass({ + "includePaths": [ + "awesome-css-module" + ] + })) + .pipe(minifyCSS()) + .pipe(dest("public/static/css", {sourcemaps: "."})); +}; +exports.main_css_watch = function () { + watch(main_css_src, function (cb) { + exports.main_css(); + cb(); + }); +}; + +const main_js_src = [ + "script.js", + "stuff/**/*.js" +]; +exports.main_js = function () { + return src(main_js_src, {sourcemaps: true}) + .pipe(concat("main.min.js")) + .pipe(uglify()) + .pipe(dest("public/static/js", {sourcemaps: "."})); +}; +exports.main_js_watch = function () { + watch(main_js_src, function (cb) { + exports.main_js(); + cb(); + }); +}; + +const main_other_src = [ + "foo.png", + "bar/**/*.jpg" +]; +exports.main_other = function () { + return src(main_other_src) + .pipe(dest("public/static")); +}; +exports.main_other_watch = function () { + watch(main_other_src, function (cb) { + exports.main_other(); + cb(); + }); +}; + +exports.main = parallel(exports.main_css, exports.main_js, exports.main_other); +exports.main_watch = parallel(exports.main_css_watch, exports.main_js_watch, exports.main_other_watch); + +const admin_css_src = [ + "foo.scss", + "bar/admin.scss" +]; +exports.admin_css = function () { + return src(admin_css_src, {sourcemaps: true}) + .pipe(concat("admin.min.css")) + .pipe(sass()) + .pipe(minifyCSS()) + .pipe(dest("public/static/css", {sourcemaps: "."})); +}; +exports.admin_css_watch = function () { + watch(admin_css_src, function (cb) { + exports.admin_css(); + cb(); + }); +}; + +const admin_js_src = [ + "admin.js" +]; +exports.admin_js = function () { + return src(admin_js_src, {sourcemaps: true}) + .pipe(concat("admin.min.js")) + .pipe(uglify()) + .pipe(dest("public/static/js", {sourcemaps: "."})); +}; +exports.admin_js_watch = function () { + watch(admin_js_src, function (cb) { + exports.admin_js(); + cb(); + }); +}; + +exports.admin = parallel(exports.admin_css, exports.admin_js); +exports.admin_watch = parallel(exports.admin_css_watch, exports.admin_js_watch); + +exports.css = parallel(exports.main_css, exports.admin_css); +exports.css_watch = parallel(exports.main_css_watch, exports.admin_css_watch); + +exports.js = parallel(exports.main_js, exports.admin_js); +exports.js_watch = parallel(exports.main_js_watch, exports.admin_js_watch); + +exports.other = parallel(exports.main_other); +exports.other_watch = parallel(exports.main_other_watch); + +exports.default = parallel(exports.css, exports.js, exports.other); +exports.watch = parallel(exports.css_watch, exports.js_watch, exports.other_watch); diff --git a/test/data/test4.json b/test/data/test4.json new file mode 100644 index 0000000..a832ccc --- /dev/null +++ b/test/data/test4.json @@ -0,0 +1,30 @@ +{ + "main": { + "css": [ + "foo.scss", + "bar/baz.scss" + ], + "js": [ + "script.js", + "stuff/**/*.js" + ], + "other": [ + "foo.png", + "bar/**/*.jpg" + ], + "sass_options": { + "includePaths": [ + "awesome-css-module" + ] + } + }, + "admin": { + "css": [ + "foo.scss", + "bar/admin.scss" + ], + "js": [ + "admin.js" + ] + } +} diff --git a/view/gulpfile.js.php b/view/gulpfile.js.php index 9ec5ea2..1e71911 100644 --- a/view/gulpfile.js.php +++ b/view/gulpfile.js.php @@ -14,14 +14,18 @@ const concat = require("gulp-concat"); const uglify = require('gulp-uglify'); - $paths) : ?> - + $portalConfig) : ?> + -const _css_src = ; +const _css_src = ; exports._css = function () { return src(_css_src, {sourcemaps: true}) .pipe(concat()) - .pipe(sass()) + .pipe(sass()) .pipe(minifyCSS()) .pipe(dest("public/static/css", {sourcemaps: "."})); }; @@ -33,9 +37,9 @@ }; - + -const _js_src = ; +const _js_src = ; exports._js = function () { return src(_js_src, {sourcemaps: true}) .pipe(concat(".min.js")) @@ -50,9 +54,9 @@ }; - + -const _other_src = ; +const _other_src = ; exports._other = function () { return src(_other_src) .pipe(dest("public/static")); @@ -67,13 +71,13 @@ exports. = parallel(); exports._watch = parallel();