#!/bin/sh # # Copyright (C) 2010 Mike Gerwitz # # This file is part of ease.js. # # ease.js is free software: you can redistribute it and/or modify it under the # terms of the GNU Lesser General Public License as published by the Free # Software Foundation, either version 3 of the License, or (at your option) # any later version. # # This program is distributed in the hope that it will be useful, but WITHOUT # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License # for more details. # # You should have received a copy of the GNU Lesser General Public License # along with this program. If not, see . # # PATH_TOOLS=$( dirname "$0" ) PATH_LIB="$PATH_TOOLS/../lib" PATH_TEST="$PATH_TOOLS/../test" MODULE_EXT='js' TPL_PATH="$PATH_TOOLS/combine.tpl" TPL_TEST_PATH="$PATH_TOOLS/combine-test.tpl" TPL_VAR='/**{CONTENT}**/' RMTRAIL="$PATH_TOOLS/rmtrail" # order matters CAT_MODULES="prop_parser util member_builder class interface" ## # Output template header ## tpl_header() { # cut out the top of the template (before the content location) cat "$TPL_PATH" \ | awk "{ if ( \$0 == \"$TPL_VAR\" ) exit; else print \$0; }" } ## # Output template footer ## tpl_footer() { # cut out the bottom of the template (after where we need to place the # content) cat "$TPL_PATH" \ | awk "BEGIN { go = 0 } { if ( \$0 == \"$TPL_VAR\" ) go = 1 else if ( go == 1 ) print \$0; }" } # ensure we can locate our template (should be in the /tools dir) if [ ! -f "$TPL_PATH" ]; then echo "Error: combine.tpl not found ($TPL_PATH)" exit 1 fi # output combined file header tpl_header # output each of the modules for module in $CAT_MODULES; do filename="$PATH_LIB/$module.$MODULE_EXT" if [ ! -f "$filename" ]; then echo "Error: module $module not found ($filename)" exit 2 fi # each module must be enclosed in a closure to emulate a module echo "/** $module **/" echo "( function( module )" echo "{" echo " var exports = module.exports = {};" # add the module, removing trailing commas cat $filename | $RMTRAIL echo "} )( module['$module'] = {} );" done # include tests? if [ "$INC_TEST" ]; then # note that not all tests are included TEST_CASES=$( find $PATH_TEST \ \( -name 'test-*.js' \ -o -name 'inc-*.js' \ \) \ -exec basename {} \; \ | sort \ | grep -v 'test-\(combine\|index\).js' \ ) # include test combine template cat "$TPL_TEST_PATH" | grep -v '^#' | $RMTRAIL echo "/** TEST CASES **/" echo "ns_exports.runTests = function()" echo "{" for testcase in $TEST_CASES; do filename="$PATH_TEST/$testcase" # generate the module name by removing path and extension, then # prefixing it with "test/" module="${filename%.*}" module="test/${module##*/}" # each module must be enclosed in a closure to emulate a module echo "/** TEST CASE: $testcase **/" echo "( function( module, __dirname )" echo "{" echo " var exports = module.exports = {};" # write out current test to make debugging easier in browsers with very # little debugging support echo " document.write( '$module...
' )" # add the module, removing trailing commas cat $filename | $RMTRAIL echo "} )( module['$module'] = {}, 'test' );" done echo "};" fi # output combined file footer tpl_footer exit 0