improve extract i18n script

This commit is contained in:
Eugenio Romano
2017-11-07 22:08:39 +00:00
parent 5fff7fcb29
commit 348f4971ce
2 changed files with 45 additions and 13 deletions

View File

@@ -282,3 +282,16 @@ Add a package across all the pacakge json in the project
```sh ```sh
./npm-add-pkg.sh --save-dev NPM_NAME ./npm-add-pkg.sh --save-dev NPM_NAME
``` ```
***extract-langs.sh***
Extract the i18n files from the repo and create a zip
| Option | Description |
| --- | --- |
| -h or --help | show the help |
| --output or o | output folder otherwise will be 18n |
```sh
./extract-langs.sh
```

View File

@@ -1,17 +1,35 @@
#!/usr/bin/env bash #!/usr/bin/env bash
if [ $# -eq 0 ]; then DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
echo "No arguments supplied. Default path for output will be used."
LANGS_OUTPUT="./i18n" LANGS_OUTPUT="./i18n"
output_folder(){
if [ $1 -eq 0 ]; then
echo "No arguments supplied. Default path for output will be used ./i18n"
else else
LANGS_OUTPUT="$1" LANGS_OUTPUT="$1"
fi fi
}
COMPONENTS_ROOT="ng2-components" show_help() {
echo "Usage: extract-langs.sh Extract the i18n files from the repo and create a zip"
echo ""
echo "--output or -o to specify a folder otherwise it will be created in i18n"
}
while [[ $1 == -* ]]; do
case "$1" in
-h|--help|-\?) show_help; exit 0;;
--output|-o) output_folder $2; shift;;
esac
done
COMPONENTS_ROOT="$DIR/../ng2-components"
# Find all directories in $COMPONENTS_ROOT called i18n and add the demo-shell manually # Find all directories in $COMPONENTS_ROOT called i18n and add the demo-shell manually
COMPONENTS=(`find $COMPONENTS_ROOT -type d -name i18n`) COMPONENTS=(`find $COMPONENTS_ROOT -type d -name i18n -not \( -name '*.*' -o -path '**/node_modules*' -o -path '**/bundles*' \)`)
COMPONENTS+=("demo-shell-ng2/resources/i18n") COMPONENTS+=("$DIR/../demo-shell-ng2/resources/i18n")
# Loop the individual components # Loop the individual components
for COMPONENT_DIR in "${COMPONENTS[@]}" for COMPONENT_DIR in "${COMPONENTS[@]}"
@@ -33,12 +51,13 @@ do :
LANG=`echo "$TMP" | tr '[:lower:]' '[:upper:]'` # Conver to upper case LANG=`echo "$TMP" | tr '[:lower:]' '[:upper:]'` # Conver to upper case
# Build the output path, ensure it exists then copy the file # Build the output path, ensure it exists then copy the file
DEST="$LANGS_OUTPUT/$LANG/$COMPONENT_DIR" DEST="$LANGS_OUTPUT/$LANG/${COMPONENT_DIR#${DIR}/../}"
echo "\tCopying $i to $DEST" echo "Copying $i to $DEST"
`mkdir -p $DEST` `mkdir -p $DEST`
`cp $i $DEST` `cp $i $DEST`
fi fi
done done
echo "\n"
done done
echo "====== Create a zip ======"
zip -r ${LANGS_OUTPUT}/i18n.zip ./${LANGS_OUTPUT}/*