Skip to content

Commit 5377452

Browse files
committed
minor fixes/updates
1 parent 83c9679 commit 5377452

35 files changed

+265
-342
lines changed

lib/build/lint.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"use strict";
2-
var chalk = require('chalk');
2+
var chalk_1 = require('chalk');
33
var validKeys = {
44
info: ['title', 'description'],
55
chapter: ['title', 'description', 'pages'],
@@ -75,12 +75,12 @@ function lintOutput(json) {
7575
});
7676
if (warningKeys.length > 0) {
7777
warningKeys.forEach(function (w) {
78-
console.log(chalk.yellow("Warning: " + w.warning + ": ", w.location));
78+
console.log(chalk_1.yellow("Warning: " + w.warning + ": ", w.location));
7979
});
8080
}
8181
if (invalidKeys.length > 0) {
8282
invalidKeys.forEach(function (e) {
83-
console.log(chalk.red("Error: " + e.error + ": ", e.location));
83+
console.log(chalk_1.red("Error: " + e.error + ": ", e.location));
8484
});
8585
process.exit(1);
8686
}
@@ -90,22 +90,22 @@ function isValidJSON(text) {
9090
if (!/^[\],:{}\s]*$/.test(text.replace(/\\["\\\/bfnrtu]/g, '@').
9191
replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']').
9292
replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {
93-
console.log(chalk.red("\n Something went wrong. Build did not output valid JSON.\n "));
93+
console.log(chalk_1.red("\n Something went wrong. Build did not output valid JSON.\n "));
9494
process.exit(1);
9595
}
9696
}
9797
exports.isValidJSON = isValidJSON;
9898
function hasTutorialInfo(json) {
9999
var validTitle = json.info.title.length > 0, validDescription = json.info.description.length > 0;
100100
if (!(validTitle && validDescription)) {
101-
console.log(chalk.red("\n Your tutorial is missing basic project information. Check the project title & description.\n "));
101+
console.log(chalk_1.red("\n Your tutorial is missing basic project information. Check the project title & description.\n "));
102102
process.exit(1);
103103
}
104104
}
105105
exports.hasTutorialInfo = hasTutorialInfo;
106106
function hasPage(json) {
107107
if (!(json.chapters[0].pages.length > 0 && !!json.chapters[0].pages[0].title)) {
108-
console.log(chalk.red("\n Your tutorial requires at least one page.\n "));
108+
console.log(chalk_1.red("\n Your tutorial requires at least one page.\n "));
109109
process.exit(1);
110110
}
111111
}

lib/build/readme.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"use strict";
2-
var fs = require('fs');
2+
var fs_1 = require('fs');
33
var file_1 = require('../tools/file');
44
function createReadme() {
55
if (!file_1.fileExists('./README.md')) {
@@ -12,19 +12,19 @@ function createReadme() {
1212
console.log('No package.json file found');
1313
return;
1414
}
15-
var data = JSON.parse(fs.readFileSync('coderoad.json', 'utf8'));
16-
var packageJson = JSON.parse(fs.readFileSync('package.json', 'utf8'));
15+
var data = JSON.parse(fs_1.readFileSync('coderoad.json', 'utf8'));
16+
var packageJson = JSON.parse(fs_1.readFileSync('package.json', 'utf8'));
1717
var content = generateReadme(data, packageJson);
18-
fs.writeFileSync('README.md', content, 'utf8');
18+
fs_1.writeFileSync('README.md', content, 'utf8');
1919
}
2020
exports.createReadme = createReadme;
2121
function generateReadme(data, packageJson) {
2222
var readme = [];
23-
readme.push();
23+
var info = data.info, chapters = data.chapters;
2424
readme = readme.concat([
25-
'# ' + data.info.title,
25+
'# ' + info.title,
2626
'',
27-
data.info.description,
27+
info.description,
2828
''
2929
]);
3030
readme = readme.concat([
@@ -50,8 +50,8 @@ function generateReadme(data, packageJson) {
5050
'## Outline',
5151
''
5252
]);
53-
if (data.chapters) {
54-
var chapters = data.chapters.map(function (chapter) {
53+
if (chapters) {
54+
var parsedChapters = chapters.map(function (chapter) {
5555
var ch = [
5656
'### ' + chapter.title,
5757
'',
@@ -73,7 +73,7 @@ function generateReadme(data, packageJson) {
7373
}
7474
return ch;
7575
});
76-
chapters.forEach(function (chapter) {
76+
parsedChapters.forEach(function (chapter) {
7777
readme = readme.concat(chapter);
7878
});
7979
}

lib/cli.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#! /usr/bin/env node
22
"use strict";
33
var program = require('commander');
4-
var chalk = require('chalk');
4+
var chalk_1 = require('chalk');
55
var build_1 = require('./build/build');
66
var create_1 = require('./create/create');
77
var search_1 = require('./search/search');
@@ -25,9 +25,9 @@ else {
2525
if (program.build) {
2626
var tutorial = program.args[0] || 'tutorial/tutorial.md';
2727
var output = 'coderoad.json';
28-
console.log(chalk.grey("building from " + tutorial + "..."));
28+
console.log(chalk_1.grey("building from " + tutorial + "..."));
2929
build_1.default(tutorial, output);
30-
console.log(chalk.grey("build complete: coderoad.json"));
30+
console.log(chalk_1.grey("build complete: coderoad.json"));
3131
}
3232
if (program.create) {
3333
var packageName = program.args[0];

lib/create/validate.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
"use strict";
2-
var chalk = require('chalk');
2+
var chalk_1 = require('chalk');
33
var validateNpm = require('validate-npm-package-name');
44
var _ = require('lodash');
55
function validatePackageName(name) {
66
var validated = validateNpm(name);
77
if (!validated.validForNewPackages || !validated.validForOldPackages) {
88
if (validated.errors) {
99
validated.errors.forEach(function (error) {
10-
console.log(chalk.red('Package ' + error));
10+
console.log(chalk_1.red('Package ' + error));
1111
});
1212
}
1313
if (validated.warnings) {
1414
validated.warnings.forEach(function (warning) {
15-
console.log(chalk.yellow('Package ' + warning));
15+
console.log(chalk_1.yellow('Package ' + warning));
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_1.red("\n Invalid package name. Try using kebab-case.\n > coderoad create " + _.kebabCase(name) + "\n "));
2020
}
2121
process.exit(1);
2222
}

lib/create/write-demo.js

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,45 @@
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
function createFile(pathToFile) {
66
if (!file_1.fileExists(pathToFile)) {
7-
var inputPath = path.join(__dirname, '..', '..', 'setup', pathToFile);
8-
var test = fs.readFileSync(inputPath, 'utf8');
9-
fs.writeFileSync(pathToFile, test, 'utf8');
7+
var inputPath = path_1.join(__dirname, '..', '..', 'setup', pathToFile);
8+
var test = fs_1.readFileSync(inputPath, 'utf8');
9+
fs_1.writeFileSync(pathToFile, test, 'utf8');
1010
}
1111
}
1212
function createFolder(pathToFolder) {
1313
if (!file_1.fileExists(pathToFolder)) {
14-
fs.mkdirSync(pathToFolder);
14+
fs_1.mkdirSync(pathToFolder);
1515
}
1616
}
1717
function createTutorialMd() {
1818
createFolder('tutorial');
19-
createFile(path.join('tutorial', 'tutorial.md'));
20-
createFolder(path.join('tutorial', '1'));
21-
createFolder(path.join('tutorial', '1', '01'));
22-
createFile(path.join('tutorial', '1', '01', 'page-one.md'));
23-
createFolder(path.join('tutorial', '1', '02'));
24-
createFile(path.join('tutorial', '1', '02', 'page-two.md'));
25-
createFolder(path.join('tutorial', 'common'));
26-
createFile(path.join('tutorial', 'common', 'loadJS.js'));
19+
createFile(path_1.join('tutorial', 'tutorial.md'));
20+
createFolder(path_1.join('tutorial', '1'));
21+
createFolder(path_1.join('tutorial', '1', '01'));
22+
createFile(path_1.join('tutorial', '1', '01', 'page-one.md'));
23+
createFolder(path_1.join('tutorial', '1', '02'));
24+
createFile(path_1.join('tutorial', '1', '02', 'page-two.md'));
25+
createFolder(path_1.join('tutorial', 'common'));
26+
createFile(path_1.join('tutorial', 'common', 'loadJS.js'));
2727
}
2828
exports.createTutorialMd = createTutorialMd;
2929
function createPackageJson(name) {
3030
if (!file_1.fileExists('package.json')) {
31-
console.log(__dirname);
32-
var inputPath = path.join(__dirname, '..', '..', 'setup', 'package.json');
33-
var packageJson = JSON.parse(fs.readFileSync(inputPath, 'utf8'));
31+
var inputPath = path_1.join(__dirname, '..', '..', 'setup', 'package.json');
32+
var packageJson = JSON.parse(fs_1.readFileSync(inputPath, 'utf8'));
3433
packageJson.name = 'coderoad-' + name;
3534
var packageJsonString = JSON.stringify(packageJson, null, 2);
36-
fs.writeFileSync('package.json', packageJsonString, 'utf8');
35+
fs_1.writeFileSync('package.json', packageJsonString, 'utf8');
3736
}
3837
}
3938
exports.createPackageJson = createPackageJson;
4039
function createTestFiles() {
41-
createFile(path.join('tutorial', '1', '01', '01.spec.js'));
42-
createFile(path.join('tutorial', '1', '01', '02.spec.js'));
43-
createFile(path.join('tutorial', '1', '02', '01.spec.js'));
44-
createFile(path.join('tutorial', '1', '02', '02.spec.js'));
40+
createFile(path_1.join('tutorial', '1', '01', '01.spec.js'));
41+
createFile(path_1.join('tutorial', '1', '01', '02.spec.js'));
42+
createFile(path_1.join('tutorial', '1', '02', '01.spec.js'));
43+
createFile(path_1.join('tutorial', '1', '02', '02.spec.js'));
4544
}
4645
exports.createTestFiles = createTestFiles;

lib/list/list.js

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

lib/publish/publish.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
"use strict";
2-
var chalk = require('chalk');
2+
var chalk_1 = require('chalk');
33
var validate_1 = require('./validate');
44
function publish(version) {
55
validate_1.default(version);
66
console.log("Publishing package version \"" + version + "\"...");
7-
console.log(chalk.yellow('Publish feature not implemented yet.\n'));
7+
console.log(chalk_1.yellow('Publish feature not implemented yet.\n'));
88
console.log('To publish your tutorial package follow these instructions: \n');
99
console.log("Setup a git repo and tag your version:\n > git init\n > git add -A\n > git commit -m \"$your-commit-message$\"\n > git tag v" + version + "\n > git add remote origin http://github.com/$your-github-id$/$your-package-name$\n > git push -u --tags\n ");
1010
console.log("Publish your package to npm:\n > npm publish\n ");

lib/publish/validate.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"use strict";
22
var fs = require('fs');
3-
var chalk = require('chalk');
3+
var chalk_1 = require('chalk');
44
var file_1 = require('../tools/file');
55
function incrementVersion(version) {
66
var finalDot = version.lastIndexOf('.');
@@ -10,19 +10,19 @@ function incrementVersion(version) {
1010
}
1111
function versionIsGreaterThanCurrent(version) {
1212
if (!file_1.fileExists('package.json')) {
13-
console.log(chalk.yellow("\n No available package.json file.Create one.\n > npm init\n "));
13+
console.log(chalk_1.yellow("\n No available package.json file.Create one.\n > npm init\n "));
1414
process.exit(1);
1515
}
1616
var currentVersion = JSON.parse(fs.readFileSync('package.json', 'utf8')).version;
1717
if (parseInt(version, 10) <= parseInt(currentVersion, 10)) {
18-
console.log(chalk.yellow("\n Published version is not larger than current version.\n Current: \"" + currentVersion + "\"\n > coderoad publish \"" + incrementVersion(currentVersion) + "\"\n "));
18+
console.log(chalk_1.yellow("\n Published version is not larger than current version.\n Current: \"" + currentVersion + "\"\n > coderoad publish \"" + incrementVersion(currentVersion) + "\"\n "));
1919
process.exit(1);
2020
}
2121
}
2222
var semverRegex = /\b^(?:0|[1-9][0-9]*)\.(?:0|[1-9][0-9]*)\.(?:0|[1-9][0-9]*)$\b/i;
2323
function isValidVersion(version) {
2424
if (!version.match(semverRegex)) {
25-
console.log(chalk.yellow("\n Not a valid semver version\n > coderoad publish \"0.1.0\"\n "));
25+
console.log(chalk_1.yellow("\n Not a valid semver version\n > coderoad publish \"0.1.0\"\n "));
2626
process.exit(1);
2727
}
2828
}

lib/search/search.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
"use strict";
2-
var chalk = require('chalk');
2+
var chalk_1 = require('chalk');
33
var validate_1 = require('./validate');
44
function search(query) {
55
validate_1.validateQuery(query);
66
console.log("Searching for \"coderoad-" + query + "\"...");
7-
console.log(chalk.yellow('Search feature not fully implemented yet.\n'));
7+
console.log(chalk_1.yellow('Search feature not fully implemented yet.\n'));
88
console.log('To search for tutorials follow the instructions below: \n');
99
console.log("Search tutorials on npm:\n > npm search coderoad tutorial\n ");
1010
}

lib/search/validate.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
"use strict";
2-
var chalk = require('chalk');
2+
var chalk_1 = require('chalk');
33
function validateQuery(query) {
44
if (query === 'undefined') {
5-
console.log(chalk.yellow("\n Please provide a search query\n > coderoad search \"query\"\n "));
5+
console.log(chalk_1.yellow("\n Please provide a search query\n > coderoad search \"query\"\n "));
66
process.exit(1);
77
}
88
}

lib/tools/file.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
"use strict";
2-
var fs = require('fs');
2+
var fs_1 = require('fs');
33
function fileExists(path) {
44
try {
5-
fs.accessSync(path, fs.F_OK);
5+
fs_1.accessSync(path, fs_1.F_OK);
66
}
77
catch (e) {
88
if (e) {

lib/tutorials/tutorials.js

Lines changed: 2 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,8 @@
11
"use strict";
2-
var path = require('path');
3-
var chalk = require('chalk');
4-
var fs = require('fs');
2+
var chalk_1 = require('chalk');
53
function tutorials() {
64
console.log("List of tutorial packages in this directory...\n");
7-
console.log(chalk.yellow('This feature is not yet implemented'));
5+
console.log(chalk_1.yellow('This feature is not yet implemented'));
86
}
97
Object.defineProperty(exports, "__esModule", { value: true });
108
exports.default = tutorials;
11-
function fileExists(path) {
12-
try {
13-
fs.accessSync(path, fs.R_OK | fs.W_OK);
14-
}
15-
catch (e) {
16-
if (e) {
17-
console.log(e);
18-
return false;
19-
}
20-
}
21-
return true;
22-
}
23-
function loadRootPackageJson() {
24-
var pathToPackageJson = path.join(process.cwd(), './package.json');
25-
if (fileExists(pathToPackageJson)) {
26-
return JSON.parse(fs.readFileSync(pathToPackageJson, 'utf8'));
27-
}
28-
else {
29-
console.log('no package.json file available. Try typing "npm init" in terminal');
30-
process.exit(1);
31-
}
32-
}
33-
function isTutorial(name) {
34-
var pathToTutorialPackageJson = path.join(process.cwd(), 'node_modules', name, 'package.json');
35-
if (fileExists(pathToTutorialPackageJson)) {
36-
var packageJson = JSON.parse(fs.readFileSync(pathToTutorialPackageJson, 'utf8'));
37-
if (packageJson.main && packageJson.main.match(/coderoad.json$/)) {
38-
var pathToCoderoadJson = path.join(process.cwd(), 'node_modules', name, packageJson.main);
39-
if (fileExists(pathToCoderoadJson)) {
40-
return true;
41-
}
42-
}
43-
}
44-
return false;
45-
}
46-
function searchForTutorials(location) {
47-
if (!!location) {
48-
return Object.keys(location)
49-
.filter(function (name) { return isTutorial(name); });
50-
}
51-
else {
52-
return [];
53-
}
54-
}
55-
function getTutorials() {
56-
var packageJson = loadRootPackageJson();
57-
var tutorials = []
58-
.concat(searchForTutorials(packageJson.dependencies))
59-
.concat(searchForTutorials(packageJson.devDependencies));
60-
if (tutorials.length) {
61-
console.log('Available tutorials: ');
62-
tutorials.forEach(function (tutorial) {
63-
console.log(' - ' + tutorial);
64-
});
65-
}
66-
console.log('No tutorials available');
67-
}

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.4.0",
3+
"version": "0.4.1",
44
"description": "Command line interface for CodeRoad. Build project files.",
55
"keywords": [
66
"coderoad"

setup/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"license": "MIT",
2020
"config": {
2121
"dir": "tutorial",
22-
"testSuffix": ".spec.js",
23-
"runner": "mocha-coderoad"
22+
"runner": "mocha-coderoad",
23+
"testSuffix": ".spec.js"
2424
}
2525
}

0 commit comments

Comments
 (0)