构建

@param {Object} timer         计时器实例
@param {Object} buildConf     构建配置
@param {Object} buildManager  构建实例
@return {Promise}
function buildProject(timer, buildConf, buildManager) {
    let {logger, output: outputOpts} = buildConf;
    let {onBuildStart, onBuildDone} = buildConf.script || {};

    let hookResult = runBuildStartHook(buildManager, onBuildStart);
    let buildResult;
    if (hookResult instanceof Promise) {
        buildResult = hookResult.then(code => {
            logger.debug('init build start done...', code);
            return buildManager.build(timer);
        });
    }
    else {
        buildResult = buildManager.build(timer);
    }

    let doneHandler = buildDone.bind(null, timer, logger, outputOpts.dir);
    return buildResult.then(
        () => buildManager.release()
    ).then(
        doneHandler
    ).then(
        () => {
            runBuildDoneHook(buildManager, onBuildDone);
        }
    ).catch(doneHandler);
}