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) {
err.message += ':\n' + err.extract.join('\n');
} else {
// Ensure message ends with a dot.
if (!/\.$/.test(err.message)) { err.message += '.'; }
}
if (err.filename === 'input') {
err.filename = filename;
}
return err;
}
var parseOptions = {
paths: [Path.dirname(filename)]//,
// filename: filename
},
parser = new less.Parser(parseOptions),
results = [];
parser.parse(body, function (err, tree) {
if (err) {
return callback(undefined, [prepareLessError(err)]);
}
try {
// Compiling to CSS will throw in case of undefined @variables etc.:
tree.toCSS();
} catch (e) {
return callback(undefined, [prepareLessError(e)]);
}
return callback(undefined, []);
});
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 ) {
// depending on the level of optimization.
if (that.optimization > 0) {
input = input.replace(/\/\*(?:[^*]|\*+[^\/*])*\*+\//g, function (comment) {
return that.optimization > 1 ? '' : comment.replace(/\n(\s*\n)+/g, '\n');
});
chunks = input.split(/^(?=\n)/mg);
} else {
chunks = [input];
}
inputLength = input.length;
// Start with the primary rule.
// The whole syntax tree is held under a Ruleset node,
// with the `root` property set to true, so no `{}` are
// output. The callback is called when the input is parsed.
root = new(tree.Ruleset)([], $(this.parsers.primary));
root.root = true;
root.toCSS = (function (toCSS) {
var line, lines, column;
return function (options) {
options = options || {};
try {
var css = toCSS.call(this, [], {
frames: [],
compress: options.compress || false
});
if (options.compress) {
return css.replace(/(\s)+/g, "$1");
} else {
return css;
// depending on the level of optimization.
if (that.optimization > 0) {
input = input.replace(/\/\*(?:[^*]|\*+[^\/*])*\*+\//g, function (comment) {
return that.optimization > 1 ? '' : comment.replace(/\n(\s*\n)+/g, '\n');
});
chunks = input.split(/^(?=\n)/mg);
} else {
chunks = [input];
}
inputLength = input.length;
// Start with the primary rule.
// The whole syntax tree is held under a Ruleset node,
// with the `root` property set to true, so no `{}` are
// output. The callback is called when the input is parsed.
root = new(tree.Ruleset)([], $(this.parsers.primary));
root.root = true;
root.toCSS = (function (toCSS) {
var line, lines, column;
return function () {
try {
return toCSS.call(this);
} catch (e) {
lines = input.split('\n');
line = (input.slice(0, e.index).match(/\n/g) || "").length + 1;
for (var n = e.index, column = -1;
n >= 0 && input.charAt(n) !== '\n';
n--) { column++ }
throw {
function saveLess (file, done) {
var lessCode = fs.readFileSync(file.filename, 'utf8')
less.render(lessCode, {
paths: [ // Specify search paths for @import directives
root,
path.join(opts.main, 'node_modules', 'bleh', 'shared')
],
filename: file.name, // Specify a filename, for better error messages
compress: false // Minify CSS output
}, function (err, cssCode) {
if (err) {
return done(err)
}
var cachebust = MD5(cssCode.css).substring(0, 8)
var name = file.filename.replace(root + path.sep, '')
var view = getViewName({
name: name.replace('.less', '')
})
var uri = assetsUri + view + '.css'
Site.prototype._compile_templates = function(){
// var templates = this.app.params.templates;
//
// for ( var template in templates ) {
// var file = fs.readFileSync( path.join( this.app.base_dir, template ), 'utf8' );
// var compiled = this.dust.compile( file, path.basename( template, '.html' ) );
// var file_path = path.join( this.app.base_dir, templates[ template ], path.basename( template, '.html' ) + '.js' );
// if ( fs.existsSync( file_path ) ) fs.unlinkSync( file_path );
// var fd = fs.openSync( file_path, 'a', 0666 );
// fs.writeSync( fd, compiled, null, 'utf8' );
// fs.closeSync( fd );
// }
var style = fs.readFileSync( path.join( this.app.base_dir, 'static/css/style.less' ), 'utf8' );
var parser = new less.Parser({
paths: [ path.join( this.app.base_dir, 'node_modules/twitter-bootstrap/less/' ) ]//, // Specify search paths for @import directives
// filename: 'style.less' // Specify a filename, for better error messages
});
var self = this;
parser.parse( style, function (e, tree) {
var css = tree.toCSS({ compress: true }); // Minify CSS output
var css_file = path.join( self.app.base_dir, 'static/css/style.css' );
if ( fs.existsSync( css_file ) ) fs.unlinkSync( css_file );
var fd = fs.openSync( css_file, 'a', 0666 );
fs.writeSync( fd, css, null, 'utf8' );
fs.closeSync( fd );
});
}
fs.readFile(srcPath, function(err, data){
if(err) return callback(err)
var dirs = [
path.dirname(srcPath),
path.dirname(path.resolve(projectPath, "public"))
]
var parser = new(less.Parser)({
paths: dirs, // Specify search paths for @import directives
filename: file // Specify a filename, for better error messages
})
parser.parse(data.toString(), function (err, tree) {
try{
var css = tree.toCSS({ compress: true })
callback(e, css)
}catch(e){
callback(e)
}
})
})
}
high.util.loopOverFolders([high.config._less_path], function(file_name, root_path) {
// LESS
if(file_name.match(/.less$/)){
var parser = new(less.Parser)({
paths: [high.config._less_path], // Specify search paths for @import directives
filename: file_name // Specify a filename, for better error messages
})
var file_contents = fs.readFileSync(root_path + file_name, {'encoding': 'utf8'});
parser.parse(file_contents, function(err, tree) {
if(err) {
log(err)
return
}
var less_config,
compiled_file_contents;
if(high.config.env === 'dev') {
less_config = high.config.less.dev;
} else {
less_config = high.config.less.prod;
grunt.fail.warn(wrapError(e, 'Generating @import paths failed.'));
}
}
if (typeof options.sourceMapBasepath === 'function') {
try {
options.sourceMapBasepath = options.sourceMapBasepath(srcFile);
} catch (e) {
grunt.fail.warn(wrapError(e, 'Generating sourceMapBasepath failed.'));
}
}
var css;
var srcCode = grunt.file.read(srcFile);
var parser = new less.Parser(_.pick(options, lessOptions.parse));
var additionalData = {
banner: options.banner
};
// Equivalent to --modify-vars option.
// Properties under options.modifyVars are appended as less variables
// to override global variables.
var modifyVarsOutput = parseVariableOptions(options['modifyVars']);
if (modifyVarsOutput) {
srcCode += '\n';
srcCode += modifyVarsOutput;
}
parser.parse(srcCode, function(parse_err, tree) {
if (parse_err) {
lessError(parse_err, srcFile);