Use @license in the copyright/license header. [closes #138]

Former-commit-id: 3b924dad24d56e0fd33e4df1341b09c6165521a1
This commit is contained in:
John-David Dalton
2012-12-22 14:51:28 -06:00
parent bd8f882c94
commit bda4747e9c
12 changed files with 307 additions and 320 deletions

View File

@@ -204,6 +204,7 @@
// restrict lines to 500 characters for consistency with the Closure Compiler
var stream = uglifyJS.OutputStream({
'ascii_only': true,
'comments': true,
'max_line_len': 500,
});

View File

@@ -6,15 +6,13 @@
var fs = require('fs');
/** The minimal license/copyright template */
var licenseTemplate = {
'lodash':
'/*!\n' +
' Lo-Dash <%= VERSION %> lodash.com/license\n' +
' Underscore.js 1.4.3 underscorejs.org/LICENSE\n' +
'*/',
'underscore':
'/*! Underscore.js <%= VERSION %> underscorejs.org/LICENSE */'
};
var licenseTemplate = [
'/**',
' * @license',
' * Lo-Dash <%= VERSION %> lodash.com/license',
' * Underscore.js 1.4.3 underscorejs.org/LICENSE',
' */'
].join('\n');
/*--------------------------------------------------------------------------*/
@@ -26,6 +24,9 @@
* @returns {String} Returns the processed source.
*/
function postprocess(source) {
// remove old copyright/license header
source = source.replace(/^\/\**[\s\S]+?\*\/\n/, '');
// move vars exposed by the Closure Compiler into the IIFE
source = source.replace(/^((?:(['"])use strict\2;)?(?:var (?:[a-z]+=(?:!0|!1|null)[,;])+)?)([\s\S]*?function[^)]+\){)/, '$3$1');
@@ -53,9 +54,11 @@
if (!snippet) {
return source;
}
// add copyright/license header
return licenseTemplate[/call\(this\);?$/.test(source) ? 'underscore' : 'lodash']
.replace('<%= VERSION %>', snippet[2]) + '\n;' + source;
// add new copyright/license header
var version = snippet[2];
source = licenseTemplate.replace('<%= VERSION %>', version) + '\n;' + source;
return source;
}
/*--------------------------------------------------------------------------*/

View File

@@ -191,11 +191,7 @@
// properties used by the `backbone` and `underscore` builds
'__chain__',
'chain',
// properties used by underscore.js
'_chain',
'_wrapped'
'chain'
];
/*--------------------------------------------------------------------------*/
@@ -217,9 +213,6 @@
if (options.isTemplate) {
return source;
}
// remove copyright/license header to add later in post-compile.js
source = source.replace(/\/\*![\s\S]+?\*\//, '');
// add brackets to whitelisted properties so the Closure Compiler won't mung them
// http://code.google.com/closure/compiler/docs/api-tutorial3.html#export
source = source.replace(RegExp('\\.(' + propWhitelist.join('|') + ')\\b', 'g'), function(match, prop) {
@@ -229,9 +222,6 @@
// remove brackets from `_.escape()` in `_.template`
source = source.replace(/__e *= *_\['escape']/g, '__e=_.escape');
// remove brackets from `_.escape()` in underscore.js `_.template`
source = source.replace(/_\['escape'\]\(__t'/g, '_.escape(__t');
// remove brackets from `collection.indexOf` in `_.contains`
source = source.replace("collection['indexOf'](target)", 'collection.indexOf(target)');
@@ -252,9 +242,6 @@
return (captured || '') + string;
});
// add newline to `+"__p+='"` in underscore.js `_.template`
source = source.replace(/\+"__p\+='"/g, '+"\\n__p+=\'"');
// add newline to `body + '}'` in `createFunction`
source = source.replace(/body *\+ *'}'/, 'body+"\\n}"');