CSScomb Core: postprocessor in 15 mins

Этот пост на русском

Want to write your own postprocessor but don’t want to spend much time?
Just fork a special template and modify it.

This summer CSScomb.js turns 1 year.
We have spent this time working on amazing project which is now easy to maintain and easy to scale.
Today I’d love to share a part of our work which will help you create your own projects.

CSScomb Core

The heart of our tool is now available as a separate module — CSScomb Core.
You can use it to write different postprocessors.
I’ve made a template repo to show you how simple it is.
Just fork it and play with code.

What’s inside

  1. Parser with preprocessors support

    Our tool is based on Gonzales PE.
    This parser can process not only CSS, but preprocessors too: LESS, Sass and SCSS.

  2. API to work with configs

    Sometimes postprocessors need to be configured.
    CSScomb has 25 settings, for example.
    As a user you can write a config file to set the options you need.
    And it’s easy to apply that config with CSScomb Core:

    var config = require(‘path/to/config.json’);

  3. API to write and use plugins

    Every option is an independent plugin.
    To use a plugin, just put it in a special directory (see Flip Comb for an example) or apply it with two lines of code:

    var option = require(‘path/to/option’);

  4. API to work with files

    Whether you want to process a single file or a whole directory — it’s easy to get done.
    We take care of syntax detection and working with file system:

    core.processString(string, syntax);

Get started

There is a tiny template I’ve made to help you get started.
The postprocessor is called Flip Comb and all it does is replace comments in CSS files with / (╯°□°)╯︵ ┻━┻ /.
It took me 15 minutes to write those two files.
The result is pretty useless, but you can learn something from it.

Just fork the repo and play around.
When you are ready to go further, read docs for more information.
Have fun!