mirror of
https://github.com/wassname/CanvasTextWrapper.git
synced 2026-07-19 11:19:26 +08:00
git ignore updates
This commit is contained in:
+133
-15
@@ -2,15 +2,17 @@
|
||||
* grunt-contrib-uglify
|
||||
* https://gruntjs.com/
|
||||
*
|
||||
* Copyright (c) 2013 "Cowboy" Ben Alman, contributors
|
||||
* Copyright (c) 2015 "Cowboy" Ben Alman, contributors
|
||||
* Licensed under the MIT license.
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
// External libs.
|
||||
var path = require('path');
|
||||
var UglifyJS = require('uglify-js');
|
||||
var fs = require('fs');
|
||||
var _ = require('lodash');
|
||||
var uriPath = require('uri-path');
|
||||
|
||||
exports.init = function(grunt) {
|
||||
var exports = {};
|
||||
@@ -25,20 +27,32 @@ exports.init = function(grunt) {
|
||||
|
||||
var topLevel = null;
|
||||
var totalCode = '';
|
||||
var sourcesContent = {};
|
||||
|
||||
var outputOptions = getOutputOptions(options, dest);
|
||||
var output = UglifyJS.OutputStream(outputOptions);
|
||||
|
||||
// Grab and parse all source files
|
||||
files.forEach(function(file){
|
||||
|
||||
var code = grunt.file.read(file);
|
||||
if (typeof options.sourceMapPrefix !== 'undefined') {
|
||||
file = file.replace(/^\/+/, "").split(/\/+/).slice(options.sourceMapPrefix).join("/");
|
||||
}
|
||||
totalCode += code;
|
||||
|
||||
// The src file name must be relative to the source map for things to work
|
||||
var basename = path.basename(file);
|
||||
var fileDir = path.dirname(file);
|
||||
var sourceMapDir = path.dirname(options.generatedSourceMapName);
|
||||
var relativePath = path.relative(sourceMapDir, fileDir);
|
||||
var pathPrefix = relativePath ? (relativePath+path.sep) : '';
|
||||
|
||||
// Convert paths to use forward slashes for sourcemap use in the browser
|
||||
file = uriPath(pathPrefix + basename);
|
||||
|
||||
sourcesContent[file] = code;
|
||||
topLevel = UglifyJS.parse(code, {
|
||||
filename: file,
|
||||
toplevel: topLevel
|
||||
toplevel: topLevel,
|
||||
expression: options.expression
|
||||
});
|
||||
});
|
||||
|
||||
@@ -49,18 +63,28 @@ exports.init = function(grunt) {
|
||||
|
||||
// Wrap code in closure with configurable arguments/parameters list.
|
||||
if (options.enclose) {
|
||||
var argParamList = grunt.util._.map(options.enclose, function(val, key) {
|
||||
var argParamList = _.map(options.enclose, function(val, key) {
|
||||
return key + ':' + val;
|
||||
});
|
||||
|
||||
topLevel = topLevel.wrap_enclose(argParamList);
|
||||
}
|
||||
|
||||
var topLevelCache = null;
|
||||
if (options.nameCache) {
|
||||
topLevelCache = UglifyJS.readNameCache(options.nameCache, 'vars');
|
||||
}
|
||||
|
||||
// Need to call this before we mangle or compress,
|
||||
// and call after any compression or ast altering
|
||||
topLevel.figure_out_scope();
|
||||
if (options.expression === false) {
|
||||
topLevel.figure_out_scope({ screw_ie8: options.screwIE8, cache: topLevelCache });
|
||||
}
|
||||
|
||||
if (options.compress !== false) {
|
||||
if (options.compress === true) {
|
||||
options.compress = {};
|
||||
}
|
||||
if (options.compress.warnings !== true) {
|
||||
options.compress.warnings = false;
|
||||
}
|
||||
@@ -68,7 +92,45 @@ exports.init = function(grunt) {
|
||||
topLevel = topLevel.transform(compressor);
|
||||
|
||||
// Need to figure out scope again after source being altered
|
||||
topLevel.figure_out_scope();
|
||||
if (options.expression === false) {
|
||||
topLevel.figure_out_scope({screw_ie8: options.screwIE8, cache: topLevelCache});
|
||||
}
|
||||
}
|
||||
|
||||
var mangleExclusions = { vars: [], props: [] };
|
||||
if (options.reserveDOMProperties) {
|
||||
mangleExclusions = UglifyJS.readDefaultReservedFile();
|
||||
}
|
||||
|
||||
if (options.exceptionsFiles) {
|
||||
try {
|
||||
options.exceptionsFiles.forEach(function(filename) {
|
||||
mangleExclusions = UglifyJS.readReservedFile(filename, mangleExclusions);
|
||||
});
|
||||
} catch (ex) {
|
||||
grunt.warn(ex);
|
||||
}
|
||||
}
|
||||
|
||||
var cache = null;
|
||||
if (options.nameCache) {
|
||||
cache = UglifyJS.readNameCache(options.nameCache, 'props');
|
||||
}
|
||||
|
||||
if (options.mangleProperties === true) {
|
||||
topLevel = UglifyJS.mangle_properties(topLevel, {
|
||||
reserved: mangleExclusions ? mangleExclusions.props : null,
|
||||
cache: cache
|
||||
});
|
||||
|
||||
if (options.nameCache) {
|
||||
UglifyJS.writeNameCache(options.nameCache, 'props', cache);
|
||||
}
|
||||
|
||||
// Need to figure out scope again since topLevel has been altered
|
||||
if (options.expression === false) {
|
||||
topLevel.figure_out_scope({screw_ie8: options.screwIE8, cache: topLevelCache});
|
||||
}
|
||||
}
|
||||
|
||||
if (options.mangle !== false) {
|
||||
@@ -78,9 +140,33 @@ exports.init = function(grunt) {
|
||||
// // compute_char_frequency optimizes names for compression
|
||||
// topLevel.compute_char_frequency(options.mangle);
|
||||
|
||||
// if options.mangle is a boolean (true) convert it into an object
|
||||
if (typeof options.mangle !== 'object') {
|
||||
options.mangle = {};
|
||||
}
|
||||
|
||||
options.mangle.cache = topLevelCache;
|
||||
|
||||
options.mangle.except = options.mangle.except ? options.mangle.except : [];
|
||||
if (mangleExclusions.vars) {
|
||||
mangleExclusions.vars.forEach(function(name){
|
||||
UglifyJS.push_uniq(options.mangle.except, name);
|
||||
});
|
||||
}
|
||||
|
||||
// Requires previous call to figure_out_scope
|
||||
// and should always be called after compressor transform
|
||||
topLevel.mangle_names(options.mangle);
|
||||
|
||||
UglifyJS.writeNameCache(options.nameCache, 'vars', options.mangle.cache);
|
||||
}
|
||||
|
||||
if (options.sourceMap && options.sourceMapIncludeSources) {
|
||||
for (var file in sourcesContent) {
|
||||
if (sourcesContent.hasOwnProperty(file)) {
|
||||
outputOptions.source_map.get().setSourceContent(file, sourcesContent[file]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Print the ast to OutputStream
|
||||
@@ -88,8 +174,10 @@ exports.init = function(grunt) {
|
||||
|
||||
var min = output.get();
|
||||
|
||||
if (options.sourceMappingURL || options.sourceMap) {
|
||||
min += "\n//# sourceMappingURL=" + (options.sourceMappingURL || options.sourceMap);
|
||||
// Add the source map reference to the end of the file
|
||||
if (options.sourceMap) {
|
||||
// Set all paths to forward slashes for use in the browser
|
||||
min += "\n//# sourceMappingURL=" + uriPath(options.destToSourceMap);
|
||||
}
|
||||
|
||||
var result = {
|
||||
@@ -117,7 +205,7 @@ exports.init = function(grunt) {
|
||||
} else if (options.preserveComments === 'some') {
|
||||
// preserve comments with directives or that start with a bang (!)
|
||||
outputOptions.comments = /^!|@preserve|@license|@cc_on/i;
|
||||
} else if (grunt.util._.isFunction(options.preserveComments)) {
|
||||
} else if (_.isFunction(options.preserveComments)) {
|
||||
|
||||
// support custom functions passed in
|
||||
outputOptions.comments = options.preserveComments;
|
||||
@@ -129,26 +217,56 @@ exports.init = function(grunt) {
|
||||
}
|
||||
|
||||
if (options.beautify) {
|
||||
if (grunt.util._.isObject(options.beautify)) {
|
||||
if (_.isObject(options.beautify)) {
|
||||
// beautify options sent as an object are merged
|
||||
// with outputOptions and passed to the OutputStream
|
||||
grunt.util._.extend(outputOptions, options.beautify);
|
||||
_.assign(outputOptions, options.beautify);
|
||||
} else {
|
||||
outputOptions.beautify = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (options.screwIE8) {
|
||||
outputOptions.screw_ie8 = true;
|
||||
}
|
||||
|
||||
if (options.sourceMap) {
|
||||
|
||||
var destBasename = path.basename(dest);
|
||||
var sourceMapIn;
|
||||
if (options.sourceMapIn) {
|
||||
sourceMapIn = grunt.file.readJSON(options.sourceMapIn);
|
||||
}
|
||||
outputOptions.source_map = UglifyJS.SourceMap({
|
||||
file: dest,
|
||||
file: destBasename,
|
||||
root: options.sourceMapRoot,
|
||||
orig: sourceMapIn
|
||||
});
|
||||
if (options.sourceMapIncludeSources && sourceMapIn && sourceMapIn.sourcesContent) {
|
||||
sourceMapIn.sourcesContent.forEach(function(content, idx) {
|
||||
outputOptions.source_map.get().setSourceContent(sourceMapIn.sources[idx], content);
|
||||
});
|
||||
}
|
||||
|
||||
if (options.sourceMapIn) {
|
||||
outputOptions.source_map.get()._file = destBasename;
|
||||
}
|
||||
}
|
||||
|
||||
if (!_.isUndefined(options.indentLevel)) {
|
||||
outputOptions.indent_level = options.indentLevel;
|
||||
}
|
||||
|
||||
if (!_.isUndefined(options.maxLineLen)) {
|
||||
outputOptions.max_line_len = options.maxLineLen;
|
||||
}
|
||||
|
||||
if (!_.isUndefined(options.ASCIIOnly)) {
|
||||
outputOptions.ascii_only = options.ASCIIOnly;
|
||||
}
|
||||
|
||||
if (!_.isUndefined(options.quoteStyle)) {
|
||||
outputOptions.quote_style = options.quoteStyle;
|
||||
}
|
||||
|
||||
return outputOptions;
|
||||
|
||||
+84
-42
@@ -8,10 +8,30 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
module.exports = function(grunt) {
|
||||
var path = require('path');
|
||||
var chalk = require('chalk');
|
||||
var maxmin = require('maxmin');
|
||||
|
||||
// Return the relative path from file1 => file2
|
||||
function relativePath(file1, file2) {
|
||||
|
||||
var file1Dirname = path.dirname(file1);
|
||||
var file2Dirname = path.dirname(file2);
|
||||
if (file1Dirname !== file2Dirname) {
|
||||
return path.relative(file1Dirname, file2Dirname) + path.sep;
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Converts \r\n to \n
|
||||
function normalizeLf( string ) {
|
||||
return string.replace(/\r\n/g, '\n');
|
||||
}
|
||||
|
||||
module.exports = function(grunt) {
|
||||
// Internal lib.
|
||||
var contrib = require('grunt-lib-contrib').init(grunt);
|
||||
var uglify = require('./lib/uglify').init(grunt);
|
||||
|
||||
grunt.registerMultiTask('uglify', 'Minify files with UglifyJS.', function() {
|
||||
@@ -24,20 +44,27 @@ module.exports = function(grunt) {
|
||||
},
|
||||
mangle: {},
|
||||
beautify: false,
|
||||
report: false
|
||||
report: 'min',
|
||||
expression: false,
|
||||
maxLineLen: 32000,
|
||||
ASCIIOnly: false,
|
||||
screwIE8: false,
|
||||
quoteStyle: 0
|
||||
});
|
||||
|
||||
// Process banner.
|
||||
var banner = grunt.template.process(options.banner);
|
||||
var footer = grunt.template.process(options.footer);
|
||||
var mapNameGenerator, mapInNameGenerator, mappingURLGenerator;
|
||||
var banner = normalizeLf(options.banner);
|
||||
var footer = normalizeLf(options.footer);
|
||||
var mapNameGenerator, mapInNameGenerator;
|
||||
var createdFiles = 0;
|
||||
var createdMaps = 0;
|
||||
|
||||
// Iterate over all src-dest file pairs.
|
||||
this.files.forEach(function(f) {
|
||||
var src = f.src.filter(function(filepath) {
|
||||
this.files.forEach(function (f) {
|
||||
var src = f.src.filter(function (filepath) {
|
||||
// Warn on and remove invalid source files (if nonull was set).
|
||||
if (!grunt.file.exists(filepath)) {
|
||||
grunt.log.warn('Source file "' + filepath + '" not found.');
|
||||
grunt.log.warn('Source file ' + chalk.cyan(filepath) + ' not found.');
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
@@ -45,16 +72,23 @@ module.exports = function(grunt) {
|
||||
});
|
||||
|
||||
if (src.length === 0) {
|
||||
grunt.log.warn('Destination (' + f.dest + ') not written because src files were empty.');
|
||||
grunt.log.warn('Destination ' + chalk.cyan(f.dest) + ' not written because src files were empty.');
|
||||
return;
|
||||
}
|
||||
|
||||
// function to get the name of the sourceMap
|
||||
if (typeof options.sourceMap === "function") {
|
||||
mapNameGenerator = options.sourceMap;
|
||||
// Warn on incompatible options
|
||||
if (options.expression && (options.compress || options.mangle)) {
|
||||
grunt.log.warn('Option ' + chalk.cyan('expression') + ' not compatible with ' + chalk.cyan('compress and mangle'));
|
||||
options.compress = false;
|
||||
options.mangle = false;
|
||||
}
|
||||
|
||||
// function to get the name of the sourceMap
|
||||
if (typeof options.sourceMapName === "function") {
|
||||
mapNameGenerator = options.sourceMapName;
|
||||
}
|
||||
|
||||
// function to get the name of the sourceMapIn file
|
||||
if (typeof options.sourceMapIn === "function") {
|
||||
if (src.length !== 1) {
|
||||
grunt.fail.warn('Cannot generate `sourceMapIn` for multiple source files.');
|
||||
@@ -62,23 +96,24 @@ module.exports = function(grunt) {
|
||||
mapInNameGenerator = options.sourceMapIn;
|
||||
}
|
||||
|
||||
// function to get the sourceMappingURL
|
||||
if (typeof options.sourceMappingURL === "function") {
|
||||
mappingURLGenerator = options.sourceMappingURL;
|
||||
}
|
||||
|
||||
// dynamically create destination sourcemap name
|
||||
if (mapNameGenerator) {
|
||||
try {
|
||||
options.sourceMap = mapNameGenerator(f.dest);
|
||||
options.generatedSourceMapName = mapNameGenerator(f.dest);
|
||||
} catch (e) {
|
||||
var err = new Error('SourceMapName failed.');
|
||||
var err = new Error('SourceMap failed.');
|
||||
err.origError = e;
|
||||
grunt.fail.warn(err);
|
||||
}
|
||||
}
|
||||
// If no name is passed append .map to the filename
|
||||
else if (!options.sourceMapName) {
|
||||
options.generatedSourceMapName = f.dest + '.map';
|
||||
} else {
|
||||
options.generatedSourceMapName = options.sourceMapName;
|
||||
}
|
||||
|
||||
// dynamically create incoming sourcemap names
|
||||
// Dynamically create incoming sourcemap names
|
||||
if (mapInNameGenerator) {
|
||||
try {
|
||||
options.sourceMapIn = mapInNameGenerator(src[0]);
|
||||
@@ -89,15 +124,17 @@ module.exports = function(grunt) {
|
||||
}
|
||||
}
|
||||
|
||||
// dynamically create sourceMappingURL
|
||||
if (mappingURLGenerator) {
|
||||
try {
|
||||
options.sourceMappingURL = mappingURLGenerator(f.dest);
|
||||
} catch (e) {
|
||||
var err = new Error('SourceMappingURL failed.');
|
||||
err.origError = e;
|
||||
grunt.fail.warn(err);
|
||||
}
|
||||
// Calculate the path from the dest file to the sourcemap for the
|
||||
// sourceMappingURL reference
|
||||
if (options.sourceMap) {
|
||||
var destToSourceMapPath = relativePath(f.dest, options.generatedSourceMapName);
|
||||
var sourceMapBasename = path.basename(options.generatedSourceMapName);
|
||||
options.destToSourceMap = destToSourceMapPath + sourceMapBasename;
|
||||
}
|
||||
|
||||
if (options.screwIE8) {
|
||||
if (options.mangle) { options.mangle.screw_ie8 = true; }
|
||||
if (options.compress) { options.compress.screw_ie8 = true; }
|
||||
}
|
||||
|
||||
// Minify files, warn and fail on error.
|
||||
@@ -114,7 +151,7 @@ module.exports = function(grunt) {
|
||||
}
|
||||
}
|
||||
err.origError = e;
|
||||
grunt.log.warn('Uglifying source "' + src + '" failed.');
|
||||
grunt.log.warn('Uglifying source ' + chalk.cyan(src) + ' failed.');
|
||||
grunt.fail.warn(err);
|
||||
}
|
||||
|
||||
@@ -129,21 +166,26 @@ module.exports = function(grunt) {
|
||||
// Write the destination file.
|
||||
grunt.file.write(f.dest, output);
|
||||
|
||||
|
||||
// Write source map
|
||||
if (options.sourceMap) {
|
||||
grunt.file.write(options.sourceMap, result.sourceMap);
|
||||
grunt.log.writeln('Source Map "' + options.sourceMap + '" created.');
|
||||
grunt.file.write(options.generatedSourceMapName, result.sourceMap);
|
||||
grunt.verbose.writeln('File ' + chalk.cyan(options.generatedSourceMapName) + ' created (source map).');
|
||||
createdMaps++;
|
||||
}
|
||||
|
||||
// Print a success message.
|
||||
grunt.log.writeln('File "' + f.dest + '" created.');
|
||||
|
||||
// ...and report some size information.
|
||||
if (options.report) {
|
||||
contrib.minMaxInfo(output, result.max, options.report);
|
||||
}
|
||||
grunt.verbose.writeln('File ' + chalk.cyan(f.dest) + ' created: ' +
|
||||
maxmin(result.max, output, options.report === 'gzip'));
|
||||
createdFiles++;
|
||||
});
|
||||
});
|
||||
|
||||
if (createdMaps > 0) {
|
||||
grunt.log.ok(createdMaps + ' source' + grunt.util.pluralize(createdMaps, 'map/maps') + ' created.');
|
||||
}
|
||||
|
||||
if (createdFiles > 0) {
|
||||
grunt.log.ok(createdFiles + ' ' + grunt.util.pluralize(this.files.length, 'file/files') + ' created.');
|
||||
} else {
|
||||
grunt.log.warn('No files created.');
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user