Skip to content

Commit 2a06335

Browse files
committed
fix(docs): update docs to reflect new changes and additional info
Signed-off-by: moT01 <tmondloch01@gmail.com>
1 parent 287d9df commit 2a06335

12 files changed

+558
-66
lines changed

README.md

-2
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,6 @@ Build and share your own interactive tutorials.
5050

5151
Learn more about [how tutorials area created](https://coderoad.github.io/docs/build-tutorial).
5252

53-
See an [interactive visualization](https://coderoad.github.io/coderoad-visual/) of a tutorial repository.
54-
5553
## Editing Tutorials
5654

5755
Tutorials can be edited directly as markdown on Github.

docs/docs/build-tutorial.md

+5-2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@ title: Building a Tutorial
44
sidebar_label: Building a Tutorial
55
---
66

7-
A tutorial is made up of two parts:
7+
A tutorial is made from a github repository that includes three parts:
88

99
1. Markdown
10-
2. Git Commits
10+
2. YAML
11+
3. Git Commits
12+
13+
The Markdown and YAML live on the master branch of the repo, and the Git commits live on a version branch.
1114

1215
We'll go into each in detail in more detail.
+309
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,309 @@
1+
---
2+
id: create-a-practice-tutorial
3+
title: Create a Practice Tutorial
4+
sidebar_label: Create a Practice Tutorial
5+
---
6+
7+
## Create a CodeRoad tutorial
8+
9+
Follow these instructions carefully to create your first CodeRoad tutorial.
10+
11+
### Create a repo
12+
- Go to GitHub and create a new repository for yourself named `first-tutorial`
13+
- After you click create, it takes you to the repo. Copy the URL for the repo, it should look like: `https://github.com/your-username/first-tutorial.git`
14+
- Open a terminal locally and find a place to clone your repo. Enter `git clone https://github.com/your-username/first-tutorial.git` with the repo URL you copied in place of that URL to clone it
15+
- Create a `.gitignore` file in your repo and add this to it:
16+
```md
17+
node_modules
18+
package-lock.json
19+
```
20+
Add anything else that may interfere such as `.DS_Store` if you are on a mac.
21+
22+
### Create the markdown
23+
- Create a new file in your repo named `TUTORIAL.md`.
24+
25+
This is the file that describes the structure of a tutorial. It contains all the lessons, lesson titles, descriptions, test text and all the other verbiage that will be displayed to a user. Enter this markdown into the file and save it:
26+
27+
```md
28+
# Introduction
29+
30+
This is an introduction to your tutorial. It will show up on the first page when your tutorial is started.
31+
32+
## L1 Create index.html
33+
34+
> Optional summary for L1
35+
36+
Here's where you can put a description, examples, and instructions for the lesson.
37+
38+
### L1S1 Level 1 Step 1
39+
40+
This is the test text. Create an `index.html` file to pass this lesson.
41+
42+
#### HINTS
43+
44+
* This is a hint to help people through the test
45+
* Second hint for L1S1, don't worry if the hints don't show up yet
46+
```
47+
48+
The above tutorial has an introduction page and one lesson.
49+
50+
### Commit to github
51+
- Back in the terminal, add all your new files to be committed with `git add .`
52+
- Commit them with `git commit -m "create markdown"`
53+
- Push them to github with `git push origin master`
54+
55+
### Create a version branch
56+
- Create and checkout a new orphan branch with `git checkout --orphan v0.1.0`.
57+
58+
This will make a branch that isn't created from master, so it has no commit history. It will hold the tests for your tutorial. Each test is its own commit. You can also add an optional commit for a solution to each test.
59+
- Check your `git status`
60+
- Delete the tutorial file from this branch with `git rm -f TUTORIAL.md`
61+
62+
### Create your project files
63+
This branch is also where users create their projects, modify files for a tutorial, and most anything they need to do.
64+
- Make a new folder named `coderoad` on your branch.
65+
66+
This folder will hold as much of the CodeRoad stuff as it can so users aren't confused with extra files in their projects.
67+
- Go to the `coderoad` folder in your terminal and run `npm init`. Press enter until you are through the setup.
68+
- Open the `package.json` file you just made and make it look like this...
69+
70+
```js
71+
{
72+
"name": "coderoad",
73+
"version": "1.0.0",
74+
"description": "",
75+
"main": "index.js",
76+
"scripts": {
77+
"programmatic-test": "mocha --reporter=mocha-tap-reporter",
78+
"test": "mocha"
79+
},
80+
"author": "",
81+
"license": "ISC"
82+
}
83+
84+
```
85+
86+
These scripts will be for CodeRoad and you to test things.
87+
88+
- From the terminal, in your `coderoad` folder, run `npm install --save mocha mocha-tap-reporter` to install some depenedencies
89+
- **Go back to the main repo folder** and add your changes with `git add .`
90+
- Commit your files with `git commit -m "INIT"`
91+
92+
The message of `INIT` in all caps is necessary. This message is used to add project setup files and anthing else you want to add before a user starts the tutorial.
93+
- Push and Create a branch on your remote with `git push -u origin v0.1.0`
94+
95+
### Create the first test
96+
- Go in the `coderoad` folder and create new folder named `test` in it
97+
- Create a file named `first-tutorial.test.js` in the `test` folder
98+
- Add this to the file:
99+
100+
```js
101+
const assert = require('assert');
102+
const fs = require('fs');
103+
const util = require('util');
104+
const path = require('path');
105+
106+
const readdir = util.promisify(fs.readdir);
107+
const getRootDir = async (dir = process.cwd()) => {
108+
const pathToRoot = path.join(dir, '..');
109+
const rootDir = await readdir(pathToRoot);
110+
111+
if (!rootDir) {
112+
throw new Error(`Could not find folder ${pathToRoot}`);
113+
}
114+
115+
return rootDir;
116+
}
117+
118+
describe("first-tutorial folder", () => {
119+
let rootDir;
120+
before(async () => {
121+
rootDir = await getRootDir();
122+
});
123+
124+
it('should have an index.html file', async () => {
125+
assert(rootDir.indexOf('index.html') >= 0)
126+
});
127+
});
128+
```
129+
130+
This will be the test for the one lesson in your tutorial. You can see that it checks for the existence of an `index.html` file in the root folder.
131+
132+
- In the `coderoad` folder, run `npm run programmatic-test` from the terminal
133+
134+
It will fail since `index.html` doesn't exist.
135+
- Create an `index.html` file in the main repo folder and run the test again
136+
137+
It should pass this time. So when a user creates the `index.html` file, this test will run, and the lesson will pass.
138+
139+
### Commit your first test
140+
- Go back to the main repo folder and add the test file to be committed with `git add coderoad/.`
141+
- Commit it with `git commit -m "L1S1Q"`
142+
143+
That stands for "Lesson 1 Step 1 Question". You can put an additional note after it, but it has to start with those letters so CodeRoad knows that this is the test for the L1S1 step.
144+
- After that, add the index file with `git add index.html`
145+
- Commit the file with `git commit -m "L1S1A"`
146+
147+
That stands for "Lesson 1 Step 1 Answer", and it's the solution to the test.
148+
- Take a quick look at the commit history with `git log`. You can see the messages there, they align with the titles you put in the markdown and there's one commit for the test (`L1S1Q`) and an optional commit for the solution (`L1S1A`)
149+
- Push your changes to github with `git push origin v0.1.0`
150+
151+
### Create the YAML file
152+
- Go back your your master branch with `git checkout master`
153+
You can think of these two branches like separate repositories, the branches will never merge and the files will always be different, even if some look the same.
154+
- Create a new file named `coderoad.yaml` and add this to it:
155+
156+
```yml
157+
version: '0.1.0'
158+
config:
159+
testRunner:
160+
command: ./node_modules/.bin/mocha
161+
args:
162+
tap: --reporter=mocha-tap-reporter
163+
setup:
164+
commands:
165+
- npm install
166+
directory: coderoad
167+
repo:
168+
uri: https://github.com/moT01/first-tut
169+
branch: v0.1.0
170+
dependencies:
171+
- name: node
172+
version: '>=10'
173+
levels:
174+
- id: L1
175+
steps:
176+
- id: L1S1
177+
setup:
178+
subtasks: false
179+
```
180+
181+
Replace the `repo uri` URL with your github repo, note that it's just the username and repo in the URL. This file links everything together. You can see the repo URL and the branch that you created. And the `L1` and `L1S1` id's that match the markdown. You can also add commands that will run when a lesson is started, as well as a host of other things.
182+
183+
- Add this with `git add .`
184+
- Commit it with `git commit -m "create yaml"`
185+
186+
The commit messages on master can be whatever you want.
187+
- Push it to github with `git push origin master`
188+
189+
### Build the config.json file
190+
You created the three things a tutorial needs from you; the markdown, the commits, and the yaml. Now you can build it. If you haven't installed the CodeRoad CLI tools, use `npm install -g @coderoad/cli` to do so.
191+
- Run `coderoad build` from the terminal on the master branch
192+
193+
If you didn't get any errors, it will have created a `tutorial.json` file which is what CodeRoad uses to find all the files, commits, and instructions you created. You should see it in your repo now.
194+
195+
### Open your tutorial
196+
To check out your tutorial, install the CodeRoad extension to VS Code if you haven't already
197+
- Open a new VS Code window
198+
- Put a **single empty folder** in the workspace
199+
- Open the command palette with `ctrl+shift+p`
200+
- Enter `CodeRoad: Start` in the search to start CodeRoad
201+
- Click `Start New Tutorial`
202+
- Click the `File` option
203+
- Click `Upload`
204+
- Find the `tutorial.json` file that you created in your repo folder and upload it
205+
206+
### Review
207+
Success! You can see the introduction page. It may not be a bad idea to take a look at the markdown file again to see it next to the running tutorial.
208+
209+
Notice that when you click the `start` button, you can see that `npm install` is run in the `coderoad` folder, and the dependencies are installed. This is an instruction in your `coderoad.yaml` file.
210+
211+
After you click start, open up any file and press `cmd+s` to save. This will run the tests. They should fail. After that, create the `index.html` file, and save it. The tests should run and pass this time :smile:
212+
213+
Keep this VS Code window open and go back to your other one.
214+
215+
### Add a second lesson
216+
Your tutorial probably needs more than one lesson.
217+
- Go back to the markdown file and add this at the bottom (make sure there's an empty line between the two lessons):
218+
219+
```md
220+
## L2 Add DOCTYPE
221+
222+
> Add a DOCTYPE to an HTML file
223+
224+
HTML files should have a `DOCTYPE`. You can add one at the top of the `index.html` file like this: `<!DOCTYPE html>`.
225+
226+
### L2S1
227+
228+
Add the DOCTYPE
229+
230+
#### HINTS
231+
232+
* Add `<!DOCTYPE html>` at the top of `index.html` and save the file
233+
```
234+
235+
#### Use git to:
236+
- Add all the files
237+
- Commit the files with any message
238+
- Push the changes to github
239+
240+
### Add second lesson test
241+
- Checkout your version branch again
242+
- Add a new test to your `.test` file below the other one, it can look like this:
243+
244+
```js
245+
const readFile = util.promisify(fs.readFile);
246+
const getIndexFile = async (dir = process.cwd()) => {
247+
const pathToIndex = path.join(dir, '..', 'index.html');
248+
const indexFile = await readFile(pathToIndex);
249+
250+
if (!indexFile) {
251+
throw new Error(`Could not find ${pathToIndex}`);
252+
}
253+
return indexFile;
254+
}
255+
256+
describe("index.html", () => {
257+
let indexFile;
258+
before(async () => {
259+
indexFile = await getIndexFile();
260+
});
261+
262+
it('should have a DOCTYPE', () => {
263+
assert(/<!doctype html>/i.test(indexFile));
264+
});
265+
});
266+
```
267+
268+
That should check if `<!DOCTYPE html>` was added to the `index.html` file.
269+
- Run the test to make sure it fails (`npm run programmatic-test` from the `coderoad` folder)
270+
271+
There should be one passing and one failing test
272+
- Add `!<DOCTYPE html>` to the `index.html` file
273+
- Run the test again to see if it passed after adding that
274+
275+
### Commit second test
276+
#### Go to the root folder and:
277+
- Add **only** the `.test` file to git to be committed
278+
- Commit it with a message of "L2S1Q"
279+
- Add the `index.html` file to be committed
280+
- Commit it with a message of "L2S1A"
281+
- Push your changes to github to your `v0.1.0` branch
282+
283+
### Update the YAML
284+
You added another lesson in the markdown, and the tests for it. Just need to update the YAML
285+
- Go back to the master branch
286+
- Add this at the bottom of the `.yaml` file, make sure the indentation is perfect and aligns with the first lesson:
287+
288+
```yml
289+
- id: L2
290+
steps:
291+
- id: L2S1
292+
setup:
293+
files:
294+
- index.html
295+
```
296+
297+
- Add, Commit, and Push your changes
298+
299+
### Rebuild
300+
- Run `coderoad build` again on your master branch (cross your fingers).
301+
302+
### Restart the tutorial
303+
- Go back to your CodeRoad tutorial if its still open
304+
- In order to start over, close CodeRoad
305+
- Delete All the files from the workspace, but leave the top level folder there
306+
- Start CodeRoad back up
307+
- Start a new tutorial using the `tutorial.json` file you just created.
308+
309+
You should have two lessons to go through now :smile:

0 commit comments

Comments
 (0)