Code Monkey home page Code Monkey logo

css-url-versioner's Introduction

CSS Url Versioner NPM version Build Status Coveralls Status Code Climate Status

A node package for css url versioner

Getting Started

Install:

npm install --save-dev css-url-versioner

How to use:

var cssVersioner = require('css-url-versioner');

fs.readFile('test/css/test.css', 'utf8', function (err, data) {
    var newCss = cssVersioner({
        content: data
    });
    console.log(newCss.output);
});

or

var cssVersioner = require('css-url-versioner');
var data = '.some_selector{background-image: url("img/sprite.png");}';

var cssVersioned = cssVersioner({
    content: data
});

console.log(cssVersioned.output);

//logs: '.some_selector{background-image: url("img/sprite.png?v=2014111");}';

Options:

content

Required: true

Here go the css content we want versioning

{content: '.some_selector{background-image: url("img/sprite.png");}'}

variable:

Default: v

Here go the variable of our version, for '?myVariable=yyyymmdd'

{variable: 'myVariable'}

version:

Default: yyyymmdd

Here you go a custom version if you so desire, but if we do not put this key, then the default version will be the current date.

{version: '0.0.2'}

lastcommit:

Default: false

If we want that version to be our short version of last commit in git, configured 'lastcommit' to true.

{lastcommit: true}

Examples

lastcommit: true

var cssVersioner = require('css-url-versioner');
var data = '.some_selector{background-image: url("img/sprite.png");}';

var cssVersioned = cssVersioner({
    content: data,
    lastcommit: true
});

console.log(cssVersioned.output);

//logs: '.some_selector{background-image: url("img/sprite.png?v=dc31e29");}';

lastcommit: true and variable: 'myVersion'

var cssVersioner = require('css-url-versioner');
var data = '@font-face{ 
    			font-family: 'gotham'; 
				src: url("fonts/gotham.svg#gotham") format('svg');
			}';

var cssVersioned = cssVersioner({
    content: data,
    variable: 'myVersion'
    lastcommit: true
});

console.log(cssVersioned.output);

//logs: '@font-face{ font-family: 'gotham'; src: url("fonts/gotham.svg?myVersion=dc31e29#gotham") format('svg'); }';

version: Math.random()

var cssVersioner = require('css-url-versioner');
var data = '.some_selector{background-image: url("img/sprite.png");}';

var cssVersioned = cssVersioner({
    content: data,
    version: Math.random()
});

console.log(cssVersioned.output);

//logs: '.some_selector{background-image: url("img/sprite.png?v=0.82140917");}';

css-url-versioner's People

Contributors

geyser avatar jansanchez avatar victorjsv avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

css-url-versioner's Issues

error al usar una urls sin extensión

Al usar una url sin extensión, se corta la ejecución del paquete.

por ejemplo al usar un estilo así:

.home-company{
    color:#fff;
    background:url("iconLayout") helpCode no-repeat
}

Conflicto al usar gulp-stylus y css-url-versioner

Actualmente tengo mi tarea gulp css

gulp.task('css', function () {
    return gulp.src(pathStylesFiles, { base : path.frontend.pre_css })
      .pipe(plugins.stylus({
        compress: config.prod,
        use     : [rupture(), jeet(), nib()],
        import  : ['jeet','nib']
      }))
      .pipe(plugins.urlVersion({lastcommit: true}))
      .pipe(gulp.dest(path.dest.css));
});

Al compilar en ocasiones me devuelve un error:
Potentially unhandled rejection [2] Error: no writecb in Transform class

Estuve depurando en el archivo _stream_transform.js, que está en la ruta: /node_modules/gulp-stylus/through2/readable-stream/_stream_transform.js y agregué dos logs en la función TransformState

