From 202380f7124d9e324ab861dba74c6fb99131bf9b Mon Sep 17 00:00:00 2001 From: Vince Salvino Date: Fri, 24 Sep 2021 15:35:01 -0400 Subject: [PATCH] Fix sass->css output, use system paths. --- .gitignore | 1 + gulpfile.js/config.js | 20 ++++++++++---------- gulpfile.js/lib/normalize-path.js | 13 ------------- gulpfile.js/lib/rename-src-to-dest-scss.js | 20 ++++++++++++++++++++ gulpfile.js/lib/rename-src-to-dest.js | 10 +++++----- gulpfile.js/tasks/styles.js | 16 ++++------------ 6 files changed, 40 insertions(+), 40 deletions(-) delete mode 100644 gulpfile.js/lib/normalize-path.js create mode 100644 gulpfile.js/lib/rename-src-to-dest-scss.js diff --git a/.gitignore b/.gitignore index 825ae61b8a..e567ce60fc 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,7 @@ /wagtail.egg-info/ /docs/_build/ /.tox/ +/.venv /venv /node_modules/ npm-debug.log* diff --git a/gulpfile.js/config.js b/gulpfile.js/config.js index 9b4eb36e55..6377b98799 100644 --- a/gulpfile.js/config.js +++ b/gulpfile.js/config.js @@ -23,16 +23,16 @@ App.prototype.scssSources = function() { // All the Wagtail apps that contain static files var apps = [ - new App('wagtail/admin', {'appName': 'wagtailadmin'}), - new App('wagtail/documents', {'appName': 'wagtaildocs'}), - new App('wagtail/embeds', {'appName': 'wagtailembeds'}), - new App('wagtail/images', {'appName': 'wagtailimages'}), - new App('wagtail/search', {'appName': 'wagtailsearch'}), - new App('wagtail/snippets', {'appName': 'wagtailsnippets'}), - new App('wagtail/users', {'appName': 'wagtailusers'}), - new App('wagtail/contrib/styleguide', {'appName': 'wagtailstyleguide'}), - new App('wagtail/contrib/settings', {'appName': 'wagtailsettings'}), - new App('wagtail/contrib/modeladmin', {'appName': 'wagtailmodeladmin'}), + new App(path.join('wagtail', 'admin'), {'appName': 'wagtailadmin'}), + new App(path.join('wagtail', 'documents'), {'appName': 'wagtaildocs'}), + new App(path.join('wagtail', 'embeds'), {'appName': 'wagtailembeds'}), + new App(path.join('wagtail', 'images'), {'appName': 'wagtailimages'}), + new App(path.join('wagtail', 'search'), {'appName': 'wagtailsearch'}), + new App(path.join('wagtail', 'snippets'), {'appName': 'wagtailsnippets'}), + new App(path.join('wagtail', 'users'), {'appName': 'wagtailusers'}), + new App(path.join('wagtail', 'contrib', 'styleguide'), {'appName': 'wagtailstyleguide'}), + new App(path.join('wagtail', 'contrib', 'settings'), {'appName': 'wagtailsettings'}), + new App(path.join('wagtail', 'contrib', 'modeladmin'), {'appName': 'wagtailmodeladmin'}), ]; module.exports = { diff --git a/gulpfile.js/lib/normalize-path.js b/gulpfile.js/lib/normalize-path.js deleted file mode 100644 index 90aec19919..0000000000 --- a/gulpfile.js/lib/normalize-path.js +++ /dev/null @@ -1,13 +0,0 @@ -var quoteRegExp = function (str) { - return (str + '').replace(/[.?*+^$[\]\\(){}|-]/g, "\\$&"); -}; -var re = new RegExp(quoteRegExp(require("path").sep), "g"); - -/** - * Normalize path separators to forward slashes - * @param path A path in either Windows or POSIX format - * @returns {string} A path in POSIX format - */ -module.exports = function (path) { - return ("" + path).replace(re, "/"); -}; diff --git a/gulpfile.js/lib/rename-src-to-dest-scss.js b/gulpfile.js/lib/rename-src-to-dest-scss.js new file mode 100644 index 0000000000..a2d3a35038 --- /dev/null +++ b/gulpfile.js/lib/rename-src-to-dest-scss.js @@ -0,0 +1,20 @@ +var path = require('path'); +var rename = require('gulp-rename'); +var config = require('../config'); + +/** + * Returns a configured gulp-rename to pipe from asset sources to dest. + * Usage: .pipe(renameSrcToDestScss()) + */ +var renameSrcToDestScss = function(log) { + return rename(function(filePath) { + if (log) console.log(filePath.dirname + path.sep + filePath.basename + filePath.extname); + filePath.dirname = filePath.dirname.replace( + path.sep + config.srcDir + path.sep, + path.sep + config.destDir + path.sep + ).replace(path.sep + "scss", path.sep + "css"); + if (log) console.log(filePath.dirname); + }); +}; + +module.exports = renameSrcToDestScss; diff --git a/gulpfile.js/lib/rename-src-to-dest.js b/gulpfile.js/lib/rename-src-to-dest.js index 1bfe557822..14e465031e 100644 --- a/gulpfile.js/lib/rename-src-to-dest.js +++ b/gulpfile.js/lib/rename-src-to-dest.js @@ -1,6 +1,6 @@ +var path = require('path'); var rename = require('gulp-rename'); var config = require('../config'); -var normalizePath = require('../lib/normalize-path'); /** * Returns a configured gulp-rename to pipe from asset sources to dest. @@ -8,10 +8,10 @@ var normalizePath = require('../lib/normalize-path'); */ var renameSrcToDest = function(log) { return rename(function(filePath) { - if (log) console.log(filePath.dirname + '/' + filePath.basename + filePath.extname); - filePath.dirname = normalizePath(filePath.dirname).replace( - '/' + config.srcDir + '/', - '/' + config.destDir + '/'); + if (log) console.log(filePath.dirname + path.sep + filePath.basename + filePath.extname); + filePath.dirname = filePath.dirname.replace( + path.sep + config.srcDir + path.sep, + path.sep + config.destDir + path.sep); if (log) console.log(filePath.dirname); }); }; diff --git a/gulpfile.js/tasks/styles.js b/gulpfile.js/tasks/styles.js index 5f86619088..cdf41e95da 100644 --- a/gulpfile.js/tasks/styles.js +++ b/gulpfile.js/tasks/styles.js @@ -10,8 +10,8 @@ var sourcemaps = require('gulp-sourcemaps'); var size = require('gulp-size'); var config = require('../config'); var simpleCopyTask = require('../lib/simplyCopy'); -var normalizePath = require('../lib/normalize-path'); var renameSrcToDest = require('../lib/rename-src-to-dest'); +var renameSrcToDestScss = require('../lib/rename-src-to-dest-scss'); var gutil = require('gulp-util'); var flatten = function(arrOfArr) { @@ -61,7 +61,7 @@ gulp.task('styles:sass', function () { // its own Sass files that need to be compiled. var sources = flatten(config.apps.map(function(app) { return app.scssSources(); })); - return gulp.src(sources) + return gulp.src(sources, {base: '.'}) .pipe(config.isProduction ? gutil.noop() : sourcemaps.init()) .pipe(sass({ errLogToConsole: true, @@ -76,16 +76,8 @@ gulp.task('styles:sass', function () { ])) .pipe(size({ title: 'Wagtail CSS' })) .pipe(config.isProduction ? gutil.noop() : sourcemaps.write()) - .pipe(gulp.dest(function (file) { - // e.g. wagtailadmin/scss/core.scss -> wagtailadmin/css/core.css - // Changing the suffix is done by Sass automatically - return normalizePath(file.base) - .replace( - '/' + config.srcDir + '/', - '/' + config.destDir + '/' - ) - .replace('/scss', '/css'); - })) + .pipe(renameSrcToDestScss()) + .pipe(gulp.dest(".")) .on('error', gutil.log); });