<commit_before>/**
 * This file is part of the gina package.
 * Copyright (c) 2014 Rhinostone <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

//Imports
var fs      = require('fs');
var os      = require('os');
var utils   = require('./../core/utils');
var console = utils.logger;



/**
 * Post install constructor
 * @constructor
 * */
function PostInstall() {

    var self = this;

    //Initialize post installation scripts.
    var init = function() {
        self.isWin32 = ( os.platform() == 'win32' ) ? true : false;
        self.path = _( __dirname.substring(0, (__dirname.length - "script".length)-1 ) );
        self.root = process.cwd().toString();

        createVersionFile(function onFileCreated(err) {
            if (err) {
                console.error(err.stack)
            }
            createGinaFileForPlatform()
        })
    }

    var createVersionFile = function(callback) {
        var version = require( _(self.path + '/package.json') ).version;
        var target = _(self.path + '/VERSION');
        try {
            if ( fs.existsSync(target) ) {
                fs.unlinkSync(target)
            }
            fs.writeFileSync(target, version);
            callback(false)
        } catch(err) {
            callback(err)
        }
    }

    //Creating framework command line file for nix.
    var createGinaFile = function(win32Name, callback) {
        var name = require( _(self.path + '/package.json') ).name;
        var appPath = _( self.path.substring(0, (self.path.length - ("node_modules/" + name + '/').length)) );
        var source = _(self.path + '/core/template/command/gina.tpl');
        var target = _(appPath +'/'+ name);
        if ( typeof(win32Name) != 'undefined') {
            target = _(appPath +'/'+ win32Name)
        }
        //Will override.
        if ( typeof(callback) != 'undefined') {
            utils.generator.createFileFromTemplate(source, target, function onGinaFileCreated(err) {
                callback(err)
            })
        } else {
            utils.generator.createFileFromTemplate(source, target)
        }
    }

    var createGinaFileForPlatform = function() {
        console.info('creating platform file');
        var name = require( _(self.path + '/package.json') ).name;

        var filename = ( (self.isWin32) ? '.' : '' ) + name;

        createGinaFile(filename, function onFileCreated(err) {
            if (err) console.error(err.stack);

            // this is done to allow multiple calls of post_install.js
            var filename = _(self.path + '/SUCCESS');
            var installed = fs.existsSync( filename );
            if (installed && /node_modules\/gina/.test( new _(process.cwd()).toUnixStyle() ) ) {
                var msg = "Gina's command line tool has been installed.";
                console.info(msg);
                process.exit(0)
            } else  {

                if (self.isWin32) {
                    var appPath = _( self.path.substring(0, (self.path.length - ("node_modules/" + name + '/').length)) );
                    var source = _(self.path + '/core/template/command/gina.bat.tpl');
                    var target = _(appPath +'/'+ name + '.bat');
                    if ( fs.existsSync(target) ) {
                        fs.unlinkSync(target)
                    }
                    utils.generator.createFileFromTemplate(source, target)
                }

                fs.writeFileSync(filename, true );
            }
            // do something that can be called after the first time installation

            // Check if npm install has been done
            if ( !hasNodeModulesSync() ) {
                npmInstall()
            } else {
                var target = new _(self.path + '/node_modules');
                console.debug('replacing: ', target.toString() );
                target
                    .rm( function(err) {
                        if (err) {
                            console.error(err.stack);
                            process.exit(1)
                        } else {
                            npmInstall()
                        }
                    })
            }

        })
    }

    var hasNodeModulesSync = function() {
        return fs.existsSync( _(self.path + '/node_modules') )
    }



    var npmInstall = function() {<commit_msg>fixed windows post_install<commit_after>/**
 * This file is part of the gina package.
 * Copyright (c) 2014 Rhinostone <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

//Imports
var fs      = require('fs');
var os      = require('os');
var utils   = require('./../core/utils');
var console = utils.logger;



/**
 * Post install constructor
 * @constructor
 * */
function PostInstall() {

    var self = this;

    //Initialize post installation scripts.
    var init = function() {
        self.isWin32 = ( os.platform() == 'win32' ) ? true : false;
        self.path = _( __dirname.substring(0, (__dirname.length - "script".length)-1 ) );
        self.root = process.cwd().toString();

        createVersionFile(function onFileCreated(err) {
            if (err) {
                console.error(err.stack)
            }
            createGinaFileForPlatform()
        })
    }

    var createVersionFile = function(callback) {
        var version = require( _(self.path + '/package.json') ).version;
        var target = _(self.path + '/VERSION');
        try {
            if ( fs.existsSync(target) ) {
                fs.unlinkSync(target)
            }
            fs.writeFileSync(target, version);
            callback(false)
        } catch(err) {
            callback(err)
        }
    }

    //Creating framework command line file for nix.
    var createGinaFile = function(win32Name, callback) {
        var name = require( _(self.path + '/package.json') ).name;
        var appPath = _( self.path.substring(0, (self.path.length - ("node_modules/" + name + '/').length)) );
        var source = _(self.path + '/core/template/command/gina.tpl');
        var target = _(appPath +'/'+ name);
        if ( typeof(win32Name) != 'undefined') {
            target = _(appPath +'/'+ win32Name)
        }
        //Will override.
        if ( typeof(callback) != 'undefined') {
            utils.generator.createFileFromTemplate(source, target, function onGinaFileCreated(err) {
                callback(err)
            })
        } else {
            utils.generator.createFileFromTemplate(source, target)
        }
    }

    var createGinaFileForPlatform = function() {
        console.info('creating platform file');
        var name = require( _(self.path + '/package.json') ).name;

        var filename = ( (self.isWin32) ? '.' : '' ) + name;

        createGinaFile(filename, function onFileCreated(err) {
            if (err) console.error(err.stack);

            // this is done to allow multiple calls of post_install.js
            var filename = _(self.path + '/SUCCESS');
            var installed = fs.existsSync( filename );
            if (installed && /node_modules\/gina/.test( new _(process.cwd()).toUnixStyle() ) ) {
                var msg = "Gina's command line tool has been installed.";
                console.info(msg);
                process.exit(0)
            } else  {
                fs.writeFileSync(filename, true );
            }
            // do something that can be called after the first time installation
            if (self.isWin32) {
                var appPath = _( self.path.substring(0, (self.path.length - ("node_modules/" + name + '/').length)) );
                var source = _(self.path + '/core/template/command/gina.bat.tpl');
                var target = _(appPath +'/'+ name + '.bat');
                if ( fs.existsSync(target) ) {
                    fs.unlinkSync(target)
                } else {
                    utils.generator.createFileFromTemplate(source, target)
                }
            }

            // Check if npm install has been done
            if ( !hasNodeModulesSync() ) {
                npmInstall()
            } else {
                var target = new _(self.path + '/node_modules');
                console.debug('replacing: ', target.toString() );
                target
                    .rm( function(err) {
                        if (err) {
                            console.error(err.stack);
                            process.exit(1)
                        } else {
                            npmInstall()
                        }
                    })
            }

        })
    }

    var hasNodeModulesSync = function() {
        return fs.existsSync( _(self.path + '/node_modules') )
    }



    var npmInstall = function() {
{'fraction_non_alphanumeric': 0.12640829202343398, 'fraction_numerical': 0.005407841369986481, 'mean_word_length': 1.6093474426807761, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '1965595', 'n_tokens_mistral': 2429, 'n_tokens_neox': 2313, 'n_words': 565}