Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

chore(grunt): add filename to comment header #12499

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions lib/grunt/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,9 @@ module.exports = {
},


process: function(src, NG_VERSION, strict){
process: function(src, NG_VERSION, fileName, strict){
var processed = src
.replace(/"NG_FILENAME"/g, fileName)
.replace(/"NG_VERSION_FULL"/g, NG_VERSION.full)
.replace(/"NG_VERSION_MAJOR"/, NG_VERSION.major)
.replace(/"NG_VERSION_MINOR"/, NG_VERSION.minor)
Expand All @@ -146,7 +147,7 @@ module.exports = {
return grunt.file.read(filepath);
}).join(grunt.util.normalizelf('\n'));
//process
var processed = this.process(src, grunt.config('NG_VERSION'), config.strict);
var processed = this.process(src, grunt.config('NG_VERSION'), this.extractFileName(config.dest), config.strict);
if (styles) {
processedStyles = this.addStyle(processed, styles.css, styles.minify);
processed = processedStyles.js;
Expand All @@ -164,23 +165,30 @@ module.exports = {
}
},


singleStrict: function(src, insert){
return src
.replace(/\s*("|')use strict("|');\s*/g, insert) // remove all file-specific strict mode flags
.replace(/(\(function\([^)]*\)\s*\{)/, "$1'use strict';"); // add single strict mode flag
},

extractFileName: function(path) {
return path.match(/[^\/]+$/)[0];
},

sourceMap: function(mapFile, fileContents) {
var sourceMapLine = '//# sourceMappingURL=' + mapFile + '\n';
return fileContents + sourceMapLine;
},

fileToMinFile: function(fileName, minFileName, fileContents) {
return fileContents.replace(fileName, minFileName);
},

min: function(file, done) {
var classPathSep = (process.platform === "win32") ? ';' : ':';
var fileName = this.extractFileName(file);
var minFile = file.replace(/\.js$/, '.min.js');
var minFileName = this.extractFileName(minFile);
var mapFile = minFile + '.map';
var mapFileName = mapFile.match(/[^\/]+$/)[0];
var errorFileName = file.replace(/\.js$/, '-errors.json');
Expand Down Expand Up @@ -212,6 +220,10 @@ module.exports = {

// move add use strict into the closure + add source map pragma
grunt.file.write(minFile, this.sourceMap(mapFileName, this.singleStrict(grunt.file.read(minFile), '\n')));

// change comment header filename to minified filename
grunt.file.write(minFile, this.fileToMinFile(fileName, minFileName, grunt.file.read(minFile)));

grunt.log.ok(file + ' minified into ' + minFile);
done();
}.bind(this));
Expand Down
5 changes: 3 additions & 2 deletions src/angular.prefix
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/**
* @license AngularJS v"NG_VERSION_FULL"
/**
* @license "NG_FILENAME"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any specific reason why the filename is now the first item in the header?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's just how it was requested in issue #12185

* AngularJS v"NG_VERSION_FULL"
* (c) 2010-2015 Google, Inc. http://angularjs.org
* License: MIT
*/
Expand Down
3 changes: 2 additions & 1 deletion src/loader.prefix
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/**
* @license AngularJS v"NG_VERSION_FULL"
* @license "NG_FILENAME"
* AngularJS v"NG_VERSION_FULL"
* (c) 2010-2015 Google, Inc. http://angularjs.org
* License: MIT
*/
Expand Down
3 changes: 2 additions & 1 deletion src/module.prefix
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/**
* @license AngularJS v"NG_VERSION_FULL"
* @license "NG_FILENAME"
* AngularJS v"NG_VERSION_FULL"
* (c) 2010-2015 Google, Inc. http://angularjs.org
* License: MIT
*/
Expand Down