Skip to content

Commit 16e77b0

Browse files
doc(cli): fixing up the cli docs
1 parent c9850e0 commit 16e77b0

File tree

2 files changed

+181
-119
lines changed

2 files changed

+181
-119
lines changed

doc/article/en-US/contact-manager-tutorial.md

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,47 @@
1313
"keywords": ["Getting Started", "ES2015", "ES2016", "TypeScript"]
1414
}
1515
---
16-
## [Getting Setup](aurelia-doc://section/1/version/1.0.0)
16+
## [Setting Up Your Machine](aurelia-doc://section/1/version/1.0.0)
17+
18+
For this tutorial, we're going to use the Aurelia CLI. If you've already setup your machine with the CLI, you can skip to the next section. If not, then please install the following CLI prerequisites:
19+
20+
* Install NodeJS >= 4.x
21+
* You can [download it here](https://nodejs.org/en/).
22+
* Install a Git Client
23+
* Here's [a nice GUI client](https://desktop.github.com).
24+
* Here's [a standard client](https://git-scm.com).
25+
26+
Once you have the prerequisites installed, you can install the Aurelia CLI itself. From the command line, use npm to install the CLI globally:
27+
28+
```
29+
npm install aurelia-cli -g
30+
```
31+
32+
> Info
33+
> Always run commands from a Bash prompt. Depending on your environment, you may need to use `sudo` when executing npm global installs.
34+
35+
> Warning
36+
> While creating a new project doesn't require NPM 3, front-end development, in general, requires a flat-package structure, which is not what NPM < 3 provides. It is recommended that you update to NPM 3, which will be able to manage this structural requirement. You can check your NPM version with `npm -v`. If you need to update, run `npm install npm -g`.
37+
38+
## [Creating A New Aurelia Project](aurelia-doc://section/2/version/1.0.0)
39+
40+
Now, that you've got your machine setup, we can create our contact manager app. To create the project, run `au new` from the command line. You will be presented with a number of options. Name the project "contact-manager" and then select either "Default ESNext" or "Default TypeScript" depending on what is most comfortable for you.
41+
42+
Once you've made your choice, the CLI will show you your selections and ask if you'd like to create the file structure. Hit enter to accpet the default "yes". After that, you'll be asked if you would like to install your new project's dependencies. Press enter to select the default "yes" for this as well.
43+
44+
Once the dependencies are installed (it will take a few minutes), your project is ready to go. Just change directory into the project folder and run it by typing `au run --watch`. This will run the app and watch the project's source for changes. Open a web browser and navigate to the url indicated in the CLI's output. If you've got everything setup correctly, you should see the message "Hello World!" in the browser.
45+
46+
## [Adding Required Assets](aurelia-doc://section/3/version/1.0.0)
47+
48+
For this tutorial, we're going to be working against a fake, in-memory backend. We've also pre-created the CSS, so we don't have to waste time on that here. Before we begin writing the app, you'll need to download these required assets and add them to your project.
49+
50+
<div style="text-align: center; margin-bottom: 32px">
51+
<a class="au-button" href="http://aurelia.io/downloads/contat-manager-assets.zip" target="_blank">Download the Contact Manager Assets</a>
52+
</div>
53+
54+
Once you've downloaded the zip file, extract it and you'll find two files:
55+
56+
* `web-api.js` - The fake, in-memory backend.
57+
* `styles.css` - The styles for this app.
58+
59+
Copy both of these files to the `src` folder of your project.

doc/article/en-US/the-aurelia-cli.md

Lines changed: 137 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -80,40 +80,48 @@ Below is some guidance for how to manually configure several different common 3r
8080

8181
If the library you have installed is a single CommonJS or AMD file, you can add an entry similar to the following to the dependencies of yoru bundle:
8282

83-
```javascript
84-
"dependencies": [
85-
{
86-
"name": "library-name",
87-
"path": "../node_modules/library-name/dist/library-name"
88-
}
89-
]
90-
```
83+
<code-listing heading="A Single File Module Dependency">
84+
<source-code lang="JavaScript">
85+
"dependencies": [
86+
{
87+
"name": "library-name",
88+
"path": "../node_modules/library-name/dist/library-name"
89+
}
90+
]
91+
</source-code>
92+
</code-listing>
9193

9294
* `name` - This is the name of the library as you will import it in your JavaScript or TypeScript code.
9395
* `path` - This is a path to the single module file itself. This path is relative to your application's `src` folder. Also, you should not include the file extension. `.js` will be appended automatically.
9496

9597
If the `main` field of the library's `package.json` points to the single file that you need to bundle, then you can opt for a simplified configuration by just adding the package name to your dependencies directly:
9698

97-
```javascript
98-
"dependencies": [
99-
"library-name"
100-
]
101-
```
99+
<code-listing heading="A Single File Module Dependency via Main">
100+
<source-code lang="JavaScript">
101+
"dependencies": [
102+
"library-name"
103+
]
104+
</source-code>
105+
</code-listing>
106+
102107

103108
### A CommonJS Package
104109

105110
Many modules installed through NPM are packages made up of multiple source files. Configuring a library like this is a bit different than the single-file scenario above. Here's an example configuration for a multi-file package:
106111

107-
```javascript
108-
"dependencies": [
109-
{
110-
"name": "aurelia-testing",
111-
"path": "../node_modules/aurelia-testing/dist/amd",
112-
"main": "aurelia-testing",
113-
"env": "dev"
114-
}
115-
]
116-
```
112+
<code-listing heading="A CommonJS Package Dependency">
113+
<source-code lang="JavaScript">
114+
"dependencies": [
115+
{
116+
"name": "aurelia-testing",
117+
"path": "../node_modules/aurelia-testing/dist/amd",
118+
"main": "aurelia-testing",
119+
"env": "dev"
120+
}
121+
]
122+
</source-code>
123+
</code-listing>
124+
117125

118126
* `name` - This is the name of the library as you will import it in your JavaScript or TypeScript code.
119127
* `path` - This is a path to the folder where the package's source is located. This path is relative to your application's `src` folder.
@@ -125,18 +133,20 @@ Many modules installed through NPM are packages made up of multiple source files
125133

126134
Libraries that predate module systems can be a pain because they often rely on global scripts which must be loaded before the library. These libraries also add their own global variables. An example of one such library is [bootstrap](http://getbootstrap.com/css/). Let's take a look at how to handle a legacy library like that.
127135

128-
```javascript
129-
"dependencies": [
130-
"jquery",
131-
{
132-
"name": "bootstrap",
133-
"path": "../node_modules/bootstrap/dist",
134-
"main": "js/bootstrap.min",
135-
"deps": ["jquery"],
136-
"exports": "$"
137-
}
138-
]
139-
```
136+
<code-listing heading="A Legacy Library Dependency">
137+
<source-code lang="JavaScript">
138+
"dependencies": [
139+
"jquery",
140+
{
141+
"name": "bootstrap",
142+
"path": "../node_modules/bootstrap/dist",
143+
"main": "js/bootstrap.min",
144+
"deps": ["jquery"],
145+
"exports": "$"
146+
}
147+
]
148+
</source-code>
149+
</code-listing>
140150

141151
* `name` - This is the name of the library as you will import it in your JavaScript or TypeScript code.
142152
* `path` - This is a path to the folder where the package's source is located. This path is relative to your application's `src` folder.
@@ -150,21 +160,23 @@ Notice first that we've included "jquery" as one of our dependencies. We are abl
150160

151161
The Bootstrap example above results in the bundling of the JavaScript portions of the library. But, as you probably know, Bootstrap is mostly about CSS. The CSS files distributed with Bootstrap aren't traceable through the module system so this still doesn't result in the Bootstrap CSS being bundled. Here's how we solve that problem:
152162

153-
```javascript
154-
"dependencies": [
155-
"jquery",
156-
{
157-
"name": "bootstrap",
158-
"path": "../node_modules/bootstrap/dist",
159-
"main": "js/bootstrap.min",
160-
"deps": ["jquery"],
161-
"exports": "$",
162-
"resources": [
163-
"css/bootstrap.css"
163+
<code-listing heading="A Library with Additional Resources">
164+
<source-code lang="JavaScript">
165+
"dependencies": [
166+
"jquery",
167+
{
168+
"name": "bootstrap",
169+
"path": "../node_modules/bootstrap/dist",
170+
"main": "js/bootstrap.min",
171+
"deps": ["jquery"],
172+
"exports": "$",
173+
"resources": [
174+
"css/bootstrap.css"
175+
]
176+
}
164177
]
165-
}
166-
]
167-
```
178+
</source-code>
179+
</code-listing>
168180

169181
Notice that we've added a `resources` array. Here we can provide a list of additional files to be included with the bundle. These files are relative to the `path` designated above and must include the file extension. You can also use glob patterns in place of exact file names.
170182

@@ -174,88 +186,95 @@ Notice that we've added a `resources` array. Here we can provide a list of addit
174186

175187
Sometimes you can't get a library to work with the module loading system. That's ok. You can still include it in the bundle, using traditional concatenation techniques. In fact, this is how the CLI bundles up the loader and promise polyfills. These items don't go into the `dependencies` section but instead go into the `prepend` section. This is because they aren't module dependencies. They also aren't relative to the `src`, but relative to the project folder. Using the `prepend` section causes the scripts to be prepended to the beginning of the bundle, using normal script concatenation techniques. Here's a full vendor bundle example, showing this and the rest of the techniques listed above.
176188

177-
```javascript
178-
{
179-
"name": "vendor-bundle.js",
180-
"prepend": [
181-
"node_modules/bluebird/js/browser/bluebird.core.js",
182-
"scripts/require.js"
183-
],
184-
"dependencies": [
185-
"aurelia-binding",
186-
"aurelia-bootstrapper",
187-
"aurelia-dependency-injection",
188-
"aurelia-event-aggregator",
189-
"aurelia-framework",
190-
"aurelia-history",
191-
"aurelia-history-browser",
192-
"aurelia-loader",
193-
"aurelia-loader-default",
194-
"aurelia-logging",
195-
"aurelia-logging-console",
196-
"aurelia-metadata",
197-
"aurelia-pal",
198-
"aurelia-pal-browser",
199-
"aurelia-path",
200-
"aurelia-polyfills",
201-
"aurelia-route-recognizer",
202-
"aurelia-router",
203-
"aurelia-task-queue",
204-
"aurelia-templating",
205-
"aurelia-templating-binding",
206-
"nprogress",
207-
"jquery",
189+
<code-listing heading="A Sample Bundle">
190+
<source-code lang="JavaScript">
208191
{
209-
"name": "bootstrap",
210-
"path": "../node_modules/bootstrap/dist",
211-
"main": "js/bootstrap.min",
212-
"deps": ["jquery"],
213-
"exports": "$",
214-
"resources": [
215-
"css/bootstrap.css"
192+
"name": "vendor-bundle.js",
193+
"prepend": [
194+
"node_modules/bluebird/js/browser/bluebird.core.js",
195+
"scripts/require.js"
196+
],
197+
"dependencies": [
198+
"aurelia-binding",
199+
"aurelia-bootstrapper",
200+
"aurelia-dependency-injection",
201+
"aurelia-event-aggregator",
202+
"aurelia-framework",
203+
"aurelia-history",
204+
"aurelia-history-browser",
205+
"aurelia-loader",
206+
"aurelia-loader-default",
207+
"aurelia-logging",
208+
"aurelia-logging-console",
209+
"aurelia-metadata",
210+
"aurelia-pal",
211+
"aurelia-pal-browser",
212+
"aurelia-path",
213+
"aurelia-polyfills",
214+
"aurelia-route-recognizer",
215+
"aurelia-router",
216+
"aurelia-task-queue",
217+
"aurelia-templating",
218+
"aurelia-templating-binding",
219+
"nprogress",
220+
"jquery",
221+
{
222+
"name": "bootstrap",
223+
"path": "../node_modules/bootstrap/dist",
224+
"main": "js/bootstrap.min",
225+
"deps": ["jquery"],
226+
"exports": "$",
227+
"resources": [
228+
"css/bootstrap.css"
229+
]
230+
},
231+
{
232+
"name": "text",
233+
"path": "../scripts/text"
234+
},
235+
{
236+
"name": "aurelia-templating-resources",
237+
"path": "../node_modules/aurelia-templating-resources/dist/amd",
238+
"main": "aurelia-templating-resources"
239+
},
240+
{
241+
"name": "aurelia-templating-router",
242+
"path": "../node_modules/aurelia-templating-router/dist/amd",
243+
"main": "aurelia-templating-router"
244+
},
245+
{
246+
"name": "aurelia-testing",
247+
"path": "../node_modules/aurelia-testing/dist/amd",
248+
"main": "aurelia-testing",
249+
"env": "dev"
250+
}
216251
]
217-
},
218-
{
219-
"name": "text",
220-
"path": "../scripts/text"
221-
},
222-
{
223-
"name": "aurelia-templating-resources",
224-
"path": "../node_modules/aurelia-templating-resources/dist/amd",
225-
"main": "aurelia-templating-resources"
226-
},
227-
{
228-
"name": "aurelia-templating-router",
229-
"path": "../node_modules/aurelia-templating-router/dist/amd",
230-
"main": "aurelia-templating-router"
231-
},
232-
{
233-
"name": "aurelia-testing",
234-
"path": "../node_modules/aurelia-testing/dist/amd",
235-
"main": "aurelia-testing",
236-
"env": "dev"
237252
}
238-
]
239-
}
240-
```
253+
</source-code>
254+
</code-listing>
241255

242256
## [Styling your Application](aurelia-doc://section/7/version/1.0.0)
243257

244258
There are many ways to style components in Aurelia. The CLI sets up your project to only process styles inside your application's `src` folder. Those styles can then be imported into a view using Aurelia's `require` element.
245259

246260
* If you aren't using any CSS preprocessor, you write css and then simply require it in the view like this:
247-
```html
248-
<require from="./path/to/styles.css"></require>
249-
```
261+
262+
<code-listing heading="Requiring styles.css">
263+
<source-code lang="HTML">
264+
<require from="./styles.css"></require>
265+
</source-code>
266+
</code-listing>
267+
250268
* For projects that use a CSS preprocessor (chosen from the cli setup questions):
251269
* Write your styles in the format you chose (styl, sass, less ...).
252270
* Require the style by `[filename].css` instead of `[filename].[extension]`. This is because
253271
your style file is transpiled into a module that encodes the resulting `css` file extension.
254-
```html
255-
<!-- example -->
256-
<!-- if you have stylus at: [project_root]/src/styles/main.styl -->
257-
<require from ="./styles/main.css"></require>
258-
```
272+
273+
<code-listing heading="Requiring main.sass">
274+
<source-code lang="HTML">
275+
<require from ="./main.css"></require>
276+
</source-code>
277+
</code-listing>
259278

260279
Bear in mind that you can always configure things any way you want by modifying the tasks in the `aurelia_project/tasks` folder.
261280
For styling purposes, you can modify the `process-css.js` file.

0 commit comments

Comments
 (0)