-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Build: Migrate to grunt 0.4. #867
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,19 @@ module.exports = function( grunt ) { | |
var path = require( "path" ), | ||
fs = require( "fs" ); | ||
|
||
function expandFiles( files ) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The other one is used directly, and only points at files. This one is used via tasks and gets folder wildcards as inputs. Folders have to be filtered out. I'm not sure what you mean with "expose it instead of redefining it". See also gruntjs/grunt#700 |
||
return grunt.util._.pluck( grunt.file.expandMapping( files ), "src" ).filter(function(filepath) { | ||
// restrict to files, exclude folders | ||
try { | ||
return fs.statSync( filepath[ 0 ] ).isFile(); | ||
} catch(e) { | ||
throw grunt.task.taskError(e.message, e); | ||
} | ||
}).map(function( values ) { | ||
return values[ 0 ]; | ||
}); | ||
} | ||
|
||
grunt.registerTask( "manifest", "Generate jquery.json manifest files", function() { | ||
var pkg = grunt.config( "pkg" ), | ||
base = { | ||
|
@@ -97,8 +110,8 @@ grunt.registerMultiTask( "copy", "Copy files to destination folder and replace @ | |
grunt.file.copy( src, dest ); | ||
} | ||
} | ||
var files = grunt.file.expandFiles( this.file.src ), | ||
target = this.file.dest + "/", | ||
var files = expandFiles( this.filesSrc ), | ||
target = this.data.dest + "/", | ||
strip = this.data.strip, | ||
renameCount = 0, | ||
fileName; | ||
|
@@ -121,28 +134,11 @@ grunt.registerMultiTask( "copy", "Copy files to destination folder and replace @ | |
|
||
|
||
grunt.registerMultiTask( "zip", "Create a zip file for release", function() { | ||
// TODO switch back to adm-zip for better cross-platform compability once it actually works | ||
// 0.1.3 works, but result can't be unzipped | ||
// its also a lot slower then zip program, probably due to how its used... | ||
// var files = grunt.file.expandFiles( "dist/" + this.file.src + "/**/*" ); | ||
// grunt.log.writeln( "Creating zip file " + this.file.dest ); | ||
|
||
//var AdmZip = require( "adm-zip" ); | ||
//var zip = new AdmZip(); | ||
//files.forEach(function( file ) { | ||
// grunt.verbose.writeln( "Zipping " + file ); | ||
// // rewrite file names from dist folder (created by build), drop the /dist part | ||
// zip.addFile(file.replace(/^dist/, "" ), fs.readFileSync( file ) ); | ||
//}); | ||
//zip.writeZip( "dist/" + this.file.dest ); | ||
//grunt.log.writeln( "Wrote " + files.length + " files to " + this.file.dest ); | ||
|
||
var done = this.async(), | ||
dest = this.file.dest, | ||
src = grunt.template.process( this.file.src, grunt.config() ); | ||
grunt.utils.spawn({ | ||
dest = this.data.dest; | ||
grunt.util.spawn({ | ||
cmd: "zip", | ||
args: [ "-r", dest, src ], | ||
args: [ "-r", dest, this.data.src ], | ||
opts: { | ||
cwd: 'dist' | ||
} | ||
|
@@ -159,19 +155,19 @@ grunt.registerMultiTask( "zip", "Create a zip file for release", function() { | |
|
||
grunt.registerMultiTask( "md5", "Create list of md5 hashes for CDN uploads", function() { | ||
// remove dest file before creating it, to make sure itself is not included | ||
if ( fs.existsSync( this.file.dest ) ) { | ||
fs.unlinkSync( this.file.dest ); | ||
if ( fs.existsSync( this.data.dest ) ) { | ||
fs.unlinkSync( this.data.dest ); | ||
} | ||
var crypto = require( "crypto" ), | ||
dir = this.file.src + "/", | ||
dir = this.filesSrc + "/", | ||
hashes = []; | ||
grunt.file.expandFiles( dir + "**/*" ).forEach(function( fileName ) { | ||
expandFiles( dir + "**/*" ).forEach(function( fileName ) { | ||
var hash = crypto.createHash( "md5" ); | ||
hash.update( grunt.file.read( fileName, "ascii" ) ); | ||
hashes.push( fileName.replace( dir, "" ) + " " + hash.digest( "hex" ) ); | ||
}); | ||
grunt.file.write( this.file.dest, hashes.join( "\n" ) + "\n" ); | ||
grunt.log.writeln( "Wrote " + this.file.dest + " with " + hashes.length + " hashes" ); | ||
grunt.file.write( this.data.dest, hashes.join( "\n" ) + "\n" ); | ||
grunt.log.writeln( "Wrote " + this.data.dest + " with " + hashes.length + " hashes" ); | ||
}); | ||
|
||
grunt.registerTask( "generate_themes", function() { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's with this? Does
grunt.file.expandFiles
no longer exist? What does it not (or no longer) do thatgrunt.file.expandMapping
(called fromexpandFiles
) does do?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
expandFiles
is gone andexpandMappings
returns a map of src -> dest, not an array.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Crap, you're right. It was removed...