Skip to content
This repository was archived by the owner on Dec 4, 2017. It is now read-only.

Commit d8c1469

Browse files
wardbellnaomiblack
authored andcommitted
(docs) getting started: npm packages installed locally
1 parent 849a685 commit d8c1469

File tree

2 files changed

+65
-68
lines changed

2 files changed

+65
-68
lines changed

public/docs/_examples/gettingstarted/ts/package.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
"description": "",
55
"main": "index.js",
66
"scripts": {
7+
"postinstall": "npm run tsd",
8+
"tsd": "tsd link --config src/tsd.json && tsd reinstall -ro --config src/tsd.json",
9+
"tsc": "tsc -p src -w",
10+
"start": "live-server --open=src",
711
"test": "echo \"Error: no test specified\" && exit 1"
812
},
913
"keywords": [],
@@ -12,5 +16,10 @@
1216
"dependencies": {
1317
"angular2": "2.0.0-alpha.38",
1418
"systemjs": "0.19.2"
19+
},
20+
"devDependencies": {
21+
"live-server": "^0.8.1",
22+
"tsd": "^0.6.5",
23+
"typescript": "^1.6.2"
1524
}
1625
}

public/docs/ts/latest/guide/gettingStarted.jade

Lines changed: 56 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ include ../../../../_includes/_util-fns
4141

4242
:markdown
4343
We've just defined an Angular 2 **component**,
44-
one of the most important beasts in the Angular zoo.
44+
one of the most important Angular 2 features.
4545
Components are our primary means of creating application views
4646
and supporting them with application logic.
4747

@@ -231,71 +231,51 @@ include ../../../../_includes/_util-fns
231231
.l-main-section
232232

233233
:markdown
234-
## Install tools and application packages
234+
## Install npm packages locally
235235

236-
We'll need a set of tools for our application development throughout this guide.
237-
We've already installed **`live-server`**. Let's install two more:
238-
239-
- the **TypeScript compiler**
236+
We'll replace the web-based scripts in our `index.html` with
237+
scripts resident on our local machine.
238+
We get those scripts by installing two runtime `npm` packages into our project.
240239

240+
>**angular.js** - the Angular 2 library.
241241

