Giter Club home page Giter Club logo

Comments (4)

t32k avatar t32k commented on July 18, 2024

Please use this code after fork in your development.

module.exports = function (grunt) {
  grunt.registerMultiTask('csscomb', 'Sorting CSS properties in specific order.', function () {

    var Comb = require('csscomb'),
        path = require('path'),
        defaultConfig = require('../node_modules/csscomb/.csscomb.json');

    // Get config file from task's options:
    var config = grunt.task.current.options().sortOrder;

    // Check if config file is set and exists. If not, use default one:
    if (config && grunt.file.exists(config)) {
      grunt.log.ok('Using custom config file "' + config + '"...');
      config = grunt.file.readJSON(config);
    } else {
      config = defaultConfig;
    }

    this.files.forEach(function(f) {

      // Create a new instance of csscomb and configure it:
      var comb = new Comb();
      comb.configure(config);

      var destDir = path.dirname(f.dest);
      var ext = path.extname(f.dest);
      var targetStr = path.basename(f.dest, ext);

      f.src.filter(function(filepath) {
        // Warn on and remove invalid source files (if nonull was set).
        if (!grunt.file.exists(filepath)) {
          grunt.log.warn('Source file "' + filepath + '" not found.');
          return false;
        } else {
          return true;
        }
      }).forEach(function(src){

        var fileName = path.basename(src, ext);
        var replacedName = targetStr.replace(/\*/, fileName);
        var fileDest = destDir + '/'+ replacedName + ext;

        // Get CSS from a source file:
        var css = grunt.file.read(src);

        // Comb it:
        grunt.log.ok('Sorting file "' + src + '"...');
        var combed = comb.processString(css);
        grunt.file.write(fileDest, combed);

      });
    });
  });
};

You can specify as follows.

csscomb: {
  main: {
    files: {
      'test/fixtures/resorted_*.css': ['test/fixtures/*.css'],
    }
  }
}

from grunt-csscomb.

t32k avatar t32k commented on July 18, 2024

@johnstrawserjr

Sorry, we can do using dynamic mapping more easily. Try it 👍

https://github.com/csscomb/grunt-csscomb#dynamic-mappings

from grunt-csscomb.

iabw avatar iabw commented on July 18, 2024

Just a note on the dynamic mapping - I couldn't get it to work using dynamic mapping, but this setup worked -

    csscomb: {
        default: {
            options: {
                config: '.csscomb.json',
            },
            files: [{
                expand: true,
                cwd: 'assets/css/',
                src: ['**/*.css','!**/frameworks/**/*.css'],
                dest: 'assets/css/',
                ext: '.css'
            }]
        }
    }

from grunt-csscomb.

johanroug avatar johanroug commented on July 18, 2024

Thanks #iabw

from grunt-csscomb.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.