make.sh 3.74 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
#!/bin/sh

cd ../media/src

# DEFAULTS
CLOSURE="/usr/local/closure_compiler/compiler.jar"
JSDOC="/usr/local/jsdoc/jsdoc"
CMD=$1

MAIN_FILE="../js/jquery.dataTables.js"
MIN_FILE="../js/jquery.dataTables.min.js"
VERSION=$(grep " * @version     " DataTables.js | awk -F" " '{ print $3 }')

echo ""
echo "  DataTables build ($VERSION)"
echo ""


IFS='%'

cp DataTables.js DataTables.js.build

echo "  Building main script"
grep "require(" DataTables.js.build > /dev/null
while [ $? -eq 0 ]; do
	REQUIRE=$(grep "require(" DataTables.js.build | head -n 1)

	SPACER=$(echo ${REQUIRE} | cut -d r -f 1)
	FILE=$(echo ${REQUIRE} | sed -e "s#^.*require('##g" -e "s#');##")
	DIR=$(echo ${FILE} | cut -d \. -f 1)

	sed "s#^#${SPACER}#" < ${DIR}/${FILE} > ${DIR}/${FILE}.build

	sed -e "/${REQUIRE}/r ${DIR}/${FILE}.build" -e "/${REQUIRE}/d" < DataTables.js.build > DataTables.js.out
	mv DataTables.js.out DataTables.js.build

	rm ${DIR}/${FILE}.build

	grep "require(" DataTables.js.build > /dev/null
done

mv DataTables.js.build $MAIN_FILE


if [ "$CMD" != "debug" ]; then
	if [ "$CMD" = "jshint" -o "$CMD" = "" -o "$CMD" = "cdn" ]; then
		echo "  JSHint"
		jshint $MAIN_FILE --config ../../scripts/jshint.config
		if [ $? -ne 0 ]; then
			echo "    Errors occured - exiting"
			exit 1
		else
			echo "    Pass" 
		fi
	fi

	if [ "$CMD" = "compress" -o "$CMD" = "" -o "$CMD" = "cdn" ]; then
		echo "  Minification"
		echo "/*
 * File:        jquery.dataTables.min.js
 * Version:     $VERSION
 * Author:      Allan Jardine (www.sprymedia.co.uk)
 * Info:        www.datatables.net
 * 
 * Copyright 2008-2012 Allan Jardine, all rights reserved.
 *
 * This source file is free software, under either the GPL v2 license or a
 * BSD style license, available at:
 *   http://datatables.net/license_gpl2
 *   http://datatables.net/license_bsd
 * 
 * This source file 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 license files for details.
 */" > $MIN_FILE 

		java -jar $CLOSURE --js $MAIN_FILE >> $MIN_FILE
		echo "    Min JS file size: $(ls -l $MIN_FILE | awk -F" " '{ print $5 }')"
	fi

	if [ "$CMD" = "docs" -o "$CMD" = "" ]; then
		echo "  Documentation"
		$JSDOC -d ../../docs -t JSDoc-DataTables $MAIN_FILE
	fi

	if [ "$CMD" = "cdn" ]; then
		echo "  CDN"
		if [ -d ../../cdn ]; then
			rm -Rf ../../cdn
		fi
		mkdir ../../cdn
		mkdir ../../cdn/css
		cp $MAIN_FILE ../../cdn
		cp $MIN_FILE ../../cdn
		cp ../css/jquery.dataTables.css ../../cdn/css
		cp ../css/jquery.dataTables_themeroller.css ../../cdn/css
		cp -r ../images ../../cdn/
		rm ../../cdn/images/Sorting\ icons.psd
	fi
fi


# Back to DataTables root dir
cd ../..

#
# Packaging files
#
cat <<EOF > package.json
{
	"name": "DataTables",
	"version": "${VERSION}",
	"title": "DataTables",
	"author": {
		"name": "Allan Jardine",
		"url": "http://sprymedia.co.uk"
	},
	"licenses": [
		{
			"type": "BSD",
			"url": "http://datatables.net/license_bsd"
		},
		{
			"type": "GPLv2",
			"url": "http://datatables.net/license_gpl2"
		}
	],
	"dependencies": {
		"jquery": "1.4 - 1.8"
	},
	"description": "DataTables enhances HTML tables with the ability to sort, filter and page the data in the table very easily. It provides a comprehensive API and set of configuration options, allowing you to consume data from virtually any data source.",
	"keywords": [
		"DataTables",
		"DataTable",
		"table",
		"grid",
		"filter",
		"sort",
		"page",
		"internationalisable"
	],
	"homepage": "http://datatables.net"
}
EOF

cat <<EOF > component.json
{
	"name": "DataTables",
	"version": "${VERSION}",
	"main": [
		"./media/js/jquery.dataTables.js",
		"./media/css/jquery.dataTables.css",
	],
	"dependencies": {
		"jquery": "~1.8.0"
	}
}
EOF


echo "  Done\n"