Skip to content
This repository has been archived by the owner on Sep 3, 2022. It is now read-only.

Adds bash script for build/test of the DataLab NodeJS backend #140

Merged
merged 5 commits into from
Mar 11, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 76 additions & 0 deletions sources/server/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#!/bin/bash
set -o errexit; # Fail build on first error, instead of carrying on by default

if [ -z "$REPO_DIR" ];
then echo "REPO_DIR is not set. Please run source tools/initenv.sh first";
exit 1;
fi

### CONFIG
# Create all of the output paths
build_root="$REPO_DIR/build/server";
# TODO(bryantd): using an additonal directory '_' to offset the build path such that
# the hard-coded dependency paths (dictated by TypeScript module system currently) will
# line up with the source directory layout. Current issue is that the source code needs
# to be compiled in multiple locations, each of which must have the correct number of parent
# directories to the externs/ts typedefs. One workaround would be to symlink externs/ts
# to each build location and then change all import references to account for this.
#
# All of this trickery would be unnecessary if TypeScript supported a requirejs-style path config
# specification, but it does not at the moment.
#
# This module path config feature is being actively discussed within the TypeScript community, so
# opting to see how it plays out before implementing more complex work-arounds. For discussion,
# see: https://github.com/Microsoft/TypeScript/issues/293
staging_path="$build_root/staging/_";
test_path="$build_root/tests";
build_path="$build_root/build";

# Define the source path
server_root="$REPO_DIR/sources/server";

# TypeScript compiler args for both backend and frontend code
common_tsc_args="--removeComments --noImplicitAny";

mkdir -p "$staging_path" "$build_path" "$test_path";


### BUILD
echo 'Building DataLab server backend...';
# Copy node .ts files to staging.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this be simplified by referring to specific .ts files explictly instead of first copying them to a staging location and later removing them?

The typescript compiler accepts a build file (see the @<file> option) where you could list all the args and have an explicit list of files. Sort of like a build file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer to avoid maintaining an explicit build file list if possible for now as it doesn't resolve the need to fix up relative paths when building, and the dynamically generated file list via the find operation is fast.

We could write a script which generates this build file on-demand from the source tree if we end up needing something the build file buys us down the road (and don't want to maintain the file list manually).

cp -r "$server_root/src/node/" "$staging_path";
# Copy shared .ts files to the backend staging area.
cp -r "$server_root/src/shared" "$staging_path/app";
# Compile the typescript code in staging.
tsc_files=`find $staging_path -name '*.ts' | tr '\n' ' '`;
tsc $common_tsc_args --module commonjs $tsc_files;
# Copy everything from staging to build.
cp -r $staging_path/* $build_path;
# Remove the unneeded .ts files.
find "$build_path" -name '*.ts' | xargs rm;


### TEST
# TODO(bryantd): Find a way to avoid needing to rebuild the src/* .ts files when compiling tests
# Best solution likely involves generating the *.d.ts typedefs when building /src/* and correctly
# symlinking these built files to the test directory, before building the tests.
echo 'Testing DataLab server backend...';
# Copy node .ts files to test.
cp -r "$server_root/src/node" "$test_path";
# Copy shared .ts files to the test area.
cp -r "$server_root/src/shared" "$test_path/node/app";
# Copy the test .ts files to the test area.
cp -r "$server_root/tests/node/" "$test_path/node";
# Compile the typescript code in test area (src and tests).
tsc_files=`find $test_path/node -name '*.ts' | tr '\n' ' '`;
tsc $common_tsc_args --module commonjs $tsc_files;
# Install the npm dependencies
echo 'Installing NPM dependencies for running the unit tests'
pushd "$test_path/node";
# Install the source code dependencies
npm install .;
# Now run the tests via the jasmine-node runner
jasmine-node .;
popd;

echo 'Done!'
28 changes: 17 additions & 11 deletions tools/initonce.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,35 @@ fi
# Python Linter (http://www.pylint.org)
pip install pylint

# Node.js check
# Node.js check (DataLab server)
if which node >/dev/null; then
echo "NodeJS installed"
else
echo "Please install NodeJS 0.10.x: http://nodejs.org/download"
fi

# TypeScript compiler (DataLab server)
if which npm >/dev/null; then
npm install -g typescript
else
echo "Please install NodeJS and then re-run this script to install the TypeScript compiler."
fi

# Jasmine test runner (DataLab server)
if which npm >/dev/null; then
npm install -g jasmine-node
else
echo "Please install NodeJS and then re-run this script to install the Jasmine NodeJS test runner."
fi

# Gradle 2.0 check
if which gradle >/dev/null; then
if which gradle >/dev/null; then
gradle_version=`gradle -version | grep Gradle | cut -f2 -d' '`
gradle_major_version=`echo $gradle_version | cut -f1 -d.`
if [ "$gradle_major_version" != "2" ]; then
echo "Please install Gradle 2.x"
fi
echo "Found Gradle version '${gradle_version}'"
else
echo "Please install Gradle 2.0: http://www.gradle.org/downloads"
fi

# TypeScript compiler
if which npm >/dev/null; then
npm install -g typescript
else
echo "Please install NodeJS and then re-run this script to install the TypeScript compiler."
echo "Please install Gradle 2.0: http://www.gradle.org/downloads"
fi