From 348f4971ced2ef2e3af3e685be955ebf38488d6f Mon Sep 17 00:00:00 2001 From: Eugenio Romano Date: Tue, 7 Nov 2017 22:08:39 +0000 Subject: [PATCH] improve extract i18n script --- scripts/README.md | 13 ++++++++++++ scripts/extract-langs.sh | 45 ++++++++++++++++++++++++++++------------ 2 files changed, 45 insertions(+), 13 deletions(-) diff --git a/scripts/README.md b/scripts/README.md index a78bea09c3..6a5f5613d9 100644 --- a/scripts/README.md +++ b/scripts/README.md @@ -281,4 +281,17 @@ Add a package across all the pacakge json in the project ```sh ./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 ``` \ No newline at end of file diff --git a/scripts/extract-langs.sh b/scripts/extract-langs.sh index 8e322e5cfa..cd16190c46 100755 --- a/scripts/extract-langs.sh +++ b/scripts/extract-langs.sh @@ -1,17 +1,35 @@ #!/usr/bin/env bash -if [ $# -eq 0 ]; then - echo "No arguments supplied. Default path for output will be used." - LANGS_OUTPUT="./i18n" -else - LANGS_OUTPUT="$1" -fi +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -COMPONENTS_ROOT="ng2-components" +LANGS_OUTPUT="./i18n" + +output_folder(){ + if [ $1 -eq 0 ]; then + echo "No arguments supplied. Default path for output will be used ./i18n" + else + LANGS_OUTPUT="$1" + fi +} + +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 -COMPONENTS=(`find $COMPONENTS_ROOT -type d -name i18n`) -COMPONENTS+=("demo-shell-ng2/resources/i18n") +COMPONENTS=(`find $COMPONENTS_ROOT -type d -name i18n -not \( -name '*.*' -o -path '**/node_modules*' -o -path '**/bundles*' \)`) +COMPONENTS+=("$DIR/../demo-shell-ng2/resources/i18n") # Loop the individual components for COMPONENT_DIR in "${COMPONENTS[@]}" @@ -33,12 +51,13 @@ do : LANG=`echo "$TMP" | tr '[:lower:]' '[:upper:]'` # Conver to upper case # Build the output path, ensure it exists then copy the file - DEST="$LANGS_OUTPUT/$LANG/$COMPONENT_DIR" - echo "\tCopying $i to $DEST" + DEST="$LANGS_OUTPUT/$LANG/${COMPONENT_DIR#${DIR}/../}" + echo "Copying $i to $DEST" `mkdir -p $DEST` `cp $i $DEST` fi done - echo "\n" +done -done \ No newline at end of file +echo "====== Create a zip ======" +zip -r ${LANGS_OUTPUT}/i18n.zip ./${LANGS_OUTPUT}/*