From 5d5b36925ed0994ffb5a6845434547aa69425bff Mon Sep 17 00:00:00 2001 From: Madds Holland Date: Wed, 30 Nov 2022 12:58:21 -0600 Subject: [PATCH] Add list of NPM module building with fallback to non-list building --- tasks/main.yml | 9 ++++++++- tasks/npm.yml | 9 +++++---- vars/main.yml | 4 ++-- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/tasks/main.yml b/tasks/main.yml index cb32ce9..446f664 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -88,8 +88,15 @@ when: - _gitignore_pantheon.stat.exists == true -- name: Work with npm +- name: Work with npm list include_tasks: "npm.yml" + loop: "{{ pantheon_deploy.build.npm }}" + when: ( pantheon_deploy.build.npm is defined ) and ( pantheon_deploy.build.npm | type_debug == "list" ) + +- name: Work with npm item + include_tasks: "npm.yml" + loop: "{{ [pantheon_deploy.build.npm] }}" + when: ( pantheon_deploy.build.npm is defined ) and ( pantheon_deploy.build.npm | type_debug != "list" ) - name: Work with secrets include_tasks: "secrets.yml" diff --git a/tasks/npm.yml b/tasks/npm.yml index 441838b..aeafea8 100644 --- a/tasks/npm.yml +++ b/tasks/npm.yml @@ -3,8 +3,8 @@ set_fact: _npm_dir: "\ {{ _run_temp_dir.path }}/src\ - {% if pantheon_deploy.build.npm_dir is defined %}\ - /{{ pantheon_deploy.build.npm_dir }}\ + {% if item.npm_dir is defined %}\ + /{{ item.npm_dir }}\ {% endif %}" - name: Check if package.json exists @@ -13,15 +13,16 @@ register: _package_json - name: Install NPM - shell: "npm {{ pantheon_deploy.build.npm_install_cmd | default('ci') }}" + shell: "npm {{ item.npm_install_cmd | default('ci') }}" args: chdir: "{{ _npm_dir }}" when: - _package_json.stat.exists == true - name: Run npm build - shell: "npm run {{ pantheon_deploy.build.npm_build_script_name | default('build') }}" + shell: "npm run {{ item.npm_build_script_name | default('build') }}" args: chdir: "{{ _npm_dir }}" when: - _package_json.stat.exists == true + diff --git a/vars/main.yml b/vars/main.yml index 74e650d..34304f8 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -4,8 +4,8 @@ _pantheon_deploy_defaults: git_dir: '' git_branch: 'main' build: - npm_dir: '' - npm_build_script_name: 'build' + - npm_dir: '' + npm_build_script_name: 'build' target: ssh_key_base64: '' ssh_pub_base64: ''