<commit_before>var fs = require('fs'),
_ = require('underscore');
exports.powPath = process.env.HOME + '/.pow'
exports.nodepunchPath = process.env.HOME + '/.nodepunch'
var self = this;


// Public: Creates a symlink in the nodepunchPath to a project
//
// path  - String of the Absolute Path to the projects root.
// projectName - (Optional) String of an alternative name for the project.
//
// Examples
//
//   nodepunch.link('/home/bencevans/Development/HNCache-Server')
//   # => true
//
//   nodepunch.link('/home/bencevans/Development/HNCache-Server', 'HNCache')
//   # => true
//
// Returns True if all a success else an Error is thrown.

exports.link = function (path, projectName) {

	// If no projectName is given, extract it as the child directory
	if(typeof projectName == 'undefined') {
		var splitPath = path.split('/');
		var projectName = splitPath[splitPath.length - 1];
	}

	return fs.symlinkSync(path, self.nodepunchPath + '/' + projectName);
}

// Public: Removes a symlink in the nodepunchPath to a project
//
// projectNameOrPath - String of the Path to a project or the projects name.
//
// Examples
//
//   nodepunch.unlink('/home/bencevans/Development/HNCache-Server')
//   # => true
//
//   nodepunch.unlink('/home/bencevans/Development/HNCache-Server', 'HNCache')
//   # => true
//
// Returns True if all a success else an Error is thrown.

exports.unlink = function (projectNameOrPath) {

	//TODO: Check and turn off if running before unlink

	// Check if using Name.
	if (fs.existsSync(self.nodepunchPath + '/' + projectNameOrPath)) {

		return fs.unlinkSync(self.nodepunchPath + '/' + projectNameOrPath);

		// Else Try as Path
	} else if (fs.existsSync(projectNameOrPath)) {

		var project = _.find(self.list(), function (project) {
			return (project.path == projectNameOrPath) ? true : false;
		})

		if (project) {
			return fs.unlinkSync(self.nodepunchPath + '/' + project.name);
		} else {
			throw "No Project Found"
		}

	} else {

		throw "No Project Found."
	}

}

// Public: Generates Object containing all projects info
//
// Examples
//
//   nodepunch.list() ... With Projects
//   # => [ { name: 'HNCache-Server',
//            path: '/Users/bencevans/Development/HNCache/HNCache-Server' },
//          { name: 'TheMinecraftFilesJS',
//            path: '/Users/bencevans/Development/TheMinecraftFilesJS' } ]
//
//   nodepunch.list() ... With No Projects
//   # => []
//
// Returns object of all project's info.

exports.list = function () {

	var projects = [];

	_.each(fs.readdirSync(self.nodepunchPath), function (name) {
		projects.push(self.projectInfo(name));
	});

	return projects;
}

// Public: Generates Object containing all a single project's info
//
// projectName - String of a projects name.
//
// Examples
//
//   nodepunch.projectInfo(HNCache-Server) ... With Projects
//   # => { name: 'HNCache-Server',
//          path: '/Users/bencevans/Development/HNCache/HNCache-Server' }
//
//
// Returns object of a project's info if sucessful else throws error. 

exports.projectInfo = function (projectName) {

	if(fs.existsSync(self.nodepunchPath + '/' + projectName)) {
		return {name:projectName, path:fs.readlinkSync(self.nodepunchPath + '/' + projectName)};
	} else {
		throw "No Project Found"
	}

}

exports.start = function () {

}
<commit_msg>Added findProjectName & exists functions to lib<commit_after>var fs = require('fs'),
_ = require('underscore');
exports.powPath = process.env.HOME + '/.pow'
exports.nodepunchPath = process.env.HOME + '/.nodepunch'
var self = this;


// Public: Creates a symlink in the nodepunchPath to a project
//
// path  - String of the Absolute Path to the projects root.
// projectName - (Optional) String of an alternative name for the project.
//
// Examples
//
//   nodepunch.link('/home/bencevans/Development/HNCache-Server')
//   # => true
//
//   nodepunch.link('/home/bencevans/Development/HNCache-Server', 'HNCache')
//   # => true
//
// Returns True if all a success else an Error is thrown.

