<commit_before>#!/bin/bash

PACKAGE_NAME=$( node -e 'console.log( require( "./package.json" ).name );' )

DISTONLY=""
BUILDONLY=""
TESTONLY=""
DEBUG=""

buildBroken() {
	echo "Repair build first."
	exit 1
}

DO_BUILD=TRUE
DO_TEST=TRUE
DO_DIST=TRUE
DO_DEVREINST=TRUE

while [[ $# -gt 0 ]]; do
	if test "x$1x" = "x--testonlyx" -o "x$1x" = "x-tx"; then
		TESTONLY="TRUE"
	elif test "x$1x" = "x--buildonlyx" -o "x$1x" = "x-bx"; then
		BUILDONLY="TRUE"
	elif test "x$1x" = "x--distonlyx" -o "x$1x" = "x-ix"; then
		DISTONLY="TRUE"
	elif test "x$1x" = "x--noreinstallx" -o "x$1x" = "x-nx"; then
		DO_DEVREINST="FALSE"
	elif test "x$1x" = "x--debugx" -o "x$1x" = "x-dx"; then
		DEBUG="--debug"
	elif test "x$1x" = "x--helpx" -o "x$1x" = "x-hx"; then
		echo "$( basename "$0" ) [options...]"
		echo ""
		echo "Possible options:"
		echo "--debug or -d       : Build in debug mode"
		echo "--testonly or -t    : Build for testing, run tests, and exit"
		echo "--buildonly or -b   : Build and exit"
		echo "--distonly or -i    : Build distributable tree and exit"
		echo "--noreinstall or -n : Do not reinstall dev dependencies after distribution"
		echo "--help or -h        : Print this message and exit"
		exit 0
	fi
	shift
done

if test "x${TESTONLY}x" = "xTRUEx"; then
	DO_BUILD=FALSE
	DO_TEST=TRUE
	DO_DIST=FALSE
fi

if test "x${BUILDONLY}x" = "xTRUEx"; then
	DO_BUILD=TRUE
	DO_TEST=FALSE
	DO_DIST=FALSE
fi

if test "x${DISTONLY}x" = "xTRUEx"; then
	DO_BUILD=FALSE
	DO_TEST=FALSE
	DO_DIST=TRUE
fi

if test "x${DEBUG}x" = "xx"; then
	MODULE_LOCATION="Release"
else
	MODULE_LOCATION="Debug"
fi

# We don't need build flags if we're just going to be copying files
if ! test "x${DO_DIST}x" = "xTRUEx" -a "x${DISTONLY}x" = "xTRUEx"; then

	# npm install needs these variables to be in place. If they're not, let's try to establish them
	# using pkg-config.
	if test "x${OCTBSTACK_CFLAGS}x" = "xx"; then
		export OCTBSTACK_CFLAGS=$( pkg-config --cflags octbstack )
	fi

	if test "x${OCTBSTACK_LIBS}x" = "xx"; then
		export OCTBSTACK_LIBS=$( pkg-config --libs octbstack )
	fi
fi

if test "x${DO_TEST}x" = "xTRUEx"; then
	echo "*** Performing test build/run ***"
	export TESTING=true

	if ! npm install ${DEBUG}; then
		buildBroken
	fi

	if ! npm test; then
		buildBroken
	fi

	unset TESTING
fi

if test "x${DO_DIST}x" = "xTRUEx"; then
	echo "*** Performing distribution ***"

	rm -rf dist &&
	mkdir -p dist/${PACKAGE_NAME} &&

	( if test "x${DISTONLY}x" != "xTRUEx"; then
		if ! npm install ${DEBUG}; then
			buildBroken
		fi
	fi; ) &&

	# Remove the devDependencies while keeping the production dependencies
	# https://github.com/npm/npm/issues/5590 is why prune needs to run twice
	npm prune --production &&
	npm prune --production &&
	cp -a AUTHORS.txt index.js lowlevel.js lib MIT-LICENSE.txt node_modules README.md dist/${PACKAGE_NAME} &&
	mkdir -p dist/${PACKAGE_NAME}/build/${MODULE_LOCATION} &&
	cp build/${MODULE_LOCATION}/iotivity.node dist/${PACKAGE_NAME}/build/${MODULE_LOCATION} &&
	if test -d deps; then
		mkdir -p dist/${PACKAGE_NAME}/deps/iotivity/lib
		cp deps/${PACKAGE_NAME}/lib/liboctbstack.so dist/${PACKAGE_NAME}/deps/iotivity/lib
	fi
	cd dist &&
	tar cvjf iotivity.tar.bz2 ${PACKAGE_NAME} &&
	cd ..

	if test "x${DO_DEVREINST}x" = "xTRUEx"; then

		# Restore devDependencies after having created the distribution package
		node -e 'Object.keys( require( "./package.json" ).devDependencies )
			.map( function( item ){ console.log( item ) } );' | xargs npm install
	fi
fi

if test "x${DO_BUILD}x" = "xTRUEx"; then
	echo "*** Performing build ***"<commit_msg>Build: Allow separate dev dependency reinstallation<commit_after>#!/bin/bash

PACKAGE_NAME=$( node -e 'console.log( require( "./package.json" ).name );' )

DISTONLY=""
BUILDONLY=""
TESTONLY=""
DEBUG=""
REINSTONLY=""

buildBroken() {
	echo "Repair build first."
	exit 1
}

DO_BUILD=TRUE
DO_TEST=TRUE
DO_DIST=TRUE
DO_DEVREINST=TRUE

while [[ $# -gt 0 ]]; do
	if test "x$1x" = "x--testonlyx" -o "x$1x" = "x-tx"; then
		TESTONLY="TRUE"
	elif test "x$1x" = "x--buildonlyx" -o "x$1x" = "x-bx"; then
		BUILDONLY="TRUE"
	elif test "x$1x" = "x--distonlyx" -o "x$1x" = "x-ix"; then
		DISTONLY="TRUE"
	elif test "x$1x" = "x--noreinstallx" -o "x$1x" = "x-nx"; then
		DO_DEVREINST="FALSE"
	elif test "x$1x" = "x--reinstallonlyx" -o "x$1x" = "x-rx"; then
		REINSTONLY="TRUE"
	elif test "x$1x" = "x--debugx" -o "x$1x" = "x-dx"; then
		DEBUG="--debug"
	elif test "x$1x" = "x--helpx" -o "x$1x" = "x-hx"; then
		echo "$( basename "$0" ) [options...]"
		echo ""
		echo "Possible options:"
		echo "--debug or -d         : Build in debug mode"
		echo "--testonly or -t      : Build for testing, run tests, and exit"
		echo "--buildonly or -b     : Build and exit"
		echo "--distonly or -i      : Build distributable tree and exit"
		echo "--noreinstall or -n   : Do not reinstall dev dependencies after distribution"
		echo "--reinstallonly or -r : Reinstall dev dependencies and exit"
		echo "--help or -h          : Print this message and exit"
		exit 0
	fi
	shift
done

if test "x${TESTONLY}x" = "xTRUEx"; then
	DO_BUILD=FALSE
	DO_TEST=TRUE
	DO_DIST=FALSE
	DO_DEVREINST=FALSE
fi

if test "x${BUILDONLY}x" = "xTRUEx"; then
	DO_BUILD=TRUE
	DO_TEST=FALSE
	DO_DIST=FALSE
	DO_DEVREINST=FALSE
fi

if test "x${DISTONLY}x" = "xTRUEx"; then
	DO_BUILD=FALSE
	DO_TEST=FALSE
	DO_DIST=TRUE
fi

if test "x${REINSTONLY}x" = "xTRUEx"; then
	DO_BUILD=FALSE
	DO_TEST=FALSE
	DO_DIST=FALSE
	DO_DEVREINST=TRUE
fi

if test "x${DEBUG}x" = "xx"; then
	MODULE_LOCATION="Release"
else
	MODULE_LOCATION="Debug"
fi

# We don't need build flags if we're just going to be copying files
if ! test "x${DO_DIST}x" = "xTRUEx" -a "x${DISTONLY}x" = "xTRUEx"; then

	# npm install needs these variables to be in place. If they're not, let's try to establish them
	# using pkg-config.
	if test "x${OCTBSTACK_CFLAGS}x" = "xx"; then
		export OCTBSTACK_CFLAGS=$( pkg-config --cflags octbstack )
	fi

	if test "x${OCTBSTACK_LIBS}x" = "xx"; then
		export OCTBSTACK_LIBS=$( pkg-config --libs octbstack )
	fi
fi

if test "x${DO_TEST}x" = "xTRUEx"; then
	echo "*** Performing test build/run ***"
	export TESTING=true

	if ! npm install ${DEBUG}; then
		buildBroken
	fi

	if ! npm test; then
		buildBroken
	fi

	unset TESTING
fi

if test "x${DO_DIST}x" = "xTRUEx"; then
	echo "*** Performing distribution ***"

	rm -rf dist &&
	mkdir -p dist/${PACKAGE_NAME} &&

	( if test "x${DISTONLY}x" != "xTRUEx"; then
		if ! npm install ${DEBUG}; then
			buildBroken
		fi
	fi; ) &&

	# Remove the devDependencies while keeping the production dependencies
	# https://github.com/npm/npm/issues/5590 is why prune needs to run twice
	npm prune --production &&
	npm prune --production &&
	cp -a AUTHORS.txt index.js lowlevel.js lib MIT-LICENSE.txt node_modules README.md dist/${PACKAGE_NAME} &&
	mkdir -p dist/${PACKAGE_NAME}/build/${MODULE_LOCATION} &&
	cp build/${MODULE_LOCATION}/iotivity.node dist/${PACKAGE_NAME}/build/${MODULE_LOCATION} &&
	if test -d deps; then
		mkdir -p dist/${PACKAGE_NAME}/deps/iotivity/lib
		cp deps/${PACKAGE_NAME}/lib/liboctbstack.so dist/${PACKAGE_NAME}/deps/iotivity/lib
	fi
	cd dist &&
	tar cvjf iotivity.tar.bz2 ${PACKAGE_NAME} &&
	cd ..
fi

if test "x${DO_DEVREINST}x" = "xTRUEx"; then
	echo "*** Re-installing development dependencies ***"

	# Restore devDependencies after having created the distribution package
	node -e 'Object.keys( require( "./package.json" ).devDependencies )
		.map( function( item ){ console.log( item ) } );' | xargs npm install
fi

if test "x${DO_BUILD}x" = "xTRUEx"; then
	echo "*** Performing build ***"
{'fraction_non_alphanumeric': 0.15696135521439916, 'fraction_numerical': 0.005823186871360508, 'mean_word_length': 3.785940468651045, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6547944', 'n_tokens_mistral': 3083, 'n_tokens_neox': 2919, 'n_words': 830}