Skip to content

Commit 2d3c5b6

Browse files
committed
tutorials partially implemented
1 parent 4ff256c commit 2d3c5b6

File tree

4 files changed

+66
-6
lines changed

4 files changed

+66
-6
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ Command line interface for [CodeRoad](http://coderoad.github.io).
1010
## Commands
1111
- create [name]
1212
- build [tutorial.md]
13-
- publish [version] _coming soon_
13+
- publish [version] _currently instructions only_
1414
- tutorials _coming soon_
15-
- search [query] _coming soon_
15+
- search [query] _currently instructions only_
1616
- help
1717

1818
### Create

cli.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ var search_1 = require('./src/search/search');
99
var tutorials_1 = require('./src/tutorials/tutorials');
1010
var publish_1 = require('./src/publish/publish');
1111
program
12-
.version('0.3.4')
12+
.version('0.3.5')
1313
.usage('[options] <keywords>')
1414
.option('-b, --build [path/to/tutorial.md]', 'tutorial markdown file', /^.+\.md$/i)
1515
.option('-c, --create [name]', 'tutorial name')

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

src/tutorials/tutorials.js

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

0 commit comments

Comments
 (0)