AngularJS Framework : angular-seed - the seed for AngularJS apps
angular-seed is an application skeleton for a typical AngularJS web app. By using it, we can quickly bootstrap our angular webapp projects and dev environment while seed app doesn't do much, and just demonstrates how to wire two controllers and views together.
A sample AngularJS application is included and it is pre-configured to install the Angular framework and other development and testing tools to help our instant web development.
If we want to run the preconfigured local web-server and the test tools, then we will also need Node.js v0.10.27+.
We can download a Node.js installer for our operating system from http://nodejs.org/download/
.Check the version of Node.js that we have installed by running the following command:
$ node --version
In Debian based distributions, there is a name clash with another utility called node. The suggested solution is to also install the nodejs-legacy apt package, which renames node to nodejs.
$ sudo apt-get install nodejs-legacy npm $ nodejs --version $ npm --version
If we just want to start a new project without the angular-seed commit history, then we can do:
$ git clone --depth=1 https://github.com/angular/angular-seed.git <our-project-name>
In our case, we'll use "seed" as our project name:
$ git clone --depth=1 https://github.com/angular/angular-seed.git seed $ cd seed
The depth=1 tells git to only pull down one commit worth of historical data.
We have two kinds of dependencies in this project: tools and angular framework code. The tools help us manage and test the application.
- We get the tools we depend upon via npm, the node package manager.
- We get the angular code via bower, a client-side code package manager.
We have pre-configured npm to automatically run bower so we can simply do:
$ npm install
Behind the scenes this will also call bower install. The bower is a package manager that helps us to find and install all our application dependencies, such as CSS frameworks, JavaScript libraries, and so on. It runs over git and avoids the need to manually download and update dependencies.
We should find that we have two new folders in our project.
- node_modules - contains the npm packages for the tools we need
- app/bower_components - contains the angular framework files
Note that the bower_components folder would normally be installed in the root folder but angular-seed changes this location through the .bowerrc file. Putting it in the app folder makes it easier to serve the files by a webserver.
We have preconfigured the project with a simple development web server. The simplest way to start this server is:
$ npm start ... > http-server -a localhost -p 8000 -c-1 Starting up http-server, serving ./ on port: 8000 Hit CTRL-C to stop the server
Now browse to the app at http://localhost:8000/app/index.html.
There are two kinds of tests in the angular-seed application: Unit tests and End to End tests.
The angular-seed app comes preconfigured with unit tests. These are written in Jasmine, which we run with the Karma Test Runner. A Karma configuration file is provided to run them.
- the configuration is found at karma.conf.js
- the unit tests are found next to the code they are testing and are named as ..._test.js.
The easiest way to run the unit tests is to use the supplied npm script:
$ npm test ... > angular-seed@0.0.0 test /home/k/TEST/Angular/seed > karma start karma.conf.js INFO [karma]: Karma v0.12.37 server started at http://localhost:9876/ INFO [launcher]: Starting browser Chrome INFO [Chrome 39.0.2171 (Linux 0.0.0)]: Connected on socket HCj0nzYQHyZ3OcYGOWrG with id 59847168 Chrome 39.0.2171 (Linux 0.0.0): Executed 5 of 5 SUCCESS (0.274 secs / 0.242 secs)
This script will start the Karma test runner to execute the unit tests. Moreover, Karma will sit and watch the source and test files for changes and then re-run the tests whenever any of them change. This is the recommended strategy; if our unit tests are being run every time we save a file then we receive instant feedback on any changes that break the expected code functionality.
The angular-seed app comes with end-to-end tests, again written in Jasmine. These tests are run with the Protractor End-to-End test runner. It uses native events and has special features for Angular applications.
- the configuration is found at e2e-tests/protractor-conf.js
- the end-to-end tests are found in e2e-tests/scenarios.js
Protractor simulates interaction with our web app and verifies that the application responds correctly. Therefore, our web server needs to be serving up the application, so that Protractor can interact with it.
$ npm test
In addition, since Protractor is built upon WebDriver we need to install this. The angular-seed project comes with a predefined script to do this:
$ npm run update-webdriver > angular-seed@0.0.0 preupdate-webdriver /home/k/TEST/Angular/seed > npm install > angular-seed@0.0.0 postinstall /home/k/TEST/Angular/seed > bower install > angular-seed@0.0.0 update-webdriver /home/k/TEST/Angular/seed > webdriver-manager update Updating selenium standalone downloading https://selenium-release.storage.googleapis.com/2.47/selenium-server-standalone-2.47.1.jar... Updating chromedriver downloading https://chromedriver.storage.googleapis.com/2.19/chromedriver_linux64.zip... chromedriver_2.19.zip downloaded to /home/k/TEST/Angular/seed/node_modules/protractor/selenium/chromedriver_2.19.zip selenium-server-standalone-2.47.1.jar downloaded to /home/k/TEST/Angular/seed/node_modules/protractor/selenium/selenium-server-standalone-2.47.1.jar
This will download and install the latest version of the stand-alone WebDriver tool.
Once we have ensured that the development web server hosting our application is up and running and WebDriver is updated, we can run the end-to-end tests using the supplied npm script:
$ npm run protractor
This script will execute the end-to-end tests against the application being hosted on the development server.
This test failed on my laptop (Ubuntu 14.04).
.. UnknownError: unknown error: Chrome version must be >= 43.0.2357.0 (Driver info: chromedriver=2.19.346067 (6abd8652f8bc7a1d825962003ac88ec6a37a82f1),platform=Linux 3.13.0-40-generic x86_64) (WARNING: The server did not provide any stacktrace information) ...
Current version:
$ google-chrome --version Google Chrome 39.0.2171.71
We need to upgrade Chrome:
$ sudo apt-get install google-chrome-stable ... Setting up google-chrome-stable (45.0.2454.101-1) ...
Now google-chrome has been updated:
$ google-chrome --version Google Chrome 45.0.2454.101
Even after restarting my laptop, there are some errors but do not know why.
npm start still runs fine, though.
Actually, based on angular-seed, I made a site Epic Math.
We need a web server (nginx) to run it in production.
Nginx is the server we want to run our app on, and we only need to edit /etc/nginx/sites-available/default:
#root /usr/share/nginx/html; root /home/ubuntu/epicmath/app;
That's the DocumentRoot. So, we need to git clone our repo:
$ git clone https://github.com/epic-math/epicmath.git
angular-seed - the seed for AngularJS apps
AngularJS
Ph.D. / Golden Gate Ave, San Francisco / Seoul National Univ / Carnegie Mellon / UC Berkeley / DevOps / Deep Learning / Visualization