Skip to content

Commit d0e7594

Browse files
filipesilvaFoxandxss
authored andcommitted
chore: add src folder (angular#362)
* chore: add src folder * incorporate Jesus's feedback * move tsconfig.json into src/e2e * add base href * ignore debug.log * remove unused npm script * some protractor changes * remove appSrcBase * explicitely list config for npm run serve * add update instructions * Add third party deps note to update section
1 parent 182d81a commit d0e7594

20 files changed

+105
-44
lines changed

.gitignore

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
.idea
22
node_modules
33
jspm_packages
4-
npm-debug.*
5-
link-checker-results.txt
6-
app/**/*.js
4+
npm-debug.log
5+
debug.log
6+
src/**/*.js
7+
!src/systemjs.config.extras.js
8+
!src/systemjs.config.js
79
*.js.map
810
e2e/**/*.js
911
e2e/**/*.js.map

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ install:
1616
- npm install
1717
script:
1818
- npm run lint
19-
- npm run test-once
19+
- npm run test:once
2020
- npm run e2e

README.md

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,24 @@ It exists primarily to get you started quickly with learning and prototyping in
1212
We are unlikely to accept suggestions about how to grow this QuickStart into something it is not.
1313
Please keep that in mind before posting issues and PRs.
1414

15+
## Updating to a newer version of the Quickstart Repo
16+
17+
From time to time the QuickStart will add be enhanced with support for new features or to reflect
18+
changes to the [official Style Guide](https://angular.io/docs/ts/latest/guide/style-guide.html).
19+
20+
You can update your existing project to an up-to-date QuickStart by following these instructions:
21+
- Create a new project using the [instructions below](#create-a-new-project-based-on-the-quickstart)
22+
- Copy the code you have in your project's `main.ts` file onto `src/app/main.ts` in the new project
23+
- Copy your old `app` folder into `src/app`
24+
- Delete `src/app/main.ts` if you have one (we now use `src/main.ts` instead)
25+
- Copy your old `index.html`, `styles.css` and `tsconfig.json` into `src/`
26+
- Install all your third party dependencies
27+
- Copy your old `e2e/` folder into `e2e/`
28+
- Copy over any other files you added to your project
29+
- Copy your old `.git` folder into your new project's root
30+
31+
Now you can continue working on the new project.
32+
1533
## Prerequisites
1634

1735
Node.js and npm are essential to Angular development.
@@ -106,16 +124,16 @@ You're ready to write your application.
106124
We've captured many of the most useful commands in npm scripts defined in the `package.json`:
107125
108126
* `npm start` - runs the compiler and a server at the same time, both in "watch mode".
109-
* `npm run tsc` - runs the TypeScript compiler once.
110-
* `npm run tsc:w` - runs the TypeScript compiler in watch mode; the process keeps running, awaiting changes to TypeScript files and re-compiling when it sees them.
111-
* `npm run lite` - runs the [lite-server](https://www.npmjs.com/package/lite-server), a light-weight, static file server, written and maintained by
127+
* `npm run build` - runs the TypeScript compiler once.
128+
* `npm run build:w` - runs the TypeScript compiler in watch mode; the process keeps running, awaiting changes to TypeScript files and re-compiling when it sees them.
129+
* `npm run serve` - runs the [lite-server](https://www.npmjs.com/package/lite-server), a light-weight, static file server, written and maintained by
112130
[John Papa](https://github.com/johnpapa) and
113131
[Christopher Martin](https://github.com/cgmartin)
114132
with excellent support for Angular apps that use routing.
115133
116134
Here are the test related scripts:
117135
* `npm test` - compiles, runs and watches the karma unit tests
118-
* `npm run e2e` - run protractor e2e tests, written in JavaScript (*e2e-spec.js)
136+
* `npm run e2e` - compiles and run protractor e2e tests, written in Typescript (*e2e-spec.ts)
119137
120138
## Testing
121139
@@ -128,9 +146,9 @@ These tools are configured for specific conventions described below.
128146
We recommend that you shut down one before starting another.*
129147
130148
### Unit Tests
131-
TypeScript unit-tests are usually in the `app` folder. Their filenames must end in `.spec`.
149+
TypeScript unit-tests are usually in the `src/app` folder. Their filenames must end in `.spec.ts`.
132150
133-
Look for the example `app/app.component.spec.ts`.
151+
Look for the example `src/app/app.component.spec.ts`.
134152
Add more `.spec.ts` files as you wish; we configured karma to find them.
135153
136154
Run it with `npm test`
@@ -147,17 +165,17 @@ restart it. No worries; it's pretty quick.
147165
148166
### End-to-end (E2E) Tests
149167
150-
E2E tests are in the `e2e` directory, side by side with the `app` folder.
168+
E2E tests are in the `e2e` directory, side by side with the `src` folder.
151169
Their filenames must end in `.e2e-spec.ts`.
152170
153171
Look for the example `e2e/app.e2e-spec.ts`.
154172
Add more `.e2e-spec.js` files as you wish (although one usually suffices for small projects);
155-
we configured protractor to find them.
173+
we configured Protractor to find them.
156174
157175
Thereafter, run them with `npm run e2e`.
158176
159-
That command first compiles, then simultaneously starts the Http-Server at `localhost:8080`
160-
and launches protractor.
177+
That command first compiles, then simultaneously starts the `lite-server` at `localhost:8080`
178+
and launches Protractor.
161179
162180
The pass/fail test results appear at the bottom of the terminal window.
163181
A custom reporter (see `protractor.config.js`) generates a `./_test-output/protractor-results.txt` file

bs-config.e2e.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"open": false,
3+
"logLevel": "silent",
4+
"port": 8080,
5+
"server": {
6+
"baseDir": "src",
7+
"routes": {
8+
"/node_modules": "node_modules"
9+
},
10+
"middleware": {
11+
"0": null
12+
}
13+
}
14+
}

bs-config.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"server": {
3+
"baseDir": "src",
4+
"routes": {
5+
"/node_modules": "node_modules"
6+
}
7+
}
8+
}
File renamed without changes.

karma-test-shim.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ Error.stackTraceLimit = 0; // "No stacktrace"" is usually best for app testing.
77
jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000;
88

99
// builtPaths: root paths for output ("built") files
10-
// get from karma.config.js, then prefix with '/base/' (default is 'app/')
11-
var builtPaths = (__karma__.config.builtPaths || ['app/'])
10+
// get from karma.config.js, then prefix with '/base/' (default is 'src/')
11+
var builtPaths = (__karma__.config.builtPaths || ['src/'])
1212
.map(function(p) { return '/base/'+p;});
1313

1414
__karma__.loaded = function () { };
@@ -34,7 +34,8 @@ var allSpecFiles = Object.keys(window.__karma__.files)
3434
.filter(isBuiltFile);
3535

3636
System.config({
37-
baseURL: 'base',
37+
// Base URL for System.js calls. 'base/' is where Karma serves files from.
38+
baseURL: 'base/src',
3839
// Extend usual application package list with test folder
3940
packages: { 'testing': { main: 'index.js', defaultExtension: 'js' } },
4041

karma.conf.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
module.exports = function(config) {
22

3-
var appBase = 'app/'; // transpiled app JS and map files
4-
var appSrcBase = 'app/'; // app source TS files
5-
var appAssets = '/base/app/'; // component assets fetched by Angular's compiler
3+
var appBase = 'src/'; // transpiled app JS and map files
4+
var appSrcBase = appBase; // app source TS files
65

76
// Testing helpers (optional) are conventionally in a folder called `testing`
87
var testingBase = 'testing/'; // transpiled test JS and map files
@@ -57,8 +56,8 @@ module.exports = function(config) {
5756
{ pattern: 'node_modules/@angular/**/*.js', included: false, watched: false },
5857
{ pattern: 'node_modules/@angular/**/*.js.map', included: false, watched: false },
5958

60-
{ pattern: 'systemjs.config.js', included: false, watched: false },
61-
{ pattern: 'systemjs.config.extras.js', included: false, watched: false },
59+
{ pattern: appBase + '/systemjs.config.js', included: false, watched: false },
60+
{ pattern: appBase + '/systemjs.config.extras.js', included: false, watched: false },
6261
'karma-test-shim.js', // optionally extend SystemJS mapping e.g., with barrels
6362

6463
// transpiled application & spec code paths loaded via module imports
@@ -72,16 +71,16 @@ module.exports = function(config) {
7271
{ pattern: appBase + '**/*.css', included: false, watched: true },
7372

7473
// Paths for debugging with source maps in dev tools
75-
{ pattern: appSrcBase + '**/*.ts', included: false, watched: false },
74+
{ pattern: appBase + '**/*.ts', included: false, watched: false },
7675
{ pattern: appBase + '**/*.js.map', included: false, watched: false },
7776
{ pattern: testingSrcBase + '**/*.ts', included: false, watched: false },
7877
{ pattern: testingBase + '**/*.js.map', included: false, watched: false}
7978
],
8079

8180
// Proxied base paths for loading assets
8281
proxies: {
83-
// required for component assets fetched by Angular's compiler
84-
"/app/": appAssets
82+
// required for modules fetched by SystemJS
83+
'/base/src/node_modules/': '/base/node_modules/'
8584
},
8685

8786
exclude: [],

package.json

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,22 @@
33
"version": "1.0.0",
44
"description": "QuickStart package.json from the documentation, supplemented with testing support",
55
"scripts": {
6-
"start": "tsc && concurrently \"tsc -w\" \"lite-server\" ",
7-
"e2e": "tsc && concurrently \"http-server -s\" \"protractor protractor.config.js\" --kill-others --success first",
8-
"lint": "tslint ./app/**/*.ts -t verbose",
9-
"lite": "lite-server",
10-
"pree2e": "webdriver-manager update",
11-
"test": "tsc && concurrently \"tsc -w\" \"karma start karma.conf.js\"",
12-
"test-once": "tsc && karma start karma.conf.js --single-run",
13-
"tsc": "tsc",
14-
"tsc:w": "tsc -w"
6+
"build": "tsc -p src/",
7+
"build:watch": "tsc -p src/ -w",
8+
"build:e2e": "tsc -p e2e/",
9+
"serve": "lite-server -c=bs-config.json",
10+
"serve:e2e": "lite-server -c=bs-config.e2e.json",
11+
"prestart": "npm run build",
12+
"start": "concurrently \"npm run build:watch\" \"npm run serve\"",
13+
"pree2e": "npm run build:e2e",
14+
"e2e": "concurrently \"npm run serve:e2e\" \"npm run protractor\" --kill-others --success first",
15+
"preprotractor": "webdriver-manager update",
16+
"protractor": "protractor protractor.config.js",
17+
"pretest": "npm run build",
18+
"test": "concurrently \"npm run build:watch\" \"karma start karma.conf.js\"",
19+
"pretest:once": "npm run build",
20+
"test:once": "karma start karma.conf.js --single-run",
21+
"lint": "tslint ./src/**/*.ts -t verbose"
1522
},
1623
"keywords": [],
1724
"author": "",
@@ -38,7 +45,6 @@
3845
"typescript": "~2.0.10",
3946

4047
"canonical-path": "0.0.2",
41-
"http-server": "^0.9.0",
4248
"tslint": "^3.15.1",
4349
"lodash": "^4.16.4",
4450
"jasmine-core": "~2.4.1",

protractor.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
//
66
// AND THEN EVERYTIME ...
77
// 1. Compile with `tsc`
8-
// 2. Make sure the test server (e.g., http-server: localhost:8080) is running.
8+
// 2. Make sure the test server (e.g., lite-server: localhost:8080) is running.
99
// 3. ./node_modules/.bin/protractor protractor.config.js
1010
//
1111
// To do all steps, try: `npm run e2e`

0 commit comments

Comments
 (0)