exports.link = function (path, projectName) {

	// If no projectName is given, extract it as the child directory
	if(typeof projectName == 'undefined') {
		var splitPath = path.split('/');
		var projectName = splitPath[splitPath.length - 1];
	}

	return fs.symlinkSync(path, self.nodepunchPath + '/' + projectName);
}

// Public: Removes a symlink in the nodepunchPath to a project
//
// projectNameOrPath - String of the Path to a project or the projects name.
//
// Examples
//
//   nodepunch.unlink('/home/bencevans/Development/HNCache-Server')
//   # => true
//
//   nodepunch.unlink('/home/bencevans/Development/HNCache-Server', 'HNCache')
//   # => true
//
// Returns True if all a success else an Error is thrown.

exports.unlink = function (projectNameOrPath) {

	// Find project's name
	var projectName = self.findProjectName(projectNameOrPath);

	// Check there's been a project's name returned
	if(typeof projectName !== 'string') {
		throw Error("No Project Found")
	}

	//TODO: Check and turn off if running before unlink

	// Go forth and unlink
	return fs.unlinkSync(self.nodepunchPath + '/' + projectName);


}

// Public: Generates Object containing all projects info
//
// Examples
//
//   nodepunch.list() ... With Projects
//   # => [ { name: 'HNCache-Server',
//            path: '/Users/bencevans/Development/HNCache/HNCache-Server' },
//          { name: 'TheMinecraftFilesJS',
//            path: '/Users/bencevans/Development/TheMinecraftFilesJS' } ]
//
//   nodepunch.list() ... With No Projects
//   # => []
//
// Returns object of all project's info.

exports.list = function () {

	var projects = [];

	_.each(fs.readdirSync(self.nodepunchPath), function (name) {
		projects.push(self.projectInfo(name));
	});

	return projects;
}

// Public: Generates Object containing all a single project's info
//
// projectName - String of a projects name.
//
// Examples
//
//   nodepunch.projectInfo(HNCache-Server) ... With Projects
//   # => { name: 'HNCache-Server',
//          path: '/Users/bencevans/Development/HNCache/HNCache-Server' }
//
//
// Returns object of a project's info if sucessful else throws error. 

exports.projectInfo = function (projectName) {

	if(fs.existsSync(self.nodepunchPath + '/' + projectName)) {
		return {name:projectName, path:fs.readlinkSync(self.nodepunchPath + '/' + projectName)};
	} else {
		throw "No Project Found"
	}

}

// Public: Finds projectName from anything relative. (directory/name)
//
// projectName - String of a projects name.
//
// Examples
//
//   nodepunch.findProjectName('/Users/bencevans/Development/HNCache/HNCache-Server') //When the Project DOES EXIST
//   # => 'HNCache-Server'
//
//   nodepunch.findProjectName('HNCache-Server') //When the Project DOES EXIST
//   # => 'HNCache-Server'
//
//   nodepunch.findProjectName('HNCache-Server') //When the Project DOES NOT EXIST
//   # => false
//
//
// If a project is found Returns string of projectsName
// Else returns False.

exports.findProjectName = function (identifier) {

	var searchResult = _.find(self.list(), function(project) {
		if (identifier == project.name || identifier == project.path)
			return true
		else
			return false
	})

	if(typeof searchResult !== "undefined")
		return searchResult.name
	else
		return false
}

// Public: Finds if a project exists or not.
//
// projectName - String of a projects name.
//
// Examples
//
//   nodepunch.exists('HNCache-Server') //When the Project DOES EXIST
//   # => true
//
//   nodepunch.exists('HNCache-Server') //When the Project DOES NOT EXIST
//   # => false
//
//
// If a project is found Returns true (bool)
// Else returns false (bool).

exports.exists = function (projectName) {
	if(_.find(nodepunch.list(), function(project){
		if(projectName = project.name)
			return true
		else
			return false
	})){
		return true
	} else
	return false
}

exports.start = function () {

}

{'fraction_non_alphanumeric': 0.1494034018786494, 'fraction_numerical': 0.0002538715410002539, 'mean_word_length': 3.0951143451143452, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 22, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 15, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4460117', 'n_tokens_mistral': 2659, 'n_tokens_neox': 2522, 'n_words': 664}