Skip to content

Instantly share code, notes, and snippets.

@jimthedev
Last active April 2, 2018 06:55
Show Gist options
  • Save jimthedev/36922801126eafd4d28b to your computer and use it in GitHub Desktop.
Save jimthedev/36922801126eafd4d28b to your computer and use it in GitHub Desktop.
Shell script to automatically copy icons and splash screens in Cordova 3.5 / Ionic Framework
#!/usr/bin/env node
// this file lives at hooks/after_prepare/010_resource_files.js
// It copies my icon and splash screens to the correct location
// so that they will be loaded by Cordova 3.5
//
// This hook copies various resource files
// from our version control system directories
// into the appropriate platform specific location
// configure all the files to copy.
// Key of object is the source file,
// value is the destination location.
// It's fine to put all platforms' icons
// and splash screen files here, even if
// we don't build for all platforms
// on each developer's box.
// Original script described here: http://devgirl.org/2013/11/12/three-hooks-your-cordovaphonegap-project-needs/
var filestocopy = [
{
"app/res/icon/android/android-icon-96.png":
"platforms/android/res/drawable/icon.png"
}, {
"app/res/icon/android/android-icon-72.png":
"platforms/android/res/drawable-hdpi/icon.png"
}, {
"app/res/icon/android/android-icon-36.png":
"platforms/android/res/drawable-ldpi/icon.png"
}, {
"app/res/icon/android/android-icon-48.png":
"platforms/android/res/drawable-mdpi/icon.png"
}, {
"app/res/icon/android/android-icon-96.png":
"platforms/android/res/drawable-xhdpi/icon.png"
}, {
"app/res/screen/android/android-splash-320x426.9.png":
"platforms/android/res/drawable/screen.9.png"
}, {
"app/res/screen/android/android-splash-480x640.9.png":
"platforms/android/res/drawable-hdpi/screen.9.png"
}, {
"app/res/screen/android/android-splash-320x426.9.png":
"platforms/android/res/drawable-ldpi/screen.9.png"
}, {
"app/res/screen/android/android-splash-320x470.9.png":
"platforms/android/res/drawable-mdpi/screen.9.png"
}, {
"app/res/screen/android/android-splash-780x960.9.png":
"platforms/android/res/drawable-xhdpi/screen.9.png"
}, {
"app/res/icon/ios/iphone-ios6-app-57.png":
"platforms/ios/FisdapMobile/Resources/icons/icon.png"
}, {
"app/res/icon/ios/[email protected]":
"platforms/ios/FisdapMobile/Resources/icons/[email protected]"
}, {
"app/res/icon/ios/iphone-ipad-ios7-search-40.png":
"platforms/ios/FisdapMobile/Resources/icons/icon-40.png"
}, {
"app/res/icon/ios/[email protected]":
"platforms/ios/FisdapMobile/Resources/icons/[email protected]"
}, {
"app/res/icon/ios/ipad-ios6-search-settings-50.png":
"platforms/ios/FisdapMobile/Resources/icons/icon-50.png"
}, {
"app/res/icon/ios/[email protected]":
"platforms/ios/FisdapMobile/Resources/icons/[email protected]"
}, {
"app/res/icon/ios/iphone-ios7-app-60.png":
"platforms/ios/FisdapMobile/Resources/icons/icon-60.png"
}, {
"app/res/icon/ios/[email protected]":
"platforms/ios/FisdapMobile/Resources/icons/[email protected]"
}, {
"app/res/icon/ios/ipad-ios6-app-72.png":
"platforms/ios/FisdapMobile/Resources/icons/icon-72.png"
}, {
"app/res/icon/ios/[email protected]":
"platforms/ios/FisdapMobile/Resources/icons/[email protected]"
}, {
"app/res/icon/ios/ipad-ios7-app-76.png":
"platforms/ios/FisdapMobile/Resources/icons/icon-76.png"
}, {
"app/res/icon/ios/[email protected]":
"platforms/ios/FisdapMobile/Resources/icons/[email protected]"
}, {
"app/res/icon/ios/iphone-ipad-ios7-settings-29.png":
"platforms/ios/FisdapMobile/Resources/icons/icon-small.png"
}, {
"app/res/icon/ios/[email protected]":
"platforms/ios/FisdapMobile/Resources/icons/[email protected]"
}, {
"app/res/screen/ios/[email protected]":
"platforms/ios/FisdapMobile/Resources/splash/Default@2x~iphone.png"
}, {
"app/res/screen/ios/[email protected]":
"platforms/ios/FisdapMobile/Resources/splash/Default-568h@2x~iphone.png"
}, {
"app/res/screen/ios/[email protected]":
"platforms/ios/FisdapMobile/Resources/splash/Default-Landscape@2x~ipad.png"
}, {
"app/res/screen/ios/apple-ipad-splash-1024x768.png":
"platforms/ios/FisdapMobile/Resources/splash/Default-Landscape~ipad.png"
}, {
"app/res/screen/ios/[email protected]":
"platforms/ios/FisdapMobile/Resources/splash/Default-Portrait@2x~ipad.png"
}, {
"app/res/screen/ios/apple-ipad-splash-768x1024.png":
"platforms/ios/FisdapMobile/Resources/splash/Default-Portrait~ipad.png"
}, {
"app/res/screen/ios/apple-iphone-splash-320x480.png":
"platforms/ios/FisdapMobile/Resources/splash/Default~iphone.png"
} ];
var fs = require('fs');
var path = require('path');
// no need to configure below
var rootdir = process.argv[2];
filestocopy.forEach(function(obj) {
Object.keys(obj).forEach(function(key) {
var val = obj[key];
var srcfile = path.join(rootdir, key);
var destfile = path.join(rootdir, val);
var destdir = path.dirname(destfile);
if (fs.existsSync(srcfile) && fs.existsSync(destdir)) {
fs.createReadStream(srcfile).pipe(
fs.createWriteStream(destfile));
}
});
});
@davorpeic
Copy link

Hi, it seems this is not working anymore on cordova 4.0?
thank you

edit: I just found that cordova 4 is finally handling this automatically from config.xml
http://cordova.apache.org/docs/en/edge/config_ref_images.md.html#Icons%20and%20Splash%20Screens

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment