{"size": 830, "ext": "js", "max_stars_repo_path": "rsg-config/replace.cdn.js", "max_stars_repo_name": "cl1107/react-bmapgl", "max_stars_repo_stars_event_min_datetime": "2020-08-04T09:58:14.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-12T05:25:37.000Z", "max_issues_repo_path": "rsg-config/replace.cdn.js", "max_issues_repo_name": "cl1107/react-bmapgl", "max_issues_repo_issues_event_min_datetime": "2020-09-16T08:20:32.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-29T06:12:51.000Z", "max_forks_repo_path": "rsg-config/replace.cdn.js", "max_forks_repo_name": "cl1107/react-bmapgl", "max_forks_repo_forks_event_min_datetime": "2021-01-19T01:36:45.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-03T05:23:36.000Z"}
{"max_stars_count": 62, "max_issues_count": 40, "max_forks_count": 7, "avg_line_length": 33.2, "max_line_length": 131, "alphanum_fraction": 0.6084337349}
var fs = require('fs');
var path = require('path');

// readdir方法读取文件名
// readFile方法读取文件内容
// writeFile改写文件内容
var filePath = path.resolve(__dirname, '../styleguide/index.html');

// 把.js文件替换成线上cdn域名前缀，正则的(?<!\/)表示后面那串的前面没有`/`，避免二次替换造成bug
fs.readFile(filePath, 'utf8', function (err, result) {
    var reg = /(?<!\/)(build\/bundle\.\S{8}\.js)/;
    var matchString = result.match(reg);
    if (matchString) {
        console.log(`replacing CDN: "${matchString[0]}"  ==>  "//mapopen.cdn.bcebos.com/github/react-bmapgl/${matchString[0]}"\n`);
        result = result.replace(reg, '//mapopen.cdn.bcebos.com/github/react-bmapgl/$1');
    } else {
        console.log(`no CDN to replace\n`);
    }
    fs.writeFile(filePath, result, 'utf8', function (err) {
        if (err) {
            return console.log(err);
        }
    });
});
