<commit_before>fs = require 'fs'
ncp = require 'ncp'
jf = require 'jsonfile'
exec = require('child_process').exec
colors = require 'colors'

Q = require 'q'



module.exports = (name, force) ->
	defer = Q.defer()

	path = process.cwd() + '/plugins/' + name
	exists = fs.existsSync process.cwd() + '/plugins/' + name

	if not exists or force
		ncp __dirname + '/../../templates/plugin', path, (err) ->
			if err
				return defer.reject err
			else
				jf.readFile path + '/plugin.json', (err, obj) ->
					return defer.reject(err) if err
					if not obj?
						obj = {}
					obj.name = name
					jf.writeFile path + 'plugin.json', obj, (err) ->
						return defer.reject err if err
						exec 'cd ' + path + '&& git init', (error, stdout, stderr) ->
							if not error
								console.log 'The plugin ' + name.green + ' was successfully created in ./plugins/' + name
							else
								console.log 'An error occured while initializing the plugin git repo'.red
	else
		console.log 'The plugin ' + name.yellow + ' already exists. To override, use ' + '--force'.green



	defer.promise<commit_msg>Fixed typo in plugin creation<commit_after>fs = require 'fs'
ncp = require 'ncp'
jf = require 'jsonfile'
exec = require('child_process').exec
colors = require 'colors'

Q = require 'q'



module.exports = (name, force) ->
	defer = Q.defer()

	path = process.cwd() + '/plugins/' + name
	exists = fs.existsSync process.cwd() + '/plugins/' + name

	if not exists or force
		ncp __dirname + '/../../templates/plugin', path, (err) ->
			if err
				return defer.reject err
			else
				jf.readFile path + '/plugin.json', (err, obj) ->
					return defer.reject(err) if err
					if not obj?
						obj = {}
					obj.name = name
					console.log obj
					jf.writeFile path + '/plugin.json', obj, (err) ->
						return defer.reject err if err
						exec 'cd ' + path + '&& git init', (error, stdout, stderr) ->
							if not error
								console.log 'The plugin ' + name.green + ' was successfully created in ./plugins/' + name
							else
								console.log 'An error occured while initializing the plugin git repo'.red
	else
		console.log 'The plugin ' + name.yellow + ' already exists. To override, use ' + '--force'.green



	defer.promise
{'fraction_non_alphanumeric': 0.1400359066427289, 'fraction_numerical': 0.0, 'mean_word_length': 2.6067961165048543, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, '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': '5686586', 'n_tokens_mistral': 860, 'n_tokens_neox': 695, 'n_words': 237}