Removes less-rhino (broken for a long time) - Fixes #3241

This commit is contained in:
Matthew Dean
2018-07-01 20:01:41 -07:00
parent 29468bffcd
commit 46c39fac36
10 changed files with 0 additions and 1014 deletions

View File

@@ -154,8 +154,6 @@ module.exports = function (grunt) {
// Project configuration.
grunt.initConfig({
// Metadata required for build.
build: grunt.file.readYAML('build/build.yml'),
pkg: grunt.file.readJSON('package.json'),
meta: {
copyright: 'Copyright (c) 2009-<%= grunt.template.today("yyyy") %>',
@@ -228,24 +226,6 @@ module.exports = function (grunt) {
dist: {
src: '<%= browserify.browser.dest %>',
dest: 'dist/less.js'
},
// Rhino
rhino: {
options: {
banner: '/* Less.js v<%= pkg.version %> RHINO | <%= meta.copyright %>, <%= pkg.author.name %> <<%= pkg.author.email %>> */\n\n',
footer: '' // override task-level footer
},
src: ['<%= build.rhino %>'],
dest: 'dist/less-rhino.js'
},
// lessc for Rhino
rhinolessc: {
options: {
banner: '/* Less.js v<%= pkg.version %> RHINO | <%= meta.copyright %>, <%= pkg.author.name %> <<%= pkg.author.email %>> */\n\n',
footer: '' // override task-level footer
},
src: ['<%= build.rhinolessc %>'],
dest: 'dist/lessc-rhino.js'
}
},
@@ -466,13 +446,6 @@ module.exports = function (grunt) {
'uglify:dist'
]);
// Release Rhino Version (UNSUPPORTED)
grunt.registerTask('rhino', [
'browserify:rhino',
'concat:rhino',
'concat:rhinolessc'
]);
// Create the browser version of less.js
grunt.registerTask('browsertest-lessjs', [
'browserify:browser',

View File

@@ -1,347 +0,0 @@
import groovy.io.FileType
import org.apache.tools.ant.taskdefs.condition.Os
import org.gradle.api.tasks.Exec
buildscript {
repositories {
mavenCentral()
jcenter()
}
dependencies {
classpath 'com.eriwen:gradle-js-plugin:1.8.0'
classpath 'com.moowork.gradle:gradle-grunt-plugin:0.2'
}
}
apply plugin: 'js'
apply plugin: 'grunt'
repositories {
mavenCentral()
}
configurations {
rhino
}
dependencies {
rhino 'org.mozilla:rhino:1.7R4'
}
project.ext {
packageProps = new groovy.json.JsonSlurper().parseText(new File("package.json").toURL().text)
failures = 0;
rhinoTestSrc = "out/rhino-test-${packageProps.version}.js"
testSrc = 'test/less'
testOut = 'out/test'
}
task runGruntRhino(type: GruntTask) {
gruntArgs = "rhino"
}
combineJs {
dependsOn runGruntRhino
source = ["dist/less-rhino-${packageProps.version}.js", "test/rhino/test-header.js","dist/lessc-rhino-${packageProps.version}.js"]
dest = file(rhinoTestSrc)
}
task testRhino(type: AllRhinoTests) {
// dependsOn 'testRhinoBase'
dependsOn 'testRhinoBase', 'testRhinoErrors', 'testRhinoLegacy', 'testRhinoStaticUrls', 'testRhinoCompression', 'testRhinoDebugAll', 'testRhinoDebugComments', 'testRhinoDebugMediaquery', 'testRhinoNoJsError', 'testRhinoSourceMap'
}
task testRhinoBase(type: RhinoTest) {
options = [ '--strict-math=true', '--relative-urls' ]
}
task testRhinoDebugAll(type: DebugRhinoTest) {
options = [ '--strict-math=true', '--line-numbers=all' ]
testDir = 'debug' + fs
suffix = "-all"
}
task testRhinoDebugComments(type: DebugRhinoTest) {
options = [ '--strict-math=true', '--line-numbers=comments' ]
testDir = 'debug' + fs
suffix = "-comments"
}
task testRhinoDebugMediaquery(type: DebugRhinoTest) {
options = [ '--strict-math=true', '--line-numbers=mediaquery' ]
testDir = 'debug' + fs
suffix = "-mediaquery"
}
task testRhinoErrors(type: RhinoTest) {
options = [ '--strict-math=true', '--strict-units=true' ]
testDir = 'errors/'
expectErrors = true
}
task testRhinoChyby(type: RhinoTest) {
options = [ '--strict-math=true', '--strict-units=true' ]
testDir = 'chyby/'
// expectErrors = true
}
task testRhinoNoJsError(type: RhinoTest) {
options = [ '--strict-math=true', '--strict-units=true', '--no-js' ]
testDir = 'no-js-errors/'
expectErrors = true
}
task testRhinoLegacy(type: RhinoTest) {
testDir = 'legacy/'
}
task testRhinoStaticUrls(type: RhinoTest) {
options = [ '--strict-math=true', '--rootpath=folder (1)/' ]
testDir = 'static-urls/'
}
task testRhinoCompression(type: RhinoTest) {
options = [ '--compress=true' ]
testDir = 'compression/'
}
task testRhinoSourceMap(type: SourceMapRhinoTest) {
options = [ '--strict-math=true', '--strict-units=true']
testDir = 'sourcemaps/'
}
task setupTest {
dependsOn combineJs
doLast {
file(testOut).deleteDir()
}
}
task clean << {
file(rhinoTestSrc).delete()
file(testOut).deleteDir()
}
class SourceMapRhinoTest extends RhinoTest {
// helper to get the output map file
def getOutputMap(lessFile) {
def outFile = project.file(lessFile.path.replace('test/less', project.testOut).replace('.less', '.css'))
return project.file(outFile.path + ".map");
}
// callback to add SourceMap options to the options list
def postProcessOptions(options, lessFile) {
def outFile = getOutputMap(lessFile)
project.file(outFile.parent).mkdirs()
options << "--source-map=${testDir}${lessFile.name.replace('.less','.css')}"
options << "--source-map-basepath=${lessRootDir}"
options << "--source-map-rootpath=testweb/"
options << "--source-map-output-map-file=${outFile}"
options
}
// Callback to validate output
def handleResult(exec, out, lessFile) {
def actualFile = getOutputMap(lessFile)
def expectedFile = project.file(projectDir + fs + "test" + fs + testDir + fs + lessFile.name.replace(".less", ".json"))
assert actualFile.text == expectedFile.text
}
}
class DebugRhinoTest extends RhinoTest {
def escapeIt(it) {
return it.replaceAll("\\\\", "\\\\\\\\").replaceAll("/", "\\\\/").replaceAll(":", "\\\\:").replaceAll("\\.", "\\\\.");
}
def globalReplacements(input, directory) {
def pDirectory = toPlatformFs(directory)
def p = lessRootDir + fs + pDirectory
def pathimport = p + toPlatformFs("import/")
def pathesc = escapeIt(p)
def pathimportesc = escapeIt(pathimport)
def result = input.replace("{path}", p).replace("{pathesc}", pathesc).replace("{pathimport}", pathimport)
return result.replace("{pathimportesc}", pathimportesc).replace("\r\n", "\n")
}
}
class RhinoTest extends DefaultTask {
RhinoTest() {
dependsOn 'setupTest'
}
def suffix = ""
def testDir = ''
def options = []
def expectErrors = false
def fs = File.separator;
def projectDir = toUpperCaseDriveLetter(System.getProperty("user.dir"));
def lessRootDir = projectDir + fs + "test" + fs + "less"
def toUpperCaseDriveLetter(path) {
if (path.charAt(1)==':' && path.charAt(2)=='\\') {
return path.substring(0,1).toUpperCase() + path.substring(1);
}
return path;
}
def toPlatformFs(path) {
return path.replace('\\', fs).replace('/', fs);
}
def expectedCssPath(lessFilePath) {
lessFilePath.replace('.less', "${suffix}.css").replace("${fs}less${fs}", "${fs}css${fs}");
}
def globalReplacements(input, directory) {
return input;
}
def stylize(str, style) {
def styles = [
reset : [0, 0],
bold : [1, 22],
inverse : [7, 27],
underline : [4, 24],
yellow : [33, 39],
green : [32, 39],
red : [31, 39],
grey : [90, 39]
];
return '\033[' + styles[style][0] + 'm' + str +
'\033[' + styles[style][1] + 'm';
}
// Callback for subclasses to make any changes to the options
def postProcessOptions(options, lessFile) {
options
}
// Callback to validate output
def handleResult(exec, out, lessFile) {
def actual = out.toString().trim()
def actualResult = project.file(lessFile.path.replace('test/less', project.testOut).replace('.less', '.css'))
project.file(actualResult.parent).mkdirs()
actualResult << actual
def expected
if (expectErrors) {
assert exec.exitValue != 0
expected = project.file(lessFile.path.replace('.less', '.txt')).text.trim().
replace('{path}', lessFile.parent + '/').
replace('{pathhref}', '').
replace('{404status}', '')
} else {
assert exec.exitValue == 0
def expectedFile = expectedCssPath(lessFile.path)
expected = project.file(expectedFile).text.trim()
expected = globalReplacements(expected, testDir)
}
actual=actual.trim()
actual = actual.replace('\r\n', '\n')
expected = expected.replace('\r\n', '\n')
actual = actual.replace("/","\\")
expected = expected.replace("/","\\")
// println "* actual *"
// println actual
// new File("actual.txt").write(actual)
// println "* expected *"
// println expected
// new File("expected.txt").write(expected)
assert actual == expected
actualResult.delete()
}
@TaskAction
def runTest() {
int testSuccesses = 0, testFailures = 0, testErrors = 0
project.file('test/less/' + testDir).eachFileMatch(FileType.FILES, ~/.*\.less/) { lessFile ->
println "lessfile: $lessFile"
if (!project.hasProperty('test') || lessFile.name.startsWith(project.test)) {
def out = new java.io.ByteArrayOutputStream()
def processedOptions = postProcessOptions([project.rhinoTestSrc, lessFile] + options, lessFile)
def execOptions = {
main = 'org.mozilla.javascript.tools.shell.Main'
// main = 'org.mozilla.javascript.tools.debugger.Main'
classpath = project.configurations.rhino
args = processedOptions
standardOutput = out
ignoreExitValue = true
}
println "rhinoTestSrc: ${project.rhinoTestSrc}"
try {
def exec = project.javaexec(execOptions)
handleResult(exec, out, lessFile)
testSuccesses++
println stylize(' ok', 'green')
}
catch (ex) {
println ex
println()
testErrors++;
}
catch (AssertionError ae) {
println stylize(' failed', 'red')
println ae
testFailures++
}
} else {
println stylize(' skipped', 'yellow')
}
}
println stylize(testSuccesses + ' ok', 'green')
println stylize(testFailures + ' assertion failed', testFailures == 0 ? 'green' : 'red')
println stylize(testErrors + ' errors', testErrors == 0 ? 'green' : 'red')
if (testFailures != 0 || testErrors != 0) {
project.failures++;
}
}
}
class AllRhinoTests extends DefaultTask {
AllRhinoTests() {
}
@TaskAction
def runTest() {
println stylize(project.failures + ' test suites failed', project.failures == 0 ? 'green' : 'red')
}
def stylize(str, style) {
def styles = [
reset : [0, 0],
bold : [1, 22],
inverse : [7, 27],
underline : [4, 24],
yellow : [33, 39],
green : [32, 39],
red : [31, 39],
grey : [90, 39]
];
return '\033[' + styles[style][0] + 'm' + str +
'\033[' + styles[style][1] + 'm';
}
}
class GruntTask extends Exec {
private String gruntExecutable = Os.isFamily(Os.FAMILY_WINDOWS) ? "grunt.cmd" : "grunt"
private String switches = "--no-color"
String gruntArgs = ""
public GruntTask() {
super()
this.setExecutable(gruntExecutable)
}
public void setGruntArgs(String gruntArgs) {
this.args = "$switches $gruntArgs".trim().split(" ") as List
}
}

View File

@@ -1,6 +0,0 @@
// amd.js
//
// Define Less as an AMD module.
if (typeof define === "function" && define.amd) {
define(function () { return less; } );
}

View File

@@ -18,12 +18,6 @@ lib_source_map: 'lib/source-map'
# =================================
# General
# =================================
prepend:
rhino: ['build/require-rhino.js', 'build/rhino-header.js', 'build/rhino-modules.js']
append:
amd: build/amd.js
rhino: <%= build.lib %>/rhino.js
# =================================
@@ -46,36 +40,6 @@ less:
browser : <%= build.lib %>/browser.js
source_map_output: <%= build.lib %>/source-map-output.js
# =================================
# Rhino build
# =================================
# <%= build.rhino %>
rhino:
# prepend utils
- <%= build.prepend.rhino %>
# core
- <%= build.less.parser %>
- <%= build.less.functions %>
- <%= build.less.colors %>
- <%= build.less.tree %>
- <%= build.less.treedir %> # glob all files
- <%= build.less.env %>
- <%= build.less.visitor %>
- <%= build.less.import_visitor %>
- <%= build.less.join %>
- <%= build.less.to_css_visitor %>
- <%= build.less.extend_visitor %>
- <%= build.less.source_map_output %>
- <%= build.source_map %>
# <%= build.rhinolessc %>
rhinolessc:
- <%= build.append.rhino %>
# =================================
# Tree files
# =================================

View File

@@ -1,12 +0,0 @@
//
// Stub out `require` in rhino
//
function require(arg) {
var split = arg.split('/');
var resultModule = split.length == 1 ? less.modules[split[0]] : less[split[1]];
if (!resultModule) {
throw { message: "Cannot find module '" + arg + "'"};
}
return resultModule;
}

View File

@@ -1,4 +0,0 @@
if (typeof window === 'undefined') { less = {} }
else { less = window.less = {} }
tree = less.tree = {};
less.mode = 'rhino';

View File

@@ -1,131 +0,0 @@
(function() {
console = function() {
var stdout = java.lang.System.out;
var stderr = java.lang.System.err;
function doLog(out, type) {
return function() {
var args = java.lang.reflect.Array.newInstance(java.lang.Object, arguments.length - 1);
var format = arguments[0];
var conversionIndex = 0;
// need to look for %d (integer) conversions because in Javascript all numbers are doubles
for (var i = 1; i < arguments.length; i++) {
var arg = arguments[i];
if (conversionIndex != -1) {
conversionIndex = format.indexOf('%', conversionIndex);
}
if (conversionIndex >= 0 && conversionIndex < format.length) {
var conversion = format.charAt(conversionIndex + 1);
if (conversion === 'd' && typeof arg === 'number') {
arg = new java.lang.Integer(new java.lang.Double(arg).intValue());
}
conversionIndex++;
}
args[i-1] = arg;
}
try {
out.println(type + java.lang.String.format(format, args));
} catch(ex) {
stderr.println(ex);
}
}
}
return {
log: doLog(stdout, ''),
info: doLog(stdout, 'INFO: '),
error: doLog(stderr, 'ERROR: '),
warn: doLog(stderr, 'WARN: ')
};
}();
less.modules = {};
less.modules.path = {
join: function() {
var parts = [];
for (i in arguments) {
parts = parts.concat(arguments[i].split(/\/|\\/));
}
var result = [];
for (i in parts) {
var part = parts[i];
if (part === '..' && result.length > 0 && result[result.length-1] !== '..') {
result.pop();
} else if (part === '' && result.length > 0) {
// skip
} else if (part !== '.') {
if (part.slice(-1)==='\\' || part.slice(-1)==='/') {
part = part.slice(0, -1);
}
result.push(part);
}
}
return result.join('/');
},
dirname: function(p) {
var path = p.split('/');
path.pop();
return path.join('/');
},
basename: function(p, ext) {
var base = p.split('/').pop();
if (ext) {
var index = base.lastIndexOf(ext);
if (base.length === index + ext.length) {
base = base.substr(0, index);
}
}
return base;
},
extname: function(p) {
var index = p.lastIndexOf('.');
return index > 0 ? p.substring(index) : '';
}
};
less.modules.fs = {
readFileSync: function(name) {
// read a file into a byte array
var file = new java.io.File(name);
var stream = new java.io.FileInputStream(file);
var buffer = [];
var c;
while ((c = stream.read()) != -1) {
buffer.push(c);
}
stream.close();
return {
length: buffer.length,
toString: function(enc) {
if (enc === 'base64') {
return encodeBase64Bytes(buffer);
} else if (enc) {
return java.lang.String["(byte[],java.lang.String)"](buffer, enc);
} else {
return java.lang.String["(byte[])"](buffer);
}
}
};
}
};
less.encoder = {
encodeBase64: function(str) {
return encodeBase64String(str);
}
};
// ---------------------------------------------------------------------------------------------
// private helper functions
// ---------------------------------------------------------------------------------------------
function encodeBase64Bytes(bytes) {
// requires at least a JRE Platform 6 (or JAXB 1.0 on the classpath)
return javax.xml.bind.DatatypeConverter.printBase64Binary(bytes)
}
function encodeBase64String(str) {
return encodeBase64Bytes(new java.lang.String(str).getBytes());
}
})();

View File

@@ -1 +0,0 @@
# Reserved for specialized Less.js tasks.

View File

@@ -1,435 +0,0 @@
/* jshint rhino:true, unused: false */
/* global name:true, less, loadStyleSheet, os */
function formatError(ctx, options) {
options = options || {};
var message = '';
var extract = ctx.extract;
var error = [];
// var stylize = options.color ? require('./lessc_helper').stylize : function (str) { return str; };
var stylize = function (str) { return str; };
// only output a stack if it isn't a less error
if (ctx.stack && !ctx.type) { return stylize(ctx.stack, 'red'); }
if (!ctx.hasOwnProperty('index') || !extract) {
return ctx.stack || ctx.message;
}
if (typeof extract[0] === 'string') {
error.push(stylize((ctx.line - 1) + ' ' + extract[0], 'grey'));
}
if (typeof extract[1] === 'string') {
var errorTxt = ctx.line + ' ';
if (extract[1]) {
errorTxt += extract[1].slice(0, ctx.column) +
stylize(stylize(stylize(extract[1][ctx.column], 'bold') +
extract[1].slice(ctx.column + 1), 'red'), 'inverse');
}
error.push(errorTxt);
}
if (typeof extract[2] === 'string') {
error.push(stylize((ctx.line + 1) + ' ' + extract[2], 'grey'));
}
error = error.join('\n') + stylize('', 'reset') + '\n';
message += stylize(ctx.type + 'Error: ' + ctx.message, 'red');
if (ctx.filename) {
message += stylize(' in ', 'red') + ctx.filename +
stylize(' on line ' + ctx.line + ', column ' + (ctx.column + 1) + ':', 'grey');
}
message += '\n' + error;
if (ctx.callLine) {
message += stylize('from ', 'red') + (ctx.filename || '') + '/n';
message += stylize(ctx.callLine, 'grey') + ' ' + ctx.callExtract + '/n';
}
return message;
}
function writeError(ctx, options) {
options = options || {};
if (options.silent) { return; }
var message = formatError(ctx, options);
throw new Error(message);
}
function loadStyleSheet(sheet, callback, reload, remaining) {
var endOfPath = Math.max(name.lastIndexOf('/'), name.lastIndexOf('\\')),
sheetName = name.slice(0, endOfPath + 1) + sheet.href,
contents = sheet.contents || {},
input = readFile(sheetName);
input = input.replace(/^\xEF\xBB\xBF/, '');
contents[sheetName] = input;
var parser = new less.Parser({
paths: [sheet.href.replace(/[\w\.-]+$/, '')],
contents: contents
});
parser.parse(input, function (e, root) {
if (e) {
return writeError(e);
}
try {
callback(e, root, input, sheet, { local: false, lastModified: 0, remaining: remaining }, sheetName);
} catch (e) {
writeError(e);
}
});
}
less.Parser.fileLoader = function (file, currentFileInfo, callback, env) {
var href = file;
if (currentFileInfo && currentFileInfo.currentDirectory && !/^\//.test(file)) {
href = less.modules.path.join(currentFileInfo.currentDirectory, file);
}
var path = less.modules.path.dirname(href);
var newFileInfo = {
currentDirectory: path + '/',
filename: href
};
if (currentFileInfo) {
newFileInfo.entryPath = currentFileInfo.entryPath;
newFileInfo.rootpath = currentFileInfo.rootpath;
newFileInfo.rootFilename = currentFileInfo.rootFilename;
newFileInfo.relativeUrls = currentFileInfo.relativeUrls;
} else {
newFileInfo.entryPath = path;
newFileInfo.rootpath = less.rootpath || path;
newFileInfo.rootFilename = href;
newFileInfo.relativeUrls = env.relativeUrls;
}
var j = file.lastIndexOf('/');
if (newFileInfo.relativeUrls && !/^(?:[a-z-]+:|\/)/.test(file) && j != -1) {
var relativeSubDirectory = file.slice(0, j + 1);
newFileInfo.rootpath = newFileInfo.rootpath + relativeSubDirectory; // append (sub|sup) directory path of imported file
}
newFileInfo.currentDirectory = path;
newFileInfo.filename = href;
var data = null;
try {
data = readFile(href);
} catch (e) {
callback({ type: 'File', message: '\'' + less.modules.path.basename(href) + '\' wasn\'t found' });
return;
}
try {
callback(null, data, href, newFileInfo, { lastModified: 0 });
} catch (e) {
callback(e, null, href);
}
};
function writeFile(filename, content) {
var fstream = new java.io.FileWriter(filename);
var out = new java.io.BufferedWriter(fstream);
out.write(content);
out.close();
}
// Command line integration via Rhino
(function (args) {
var options = require('../default-options');
var continueProcessing = true,
currentErrorcode;
var checkArgFunc = function(arg, option) {
if (!option) {
print(arg + ' option requires a parameter');
continueProcessing = false;
return false;
}
return true;
};
var checkBooleanArg = function(arg) {
var onOff = /^((on|t|true|y|yes)|(off|f|false|n|no))$/i.exec(arg);
if (!onOff) {
print(' unable to parse ' + arg + ' as a boolean. use one of on/t/true/y/yes/off/f/false/n/no');
continueProcessing = false;
return false;
}
return Boolean(onOff[2]);
};
var warningMessages = '';
var sourceMapFileInline = false;
args = args.filter(function (arg) {
var match = arg.match(/^-I(.+)$/);
if (match) {
options.paths.push(match[1]);
return false;
}
match = arg.match(/^--?([a-z][0-9a-z-]*)(?:=(.*))?$/i);
if (match) {
arg = match[1];
}
else {
return arg;
}
switch (arg) {
case 'v':
case 'version':
console.log('lessc ' + less.version.join('.') + ' (Less Compiler) [JavaScript]');
continueProcessing = false;
break;
case 'verbose':
options.verbose = true;
break;
case 's':
case 'silent':
options.silent = true;
break;
case 'l':
case 'lint':
options.lint = true;
break;
case 'strict-imports':
options.strictImports = true;
break;
case 'h':
case 'help':
// TODO
// require('../lib/less/lessc_helper').printUsage();
continueProcessing = false;
break;
case 'x':
case 'compress':
options.compress = true;
break;
case 'M':
case 'depends':
options.depends = true;
break;
case 'yui-compress':
warningMessages += 'yui-compress option has been removed. assuming clean-css.';
options.cleancss = true;
break;
case 'clean-css':
options.cleancss = true;
break;
case 'max-line-len':
if (checkArgFunc(arg, match[2])) {
options.maxLineLen = parseInt(match[2], 10);
if (options.maxLineLen <= 0) {
options.maxLineLen = -1;
}
}
break;
case 'no-color':
options.color = false;
break;
case 'no-ie-compat':
options.ieCompat = false;
break;
case 'no-js':
options.javascriptEnabled = false;
break;
case 'include-path':
if (checkArgFunc(arg, match[2])) {
// support for both ; and : path separators
// even on windows when using absolute paths with drive letters (eg C:\path:D:\path)
options.paths = match[2]
.split(os.type().match(/Windows/) ? /:(?!\\)|;/ : ':')
.map(function(p) {
if (p) {
// return path.resolve(process.cwd(), p);
return p;
}
});
}
break;
case 'line-numbers':
if (checkArgFunc(arg, match[2])) {
options.dumpLineNumbers = match[2];
}
break;
case 'source-map':
if (!match[2]) {
options.sourceMap = true;
} else {
options.sourceMap = match[2];
}
break;
case 'source-map-rootpath':
if (checkArgFunc(arg, match[2])) {
options.sourceMapRootpath = match[2];
}
break;
case 'source-map-basepath':
if (checkArgFunc(arg, match[2])) {
options.sourceMapBasepath = match[2];
}
break;
case 'source-map-map-inline':
sourceMapFileInline = true;
options.sourceMap = true;
break;
case 'source-map-less-inline':
options.outputSourceFiles = true;
break;
case 'source-map-url':
if (checkArgFunc(arg, match[2])) {
options.sourceMapURL = match[2];
}
break;
case 'source-map-output-map-file':
if (checkArgFunc(arg, match[2])) {
options.writeSourceMap = function(sourceMapContent) {
writeFile(match[2], sourceMapContent);
};
}
break;
case 'rp':
case 'rootpath':
if (checkArgFunc(arg, match[2])) {
options.rootpath = match[2].replace(/\\/g, '/');
}
break;
case 'ru':
case 'relative-urls':
options.relativeUrls = true;
break;
case 'sm':
case 'strict-math':
if (checkArgFunc(arg, match[2])) {
options.strictMath = checkBooleanArg(match[2]);
}
break;
case 'su':
case 'strict-units':
if (checkArgFunc(arg, match[2])) {
options.strictUnits = checkBooleanArg(match[2]);
}
break;
default:
console.log('invalid option ' + arg);
continueProcessing = false;
}
});
if (!continueProcessing) {
return;
}
var name = args[0];
if (name && name != '-') {
// name = path.resolve(process.cwd(), name);
}
var output = args[1];
var outputbase = args[1];
if (output) {
options.sourceMapOutputFilename = output;
// output = path.resolve(process.cwd(), output);
if (warningMessages) {
console.log(warningMessages);
}
}
// options.sourceMapBasepath = process.cwd();
// options.sourceMapBasepath = '';
if (options.sourceMap === true) {
console.log('output: ' + output);
if (!output && !sourceMapFileInline) {
console.log('the sourcemap option only has an optional filename if the css filename is given');
return;
}
options.sourceMapFullFilename = options.sourceMapOutputFilename + '.map';
options.sourceMap = less.modules.path.basename(options.sourceMapFullFilename);
} else if (options.sourceMap) {
options.sourceMapOutputFilename = options.sourceMap;
}
if (!name) {
console.log('lessc: no inout files');
console.log('');
// TODO
// require('../lib/less/lessc_helper').printUsage();
currentErrorcode = 1;
return;
}
/*
var ensureDirectory = function (filepath) {
var dir = path.dirname(filepath),
cmd,
existsSync = fs.existsSync || path.existsSync;
if (!existsSync(dir)) {
if (mkdirp === undefined) {
try {mkdirp = require('mkdirp');}
catch(e) { mkdirp = null; }
}
cmd = mkdirp && mkdirp.sync || fs.mkdirSync;
cmd(dir);
}
}; */
if (options.depends) {
if (!outputbase) {
console.log('option --depends requires an output path to be specified');
return;
}
console.log(outputbase + ': ');
}
if (!name) {
console.log('No files present in the fileset');
quit(1);
}
var input = null;
try {
input = readFile(name, 'utf-8');
} catch (e) {
console.log('lesscss: couldn\'t open file ' + name);
quit(1);
}
options.filename = name;
var result;
try {
var parser = new less.Parser(options);
parser.parse(input, function (e, root) {
if (e) {
writeError(e, options);
quit(1);
} else {
result = root.toCSS(options);
if (output) {
writeFile(output, result);
console.log('Written to ' + output);
} else {
print(result);
}
quit(0);
}
});
}
catch (e) {
writeError(e, options);
quit(1);
}
}(arguments));

View File

@@ -1,15 +0,0 @@
function initRhinoTest() {
process = { title: 'dummy' };
less.tree.functions.add = function (a, b) {
return new(less.tree.Dimension)(a.value + b.value);
};
less.tree.functions.increment = function (a) {
return new(less.tree.Dimension)(a.value + 1);
};
less.tree.functions._color = function (str) {
if (str.value === 'evil red') { return new(less.tree.Color)('600'); }
};
}
initRhinoTest();