From: Youngsoo Choi Date: Tue, 12 Sep 2017 12:03:28 +0000 (+0900) Subject: Add utility scripts to run grunt or was X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d637d8a62c17b79d7b241c22af86a6eef055693b;p=platform%2Fframework%2Fweb%2Fcrosswalk-tizen.git Add utility scripts to run grunt or was This adds utility scripts to run grunt or was and releases them to out folder. Change-Id: I218e08055763231509ef5da86fea60e2b3468008 Signed-off-by: Youngsoo Choi --- diff --git a/efl/build/desktop/launch.sh b/efl/build/desktop/launch.sh index 53a5199..555ebe7 100755 --- a/efl/build/desktop/launch.sh +++ b/efl/build/desktop/launch.sh @@ -6,7 +6,7 @@ CHROMIUM_EFL_LIBDIR=$(echo "$@" | grep -Po "(?<=\--chromium-efl-path=)[^\s]*" || APP_PATH=$(echo "$@" | grep -Po "(?<=\--app-path=)[^\s]*" || :) if [[ "$CHROMIUM_EFL_LIBDIR" == "" ]]; then - echo "Please add --chromium-efl-path=/PATH/TO/chromium-efl" + echo "Please use --chromium-efl-path option" exit 1 fi CHROMIUM_EFL_LIBDIR=$CHROMIUM_EFL_LIBDIR/out.x64 diff --git a/wrt/build/run_grunt.sh b/wrt/build/run_grunt.sh new file mode 100755 index 0000000..f912884 --- /dev/null +++ b/wrt/build/run_grunt.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash + +export SCRIPTDIR=$(readlink -e $(dirname $0)) +pushd $SCRIPTDIR +grunt -v +popd diff --git a/wrt/build/script/optparse/LICENSE b/wrt/build/script/optparse/LICENSE new file mode 100644 index 0000000..26539d0 --- /dev/null +++ b/wrt/build/script/optparse/LICENSE @@ -0,0 +1,7 @@ +Copyright (c) 2015 Nagarjuna Kumar + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/wrt/build/script/optparse/README.md b/wrt/build/script/optparse/README.md new file mode 100644 index 0000000..0810462 --- /dev/null +++ b/wrt/build/script/optparse/README.md @@ -0,0 +1,64 @@ +#Optparse +A BASH wrapper for getopts, for simple command-line argument parsing + +##What is this? +A wrapper that provides a clean and easy way to parse arguments to your BASH scripts. It lets you define short and long option names, handle flag variables, and set default values for optional arguments, all while aiming to be as minimal as possible: *One line per argument definition*. + +##Usage +##### See `sample_head.sh` for a demonstration of optparse +###1. Define your arguments + +Each argument to the script is defined with `optparse.define`, which specifies the option names, a short description, the variable it sets and the default value (if any). + +```bash +optparse.define short=f long=file desc="The input file" variable=filename +``` + +Flags are defined in exactly the same way, but with an extra parameter `value` that is assigned to the variable. + +```bash +optparse.define short=v long=verbose desc="Set flag for verbose mode" variable=verbose_mode value=true default=false +``` + +###2. Evaluate your arguments +The `optparse.build` function creates a temporary header script based on the provided argument definitions. Simply source the file the function returns, to parse the arguments. + +```bash +source $( optparse.build ) +``` + +####That's it! +The script can now make use of the variables. Running the script (without any arguments) should give you a neat usage description. + + usage: ./script.sh [OPTIONS] + + OPTIONS: + + -f --file : The input file + -v --verbose : Set flag for verbose mode + + -? --help : usage + +##Supported definition parameters +All definition parameters for `optparse.define` are provided as `key=value` pairs, seperated by an `=` sign. +####`short` +a short, single-letter name for the option +####`long` +a longer expanded option name +####`variable` +the target variable that the argument represents +####`value`(optional) +the value to set the variable to. If unspecified, user is expected to provide a value. +####`desc`(optional) +a short description of the argument (to build the usage description) +####`default`(optional) +the default value to set the variable to if argument not specified + +##Installation +1. Download/clone `optparse.bash` +2. Add + +```bash +`source /path/to/optparse.bash` +``` +to `~/.bashrc` diff --git a/wrt/build/script/optparse/optparse.bash b/wrt/build/script/optparse/optparse.bash new file mode 100644 index 0000000..894c8fc --- /dev/null +++ b/wrt/build/script/optparse/optparse.bash @@ -0,0 +1,156 @@ +# Optparse - a BASH wrapper for getopts +# @author : nk412 / nagarjuna.412@gmail.com + +optparse_usage="" +optparse_contractions="" +optparse_defaults="" +optparse_process="" +optparse_arguments_string="" + +# ----------------------------------------------------------------------------------------------------------------------------- +function optparse.throw_error(){ + local message="$1" + echo "OPTPARSE: ERROR: $message" + exit 1 +} + +# ----------------------------------------------------------------------------------------------------------------------------- +function optparse.define(){ + if [ $# -lt 3 ]; then + optparse.throw_error "optparse.define [] [] []" + fi + for option_id in $( seq 1 $# ) ; do + local option="$( eval "echo \$$option_id")" + local key="$( echo $option | awk -F "=" '{print $1}' )"; + local value="$( echo $option | awk -F "=" '{print $2}' )"; + + #essentials: shortname, longname, description + if [ "$key" = "short" ]; then + local shortname="$value" + if [ ${#shortname} -ne 1 ]; then + optparse.throw_error "short name expected to be one character long" + fi + local short="-${shortname}" + elif [ "$key" = "long" ]; then + local longname="$value" + if [ ${#longname} -lt 2 ]; then + optparse.throw_error "long name expected to be atleast one character long" + fi + local long="--${longname}" + elif [ "$key" = "desc" ]; then + local desc="$value" + elif [ "$key" = "default" ]; then + local default="$value" + elif [ "$key" = "variable" ]; then + local variable="$value" + elif [ "$key" = "value" ]; then + local val="$value" + fi + done + + if [ "$variable" = "" ]; then + optparse.throw_error "You must give a variable for option: ($short/$long)" + fi + + if [ "$val" = "" ]; then + val="\$OPTARG" + fi + + # build OPTIONS and help + optparse_usage="${optparse_usage}#NL#TB${short} $(printf "%-25s %s" "${long}:" "${desc}")" + if [ "$default" != "" ]; then + optparse_usage="${optparse_usage} [default:$default]" + fi + optparse_contractions="${optparse_contractions}#NL#TB#TB${long})#NL#TB#TB#TBparams=\"\$params ${short}\";;" + if [ "$default" != "" ]; then + optparse_defaults="${optparse_defaults}#NL${variable}=${default}" + fi + optparse_arguments_string="${optparse_arguments_string}${shortname}" + if [ "$val" = "\$OPTARG" ]; then + optparse_arguments_string="${optparse_arguments_string}:" + fi + optparse_process="${optparse_process}#NL#TB#TB${shortname})#NL#TB#TB#TB${variable}=\"$val\";;" +} + +# ----------------------------------------------------------------------------------------------------------------------------- +function optparse.build(){ + local build_file="/tmp/optparse-${RANDOM}.tmp" + + # Building getopts header here + + # Function usage + cat << EOF > $build_file +function usage(){ +cat << XXX +usage: \$0 [OPTIONS] + +OPTIONS: + $optparse_usage + + -? --help : usage + +XXX +} + +# Contract long options into short options +params="" +while [ \$# -ne 0 ]; do + param="\$1" + shift + + case "\$param" in + $optparse_contractions + "-?"|--help) + usage + exit 0;; + *) + if [[ "\$param" == --* ]]; then + echo -e "Unrecognized long option: \$param" + usage + exit 1 + fi + params="\$params \"\$param\"";; + esac +done + +eval set -- "\$params" + +# Set default variable values +$optparse_defaults + +# Process using getopts +while getopts "$optparse_arguments_string" option; do + case \$option in + # Substitute actions for different variables + $optparse_process + :) + echo "Option - \$OPTARG requires an argument" + exit 1;; + *) + usage + exit 1;; + esac +done + +# Clean up after self +rm $build_file + +EOF + + local -A o=( ['#NL']='\n' ['#TB']='\t' ) + + for i in "${!o[@]}"; do + sed -i "s/${i}/${o[$i]}/g" $build_file + done + + # Unset global variables + unset optparse_usage + unset optparse_process + unset optparse_arguments_string + unset optparse_defaults + unset optparse_contractions + + # Return file name to parent + echo "$build_file" +} +# ----------------------------------------------------------------------------------------------------------------------------- diff --git a/wrt/build/script/optparse/sample_head.sh b/wrt/build/script/optparse/sample_head.sh new file mode 100755 index 0000000..a7e6c86 --- /dev/null +++ b/wrt/build/script/optparse/sample_head.sh @@ -0,0 +1,38 @@ +#!/usr/bin/env bash + +# Source the optparse.bash file --------------------------------------------------- +source optparse.bash +# Define options +optparse.define short=f long=file desc="The file to process" variable=file +optparse.define short=o long=output desc="The output file" variable=output default=head_output.txt +optparse.define short=l long=lines desc="The number of lines to head (default:5)" variable=lines default=5 +optparse.define short=v long=verbose desc="Flag to set verbose mode on" variable=verbose_mode value=true default=false +# Source the output file ---------------------------------------------------------- +source $( optparse.build ) + +if [ "$file" == "" ]; then + echo "ERROR: Please provide a file" + exit 1 +fi + +# Display arguments +if [ "$verbose_mode" = "true" ]; then + echo "Verbose mode ON" + echo "FILE : $file" + echo "OUTPUT: $output" + echo "LINES : $lines" +fi + +# Check if input file exists +if [ "$verbose_mode" = "true" ]; then echo "Checking input file $file..." ; fi +if [ ! -f $file ]; then + echo "File does not exist" + exit 1 +fi + +if [ "$verbose_mode" = "true" ]; then echo "Heading first $lines lines into $output..." ; fi +cat $file | head -n $lines > $output + +if [ "$verbose_mode" = "true" ]; then echo "Done."; fi + +exit 0 diff --git a/wrt/build/script/run_was_ubuntu.sh b/wrt/build/script/run_was_ubuntu.sh new file mode 100755 index 0000000..15a14ff --- /dev/null +++ b/wrt/build/script/run_was_ubuntu.sh @@ -0,0 +1,67 @@ +#!/usr/bin/env bash +#was +#get dirname from first system arguments +dir=`dirname $0` + +#value +export SCRIPTDIR=$(readlink -e $(dirname $0)) +# we use this npm module for debugging +# https://github.com/visionmedia/debug + +#MAIN,RUNTIME,WEBAPPLICATION,WEBVIEW +export TARGET=UBUNTU + +export WAS_EXTENSIONS_REPO=$SCRIPTDIR/wrt_support/extensions_repo +export WAS_EXTENSIONS_PATH=$SCRIPTDIR/wrt_support/extensions +export WAS_INSTALLER_PATH=$SCRIPTDIR/wrt_support/installer +export WAS_INSTALLER_EXT_PATH=$SCRIPTDIR/wrt_support/installer/js/extension +export WAS_APPS_REPO=$SCRIPTDIR/wrt_support/apps_repo +export WAS_HOME=$SCRIPTDIR/wrt_support +export WAS_SAMPLE_PATH=$SCRIPTDIR/wrt_support/sample + +# Source the optparse.bash file --------------------------------------------------- +source $SCRIPTDIR/optparse/optparse.bash +# Define options +optparse.define short=p long=package desc="The file to process" variable=package +optparse.define short=u long=path desc="path" variable=path +optparse.define short=d long=debug desc="debug mode on" variable=debug value=true default=false +optparse.define short=e long=electron desc="electron" variable=electron +optparse.define short=c long=chromium-efl-path desc="chromium-elf path" variable=chromium_efl_path + +if [ "$1" != "" ]; then + export ELECTRON= +else + export ELECTRON="$SCRIPTDIR/../electron" +fi + + +# Source the output file ---------------------------------------------------------- +source $( optparse.build ) + +# Display arguments +if [ "$debug" = "true" ]; then + echo "********* DEBUG MODE ON *********" + export DEBUG=* +fi + +if [ -n "$package" ]; then + echo "PACKAGE_NAME : " $package + $SCRIPTDIR/../electron --package $package +fi + +if [ -n "$path" ]; then + echo "PATH_NAME : " $path + $SCRIPTDIR/../electron --path `readlink -f $path` # path is going to change to absolute path +fi + +if [ -n "$electron" ]; then + \echo "ELECTRON_PATH_NAME : " $electron + $electron +fi + +if [ "$package" == "" ] && [ "$path" == "" ] && [ "$electron" == "" ]; then + $SCRIPTDIR/../electron.sh --chromium-efl-path=$chromium_efl_path +fi + +exit 0 + diff --git a/wrt/build/tasks/build-task.coffee b/wrt/build/tasks/build-task.coffee index 42e5930..be2eaf4 100644 --- a/wrt/build/tasks/build-task.coffee +++ b/wrt/build/tasks/build-task.coffee @@ -191,6 +191,7 @@ module.exports = (grunt) -> cp path.join(wrtDir, 'static'), path.join(appDir, 'static') cp path.join(wrtDir, 'wrt_support'), path.join(buildDir, 'resources/wrt_support') cp path.join(wrtDir, 'node_modules'), path.join(appDir, '..', 'node_modules') + cp path.join(wrtDir, 'build', 'script'), path.join(buildDir, 'resources') # cp path.join('apm', 'node_modules', 'atom-package-manager'), path.resolve(appDir, '..', 'new-app', 'apm'), filter: filterNodeModule # if process.platform isnt 'win32'