<commit_before>#
# PRE-RELEASE - ALPHA - CLI
# =========================
# 
# ipso -h
# 
# * Expect no consistency between versions (worst case)
# * Care **has already been taken** to minimize changes
# 


{deferred}     = require 'also'
{watcher}      = require './watcher'
{environment}  = require './environment'
{inspector}    = require './inspector'
{readFileSync, readdirSync, lstatSync} = require 'fs'
{normalize}    = require 'path'
{spawn}        = require 'child_process'
{sep}          = require 'path'
{compile}      = require 'coffee-script'
colors         = require 'colors'
program        = require 'commander'
keypress       = require 'keypress'
keypress process.stdin

program.version JSON.parse( 
    readFileSync __dirname + '/../package.json'
    'utf8'
).version

program.option '-w, --no-watch',         'Dont watch spec and src dirs.'
program.option '-n, --no-env',           'Dont load .env.test'
program.option '-m, --mocha',            'Use mocha.'
program.option '-e, --alt-env [name]',   'Loads .env.name'
program.option '    --spec    [dir]',    'Specify alternate spec dir.',       'spec'
program.option '    --src     [dir]',    'Specify alternate src dir.',        'src'
program.option '    --lib     [dir]',    'Specify alternate compile target.', 'lib'


{env, altEnv, mocha, watch, spec, src, lib, env} = program.parse process.argv


kids = []

test = deferred ({resolve}, file) -> 

    unless mocha 
        console.log '\nipso: ' + "Unspecified spec scaffold.".red, "ipso --mocha"
        refresh()
        return

        #
        # mocha is not the default
        # there is no default yet
        #
    
    ipsoPath = normalize __dirname + '/ipso'
    bin      = normalize __dirname + '/../node_modules/.bin/mocha'
    args     = [ 
        '--colors'
        '--compilers', 'coffee:coffee-script'
        '--require',   'should'
        file 
    ]
    console.log '\nipso: ' + "./node_modules/.bin/mocha #{args.join ' '}".grey
    running = spawn bin, args, stdio: 'inherit'
    # running.stdout.on 'data', (chunk) -> refresh chunk.toString()
    # running.stderr.on 'data', (chunk) -> refresh chunk.toString(), 'stderr'
    running.on 'exit', resolve

compile = deferred ({resolve}) ->

    #
    # TODO: optional compile per file, (and not spawned)
    #

    bin    = normalize __dirname + '/../node_modules/.bin/coffee'
    args   = [ '-c', '-b', '-o', lib, src ]
    console.log '\nipso: ' + "./node_modules/.bin/coffee #{args.join ' '}".grey
    running = spawn bin, args, stdio: 'inherit'
    # running.stdout.on 'data', (chunk) -> refresh chunk.toString()
    # running.stderr.on 'data', (chunk) -> refresh chunk.toString(), 'stderr'
    running.on 'exit', resolve


if env or typeof altEnv is 'string' then environment altEnv

if watch

    watcher 
        path: program.spec || 'spec'
        handler: 
            change: (file, stats) -> 
                test( file ).then -> refresh()
    
    watcher 
        path: program.src || 'src'<commit_msg>posibilities<commit_after>#
# PRE-RELEASE - ALPHA - CLI
# =========================
# 
# ipso -h
# 
# * Expect no consistency between versions (worst case)
# * Care **has already been taken** to minimize changes
# 


{deferred}     = require 'also'
{watcher}      = require './watcher'
{environment}  = require './environment'
{inspector}    = require './inspector'
{readFileSync, readdirSync, lstatSync} = require 'fs'
{normalize}    = require 'path'
{spawn}        = require 'child_process'
{sep}          = require 'path'
{compile}      = require 'coffee-script'
colors         = require 'colors'
program        = require 'commander'
keypress       = require 'keypress'
keypress process.stdin

program.version JSON.parse( 
    readFileSync __dirname + '/../package.json'
    'utf8'
).version

program.option '-w, --no-watch',         'Dont watch spec and src dirs.'
program.option '-n, --no-env',           'Dont load .env.test'
program.option '-m, --mocha',            'Use mocha.'
program.option '-e, --alt-env [name]',   'Loads .env.name'
program.option '    --spec    [dir]',    'Specify alternate spec dir.',       'spec'
program.option '    --src     [dir]',    'Specify alternate src dir.',        'src'
program.option '    --lib     [dir]',    'Specify alternate compile target.', 'lib'


{env, altEnv, mocha, watch, spec, src, lib, env} = program.parse process.argv


kids = []

test = deferred ({resolve}, file) -> 

    unless mocha 
        console.log '\nipso: ' + "Unspecified spec scaffold.".red, "ipso --mocha"
        refresh()
        return

        #
        # mocha is not the default
        # there is no default yet
        #
    
    ipsoPath = normalize __dirname + '/ipso'
    bin      = normalize __dirname + '/../node_modules/.bin/mocha'
    args     = [ 
        '--colors'
        '--compilers', 'coffee:coffee-script'
        '--require',   'should'
        file 
    ]

    #
    # TODO: consider posibilities behind source diffs to facto
    #       * related notes below
    #

    console.log '\nipso: ' + "./node_modules/.bin/mocha #{args.join ' '}".grey
    running = spawn bin, args, stdio: 'inherit'
    # running.stdout.on 'data', (chunk) -> refresh chunk.toString()
    # running.stderr.on 'data', (chunk) -> refresh chunk.toString(), 'stderr'

    running.on 'exit', resolve

compile = deferred ({resolve}) ->

    #
    # TODO: optional compile per file, (and not spawned)
    #

    bin    = normalize __dirname + '/../node_modules/.bin/coffee'
    args   = [ '-c', '-b', '-o', lib, src ]

    #
    # TODO: consider posibilities behind source diffs to facto
    #       * team's view of each developer progress / attempt
    #       * others can observe / assist a stuck team member
    #       * detecting stuck
    #

    console.log '\nipso: ' + "./node_modules/.bin/coffee #{args.join ' '}".grey
    running = spawn bin, args, stdio: 'inherit'
    # running.stdout.on 'data', (chunk) -> refresh chunk.toString()
    # running.stderr.on 'data', (chunk) -> refresh chunk.toString(), 'stderr'
    running.on 'exit', resolve


if env or typeof altEnv is 'string' then environment altEnv

if watch

    watcher 
        path: program.spec || 'spec'
        handler: 
            change: (file, stats) -> 
                test( file ).then -> refresh()
    
    watcher 
        path: program.src || 'src'
{'fraction_non_alphanumeric': 0.15736519415186292, 'fraction_numerical': 0.00031441597233139445, 'mean_word_length': 2.3066528066528065, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, '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': '2045381', 'n_tokens_mistral': 2048, 'n_tokens_neox': 1940, 'n_words': 571}