Skip to content

Instantly share code, notes, and snippets.

@lnoering
Last active July 26, 2023 21:21
Show Gist options
  • Save lnoering/df95227dd68ed1826768c9657627595f to your computer and use it in GitHub Desktop.
Save lnoering/df95227dd68ed1826768c9657627595f to your computer and use it in GitHub Desktop.
Zip All modules from vendor

Zip all modules to install by artifact

Steps

Go to the vendor_name folder.

  • Ex.: cd vendor/amasty

Create the file at that folder.

  • Ex.: zip-all.sh

Call the file, and the .zip modules created at the same folder.

  • Ex.: bash zip-all.sh
    -- (vendor/amasty/<vendorname_modulename_1.7.1.zip>)

The name to zip use the composer.json attributes.

name = vendorname/modulename

version = 1.7.1

  • The zip name is: vendorname_modulename_1.7.1.zip
#!/bin/bash

for file in $(find . -name "composer.json"); do
    # DATA=grep -irw -m 2 "\"name\"\|\"version\"" ${file}
    echo ${file}
    # get data
    NAME=$(grep -iw "\"name\"" ${file})
    VERSION=$(grep -iw "\"version\"" ${file})
    
    #remove all before first space
    NAME="$(echo ${NAME} | cut -d' ' -f2)"
    VERSION="$(echo ${VERSION} | cut -d' ' -f2)"

    # remove first " and the last ",
    NAME=${NAME#*\"}
    VERSION=${VERSION#*\"}
    NAME=${NAME%??}
    VERSION=${VERSION%??}

    # change the /
    NAME=${NAME//\//_}  #bash only

    echo ${NAME}"_"${VERSION}".zip"
    ZIPNAME=${NAME}"_"${VERSION}".zip"


    ZIPDIR=${file%/*}

    zip -r ${ZIPNAME} ${ZIPDIR}
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment