[4037] | 1 | #!/bin/sh |
---|
| 2 | |
---|
| 3 | # Usage: build-module.sh [theme] |
---|
| 4 | # The local directory of module must be a git repo and version will be extracted from its tags |
---|
| 5 | # The module installable archive will be created inside the current directory (module root) |
---|
| 6 | # |
---|
| 7 | # Examples: |
---|
| 8 | # (Assuming that the current path is the dotclear local repo root) |
---|
| 9 | # |
---|
| 10 | # Plugin module, inside plugins folder: |
---|
| 11 | # $ cd plugins/my-plugin |
---|
| 12 | # $ ../build-tools/build-module.sh |
---|
| 13 | # |
---|
| 14 | # Theme module, inside themes folder: |
---|
| 15 | # $ cd themes/my-theme |
---|
| 16 | # $ ../build-tools/build-module.sh theme |
---|
| 17 | |
---|
| 18 | # Module type |
---|
| 19 | MOD_TYPE="plugin" |
---|
| 20 | |
---|
| 21 | # Default module version |
---|
| 22 | DEF_VERSION="0.1" |
---|
| 23 | |
---|
| 24 | # Path for JS minifier (1st argument is the js file to minify) |
---|
| 25 | DIRECTORY=$(dirname "$0") |
---|
| 26 | MIN_JS="$DIRECTORY/min-js.php" |
---|
| 27 | |
---|
| 28 | # Check optionnal 1st parameter (module type) |
---|
| 29 | if [ "$1" = "theme" ]; then |
---|
| 30 | MOD_TYPE="theme" |
---|
| 31 | fi |
---|
| 32 | |
---|
| 33 | # Find module name |
---|
| 34 | MOD_NAME=$(basename "$PWD") |
---|
[4038] | 35 | if [ "$MOD_NAME" = "themes" ] || [ "$MOD_NAME" = "plugins" ] || [ -d ./plugins ] ; then |
---|
| 36 | echo "Launch this command inside the module folder!" |
---|
| 37 | exit 1 |
---|
| 38 | fi |
---|
[4037] | 39 | |
---|
| 40 | # Copy all files to tmp dir |
---|
| 41 | if [ -d "$MOD_NAME" ]; then |
---|
| 42 | rm -rf ./"$MOD_NAME" |
---|
| 43 | fi |
---|
| 44 | mkdir ./"$MOD_NAME" |
---|
| 45 | rsync --exclude="$MOD_NAME" --exclude="mkdocs" --exclude="build.sh" --exclude=".git*" --exclude=".DS_Store" --exclude="*.zip" --exclude="*.map" --exclude="*.rb" --exclude="sass" --exclude="scss" --exclude=".sass*" --exclude="scripts" -a . ./"$MOD_NAME" |
---|
| 46 | |
---|
| 47 | # Pack Javascript files |
---|
| 48 | if [ -f "$MIN_JS" ]; then |
---|
| 49 | find ./"$MOD_NAME" -name '*.js' -exec "$MIN_JS" \{\} \; |
---|
| 50 | fi |
---|
| 51 | |
---|
| 52 | # Find last version (if any) |
---|
| 53 | CUR_VERSION=$(git tag -l | sort -r -V | grep -E "[0-9]" | head -n 1) |
---|
| 54 | if [ -z "$CUR_VERSION" ]; then |
---|
| 55 | CUR_VERSION=$DEF_VERSION |
---|
| 56 | fi |
---|
| 57 | |
---|
| 58 | # Make installable archive |
---|
| 59 | if [ -f $MOD_TYPE-"$MOD_NAME"-$CUR_VERSION.zip ]; then |
---|
| 60 | rm $MOD_TYPE-"$MOD_NAME"-$CUR_VERSION.zip |
---|
| 61 | fi |
---|
| 62 | zip -q -r $MOD_TYPE-"$MOD_NAME"-$CUR_VERSION.zip ./"$MOD_NAME"/ |
---|
| 63 | |
---|
| 64 | # Cleanup |
---|
| 65 | rm -rf ./"$MOD_NAME" |
---|
| 66 | |
---|
| 67 | # Final output |
---|
| 68 | echo "$MOD_TYPE-$MOD_NAME-$CUR_VERSION.zip ready!" |
---|