<commit_before>'use strict';

const os = require('os');
const path = require('path');

const readjson = require('readjson');
const writejson = require('writejson');
const tryCatch = require('try-catch');
const squad = require('squad');
const currify = require('currify');
const apart = require('apart');
const find = require('../find');

const ifFound = currify((name, array) => {
    if (find(name, array))
        throw Error(`name "${name}" already exist`);
     
    return array;
});

const add = currify((name, command, directory, array) => {
    return array.concat({
        name,
        command,
        directories: [
            directory
        ]
    });
});

module.exports = (argv) => {
    const name = argv._[1];
    const command = argv.command;
    const longrunPath = path.join(os.homedir(), '.longrun.json');
    
    const create = squad.apply(null, [
        apart(writejson.sync, longrunPath),
        add(name, command, process.cwd()),
        ifFound(name),
        readjson.sync
    ]);
    
    const error = tryCatch(() => {
        checkName(name);
        checkCommand(argv.command);
        
        create(longrunPath);
    });
    
    exitIfError(error);
};

function checkCommand(command) {
    if (!command)
        throw Error('command could not be empty');
}

function checkName(name) {
    if (!name)
        throw Error('name could not be empty');
}

function exitIfError(error) {
    error && exit(error.message);
}

function exit(message) {
    console.error(message);
    process.exit(-1);
}

<commit_msg>feature(init) add tildify<commit_after>'use strict';

const os = require('os');
const path = require('path');

const readjson = require('readjson');
const writejson = require('writejson');
const tryCatch = require('try-catch');
const squad = require('squad');
const currify = require('currify');
const apart = require('apart');
const tildify = require('tildify');

const find = require('../find');
const cwd = squad(tildify, process.cwd);

const ifFound = currify((name, array) => {
    if (find(name, array))
        throw Error(`name "${name}" already exist`);
     
    return array;
});

const add = currify((name, command, directory, array) => {
    return array.concat({
        name,
        command,
        directories: [
            directory
        ]
    });
});

module.exports = (argv) => {
    const name = argv._[1];
    const command = argv.command;
    const longrunPath = path.join(os.homedir(), '.longrun.json');
    
    const create = squad.apply(null, [
        apart(writejson.sync, longrunPath),
        add(name, command, cwd()),
        ifFound(name),
        readjson.sync
    ]);
    
    const error = tryCatch(() => {
        checkName(name);
        checkCommand(argv.command);
        
        create(longrunPath);
    });
    
    exitIfError(error);
};

function checkCommand(command) {
    if (!command)
        throw Error('command could not be empty');
}

function checkName(name) {
    if (!name)
        throw Error('name could not be empty');
}

function exitIfError(error) {
    error && exit(error.message);
}

function exit(message) {
    console.error(message);
    process.exit(-1);
}


{'fraction_non_alphanumeric': 0.15493400377121308, 'fraction_numerical': 0.001257071024512885, 'mean_word_length': 2.8395657418576596, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '6675812', 'n_tokens_mistral': 961, 'n_tokens_neox': 969, 'n_words': 233}