Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Prepend right copyright to the passed content

  • Loading branch information...
commit f16485a27a8c8881c54a7d93e151c208d1a92739 1 parent 2ac610a
@gseguin gseguin authored
Showing with 35 additions and 5 deletions.
  1. +35 −5 build/filter.js
View
40 build/filter.js
@@ -5,9 +5,39 @@
var fs = require( 'fs' ),
path = require( 'path' ),
buildDir = __dirname,
- versionRegExp = /__version__/g,
- version = fs.readFileSync( path.join( buildDir, "../version.txt" ), "utf8" ).trim();
+ copyrightVersionRegExp = /@VERSION/g,
+ apiVersionRegExp = /__version__/g,
+ copyrightBaseName = "../LICENSE-INFO",
+ copyrightRegFile = copyrightBaseName + ".txt",
+ copyrightMinFile = copyrightBaseName + ".min.txt";
-module.exports = function ( contents ) {
- return contents.replace( versionRegExp, '"' + version + '"' );
-};
+module.exports = function ( contents, ext, callback ) {
+ fs.readFile( path.join( buildDir, "../version.txt" ), "utf8",
+ function( err, version ) {
+ var copyrightFile;
+ if ( err ) {
+ callback( err );
+ } else {
+ version = version.trim();
+
+ if ( /^\.min/.test( ext ) ) {
+ copyrightFile = copyrightMinFile;
+ } else {
+ copyrightFile = copyrightRegFile;
+ }
+ fs.readFile( path.join( buildDir, copyrightFile ), "utf8",
+ function( err, copyright ) {
+ if ( err ) {
+ callback( err );
+ } else {
+ contents = copyright.replace( copyrightVersionRegExp, version ) + "\n" + contents;
+ contents = contents.replace( apiVersionRegExp, '"' + version + '"' );
+
+ callback( null, contents );
+ }
+ }
+ )
+ }
+ }
+ )
+};

0 comments on commit f16485a

Please sign in to comment.
Something went wrong with that request. Please try again.