Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / vendor / g1a / composer-test-scenarios / scripts / create-scenario
1 #!/bin/bash
2
3 SELF_DIRNAME="`dirname -- "$0"`"
4
5 # The first argument is always the scenario name. Options come after.
6 SCENARIO="$1"
7 shift
8
9 #
10 # This script is typically called after `composer update` from a
11 # "post-update-cmd" in the "scripts" section of composer.json.
12 #
13
14 # Defaults
15 PLATFORM_PHP="--unset"
16 STABILITY="stable"
17 CREATE_LOCKFILE=true
18 AUTOLOAD_DIRECTORIES="src tests"
19 REMOVALS=
20 REQUIREMENTS=
21 BASE=..
22
23 echo
24 echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::"
25 echo "::"
26 echo ":: Create scenario ${SCENARIO}"
27 echo "::"
28 echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::"
29 echo
30
31 while [ $# -gt 0 ] ; do
32
33   option="$1"
34   shift
35
36   case "$option" in
37     --unset-platform-php)
38       PLATFORM_PHP="--unset"
39       shift
40       ;;
41
42     --platform-php)
43       PLATFORM_PHP="$1"
44       shift
45       ;;
46
47     --stability)
48       STABILITY="$1"
49       shift
50       ;;
51
52     --create-lockfile)
53       CREATE_LOCKFILE=true
54       ;;
55
56     --no-lockfile)
57       CREATE_LOCKFILE=false
58       ;;
59
60     --autoload-dir)
61       autoload_dir="$1"
62       shift
63       AUTOLOAD_DIRECTORIES="${AUTOLOAD_DIRECTORIES} ${autoload_dir}"
64       ;;
65
66     --remove)
67       project_to_remove="$1"
68       shift
69       REMOVALS="${REMOVALS} ${project_to_remove}"
70       ;;
71
72     --keep)
73       keep_pattern="$1"
74       shift
75       projects_to_remove="$(composer info --direct | cut -f 1 -d ' ' | grep -v $keep_pattern)"
76       REMOVALS="${REMOVALS} ${projects_to_remove}"
77       ;;
78
79     --base)
80       BASE="$1"
81       shift
82       ;;
83
84     -*)
85       echo "Unknown option $option"
86       exit 1;
87       ;;
88
89     *)
90       REQUIREMENTS="${REQUIREMENTS} ${option}"
91       ;;
92   esac
93 done
94
95 set -ex
96
97 original_name=scenarios
98 recommended_name=".scenarios.lock"
99
100 scenarios_dir="$original_name"
101 if [ -d "$recommended_name" ] ; then
102   scenarios_dir="$recommended_name"
103 fi
104
105 # Create the scenario directory, and start with a fresh composer.json file.
106 dir="$scenarios_dir/${SCENARIO}"
107 mkdir -p $dir
108 cp $scenarios_dir/$BASE/composer.json $dir
109
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}"
112
113 # Set an appropriate minimum stability for this version of Symfony
114 composer -n --working-dir=$dir config minimum-stability "${STABILITY}"
115
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
122
123 # Add a constraint
124 [[ -z "${REQUIREMENTS}" ]] || composer -n --working-dir=$dir require --dev --no-update ${REQUIREMENTS}
125
126 # Never commit a cached 'vendor' directory in the scenario folder
127 echo 'vendor' > $dir/.gitignore
128
129 # Create a lockfile via `composer update`, if requested
130 if $CREATE_LOCKFILE ; then
131
132   # Temporarily set our vendor directory to 'vendor'
133   composer -n --working-dir=$dir config vendor-dir vendor
134
135   # Create the composer.lock file. Ignore the vendor directory created.
136   composer -n --working-dir=$dir update --no-scripts
137
138 else
139
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
143
144 fi
145
146 # Set the vendor directory to its final desired location.
147 composer -n --working-dir=$dir config vendor-dir '../../vendor'
148
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
154 done
155
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