deploy.sh 2.08 KB
#/bin/sh


# Ugly mix of shell and javascript to get the job done.
# Maybe it would be better to fuse all into one javascript code for node.

if [ -z $2 ]; then
    cat <<_USAGE
usage: $0 dev_app_path deploy_path
       $0 must be run from the base path (baseUrl) of your application
       all paths must be directories and deploy_path must be empty
_USAGE
    exit 1 ;
fi

if [ ! -d $1 ]; then
    echo "$1 do not exist or is not a directory. Stop."
    exit 1;
fi

if [ ! -e $2 ]; then
    echo "$2 do not exist. Creating."
    mkdir -p "$2"
else
    if [ ! -d $2 ]; then 
        echo "$2 is not a directory. Stop"
        exit 1;
    fi
fi

for i in $1/*.json ; 
do

DEPS=`node <<_END | sort | uniq

/* this dummy arcs_module function is here to extract dependencies of each
 * component library 
 */

function arcs_module() {
    var i,j , arr;
    for (i = 1; i < arguments.length; i++) {
        arr = arguments[i];
        for (j=0; j < arr.length; j++) {
            if (typeof arr[j] === "string") {
                console.log( arr[j] + '.js' );
            } else {
                if (arr[j].name !== undefined ) {
                    console.log( arr[j].name + '.js' );
                }
            }
        }
    }
}

/* this main code checks out if a file name arcsapp.json exists and then 
 * parses it and look for component libraries 
 */

var j, libs, mod;
var descr = require('./$i');
if (descr.context !== undefined) {
    if (descr.context.libraries !== undefined) {
        libs = descr.context.libraries ;
        if (libs.length !== undefined) {
            for (j= 0; j < libs.length; j++) {
                console.log('./' + libs[j] + ".js");
                var mod = require( './' + libs[j] + ".js");
            }
        }
    }
}

_END
`;

mkdir -p "$2/$1"
mkdir -p "$2/deps/requirejs"
cp "deps/requirejs/"* "$2/deps/requirejs"
cp -r docs "$2/"
cp -r "$1/"* "$2/$1"
mkdir "$2/build"
cp build/arcs.*js "build/arcs_browser.js" "$2/build"

for i in  $DEPS; do
    echo "Copying $i"
    FILE="$2/"$i
    #echo "$FILE"
    mkdir -p "$FILE"
    rmdir "$FILE";
    cp "$i" "$FILE"
done 



done