- name: copy or replace default index.js in frontend-workstation/locale folder
  copy:
    src: "{{ playbook_dir }}/files/default_locale/index.js"
    dest: "{{ DEVORCH_BASE_PATH }}/{{ DEVORCH_HOME_DIR }}/frontend-workstation/locale/index.js"

- name: Register the NVM_DIR
  shell: echo $NVM_DIR
  register: nvm_dir

- name: Install the nvm if not install already
  shell: curl https://raw.githubusercontent.com/creationix/nvm/master/install.sh | bash
  args:
    executable: /bin/bash
  when: nvm_dir.stdout == ""

- name: Install the default node version
  # Need to source nvm.sh with --no-use flag because of https://github.com/nvm-sh/nvm/issues/1985
  shell: source ~/.nvm/nvm.sh --no-use && nvm install
  args:
    executable: /bin/bash
    chdir: "{{ DEVORCH_BASE_PATH }}/{{ DEVORCH_HOME_DIR }}/frontend-workstation/"

- name: Install frontend-workstation dependencies
  shell: source ~/.nvm/nvm.sh && nvm use && corepack enable pnpm && pnpm install --frozen-lockfile
  args:
    executable: /bin/bash
    chdir: "{{ DEVORCH_BASE_PATH }}/{{ DEVORCH_HOME_DIR }}/frontend-workstation/"

- name: Build frontend-workstation
  shell: source ~/.nvm/nvm.sh && nvm use && corepack enable pnpm && pnpm build
  args:
    executable: /bin/bash
    chdir: "{{ DEVORCH_BASE_PATH }}/{{ DEVORCH_HOME_DIR }}/frontend-workstation/"
