Last active
August 29, 2015 14:02
-
-
Save nerik/64e4798d2bf1c19800f6 to your computer and use it in GitHub Desktop.
make a local copy of mapbox assets
This file contains 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('mapbox', function() { | |
var version = this.options().version; | |
console.log('mapbox v' + version); | |
var baseUrl = 'https://api.tiles.mapbox.com/mapbox.js/v'+version+'/'; | |
//async task | |
var done = this.async(); | |
//reset mapbox folder in bower_components | |
exec('rm -rf app/bower_components/mapbox.css'); | |
exec('rm -rf app/bower_components/mapbox.js'); | |
//grab latest mapbox js and css files through bower | |
exec('bower install mapbox.js='+baseUrl+'mapbox.js --save', function(err, stdout, stderr) { | |
console.log(stdout); | |
exec('bower install mapbox.css='+baseUrl+'mapbox.css --save', function(err, stdout, stderr) { | |
console.log(stdout); | |
prepareStyles(); | |
}); | |
}); | |
//rename mapbox css to scss, move it to styles, replace image links with local versions (donwloaded later) | |
function prepareStyles() { | |
var scssPath = 'app/assets/styles/mapbox/mapbox.scss'; | |
fs.writeFileSync(scssPath, fs.readFileSync('app/bower_components/mapbox.css/index.css')); | |
var scss = fs.readFileSync(scssPath).toString(); | |
scss = scss.replace(/url\(images\//g, 'url(../images/mapbox/'); | |
fs.writeFileSync(scssPath, scss); | |
fetchImages(); | |
} | |
//fetch mapbox image assets | |
function fetchImages() { | |
process.chdir('app/assets/images/mapbox/') | |
exec('curl -O '+baseUrl+'images/icons-000000.png', function(err, stdout, stderr) { | |
exec('curl -O '+baseUrl+'images/icons-ffffff.png', function(err, stdout, stderr) { | |
exec('curl -O '+baseUrl+'images/[email protected]', function(err, stdout, stderr) { | |
exec('curl -O '+baseUrl+'images/[email protected]', function(err, stdout, stderr) { | |
done(); | |
}); | |
}); | |
}); | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment