<commit_before>"use strict";

var
	path = require('path'),
	dir = require('../lib/dir'),
	fs = require('fs'),
	mkdirp = require('mkdirp'),
	_ = require('lodash'),
	marked = require('marked'),
	parse = require('./parser'),
	compile = require('./compile'),
	symbols = require('./symbols'),
	defaults = require('./defaults');

/**
 * Options & Defaults
 */
var ignoredDirs = defaults.ignoredDirs,
	pkg = defaults.pkg,
	target_extension = defaults.target_extension;

module.exports = function (options) {

	if (options.target_extension) {
		target_extension = options.target_extension;
	}

	if (options.template) {
		compile.tpl = fs.readFileSync(options.template).toString();
		compile.tplFileName = options.template;
	}

	if (!options.source) {
		console.error("  Error you must define a source\n");
		return;
	}


	var target, ignore;
	if (!options.target) {
		target = process.cwd() + '/docs';
	} else {
		target = path.resolve(process.cwd(), options.target) || process.cwd() + '/docs';
	}
	ignore = options.ignore || ignoredDirs;

	//Cleanup and turn into an array the ignoredDirs
	ignore = ignore.trim().replace(' ', '').split(',');

	mkdirp.sync(target);

	var source;

	if (options.source instanceof Array) {
		source = options.source;
		//Handle already compiled input
		var files = source.map(function (doc) {
			var targetName = doc.name + '.' + target_extension;
			if (!doc.targetName) doc.targetName = targetName;
			doc.symbols = symbols(doc.dox, doc.targetName);
			return doc;
		});
	} else {
		//Compile files
		//Find, cleanup and validate all potential files
		source = path.resolve(process.cwd(), options.source);
		var files = dir.collectFiles(source, {
			ignore: ignore
		});

		//Parse each file
		files = files.map(function (file) {
			var dox = parse(path.join(source, file), {});
			var targetName = file + '.' + target_extension;
			return {
				name: file.replace(/\\/g, '/'),
				targetName: targetName.replace(/\\/g, '/'),
				dox: dox,
				symbols: symbols(dox, targetName)
			};
		});

	}

	//Compute all symboles
	var allSymbols = files.reduce(function (m, a) {
		m = m.concat(a.symbols || []);
		return m;
	}, []);

	//Get package.json
	try {
		pkg = require(process.cwd() + '/package')
	} catch (err) {}

	var readme = pkg && pkg.readme,
		readMeFile = path.resolve(process.cwd(), options.readme || (pkg && pkg.readmeFileName) || 'README.md')

	if (!readme && fs.existsSync(readMeFile)) {
		readme = fs.readFileSync(readMeFile).toString()
	} else {
		console.warn(new Error('No README.md file found at ' + readMeFile));
	}

	readme = readme || (pkg && pkg.description)

	//Enable line-breaks ala github markdown
	marked.setOptions({
		breaks: true,
		smartLists: true
	})

	//Get readme data
	files.unshift({
		name: "Main",
		targetName: "index.html",<commit_msg>fix(doxx): handle empty README.md, fixes #64<commit_after>"use strict";

var
	path = require('path'),
	dir = require('../lib/dir'),
	fs = require('fs'),
	mkdirp = require('mkdirp'),
	_ = require('lodash'),
	marked = require('marked'),
	parse = require('./parser'),
	compile = require('./compile'),
	symbols = require('./symbols'),
	defaults = require('./defaults');

/**
 * Options & Defaults
 */
var ignoredDirs = defaults.ignoredDirs,
	pkg = defaults.pkg,
	target_extension = defaults.target_extension;

module.exports = function (options) {

	if (options.target_extension) {
		target_extension = options.target_extension;
	}

	if (options.template) {
		compile.tpl = fs.readFileSync(options.template).toString();
		compile.tplFileName = options.template;
	}

	if (!options.source) {
		console.error("  Error you must define a source\n");
		return;
	}


	var target, ignore;
	if (!options.target) {
		target = process.cwd() + '/docs';
	} else {
		target = path.resolve(process.cwd(), options.target) || process.cwd() + '/docs';
	}
	ignore = options.ignore || ignoredDirs;

	//Cleanup and turn into an array the ignoredDirs
	ignore = ignore.trim().replace(' ', '').split(',');

	mkdirp.sync(target);

	var source;

	if (options.source instanceof Array) {
		source = options.source;
		//Handle already compiled input
		var files = source.map(function (doc) {
			var targetName = doc.name + '.' + target_extension;
			if (!doc.targetName) doc.targetName = targetName;
			doc.symbols = symbols(doc.dox, doc.targetName);
			return doc;
		});
	} else {
		//Compile files
		//Find, cleanup and validate all potential files
		source = path.resolve(process.cwd(), options.source);
		var files = dir.collectFiles(source, {
			ignore: ignore
		});

		//Parse each file
		files = files.map(function (file) {
			var dox = parse(path.join(source, file), {});
			var targetName = file + '.' + target_extension;
			return {
				name: file.replace(/\\/g, '/'),
				targetName: targetName.replace(/\\/g, '/'),
				dox: dox,
				symbols: symbols(dox, targetName)
			};
		});

	}

	//Compute all symboles
	var allSymbols = files.reduce(function (m, a) {
		m = m.concat(a.symbols || []);
		return m;
	}, []);

	//Get package.json
	try {
		pkg = require(process.cwd() + '/package')
	} catch (err) {}

	var readme = pkg && pkg.readme,
		readMeFile = path.resolve(process.cwd(), options.readme || (pkg && pkg.readmeFileName) || 'README.md')

	if (!readme && fs.existsSync(readMeFile)) {
		readme = fs.readFileSync(readMeFile).toString()
	} else {
		console.warn(new Error('No README.md file found at ' + readMeFile));
	}

	readme = readme || (pkg && pkg.description)

	if (!readme) {
		console.warn(new Error('Empty README.md ' + readMeFile));
		readme = '';
	}

	//Enable line-breaks ala github markdown
	marked.setOptions({
		breaks: true,
		smartLists: true
	})

	//Get readme data
	files.unshift({
		name: "Main",
		targetName: "index.html",
{'fraction_non_alphanumeric': 0.17045454545454544, 'fraction_numerical': 0.00034965034965034965, 'mean_word_length': 3.6248989490703316, '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': '2697742', 'n_tokens_mistral': 2106, 'n_tokens_neox': 1924, 'n_words': 449}