Skip to content

Commit 481e9f4

Browse files
committed
remove chapters, refactor, 0.5 release
1 parent a081f3c commit 481e9f4

36 files changed

+302
-456
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
All notable changes to this project will be documented in this file.
33
This project adheres to [Semantic Versioning](http://semver.org/).
44

5+
## [0.5.0] - 2016-05-02
6+
- bug fixes
7+
- remove 'chapters', now only 'pages'
8+
59
## [0.4.2]
610
- same line '✓' output
711
- bug fixes

lib/build/build.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,13 @@ function build(lines) {
88
var result = {
99
info: {
1010
title: '',
11-
description: ''
11+
description: '',
1212
},
13-
chapters: []
13+
pages: []
1414
};
1515
var index = {
16-
chapter: -1,
1716
page: -1,
18-
task: -1
17+
task: -1,
1918
};
2019
return info_1.info(result, lines, index);
2120
}

lib/build/lint.js

Lines changed: 20 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
var chalk_1 = require('chalk');
33
var validKeys = {
44
info: ['title', 'description'],
5-
chapter: ['title', 'description', 'pages'],
65
page: ['title', 'description', 'onPageComplete', 'tasks', 'video', 'link'],
76
task: ['description', 'tests', 'actions', 'hints']
87
};
@@ -18,58 +17,39 @@ function lintOutput(json) {
1817
});
1918
}
2019
});
21-
json.chapters.forEach(function (chapter, cIndex) {
22-
var chKeys = Object.keys(chapter);
23-
chKeys.forEach(function (key) {
24-
if (validKeys.chapter.indexOf(key) < 0) {
20+
json.pages.forEach(function (page, pIndex) {
21+
var pKeys = Object.keys(page);
22+
pKeys.forEach(function (key) {
23+
if (validKeys.page.indexOf(key) < 0) {
2524
invalidKeys.push({
26-
error: "Invalid Chapter key \"" + key + "\"",
27-
location: "ch: " + (cIndex + 1)
25+
error: "Invalid Page key \"" + key + "\"",
26+
location: "page: " + (pIndex + 1)
2827
});
2928
}
3029
});
31-
if (chapter.pages && chapter.pages.length > 0) {
32-
chapter.pages.forEach(function (page, pIndex) {
33-
var pKeys = Object.keys(page);
34-
pKeys.forEach(function (key) {
35-
if (validKeys.page.indexOf(key) < 0) {
30+
if (page.tasks && page.tasks.length > 0) {
31+
page.tasks.forEach(function (task, tIndex) {
32+
var tKeys = Object.keys(task);
33+
tKeys.forEach(function (key) {
34+
if (validKeys.task.indexOf(key) < 0) {
3635
invalidKeys.push({
37-
error: "Invalid Page key \"" + key + "\"",
38-
location: "ch: " + (cIndex + 1) + ", page: " + (pIndex + 1)
36+
error: "Invalid Task key \"" + key + "\"",
37+
location: "page: " + (pIndex + 1) + ", task: " + (tIndex + 1)
3938
});
4039
}
4140
});
42-
if (page.tasks && page.tasks.length > 0) {
43-
page.tasks.forEach(function (task, tIndex) {
44-
var tKeys = Object.keys(task);
45-
tKeys.forEach(function (key) {
46-
if (validKeys.task.indexOf(key) < 0) {
47-
invalidKeys.push({
48-
error: "Invalid Task key \"" + key + "\"",
49-
location: "ch: " + (cIndex + 1) + ", page: " + (pIndex + 1) + ", task: " + (tIndex + 1)
50-
});
51-
}
52-
});
53-
if (!task.tests || task.tests.length < 1) {
54-
invalidKeys.push({
55-
error: 'Missing Task Test',
56-
location: "ch: " + (cIndex + 1) + ", page: " + (pIndex + 1) + ", task: " + (tIndex + 1)
57-
});
58-
}
59-
});
60-
}
61-
else {
62-
warningKeys.push({
63-
warning: 'Missing page tasks',
64-
location: "ch: " + (cIndex + 1) + ", page: " + (pIndex + 1)
41+
if (!task.tests || task.tests.length < 1) {
42+
invalidKeys.push({
43+
error: 'Missing Task Test',
44+
location: "page: " + (pIndex + 1) + ", task: " + (tIndex + 1)
6545
});
6646
}
6747
});
6848
}
6949
else {
7050
warningKeys.push({
71-
warning: 'Missing pages',
72-
location: "ch: " + (cIndex + 1)
51+
warning: 'Missing page tasks',
52+
location: "page: " + (pIndex + 1)
7353
});
7454
}
7555
});
@@ -104,7 +84,7 @@ function hasTutorialInfo(json) {
10484
}
10585
exports.hasTutorialInfo = hasTutorialInfo;
10686
function hasPage(json) {
107-
if (!(json.chapters[0].pages.length > 0 && !!json.chapters[0].pages[0].title)) {
87+
if (!(json.pages.length > 0 && !!json.pages[0].title)) {
10888
console.log(chalk_1.red('\nYour tutorial requires at least one page.'));
10989
process.exit(1);
11090
}

lib/build/parser/actions.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,30 @@
22
var cleanup_1 = require('./cleanup');
33
var match_1 = require('./match');
44
function doAction(type, isArray, actionValue, result, line, _a) {
5-
var chapter = _a.chapter, page = _a.page, task = _a.task;
6-
if (result.chapters[chapter].pages[page].tasks[task][type] === undefined) {
7-
result.chapters[chapter].pages[page].tasks[task][type] = [];
5+
var page = _a.page, task = _a.task;
6+
if (result.pages[page].tasks[task][type] === undefined) {
7+
result.pages[page].tasks[task][type] = [];
88
}
9-
var current = result.chapters[chapter].pages[page].tasks[task][type];
9+
var current = result.pages[page].tasks[task][type];
1010
if (!!isArray) {
1111
var values_1 = cleanup_1.trimArray(actionValue);
1212
values_1.forEach(function (value) {
1313
if (current.indexOf(value) === -1 && values_1.indexOf(value) === -1) {
14-
result.chapters[chapter].pages[page].tasks[task][type].push(value);
14+
result.pages[page].tasks[task][type].push(value);
1515
}
1616
});
1717
}
1818
else {
1919
if (current.indexOf(actionValue) === -1) {
20-
result.chapters[chapter].pages[page].tasks[task][type].push(actionValue);
20+
result.pages[page].tasks[task][type].push(actionValue);
2121
}
2222
}
2323
return result;
2424
}
2525
function addToTasks(result, line, index) {
2626
var action = match_1.isAction(line);
27-
var chapter = index.chapter, page = index.page, task = index.task;
28-
var currentTask = result.chapters[chapter].pages[page].tasks[task];
27+
var page = index.page, task = index.task;
28+
var currentTask = result.pages[page].tasks[task];
2929
var trimmedContent = line.slice(action.length + 2, line.length - 1);
3030
var actionValue = cleanup_1.trimQuotes(trimmedContent);
3131
var isActionArray = match_1.isArray(cleanup_1.trimQuotes(actionValue));
@@ -40,18 +40,18 @@ function addToTasks(result, line, index) {
4040
break;
4141
case 'action':
4242
if (currentTask.actions === undefined) {
43-
result.chapters[chapter].pages[page].tasks[task].actions = [];
43+
result.pages[page].tasks[task].actions = [];
4444
}
4545
if (!!isActionArray) {
4646
var arrayOfActions = JSON.parse(isActionArray);
4747
arrayOfActions.forEach(function (value) {
4848
value = cleanup_1.trimCommandValue(cleanup_1.trimQuotes(value.trim()));
49-
result.chapters[chapter].pages[page].tasks[task].actions.push(value);
49+
result.pages[page].tasks[task].actions.push(value);
5050
});
5151
}
5252
else {
5353
var value = cleanup_1.trimCommandValue(actionValue);
54-
result.chapters[chapter].pages[page].tasks[task].actions.push(value);
54+
result.pages[page].tasks[task].actions.push(value);
5555
}
5656
return result;
5757
default:

lib/build/parser/cleanup.js

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -76,22 +76,15 @@ function cleanup(result) {
7676
if (result.info.description) {
7777
result.info.description = trimLineBreaks(result.info.description);
7878
}
79-
if (result.chapters) {
80-
result.chapters.map(function (chapter) {
81-
if (chapter.description) {
82-
chapter.description = trimLineBreaks(chapter.description);
79+
if (result.pages) {
80+
result.pages.map(function (page) {
81+
if (page.description) {
82+
page.description = trimLineBreaks(page.description);
8383
}
84-
if (chapter.pages) {
85-
chapter.pages.map(function (page) {
86-
if (page.description) {
87-
page.description = trimLineBreaks(page.description);
88-
}
89-
if (page.tasks) {
90-
page.tasks.map(function (task) {
91-
if (task.description) {
92-
task.description = trimLineBreaks(task.description);
93-
}
94-
});
84+
if (page.tasks) {
85+
page.tasks.map(function (task) {
86+
if (task.description) {
87+
task.description = trimLineBreaks(task.description);
9588
}
9689
});
9790
}

lib/build/parser/info.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"use strict";
22
var Match = require('./match');
3-
var chapter_1 = require('./chapter');
3+
var page_1 = require('./page');
44
var import_1 = require('./import');
55
function info(result, lines, index) {
66
var inCodeBlock = false;
@@ -23,8 +23,8 @@ function info(result, lines, index) {
2323
case !!Match.info(line):
2424
result.info.title = Match.info(line).trim();
2525
continue;
26-
case !!Match.chapter(line):
27-
return chapter_1.chapter(result, lines.slice(i), index);
26+
case !!Match.page(line):
27+
return page_1.page(result, lines.slice(i), index);
2828
default:
2929
if (i > 1) {
3030
result.info.description += '\n';

lib/build/parser/match.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ function match(char, times) {
66
var regex = {
77
'#': match('#', 1),
88
'##': match('#', 2),
9-
'###': match('#', 3),
109
'+': match('\\+', 1),
1110
'```': match('`', 3),
1211
'action': /^@(action|test|hint|openConsole)/,
@@ -27,8 +26,7 @@ function parseWithCode(code) {
2726
};
2827
}
2928
exports.info = parseWithCode('#');
30-
exports.chapter = parseWithCode('##');
31-
exports.page = parseWithCode('###');
29+
exports.page = parseWithCode('##');
3230
exports.task = parseWithCode('+');
3331
exports.codeBlock = parseWithCode('```');
3432
exports.isAction = parseWithCode('action');

lib/build/parser/page.js

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
"use strict";
22
var Match = require('./match');
3-
var chapter_1 = require('./chapter');
43
var task_1 = require('./task');
54
var import_1 = require('./import');
65
var cleanup_1 = require('./cleanup');
76
function page(result, lines, index) {
87
index.page += 1;
98
index.task = -1;
10-
result.chapters[index.chapter].pages.push({
9+
result.pages.push({
1110
title: Match.page(lines[0]).trim(),
1211
description: ''
1312
});
@@ -28,34 +27,32 @@ function page(result, lines, index) {
2827
: Match.isPageComplete(line);
2928
bracketCount = cleanup_1.bracketTracker(currentPageComplete);
3029
if (bracketCount === 0) {
31-
result.chapters[index.chapter].pages[index.page].onPageComplete = cleanup_1.trimValue(currentPageComplete);
30+
result.pages[index.page].onPageComplete = cleanup_1.trimValue(currentPageComplete);
3231
currentPageComplete = null;
3332
}
3433
continue;
3534
case !!Match.codeBlock(line):
3635
if (line.length > 3) {
37-
result.chapters[index.chapter].pages[index.page].description += '\n' + line;
36+
result.pages[index.page].description += '\n' + line;
3837
}
3938
else {
4039
inCodeBlock = !inCodeBlock;
4140
}
4241
continue;
4342
case inCodeBlock:
4443
continue;
45-
case !!Match.chapter(line):
46-
return chapter_1.chapter(result, lines.slice(i), index);
4744
case !!Match.page(line):
4845
return page(result, lines.slice(i), index);
4946
case !!Match.task(line):
50-
if (result.chapters[index.chapter].pages[index.page].tasks === undefined) {
51-
result.chapters[index.chapter].pages[index.page].tasks = [];
47+
if (result.pages[index.page].tasks === undefined) {
48+
result.pages[index.page].tasks = [];
5249
}
5350
return task_1.task(result, lines.slice(i), index);
5451
default:
5552
if (i > 1) {
56-
result.chapters[index.chapter].pages[index.page].description += '\n';
53+
result.pages[index.page].description += '\n';
5754
}
58-
result.chapters[index.chapter].pages[index.page].description += line;
55+
result.pages[index.page].description += line;
5956
continue;
6057
}
6158
}

lib/build/parser/settings.js

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,2 @@
11
"use strict";
2-
var fs_1 = require('fs');
3-
var path_1 = require('path');
4-
var chalk_1 = require('chalk');
5-
var settings = null;
6-
try {
7-
settings = JSON.parse(fs_1.readFileSync(path_1.join(process.cwd(), 'package.json'), 'utf8'));
8-
}
9-
catch (e) {
10-
console.log(chalk_1.red('No package.json config found in directory ', process.cwd(), e));
11-
}
12-
exports.tutorialDir = settings.dir || 'tutorial';
2+
exports.tutorialDir = 'tutorial';

lib/build/parser/task.js

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
"use strict";
22
var Match = require('./match');
3-
var chapter_1 = require('./chapter');
43
var page_1 = require('./page');
54
var actions_1 = require('./actions');
65
var cleanup_1 = require('./cleanup');
76
var import_1 = require('./import');
87
function task(result, lines, index) {
9-
result.chapters[index.chapter].pages[index.page].tasks.push({
8+
result.pages[index.page].tasks.push({
109
description: cleanup_1.trimLeadingSpaces(Match.task(lines[0]))
1110
});
1211
index.task += 1;
@@ -28,7 +27,7 @@ function task(result, lines, index) {
2827
: Match.isPageComplete(line);
2928
bracketCount = cleanup_1.bracketTracker(currentPageComplete);
3029
if (bracketCount === 0) {
31-
result.chapters[index.chapter].pages[index.page].onPageComplete = cleanup_1.trimValue(currentPageComplete);
30+
result.pages[index.page].onPageComplete = cleanup_1.trimValue(currentPageComplete);
3231
currentPageComplete = null;
3332
}
3433
continue;
@@ -50,9 +49,9 @@ function task(result, lines, index) {
5049
case !Match.isAction(line) && !!Match.codeBlock(line):
5150
if (line.length > 3) {
5251
if (i > 0) {
53-
result.chapters[index.chapter].pages[index.page].tasks[index.task].description += '\n';
52+
result.pages[index.page].tasks[index.task].description += '\n';
5453
}
55-
result.chapters[index.chapter].pages[index.page].tasks[index.task].description += line;
54+
result.pages[index.page].tasks[index.task].description += line;
5655
}
5756
else {
5857
inCodeBlock = !inCodeBlock;
@@ -70,13 +69,11 @@ function task(result, lines, index) {
7069
return task(result, lines.slice(i), index);
7170
case !!Match.page(line):
7271
return page_1.page(result, lines.slice(i), index);
73-
case !!Match.chapter(line):
74-
return chapter_1.chapter(result, lines.slice(i), index);
7572
default:
7673
if (i > 0) {
77-
result.chapters[index.chapter].pages[index.page].tasks[index.task].description += '\n';
74+
result.pages[index.page].tasks[index.task].description += '\n';
7875
}
79-
result.chapters[index.chapter].pages[index.page].tasks[index.task].description += line;
76+
result.pages[index.page].tasks[index.task].description += line;
8077
}
8178
}
8279
return result;

0 commit comments

Comments
 (0)