Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

executable file 117 lines (92 sloc) 3.094 kb
#! /usr/bin/env node
/**
* UglifyCSS
* Port of YUI CSS Compressor to NodeJS
* Author: Franck Marcia - https://github.com/fmarcia
* MIT licenced
*/
/**
* cssmin.js
* Author: Stoyan Stefanov - http://phpied.com/
* This is a JavaScript port of the CSS minification tool
* distributed with YUICompressor, itself a port
* of the cssmin utility by Isaac Schlueter - http://foohack.com/
* Permission is hereby granted to use the JavaScript version under the same
* conditions as the YUICompressor (original YUICompressor note below).
*/
/**
* YUI Compressor
* http://developer.yahoo.com/yui/compressor/
* Author: Julien Lecomte - http://www.julienlecomte.net/
* Copyright (c) 2011 Yahoo! Inc. All rights reserved.
* The copyrights embodied in the content of this file are licensed
* by Yahoo! Inc. under the BSD (revised) open source license.
*/
var uglifycss = require("./");
// Print usage
function usage() {
console.log(
"Usage: uglifycss [options] file1.css [file2.css [...]] > output\n" +
"options:\n" +
"--max-line-len x add a newline every x characters; 0 means no newline; default: 5000\n" +
"--expand-vars expand variables\n" +
"--ugly-comments remove newlines within preserved comments\n" +
"--cute-comments preserve newlines within and around preserved comments"
);
}
// Transform strings like "the-parameter" to "theParameter"
function par2var(param) {
return param.replace(/-(.)/g, function (ignore, character) {
return character === "-" ? "" : character.toUpperCase();
});
}
// Parse parameters from command line
function parseArguments(argv) {
var params = {
options: uglifycss.defaultOptions,
files: []
};
var len = argv.length;
for (var index = 2; index < len; index += 1) {
// last argument is always a file
if (index === len - 1) {
params.files.push(argv[index]);
} else {
var varia = par2var(argv[index]);
// boolean parameters
if (typeof params.options[varia] === "boolean") {
params.options[varia] = true;
// integer parameter
} else if (typeof params.options[varia] !== "undefined") {
params.options[varia] = parseInt(argv[index + 1], 10);
index += 1;
// file
} else {
params.files.push(argv[index]);
}
}
}
return params;
}
// Entry
(function main() {
var params = parseArguments(process.argv);
var nFiles = params.files.length;
var stdin = process.stdin;
var content = "";
// . files
if (nFiles) {
console.log(uglifycss.processFiles(params.files, params.options));
// . usage
} else if (stdin.isTTY) {
usage();
// . stdin
} else {
stdin.on("data", function (part) {
content += part;
});
stdin.on("end", function () {
console.log(uglifycss.processString(content, params.options));
});
}
}());
Jump to Line
Something went wrong with that request. Please try again.