ProgramiCo
JavaScript Web Application Development
  • Home
  • SmartJs
    • Setting up the Environment
    • Running SmartJs
  • SmartJs Blog
  • About

Run SmartJs

Running SmartJs always follows the same flow

  1. Launch the Mongo database.  You can use /database/launchDatabase.bat on Windows.  The SmartJs project just launches it as a console window but you can configure it to run as a service
  2. Launch the Now webserver.  You can use /server/launchWebserver.bat on Windows.  The SmartJs project just launches it as a console window but you can configure it to run as a service
  3. Open a web browser onto the client.  Default is to have an Apache site listening on port 97 pointed at /client so that would mean that /client/index.html resolves to http://localhost:97
  4. Open a F12 developer tools in your web browser for Js debugging
  5. Console messages are printed in the clientside developer tools and in the serverside Nowjs console window
  6. You can open multiple copies of the client, use ?config=test to override the default config and allow multiple users to be created on the same computer
  7. If you've made changes to the Client, you can just refresh your web browser.
  8. If you've changed the server code, hit CTRL+C in the Webserver console window to quit the batch file and then execute it again to pick up your code changes.
  9. You shouldn't need to restart your mongo window, but you can use CTRL+C to exit that window's process also.
Picture

Running the Unit Tests

When running the Unit Tests, you need to set up a QA website that points to the SmartJs project root.  That way the test files can find the test target files in the client folder in-place, without having to make copies of them.

  1. Set up your workstation according to the setup instructions
  2. Browse to the index of the unit tests in the qa folder in the website pointed at the SmartJs project root.  The default setup is for that to be on port 100.  So the unit test index would be: http://localhost:100/qa/unitTest/index.html
  3. Click each link to run the tests for each module

Building with r.js

The /qa/builds folder of SmartJs contains 2 r.js build scripts for each platform.  There are separate scripts for prod and non-prod, which could be built out into a more comprehensive matrix of environments and configurations.  These scripts use a naming convention to connect them to a set of subfolders under /qa/builds and the names also correspond to the configurations available in /client/app/config.js.  The config.js module will  pick up variables set by the build script to dynamically generate the correct config and environment as specified in the build script.

The Android build outputs its built main.js to a deeper subfolder under /qa/builds/android/assets/www/app.  That is because the /qa/builds/android folder is a complete Android project that is ready to deploy using the steps in the Cordova Getting Started for Android.  The getting started guide's original hello world content is preserved in SmartJs under /qa/builds/android/_helloWorld. 

There is also a build.debug.js script included which does all of the work to combine the application modules into one js file.  But the uglification is turned off so that the source is intact.  This proved to be very useful in debugging builds.  We can generate a build targeted to a device, but still get the benefit of meaningful function names when console logging for debug.

To allow me to easily run any build, I have included compileJs.bat which takes a command line parameter of the build name to run.  It is just a simple way to run r.js without having to remember the command line switches I need.
Powered by Create your own unique website with customizable templates.