jobs:
    install_front_dependencies:
        machine:
            image: 'ubuntu-2004:2022.04.1'
        parameters:
            edition:
                description: either "ce" or "ee"
                type: string
        steps:
            -   attach_workspace:
                    at: ~/
            -   when:
                    condition: { equal: [ ce, << parameters.edition >> ] }
                    steps:
                        -   restore_frontend_dependency_cache
                        -   restore_frontend_dsm_cache:
                                path_to_front_packages: front-packages
                        -   restore_frontend_shared_cache:
                                path_to_front_packages: front-packages
                        -   fix_files_permissions
                        -   load_docker_image_node
                        -   run:
                                name: Install front dependencies
                                command: make node_modules
                        -   run:
                                name: Build front shared libraries
                                command: |
                                    [ -d ~/project/front-packages/akeneo-design-system/lib ] || docker-compose run -u node --rm node yarn dsm:build
                                    [ -d ~/project/front-packages/shared/lib ] || docker-compose run -u node --rm node yarn workspace @akeneo-pim-community/shared lib:build
                        -   persist_to_workspace:
                                root: ~/
                                paths:
                                    - project/node_modules
                                    - project/front-packages/akeneo-design-system/lib
                                    - project/front-packages/shared/lib

            -   when:
                    condition: { equal: [ ee, << parameters.edition >> ] }
                    steps:
                        -   restore_frontend_dependency_cache
                        -   restore_frontend_dsm_cache:
                                path_to_front_packages: vendor/akeneo/pim-community-dev/front-packages
                        -   restore_frontend_shared_cache:
                                path_to_front_packages: vendor/akeneo/pim-community-dev/front-packages
                        -   fix_files_permissions
                        -   load_docker_image_node
                        -   run:
                                name: Install front dependencies
                                command: make node_modules
                        -   run:
                                name: Build front shared libraries
                                command: |
                                    [ -d ~/project/vendor/akeneo/pim-community-dev/front-packages/akeneo-design-system/lib ] || docker-compose run -u node --rm node yarn dsm:build
                                    [ -d ~/project/vendor/akeneo/pim-community-dev/front-packages/shared/lib ] || docker-compose run -u node --rm node yarn workspace @akeneo-pim-community/shared lib:build
                        -   persist_to_workspace:
                                root: ~/
                                paths:
                                    - project/node_modules
                                    - project/vendor/akeneo/pim-community-dev/front-packages/akeneo-design-system/lib
                                    - project/vendor/akeneo/pim-community-dev/front-packages/shared/lib
