Skip to content

Commit

Permalink
Add more rules to the package.js
Browse files Browse the repository at this point in the history
  • Loading branch information
green3g committed May 12, 2016
1 parent 059b3ac commit a62df6a
Showing 1 changed file with 32 additions and 7 deletions.
39 changes: 32 additions & 7 deletions package.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,21 @@
*/

var profile = (function() {
var excludes = {
'Gruntfile': 1,
'package': 1
};
//only copy files matching these expressions
//this prevents them from being evaluated as amd modules
var reCopyOnly = [
/Gruntfile/,
/package/
];
//exclude from builds completely
var reMiniExclude = [
/Gruntfile/,
/package/
];
//non-amd modules
var reNonAmd = [
/plugins\/Google/
];
return {
// Resource tags are functions that provide hints to the build system about the way files should be processed.
// Each of these functions is called once for every file in the package directory. The first argument passed to
Expand All @@ -26,23 +37,37 @@ var profile = (function() {
// are typically binaries (images, etc.) and may be corrupted by the build system if it attempts to process
// them and naively assumes they are scripts.
copyOnly: function(filename, mid) {
for (var i = 0; i < reCopyOnly.length; i++) {
if (reCopyOnly[i].test(filename)) {
return true;
}
}
return (/\/(images)\//.test(mid) && !/\.css$/.test(filename)) ||
/\/node_modules\//.test(mid) ||
filename in excludes;
/\/node_modules\//.test(mid);
},

// Files that are AMD modules.
// All JavaScript in this package should be AMD modules if you are starting a new project. If you are copying
// any legacy scripts from an existing project, those legacy scripts should not be given the `amd` tag.
amd: function(filename, mid) {
for (var i = 0; i < reNonAmd.length; i++) {
if (reNonAmd[i].test(filename)) {
return false;
}
}
return !this.copyOnly(filename, mid) && /\.js$/.test(filename);
},

// Files that should not be copied when the `mini` build flag is set to true.
// In this case, we are excluding this package configuration file which is not necessary in a built copy of
// the application.
miniExclude: function(filename, mid) {
return filename in excludes;
for (var i = 0; i < reMiniExclude.length; i++) {
if (reMiniExclude[i].test(filename)) {
return true;
}
}
return false;
}
}
};
Expand Down

0 comments on commit a62df6a

Please sign in to comment.