Skip to content

Commit 4d01bb8

Browse files
committed
update for atom-coderoad@0.7.0
1 parent ec15fa5 commit 4d01bb8

31 files changed

+181
-92
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.4]
6+
- rename "project" to "info"
7+
- rename "testDir" to "dir"
8+
- rename "testRunner" to "runner"
9+
510
## [0.3.27] - 2016-03-12
611
- lint output and show errors/warnings
712

lib/build/build.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
"use strict";
2-
var fs = require('fs');
2+
var fs_1 = require('fs');
33
var validate = require('./validators');
4-
var project_1 = require('./parser/project');
4+
var info_1 = require('./parser/info');
55
var readme_1 = require('./readme');
66
var cleanup_1 = require('./parser/cleanup');
77
function build(lines) {
88
var result = {
9-
project: {
9+
info: {
1010
title: '',
1111
description: ''
1212
},
@@ -17,15 +17,15 @@ function build(lines) {
1717
page: -1,
1818
task: -1
1919
};
20-
return project_1.project(result, lines, index);
20+
return info_1.info(result, lines, index);
2121
}
2222
function default_1(filePath, output) {
2323
if (output === void 0) { output = './coderoad.json'; }
2424
validate.filePath(filePath);
25-
var lines = fs.readFileSync(filePath, 'utf8').split('\n');
25+
var lines = fs_1.readFileSync(filePath, 'utf8').split('\n');
2626
var result = cleanup_1.cleanup(build(lines));
2727
if (validate.result(result)) {
28-
fs.writeFileSync(output, result, 'utf8');
28+
fs_1.writeFileSync(output, result, 'utf8');
2929
}
3030
readme_1.createReadme();
3131
}

lib/build/lint.js

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,76 @@
11
"use strict";
22
var chalk = require('chalk');
33
var validKeys = {
4-
project: ['title', 'description'],
4+
info: ['title', 'description'],
55
chapter: ['title', 'description', 'pages'],
66
page: ['title', 'description', 'onPageComplete', 'tasks', 'video', 'link'],
77
task: ['description', 'tests', 'actions', 'hints']
88
};
99
function lintOutput(json) {
1010
var invalidKeys = [];
1111
var warningKeys = [];
12-
var prKeys = Object.keys(json.project);
12+
var prKeys = Object.keys(json.info);
1313
prKeys.forEach(function (key) {
14-
if (validKeys.project.indexOf(key) < 0) {
15-
invalidKeys.push({ error: "Invalid Project key \"" + key + "\"", location: 'Project' });
14+
if (validKeys.info.indexOf(key) < 0) {
15+
invalidKeys.push({
16+
error: "Invalid Project key \"" + key + "\"",
17+
location: 'Project'
18+
});
1619
}
1720
});
1821
json.chapters.forEach(function (chapter, cIndex) {
1922
var chKeys = Object.keys(chapter);
2023
chKeys.forEach(function (key) {
2124
if (validKeys.chapter.indexOf(key) < 0) {
22-
invalidKeys.push({ error: "Invalid Chapter key \"" + key + "\"", location: "ch: " + (cIndex + 1) });
25+
invalidKeys.push({
26+
error: "Invalid Chapter key \"" + key + "\"",
27+
location: "ch: " + (cIndex + 1)
28+
});
2329
}
2430
});
2531
if (chapter.pages && chapter.pages.length > 0) {
2632
chapter.pages.forEach(function (page, pIndex) {
2733
var pKeys = Object.keys(page);
2834
pKeys.forEach(function (key) {
2935
if (validKeys.page.indexOf(key) < 0) {
30-
invalidKeys.push({ error: "Invalid Page key \"" + key + "\"", location: "ch: " + (cIndex + 1) + ", page: " + (pIndex + 1) });
36+
invalidKeys.push({
37+
error: "Invalid Page key \"" + key + "\"",
38+
location: "ch: " + (cIndex + 1) + ", page: " + (pIndex + 1)
39+
});
3140
}
3241
});
3342
if (page.tasks && page.tasks.length > 0) {
3443
page.tasks.forEach(function (task, tIndex) {
3544
var tKeys = Object.keys(task);
3645
tKeys.forEach(function (key) {
3746
if (validKeys.task.indexOf(key) < 0) {
38-
invalidKeys.push({ error: "Invalid Task key \"" + key + "\"", location: "ch: " + (cIndex + 1) + ", page: " + (pIndex + 1) + ", task: " + (tIndex + 1) });
47+
invalidKeys.push({
48+
error: "Invalid Task key \"" + key + "\"",
49+
location: "ch: " + (cIndex + 1) + ", page: " + (pIndex + 1) + ", task: " + (tIndex + 1)
50+
});
3951
}
4052
});
4153
if (!task.tests || task.tests.length < 1) {
42-
invalidKeys.push({ error: 'Missing Task Test', location: "ch: " + (cIndex + 1) + ", page: " + (pIndex + 1) + ", task: " + (tIndex + 1) });
54+
invalidKeys.push({
55+
error: 'Missing Task Test',
56+
location: "ch: " + (cIndex + 1) + ", page: " + (pIndex + 1) + ", task: " + (tIndex + 1)
57+
});
4358
}
4459
});
4560
}
4661
else {
47-
warningKeys.push({ warning: 'Missing page tasks', location: "ch: " + (cIndex + 1) + ", page: " + (pIndex + 1) });
62+
warningKeys.push({
63+
warning: 'Missing page tasks',
64+
location: "ch: " + (cIndex + 1) + ", page: " + (pIndex + 1)
65+
});
4866
}
4967
});
5068
}
5169
else {
52-
warningKeys.push({ warning: 'Missing pages', location: "ch: " + (cIndex + 1) });
70+
warningKeys.push({
71+
warning: 'Missing pages',
72+
location: "ch: " + (cIndex + 1)
73+
});
5374
}
5475
});
5576
if (warningKeys.length > 0) {
@@ -74,14 +95,14 @@ function isValidJSON(text) {
7495
}
7596
}
7697
exports.isValidJSON = isValidJSON;
77-
function hasProjectInfo(json) {
78-
var validTitle = json.project.title.length > 0, validDescription = json.project.description.length > 0;
98+
function hasTutorialInfo(json) {
99+
var validTitle = json.info.title.length > 0, validDescription = json.info.description.length > 0;
79100
if (!(validTitle && validDescription)) {
80101
console.log(chalk.red("\n Your tutorial is missing basic project information. Check the project title & description.\n "));
81102
process.exit(1);
82103
}
83104
}
84-
exports.hasProjectInfo = hasProjectInfo;
105+
exports.hasTutorialInfo = hasTutorialInfo;
85106
function hasPage(json) {
86107
if (!(json.chapters[0].pages.length > 0 && !!json.chapters[0].pages[0].title)) {
87108
console.log(chalk.red("\n Your tutorial requires at least one page.\n "));

lib/build/parser/actions.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"use strict";
22
var cleanup_1 = require('./cleanup');
3-
var Match = require('./match');
3+
var match_1 = require('./match');
44
function doAction(type, isArray, actionValue, result, line, _a) {
55
var chapter = _a.chapter, page = _a.page, task = _a.task;
66
if (result.chapters[chapter].pages[page].tasks[task][type] === undefined) {
@@ -23,12 +23,12 @@ function doAction(type, isArray, actionValue, result, line, _a) {
2323
return result;
2424
}
2525
function addToTasks(result, line, index) {
26-
var action = Match.isAction(line);
26+
var action = match_1.isAction(line);
2727
var chapter = index.chapter, page = index.page, task = index.task;
2828
var currentTask = result.chapters[chapter].pages[page].tasks[task];
2929
var trimmedContent = line.slice(action.length + 2, line.length - 1);
3030
var actionValue = cleanup_1.trimQuotes(trimmedContent);
31-
var isActionArray = Match.isArray(cleanup_1.trimQuotes(actionValue));
31+
var isActionArray = match_1.isArray(cleanup_1.trimQuotes(actionValue));
3232
switch (action) {
3333
case 'test':
3434
result = doAction('tests', isActionArray, actionValue, result, line, index);

lib/build/parser/cleanup.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ function trimValue(text) {
7373
exports.trimValue = trimValue;
7474
function cleanup(result) {
7575
result = JSON.parse(JSON.stringify(result));
76-
if (result.project.description) {
77-
result.project.description = trimLineBreaks(result.project.description);
76+
if (result.info.description) {
77+
result.info.description = trimLineBreaks(result.info.description);
7878
}
7979
if (result.chapters) {
8080
result.chapters.map(function (chapter) {

lib/build/parser/import.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
"use strict";
2-
var fs = require('fs');
3-
var path = require('path');
2+
var fs_1 = require('fs');
3+
var path_1 = require('path');
44
var file_1 = require('../../tools/file');
55
var cleanup_1 = require('./cleanup');
66
function loadImport(lines, pathToMd) {
77
pathToMd = cleanup_1.trimQuotes(pathToMd);
88
if (!pathToMd.match(/\.md$/)) {
99
pathToMd = pathToMd.concat('.md');
1010
}
11-
var realPath = path.join(process.cwd(), pathToMd);
11+
var realPath = path_1.join(process.cwd(), pathToMd);
1212
if (!file_1.fileExists(pathToMd)) {
1313
console.log('Invalid path to markdown file', realPath);
1414
return;
1515
}
16-
var importLines = fs.readFileSync(realPath, 'utf8');
16+
var importLines = fs_1.readFileSync(realPath, 'utf8');
1717
var splitLines = importLines.split('\n');
1818
return lines.concat(splitLines);
1919
}

lib/build/parser/info.js

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

lib/build/parser/match.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ function parseWithCode(code) {
2626
}
2727
};
2828
}
29-
exports.project = parseWithCode('#');
29+
exports.info = parseWithCode('#');
3030
exports.chapter = parseWithCode('##');
3131
exports.page = parseWithCode('###');
3232
exports.task = parseWithCode('+');

lib/build/parser/page.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ function page(result, lines, index) {
2323
lines = import_1.loadImport(lines, Match.isImport(line));
2424
continue;
2525
case (!!Match.isPageComplete(line) || !!currentPageComplete):
26-
currentPageComplete = !!currentPageComplete ? currentPageComplete += '\n' + line : Match.isPageComplete(line);
26+
currentPageComplete = !!currentPageComplete
27+
? currentPageComplete += '\n' + line
28+
: Match.isPageComplete(line);
2729
bracketCount = cleanup_1.bracketTracker(currentPageComplete);
2830
if (bracketCount === 0) {
2931
result.chapters[index.chapter].pages[index.page].onPageComplete = cleanup_1.trimValue(currentPageComplete);

lib/build/parser/task.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ function task(result, lines, index) {
2323
lines = import_1.loadImport(lines, Match.isImport(line));
2424
continue;
2525
case (!!Match.isPageComplete(line) || !!currentPageComplete):
26-
currentPageComplete = !!currentPageComplete ? currentPageComplete += '\n' + line : Match.isPageComplete(line);
26+
currentPageComplete = !!currentPageComplete
27+
? currentPageComplete += '\n' + line
28+
: Match.isPageComplete(line);
2729
bracketCount = cleanup_1.bracketTracker(currentPageComplete);
2830
if (bracketCount === 0) {
2931
result.chapters[index.chapter].pages[index.page].onPageComplete = cleanup_1.trimValue(currentPageComplete);

lib/build/readme.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ function generateReadme(data, packageJson) {
2222
var readme = [];
2323
readme.push();
2424
readme = readme.concat([
25-
'# ' + data.project.title,
25+
'# ' + data.info.title,
2626
'',
27-
data.project.description,
27+
data.info.description,
2828
''
2929
]);
3030
readme = readme.concat([

lib/build/validators.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ exports.filePath = filePath;
1111
function result(text) {
1212
lint_1.isValidJSON(text);
1313
var jsonObject = JSON.parse(text);
14-
lint_1.hasProjectInfo(jsonObject);
14+
lint_1.hasTutorialInfo(jsonObject);
1515
lint_1.hasPage(jsonObject);
1616
lint_1.lintOutput(jsonObject);
1717
return true;

lib/cli.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#! /usr/bin/env node
2-
32
"use strict";
43
var program = require('commander');
54
var chalk = require('chalk');

lib/create/validate.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ function validatePackageName(name) {
1616
});
1717
}
1818
if (!validated.errors && !validated.warnings) {
19-
console.log(chalk.red("\n Invalid package name. Try using kebab-case.\n > coderoad create " + _.kebabCase(name) + "\n "));
19+
console.log(chalk.red("\n Invalid package name. Try using kebab-case.\n > coderoad create " + _.kebabCase(name) + "\n "));
2020
}
2121
process.exit(1);
2222
}

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "coderoad-cli",
3-
"version": "0.3.27",
3+
"version": "0.4.0",
44
"description": "Command line interface for CodeRoad. Build project files.",
55
"keywords": [
66
"coderoad"
@@ -24,9 +24,9 @@
2424
"*.md"
2525
],
2626
"dependencies": {
27-
"chalk": "1.1.1",
27+
"chalk": "1.1.3",
2828
"commander": "2.9.0",
29-
"lodash": "4.6.1",
29+
"lodash": "4.9.0",
3030
"prompt": "1.0.0",
3131
"validate-npm-package-name": "2.2.2"
3232
},

setup/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
},
1919
"license": "MIT",
2020
"config": {
21-
"testDir": "tutorial",
21+
"dir": "tutorial",
2222
"testSuffix": ".spec.js",
23-
"testRunner": "mocha-coderoad"
23+
"runner": "mocha-coderoad"
2424
}
2525
}

setup/tutorial/tutorial.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
# Project Title
2-
Project description.
1+
# Tutorial Title
2+
Tutorial description.
33

44
## Chapter One Title
55
Chapter one description.

src/build/build.ts

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

77
function build(lines: string[]): CR.Output {
88
let result = {
9-
project: {
9+
info: {
1010
title: '',
1111
description: ''
1212
},
@@ -17,21 +17,21 @@ function build(lines: string[]): CR.Output {
1717
page: -1,
1818
task: -1
1919
};
20-
return project(result, lines, index);
20+
return info(result, lines, index);
2121
}
2222

2323
export default function(filePath: string, output = './coderoad.json'): void {
2424
// VALIDATE: path name
2525
validate.filePath(filePath);
2626

2727
// Read
28-
let lines: string[] = fs.readFileSync(filePath, 'utf8').split('\n');
28+
let lines: string[] = readFileSync(filePath, 'utf8').split('\n');
2929
// Build
3030
let result = cleanup(build(lines));
3131

3232
if (validate.result(result)) {
3333
// Safe to Write coderoad.json
34-
fs.writeFileSync(output, result, 'utf8');
34+
writeFileSync(output, result, 'utf8');
3535
}
3636
createReadme();
3737
}

0 commit comments

Comments
 (0)