Skip to content

Commit 8427265

Browse files
committed
Crawl tutorials
1 parent f6330b9 commit 8427265

File tree

13 files changed

+153
-188
lines changed

13 files changed

+153
-188
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"

packages/webdoc-cli/src/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,14 @@ async function main(argv: yargs.Argv) {
100100
const sourceFiles = sources(config, documentTree);
101101

102102
documentTree.children = documentTree.members;
103+
documentTree.tutorials.push(...tutorials);
103104

104105
if (config.opts && config.opts.export) {
105106
fse.ensureFileSync(config.opts.export);
106107
}
107108

108109
try {
109-
if (!argv.skipAPI)
110-
parse(sourceFiles, documentTree);
110+
parse(sourceFiles, documentTree);
111111
} catch (e) {
112112
// Make sure we get that API structure out so the user can debug the problem!
113113
if (config.opts && config.opts.export) {

packages/webdoc-cli/src/load-tutorials/load-tutorials.js

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
// @flow
22

3+
import {log, tag} from "missionlog";
34
import type {Tutorial} from "@webdoc/types";
5+
import {createTutorialDoc} from "@webdoc/model";
46
import fs from "fs";
57
import globby from "globby";
6-
import {log, tag} from "missionlog";
78
import merge from "lodash.merge";
89
import {morphTutorials} from "./morph-tutorials";
910
import path from "path";
@@ -27,12 +28,12 @@ export function loadTutorials(tutorialsDir?: string): Tutorial[] {
2728

2829
const tutorialFiles = globby.sync(path.join(tutorialsDir, "./**/*"));
2930
const webdocIgnoreExists = fs.existsSync(path.join(tutorialsDir, "./.webdocignore"));
30-
const webdocIgnorePatterns: $ReadOnlyArray<string> = webdocIgnoreExists
31-
? fs.readFileSync(path.join(tutorialsDir, ".webdocignore"), 'utf8')
32-
.split('\n')
31+
const webdocIgnorePatterns: $ReadOnlyArray<string> = webdocIgnoreExists ?
32+
fs.readFileSync(path.join(tutorialsDir, ".webdocignore"), "utf8")
33+
.split("\n")
3334
.map((line) => line.trim())
34-
.filter((line) => !line.startsWith('#'))
35-
: [];
35+
.filter((line) => !line.startsWith("#")) :
36+
[];
3637

3738
if (webdocIgnoreExists) {
3839
log.info(tag.CLI, "Found .webdocignore in the tutorials directory");
@@ -48,7 +49,7 @@ export function loadTutorials(tutorialsDir?: string): Tutorial[] {
4849

4950
// Really simple check to ignore files using .webdocignore (undocumented feature)
5051
if (webdocIgnorePatterns.some(
51-
(pattern) => relativePath.startsWith(pattern)
52+
(pattern) => relativePath.startsWith(pattern),
5253
)) {
5354
continue;
5455
}
@@ -77,16 +78,14 @@ export function loadTutorials(tutorialsDir?: string): Tutorial[] {
7778
fileName = fileName.slice(0, fileName.lastIndexOf("."));
7879

7980
// Tutorials can be part of the doc-tree!
80-
tutorials.push({
81-
id: `tutorial-${fileName}`,
82-
name: fileName,
83-
path: fileName,
84-
stack: [fileName],
85-
title: fileName,
86-
content: fileContent,
87-
members: [],
88-
type: "TutorialDoc",
89-
});
81+
tutorials.push(createTutorialDoc(
82+
fileName,
83+
relativePath
84+
.replace(".html", "")
85+
.replace(".htm", "")
86+
.replace(".md", ""),
87+
fileContent,
88+
));
9089
}
9190

9291
if (tutorialConf) {

packages/webdoc-cli/src/load-tutorials/morph-tutorials.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,12 @@ function resolveConfigurator(
9494
function tutorialDoc(name: string, configurator?: TutorialConfigurator): TutorialDoc {
9595
let tdoc = tutorialDB.get(name);
9696

97-
if (!tdoc && configurator?.kind !== "category") {
97+
if (!tdoc && (!configurator || configurator.kind !== "category")) {
9898
throw new Error("There is no such tutorial '" + name + "'");
9999
}
100100
if (!tdoc) {
101101
// category tutorial
102-
tdoc = createTutorialDoc(name, '');
102+
tdoc = createTutorialDoc(name, "", "");
103103
tutorialDB.set(name, tdoc);
104104
}
105105
if (configurator) {

packages/webdoc-default-template/helper/crawl/crawl-reference-explorer.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,16 @@ function traversePackage(doc /*: Doc | PackageDoc */, context /*: Object */, par
155155
context.exit(doc);
156156
}
157157

158+
/*::
159+
export type ExplorerTarget = {
160+
title: string,
161+
page?: ?string,
162+
children: {
163+
[id: string]: ExplorerTarget,
164+
}
165+
};
166+
*/
167+
158168
function buildExplorerTargetsTree(
159169
node /*: ExplorerNode */,
160170
parentTitle /*: string */ = "",
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// @flow
2+
3+
const {linker} = require("../linker");
4+
5+
/*::
6+
import type {
7+
Doc,
8+
RootDoc,
9+
TutorialDoc,
10+
} from "@webdoc/types";
11+
12+
import type { ExplorerTarget } from './crawl-reference-explorer';
13+
*/
14+
15+
// Build a explorer tree for tutorials
16+
function crawlTutorials(docTree /*: RootDoc */)/*: ?ExplorerTarget */ {
17+
if (!docTree.tutorials.length) {
18+
return null;
19+
}
20+
21+
const rootTarget = {
22+
title: "Tutorials",
23+
page: linker.createURI("tutorials/index.html"),
24+
children: {},
25+
};
26+
27+
for (const tutorial of docTree.tutorials) {
28+
buildTutorialTargets(tutorial, rootTarget);
29+
}
30+
31+
return rootTarget;
32+
}
33+
34+
function buildTutorialTargets(
35+
tutorial /*: TutorialDoc */,
36+
parent /*: ExplorerTarget */,
37+
)/*: ExplorerTarget */ {
38+
const tutorialTarget = {
39+
title: tutorial.title,
40+
page: linker.createURI(tutorial.route),
41+
children: {},
42+
};
43+
44+
parent.title = tutorialTarget;
45+
parent.children[tutorialTarget.title] = tutorialTarget;
46+
47+
for (const childTutorial of tutorial.members) {
48+
if (childTutorial.type === "TutorialDoc") {
49+
buildTutorialTargets(childTutorial, tutorialTarget);
50+
}
51+
}
52+
53+
return tutorialTarget;
54+
}
55+
56+
exports.crawlTutorials = crawlTutorials;

0 commit comments

Comments
 (0)