Skip to content

Commit da83847

Browse files
committed
tslinting, @onComplete
1 parent 18f57bf commit da83847

File tree

25 files changed

+64
-78
lines changed

25 files changed

+64
-78
lines changed

lib/build/parser/actions.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ function addToTasks(result, line, index) {
4040
result = doAction('hints', isActionArray, actionValue, result, line, index);
4141
break;
4242
case 'continue':
43-
result = doAction('continue', isActionArray, actionValue, result, line, index);
43+
break;
4444
case 'action':
4545
if (task.actions === undefined) {
4646
result.chapters[index.chapter].pages[index.page].tasks[index.task].actions = [];

lib/build/parser/chapter.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ function chapter(result, lines, index) {
2525
continue;
2626
}
2727
inCodeBlock = !inCodeBlock;
28-
case inCodeBlock:
2928
continue;
3029
case !!Match.page(line):
3130
return page_1.page(result, lines.slice(i), index);

lib/build/parser/match.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"use strict";
2+
var cleanup_1 = require('./cleanup');
23
function match(char, times) {
34
return new RegExp('^' + char + '{' + times + '}(?!#)(.*?)$', 'gm');
45
}
@@ -10,15 +11,15 @@ var regex = {
1011
'```': match('`', 3),
1112
'action': /^@(action|test|hint|continue)/,
1213
'import': /^@import\((.+)\)$/,
13-
'continue': /^@continue/
14+
'onComplete': /^@onComplete\((.+)\)$/
1415
};
1516
function parseWithCode(code) {
1617
return function (line) {
1718
if (!line) {
1819
return null;
1920
}
2021
if (line.match(regex[code])) {
21-
return regex[code].exec(line)[1];
22+
return cleanup_1.trimQuotes(regex[code].exec(line)[1]);
2223
}
2324
else {
2425
return null;
@@ -32,7 +33,7 @@ exports.task = parseWithCode('+');
3233
exports.codeBlock = parseWithCode('```');
3334
exports.isAction = parseWithCode('action');
3435
exports.isImport = parseWithCode('import');
35-
exports.isContinue = parseWithCode('continue');
36+
exports.isComplete = parseWithCode('onComplete');
3637
exports.isArray = function (line) {
3738
var isMatch = line.match(/^\[.+\]$/);
3839
return isMatch ? isMatch[0] : null;

lib/build/parser/page.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,14 @@ var task_1 = require('./task');
55
var import_1 = require('./import');
66
var cleanup_1 = require('./cleanup');
77
function page(result, lines, index) {
8-
var hasBreak = null;
98
index.page += 1;
109
index.task = -1;
1110
result.chapters[index.chapter].pages.push({
1211
title: Match.page(lines[0]).trim(),
1312
description: ''
1413
});
1514
var inCodeBlock = false;
16-
var currentContinue = null;
15+
var currentComplete = null;
1716
var bracketCount = 0;
1817
var i = 0;
1918
while (i < lines.length - 1) {
@@ -26,19 +25,20 @@ function page(result, lines, index) {
2625
case !!Match.codeBlock(line):
2726
if (line.length > 3) {
2827
result.chapters[index.chapter].pages[index.page].description += '\n' + line;
29-
continue;
3028
}
31-
inCodeBlock = !inCodeBlock;
29+
else {
30+
inCodeBlock = !inCodeBlock;
31+
}
32+
continue;
3233
case inCodeBlock:
3334
continue;
34-
case !!Match.isContinue(line) || !!currentContinue:
35-
currentContinue = currentContinue ? currentContinue += line : line;
35+
case !!Match.isComplete(line) || !!currentComplete:
36+
currentComplete = currentComplete ? currentComplete += line : Match.isComplete(line);
3637
bracketCount = cleanup_1.bracketTracker(line);
3738
if (bracketCount === 0) {
38-
result.chapters[index.chapter].pages[index.page].continue = currentContinue;
39-
currentContinue = null;
39+
result.chapters[index.chapter].pages[index.page].onComplete = currentComplete;
40+
currentComplete = null;
4041
}
41-
console.log(line);
4242
continue;
4343
case !!Match.chapter(line):
4444
return chapter_1.chapter(result, lines.slice(i), index);

lib/build/parser/project.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ function project(result, lines, index) {
1515
case !!Match.codeBlock(line):
1616
if (line.length > 3) {
1717
result.project.description += line;
18-
continue;
1918
}
20-
inCodeBlock = !inCodeBlock;
21-
case inCodeBlock:
19+
else {
20+
inCodeBlock = !inCodeBlock;
21+
}
2222
continue;
2323
case !!Match.project(line):
2424
result.project.title = Match.project(line).trim();

lib/list/list.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"use strict";
22
var chalk = require('chalk');
33
function tutorials() {
4-
console.log("List of tutorial packages...");
4+
console.log('List of tutorial packages...');
55
console.log(chalk.red('"Tutorials" feature not implemented yet.'));
66
}
77
exports.tutorials = tutorials;

lib/publish/validate.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ var file_1 = require('../tools/file');
55
function incrementVersion(version) {
66
var finalDot = version.lastIndexOf('.');
77
var start = version.substring(0, finalDot + 1);
8-
var patch = parseInt(version.substring(finalDot + 1, version.length)) + 1;
8+
var patch = parseInt(version.substring(finalDot + 1, version.length), 10) + 1;
99
return start + patch;
1010
}
1111
function versionIsGreaterThanCurrent(version) {
@@ -14,7 +14,7 @@ function versionIsGreaterThanCurrent(version) {
1414
process.exit(1);
1515
}
1616
var currentVersion = JSON.parse(fs.readFileSync('package.json', 'utf8')).version;
17-
if (parseInt(version) <= parseInt(currentVersion)) {
17+
if (parseInt(version, 10) <= parseInt(currentVersion, 10)) {
1818
console.log(chalk.yellow("\n Published version is not larger than current version.\n Current: \"" + currentVersion + "\"\n > coderoad publish \"" + incrementVersion(currentVersion) + "\"\n "));
1919
process.exit(1);
2020
}

src/build/build.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ function build(lines: string[]): CR.Output {
1111
description: ''
1212
},
1313
chapters: []
14-
}
14+
};
1515
let index = {
1616
chapter: -1,
1717
page: -1,
@@ -33,8 +33,5 @@ export default function(filePath: string, output = './coderoad.json'): void {
3333
// Safe to Write coderoad.json
3434
fs.writeFileSync(output, result, 'utf8');
3535
}
36-
3736
createReadme();
38-
39-
4037
}

src/build/parser/actions.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ function doAction(type: CR.OutputAction, isArray, actionValue, result, line, ind
2020
valueList.forEach((value) => {
2121
value = trimQuotes(value.trim(), true);
2222
result.chapters[index.chapter].pages[index.page].tasks[index.task][type].push(value);
23-
})
23+
});
2424
} else {
2525
result.chapters[index.chapter].pages[index.page].tasks[index.task][type].push(actionValue);
2626
}
2727
return result;
2828
}
2929

3030
export function addToTasks(result, line, index) {
31-
let action: CR.TaskAction|string = Match.isAction(line); //: 'action'|'test'|'hint'|'continue'
31+
let action: CR.TaskAction|string = Match.isAction(line); // 'action'|'test'|'hint'|'continue'
3232
let task: CR.Task = result.chapters[index.chapter].pages[index.page].tasks[index.task];
3333
let trimmedContent: string = line.slice(action.length + 2, line.length - 1); // content between brackets
3434
let actionValue: string = trimQuotes(trimmedContent);
@@ -41,7 +41,7 @@ export function addToTasks(result, line, index) {
4141
result = doAction('hints', isActionArray, actionValue, result, line, index);
4242
break;
4343
case 'continue':
44-
result = doAction('continue', isActionArray, actionValue, result, line, index);
44+
break;
4545
case 'action':
4646
if (task.actions === undefined) {
4747
result.chapters[index.chapter].pages[index.page].tasks[index.task].actions = [];
@@ -52,8 +52,7 @@ export function addToTasks(result, line, index) {
5252
value = trimCommandValue(trimQuotes(value.trim()));
5353
result.chapters[index.chapter].pages[index.page].tasks[index.task].actions.push(value);
5454
});
55-
}
56-
else {
55+
} else {
5756
let value: string = trimCommandValue(actionValue);
5857
result.chapters[index.chapter].pages[index.page].tasks[index.task].actions.push(value);
5958
}

src/build/parser/chapter.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import * as Match from './match';
22
import {page} from './page';
33
import {loadImport} from './import';
4-
import {trimLineBreaks} from './cleanup';
54

65
export function chapter(result: CR.Output, lines: string[], index: CR.Index): CR.Output {
76
index.page = -1;
@@ -31,7 +30,6 @@ export function chapter(result: CR.Output, lines: string[], index: CR.Index): CR
3130
continue;
3231
}
3332
inCodeBlock = !inCodeBlock;
34-
case inCodeBlock:
3533
continue;
3634

3735
// ###

0 commit comments

Comments
 (0)