This repository has been archived by the owner on Sep 3, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 249
Adds bash script for build/test of the DataLab NodeJS backend #140
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
8e15e36
Adds a build.sh script for building and testing the DataLab NodeJS ba…
drewbryant 2a80b1b
Added note about work-around for the lack of a requirejs-style paths …
drewbryant 0e950a7
Changed offset dir name from foo to _
drewbryant 64b09ae
Adds reference to the TypeScript path config discussion/planning for …
drewbryant 46b44ac
Added TODO note for avoiding the need to recompile src/* when buildin…
drewbryant File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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).