#!/bin/bash

# Bash script to lint the content of playgrounds
# Heavily based on RxSwift's
# https://github.com/ReactiveX/RxSwift/blob/master/scripts/validate-playgrounds.sh

if [ -z "$BUILD_DIRECTORY" ]; then
	echo "\$BUILD_DIRECTORY is not set. Are you trying to run \`validate-playgrounds.sh\` without building RAC first?\n"
	echo "To validate the playground, run \`script/build\`."
	exit 1
fi

if [ -z "$XCODE_PLAYGROUND_TARGET" ]; then
	echo "\$XCODE_PLAYGROUND_TARGET is not set."
	exit 1
fi

PAGES_PATH=${BUILD_DIRECTORY}/Build/Products/${CONFIGURATION}/all-playground-pages.swift

validate () {
	echo "Validating \$1..."
	cat $1/Sources/*.swift $1/Pages/**/*.swift > ${PAGES_PATH}
	swift -v -target ${XCODE_PLAYGROUND_TARGET} -D NOT_IN_PLAYGROUND -F ${BUILD_DIRECTORY}/Build/Products/${CONFIGURATION} ${PAGES_PATH} > /dev/null
result=$?
}

validate ReactiveSwift.playground
validate ReactiveSwift-UIExamples.playground

# Cleanup
rm -Rf $BUILD_DIRECTORY

exit $result

#!/bin/bash

# Bash script to lint the content of playgrounds
# Heavily based on RxSwift's
# https://github.com/ReactiveX/RxSwift/blob/master/scripts/validate-playgrounds.sh

if [ -z "$BUILD_DIRECTORY" ]; then
	echo "\$BUILD_DIRECTORY is not set. Are you trying to run \`validate-playgrounds.sh\` without building RAC first?\n"
	echo "To validate the playground, run \`script/build\`."
	exit 1
fi

if [ -z "$XCODE_PLAYGROUND_TARGET" ]; then
	echo "\$XCODE_PLAYGROUND_TARGET is not set."
	exit 1
fi

PAGES_PATH=${BUILD_DIRECTORY}/Build/Products/${CONFIGURATION}/all-playground-pages.swift

cat ReactiveSwift.playground/Sources/*.swift ReactiveSwift.playground/Pages/**/*.swift > ${PAGES_PATH}

swift -v -target ${XCODE_PLAYGROUND_TARGET} -D NOT_IN_PLAYGROUND -F ${BUILD_DIRECTORY}/Build/Products/${CONFIGURATION} ${PAGES_PATH} > /dev/null
result=$?

# Cleanup
rm -Rf $BUILD_DIRECTORY

exit $result

--- 
+++ 
@@ -17,15 +17,10 @@
 
 PAGES_PATH=${BUILD_DIRECTORY}/Build/Products/${CONFIGURATION}/all-playground-pages.swift
 
-validate () {
-	echo "Validating \$1..."
-	cat $1/Sources/*.swift $1/Pages/**/*.swift > ${PAGES_PATH}
-	swift -v -target ${XCODE_PLAYGROUND_TARGET} -D NOT_IN_PLAYGROUND -F ${BUILD_DIRECTORY}/Build/Products/${CONFIGURATION} ${PAGES_PATH} > /dev/null
+cat ReactiveSwift.playground/Sources/*.swift ReactiveSwift.playground/Pages/**/*.swift > ${PAGES_PATH}
+
+swift -v -target ${XCODE_PLAYGROUND_TARGET} -D NOT_IN_PLAYGROUND -F ${BUILD_DIRECTORY}/Build/Products/${CONFIGURATION} ${PAGES_PATH} > /dev/null
 result=$?
-}
-
-validate ReactiveSwift.playground
-validate ReactiveSwift-UIExamples.playground
 
 # Cleanup
 rm -Rf $BUILD_DIRECTORY
Update the CI playground validation script.