08-27-周三_17-09-29
This commit is contained in:
14
node_modules/less/lib/less-node/environment.js
generated
vendored
Normal file
14
node_modules/less/lib/less-node/environment.js
generated
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
module.exports = {
|
||||
encodeBase64: function encodeBase64(str) {
|
||||
return new Buffer(str).toString('base64');
|
||||
},
|
||||
mimeLookup: function (filename) {
|
||||
return require('mime').lookup(filename);
|
||||
},
|
||||
charsetLookup: function (mime) {
|
||||
return require('mime').charsets.lookup(mime);
|
||||
},
|
||||
getSourceMapGenerator: function getSourceMapGenerator() {
|
||||
return require("source-map").SourceMapGenerator;
|
||||
}
|
||||
};
|
108
node_modules/less/lib/less-node/file-manager.js
generated
vendored
Normal file
108
node_modules/less/lib/less-node/file-manager.js
generated
vendored
Normal file
@@ -0,0 +1,108 @@
|
||||
var path = require('path'),
|
||||
fs = require('./fs'),
|
||||
PromiseConstructor,
|
||||
AbstractFileManager = require("../less/environment/abstract-file-manager.js");
|
||||
|
||||
try {
|
||||
PromiseConstructor = typeof Promise === 'undefined' ? require('promise') : Promise;
|
||||
} catch(e) {
|
||||
}
|
||||
|
||||
var FileManager = function() {
|
||||
};
|
||||
|
||||
FileManager.prototype = new AbstractFileManager();
|
||||
|
||||
FileManager.prototype.supports = function(filename, currentDirectory, options, environment) {
|
||||
return true;
|
||||
};
|
||||
FileManager.prototype.supportsSync = function(filename, currentDirectory, options, environment) {
|
||||
return true;
|
||||
};
|
||||
|
||||
FileManager.prototype.loadFile = function(filename, currentDirectory, options, environment, callback) {
|
||||
var fullFilename,
|
||||
data,
|
||||
isAbsoluteFilename = this.isPathAbsolute(filename),
|
||||
filenamesTried = [];
|
||||
|
||||
options = options || {};
|
||||
|
||||
if (options.syncImport || !PromiseConstructor) {
|
||||
data = this.loadFileSync(filename, currentDirectory, options, environment, 'utf-8');
|
||||
callback(data.error, data);
|
||||
return;
|
||||
}
|
||||
|
||||
var paths = isAbsoluteFilename ? [""] : [currentDirectory];
|
||||
if (options.paths) { paths.push.apply(paths, options.paths); }
|
||||
if (!isAbsoluteFilename && paths.indexOf('.') === -1) { paths.push('.'); }
|
||||
|
||||
// promise is guarenteed to be asyncronous
|
||||
// which helps as it allows the file handle
|
||||
// to be closed before it continues with the next file
|
||||
return new PromiseConstructor(function(fulfill, reject) {
|
||||
(function tryPathIndex(i) {
|
||||
if (i < paths.length) {
|
||||
fullFilename = filename;
|
||||
if (paths[i]) {
|
||||
fullFilename = path.join(paths[i], fullFilename);
|
||||
}
|
||||
fs.stat(fullFilename, function (err) {
|
||||
if (err) {
|
||||
filenamesTried.push(fullFilename);
|
||||
tryPathIndex(i + 1);
|
||||
} else {
|
||||
fs.readFile(fullFilename, 'utf-8', function(e, data) {
|
||||
if (e) { reject(e); return; }
|
||||
|
||||
fulfill({ contents: data, filename: fullFilename});
|
||||
});
|
||||
}
|
||||
});
|
||||
} else {
|
||||
reject({ type: 'File', message: "'" + filename + "' wasn't found. Tried - " + filenamesTried.join(",") });
|
||||
}
|
||||
}(0));
|
||||
});
|
||||
};
|
||||
|
||||
FileManager.prototype.loadFileSync = function(filename, currentDirectory, options, environment, encoding) {
|
||||
var fullFilename, paths, filenamesTried = [], isAbsoluteFilename = this.isPathAbsolute(filename) , data;
|
||||
options = options || {};
|
||||
|
||||
paths = isAbsoluteFilename ? [""] : [currentDirectory];
|
||||
if (options.paths) {
|
||||
paths.push.apply(paths, options.paths);
|
||||
}
|
||||
if (!isAbsoluteFilename && paths.indexOf('.') === -1) {
|
||||
paths.push('.');
|
||||
}
|
||||
|
||||
var err, result;
|
||||
for (var i = 0; i < paths.length; i++) {
|
||||
try {
|
||||
fullFilename = filename;
|
||||
if (paths[i]) {
|
||||
fullFilename = path.join(paths[i], fullFilename);
|
||||
}
|
||||
filenamesTried.push(fullFilename);
|
||||
fs.statSync(fullFilename);
|
||||
break;
|
||||
} catch (e) {
|
||||
fullFilename = null;
|
||||
}
|
||||
}
|
||||
|
||||
if (!fullFilename) {
|
||||
err = { type: 'File', message: "'" + filename + "' wasn't found. Tried - " + filenamesTried.join(",") };
|
||||
result = { error: err };
|
||||
} else {
|
||||
data = fs.readFileSync(fullFilename, encoding);
|
||||
result = { contents: data, filename: fullFilename};
|
||||
}
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
module.exports = FileManager;
|
10
node_modules/less/lib/less-node/fs.js
generated
vendored
Normal file
10
node_modules/less/lib/less-node/fs.js
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
var fs;
|
||||
try
|
||||
{
|
||||
fs = require("graceful-fs");
|
||||
}
|
||||
catch(e)
|
||||
{
|
||||
fs = require("fs");
|
||||
}
|
||||
module.exports = fs;
|
57
node_modules/less/lib/less-node/image-size.js
generated
vendored
Normal file
57
node_modules/less/lib/less-node/image-size.js
generated
vendored
Normal file
@@ -0,0 +1,57 @@
|
||||
module.exports = function(environment) {
|
||||
var Dimension = require("../less/tree/dimension"),
|
||||
Expression = require("../less/tree/expression"),
|
||||
functionRegistry = require("./../less/functions/function-registry");
|
||||
|
||||
function imageSize(functionContext, filePathNode) {
|
||||
var filePath = filePathNode.value;
|
||||
var currentFileInfo = functionContext.currentFileInfo;
|
||||
var currentDirectory = currentFileInfo.relativeUrls ?
|
||||
currentFileInfo.currentDirectory : currentFileInfo.entryPath;
|
||||
|
||||
var fragmentStart = filePath.indexOf('#');
|
||||
var fragment = '';
|
||||
if (fragmentStart !== -1) {
|
||||
fragment = filePath.slice(fragmentStart);
|
||||
filePath = filePath.slice(0, fragmentStart);
|
||||
}
|
||||
|
||||
var fileManager = environment.getFileManager(filePath, currentDirectory, functionContext.context, environment, true);
|
||||
|
||||
if (!fileManager) {
|
||||
throw {
|
||||
type: "File",
|
||||
message: "Can not set up FileManager for " + filePathNode
|
||||
};
|
||||
}
|
||||
|
||||
var fileSync = fileManager.loadFileSync(filePath, currentDirectory, functionContext.context, environment);
|
||||
|
||||
if (fileSync.error) {
|
||||
throw fileSync.error;
|
||||
}
|
||||
|
||||
var sizeOf = require('image-size');
|
||||
return sizeOf(fileSync.filename);
|
||||
}
|
||||
|
||||
var imageFunctions = {
|
||||
"image-size": function(filePathNode) {
|
||||
var size = imageSize(this, filePathNode);
|
||||
return new Expression([
|
||||
new Dimension(size.width, "px"),
|
||||
new Dimension(size.height, "px")
|
||||
]);
|
||||
},
|
||||
"image-width": function(filePathNode) {
|
||||
var size = imageSize(this, filePathNode);
|
||||
return new Dimension(size.width, "px");
|
||||
},
|
||||
"image-height": function(filePathNode) {
|
||||
var size = imageSize(this, filePathNode);
|
||||
return new Dimension(size.height, "px");
|
||||
}
|
||||
};
|
||||
|
||||
functionRegistry.addMultiple(imageFunctions);
|
||||
};
|
74
node_modules/less/lib/less-node/index.js
generated
vendored
Normal file
74
node_modules/less/lib/less-node/index.js
generated
vendored
Normal file
@@ -0,0 +1,74 @@
|
||||
var environment = require("./environment"),
|
||||
FileManager = require("./file-manager"),
|
||||
UrlFileManager = require("./url-file-manager"),
|
||||
createFromEnvironment = require("../less"),
|
||||
less = createFromEnvironment(environment, [new FileManager(), new UrlFileManager()]),
|
||||
lesscHelper = require('./lessc-helper');
|
||||
|
||||
// allow people to create less with their own environment
|
||||
less.createFromEnvironment = createFromEnvironment;
|
||||
less.lesscHelper = lesscHelper;
|
||||
less.PluginLoader = require("./plugin-loader");
|
||||
less.fs = require("./fs");
|
||||
less.FileManager = FileManager;
|
||||
less.UrlFileManager = UrlFileManager;
|
||||
less.formatError = function(ctx, options) {
|
||||
options = options || {};
|
||||
|
||||
var message = "";
|
||||
var extract = ctx.extract;
|
||||
var error = [];
|
||||
var stylize = options.color ? lesscHelper.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].substr(ctx.column, 1), '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;
|
||||
};
|
||||
|
||||
less.writeError = function (ctx, options) {
|
||||
options = options || {};
|
||||
if (options.silent) { return; }
|
||||
console.error(less.formatError(ctx, options));
|
||||
};
|
||||
|
||||
// provide image-size functionality
|
||||
require('./image-size')(less.environment);
|
||||
|
||||
module.exports = less;
|
82
node_modules/less/lib/less-node/lessc-helper.js
generated
vendored
Normal file
82
node_modules/less/lib/less-node/lessc-helper.js
generated
vendored
Normal file
@@ -0,0 +1,82 @@
|
||||
// lessc_helper.js
|
||||
//
|
||||
// helper functions for lessc
|
||||
var lessc_helper = {
|
||||
|
||||
//Stylize a string
|
||||
stylize : function(str, style) {
|
||||
var 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';
|
||||
},
|
||||
|
||||
//Print command line options
|
||||
printUsage: function() {
|
||||
console.log("usage: lessc [option option=parameter ...] <source> [destination]");
|
||||
console.log("");
|
||||
console.log("If source is set to `-' (dash or hyphen-minus), input is read from stdin.");
|
||||
console.log("");
|
||||
console.log("options:");
|
||||
console.log(" -h, --help Prints help (this message) and exit.");
|
||||
console.log(" --include-path=PATHS Sets include paths. Separated by `:'. `;' also supported on windows.");
|
||||
console.log(" -M, --depends Outputs a makefile import dependency list to stdout.");
|
||||
console.log(" --no-color Disables colorized output.");
|
||||
console.log(" --no-ie-compat Disables IE compatibility checks.");
|
||||
console.log(" --no-js Disables JavaScript in less files");
|
||||
console.log(" -l, --lint Syntax check only (lint).");
|
||||
console.log(" -s, --silent Suppresses output of error messages.");
|
||||
console.log(" --strict-imports Forces evaluation of imports.");
|
||||
console.log(" --insecure Allows imports from insecure https hosts.");
|
||||
console.log(" -v, --version Prints version number and exit.");
|
||||
console.log(" --verbose Be verbose.");
|
||||
console.log(" --source-map[=FILENAME] Outputs a v3 sourcemap to the filename (or output filename.map).");
|
||||
console.log(" --source-map-rootpath=X Adds this path onto the sourcemap filename and less file paths.");
|
||||
console.log(" --source-map-basepath=X Sets sourcemap base path, defaults to current working directory.");
|
||||
console.log(" --source-map-less-inline Puts the less files into the map instead of referencing them.");
|
||||
console.log(" --source-map-map-inline Puts the map (and any less files) as a base64 data uri into the output css file.");
|
||||
console.log(" --source-map-url=URL Sets a custom URL to map file, for sourceMappingURL comment");
|
||||
console.log(" in generated CSS file.");
|
||||
console.log(" -rp, --rootpath=URL Sets rootpath for url rewriting in relative imports and urls");
|
||||
console.log(" Works with or without the relative-urls option.");
|
||||
console.log(" -ru, --relative-urls Re-writes relative urls to the base less file.");
|
||||
console.log(" -sm=on|off Turns on or off strict math, where in strict mode, math.");
|
||||
console.log(" --strict-math=on|off Requires brackets. This option may default to on and then");
|
||||
console.log(" be removed in the future.");
|
||||
console.log(" -su=on|off Allows mixed units, e.g. 1px+1em or 1px*1px which have units");
|
||||
console.log(" --strict-units=on|off that cannot be represented.");
|
||||
console.log(" --global-var='VAR=VALUE' Defines a variable that can be referenced by the file.");
|
||||
console.log(" --modify-var='VAR=VALUE' Modifies a variable already declared in the file.");
|
||||
console.log(" --url-args='QUERYSTRING' Adds params into url tokens (e.g. 42, cb=42 or 'a=1&b=2')");
|
||||
console.log(" --plugin=PLUGIN=OPTIONS Loads a plugin. You can also omit the --plugin= if the plugin begins");
|
||||
console.log(" less-plugin. E.g. the clean css plugin is called less-plugin-clean-css");
|
||||
console.log(" once installed (npm install less-plugin-clean-css), use either with");
|
||||
console.log(" --plugin=less-plugin-clean-css or just --clean-css");
|
||||
console.log(" specify options afterwards e.g. --plugin=less-plugin-clean-css=\"advanced\"");
|
||||
console.log(" or --clean-css=\"advanced\"");
|
||||
console.log("");
|
||||
console.log("-------------------------- Deprecated ----------------");
|
||||
console.log(" --line-numbers=TYPE Outputs filename and line numbers.");
|
||||
console.log(" TYPE can be either 'comments', which will output");
|
||||
console.log(" the debug info within comments, 'mediaquery'");
|
||||
console.log(" that will output the information within a fake");
|
||||
console.log(" media query which is compatible with the SASS");
|
||||
console.log(" format, and 'all' which will do both.");
|
||||
console.log(" -x, --compress Compresses output by removing some whitespaces.");
|
||||
console.log(" We recommend you use a dedicated minifer like less-plugin-clean-css");
|
||||
console.log("");
|
||||
console.log("Report bugs to: http://github.com/less/less.js/issues");
|
||||
console.log("Home page: <http://lesscss.org/>");
|
||||
}
|
||||
};
|
||||
|
||||
// Exports helper functions
|
||||
for (var h in lessc_helper) { if (lessc_helper.hasOwnProperty(h)) { exports[h] = lessc_helper[h]; }}
|
91
node_modules/less/lib/less-node/plugin-loader.js
generated
vendored
Normal file
91
node_modules/less/lib/less-node/plugin-loader.js
generated
vendored
Normal file
@@ -0,0 +1,91 @@
|
||||
var path = require("path");
|
||||
/**
|
||||
* Node Plugin Loader
|
||||
*/
|
||||
var PluginLoader = function(less) {
|
||||
this.less = less;
|
||||
};
|
||||
PluginLoader.prototype.tryLoadPlugin = function(name, argument) {
|
||||
var plugin = this.tryRequirePlugin(name);
|
||||
if (plugin) {
|
||||
// support plugins being a function
|
||||
// so that the plugin can be more usable programmatically
|
||||
if (typeof plugin === "function") {
|
||||
plugin = new plugin();
|
||||
}
|
||||
if (plugin.minVersion) {
|
||||
if (this.compareVersion(plugin.minVersion, this.less.version) < 0) {
|
||||
console.log("plugin " + name + " requires version " + this.versionToString(plugin.minVersion));
|
||||
return null;
|
||||
}
|
||||
}
|
||||
if (argument) {
|
||||
if (!plugin.setOptions) {
|
||||
console.log("options have been provided but the plugin " + name + "does not support any options");
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
plugin.setOptions(argument);
|
||||
}
|
||||
catch(e) {
|
||||
console.log("Error setting options on plugin " + name);
|
||||
console.log(e.message);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return plugin;
|
||||
}
|
||||
return null;
|
||||
};
|
||||
PluginLoader.prototype.compareVersion = function(aVersion, bVersion) {
|
||||
for (var i = 0; i < aVersion.length; i++) {
|
||||
if (aVersion[i] !== bVersion[i]) {
|
||||
return parseInt(aVersion[i]) > parseInt(bVersion[i]) ? -1 : 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
};
|
||||
PluginLoader.prototype.versionToString = function(version) {
|
||||
var versionString = "";
|
||||
for (var i = 0; i < version.length; i++) {
|
||||
versionString += (versionString ? "." : "") + version[i];
|
||||
}
|
||||
return versionString;
|
||||
};
|
||||
PluginLoader.prototype.tryRequirePlugin = function(name) {
|
||||
// is at the same level as the less.js module
|
||||
try {
|
||||
return require("../../../" + name);
|
||||
}
|
||||
catch(e) {
|
||||
}
|
||||
// is installed as a sub dependency of the current folder
|
||||
try {
|
||||
return require(path.join(process.cwd(), "node_modules", name));
|
||||
}
|
||||
catch(e) {
|
||||
}
|
||||
// is referenced relative to the current directory
|
||||
try {
|
||||
return require(path.join(process.cwd(), name));
|
||||
}
|
||||
catch(e) {
|
||||
}
|
||||
// unlikely - would have to be a dependency of where this code was running (less.js)...
|
||||
if (name[0] !== '.') {
|
||||
try {
|
||||
return require(name);
|
||||
}
|
||||
catch(e) {
|
||||
}
|
||||
}
|
||||
};
|
||||
PluginLoader.prototype.printUsage = function(plugins) {
|
||||
for (var i = 0; i < plugins.length; i++) {
|
||||
var plugin = plugins[i];
|
||||
if (plugin.printUsage) {
|
||||
plugin.printUsage();
|
||||
}
|
||||
}
|
||||
};
|
||||
module.exports = PluginLoader;
|
56
node_modules/less/lib/less-node/url-file-manager.js
generated
vendored
Normal file
56
node_modules/less/lib/less-node/url-file-manager.js
generated
vendored
Normal file
@@ -0,0 +1,56 @@
|
||||
var isUrlRe = /^(?:https?:)?\/\//i,
|
||||
url = require('url'),
|
||||
request,
|
||||
PromiseConstructor,
|
||||
AbstractFileManager = require("../less/environment/abstract-file-manager.js"),
|
||||
logger = require("../less/logger");
|
||||
|
||||
var UrlFileManager = function() {
|
||||
};
|
||||
|
||||
UrlFileManager.prototype = new AbstractFileManager();
|
||||
|
||||
UrlFileManager.prototype.supports = function(filename, currentDirectory, options, environment) {
|
||||
return isUrlRe.test( filename ) || isUrlRe.test(currentDirectory);
|
||||
};
|
||||
|
||||
UrlFileManager.prototype.loadFile = function(filename, currentDirectory, options, environment) {
|
||||
if (!PromiseConstructor) {
|
||||
PromiseConstructor = typeof Promise === 'undefined' ? require('promise') : Promise;
|
||||
}
|
||||
return new PromiseConstructor(function(fulfill, reject) {
|
||||
if (request === undefined) {
|
||||
try { request = require('request'); }
|
||||
catch(e) { request = null; }
|
||||
}
|
||||
if (!request) {
|
||||
reject({ type: 'File', message: "optional dependency 'request' required to import over http(s)\n" });
|
||||
return;
|
||||
}
|
||||
|
||||
var urlStr = isUrlRe.test( filename ) ? filename : url.resolve(currentDirectory, filename),
|
||||
urlObj = url.parse(urlStr);
|
||||
|
||||
if (!urlObj.protocol) {
|
||||
urlObj.protocol = "http";
|
||||
urlStr = urlObj.format();
|
||||
}
|
||||
|
||||
request.get({uri: urlStr, strictSSL: !options.insecure }, function (error, res, body) {
|
||||
if (error) {
|
||||
reject({ type: 'File', message: "resource '" + urlStr + "' gave this Error:\n " + error + "\n" });
|
||||
return;
|
||||
}
|
||||
if (res && res.statusCode === 404) {
|
||||
reject({ type: 'File', message: "resource '" + urlStr + "' was not found\n" });
|
||||
return;
|
||||
}
|
||||
if (!body) {
|
||||
logger.warn('Warning: Empty body (HTTP ' + res.statusCode + ') returned by "' + urlStr + '"');
|
||||
}
|
||||
fulfill({ contents: body, filename: urlStr });
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = UrlFileManager;
|
Reference in New Issue
Block a user