"use strict";
var util = require( './lib/util' ).obj;
var bUtil = require( './util/build.util' ).obj;

exports.build_cmd = [ {
    "info": "发布模板",
    "cmd": "tpl_release"
}, {
    "info": "复制默认的项目配置",
    "cmd": "copy_project_conf"
}, {
    "info": "创建项目频道",
    "cmd": "build_module"
} ];

exports.init = function() {
    var project_name;
    if ( arguments.length > 1 ) {
        project_name = arguments[ 1 ];
    } else {
        project_name = bUtil.getName( "请输入您要创建的项目名：" );
    }
    if ( !project_name ) {
        return;
    }
    exports.cmd( project_name );
};
exports.cmd = function( project_name ) {
    exports[ bUtil.select_cmd( exports.build_cmd ) ]( project_name );
};
exports.tpl_release = function( projectModule ) {
    var prj_hoo_conf;
    if ( ( prj_hoo_conf = bUtil.is_project_dir() ) === false ) {
        return util.error( "请在项目目录里操作项目的频道！！" );
    }
    if ( !projectModule ) {
        return util.error( "请输入你要操作的频道名！！" );
    }
    var tplSrc = prj_hoo_conf.set.tplSrc;
    var tplDest = prj_hoo_conf.set.tplDest;

    if ( projectModule === "common" ) {
        //复制文件
        util.copyDir( tplSrc + projectModule, tplDest + projectModule, prj_hoo_conf.tplParseData );
    } else {
        util.copyDir( tplSrc + "home/" + projectModule, tplDest + "home/" + projectModule, prj_hoo_conf.tplParseData );
        util.copyDir( tplSrc + "modules/" + projectModule, tplDest + "modules/" + projectModule, prj_hoo_conf.tplParseData );

        if ( prj_hoo_conf.specialTpl.hasOwnProperty( projectModule ) ) {
            var specialTpl = prj_hoo_conf.specialTpl[ projectModule ];
            for ( var i = 0; i < specialTpl.length; i++ ) {
                util.copyDir( specialTpl[ i ].src, specialTpl[ i ].dest, prj_hoo_conf.tplParseData );
            }
        }
    }
};
exports.tpl_tmp = function(projectModule) {
    var prj_hoo_conf;
    if ( ( prj_hoo_conf = bUtil.is_project_dir() ) === false ) {
        return util.error( "请在项目目录里操作项目的频道！！" );
    }
    if ( !projectModule ) {
        return util.error( "请输入你要操作的频道名！！" );
    }
    var tplSrc = prj_hoo_conf.set.tplSrc;
    
}