<commit_before>#!/usr/bin/env bash

set -e

export SHOP="/data/shop"
export SETUP=spryker
export TERM=xterm 
export VERBOSITY='-v'
export CONSOLE=vendor/bin/console

source /data/bin/functions.sh

cd $SHOP


function generate_configurations {
  labelText "Create runtime configuration ..."

  infoText "Applying confd templates ..."
  if [ -n "$ETCD_NODE" ]; then
      confd -backend etcd -node ${ETCD_NODE} -prefix ${ETCD_PREFIX} -onetime
  else
      confd -backend env -onetime
  fi

  if [ -e $CONSOLE ]; then
    infoText "Propel - Converting configuration ..."
    $CONSOLE propel:config:convert
  fi 
}


function install_dependencies {
    labelText "Resolving dependencies ..."

    if [ -n "$PHP_EXTENSIONS" ]; then
      export DEBIAN_FRONTEND=noninteractive
      exts=$(echo "$PHP_EXTENSIONS" | awk  'BEGIN {RS=" "} { if (length($1) != 0) { printf "php-%s ", $1 }}' )
      infoText "Installing required PHP extensions: $exts"
      apt-get -y update
      apt-get -y --no-install-recommends install $exts
    fi

    if [ "${APPLICATION_ENV}x" != "developmentx" ]; then
      infoText "Installing required NPM dependencies..."
      npm install --only=production
      infoText "Installing required PHP dependencies..."
      php /data/bin/composer.phar install --prefer-dist --no-dev
    else
      infoText "Installing required NPM dependencies (including dev) ..."
      npm install
      infoText "Installing required PHP dependencies (including PHP) ..."
      php /data/bin/composer.phar install --prefer-dist
    fi
    php /data/bin/composer.phar clear-cache

    antelope install
}


function generate_shared_code {
    labelText "Generate code for both Yves and Zed ..."

    infoText "Generate transfer objects ..."
    $CONSOLE transfer:generate
}


function generate_zed_code {
    labelText "Generate code for Zed ..."

    infoText "Propel - Copy schema files ..."
    $CONSOLE propel:schema:copy

    infoText "Propel - Build models ..."
    $CONSOLE propel:model:build

    infoText "Propel - Removing old migration plans ..."
    rm -f $SHOP/src/Orm/Propel/*/Migration_pgsql/*

    infoText "Build Zeds Navigation Cache ..."
    $CONSOLE application:build-navigation-cache
}


function build_assets_for_yves {
    labelText "Building and optimizing assets of Yves"
    antelope build yves
}


function build_assets_for_zed {
    labelText "Building and optimizing assets of Zed"
    antelope build zed
}


function init_shared {
    labelText "Initializing setup"

    infoText "Propel - Converting configuration ..."
    $CONSOLE propel:config:convert

    # FIXME Does this task makes sense during init stage? Since it works on
    # ./data which is not a shared volume? 
    infoText "Cleaning cache ..."
    $CONSOLE cache:delete-all

    infoText "Create Search Index and Mapping Types; Generate Mapping Code."
    $CONSOLE setup:search

    exec_hooks "$SHOP/docker/init.d/Shared"
}


function init_yves {
    labelText "Initializing Yves ..."<commit_msg>moves build of navigation cache into init stage<commit_after>#!/usr/bin/env bash

set -e

export SHOP="/data/shop"
export SETUP=spryker
export TERM=xterm 
export VERBOSITY='-v'
export CONSOLE=vendor/bin/console

source /data/bin/functions.sh

cd $SHOP


function generate_configurations {
  labelText "Create runtime configuration ..."

  infoText "Applying confd templates ..."
  if [ -n "$ETCD_NODE" ]; then
      confd -backend etcd -node ${ETCD_NODE} -prefix ${ETCD_PREFIX} -onetime
  else
      confd -backend env -onetime
  fi

  if [ -e $CONSOLE ]; then
    infoText "Propel - Converting configuration ..."
    $CONSOLE propel:config:convert
  fi 
}


function install_dependencies {
    labelText "Resolving dependencies ..."

    if [ -n "$PHP_EXTENSIONS" ]; then
      export DEBIAN_FRONTEND=noninteractive
      exts=$(echo "$PHP_EXTENSIONS" | awk  'BEGIN {RS=" "} { if (length($1) != 0) { printf "php-%s ", $1 }}' )
      infoText "Installing required PHP extensions: $exts"
      apt-get -y update
      apt-get -y --no-install-recommends install $exts
    fi

    if [ "${APPLICATION_ENV}x" != "developmentx" ]; then
      infoText "Installing required NPM dependencies..."
      npm install --only=production
      infoText "Installing required PHP dependencies..."
      php /data/bin/composer.phar install --prefer-dist --no-dev
    else
      infoText "Installing required NPM dependencies (including dev) ..."
      npm install
      infoText "Installing required PHP dependencies (including PHP) ..."
      php /data/bin/composer.phar install --prefer-dist
    fi
    php /data/bin/composer.phar clear-cache

    antelope install
}


function generate_shared_code {
    labelText "Generate code for both Yves and Zed ..."

    infoText "Generate transfer objects ..."
    $CONSOLE transfer:generate
}


function generate_zed_code {
    labelText "Generate code for Zed ..."

    infoText "Propel - Copy schema files ..."
    $CONSOLE propel:schema:copy

    infoText "Propel - Build models ..."
    $CONSOLE propel:model:build

    infoText "Propel - Removing old migration plans ..."
    rm -f $SHOP/src/Orm/Propel/*/Migration_pgsql/*
}


function build_assets_for_yves {
    labelText "Building and optimizing assets of Yves"
    antelope build yves
}


function build_assets_for_zed {
    labelText "Building and optimizing assets of Zed"
    antelope build zed
}


function init_shared {
    labelText "Initializing setup"

    infoText "Propel - Converting configuration ..."
    $CONSOLE propel:config:convert

    # FIXME Does this task makes sense during init stage? Since it works on
    # ./data which is not a shared volume? 
    infoText "Cleaning cache ..."
    $CONSOLE cache:delete-all

    infoText "Create Search Index and Mapping Types; Generate Mapping Code."
    $CONSOLE setup:search

    infoText "Build Zeds Navigation Cache ..."
    $CONSOLE application:build-navigation-cache

    exec_hooks "$SHOP/docker/init.d/Shared"
}


function init_yves {
    labelText "Initializing Yves ..."
{'fraction_non_alphanumeric': 0.10362005978080371, 'fraction_numerical': 0.0009963467286615742, 'mean_word_length': 2.99933598937583, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2521683', 'n_tokens_mistral': 1935, 'n_tokens_neox': 1810, 'n_words': 555}