<commit_before><?php
/**
 * This is Phlomis project's console commands configuration for Robo task runner.
 *
 * @see http://robo.li/
 */

class RoboFile extends \Robo\Tasks
{
  protected $vendorDir;
  protected $assetPackages;

  /**
   * Contruct for the class, checks and creates the dist folders
   */
  public function __construct() {
    // check the build folder
    if (! is_dir('dist')) {
      mkdir('dist');
    }
    if (! is_dir('dist/styles')) {
      mkdir('dist/styles');
    }
    if (! is_dir('dist/scripts')) {
      mkdir('dist/scripts');
    }
    if (! is_dir('dist/fonts')) {
      mkdir('dist/fonts');
    }

    // get the vendorDir
    $io = new Composer\IO\NullIO();
    $factory = new Composer\Factory();
    $composer = $factory->createComposer($io);
    $this->vendorDir = rtrim($composer->getConfig()->get('vendor-dir'), '/');

    // go through installed packages (taken from Composer\Command\ShowCommand.php)
    $installedRepo = $composer->getRepositoryManager()->getLocalRepository();
    $this->assetPackages = [];
    foreach ($installedRepo->getPackages() as $package) {
      if ($package->getType() == 'bower-asset-library' ) {
        // store the extra information for assets
        $this->assetPackages[$package->getPrettyName()] = $package;
      }
    }
  }

  private function getAssetPath($packageName) {
    foreach ($this->assetPackages as $k => $package) {
      if ( strpos($k, $packageName) !== FALSE) {
        return $this->vendorDir .'/'. $k . '/';
      }
    }
  }

  private function getAssetMain($packageName) {
    foreach ($this->assetPackages as $k => $package) {
      if ( strpos($k, $packageName) !== FALSE) {
        $extra = $package->getExtra();
        $main = '';
        if (isset($extra['bower-asset-main'])) $main = $extra['bower-asset-main'];
        // check if single value is given, then return a string instead of an array
        if (is_array($main) && count($main) == 1){
          $main = $this->vendorDir.'/bower-asset/'.$packageName.'/'.$main[0];
        }
        return $main;
      }<commit_msg>Add function to create build folders<commit_after><?php
/**
 * This is Phlomis project's console commands configuration for Robo task runner.
 *
 * @see http://robo.li/
 */

class RoboFile extends \Robo\Tasks
{
  private $vendorDir;
  private $assetPackages;

  /**
   * Contruct for the class, checks and creates the dist folders
   */
  public function __construct() {
    // check the build folder
    $buildFolders = array(
      'dist/styles',
      'dist/scripts',
      'dist/fonts'
    );
    $this->createPaths($buildFolders);

    // get the vendorDir
    $io = new Composer\IO\NullIO();
    $factory = new Composer\Factory();
    $composer = $factory->createComposer($io);
    $this->vendorDir = rtrim($composer->getConfig()->get('vendor-dir'), '/');

    // go through installed packages (taken from Composer\Command\ShowCommand.php)
    $installedRepo = $composer->getRepositoryManager()->getLocalRepository();
    $this->assetPackages = [];
    foreach ($installedRepo->getPackages() as $package) {
      if ($package->getType() == 'bower-asset-library' ) {
        // store the extra information for assets
        $this->assetPackages[$package->getPrettyName()] = $package;
      }
    }
  }

  private function createPaths($paths){
    // iterate through paths array and create folder
    foreach ($paths as $path) {
      $pathPart = '';
      foreach(explode('/', $path) as $part) {
        // iterate through path and create parent folders before child folders
        $pathPart .= $part.'/';
        if (! is_dir($pathPart)) {
          $this->taskFileSystemStack()
            ->mkdir($pathPart)
            ->run();
        }
      }
    }
  }

  private function getAssetPath($packageName) {
    foreach ($this->assetPackages as $k => $package) {
      if ( strpos($k, $packageName) !== FALSE) {
        return $this->vendorDir .'/'. $k . '/';
      }
    }
  }

  private function getAssetMain($packageName) {
    foreach ($this->assetPackages as $k => $package) {
      if ( strpos($k, $packageName) !== FALSE) {
        $extra = $package->getExtra();
        $main = '';
        if (isset($extra['bower-asset-main'])) $main = $extra['bower-asset-main'];
        // check if single value is given, then return a string instead of an array
        if (is_array($main) && count($main) == 1){
          $main = $this->vendorDir.'/bower-asset/'.$packageName.'/'.$main[0];
        }
        return $main;
      }
{'fraction_non_alphanumeric': 0.164562569213732, 'fraction_numerical': 0.0008859357696566999, 'mean_word_length': 2.668562144597888, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 43, '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': '446542', 'n_tokens_mistral': 1388, 'n_tokens_neox': 1358, 'n_words': 325}