Skip to content

Instantly share code, notes, and snippets.

@davidsharp
Created August 23, 2016 16:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidsharp/4edaff0d0b8e606e27d685085bc28262 to your computer and use it in GitHub Desktop.
Save davidsharp/4edaff0d0b8e606e27d685085bc28262 to your computer and use it in GitHub Desktop.
A Node after_prepare hook for iOS, for moving image location issues when upgrading from cordova-ios@3.X.X to 4.X.X
#!/usr/bin/env node
console.log('ios image moving has begun');
var fs = require('fs');
var path = require('path');
var rootdir = process.argv[2];
function move_folder_contents(_from,_to){
if(fs.statSync(_from).isDirectory()
&& fs.statSync(_to).isDirectory()){
fs.readdir(_from,(err,fileNames)=>{
fileNames.forEach(c=>{
try{
fs.renameSync(
path.join(_from,c),
path.join(_to,c)
)
}catch(e){console.error(`Failed to move ${c} from ${_from} to ${_to}, received error: ${e}`);}
})
});
}
}
if (rootdir) {
//TODO: replace project name before use
var fullfilename = path.join(rootdir, "platforms","ios","MyAwesomeCordovaProject","Resources");
var xcodefilename = path.join(rootdir, "platforms","ios","MyAwesomeCordovaProject","Images.xcassets");
if (fs.statSync(fullfilename).isDirectory() && fs.statSync(xcodefilename).isDirectory()) {
move_folder_contents(path.join(fullfilename,'icons'),path.join(xcodefilename,'AppIcon.appiconset'));
move_folder_contents(path.join(fullfilename,'splash'),path.join(xcodefilename,'LaunchImage.launchimage'));
}else{console.log(fullfilename+' or '+xcodefilename+' folder: not found');}
}
console.log('ios image moving has ended');
console.log(`Prepared at: ${new Date().toTimeString()}`);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment