<commit_before><?php

namespace Bob;

// Your package's name. Used to identify it on Packagist.org
function getName()
{
    return 'chh/bob';
}

// Should return the package's version.
//
// An idea would be to fetch the latest tag from the repo 
// in your favourite VCS.
function getVersion()
{
    return "master-dev";
}

// Should return an array of authors.
// Each individual author should be an array of `name`, 
// `email` and optionally a `homepage`
//
// By default this parses an `AUTHORS.txt` file in the root
// of the project which is formatted with an author name on
// each line. For example:
//
//     <NAME> <<EMAIL>>
//     <NAME> <<EMAIL>>
//
function getAuthors()
{
    $authorsFile = 'AUTHORS.txt';

    if (!file_exists($authorsFile)) {
        return array();
    }

    $authors = array();

    foreach (new \SplFileObject($authorsFile) as $line) {
        if (preg_match('/^(.+) <(.+)>$/', $line, $matches)) {
            $authors[] = array(
                'name' => $matches[1],
                'email' => $matches[2]
            );
        }
    }

    return $authors;
}

function getExecutables()
{
    $binDir = 'bin';

    if (!is_dir($binDir)) {
        return array();
    }

    $executables = array();

    foreach (new \DirectoryIterator($binDir) as $file) {
        if ($file->isFile() and $file->isExecutable()) {
            $logicalPath = substr($file->getRealpath(), strlen($_SERVER['PWD']) + 1);
            $executables[] = $logicalPath;
        }
    }

    return $executables;
}

desc('Generates the composer.json from the composer_spec.php');
fileTask('composer.json', array('composer_spec.php'), function($task) {
    $NAME = getName();
    $AUTHORS = getAuthors();
    $EXECUTABLES = getExecutables();
    $VERSION = getVersion();

    $pkg = include($task->prerequisites[0]);

    if (!is_array($pkg)) {
        printLn('ERROR: composer_spec.php MUST return an array');
        exit(1);
    }

    $json = json_encode($pkg, JSON_PRETTY_PRINT);

    printLn('Writing composer.json');
    @file_put_contents($task->name, $json);
});
<commit_msg>Fetching version from git tags for composer.json<commit_after><?php

namespace Bob;

// Your package's name. Used to identify it on Packagist.org
function getName()
{
    return 'chh/bob';
}

// Should return the package's version.
//
// An idea would be to fetch the latest tag from the repo 
// in your favourite VCS.
function getVersion()
{
    $tags = `git tag`;

    if (!$tags) {
        return "master-dev";
    }

    $tags = explode("\n", $tags);
    rsort($tags);
    return $tags[0];
}

// Should return an array of authors.
// Each individual author should be an array of `name`, 
// `email` and optionally a `homepage`
//
// By default this parses an `AUTHORS.txt` file in the root
// of the project which is formatted with an author name on
// each line. For example:
//
//     <NAME> <<EMAIL>>
//     <NAME> <<EMAIL>>
//
function getAuthors()
{
    $authorsFile = 'AUTHORS.txt';

    if (!file_exists($authorsFile)) {
        return array();
    }

    $authors = array();

    foreach (new \SplFileObject($authorsFile) as $line) {
        if (preg_match('/^(.+) <(.+)>$/', $line, $matches)) {
            $authors[] = array(
                'name' => $matches[1],
                'email' => $matches[2]
            );
        }
    }

    return $authors;
}

function getExecutables()
{
    $binDir = 'bin';

    if (!is_dir($binDir)) {
        return array();
    }

    $executables = array();

    foreach (new \DirectoryIterator($binDir) as $file) {
        if ($file->isFile() and $file->isExecutable()) {
            $logicalPath = substr($file->getRealpath(), strlen($_SERVER['PWD']) + 1);
            $executables[] = $logicalPath;
        }
    }

    return $executables;
}

desc('Generates the composer.json from the composer_spec.php');
task('composer.json', array('composer_spec.php'), function($task) {
    $NAME = getName();
    $AUTHORS = getAuthors();
    $EXECUTABLES = getExecutables();
    $VERSION = getVersion();

    $pkg = include($task->prerequisites[0]);

    if (!is_array($pkg)) {
        printLn('ERROR: composer_spec.php MUST return an array');
        exit(1);
    }

    $json = json_encode($pkg, JSON_PRETTY_PRINT);

    printLn('Writing composer.json');
    @file_put_contents($task->name, $json);
});

{'fraction_non_alphanumeric': 0.16333103289625028, 'fraction_numerical': 0.0025304807913503567, 'mean_word_length': 2.629382303839733, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 31, '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': '4374338', 'n_tokens_mistral': 1434, 'n_tokens_neox': 1373, 'n_words': 375}