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

Commit

Permalink
Merge pull request #140 from GoogleCloudPlatform/build/datalab-server…
Browse files Browse the repository at this point in the history
…-bash

Adds bash script for build/test of the DataLab NodeJS backend
  • Loading branch information
drewbryant committed Mar 11, 2015
2 parents 1142ef0 + 46b44ac commit 0ccf3b0
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 11 deletions.
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.
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

0 comments on commit 0ccf3b0

Please sign in to comment.