Skip to content

Commit

Permalink
Merge pull request #38 from axelerant/modules
Browse files Browse the repository at this point in the history
feat: allow specifying composer packages and Drupal modules
  • Loading branch information
hussainweb authored Oct 11, 2020
2 parents 9ae0973 + e229763 commit ba23665
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
30 changes: 29 additions & 1 deletion axltempl/composer.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,34 @@ def run_install():
sys.exit(4)


def require_packages(packages, dev=False):
"""
Run composer require or require --dev
"""
if not is_present():
util.write_error("Cannot find composer. Aborting...")
sys.exit(4)

if len(packages) == 0:
return

cmd = "composer require "
if dev:
cmd += "--dev "
cmd += " ".join([str(p) for p in packages])

composer_run = subprocess.run(cmd, shell=True, check=False)
if composer_run.returncode != 0:
util.write_error("Error when running 'composer require'. Aborting...")
util.write_error("Make sure you have set an adequate PHP memory limit.")
util.write_warning(
"Read {} for more details".format(
"https://getcomposer.org/doc/articles/troubleshooting.md#memory-limit-errors"
)
)
sys.exit(4)


def get_drupal_template(name, description, core, core_version, docroot, cache_service):
"""
Get the composer template from package and modify it as per given options
Expand Down Expand Up @@ -180,7 +208,7 @@ def __str__(self) -> str:
"""
package_str = self.name
if self.version:
package_str += ":" + self.version
package_str += f':"{self.version}"'
return package_str

def __repr__(self) -> str:
Expand Down
12 changes: 12 additions & 0 deletions axltempl/drupal.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,16 @@
default=DEFAULT_CORE_VERSION,
show_default=True,
)
@click.option(
"--module",
"--package",
"-m",
"-p",
"packages",
type=click_types.COMPOSER_PACKAGE,
help="Specify Drupal module names or PHP packages",
multiple=True,
)
@click.option(
"--docroot", help="The document root", type=click.Path(exists=False), default="web"
)
Expand All @@ -80,6 +90,7 @@ def main(
description,
core_package,
core_version,
packages,
docroot,
cache,
add_lando,
Expand Down Expand Up @@ -112,6 +123,7 @@ def main(
)

composer.run_install()
composer.require_packages(packages)

settings_file = ensure_settings_file(docroot)
modify_settings_file(
Expand Down

0 comments on commit ba23665

Please sign in to comment.