|
| 1 | +# Angular documentation project (https://angular.io) |
| 2 | + |
| 3 | +Everything in this folder is part of the documentation project. This includes |
| 4 | + |
| 5 | +* the web site for displaying the documentation |
| 6 | +* the dgeni configuration for converting source files to rendered files that can be viewed in the web site. |
| 7 | +* the tooling for setting up examples for development; and generating live-example and zip files from the examples. |
| 8 | + |
| 9 | +## Developer tasks |
| 10 | + |
| 11 | +We use `yarn` to manage the dependencies and to run build tasks. |
| 12 | +You should run all these tasks from the `angular/aio` folder. |
| 13 | +Here are the most important tasks you might need to use: |
| 14 | + |
| 15 | +* `yarn` - install all the dependencies. |
| 16 | +* `yarn setup` - install all the dependencies, boilerplate, stackblitz, zips and run dgeni on the docs. |
| 17 | +* `yarn setup-local` - same as `setup`, but use the locally built Angular packages for aio and docs examples boilerplate. |
| 18 | + |
| 19 | +* `yarn build` - create a production build of the application (after installing dependencies, boilerplate, etc). |
| 20 | +* `yarn build-local` - same as `build`, but use `setup-local` instead of `setup`. |
| 21 | + |
| 22 | +* `yarn start` - run a development web server that watches the files; then builds the doc-viewer and reloads the page, as necessary. |
| 23 | +* `yarn serve-and-sync` - run both the `docs-watch` and `start` in the same console. |
| 24 | +* `yarn lint` - check that the doc-viewer code follows our style rules. |
| 25 | +* `yarn test` - watch all the source files, for the doc-viewer, and run all the unit tests when any change. |
| 26 | +* `yarn e2e` - run all the e2e tests for the doc-viewer. |
| 27 | + |
| 28 | +* `yarn docs` - generate all the docs from the source files. |
| 29 | +* `yarn docs-watch` - watch the Angular source and the docs files and run a short-circuited doc-gen for the docs that changed. |
| 30 | +* `yarn docs-lint` - check that the doc gen code follows our style rules. |
| 31 | +* `yarn docs-test` - run the unit tests for the doc generation code. |
| 32 | + |
| 33 | +* `yarn boilerplate:add` - generate all the boilerplate code for the examples, so that they can be run locally. Add the option `--local` to use your local version of Angular contained in the "dist" folder. |
| 34 | +* `yarn boilerplate:remove` - remove all the boilerplate code that was added via `yarn boilerplate:add`. |
| 35 | +* `yarn generate-stackblitz` - generate the stackblitz files that are used by the `live-example` tags in the docs. |
| 36 | +* `yarn generate-zips` - generate the zip files from the examples. Zip available via the `live-example` tags in the docs. |
| 37 | + |
| 38 | +* `yarn example-e2e` - run all e2e tests for examples |
| 39 | + - `yarn example-e2e --setup` - force webdriver update & other setup, then run tests |
| 40 | + - `yarn example-e2e --filter=foo` - limit e2e tests to those containing the word "foo" |
| 41 | + - `yarn example-e2e --setup --local` - run e2e tests with the local version of Angular contained in the "dist" folder |
| 42 | + |
| 43 | +* `yarn build-ie-polyfills` - generates a js file of polyfills that can be loaded in Internet Explorer. |
| 44 | + |
| 45 | +## Using ServiceWorker locally |
| 46 | + |
| 47 | +Since abb36e3cb, running `yarn start --prod` will no longer set up the ServiceWorker, which |
| 48 | +would require manually running `yarn sw-manifest` and `yarn sw-copy` (something that is not possible |
| 49 | +with webpack serving the files from memory). |
| 50 | + |
| 51 | +If you want to test ServiceWorker locally, you can use `yarn build` and serve the files in `dist/` |
| 52 | +with `yarn http-server dist -p 4200`. |
| 53 | + |
| 54 | +For more details see #16745. |
| 55 | + |
| 56 | + |
| 57 | +## Guide to authoring |
| 58 | + |
| 59 | +There are two types of content in the documentation: |
| 60 | + |
| 61 | +* **API docs**: descriptions of the modules, classes, interfaces, decorators, etc that make up the Angular platform. |
| 62 | +API docs are generated directly from the source code. |
| 63 | +The source code is contained in TypeScript files, located in the `angular/packages` folder. |
| 64 | +Each API item may have a preceding comment, which contains JSDoc style tags and content. |
| 65 | +The content is written in markdown. |
| 66 | + |
| 67 | +* **Other content**: guides, tutorials, and other marketing material. |
| 68 | +All other content is written using markdown in text files, located in the `angular/aio/content` folder. |
| 69 | +More specifically, there are sub-folders that contain particular types of content: guides, tutorial and marketing. |
| 70 | + |
| 71 | +* **Code examples**: code examples need to be testable to ensure their accuracy. |
| 72 | +Also, our examples have a specific look and feel and allow the user to copy the source code. For larger |
| 73 | +examples they are rendered in a tabbed interface (e.g. template, HTML, and TypeScript on separate |
| 74 | +tabs). Additionally, some are live examples, which provide links where the code can be edited, executed, and/or downloaded. For details on working with code examples, please read the [Code snippets](https://angular.io/guide/docs-style-guide#code-snippets), [Source code markup](https://angular.io/guide/docs-style-guide#source-code-markup), and [Live examples](https://angular.io/guide/docs-style-guide#live-examples) pages of the [Authors Style Guide](https://angular.io/guide/docs-style-guide). |
| 75 | + |
| 76 | +We use the [dgeni](https://github.com/angular/dgeni) tool to convert these files into docs that can be viewed in the doc-viewer. |
| 77 | + |
| 78 | +The [Authors Style Guide](https://angular.io/guide/docs-style-guide) prescribes guidelines for |
| 79 | +writing guide pages, explains how to use the documentation classes and components, and how to markup sample source code to produce code snippets. |
| 80 | + |
| 81 | +### Generating the complete docs |
| 82 | + |
| 83 | +The main task for generating the docs is `yarn docs`. This will process all the source files (API and other), |
| 84 | +extracting the documentation and generating JSON files that can be consumed by the doc-viewer. |
| 85 | + |
| 86 | +### Partial doc generation for editors |
| 87 | + |
| 88 | +Full doc generation can take up to one minute. That's too slow for efficient document creation and editing. |
| 89 | + |
| 90 | +You can make small changes in a smart editor that displays formatted markdown: |
| 91 | +>In VS Code, _Cmd-K, V_ opens markdown preview in side pane; _Cmd-B_ toggles left sidebar |
| 92 | +
|
| 93 | +You also want to see those changes displayed properly in the doc viewer |
| 94 | +with a quick, edit/view cycle time. |
| 95 | + |
| 96 | +For this purpose, use the `yarn docs-watch` task, which watches for changes to source files and only |
| 97 | +re-processes the the files necessary to generate the docs that are related to the file that has changed. |
| 98 | +Since this task takes shortcuts, it is much faster (often less than 1 second) but it won't produce full |
| 99 | +fidelity content. For example, links to other docs and code examples may not render correctly. This is |
| 100 | +most particularly noticed in links to other docs and in the embedded examples, which may not always render |
| 101 | +correctly. |
| 102 | + |
| 103 | +The general setup is as follows: |
| 104 | + |
| 105 | +* Open a terminal, ensure the dependencies are installed; run an initial doc generation; then start the doc-viewer: |
| 106 | + |
| 107 | +```bash |
| 108 | +yarn setup |
| 109 | +yarn start |
| 110 | +``` |
| 111 | + |
| 112 | +* Open a second terminal and start watching the docs |
| 113 | + |
| 114 | +```bash |
| 115 | +yarn docs-watch |
| 116 | +``` |
| 117 | + |
| 118 | +>Alternatively, try the consolidated `serve-and-sync` command that builds, watches and serves in the same terminal window |
| 119 | +```bash |
| 120 | +yarn serve-and-sync |
| 121 | +``` |
| 122 | + |
| 123 | +* Open a browser at https://localhost:4200/ and navigate to the document on which you want to work. |
| 124 | +You can automatically open the browser by using `yarn start -o` in the first terminal. |
| 125 | + |
| 126 | +* Make changes to the page's associated doc or example files. Every time a file is saved, the doc will |
| 127 | +be regenerated, the app will rebuild and the page will reload. |
| 128 | + |
| 129 | +* If you get a build error complaining about examples or any other odd behavior, be sure to consult |
| 130 | +the [Authors Style Guide](https://angular.io/guide/docs-style-guide). |
0 commit comments