Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
parser.parse(lessContent, function (error, tree) {
if (error) {
less.writeError(error);
process.exit(1);
}
// Get output CSS
var outputText = tree.toCSS({compress: false});
// If the caller asked to output an AMD module rather than a plain CSS file, add define() wrapper around CSS.
// Assumes no single quotes or other weird characters, although double quotes for url("...") are OK.
if (/\.js$/.test(outputFile)) {
outputText = "define(function(){ return '\\\n" + outputText.replace(/\n/mg, "\\\n") + "'; } );\n";
}
// Now write out that CSS as an AMD module
console.log("writing:", outputFile);
var fd = fs.openSync(outputFile, "w");
fs.write(fd, outputText, 0, "utf-8", function (f) {
this.emit( 'parseError', file, output );
less.writeError( err, { color: true } );
this.parsePending--;
} else {
var css,
parseError = false;
// Process less tree to css
try {
css = tree.toCSS({
compress: this.options.compress
});
} catch ( e ) {
this.emit( 'parseError', file, output );
less.writeError( e, { color: true } );
this.parsePending--;
parseError = true;
}
var outputPath = this.getOuputPath(file, output);
// Write the output file
if ( !parseError ) {
fs.writeFile( this.getAbsolutePath( outputPath ), css, "utf8", function( err ) {
if ( err ) {
this.emit( 'error', { message: 'Could not write file "' + outputPath + '"' } );
} else {
pending.erase( file );
this.emit( 'parseComplete', file, outputPath, pending.length === 0 );
}
if ( --this.parsePending === 0 ) {
less.render(data.toString('utf8'), opts, function(err, output) {
if (err) {
if (options.debug) {
less.writeError(err);
}
return res.sendStatus(500);
}
// Store in cache
if (options.cache) {
cache[src] = output.css;
}
res.set('Content-Type', 'text/css');
res.send(output.css);
});
});
lessFiles.forEach(function(a){console.log("=== "+a);fs.readFile(a,"utf-8",function(b,c){b&&(console.error("lessc: "+b.message),process.exit(1));(new less.Parser({paths:[path.dirname(a)],optimization:options.optimization,filename:a})).parse(c,function(b,c){if(b)less.writeError(b,options),process.exit(1);else try{var d=c.toCSS({compress:options.compress}),e=a.replace(".less",".css");fd=fs.openSync(e,"w");fs.writeSync(fd,d,0,"utf8")}catch(f){less.writeError(f,options),process.exit(2)}})})});
parser.parse(lessContent, function(error, tree){
if(error){
less.writeError(error);
process.exit(1);
}
var fd = fs.openSync(outputFile, "w");
fs.write(fd, tree.toCSS({compress: false}).replace(/\n/g, "\r\n"), 0, "utf-8", function(f){
fs.close(fd);
console.log("writing:", outputFile);
endProcess();
});
});
}
new(less.Parser)(options).parse(data, function (err, tree) {
if (err) {
less.writeError(err, options);
process.exit(1);
} else {
try {
css = tree.toCSS({ compress: 1 });
fs.writeFileSync(cssPath,css);
} catch (e) {
less.writeError(e, options);
process.exit(2);
}
}
});
parser.parse(data, function (err, root) {
if (err) {
less.writeError(err, options);
return callback(err);
}
try {
callback(null, root.toCSS(options));
}
catch (e) {
less.writeError(e, options);
callback(e);
}
});
}
}, function(error) {
less.writeError(error, options);
});
};