<commit_before>var Promise = require('bluebird');
var fs = require('fs');
var child_process = require('child_process');

module.exports = function(grunt) {

    // initialize the grunt-nodemon configuration
    grunt.initConfig({
        nodemon: {
            dev: {
                script: 'app.js',
                options: {
                    callback: function(nodemon) {
                        // gets run when server first starts
                        nodemon.on('config:update', function() {
                            PythonControl.start();
                        });

                        // gets run when changes detected
                        nodemon.on('restart', function() {
                            PythonControl.restart();
                        });
                    }
                }
            }
        }
    });
    grunt.loadNpmTasks('grunt-nodemon');

    grunt.registerTask('run', function() {
        // start up the server
        var Server = require('./app');
        grunt.task.run(['keepalive']);
    });

    grunt.registerTask('keepalive', function() {
        // stay alive forever
        setInterval(function(){}, 60*60*1000);
        this.async();
    });
};

var PythonControl = {
    restart: function() {
        // kill the current process
        this.pythonProcess.kill('SIGKILL');

        this.start();
    },

    start: function() {
        var self = this;
        // spawn the python process
        Promise.delay(2500)
        .then(function() {
            // open up a logging file
            var logStream = fs.createWriteStream('./myapp.log');

            self.pythonProcess = child_process.spawn('python2', ['../SampleApp/my_app.py']);
            self.pythonProcess.stdout.pipe(logStream);
            self.pythonProcess.stderr.pipe(logStream);

            self.pythonProcess.on('exit', function(code) {<commit_msg>Gruntfile improvements now is a grunt run which should start up just the server.  `grunt dev` will start a dev mode instance, looking at all folders in the beamware project directory.  Server will restart when any javascript or python file is changed<commit_after>var Promise = require('bluebird');
var fs = require('fs');
var child_process = require('child_process');

module.exports = function(grunt) {

    // initialize the grunt-nodemon configuration
    grunt.initConfig({
        nodemon: {
            dev: {
                script: 'app.js',
                options: {
                    callback: function(nodemon) {
                        // gets run when server first starts
                        nodemon.on('config:update', function() {
                            PythonControl.start();
                        });

                        // gets run when changes detected
                        nodemon.on('restart', function() {
                            PythonControl.restart();
                        });
                    },

                    watch: ['../'],
                    ext: 'js,py'
                }

            }
        }
    });
    grunt.loadNpmTasks('grunt-nodemon');

    grunt.registerTask('run', function() {
        // start up the server
        var Server = require('./app');
        grunt.task.run(['keepalive']);
    });

    grunt.registerTask('keepalive', function() {
        // stay alive forever
        setInterval(function(){}, 60*60*1000);
        this.async();
    });

    grunt.registerTask('dev', function(name) {
        if (name) {
            PythonControl.app = name;
        } else {
            PythonControl.app = "my_app.py";
        }

        grunt.task.run(['nodemon']);
    });
};

var PythonControl = {
    restart: function() {
        // kill the current process
        this.pythonProcess.kill('SIGKILL');

        this.start();
    },

    start: function() {
        if (!this.app) {
            throw new Error('Need to provide application name');
        }

        var self = this;
        // spawn the python process
        Promise.delay(2500)
        .then(function() {
            // open up a logging file
            var logStream = fs.createWriteStream('./myapp.log');

            self.pythonProcess = child_process.spawn('python2', ['../SampleApp/' + self.app]);
            self.pythonProcess.stdout.pipe(logStream);
            self.pythonProcess.stderr.pipe(logStream);

            self.pythonProcess.on('exit', function(code) {
{'fraction_non_alphanumeric': 0.12471757794848622, 'fraction_numerical': 0.00587437867148667, 'mean_word_length': 1.5589595375722543, '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': '4850586', 'n_tokens_mistral': 1163, 'n_tokens_neox': 1098, 'n_words': 254}