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 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426
|
#!/bin/bash
set -e
. include.sh
export DT_BUILD=1
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
BASE_DIR="${SCRIPT_DIR}/.."
BUILD_DIR="${BASE_DIR}/built"
SYNC_BRANCH="master"
VERSION=$(grep " * @version " ${BASE_DIR}/js/DataTables.js | awk -F" " '{ print $3 }')
CMD=$1
SUBCMD=$2
DEBUG=""
if [ "$SUBCMD" = "debug" -o "$3" = "debug" ]; then
DEBUG=1
fi
function build_js {
echo_section "JS"
SRC_DIR="${BASE_DIR}/js"
OUT_DIR="${BUILD_DIR}/js"
OUT_FILE="${OUT_DIR}/jquery.dataTables.js"
OUT_MIN_FILE="${OUT_DIR}/jquery.dataTables.min.js"
if [ -d $OUT_DIR ]; then
rm -r $OUT_DIR
fi
mkdir $OUT_DIR
cd $SRC_DIR
OLD_IFS=$IFS
IFS='%'
cp DataTables.js DataTables.js.build
CODE=0
grep "_buildInclude('" DataTables.js.build > /dev/null || CODE=$?
while [ $CODE -eq 0 ]; do
REQUIRE=$(grep "_buildInclude('" DataTables.js.build | head -n 1)
SPACER=$(echo ${REQUIRE} | cut -d _ -f 1)
FILE=$(echo ${REQUIRE} | sed -e "s#^.*_buildInclude('##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 "_buildInclude('" DataTables.js.build > /dev/null || CODE=$?
done
mv DataTables.js.build $OUT_FILE
# JSHint
if [ -e $JSHINT ]; then
$JSHINT --config $SCRIPT_DIR/jshint.config $OUT_FILE
if [ $? -eq 0 ]; then
echo_msg "JSHint passed"
else
echo_error "JSHint failed"
fi
else
echo_error "JSHint not installed at $JSHINT - skipping"
fi
js_compress $OUT_FILE
#cp jquery.js $OUT_DIR
cp integration/* $OUT_DIR
# Compress the integration files
js_frameworks dataTables $OUT_DIR
IFS=$OLD_IFS
}
function build_css {
echo_section "CSS"
SRC_DIR="${BASE_DIR}/css"
OUT_DIR="${BUILD_DIR}/css"
if [ -d $OUT_DIR ]; then
rm -r $OUT_DIR
fi
mkdir $OUT_DIR
cd $SRC_DIR
for file in $(find $SRC_DIR -name "*.scss"); do
filename=$(basename $file .scss)
sass --scss --stop-on-error --style expanded $file > $OUT_DIR/$filename.css
css_compress $OUT_DIR/$filename.css
done
}
function build_images {
echo_section "Images"
SRC_DIR="${BASE_DIR}/images"
OUT_DIR="${BUILD_DIR}/images"
OUT_FILE="${OUT_DIR}/jquery.dataTables.css"
OUT_MIN_FILE="${OUT_DIR}/jquery.dataTables.min.css"
if [ -d $OUT_DIR ]; then
rm -r $OUT_DIR
fi
mkdir $OUT_DIR
cp $SRC_DIR/*.png $OUT_DIR
cp $SRC_DIR/*.ico $OUT_DIR
}
function build_examples {
echo_section "Examples"
SRC_DIR="${BASE_DIR}/examples"
OUT_DIR="${BUILD_DIR}/examples"
TEMPLATE_DIR="${BASE_DIR}/build/templates"
if [ -e $OUT_DIR ]; then
rm -Rf $OUT_DIR
fi
# Transform in place
cp -r $SRC_DIR $OUT_DIR
php ${BASE_DIR}/build/examples.php \
-o $OUT_DIR \
-u ${TEMPLATE_DIR}/example_index.html \
-t ${TEMPLATE_DIR}/example.html \
-c "demo:${OUT_DIR}/resources/demo.css" \
-j "demo:${OUT_DIR}/resources/demo.js" \
-c "syntax:${OUT_DIR}/resources/syntax/shCore.css" \
-j "syntax:${OUT_DIR}/resources/syntax/shCore.js" \
-m "${BUILD_DIR}/media" \
-l "js:jquery css:syntax css:demo js:syntax js:demo"
}
# Use the latest JS, CSS etc in the DataTables build repo
# Assumes that the files have already been built
function build_repo {
echo_section "Deploying to build repo"
update_build_repo
build_js
build_css
build_images
build_examples
cp $BUILD_DIR/js/* ${BUILD_DIR}/DataTables/media/js/
cp $BUILD_DIR/css/* ${BUILD_DIR}/DataTables/media/css/
cp -r $BUILD_DIR/images ${BUILD_DIR}/DataTables/media/
if [ -e ${BUILD_DIR}/DataTables/examples ]; then
rm -Rf ${BUILD_DIR}/DataTables/examples
fi
cp -r $BUILD_DIR/examples ${BUILD_DIR}/DataTables/examples
# Create the manifest files for the various package managers
build_descriptors
}
# Build the DataTables/DataTables distribution
function build_repo_sync {
echo_section "Syncing build repo to source repo"
update_build_repo
LAST_HASH=$(cat ${BUILD_DIR}/DataTables/.datatables-commit-sync)
# Get the commits between the latest commit that the build repo was synced
# to and the head
COMMITS=$(git log --format=format:%H --reverse ${LAST_HASH}..HEAD)
if [ "$COMMITS" = "" ]; then
echo_msg "Build repo up to date"
else
CHANGES=0
for HASH in $COMMITS; do
echo_msg "Checking if there are build changes resulting from commit $HASH"
git checkout $HASH
COMMIT_MESSAGE=$(git log -1 --format=format:%B $HASH)
build_repo
cd ${BUILD_DIR}/DataTables
# git appears to have a bug whereby --quiet doesn't work immediately
# after files have been generated. Running twice fixes
git diff --quiet --exit-code
git diff --quiet --exit-code
if [ $? -eq 1 ]; then
echo_msg "Committing changes"
echo $HASH > .datatables-commit-sync
git commit -a -m "$COMMIT_MESSAGE"
CHANGES=1
else
echo_msg "No build changes"
fi
cd - > /dev/null 2>&1
done
# Push latest changes up to origin
if [ $CHANGES -eq 1 ]; then
echo_msg "Pushing changes in build repo up to origin"
cd ${BUILD_DIR}/DataTables
git push --quiet origin $SYNC_BRANCH
cd - > /dev/null 2>&1
fi
fi
git checkout --quiet $SYNC_BRANCH
}
function build_descriptors {
echo_msg "Updating package descriptors"
for FILE in $(ls ${BASE_DIR}/descriptors); do
cat ${BASE_DIR}/descriptors/${FILE} | \
sed -e "s/\_VERSION\_/${VERSION}/g" > ${BUILD_DIR}/DataTables/${FILE}
done
}
function update_build_repo {
if [ ! -d "${BUILD_DIR}/DataTables" ]; then
echo_msg "Checking out DataTables/DataTables"
cd $BUILD_DIR
git clone https://github.com/DataTables/DataTables.git
cd - > /dev/null 2>&1
else
echo_msg "Pulling latest changes for build repo from origin"
fi
# This will throw away local changes in the build file...
# Don't change files in it!
cd $BUILD_DIR/DataTables
#git pull --quiet origin $SYNC_BRANCH
git checkout --quiet -f $SYNC_BRANCH
cd - > /dev/null 2>&1
}
function extensions_dirs {
if [ ! -d ${BASE_DIR}/extensions ]; then
mkdir ${BASE_DIR}/extensions
fi
if [ ! -d ${BUILD_DIR}/DataTables/extensions ]; then
mkdir ${BUILD_DIR}/DataTables/extensions
fi
}
function build_extension {
EXTENSION=$1
echo_section "Building DataTables extension $EXTENSION"
extensions_dirs
cd ${BASE_DIR}/extensions
if [ ! -d ${BASE_DIR}/extensions/${EXTENSION} ]; then
echo_msg "Cloning $EXTENSION from GitHub"
git clone git@github.com:DataTables/${EXTENSION}.git
#git clone https://github.com/DataTables/${EXTENSION}.git
fi
if [ -e ${BASE_DIR}/extensions/${EXTENSION}/make.sh ]; then
# If there is a make file, then leave it to the extension to do its own
# build and copy files into place
echo_msg "Running $EXTENSION build script"
bash ${BASE_DIR}/extensions/${EXTENSION}/make.sh \
${BUILD_DIR}/DataTables/extensions/${EXTENSION} $DEBUG
else
# Otherwise, just copy the whole lot over
echo_msg "Copying $EXTENSION files into place"
rsync -r ${BASE_DIR}/extensions/${EXTENSION} \
${BUILD_DIR}/DataTables/extensions
fi
}
function usage {
echo " Usage: make.sh <cmd> [debug]
where <cmd> is one of:
build - Create the build repo from the current source files. Will
automatically make the calls to to build the 'js' and 'css'
targets. The created repo is in 'built/DataTables'
js - Create the DataTables Javascript file
css - Create the DataTables CSS files
sync - Synchronise the DataTables/DataTables build repo to the source
repo
examples - Build the examples
test - Build the unit tests
all [debug] - Build DataTables core and all extensions
extension <ext> [debug] - Extension to build where <ext> is one of:
- AutoFill
- Buttons
- ColReorder
- FixedColumns
- FixedHeader
- KeyTable
- RowReorder
- Responsive
- Scroller
- Select
and the optional [debug] parameter can be used to disable JS and CSS
compression for faster development build times."
}
#
# Main script
#
cd $BASE_DIR
echo ""
echo_section "DataTables build ($VERSION) - branch: $SYNC_BRANCH"
echo ""
if [ ! -d $BUILD_DIR ]; then
mkdir $BUILD_DIR
fi
case "$1" in
"thirdparty")
# Update all third party libraries used for the DataTables distribution
#thirdparty_markdown()
;;
"build")
build_repo
;;
"all")
build_repo
build_extension AutoFill
build_extension Buttons
build_extension ColReorder
build_extension FixedColumns
build_extension FixedHeader
build_extension KeyTable
build_extension Responsive
build_extension RowGroup
build_extension RowReorder
build_extension Scroller
build_extension SearchPanes
build_extension Select
if [ -d ../extensions/Editor ]; then
build_extension Editor
fi
;;
"examples")
build_examples
;;
"test")
;;
"js")
build_js
;;
"css")
build_css
;;
"sync")
# Sanity check that the working branch is going to build correctly
# CURR_BRANCH="$(git rev-parse --abbrev-ref HEAD)"
# if [ $SYNC_BRANCH != $CURR_BRANCH ]; then
# echo_error "Working branch ($CURR_BRANCH) is not the same as the script branch ($SYNC_BRANCH)"
# echo_error "Exiting..."
# exit
# fi
build_repo_sync
;;
"extension")
build_extension $SUBCMD
;;
*)
usage
esac
unset DT_BUILD
echo ""
echo_section "Done"
echo ""
|