Skip to content

Instantly share code, notes, and snippets.

@shawnachieve
Last active December 5, 2016 19:37
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shawnachieve/49e7492c328f5e52db24 to your computer and use it in GitHub Desktop.
Save shawnachieve/49e7492c328f5e52db24 to your computer and use it in GitHub Desktop.
Drush qd shell extension.
# Creates a quick drupal installation with pre-configured defaults.
# Syntax:
# qd [drupalversion:7|8] [projectname] [modulelist] [giturl]
qd() {
if [ "$#" -gt 4 ]; then
echo -ne "ERROR: Too many arguments specified. Make sure there are no spaces in the list of contrib modules.\n"
fi
if [ "$#" -lt 2 ] || [ "$#" -gt 4 ]; then
echo -ne "Creates a quick Drupal installation with pre-configured defaults.\n"
echo -ne "Syntax:\n"
echo -ne "qd [drupalversion:7|8] [projectname] [modulelist] [giturl]\n"
echo -ne "\nExample: qd 7 views https://git.drupal.org/project/views.git ctools,token\n"
return 1
fi
if [ ! -f /usr/local/bin/pstorm ]; then
echo -ne "ERROR: PHPStorm command line executable has not been created at /usr/local/bin/pstorm.\n"
echo -ne "Launch PHPStorm, go to the Tools menu, and select 'Create command line launcher'."
return 1
fi
DRUPAL_VERSION=$1
CORE="drupal-${DRUPAL_VERSION}.x"
PROJECT_NAME="$2"
GIT_REPO="$4"
MODULE_LIST="$3"
PROJECT_ROOT=~/Sites/contrib_modules
DOCROOT_DIRECTORY=${PROJECT_ROOT}/${PROJECT_NAME}/${CORE}
if [ ! -d ${PROJECT_ROOT} ]; then
mkdir -p ${PROJECT_ROOT}
fi
echo -ne "Drupal Core: ${CORE}\n"
echo -ne "Project Name: ${PROJECT_NAME}\n"
echo -ne "Git Repo: ${GIT_REPO}\n"
echo -ne "Module List: ${MODULE_LIST}\n"
cd ${PROJECT_ROOT}
drush qd --core=$CORE --account-pass=admin --no-browser --no-server --yes ${PROJECT_NAME} ${MODULE_LIST}
cd ${DOCROOT_DIRECTORY}
echo -ne "\n\nDocument Root: ${DOCROOT_DIRECTORY}\n\n"
# Add the php web server router file so that clean urls work.
wget --output-document=${DOCROOT_DIRECTORY}/.ht.router.php https://gist.githubusercontent.com/shawnachieve/4592ea196d1c8519e3b6/raw
if [ "${DRUPAL_VERSION}" -eq "7" ]; then
MODULE_DIRECTORY=${DOCROOT_DIRECTORY}/sites/all/modules
elif [ "${DRUPAL_VERSION}" -eq "8" ]; then
MODULE_DIRECTORY=${DOCROOT_DIRECTORY}/modules
fi
if [ ! -z MODULE_DIRECTORY ] && [ ! -z $GIT_REPO ]; then
cd $MODULE_DIRECTORY
git clone ${GIT_REPO}
PROJECT_DIRECTORY=${MODULE_DIRECTORY}/${PROJECT_NAME}
cd ${PROJECT_DIRECTORY}
# Create the default PHPStorm Run Configuration.
IDEA_DIR=${PROJECT_DIRECTORY}/.idea
RUN_CONFIG_DIR=${IDEA_DIR}/runConfigurations
DEV_SITE_RUN_CONF=${RUN_CONFIG_DIR}/Dev_Site.xml
mkdir -p ${RUN_CONFIG_DIR}
echo -ne "<component name=\"ProjectRunConfigurationManager\">\n" >> ${DEV_SITE_RUN_CONF}
echo -ne " <configuration default=\"false\" name=\"Dev Site\" type=\"PhpBuiltInWebServerConfigurationType\" factoryName=\"PHP Built-in Web Server\" document_root=\"\$PROJECT_DIR\$/../../../..\" host=\"127.0.0.1\" port=\"8888\" router_script=\"\$PROJECT_DIR\$/../../../../.ht.router.php\" use_router_script=\"true\">\n" >> ${DEV_SITE_RUN_CONF}
echo -ne " <method />\n" >> ${DEV_SITE_RUN_CONF}
echo -ne " </configuration>\n" >> ${DEV_SITE_RUN_CONF}
echo -ne "</component>\n" >> ${DEV_SITE_RUN_CONF}
# Create a minimal PHPStorm workspace.xml file.
WORKSPACE_FILE=${IDEA_DIR}/workspace.xml
echo -ne "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" >> ${WORKSPACE_FILE}
echo -ne "<project version=\"4\">\n" >> ${WORKSPACE_FILE}
echo -ne " <component name=\"PhpWorkspaceProjectConfiguration\" backward_compatibility_performed=\"true\" interpreter_name=\"PHP 5.6\" />\n" >> ${WORKSPACE_FILE}
echo -ne " <component name=\"DrupalConfiguration\" enabled=\"true\" version=\"${DRUPAL_VERSION}\">\n" >> ${WORKSPACE_FILE}
echo -ne " <drupalPath>\$PROJECT_DIR\$/../../../..</drupalPath>\n" >> ${WORKSPACE_FILE}
echo -ne " </component>\n" >> ${WORKSPACE_FILE}
echo -ne "</project>\n" >> ${WORKSPACE_FILE}
# Launch PHPStorm.
/usr/local/bin/pstorm ${PROJECT_DIRECTORY}
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment