
var path = require('path');
var fs = require("fs");
var config = require("./config");

var distFolder0, distFolder1, distFolder2;

function copyAll() {
    distFolder0 = path.join(process.cwd(), "publish/ios/" + config.compileOptions.pureGameId + "/Images.xcassets/LaunchImage.launchimage");
    distFolder1 = path.join(process.cwd(), "publish/ios_shell/" + config.compileOptions.pureGameId + "/Images.xcassets/LaunchImage.launchimage");
    distFolder2 = path.join(process.cwd(), "publish/ios_shell1/" + config.compileOptions.pureGameId + "/Images.xcassets/LaunchImage.launchimage");
    try{
        copySplashes(distFolder0);
    } catch (e) {
        console.log(e)
    }
    if(fs.existsSync(distFolder1)) {
        copySplashes(distFolder1);
    }
    if(fs.existsSync(distFolder2)) {
        copySplashes(distFolder2);
    }
}


function copySplashes(distFolder) {
    var files = fs.readdirSync(config.splashesPath);
    files.forEach(function(path) {
        var _src = config.splashesPath + '/' + path;
        var _dist = distFolder + '/' + path;
        var stat = fs.statSync(_src);
        // 判断是文件还是目录
        if (stat.isFile() && path.indexOf(".png") > -1) {
            fs.writeFileSync(_dist, fs.readFileSync(_src));
        }
    })
}

module.exports = copyAll;