|
| 1 | +## Build System |
| 2 | + |
| 3 | +Our project uses [gulp](http://gulpjs.com/) to: |
| 4 | + |
| 5 | +- combine all individual modules into a single file |
| 6 | +- transpile ES6 code to ES5 with [babel.js](http://babeljs.io/) |
| 7 | +- minimize JS and CSS code |
| 8 | +- generate source maps |
| 9 | +- add vendor prefixer to the css |
| 10 | +- provide a server with live-reload |
| 11 | + |
| 12 | +## Installation |
| 13 | + |
| 14 | +```bash |
| 15 | +# install gulp globally so you can run it from the command line |
| 16 | +npm install -g gulp-cli |
| 17 | + |
| 18 | +# install all dependencies |
| 19 | +npm install |
| 20 | + |
| 21 | +# run gulp to start the livereload server on http://localhost:8080 |
| 22 | +gulp |
| 23 | +``` |
| 24 | + |
| 25 | +**NOTE**: For Node.js versions below 0.12, you need to install an ES6-style Promise Polyfill (in case you receive a "Promise is undefined" error). To run with Promise, use: |
| 26 | + |
| 27 | +```bash |
| 28 | +npm install es6-promise |
| 29 | +``` |
| 30 | + |
| 31 | +Then add the following line at the top of your *gulpfile.babel.js*: |
| 32 | + |
| 33 | +```javascript |
| 34 | +var Promise = require ('es6-promise').Promise; |
| 35 | +``` |
| 36 | +Check out [stackoverflow](http://stackoverflow.com/questions/32490328/gulp-autoprefixer-throwing-referenceerror-promise-is-not-defined) for more details on this issue. |
| 37 | + |
| 38 | +To check your Node.js version, use: |
| 39 | + |
| 40 | +```bash |
| 41 | +node --version |
| 42 | +``` |
| 43 | + |
| 44 | +## Code Structure |
| 45 | + |
| 46 | +*Note:* Although no linter is added as of yet, the code closely follows the conventions from [Airbnb's ECMAScript 6 Javascript style guide](https://github.com/airbnb/javascript) |
| 47 | + |
| 48 | +### [js/index.js](https://github.com/parkjs814/AlgorithmVisualizer/blob/master/js/index.js) |
| 49 | + |
| 50 | +The app entry point is [`js/index.js`](https://github.com/parkjs814/AlgorithmVisualizer/blob/master/js/index.js). |
| 51 | +It performs the initial application setup (loads the app when jQuery loads, loads the initial data from the server etc.) |
| 52 | + |
| 53 | +### [js/app/*.js](https://github.com/parkjs814/AlgorithmVisualizer/tree/master/js/app) |
| 54 | + |
| 55 | +The main application object is [`js/app/index.js`](https://github.com/parkjs814/AlgorithmVisualizer/blob/master/js/app/index.js), which holds the necessary global application state flags and application level methods. |
| 56 | +It is [extended once the app loads in `index.js`](https://github.com/parkjs814/AlgorithmVisualizer/blob/master/js/index.js#L39) with the contents of [`app/constructor`](https://github.com/parkjs814/AlgorithmVisualizer/blob/master/js/app/constructor.js) and [`app/cache`](https://github.com/parkjs814/AlgorithmVisualizer/blob/master/js/app/cache.js). |
| 57 | +This means that from here on now, any file that does `require(/* path to js/app */)` is getting that populated object since calls to `require` are cached. |
| 58 | + |
| 59 | +### [js/dom/*.js](https://github.com/parkjs814/AlgorithmVisualizer/tree/master/js/dom) |
| 60 | + |
| 61 | +The `js/dom` directory holds all the code interacting with the DOM (go figure 😜). |
| 62 | +The code is split into: |
| 63 | + |
| 64 | +- "static" methods that are used everywhere (such as adding algorithm info to the DOM) and, |
| 65 | +- setup code which is called within the `app/constructor`, after the DOM is ready, to initialize all the elements with their contents and listeners. |
| 66 | + |
| 67 | +### [js/editor/*.js](https://github.com/parkjs814/AlgorithmVisualizer/tree/master/js/editor) |
| 68 | + |
| 69 | +The `js/editor` directory holds the code to create and execute code in the ace editor. |
| 70 | + |
| 71 | +### [js/module/\*/\*.js](https://github.com/parkjs814/AlgorithmVisualizer/tree/master/js/module) |
| 72 | + |
| 73 | +The `js/module` directory holds all the tracers and the random-data-creators. |
| 74 | +All the modules are exported together and then "required" inside the entry point [`js/index.js`](https://github.com/parkjs814/AlgorithmVisualizer/blob/master/js/index.js) where they are [attached to the global `window` object](https://github.com/parkjs814/AlgorithmVisualizer/blob/master/js/index.js#L42) so [`eval` can use them](https://github.com/parkjs814/AlgorithmVisualizer/blob/master/js/editor/executor.js#L12) when executing code in the code editor. |
| 75 | + |
| 76 | +### [js/server/*.js](https://github.com/parkjs814/AlgorithmVisualizer/tree/master/js/server) |
| 77 | + |
| 78 | +The `js/server` directory holds all the code to load data from the server and utilizes promises from [RSVP.js](https://github.com/tildeio/rsvp.js/). |
| 79 | +In [`js/server/ajax`](https://github.com/parkjs814/AlgorithmVisualizer/tree/master/js/server/ajax) are some helper methods to make requesting from the server a little easier. |
| 80 | +The main method is [`js/server/ajax/request.js`](https://github.com/parkjs814/AlgorithmVisualizer/blob/master/js/server/ajax/request.js) that is used by all other methods to call `$.ajax` with certain options and set/reset the global `isLoading` flag for every request. |
| 81 | + |
| 82 | +### [js/trace_manager/*.js](https://github.com/parkjs814/AlgorithmVisualizer/tree/master/js/server/ajax) |
| 83 | + |
| 84 | +The `js/tracer_manager` directory holds the manager of tracers, which controls all the present tracers simultaneously. |
| 85 | + |
| 86 | +### [js/utils/*.js](https://github.com/parkjs814/AlgorithmVisualizer/tree/master/js/utils) |
| 87 | + |
| 88 | +The `utils` directory holds a few helper methods that are used everywhere such as building the strings for algorithm and file directories. |
0 commit comments