Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 3650763

Browse files
committedSep 17, 2016
add final page parsing
1 parent e87de1a commit 3650763

24 files changed

+194
-102
lines changed
 

‎CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
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.10.0] - 2016-09-16
6+
- add to parser:
7+
- `@resource([link to resource](http://path/to/link))` - collect helpful resource links
8+
- `## Final` fill in the content for the final page after tutorial completion. Matches on page title "Final".
9+
510
## [0.9.1] - 2016-09-15
611
- find tutorials now returns "isLatest" (bool) & "latest": (string of version)
712

‎lib/build/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ function parseAndBuild(dir, lines) {
1717
page: -1,
1818
task: -1,
1919
};
20-
return info_1.info({ dir: dir, result: result, lines: lines, index: index });
20+
return info_1.default({ dir: dir, result: result, lines: lines, index: index });
2121
}
2222
function build(_a) {
2323
var dir = _a.dir, filePath = _a.filePath, _b = _a.output, output = _b === void 0 ? './coderoad.json' : _b;

‎lib/build/lint.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
var chalk_1 = require('chalk');
33
var validKeys = {
44
info: ['title', 'description'],
5-
page: ['title', 'description', 'onPageComplete', 'tasks', 'video', 'link'],
5+
page: ['title', 'description', 'onPageComplete', 'tasks', 'video', 'resource'],
66
task: ['description', 'tests', 'actions', 'hints']
77
};
88
function lintOutput(json) {

‎lib/build/parser/actions.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,16 @@ function addToTasks(_a) {
4747
task: task,
4848
});
4949
break;
50+
case 'resource':
51+
result = doAction({
52+
type: 'resource',
53+
isArray: isActionArray,
54+
actionValue: actionValue,
55+
result: result,
56+
page: page,
57+
task: task
58+
});
59+
break;
5060
case 'continue':
5161
break;
5262
case 'action':

‎lib/build/parser/final.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
"use strict";
2+
var Match = require('./match');
3+
var import_1 = require('./import');
4+
function final(_a) {
5+
var dir = _a.dir, result = _a.result, lines = _a.lines;
6+
var inCodeBlock = false;
7+
var currentPageComplete = null;
8+
var bracketCount = 0;
9+
result.final = {
10+
description: '',
11+
};
12+
var i = 0;
13+
while (i < lines.length - 1) {
14+
i += 1;
15+
var line = lines[i];
16+
switch (true) {
17+
case !!Match.isImport(line):
18+
lines = import_1.default({ dir: dir, lines: lines, pathToMd: Match.isImport(line) });
19+
continue;
20+
case !!Match.codeBlock(line):
21+
if (line.length > 3) {
22+
result.final.description += '\n' + line;
23+
}
24+
else {
25+
inCodeBlock = !inCodeBlock;
26+
}
27+
continue;
28+
case inCodeBlock:
29+
continue;
30+
default:
31+
if (i > 1) {
32+
result.final.description += '\n';
33+
}
34+
result.final.description += line;
35+
continue;
36+
}
37+
}
38+
return result;
39+
}
40+
Object.defineProperty(exports, "__esModule", { value: true });
41+
exports.default = final;

‎lib/build/parser/import.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,5 @@ function loadImport(_a) {
2424
var splitLines = importLines.split('\n');
2525
return lines.concat(splitLines);
2626
}
27-
exports.loadImport = loadImport;
27+
Object.defineProperty(exports, "__esModule", { value: true });
28+
exports.default = loadImport;

‎lib/build/parser/info.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ function info(_a) {
1111
var line = lines[i];
1212
switch (true) {
1313
case !!Match.isImport(line):
14-
lines = import_1.loadImport({ dir: dir, lines: lines, pathToMd: Match.isImport(line) });
14+
lines = import_1.default({ dir: dir, lines: lines, pathToMd: Match.isImport(line) });
1515
continue;
1616
case !!Match.codeBlock(line):
1717
if (line.length > 3) {
@@ -25,7 +25,7 @@ function info(_a) {
2525
result.info.title = Match.info(line).trim();
2626
continue;
2727
case !!Match.page(line):
28-
return page_1.page({ dir: dir, result: result, lines: lines.slice(i), index: index });
28+
return page_1.default({ dir: dir, result: result, lines: lines.slice(i), index: index });
2929
default:
3030
if (i > 1) {
3131
result.info.description += '\n';
@@ -35,4 +35,5 @@ function info(_a) {
3535
}
3636
return result;
3737
}
38-
exports.info = info;
38+
Object.defineProperty(exports, "__esModule", { value: true });
39+
exports.default = info;

‎lib/build/parser/match.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ var regex = {
88
'##': match('#', 2),
99
'+': match('\\+', 1),
1010
'```': match('`', 3),
11-
'action': /^@(action|test|hint|openConsole|write|writeFromFile)/,
11+
'action': /^@(action|test|hint|openConsole|resource)/,
1212
'import': /^@import\((.+)\)$/,
13-
'onPageComplete': /^(@onPageComplete.+)/
13+
'onPageComplete': /^(@onPageComplete.+)/,
1414
};
1515
function parseWithCode(code) {
1616
return function (line) {

‎lib/build/parser/page.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,18 @@
22
var Match = require('./match');
33
var task_1 = require('./task');
44
var import_1 = require('./import');
5+
var final_1 = require('./final');
56
var cleanup_1 = require('./cleanup');
67
function page(_a) {
78
var dir = _a.dir, result = _a.result, lines = _a.lines, index = _a.index;
89
index.page += 1;
910
index.task = -1;
11+
var title = Match.page(lines[0]);
12+
if (title === 'Final') {
13+
return final_1.default({ dir: dir, result: result, lines: lines });
14+
}
1015
result.pages.push({
11-
title: Match.page(lines[0]),
16+
title: title,
1217
description: ''
1318
});
1419
var inCodeBlock = false;
@@ -20,7 +25,7 @@ function page(_a) {
2025
var line = lines[i];
2126
switch (true) {
2227
case !!Match.isImport(line):
23-
lines = import_1.loadImport({ dir: dir, lines: lines, pathToMd: Match.isImport(line) });
28+
lines = import_1.default({ dir: dir, lines: lines, pathToMd: Match.isImport(line) });
2429
continue;
2530
case (!!Match.isPageComplete(line) || !!currentPageComplete):
2631
currentPageComplete = !!currentPageComplete
@@ -48,7 +53,7 @@ function page(_a) {
4853
if (result.pages[index.page].tasks === undefined) {
4954
result.pages[index.page].tasks = [];
5055
}
51-
return task_1.task({ dir: dir, result: result, lines: lines.slice(i), index: index });
56+
return task_1.default({ dir: dir, result: result, lines: lines.slice(i), index: index });
5257
default:
5358
if (i > 1) {
5459
result.pages[index.page].description += '\n';
@@ -59,4 +64,5 @@ function page(_a) {
5964
}
6065
return result;
6166
}
62-
exports.page = page;
67+
Object.defineProperty(exports, "__esModule", { value: true });
68+
exports.default = page;

‎lib/build/parser/task.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ function task(_a) {
2020
var line = lines[i];
2121
switch (true) {
2222
case !!Match.isImport(line):
23-
lines = import_1.loadImport({ dir: dir, lines: lines, pathToMd: Match.isImport(line) });
23+
lines = import_1.default({ dir: dir, lines: lines, pathToMd: Match.isImport(line) });
2424
continue;
2525
case (!!Match.isPageComplete(line) || !!currentPageComplete):
2626
currentPageComplete = !!currentPageComplete
@@ -69,7 +69,7 @@ function task(_a) {
6969
case !!Match.task(line):
7070
return task({ dir: dir, result: result, lines: lines.slice(i), index: index });
7171
case !!Match.page(line):
72-
return page_1.page({ dir: dir, result: result, lines: lines.slice(i), index: index });
72+
return page_1.default({ dir: dir, result: result, lines: lines.slice(i), index: index });
7373
default:
7474
if (i > 0) {
7575
result.pages[index.page].tasks[index.task].description += '\n';
@@ -79,4 +79,5 @@ function task(_a) {
7979
}
8080
return result;
8181
}
82-
exports.task = task;
82+
Object.defineProperty(exports, "__esModule", { value: true });
83+
exports.default = task;

‎lib/build/readme.js

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ function createReadme(dir) {
2121
exports.createReadme = createReadme;
2222
function generateReadme(data, packageJson) {
2323
var readme = [];
24-
var info = data.info, pages = data.pages;
24+
var info = data.info, pages = data.pages, final = data.final;
2525
readme = readme.concat([
2626
'# ' + info.title,
2727
'',
@@ -59,16 +59,23 @@ function generateReadme(data, packageJson) {
5959
'## Outline',
6060
''
6161
]);
62-
var parsedPages = pages.map(function (page) {
63-
return [
64-
'##### ' + page.title,
65-
'',
66-
page.description,
67-
''
68-
];
69-
});
62+
var parsedPages = pages.map(function (page) { return ([
63+
'##### ' + page.title,
64+
'',
65+
page.description,
66+
''
67+
]); });
7068
parsedPages.forEach(function (page) {
7169
readme = readme.concat(page);
7270
});
71+
if (final && final.description) {
72+
readme = readme.concat([
73+
'',
74+
'## Final',
75+
'',
76+
final.description,
77+
''
78+
]);
79+
}
7380
return readme.join('\n');
7481
}

‎package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "coderoad-cli",
3-
"version": "0.9.1",
3+
"version": "0.10.0",
44
"description": "Command line interface for CodeRoad. Build project files.",
55
"keywords": [
66
"coderoad"

‎src/build/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {readFileSync, writeFileSync} from 'fs';
22
import * as validate from './validators';
3-
import {info} from './parser/info';
3+
import info from './parser/info';
44
import {createReadme} from './readme';
55
import {cleanup} from './parser/cleanup';
66
import {join} from 'path';

‎src/build/lint.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {yellow, red} from 'chalk';
22

33
const validKeys = {
44
info: ['title', 'description'],
5-
page: ['title', 'description', 'onPageComplete', 'tasks', 'video', 'link'],
5+
page: ['title', 'description', 'onPageComplete', 'tasks', 'video', 'resource'],
66
task: ['description', 'tests', 'actions', 'hints']
77
};
88

‎src/build/parser/actions.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,16 @@ export function addToTasks({ result, line, index: {page, task} }) {
5050
task,
5151
});
5252
break;
53+
case 'resource':
54+
result = doAction({
55+
type: 'resource',
56+
isArray: isActionArray,
57+
actionValue,
58+
result,
59+
page,
60+
task
61+
});
62+
break;
5363
case 'continue':
5464
break;
5565
case 'action':

‎src/build/parser/final.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import * as Match from './match';
2+
import loadImport from './import';
3+
import {bracketTracker, trimValue} from './cleanup';
4+
5+
export default function final({ dir, result, lines }) {
6+
let inCodeBlock = false;
7+
let currentPageComplete = null;
8+
let bracketCount = 0;
9+
10+
result.final = {
11+
description: '',
12+
};
13+
14+
let i = 0;
15+
while (i < lines.length - 1) {
16+
i += 1;
17+
let line = lines[i];
18+
19+
switch (true) {
20+
21+
// @import
22+
case !!Match.isImport(line):
23+
lines = loadImport({dir, lines, pathToMd: Match.isImport(line)});
24+
continue;
25+
26+
// ``` `
27+
case !!Match.codeBlock(line):
28+
if (line.length > 3) {
29+
result.final.description += '\n' + line;
30+
} else {
31+
inCodeBlock = !inCodeBlock;
32+
}
33+
continue;
34+
case inCodeBlock:
35+
continue;
36+
37+
// description
38+
default:
39+
if (i > 1) {
40+
result.final.description += '\n';
41+
}
42+
result.final.description += line;
43+
continue;
44+
}
45+
}
46+
return result;
47+
}

‎src/build/parser/import.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import fileExists from 'node-file-exists';
44
import {trimQuotes} from './cleanup';
55
import {tutorialDir} from './settings';
66

7-
export function loadImport({ dir, lines, pathToMd }): string[] {
7+
export default function loadImport({ dir, lines, pathToMd }): string[] {
88
// add .md suffix
99
pathToMd = trimQuotes(pathToMd);
1010
if (!pathToMd.match(/\.md$/)) {

‎src/build/parser/info.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import * as Match from './match';
2-
import {page} from './page';
3-
import {loadImport} from './import';
2+
import page from './page';
3+
import loadImport from './import';
44

5-
export function info({ dir, result, lines, index }): CR.Output {
5+
export default function info({ dir, result, lines, index }): CR.Output {
66
let inCodeBlock = false;
77
let i = -1;
88

‎src/build/parser/match.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ var regex = {
99
'##': match('#', 2),
1010
'+': match('\\+', 1),
1111
'```': match('`', 3),
12-
'action': /^@(action|test|hint|openConsole|write|writeFromFile)/,
12+
'action': /^@(action|test|hint|openConsole|resource)/,
1313
'import': /^@import\((.+)\)$/,
14-
'onPageComplete': /^(@onPageComplete.+)/
14+
'onPageComplete': /^(@onPageComplete.+)/,
1515
};
1616

1717
function parseWithCode(code: string) {

‎src/build/parser/page.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
import * as Match from './match';
2-
import {task} from './task';
3-
import {loadImport} from './import';
2+
import task from './task';
3+
import loadImport from './import';
4+
import final from './final';
45
import {bracketTracker, trimValue} from './cleanup';
56

6-
export function page({ dir, result, lines, index }) {
7+
export default function page({ dir, result, lines, index }) {
78
index.page += 1;
89
index.task = -1;
10+
const title = Match.page(lines[0]);
11+
if (title === 'Final') {
12+
return final({dir, result, lines});
13+
}
914
result.pages.push({
10-
title: Match.page(lines[0]),
15+
title,
1116
description: ''
1217
});
1318
let inCodeBlock = false;

‎src/build/parser/task.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import * as Match from './match';
2-
import { page } from './page';
2+
import page from './page';
33
import { addToTasks } from './actions';
44
import { trimLeadingSpaces, bracketTracker, trimValue } from './cleanup';
5-
import { loadImport } from './import';
5+
import loadImport from './import';
66

7-
export function task({ dir, result, lines, index }) {
7+
export default function task({ dir, result, lines, index }) {
88
result.pages[index.page].tasks.push({
99
description: trimLeadingSpaces(Match.task(lines[0]))
1010
});

‎src/build/readme.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import fileExists from 'node-file-exists';
33
import {red} from 'chalk';
44
import {join} from 'path';
55

6-
export function createReadme(dir): boolean {
6+
export function createReadme(dir: string): boolean {
77
// if (!fileExists('./README.md')) {
88
// }
99
if (!fileExists(join(dir, 'coderoad.json'))) {
@@ -24,7 +24,7 @@ export function createReadme(dir): boolean {
2424
function generateReadme(data: CR.Output, packageJson: PackageJson): string {
2525
let readme = [];
2626

27-
const {info, pages} = data;
27+
const {info, pages, final} = data;
2828
// title
2929
readme = readme.concat([
3030
'# ' + info.title,
@@ -65,18 +65,26 @@ function generateReadme(data: CR.Output, packageJson: PackageJson): string {
6565
'## Outline',
6666
''
6767
]);
68-
let parsedPages: string[][] = pages.map((page) => {
69-
return [
68+
let parsedPages: string[][] = pages.map((page) => ([
7069
'##### ' + page.title,
7170
'',
7271
page.description,
7372
''
74-
];
75-
});
73+
]));
7674

7775
parsedPages.forEach((page: string[]) => {
7876
readme = readme.concat(page);
7977
});
8078

79+
if (final && final.description) {
80+
readme = readme.concat([
81+
'',
82+
'## Final',
83+
'',
84+
final.description,
85+
''
86+
]);
87+
}
88+
8189
return readme.join('\n');
8290
}

‎src/typings/cr.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ declare namespace CR {
33
interface Output {
44
info: Info;
55
pages: Page[];
6+
final?: Final;
7+
}
8+
9+
interface Final {
10+
description: string;
611
}
712

813
type OutputAction = string;

‎tsconfig.json

Lines changed: 1 addition & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -12,62 +12,7 @@
1212
"src/*.ts",
1313
"src/**/*.ts"
1414
],
15-
"files": [
16-
"src/cli.ts",
17-
"src/index.ts",
18-
"src/result.ts",
19-
"src/build/index.ts",
20-
"src/build/lint.ts",
21-
"src/build/parser/actions.ts",
22-
"src/build/parser/cleanup.ts",
23-
"src/build/parser/import.ts",
24-
"src/build/parser/info.ts",
25-
"src/build/parser/match.ts",
26-
"src/build/parser/page.ts",
27-
"src/build/parser/settings.ts",
28-
"src/build/parser/task.ts",
29-
"src/build/readme.ts",
30-
"src/build/validators.ts",
31-
"src/create/index.ts",
32-
"src/create/validate.ts",
33-
"src/create/write-demo.ts",
34-
"src/publish/index.ts",
35-
"src/publish/validate.ts",
36-
"src/search/index.ts",
37-
"src/search/validate.ts",
38-
"src/tutorials/find-tutorials.ts",
39-
"src/tutorials/index.ts",
40-
"src/tutorials/is-tutorial.ts",
41-
"src/tutorials/update.ts",
42-
"src/typings/atom-plugin-command-line/index.d.ts",
43-
"src/typings/chalk/chalk.d.ts",
44-
"src/typings/commander/commander.d.ts",
45-
"src/typings/cr.d.ts",
46-
"src/typings/cr/cli.d.ts",
47-
"src/typings/cr/core.d.ts",
48-
"src/typings/cr/cr.d.ts",
49-
"src/typings/cr/globals.d.ts",
50-
"src/typings/cr/test.d.ts",
51-
"src/typings/cr/tutorial.d.ts",
52-
"src/typings/cr/validate.d.ts",
53-
"src/typings/es6-promise/es6-promise.d.ts",
54-
"src/typings/globals.d.ts",
55-
"src/typings/node-file-exists/index.d.ts",
56-
"src/typings/node/node.d.ts",
57-
"src/typings/prompt/prompt.d.ts",
58-
"src/typings/sort-package-json/index.d.ts",
59-
"src/update/index.ts",
60-
"src/utils/getJson.ts",
61-
"src/validate/coderoadJson.ts",
62-
"src/validate/index.ts",
63-
"src/validate/packageJson.ts",
64-
"src/validate/validation-messages.ts",
65-
"src/validate/validations.ts"
66-
],
6715
"exclude": [
6816
"node_modules"
69-
],
70-
"atom": {
71-
"rewriteTsconfig": true
72-
}
17+
]
7318
}

0 commit comments

Comments
 (0)
Please sign in to comment.