mirror of
https://github.com/wassname/CanvasTextWrapper.git
synced 2026-08-03 12:30:38 +08:00
git ignore updates
This commit is contained in:
+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