Skip to content

Commit

Permalink
use stylefmt
Browse files Browse the repository at this point in the history
  • Loading branch information
masaakim committed Jul 7, 2016
1 parent 51b0d73 commit debf3c9
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 28 deletions.
29 changes: 20 additions & 9 deletions index.js
@@ -1,6 +1,6 @@
var gutil = require('gulp-util');
var through = require('through2');
var cssfmt = require('cssfmt');
var stylefmt = require('stylefmt');

module.exports = function (options) {
options = options || {};
Expand All @@ -12,17 +12,28 @@ module.exports = function (options) {
}

if (file.isStream()) {
cb(new gutil.PluginError('gulp-cssfmt', 'Streaming not supported'));
cb(new gutil.PluginError('gulp-stylefmt', 'Streaming not supported'));
return;
}

try {
file.contents = new Buffer(cssfmt.process(file.contents.toString()).toString());
this.push(file);
} catch (err) {
this.emit('error', new gutil.PluginError('gulp-cssfmt', err, {fileName: file.path}));
}
// try {
// file.contents = new Buffer(stylefmt.process(file.contents.toString()).toString());
// this.push(file);
// } catch (err) {
// this.emit('error', new gutil.PluginError('gulp-stylefmt', err, {fileName: file.path}));
// }

var self = this
stylefmt
.process(file.contents.toString())
.then(function (result) {
file.contents = new Buffer(result.css);
self.push(file);
cb();
})
.catch(function (err) {
this.emit('error', new gutil.PluginError('gulp-cssfmt', err, {fileName: file.path}));
});

cb();
});
};
14 changes: 7 additions & 7 deletions package.json
@@ -1,7 +1,7 @@
{
"name": "gulp-cssfmt",
"version": "0.3.0",
"description": "gulp plugin for CSSfmt",
"description": "gulp plugin for stylefmt",
"main": "index.js",
"scripts": {
"test": "mocha"
Expand All @@ -12,19 +12,19 @@
},
"keywords": [
"gulpplugin",
"cssfmt",
"stylefmt",
"css",
"format"
],
"author": "Masaaki Morishita",
"license": "MIT",
"dependencies": {
"cssfmt": "^0.6.0",
"gulp-util": "^3.0.6",
"through2": "^2.0.0"
"gulp-util": "^3.0.7",
"stylefmt": "^4.1.1",
"through2": "^2.0.1"
},
"devDependencies": {
"gulp": "^3.9.0",
"mocha": "^2.2.5"
"gulp": "^3.9.1",
"mocha": "^2.5.3"
}
}
32 changes: 20 additions & 12 deletions test/index.js
@@ -1,20 +1,28 @@
var fs = require('fs');
var assert = require('assert');
var gutil = require('gulp-util');
var cssfmt = require('cssfmt');
var gulpCssfmt = require('../');
var stylefmt = require('stylefmt');
var gulpStylefmt = require('../');

it('cssfmt', function (cb) {
var stream = gulpCssfmt();
it('stylefmt', function (cb) {
var stream = gulpStylefmt();
var cssFile = fs.readFileSync('test/fixtures/input.css', 'utf-8');
var output = cssfmt.process(cssFile);

stream.on('data', function (file) {
assert.equal(file.contents.toString(), output);
cb();
});
stylefmt
.process(cssFile)
.then(function (result) {
stream.on('data', function (file) {
assert.equal(file.contents.toString(), output);
});

stream.write(new gutil.File({
contents: new Buffer(cssFile)
}));

cb();
})
.catch(function (e) {
cb(e);
});

stream.write(new gutil.File({
contents: new Buffer(cssFile)
}));
});

0 comments on commit debf3c9

Please sign in to comment.