242-
- the [**tsd package manager**](https://www.npmjs.com/package/tsd "TSD Package Manager") so we can access
243-
[TypeScript type definition files](http://definitelytyped.org/ "Definitely Typed").
242+
>**system.js** - an open-source library that provides module loading.
244243

245-
**Open** a terminal window and issue the following `npm` command to install both packages globally:
244+
We'll also install three development tools:
246245

247-
pre.prettyprint.lang-bash
248-
code npm install -g typescript tsd
246+
>**typescript** - the TypeScript compiler
249247

250-
.l-sub-section
251-
:markdown
252-
Now might be a good time to ensure that we're installing Angular-compatible versions of our tools.
253-
Issue the following commands in that same terminal window to confirm that we have the appropriate versions:
254-
table
255-
tr
256-
th Command
257-
th Versions
258-
tr
259-
td
260-
code node -v
261-
td 0.10.* - 0.12.*  &nbsp&nbspBut not 4.0.0 !!!
262-
tr
263-
td
264-
code npm -v
265-
td 2.11+ (3.* is fine)
266-
tr
267-
td
268-
code tsc -v
269-
td 1.6+
270-
tr
271-
td
272-
code tsd --version
273-
td 0.6.5+
274-
tr
275-
td
276-
code live-server -v
277-
td 0.8+
278-
279-
:markdown
280-
### Install local packages
281-
282-
We'll replace the web-based scripts in our `index.html` with
283-
scripts resident on our local machine. We get those scripts by installing two `npm` packages into our project.
248+
>**tsd** - the [tsd package manager](https://www.npmjs.com/package/tsd "TSD Package Manager") so we can access
249+
[TypeScript type definition files](http://definitelytyped.org/ "Definitely Typed")
284250

285-
>***angular.js***, the Angular 2 library.
251+
>**[live-server](https://www.npmjs.com/package/live-server "Live-server")** - the static file server that reloads the browser when files change.
252+
We may have loaded it earlier. We're doing it again
253+
locally in our project so we are no longer vulnerable to
254+
a global uninstall or version change.
286255

287-
>***system.js***, an open-source library that provides module loading.
256+
**Open** a terminal window at our application's **root folder**
288257

289-
In a terminal window at our application's **root folder** type:
258+
Enter these commands:
290259
```
291260
npm init -y
292261
npm i [email protected] [email protected] --save --save-exact
262+
npm i typescript tsd live-server --save-dev
293263
```
294264

295265
These commands both *install* the packages and *create* an npm `package.json` that will
296266
help us develop and maintain our application in future.
297267
The essence of our `package.json` should look like this:
298-
+makeJson('gettingstarted/ts/package.json', { paths: 'name, version, dependencies '})
268+
269+
+makeJson('gettingstarted/ts/package.json', { paths: 'name, version, dependencies, devDependencies'})
270+
271+
:markdown
272+
There is also a `scripts` section. **Find and replace** it with the following:
273+
274+
+makeJson('gettingstarted/ts/package.json', { paths: 'scripts'})
275+
276+
:markdown
277+
We've just extended our project world with script commands
278+
that we'll be running very soon.
299279

300280
.l-main-section
301281
:markdown
@@ -354,14 +334,15 @@ include ../../../../_includes/_util-fns
354334
that holds links to the type definition files in those packages.
355335

356336
In the ***root* folder** enter the following command
337+
(one of the `npm` scripts we added a short while ago)
357338

358339
pre.prettyprint.lang-bash
359-
code tsd link --config src/tsd.json
340+
code npm run tsd
360341

361342
:markdown
362343
That produces a new **`src/typings`** folder with the **`tsd.d.ts`** file.
363344

364-
Now Angular type checking and intellisense lights up automatically as we write our app
345+
Now type-checking and intellisense light up automatically as we write our app
365346
in the Visual Studio Code and Web Storm editors. Check your editor's documentation for
366347
instructions on using the `tsd.d.ts` file.
367348

@@ -393,49 +374,56 @@ include ../../../../_includes/_util-fns
393374
:markdown
394375
## Compile the TypeScript to JavaScript
395376

396-
We are no longer transpiling TypeScript to JavaScript in the browser.
397-
We're compiling it on our machine instead.
377+
We no longer transpile TypeScript to JavaScript in the browser.
378+
We run the **T**ype**S**cript **C**ompiler (TSC) on our machine instead.
398379

399-
Open a terminal window in the **root of the application folder** (not *src*) and enter:
380+
Open a terminal window in the **root of the application folder** and enter:
400381

401382
pre.prettyprint.lang-bash
402-
code tsc -p src -w
383+
code npm run tsc
403384

404385
:markdown
405-
After it runs we should find the generated *app.js* file in the *src* folder and also an *app.map.js* file that
386+
When it's done we should find the generated *app.js* file in the *src* folder and also an *app.map.js* file that
406387
helps debuggers navigate between the JavaScript and the TypeScript source.
407388

408-
We gave *tsc* the watch option (`-w`). It will watch for changes to our *.ts* files and
409-
recompile them automatically. Leave it running in this terminal window.
389+
Our script set the compiler watch option (`-w`) so the
390+
compiler stays alive when it's finished.
391+
It watches for changes to our **`.ts`** files
392+
and recompiles them automatically.
393+
394+
Leave this command running in the terminal window.
395+
You can stop it anytime with `Ctrl-C`.
410396

411397
.l-main-section
412398
:markdown
413399
## Run the app!
414400

415-
Now we are ready to see this app in action.
401+
Now we are ready to see our app in action.
416402

417-
Open another terminal window in the **root of the application folder** (not *src*) and
418-
launch `live-server` again although this time we add command line
419-
arguments telling it to **serve from the application's new location in `src`**:
403+
Open another terminal window in the **root of the application folder** and
404+
launch `live-server` again although this time we'll do it with
405+
one of our `npm` script commands:
420406

421407
pre.prettyprint.lang-bash
422-
code live-server --open=src
408+
code npm start
423409

424410
:markdown
425-
**live-server** loads the browser for us, serves the HTML and JavaScript files, and we should see it display our
426-
application message once more:
411+
**live-server** loads the browser for us, serves the HTML and JavaScript files,
412+
and displays our application message once more:
427413

428414
figure.image-display
429415
img(src='/resources/images/devguide/getting-started/my-first-app.png' alt="Output of getting started app")
430416

431417
:markdown
432418
### Make some changes
433-
**live-server** detects changes to our files and refreshes the browser page for us automatically.
419+
**`live-server`** detects changes to our files and refreshes the browser page for us automatically.
434420

435421
Try changing the message to "My SECOND Angular 2 app".
436422

437-
The TypeScript compiler running in the first terminal window is watching our source code. It recompiles and produces
438-
the revised *app.js*. The *live-server* sees that change and reloads the browser.
423+
The TypeScript compiler in the first terminal window is watching our source code. It recompiles and produces
424+
the revised *app.js*. The `live-server` sees that change and reloads the browser.
425+
426+
Keep `live-server` running in this terminal window. You can stop it anytime with `Ctrl-C`.
439427

440428
.l-main-section
441429
:markdown

0 commit comments

Comments
 (0)