3 SELF_DIRNAME="`dirname -- "$0"`"
5 # The first argument is always the scenario name. Options come after.
10 # This script is typically called after `composer update` from a
11 # "post-update-cmd" in the "scripts" section of composer.json.
15 PLATFORM_PHP="--unset"
18 AUTOLOAD_DIRECTORIES="src tests"
24 echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::"
26 echo ":: Create scenario ${SCENARIO}"
28 echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::"
31 while [ $# -gt 0 ] ; do
38 PLATFORM_PHP="--unset"
63 AUTOLOAD_DIRECTORIES="${AUTOLOAD_DIRECTORIES} ${autoload_dir}"
67 project_to_remove="$1"
69 REMOVALS="${REMOVALS} ${project_to_remove}"
75 projects_to_remove="$(composer info --direct | cut -f 1 -d ' ' | grep -v $keep_pattern)"
76 REMOVALS="${REMOVALS} ${projects_to_remove}"
85 echo "Unknown option $option"
90 REQUIREMENTS="${REQUIREMENTS} ${option}"
97 original_name=scenarios
98 recommended_name=".scenarios.lock"
100 scenarios_dir="$original_name"
101 if [ -d "$recommended_name" ] ; then
102 scenarios_dir="$recommended_name"
105 # Create the scenario directory, and start with a fresh composer.json file.
106 dir="$scenarios_dir/${SCENARIO}"
108 cp $scenarios_dir/$BASE/composer.json $dir
110 # Then set our own platform php version if applicable (otherwise unset it)
111 [[ -z "${PLATFORM_PHP}" ]] || composer -n --working-dir=$dir config platform.php "${PLATFORM_PHP}"
113 # Set an appropriate minimum stability for this version of Symfony
114 composer -n --working-dir=$dir config minimum-stability "${STABILITY}"
116 # Remove components that are not desired.
117 # We do not care whether a component is present in the `require` or
118 # `require-dev` section; we will attempt to remove each request from
119 # both. This may produce warning messages.
120 [[ -z "${REMOVALS}" ]] || composer -n --working-dir=$dir remove --no-update ${REMOVALS}
121 [[ -z "${REMOVALS}" ]] || composer -n --working-dir=$dir remove --no-update --dev ${REMOVALS} >/dev/null 2>&1
124 [[ -z "${REQUIREMENTS}" ]] || composer -n --working-dir=$dir require --dev --no-update ${REQUIREMENTS}
126 # Never commit a cached 'vendor' directory in the scenario folder
127 echo 'vendor' > $dir/.gitignore
129 # Create a lockfile via `composer update`, if requested
130 if $CREATE_LOCKFILE ; then
132 # Temporarily set our vendor directory to 'vendor'
133 composer -n --working-dir=$dir config vendor-dir vendor
135 # Create the composer.lock file. Ignore the vendor directory created.
136 composer -n --working-dir=$dir update --no-scripts
140 # If we are not storing a composer.lock, mark it as ignored if
141 # transiently generated in the future
142 echo 'composer.lock' >> $dir/.gitignore
146 # Set the vendor directory to its final desired location.
147 composer -n --working-dir=$dir config vendor-dir '../../vendor'
149 # The 'autoload' section specifies directory paths that are relative
150 # to the composer.json file. We will drop in some symlinks so that
151 # these paths will resolve as if the composer.json were in the root.
152 for target in ${AUTOLOAD_DIRECTORIES} ; do
153 [[ ! -d "$target" ]] || ln -s -f ../../$target $dir
156 # Copy our install-scenario script in so that it may be committed with our composer.lock files
157 cp -f ${SELF_DIRNAME}/install-scenario $dir/../install
158 chmod +x $dir/../install