function TransformState(stream) {
  this.afterTransform = function(er, data) {
    console.log("ERROR_CONSOLE", er)
    console.log("DATA_CONSOLE", data)
    return afterTransform(stream, er, data);
  };
...

la cuál me salió el siguiente error:

ERROR_CONSOLE null
DATA_CONSOLE <File "ie\ie.css" <Buffer 2e 6c 74 2d 69 65 38 20 73 65 6c 65 63 74 7b 70 61 64 64 69 6e 67 3a 38 70 78 20 31 30 70 78 7d 2e 6c 74 2d 69 65 38 20 2e 72 65 67 69 73 74 65 72 5f ... >>
ERROR_CONSOLE { [Error: ENOENT, no such file or directory 'H:\flux\frontend\output']
  errno: -4058,
  code: 'ENOENT',
  path: 'H:\\flux\\frontend\\output',
  syscall: 'open',
  name: 'Error',
  message: 'ENOENT, no such file or directory \'H:\\flux\\frontend\\output\'',
  stack: 'Error: ENOENT, no such file or directory \'H:\\flux\\frontend\\output\'\n  at Error (native)\n  at Object.fs.openSync (fs.js:500:18)\n  at Object.fs.openSync (H:\\flux\\frontend\\node_modules\\preen\\node_modules\\bower\\node_modules\\rimraf\\node_modules\\graceful-fs\\graceful-fs.js:68:26)\n  at Object.fs.readFileSync (fs.js:352:15)\n  at [object Object].Execute.validateFlag (H:\\flux\\frontend\\node_modules\\gulp-css-url-versioner\\node_modules\\css-url-versioner\\dist\\package\\lib\\execute.js:56:22)\n  at [object Object].Execute.readFile (H:\\flux\\frontend\\node_modules\\gulp-css-url-versioner\\node_modules\\css-url-versioner\\dist\\package\\lib\\execute.js:51:8)\n  at [object Object].Execute.runCommand (H:\\flux\\frontend\\node_modules\\gulp-css-url-versioner\\node_modules\\css-url-versioner\\dist\\package\\lib\\execute.js:35:8)\n  at [object Object].CssUrlVersioner.getLastCommit (H:\\flux\\frontend\\node_modules\\gulp-css-url-versioner\\node_modules\\css-url-versioner\\dist\\package\\lib\\css-url-versioner.js:59:20)\n  at [object Object].CssUrlVersioner.generateVersion (H:\\flux\\frontend\\node_modules\\gulp-css-url-versioner\\node_modules\\css-url-versioner\\dist\\package\\lib\\css-url-versioner.js:51:10)\n  at new CssUrlVersioner (H:\\flux\\frontend\\node_modules\\gulp-css-url-versioner\\node_modules\\css-url-versioner\\dist\\package\\lib\\css-url-versioner.js:28:8)\n  at new module.exports (H:\\flux\\frontend\\node_modules\\gulp-css-url-versioner\\node_modules\\css-url-versioner\\dist\\package\\index.js:22:21)\n  at DestroyableTransform._transform (H:\\flux\\frontend\\node_modules\\gulp-css-url-versioner\\dist\\package\\lib\\gulp-css-url-versioner.js:42:16)\n  at DestroyableTransform.Transform._read (H:\\flux\\frontend\\node_modules\\gulp-css-url-versioner\\node_modules\\through2\\node_modules\\readable-stream\\lib\\_stream_transform.js:184:10)\n  at DestroyableTransform.Transform._write (H:\\flux\\frontend\\node_modules\\gulp-css-url-versioner\\node_modules\\through2\\node_modules\\readable-stream\\lib\\_stream_transform.js:172:12)\n  at doWrite (H:\\flux\\frontend\\node_modules\\gulp-css-url-versioner\\node_modules\\through2\\node_modules\\readable-stream\\lib\\_stream_writable.js:237:10)\n  at writeOrBuffer (H:\\flux\\frontend\\node_modules\\gulp-css-url-versioner\\node_modules\\through2\\node_modules\\readable-stream\\lib\\_stream_writable.js:227:5)\n  at DestroyableTransform.Writable.write (H:\\flux\\frontend\\node_modules\\gulp-css-url-versioner\\node_modules\\through2\\node_modules\\readable-stream\\lib\\_stream_writable.js:194:11)\n  at DestroyableTransform.ondata (H:\\flux\\frontend\\node_modules\\gulp-stylus\\node_modules\\through2\\node_modules\\readable-stream\\lib\\_stream_readable.js:574:20)\n  at DestroyableTransform.emit (events.js:107:17)\n  at readableAddChunk (H:\\flux\\frontend\\node_modules\\gulp-stylus\\node_modules\\through2\\node_modules\\readable-stream\\lib\\_stream_readable.js:198:16)\n  at DestroyableTransform.Readable.push (H:\\flux\\frontend\\node_modules\\gulp-stylus\\node_modules\\through2\\node_modules\\readable-stream\\lib\\_stream_readable.js:162:10)\n  at DestroyableTransform.Transform.push (H:\\flux\\frontend\\node_modules\\gulp-stylus\\node_modules\\through2\\node_modules\\readable-stream\\lib\\_stream_transform.js:135:32)\n  at afterTransform (H:\\flux\\frontend\\node_modules\\gulp-stylus\\node_modules\\through2\\node_modules\\readable-stream\\lib\\_stream_transform.js:83:12)\n  at TransformState.afterTransform (H:\\flux\\frontend\\node_modules\\gulp-stylus\\node_modules\\through2\\node_modules\\readable-stream\\lib\\_stream_transform.js:61:12)\n  at H:\\flux\\frontend\\node_modules\\gulp-stylus\\index.js:41:18\n  at tryCatchReject (H:\\flux\\frontend\\node_modules\\gulp-stylus\\node_modules\\accord\\node_modules\\when\\lib\\makePromise.js:845:30)\n  at runContinuation1 (H:\\flux\\frontend\\node_modules\\gulp-stylus\\node_modules\\accord\\node_modules\\when\\lib\\makePromise.js:804:4)\n  at Fulfilled.when (H:\\flux\\frontend\\node_modules\\gulp-stylus\\node_modules\\accord\\node_modules\\when\\lib\\makePromise.js:592:4)\n  at Pending.run (H:\\flux\\frontend\\node_modules\\gulp-stylus\\node_modules\\accord\\node_modules\\when\\lib\\makePromise.js:483:13)\n  at Scheduler._drain (H:\\flux\\frontend\\node_modules\\gulp-stylus\\node_modules\\accord\\node_modules\\when\\lib\\Scheduler.js:62:19)\n  at Scheduler.drain (H:\\flux\\frontend\\node_modules\\gulp-stylus\\node_modules\\accord\\node_modules\\when\\lib\\Scheduler.js:27:9)\n  at process._tickDomainCallback (node.js:381:11)\n',
  showStack: false,
  showProperties: true,
  plugin: 'gulp-stylus' }
DATA_CONSOLE undefined
Potentially unhandled rejection [2] Error: no writecb in Transform class
  at afterTransform (H:\flux\frontend\node_modules\gulp-stylus\node_modules\through2\node_modules\readable-stream\lib\_stream_transform.js:77:33)
  at TransformState.afterTransform (H:\flux\frontend\node_modules\gulp-stylus\node_modules\through2\node_modules\readable-stream\lib\_stream_transform.js:61:12)
  at H:\flux\frontend\node_modules\gulp-stylus\index.js:46:16
  at tryCatchReject (H:\flux\frontend\node_modules\gulp-stylus\node_modules\accord\node_modules\when\lib\makePromise.js:845:30)
  at runContinuation1 (H:\flux\frontend\node_modules\gulp-stylus\node_modules\accord\node_modules\when\lib\makePromise.js:804:4)
  at Rejected.when (H:\flux\frontend\node_modules\gulp-stylus\node_modules\accord\node_modules\when\lib\makePromise.js:625:4)
  at Pending.run (H:\flux\frontend\node_modules\gulp-stylus\node_modules\accord\node_modules\when\lib\makePromise.js:483:13)
  at Scheduler._drain (H:\flux\frontend\node_modules\gulp-stylus\node_modules\accord\node_modules\when\lib\Scheduler.js:62:19)
  at Scheduler.drain (H:\flux\frontend\node_modules\gulp-stylus\node_modules\accord\node_modules\when\lib\Scheduler.js:27:9)
  at process._tickDomainCallback (node.js:381:11)

Porfavor tu ayuda para solucionar este problema.
Gracias!.

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.