Created
March 15, 2015 21:27
-
-
Save adasq/2cd367081c3359613681 to your computer and use it in GitHub Desktop.
grunt file expand
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
grunt.registerTask('bs', 'sadas', function(){ | |
var result2, result3; | |
var realPaths = grunt.file.expand({ | |
cwd: 'project' | |
},'**/*.js'); | |
result2 = _.map(realPaths, function(path){ | |
var parts = path.split('/'); | |
return { | |
absolute: path, | |
filename: parts[parts.length-1] | |
}; | |
}); | |
result3 = _.map(realPaths, function(path){ | |
return { | |
'src': path, | |
'new': '' | |
}; | |
}); | |
// grunt.file.write('filemap.json', JSON.stringify({js: result3})); | |
var content = grunt.file.readJSON('filemap.json'); | |
var mappingPaths = _.pluck(content.js, 'src'); | |
console.log(_.difference(realPaths, mappingPaths)); | |
}); | |
grunt.registerTask('copy2', '', function(){ | |
var SOURCE_DIR = 'project/'; | |
var TARGET_DIR = 'project2/'; | |
var mapFiles = grunt.file.readJSON('filemap.json'); | |
//console.log(mapFiles); | |
_.each(mapFiles.js, function(obj){ | |
var parts = obj.src.split('/') | |
, fileName = '/'+parts[parts.length-1] | |
, sourcePath = SOURCE_DIR+obj.src | |
, targetPath = TARGET_DIR+obj['new']+fileName | |
; | |
grunt.file.copy(sourcePath, targetPath, { | |
process: function(__, src){ | |
if(!grunt.file.exists(sourcePath)){ | |
console.log('src not exists!:', src); | |
return false; | |
} | |
return targetPath; | |
} | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment