Skip to content

Commit 2f4c74c

Browse files
committed
Grunt: Replace all instances of @Version during copy. Fixes #8261 - Build: @Version replacement incomplete.
(cherry picked from commit 7475763)
1 parent aec682c commit 2f4c74c

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

grunt.js

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,16 @@ grunt.initConfig({
332332

333333
grunt.registerMultiTask( "copy", "Copy files to destination folder and replace @VERSION with pkg.version", function() {
334334
function replaceVersion( source ) {
335-
return source.replace( "@VERSION", grunt.config( "pkg.version" ) );
335+
return source.replace( /@VERSION/g, grunt.config( "pkg.version" ) );
336+
}
337+
function copyFile( src, dest ) {
338+
if ( /(js|css)$/.test( src ) ) {
339+
grunt.file.copy( src, dest, {
340+
process: replaceVersion
341+
});
342+
} else {
343+
grunt.file.copy( src, dest );
344+
}
336345
}
337346
var files = grunt.file.expandFiles( this.file.src );
338347
var target = this.file.dest + "/";
@@ -342,19 +351,13 @@ grunt.registerMultiTask( "copy", "Copy files to destination folder and replace @
342351
}
343352
files.forEach(function( fileName ) {
344353
var targetFile = strip ? fileName.replace( strip, "" ) : fileName;
345-
if ( /(js|css)$/.test( fileName ) ) {
346-
grunt.file.copy( fileName, target + targetFile, {
347-
process: replaceVersion
348-
});
349-
} else {
350-
grunt.file.copy( fileName, target + targetFile );
351-
}
354+
copyFile( fileName, target + targetFile );
352355
});
353356
grunt.log.writeln( "Copied " + files.length + " files." );
354357
var renameCount = 0;
355358
for ( var fileName in this.data.renames ) {
356359
renameCount += 1;
357-
grunt.file.copy( fileName, target + grunt.template.process( this.data.renames[ fileName ], grunt.config() ) );
360+
copyFile( fileName, target + grunt.template.process( this.data.renames[ fileName ], grunt.config() ) );
358361
}
359362
if ( renameCount ) {
360363
grunt.log.writeln( "Renamed " + renameCount + " files." );

0 commit comments

Comments
 (0)