Skip to content

Commit 5d2baf8

Browse files
chore(dependencies): remove inline dependencies (use npm & bower instead)
It is inefficient to store the angular libraries inside this repository. Moreover it is a pain to have to update them every time a new version of Angular is released. This commit changes the project to use bower to install the angular dependencies. In addition, simplify the structure of the project, all the support scripts have either been replaced with well-defined npm modules (e.g http-server) or have been moved to the package.json `script` property. This means that we can now do all the management of the project with three simple commands: * `npm start` - start the development web server to host the application * `npm test` - start the Karma test runner * `npm run-script protractor` - start the Protractor end-to-end test runner A nice feature of these scripts is that they run `npm install` first, thus ensuring that the necessary npm dependencies are in place. Also there is a `postinstall` script which runs `bower install` to ensure the angular library dependencies are in place and updates the index-async.html with the `angular-loader.min.js` content via the following sed script: ``` sed '/@@NG_LOADER@@/{ s/@@NG_LOADER@@//g r bower_components/angular-loader/angular-loader.min.js }' app/index-async.html.template > app/index-async.html ```
1 parent f84c292 commit 5d2baf8

File tree

292 files changed

+194
-84385
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

292 files changed

+194
-84385
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
logs/*
22
!.gitkeep
33
node_modules/
4+
bower_components/
45
tmp
56
.DS_Store
67
.idea

README.md

Lines changed: 139 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -4,35 +4,88 @@ This project is an application skeleton for a typical [AngularJS](http://angular
44
You can use it to quickly bootstrap your angular webapp projects and dev environment for these
55
projects.
66

7-
The seed contains AngularJS libraries, test libraries and a bunch of scripts all preconfigured for
8-
instant web development gratification. Just clone the repo (or download the zip/tarball), start up
9-
our (or your) webserver and you are ready to develop and test your application.
7+
The seed contains a sample AngularJS application and is preconfigured to install the Angular
8+
framework and a bunch of development and testing tools for instant web development gratification.
109

11-
The seed app doesn't do much, just shows how to wire two controllers and views together. You can
12-
check it out by opening app/index.html in your browser (might not work file `file://` scheme in
13-
certain browsers, see note below).
10+
The seed app doesn't do much, just shows how to wire two controllers and views together.
1411

15-
_Note: While angular is client-side-only technology and it's possible to create angular webapps that
16-
don't require a backend server at all, we recommend hosting the project files using a local
17-
webserver during development to avoid issues with security restrictions (sandbox) in browsers. The
18-
sandbox implementation varies between browsers, but quite often prevents things like cookies, xhr,
19-
etc to function properly when an html page is opened via `file://` scheme instead of `http://`._
2012

13+
## Getting Started
14+
15+
To get you started you can simply clone the angular-seed repository and run the preconfigured
16+
development web server...
17+
18+
### Clone angular-seed
19+
20+
Clone the angular-seed repository using [git][git]:
21+
22+
```
23+
git clone https://github.com/angular/angular-seed.git
24+
cd angular-seed
25+
```
26+
27+
### Run the Application
28+
29+
We have preconfigured the project with node.js to download the latest stable version
30+
of AngularJS and install a simple development web server. The simplest way to do this is:
31+
32+
```
33+
npm start
34+
```
35+
36+
Now browse to the app at `http://localhost:8080/app/index.html`.
2137

22-
## How to use angular-seed
2338

24-
Clone the angular-seed repository and start hacking...
39+
## The AngularJS Files
40+
41+
The AngularJS files are not stored inside the angular-seed project, we download them from the
42+
[bower][bower] repository. [Bower][bower] is a [node.js][node] utility for managing client-side web
43+
application dependencies. It is installed via npm.
44+
45+
**Running `npm start`, in the [Getting Started](#Getting-Started) section, automatically installed
46+
[bower][bower] locally for us. You may prefer to have [bower][bower] installed globally**:
47+
48+
```
49+
sudo npm install -g bower
50+
```
51+
52+
Once we have bower installed, we can use it to get the Angular framework dependencies we need:
53+
54+
```
55+
bower install
56+
```
57+
58+
Bower will download all the necessary dependencies into the `bower_components` folder. Again, this
59+
is done automatically for us when we run `npm start`.
60+
61+
## Serving the Application Files
62+
63+
While angular is client-side-only technology and it's possible to create angular webapps that
64+
don't require a backend server at all, we recommend serving the project files using a local
65+
webserver during development to avoid issues with security restrictions (sandbox) in browsers. The
66+
sandbox implementation varies between browsers, but quite often prevents things like cookies, xhr,
67+
etc to function properly when an html page is opened via `file://` scheme instead of `http://`.
2568

2669

2770
### Running the app during development
2871

29-
You can pick one of these options:
72+
The angular-seed project comes preconfigured with a local development webserver. It is a node.js
73+
tool called `http-server`. You can start this webserver with `npm start` but you may choose to
74+
install the tool globally:
75+
76+
```
77+
sudo npm install -g http-server
78+
```
79+
80+
Then you can start your own development web server to server static files, from a folder, by
81+
running:
3082

31-
* serve this repository with your webserver
32-
* install node.js and run `scripts/web-server.js`
83+
```
84+
http-server
85+
```
3386

34-
Then navigate your browser to `http://localhost:<port>/app/index.html` to see the app running in
35-
your browser.
87+
Alternatively, you can choose to configure your own webserver, such as apache or nginx. Just
88+
configure your server to serve the files under the `app/` directory.
3689

3790

3891
### Running the app in production
@@ -47,43 +100,84 @@ somewhere, where they can be accessed by browsers.
47100
If your Angular app is talking to the backend server via xhr or other means, you need to figure
48101
out what is the best way to host the static files to comply with the same origin policy if
49102
applicable. Usually this is done by hosting the files by the backend server or through
50-
reverse-proxying the backend server(s) and a webserver(s).
103+
reverse-proxying the backend server(s) and webserver(s).
104+
105+
106+
## Testing
51107

108+
There are two kinds of tests in the angular-seed application: Unit tests and End to End tests.
52109

53-
### Running unit tests
110+
### Running Unit Tests
54111

55112
We recommend using [jasmine](http://pivotal.github.com/jasmine/) and
56113
[Karma](http://karma-runner.github.io) for your unit tests/specs, but you are free
57114
to use whatever works for you.
58115

59-
Requires [node.js](http://nodejs.org/), Karma (`sudo npm install -g karma`) and a local
60-
or remote browser.
116+
The angular-seed app comes preconfigured with such tests and a Karma configuration file to run them.
117+
118+
* the configuration is found at `test/karma.conf.js`
119+
* the unit tests are found in `test/unit/`.
120+
121+
The easiest way to run the unit tests is to use the supplied npm script:
122+
123+
```
124+
npm test
125+
```
126+
127+
This script will ensure that the Karma dependencies are installed and then start the Karma test
128+
runner to execute the unit tests. Karma will then sit and watch the application and test files for
129+
changes and re-run the tests whenever any of them change.
130+
131+
The Karma Test Runner is a [node.js][node] tool. You may choose to install the CLI tool globally
132+
133+
```
134+
sudo npm install -g karma
135+
```
136+
137+
You can then start Karma directly, passing it the test configuration file:
138+
139+
```
140+
karma start test/karma.conf.js
141+
```
142+
143+
A browser will start and connect to the Karma server (Chrome is default browser, others can be
144+
captured by loading the same url as the one in Chrome or by changing the `test/karma.conf.js`
145+
file). Karma will then re-run the tests when there are changes to any of the source or test
146+
javascript files.
61147

62-
* start `scripts/test.sh` (on windows: `scripts\test.bat`)
63-
* a browser will start and connect to the Karma server (Chrome is default browser, others can be captured by loading the same url as the one in Chrome or by changing the `config/karma.conf.js` file)
64-
* to run or re-run tests just change any of your source or test javascript files
65148

66149

67150
### End to end testing
68151

69-
We recommend using [protractor](https://github.com/angular/protractor) for end-to-end tests. It
70-
uses native events and has special features for Angular applications.
152+
We recommend using [Protractor][protractor] for end-to-end tests. It uses native events and has
153+
special features for Angular applications.
154+
155+
* the configuration is found at `test/protractor-conf.js`
156+
* the end-to-end tests are found in `test/e2e/`
71157

72-
Requires a webserver, node.js + `./scripts/web-server.js` or your backend server that hosts the angular static files.
158+
Protractor simulates interaction with our web app and verifies that the application responds
159+
correctly. Therefore, our web server needs to be serving up the application, so that Protractor
160+
can interact with it.
161+
162+
Once you have ensured that the development web server hosting our application is up and running
163+
(probably `npm start`) you can run the end-to-end tests using the supplied npm script:
164+
165+
```
166+
npm run-script protractor
167+
```
168+
169+
This script will ensure that the dependencies (including the Selenium Web Driver component) are
170+
up to date and then execute the end-to-end tests against the application being hosted on the
171+
development server.
73172

74-
* create your end-to-end tests in `test/e2e/scenarios.js`
75-
* serve your project directory with your http/backend server or node.js + `scripts/web-server.js`
76-
* to run:
77-
* run the tests from console with [Protractor](https://github.com/angular/protractor) via
78-
`scripts/e2e-test.sh` (on windows: `scripts\e2e-test.bat`)
79173

80174
### Continuous Integration
81175

82176
CloudBees have provided a CI/deployment setup:
83177

84178
<a href="https://grandcentral.cloudbees.com/?CB_clickstart=https://raw.github.com/CloudBees-community/angular-js-clickstart/master/clickstart.json"><img src="https://d3ko533tu1ozfq.cloudfront.net/clickstart/deployInstantly.png"/></a>
85179

86-
If you run this, you will get a cloned version of this repo to start working on in a private git repo,
180+
If you run this, you will get a cloned version of this repo to start working on in a private git repo,
87181
along with a CI service (in Jenkins) hosted that will run unit and end to end tests in both Firefox and Chrome.
88182

89183
### Receiving updates from upstream
@@ -116,24 +210,12 @@ fetch the changes and merge them into your project with git.
116210
partial1.html
117211
partial2.html
118212

119-
config/karma.conf.js --> config file for running unit tests with Karma
120-
config/protractor-conf.js --> config file for running e2e tests with Protractor
121-
122-
scripts/ --> handy shell/js/ruby scripts
123-
e2e-test.sh --> runs end-to-end tests with Karma (*nix)
124-
e2e-test.bat --> runs end-to-end tests with Karma (windows)
125-
test.bat --> autotests unit tests with Karma (windows)
126-
test.sh --> autotests unit tests with Karma (*nix)
127-
web-server.js --> simple development webserver based on node.js
128-
129-
test/ --> test source files and libraries
130-
e2e/ -->
131-
scenarios.js --> end-to-end specs
132-
lib/
133-
angular/ --> angular testing libraries
134-
angular-mocks.js --> mocks that replace certain angular services in tests
135-
version.txt --> version file
136-
unit/ --> unit level specs/tests
213+
test/ --> test config and source files
214+
protractor-conf.js --> config file for running e2e tests with Protractor
215+
e2e/ --> end-to-end specs
216+
scenarios.js
217+
karma.conf.js --> config file for running unit tests with Karma
218+
unit/ --> unit level specs/tests
137219
controllersSpec.js --> specs for controllers
138220
directivessSpec.js --> specs for directives
139221
filtersSpec.js --> specs for filters
@@ -142,3 +224,8 @@ fetch the changes and merge them into your project with git.
142224
## Contact
143225

144226
For more information on AngularJS please check out http://angularjs.org/
227+
228+
[git]: http://git-scm.com/
229+
[bower]: http://bower.io
230+
[node]: http://nodejs.org
231+
[protractor]: https://github.com/angular/protractor

app/index-async.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@
3232

3333
// load all of the dependencies asynchronously.
3434
$script([
35-
'lib/angular/angular.js',
36-
'lib/angular/angular-route.js',
35+
'../bower_components/angular/angular.js',
36+
'../bower_components/angular-route/angular-route.js',
3737
'js/app.js',
3838
'js/services.js',
3939
'js/controllers.js',

app/index-async.html.template

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323

2424
// load all of the dependencies asynchronously.
2525
$script([
26-
'lib/angular/angular.js',
27-
'lib/angular/angular-route.js',
26+
'../bower_components/angular/angular.js',
27+
'../bower_components/angular-route/angular-route.js',
2828
'js/app.js',
2929
'js/services.js',
3030
'js/controllers.js',

app/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
<!-- In production use:
1919
<script src="//ajax.googleapis.com/ajax/libs/angularjs/x.x.x/angular.min.js"></script>
2020
-->
21-
<script src="lib/angular/angular.js"></script>
22-
<script src="lib/angular/angular-route.js"></script>
21+
<script src="../bower_components/angular/angular.js"></script>
22+
<script src="../bower_components/angular-route/angular-route.js"></script>
2323
<script src="js/app.js"></script>
2424
<script src="js/services.js"></script>
2525
<script src="js/controllers.js"></script>

0 commit comments

Comments
 (0)