<commit_before>'use strict';

const fs = require('fs');
const path = require('path');
const fileConfig = require('./file.config.js');
const _ = require('lodash');
const co = require('co');
const thunkify = require('thunkify');
/**
 * 写数据操作
 * @param  {String}   fd   路径
 * @param  {String}   data 数据内容
 * @param  {Function} cb   [description]
 * @return {[type]}        [description]
 */
function writeFile(fd, data, cb) {
    fs.writeFile(fd, data, function(err) {
        if (err) {
            throw err;
        }
        cb();
    });
}
/**
 * 过滤文件内容
 * @param  {[type]} fData             [description]
 * @param  {[type]} key               [description]
 * @param  {[type]} svnConfig         [description]
 * @param  {[type]} webpackConfigInfo [description]
 * @return {[type]}                   [description]
 */
function filterFileContent(fData, key, svnConfig, webpackConfigInfo) {
    switch (key) {
        case 'qb.html':
            //没有svnConfig的配置信息的时候不生成qb.html
            if (!svnConfig) {
                return false;
            }
            //svn 的trunk目录下的assets文件目录
            fData = fData.replace('onlineSvnPathStr', svnConfig.onlinePath);
            //svn qb上线到的tag目录
            fData = fData.replace('tagPathStr', svnConfig.tagPath);
            //标签名称  这里应该是文件的名字
            fData = fData.replace('tagNameStr', svnConfig.tagName);
            //标签内新增目录
            fData = fData.replace('addPathStr', svnConfig.addPath);
            break;
        case 'config.js':
            fData = fData.replace('{{publicPath}}', webpackConfigInfo.devPubilcPath);
            fData = fData.replace('{{onlinePath}}', webpackConfigInfo.onLinePubilcPath);
            break;
    }
    return fData;
}
/**
 * 拷贝文件工作
 * @param  {[type]} webpackConfigInfo [description]
 * @param  {[type]} svnConfig         [description]
 * @param  {[type]} rootDir           [description]
 * @return {[type]}                   [description]
 */
function copyFile(webpackConfigInfo, svnConfig, rootDir) {
    return co(function*() {
        for (let key in fileConfig) {
            let filePath = path.join(__dirname, '..', 'config', key);
            let fileContent = yield thunkify(fs.readFile)(filePath, 'utf-8');
            fileContent = filterFileContent(fileContent, key, svnConfig, webpackConfigInfo);
            if(!fileContent){
                continue;
            }
            yield thunkify(fs.writeFile)(path.resolve(rootDir, fileConfig[key], key), fileContent);
        }
    });
}

exports.copyFile = copyFile;

// module.exports = {
//     /**
//      * 复制文件
//      * @param  {Object} webpackConfigInfo webpack相关动态配置
//      * @param  {Object} svnConfig         SVN相关配置
//      * @param  {String} rootDir           生成项目的根路径
//      * @param  {Function} cb              文件复制完毕的回调函数
//      */
//     copy: function(webpackConfigInfo, svnConfig, rootDir, cb) {
//         let count = _.size(fileConfig);
//         _.each(fileConfig, function(val, key) {
//
//             fs.readFile(path.resolve(__dirname, '..', 'config', key), 'utf-8', function(err, fData) {
//                 if (err) {
//                     throw err;
//                 }
//                 switch (key) {
//                     case 'qb.html':
//                         //没有svnConfig的配置信息的时候不生成qb.html
//                         if (!svnConfig) {
//                             count--;
//                             return;
//                         }
//                         //svn 的trunk目录下的assets文件目录
//                         fData = fData.replace('onlineSvnPathStr', svnConfig.onlinePath);
//                         //svn qb上线到的tag目录
//                         fData = fData.replace('tagPathStr', svnConfig.tagPath);
//                         //标签名称  这里应该是文件的名字
//                         fData = fData.replace('tagNameStr', svnConfig.tagName);
//                         //标签内新增目录
//                         fData = fData.replace('addPathStr', svnConfig.addPath);
//                         break;
//                     case 'config.js':
//                         fData = fData.replace('{{publicPath}}', webpackConfigInfo.devPubilcPath);
//                         fData = fData.replace('{{onlinePath}}', webpackConfigInfo.onLinePubilcPath);
//                         break;
//                 }
//                 writeFile(path.resolve(rootDir, val, key), fData, function() {
//                     count--;
//                     if (count === 0) {
//                         cb();
//                     }
//                 });
//             });
//         });
//     }
// }<commit_msg>删除多于的code<commit_after>'use strict';

const fs = require('fs');
const path = require('path');
const fileConfig = require('./file.config.js');
const _ = require('lodash');
const co = require('co');
const thunkify = require('thunkify');

/**
 * 过滤文件内容
 * @param  {[type]} fData             [description]
 * @param  {[type]} key               [description]
 * @param  {[type]} svnConfig         [description]
 * @param  {[type]} webpackConfigInfo [description]
 * @return {[type]}                   [description]
 */
function filterFileContent(fData, key, svnConfig, webpackConfigInfo) {
    switch (key) {
        case 'qb.html':
            //没有svnConfig的配置信息的时候不生成qb.html
            if (!svnConfig) {
                return false;
            }
            //svn 的trunk目录下的assets文件目录
            fData = fData.replace('onlineSvnPathStr', svnConfig.onlinePath);
            //svn qb上线到的tag目录
            fData = fData.replace('tagPathStr', svnConfig.tagPath);
            //标签名称  这里应该是文件的名字
            fData = fData.replace('tagNameStr', svnConfig.tagName);
            //标签内新增目录
            fData = fData.replace('addPathStr', svnConfig.addPath);
            break;
        case 'config.js':
            fData = fData.replace('{{publicPath}}', webpackConfigInfo.devPubilcPath);
            fData = fData.replace('{{onlinePath}}', webpackConfigInfo.onLinePubilcPath);
            break;
    }
    return fData;
}
/**
 * 拷贝文件工作
 * @param  {Object} webpackConfigInfo webpack相关动态配置
 * @param  {Object} svnConfig         SVN相关配置
 * @param  {String} rootDir           生成项目的根路径
 * @return {Promise}                  返回promise对象
 */
function copyFile(webpackConfigInfo, svnConfig, rootDir) {
    return co(function*() {
        for (let key in fileConfig) {
            let filePath = path.join(__dirname, '..', 'config', key);
            let fileContent = yield thunkify(fs.readFile)(filePath, 'utf-8');
            fileContent = filterFileContent(fileContent, key, svnConfig, webpackConfigInfo);
            if(!fileContent){
                continue;
            }
            yield thunkify(fs.writeFile)(path.resolve(rootDir, fileConfig[key], key), fileContent);
        }
    });
}

exports.copyFile = copyFile;
{'fraction_non_alphanumeric': 0.1379765395894428, 'fraction_numerical': 0.0005865102639296188, 'mean_word_length': 1.6907297830374755, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2830034', 'n_tokens_mistral': 2140, 'n_tokens_neox': 2141, 'n_words': 385}