<commit_before>#!/usr/bin/env node

/* jslint node: true */

'use strict';

var program = require( 'commander' );

program
	.option( '-v, --verbose', 'increase verbosity', function( v, total ) { return total + 1; }, 0 )
	.option( '-w, --watch', 'automatically recompile on file change' )
	.option( '-t, --throttle [milliseconds]', 'throttle recompile watcher', 1000 )
	.parse( process.argv )
	;

var basePath = program.args.length ? program.args[ program.args.length - 1 ] : '.';
var Documark = require( '../lib/Documark' );
var doc      = new Documark( basePath );
var chalk    = require( 'chalk' );

doc.setVerbosity( program.verbose );

function compile() {
	console.log( chalk.bold( 'Compiling..' ) );
	try {
		doc.compile();
	}
	catch( e ) {
		console.log( chalk.red( 'Error!' ) );
		console.error( e );
	}
}

compile();

if( program.watch ) {
	var monocle  = require( 'monocle' )();
	var throttle = require( 'throttleit' );

	monocle.watchDirectory( {
		root: doc.getPath(),
		fileFilter: [ '!**/*.pdf' ],
		listener: throttle( compile, program.throttle )
	} );
}
<commit_msg>Improve compile watcher logging.<commit_after>#!/usr/bin/env node

/* jslint node: true */

'use strict';

var program = require( 'commander' );

program
	.option( '-v, --verbose', 'increase verbosity', function( v, total ) { return total + 1; }, 0 )
	.option( '-w, --watch', 'automatically recompile on file change' )
	.option( '-t, --throttle [milliseconds]', 'throttle recompile watcher', 1000 )
	.parse( process.argv )
	;

var basePath = program.args.length ? program.args[ program.args.length - 1 ] : '.';
var Documark = require( '../lib/Documark' );
var document = new Documark( basePath );
var chalk    = require( 'chalk' );

document.verbosity( program.verbose );

var start, stop;

function done() {
	stop = new Date();

	console.log( chalk.cyan( 'Completed in ' + ( ( stop.getTime() - start.getTime() ) / 1000 ).toFixed( 3 ) + 's at ' + stop ) + ( program.watch ? ' - Waiting..' : '' ) );
}
function error( e ) {
	console.log( chalk.red( 'Error!' ) );
	throw e;
}
function compile( changedFile ) {
	start = new Date();

	if( changedFile ) {
		console.log( '\n' + chalk.green( '>>' ) + ' File "' + changedFile.fullPath.substr( document.path().length + 1 ) + '" changed.\n' );
	}

	console.log( chalk.underline( 'Compiling..' ) );

	try {
		document.compile( done );
	}
	catch( e ) {
		error( e );
	}
}

compile();

if( program.watch ) {
	var monocle  = require( 'monocle' )();
	var throttle = require( 'throttleit' );

	monocle.watchDirectory( {
		root: document.path(),
		fileFilter: [ '!**/*.pdf' ],
		listener: throttle( compile, program.throttle )
	} );
}

{'fraction_non_alphanumeric': 0.1916258015843078, 'fraction_numerical': 0.007544322897019992, 'mean_word_length': 3.4496644295302015, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '1966767', 'n_tokens_mistral': 1005, 'n_tokens_neox': 947, 'n_words': 239}