<commit_before>import path          from 'path'

import gulp          from 'gulp'
import nodemon       from 'gulp-nodemon'
import gutil         from 'gulp-util'
import {exec, spawn} from 'child_process'

import colors        from 'colors'

import appConfig     from '../../config/appConfig'

const {
    isDevelopment,
    paths
} = appConfig

const closeFn = done => data => {
    gutil.log('production server stopped!')
    console.log('closed!')
    done(data)
}

gulp.task('productionServer', done => {
    // leftover: refactor: remove it?
    if (isDevelopment) {
        const {yellow} = colors
        gutil.log(yellow(
            '[Warning] '.bold
        +   "skipped task 'productionServer' because NODE_ENV !== 'production'"
        ))
        done()
        return
    }

    const runner = spawn('node', [paths.ROOT + '/server/index.js'], {cwd: process.cwd()})

    runner.stdout.setEncoding('utf8')

    runner.stdout.on('data', data => gutil.log(data))

    // broken: refactor: doesn't work.
    process.on('finish', () => runner.exit())
    // refactor: only fires on error
    // doesn't fire on strg+c
    runner.on('close', closeFn(done))
    runner.on('exit', closeFn(done))
})


// gulp.task('productionServer', done => {
//     // 'node ' + paths.ROOT + '/server/index.js'
//     exec('ping localhost', (err, stdout, stderr) => {
//         if (err || stderr) {
//             stderr  && console.log('[Error] ', stderr)
//             err     && console.log('[Error] ', err)<commit_msg>kill server process on gulp exit<commit_after>import path          from 'path'

import gulp          from 'gulp'
import nodemon       from 'gulp-nodemon'
import gutil         from 'gulp-util'
import {exec, spawn} from 'child_process'

import colors        from 'colors'

import appConfig     from '../../config/appConfig'

const {
    isDevelopment,
    paths
} = appConfig

const closeFn = done => data => {
    gutil.log('production server stopped!')
    console.log('closed!')
    done(data)
}

gulp.task('productionServer', done => {
    // leftover: refactor: remove it?
    if (isDevelopment) {
        const {yellow} = colors
        gutil.log(yellow(
            '[Warning] '.bold
        +   "skipped task 'productionServer' because NODE_ENV !== 'production'"
        ))
        done()
        return
    }

    const runner = spawn('node', [paths.ROOT + '/server/index.js'], {cwd: process.cwd()})

    runner.stdout.setEncoding('utf8')

    runner.stdout.on('data', data => gutil.log(data))

    // kill server process on gulp exit
    process.on('exit', () => runner.kill())
    // refactor: only fires on error
    // doesn't fire on strg+c
    runner.on('close', closeFn(done))
    runner.on('exit', closeFn(done))
})


// gulp.task('productionServer', done => {
//     // 'node ' + paths.ROOT + '/server/index.js'
//     exec('ping localhost', (err, stdout, stderr) => {
//         if (err || stderr) {
//             stderr  && console.log('[Error] ', stderr)
//             err     && console.log('[Error] ', err)
{'fraction_non_alphanumeric': 0.1618421052631579, 'fraction_numerical': 0.0006578947368421052, 'mean_word_length': 2.382647385984427, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3688197', 'n_tokens_mistral': 976, 'n_tokens_neox': 941, 'n_words': 232}