Skip to content

Commit 33581f9

Browse files
authored
Merge pull request #109 from webdoc-labs/feature/tutorials
Feature: Tutorials
2 parents 9237438 + 5f3613a commit 33581f9

File tree

25 files changed

+528
-229
lines changed

25 files changed

+528
-229
lines changed

common/config/rush/command-line.json

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -13,66 +13,66 @@
1313
"commands": [
1414
{
1515
"commandKind": "bulk",
16-
16+
1717
"name": "unit-test",
1818
"summary": "Runs Unit Tests for all packages",
1919
"description": "This will run all the unit tests that are defined within each package.json.\nScript name should be 'unit-tests'",
20-
20+
2121
"safeForSimultaneousRushProcesses": false,
2222
"enableParallelism": false,
2323
"ignoreDependencyOrder": false,
2424
"ignoreMissingScript": false,
25-
25+
2626
"allowWarningsInSuccessfulBuild": true
2727
},
2828
{
2929
"commandKind": "bulk",
30-
30+
3131
"name": "lint",
3232
"summary": "Lints all packages",
3333
"description": "This will run linting on all packages that have a `lint` script defined.",
34-
34+
3535
"safeForSimultaneousRushProcesses": false,
3636
"enableParallelism": true,
3737
"ignoreDependencyOrder": true,
3838
"ignoreMissingScript": true,
39-
39+
4040
"allowWarningsInSuccessfulBuild": false
4141
},
4242
{
4343
"commandKind": "bulk",
44-
44+
4545
"name": "flow",
4646
"summary": "Runs flow on all packages",
4747
"description": "This will run flow type checking on all packages that have a `flow` script defined.",
4848
"safeForSimultaneousRushProcesses": false,
4949
"enableParallelism": true,
5050
"ignoreDependencyOrder": true,
5151
"ignoreMissingScript": true,
52-
52+
5353
"allowWarningsInSuccessfulBuild": false
5454
}
55-
//
55+
//
5656
// {
5757
// /**
5858
// * (Required) Determines the type of custom command.
5959
// * Rush's "global" commands are invoked once for the entire repo.
6060
// */
6161
// "commandKind": "global",
62-
//
62+
//
6363
// "name": "my-global-command",
6464
// "summary": "Example global custom command",
6565
// "description": "This is an example custom command that runs once for the entire repo",
66-
//
66+
//
6767
// "safeForSimultaneousRushProcesses": false,
68-
//
68+
//
6969
// /**
7070
// * (Required) A script that will be invoked using the OS shell. The working directory will be
7171
// * the folder that contains rush.json. If custom parameters are associated with this command, their
7272
// * values will be appended to the end of this string.
7373
// */
7474
// "shellCommand": "node common/scripts/my-global-command.js",
75-
//
75+
//
7676
// /**
7777
// * If your "shellCommand" script depends on NPM packages, the recommended best practice is
7878
// * to make it into a regular Rush project that builds using your normal toolchain. In cases where
@@ -106,12 +106,12 @@
106106
// * A "flag" is a custom command-line parameter whose presence acts as an on/off switch.
107107
// */
108108
// "parameterKind": "flag",
109-
//
109+
//
110110
// /**
111111
// * (Required) The long name of the parameter. It must be lower-case and use dash delimiters.
112112
// */
113113
// "longName": "--my-flag",
114-
//
114+
//
115115
// /**
116116
// * An optional alternative short name for the parameter. It must be a dash followed by a single
117117
// * lower-case or upper-case letter, which is case-sensitive.
@@ -122,22 +122,22 @@
122122
// * a short name if you expect the parameter to be needed very often in everyday operations.
123123
// */
124124
// "shortName": "-m",
125-
//
125+
//
126126
// /**
127127
// * (Required) A long description to be shown in the command-line help.
128128
// *
129129
// * Whenever you introduce commands/parameters, taking a little time to write meaningful
130130
// * documentation can make a big difference for the developer experience in your repo.
131131
// */
132132
// "description": "A custom flag parameter that is passed to the scripts that are invoked when building projects",
133-
//
133+
//
134134
// /**
135135
// * (Required) A list of custom commands and/or built-in Rush commands that this parameter may
136136
// * be used with. The parameter will be appended to the shell command that Rush invokes.
137137
// */
138138
// "associatedCommands": ["build", "rebuild"]
139139
// },
140-
//
140+
//
141141
// {
142142
// /**
143143
// * (Required) Determines the type of custom parameter.
@@ -146,9 +146,9 @@
146146
// "parameterKind": "string",
147147
// "longName": "--my-string",
148148
// "description": "A custom string parameter for the \"my-global-command\" custom command",
149-
//
149+
//
150150
// "associatedCommands": ["my-global-command"],
151-
//
151+
//
152152
// /**
153153
// * The name of the argument, which will be shown in the command-line help.
154154
// *
@@ -157,13 +157,13 @@
157157
// * be comprised of upper-case letters, numbers, and underscores. It should be kept short.
158158
// */
159159
// "argumentName": "SOME_TEXT",
160-
//
160+
//
161161
// /**
162162
// * If true, this parameter must be included with the command. The default is false.
163163
// */
164164
// "required": false
165165
// },
166-
//
166+
//
167167
// {
168168
// /**
169169
// * (Required) Determines the type of custom parameter.
@@ -173,22 +173,22 @@
173173
// "parameterKind": "choice",
174174
// "longName": "--my-choice",
175175
// "description": "A custom choice parameter for the \"my-global-command\" custom command",
176-
//
176+
//
177177
// "associatedCommands": ["my-global-command"],
178-
//
178+
//
179179
// /**
180180
// * If true, this parameter must be included with the command. The default is false.
181181
// */
182182
// "required": false,
183-
//
183+
//
184184
// /**
185185
// * Normally if a parameter is omitted from the command line, it will not be passed
186186
// * to the shell command. this value will be inserted by default. Whereas if a "defaultValue"
187187
// * is defined, the parameter will always be passed to the shell command, and will use the
188188
// * default value if unspecified. The value must be one of the defined alternatives.
189189
// */
190190
// "defaultValue": "vanilla",
191-
//
191+
//
192192
// /**
193193
// * (Required) A list of alternative argument values that can be chosen for this parameter.
194194
// */
@@ -199,7 +199,7 @@
199199
// * e.g. "vanilla" in "--flavor vanilla".
200200
// */
201201
// "name": "vanilla",
202-
//
202+
//
203203
// /**
204204
// * A detailed description for the alternative that can be shown in the command-line help.
205205
// *
@@ -208,12 +208,12 @@
208208
// */
209209
// "description": "Use the vanilla flavor (the default)"
210210
// },
211-
//
211+
//
212212
// {
213213
// "name": "chocolate",
214214
// "description": "Use the chocolate flavor"
215215
// },
216-
//
216+
//
217217
// {
218218
// "name": "strawberry",
219219
// "description": "Use the strawberry flavor"

example/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"build-next": "cd .. && webdoc && cd example",
2828
"build-pixi-api": "cd ../../pixi-api && webdoc && cd ../webdoc/example",
2929
"build-pixi-api-prod": "cd ../../pixi-api && webdoc --site-root pixi-api && cd ../webdoc/example",
30-
"build-pixi-api-gcp": "cd ../../pixi-api && webdoc && cd ../webdoc/example"
30+
"build-pixi-api-gcp": "cd ../../pixi-api && webdoc --tutorials ./projects/guides --verbose && cd ../webdoc/example"
3131
},
3232
"bugs": {
3333
"url": "https://github.com/SukantPal/webdoc/issues"

packages/webdoc-cli/README.md

Lines changed: 122 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ npm install --save-dev @webdoc/cli
1818
generate the `sitemap.xml`. This is useful if you want to integrate with [Algolia and use its crawler](https://www.algolia.com/products/crawler/). You must include the protocol for this to work currently, e.g. `http://pixijs.webdoclabs.com`.
1919
* `--site-root <path>`: If using absolute links in a template, this will set the basepath. The basepath should the directory in which the documentation is being stored relative to where the server is running. The site root is "/" by default - which means that you'll need to serve the documentation directory as top-level. Note that @webdoc/default-template uses absolute links.
2020
* `-c <config-path>`: This sets the path of the configuration file webdoc uses.
21+
* `-u <tutorials-directory>` - (optional) This should point to a directory containing tutorials written in Markdown (".md") or HTML ".html, ".htm". JSON files can be used to configure the hierarchy and naming of tutorials (see the Tutorial Configuration section).
2122

2223
### Configuration
2324

@@ -90,21 +91,23 @@ The `template` object is used by the site template.
9091

9192
```json
9293
{
93-
"applicationName": "{ <i>webdoc</i> }",
94-
"meta": {
95-
"og:title": "webdoc",
96-
"og:description": "webdoc API documentation",
97-
"og:image": "https://camo.githubusercontent.com/1427d2fdabd8790c93ca05cbfb653e2c6a8ab5694e671a04aa3af3fcef313539/68747470733a2f2f692e6962622e636f2f5a4850395044382f4c6f676f2d4672616d652d352e706e67",
98-
"og:url": "{{url}}",
99-
"og:site_name": "webdoclabs.com"
100-
},
101-
"repository": "http://github.com/webdoc-labs/webdoc",
102-
"integrations": {
103-
"search": {
104-
"provider": "algolia",
105-
"apiKey": "kadlfj232983lkqwem",
106-
"indexName": "webdoc-example",
107-
"appId": "349o39841;akdsfu"
94+
"template": {
95+
"applicationName": "{ <i>webdoc</i> }",
96+
"meta": {
97+
"og:title": "webdoc",
98+
"og:description": "webdoc API documentation",
99+
"og:image": "https://camo.githubusercontent.com/1427d2fdabd8790c93ca05cbfb653e2c6a8ab5694e671a04aa3af3fcef313539/68747470733a2f2f692e6962622e636f2f5a4850395044382f4c6f676f2d4672616d652d352e706e67",
100+
"og:url": "{{url}}",
101+
"og:site_name": "webdoclabs.com"
102+
},
103+
"repository": "http://github.com/webdoc-labs/webdoc",
104+
"integrations": {
105+
"search": {
106+
"provider": "algolia",
107+
"apiKey": "kadlfj232983lkqwem",
108+
"indexName": "webdoc-example",
109+
"appId": "349o39841;akdsfu"
110+
}
108111
}
109112
}
110113
}
@@ -117,3 +120,107 @@ The `template` object is used by the site template.
117120
* `template.integrations`: (optional) Integrations with 3rd party solutions in your template. This object is dependent on which template you're using. For @webdoc/default-template, the following integrations are available:
118121
* `search`: This is used as the backend for the global site search. You'll need to create an Algolia account yourself and provide
119122
the `apiKey`, `appId`, `indexName`. (The only supported provider is "algolia" right now)
123+
124+
### Tutorial configuration
125+
126+
Tutorials can be structured in a hierarchy using JSON files in the tutorials directory. If you have multiple JSON configuration, they
127+
are deep-merged before being processed.
128+
129+
#### Per-tutorial configuration
130+
131+
Tutorials are referenced using their file name - so make sure all file names in the tutorial directory are unique. To configure a specific
132+
tutorial file, any configuration should reference it by the file name (excluding the extension). For example, to configure "hello-world.md":
133+
134+
```json
135+
{
136+
"hello-world": {
137+
"title": "Hello world! by webdoc"
138+
}
139+
}
140+
```
141+
142+
* `title` - This is what the navigation sidebar will list the tutorial as.
143+
144+
#### Defining a hierarchy
145+
146+
You can also define children in tutorial configurators inline:
147+
148+
```json
149+
{
150+
"hello-world": {
151+
"title": "Hello world! by webdoc",
152+
"children": {
153+
"chapter-1": {
154+
"title": "Chapter 1"
155+
},
156+
"chapter-2": {
157+
"title": "Chapter 2"
158+
}
159+
}
160+
},
161+
"next-steps": {
162+
"title": "Next-steps"
163+
}
164+
}
165+
```
166+
167+
In this configuration, "Chapter 1" and "Chapter 2" will be items under the "Hello world!" category.
168+
169+
#### Referencing other tutorials
170+
171+
Instead of defining tutorials inline in the `children` object, you can add them to the root and then reference
172+
them by name in a `children` array.
173+
174+
```json
175+
{
176+
"hello-world": {
177+
"title": "Hello world! by webdoc",
178+
"children": [
179+
"chapter-1",
180+
"chapter-2"
181+
]
182+
},
183+
"chapter-1": {
184+
"title": "Chapter 1"
185+
},
186+
"chapter-2": {
187+
"title": "Chapter 2"
188+
},
189+
"next-steps": {
190+
"title": "Next-steps"
191+
}
192+
}
193+
```
194+
195+
The above configuration is equivalent to the one defining "Chapter 1" and "Chapter 2" children inline "Hello world!". This way,
196+
you can also split the configuration into multiple files:
197+
198+
**main.json**
199+
200+
```json
201+
{
202+
"hello-world": {
203+
"title": "Hello world! by webdoc",
204+
"children": [
205+
"chapter-1",
206+
"chapter-2"
207+
]
208+
},
209+
"next-steps": {
210+
"title": "Next-steps"
211+
}
212+
}
213+
```
214+
215+
**chapters.json**
216+
217+
```json
218+
{
219+
"chapter-1": {
220+
"title": "Chapter 1"
221+
},
222+
"chapter-2": {
223+
"title": "Chapter 2"
224+
}
225+
}
226+
```

packages/webdoc-cli/src/config.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// @flow
2-
import {log, tags} from "missionlog";
2+
3+
import {log, tag} from "missionlog";
34
import fs from "fs";
45
import merge from "lodash.merge";
56

@@ -102,13 +103,15 @@ export function loadConfig(file: string): ConfigSchema {
102103
let config;
103104

104105
if (!fs.existsSync(file)) {
105-
log.warn(tags.Config, `Configuration file not found at: ${file}`);
106+
log.warn(tag.Config, `Configuration file not found at: ${file}`);
106107
config = defaultConfig;
107108
} else {
108109
const userConfig = JSON.parse(fs.readFileSync(file, "utf8"));
109110
config = merge(defaultConfig, userConfig);
110111
}
111112

113+
log.info(tag.CLI, "Loaded configuration");
114+
112115
return config;
113116
}
114117

0 commit comments

Comments
 (0)