'use strict';

(function () {

    var chalk = require('chalk');
    var fs = require('fs');
    var path = require('../../utils/path.js');

    var addHooks = function addHooks(dirname) {

        console.log(chalk.green('Add "pre-commit hooks" to you git.'));

        var hook = path.join(dirname, '.git/hooks/pre-commit');

        fs.writeFileSync(hook, fs.readFileSync(path.join(__dirname, 'hooks/pre-commit')));
        fs.chmodSync(hook, '751');
        console.log(chalk.green('Hooks successfully added.'));
        return;
    };

    var addGitignore = function addGitignore(dirname) {
        console.log(chalk.green('Add ".gitignore" to you git.'));

        var tmpl = fs.readFileSync(path.join(__dirname, 'root/' + 'gitignore'), {
            encoding: 'utf8'
        });

        var gitignore = path.join(dirname, '.gitignore');

        fs.writeFileSync(gitignore, tmpl);

        console.log(chalk.green('.gitignore successfully added.'));
        return;
    };

    module.exports = function (options) {
        addHooks(process.cwd());
        addGitignore(process.cwd());
    };
})();