<commit_before>const fs = require('fs');
const fse = require('fs.extra');
var cmd = require('node-cmd');

const destPath = '../../deploy';
const gulpSrc = 'gulpfile.merge.js';
const gulpDest = '../../deploy/gulpfile.js';
const deploySrc = './dist/deploy.js';
const deployDest = '../../deploy/deploy.js';
const demoSrc = './demofiles';
const demoDest = '../../config/';
const packageName = 'ais-sp-js-deployment';
const confDestReg = /configDest\s=\s'.*'/;
let confDest = 'configDest = \'../config/\'';
const confPrefixReg = /partialConfigPrefix\s=\s'.*'/;
let confDemoPrefix = 'partialConfigPrefix = \'democonfig_*.json\'';
const deployScript = 'cd deploy && gulp && cd .. && node ./deploy/deploy -f config/config_demo.json';

function processGulpfile() {
    fs.exists(gulpDest, exists => {
        if (exists) {
            let file = fs.readFileSync(gulpDest, 'utf8');
            let fileConfDest = file.match(confDestReg);
            if (fileConfDest) confDest = fileConfDest[0];
            let fileConfDemoPrefix = file.match(confPrefixReg);
            if (fileConfDemoPrefix) confDemoPrefix = fileConfDemoPrefix[0];
        }
        fs.rename(gulpSrc, gulpDest, error => {
            console.log("- copy gulpfile for config merge");
            if (error) {
                console.error(error);
            } else {
                fs.readFile(gulpDest, 'utf8', (error, data) => {
                    console.log('- gulpfile replacements');
                    if (error) {
                        console.error(error);
                    } else {
                        let result = data.replace(confPrefixReg, confDemoPrefix);
                        result = result.replace(confDestReg, confDest);
                        fs.writeFile(gulpDest, result, 'utf8', error => {
                            if (error) {
                                return console.log(error);
                            };
                        });
                    }
                });
            }
        });
    });
}

function processDeployJs() {
    fs.rename(deploySrc, deployDest, error => {
        console.log('- copy deploy.js');
        if (error) {
            console.error(error);
        } else {
            fs.readFile(deployDest, 'utf8', (error, data) => {
                console.log('- fix deploy.js requires');
                if (error) {
                    console.error(error);
                } else {
                    let result = data.replace('./index', packageName);
                    result = result.replace('//# sourceMappingURL=deploy.js.map', '');
                    fs.writeFile(deployDest, result, 'utf8', error => {
                        if (error) {
                            return console.error(error);
                        };
                    });
                }
            });
        }
    });
}

function createPackageScript() {
    fs.readFile('../../package.json', 'utf8', (error, data) => {
        console.log('- add "deploy" script to package.json');
        if (error) {
            console.error(error);
        } else {
            let packageObj = JSON.parse(data);
            packageObj.scripts['deploy'] = deployScript;
            fs.writeFile('../../package.json', JSON.stringify(packageObj, null, 2), 'utf8', error => {
                if (error) {
                    return console.error(error);
                };
            });
        }
    });
}

if(__dirname.includes("node_modules")) {
    console.log('Initialize ais-sp-js-deployment package: ');
    fs.exists(destPath, exists => {
        if (!exists) fs.mkdirSync(destPath);
    });

    processGulpfile();
    processDeployJs();

    fs.exists(demoSrc, exists => {
        if (!exists) {
            fse.copyRecursive(demoSrc, demoDest, error => {
                console.log('- copy demo configs');
                if (error) console.error(error);
            });
        }
    });

    createPackageScript();
} else {
    cmd.run('typings install');
}<commit_msg>fixed postinstall deploy.js and demo configs<commit_after>const fs = require('fs');
const fse = require('fs.extra');
var cmd = require('node-cmd');

const destPath = '../../deploy';
const gulpSrc = 'gulpfile.merge.js';
const gulpDest = '../../deploy/gulpfile.js';
const deploySrc = './dist/deploy.js';
const deployDest = '../../deploy/deploy.js';
const demoSrc = './demofiles';
const demoDest = '../../config/';
const packageName = 'ais-sp-js-deployment';
const confDestReg = /configDest\s=\s'.*'/;
let confDest = 'configDest = \'../config/\'';
const confPrefixReg = /partialConfigPrefix\s=\s'.*'/;
let confDemoPrefix = 'partialConfigPrefix = \'democonfig_*.json\'';
const deployScript = 'cd deploy && gulp && cd .. && node ./deploy/deploy -f config/config_demo.json';

function processGulpfile() {
    fs.exists(gulpDest, exists => {
        if (exists) {
            let file = fs.readFileSync(gulpDest, 'utf8');
            let fileConfDest = file.match(confDestReg);
            if (fileConfDest) confDest = fileConfDest[0];
            let fileConfDemoPrefix = file.match(confPrefixReg);
            if (fileConfDemoPrefix) confDemoPrefix = fileConfDemoPrefix[0];
        }
        fs.rename(gulpSrc, gulpDest, error => {
            console.log("- copy gulpfile for config merge");
            if (error) {
                console.error(error);
            } else {
                fs.readFile(gulpDest, 'utf8', (error, data) => {
                    console.log('- gulpfile replacements');
                    if (error) {
                        console.error(error);
                    } else {
                        let result = data.replace(confPrefixReg, confDemoPrefix);
                        result = result.replace(confDestReg, confDest);
                        fs.writeFile(gulpDest, result, 'utf8', error => {
                            if (error) {
                                return console.log(error);
                            };
                        });
                    }
                });
            }
        });
    });
}

function processDeployJs() {
    fs.rename(deploySrc, deployDest, error => {
        console.log('- copy deploy.js');
        if (error) {
            console.error(error);
        } else {
            fs.readFile(deployDest, 'utf8', (error, data) => {
                console.log('- fix deploy.js requires');
                if (error) {
                    console.error(error);
                } else {
                    let result = data.replace('./index', packageName);
                    result = result.replace('//# sourceMappingURL=deploy.js.map', '');
                    fs.writeFile(deployDest, result, 'utf8', error => {
                        if (error) {
                            return console.error(error);
                        };
                    });
                }
            });
        }
    });
}

function createPackageScript() {
    fs.readFile('../../package.json', 'utf8', (error, data) => {
        console.log('- add "deploy" script to package.json');
        if (error) {
            console.error(error);
        } else {
            let packageObj = JSON.parse(data);
            packageObj.scripts['deploy'] = deployScript;
            fs.writeFile('../../package.json', JSON.stringify(packageObj, null, 2), 'utf8', error => {
                if (error) {
                    return console.error(error);
                };
            });
        }
    });
}

if(__dirname.includes("node_modules")) {
    console.log('Initialize ais-sp-js-deployment package: ');
    if(!fs.existsSync(destPath)) {
        fs.mkdirSync(destPath);
    }

    processGulpfile();
    processDeployJs();

    if(!fs.existsSync(demoDest)) {
        console.log('- copy demo configs');
        fs.mkdirSync(demoDest);
        fse.copyRecursive(demoSrc, demoDest, error => { 
            if (error) console.error(error);
        });
    }

    createPackageScript();
} else {
    cmd.run('typings install');
}
{'fraction_non_alphanumeric': 0.1483098415866284, 'fraction_numerical': 0.0024946987651241113, 'mean_word_length': 1.6151337247227657, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 25, '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': '176809', 'n_tokens_mistral': 2276, 'n_tokens_neox': 2172, 'n_words': 438}