Skip to content

Commit 18a1bf4

Browse files
committed
fix tutorial list bug if no pj.main
1 parent 9b0a63a commit 18a1bf4

File tree

7 files changed

+32
-26
lines changed

7 files changed

+32
-26
lines changed

lib/cli.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ program
1515
.option('-b, --build [path/to/tutorial.md]', 'tutorial markdown file', /^.+\.md$/i)
1616
.option('-c, --create [name]', 'tutorial name')
1717
.option('-p, --publish [version]', 'publish tutorial to npm with new version number')
18-
.option('-t, --tutorials', 'list of tutorial packages')
18+
.option('-t, --tutorials', 'list of local tutorial packages')
1919
.option('-s, --search [query]', 'search for tutorial package')
2020
.option('-r, --run', 'run tutorial')
2121
.parse(process.argv);
@@ -47,9 +47,14 @@ else if (program.tutorials) {
4747
}
4848
else {
4949
process.stdout.write('\n');
50-
tuts.forEach(function (tut) {
51-
process.stdout.write(" " + tut.name + " : " + tut.version + "\n");
52-
});
50+
if (tuts.length < 1) {
51+
process.stdout.write(chalk_1.yellow(" No tutorials in this directory."));
52+
}
53+
else {
54+
tuts.forEach(function (tut) {
55+
process.stdout.write(" " + tut.name + " : " + tut.version + "\n");
56+
});
57+
}
5358
}
5459
}
5560
else if (program.publish) {

lib/tutorials/is-tutorial.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,17 @@ function isTutorial(dir, name) {
99
console.log("Error with " + name + ": no package.json file found. " + exports.tutorialError);
1010
return false;
1111
}
12-
var packageJson = JSON.parse(fs_1.readFileSync(pathToTutorialPackageJson, 'utf8'));
13-
if (!packageJson.main && packageJson.main.match(/coderoad.json$/)) {
14-
console.log("Error with " + name + ": main does not load a coderoad.json file. " + exports.tutorialError);
12+
var pj = JSON.parse(fs_1.readFileSync(pathToTutorialPackageJson, 'utf8'));
13+
if (!pj.hasOwnProperty('main') || !pj.main.match(/coderoad.json$/)) {
1514
return false;
1615
}
17-
var pathToCoderoadJson = path_1.join(dir, 'node_modules', name, packageJson.main);
16+
var pathToCoderoadJson = path_1.join(dir, 'node_modules', name, pj.main);
1817
if (!node_file_exists_1.default(pathToCoderoadJson)) {
1918
console.log("Error with " + name + ": no coderoad.json file. " + exports.tutorialError);
2019
return false;
2120
}
2221
;
23-
if (!packageJson.config || !packageJson.config.runner) {
22+
if (!pj.config || !pj.config.runner) {
2423
console.log("Error with " + name + ": no test runner specified. " + exports.tutorialError);
2524
return false;
2625
}

src/cli.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#! /usr/bin/env node
22

33
import * as program from 'commander';
4-
import {grey} from 'chalk';
4+
import {grey, yellow} from 'chalk';
55
import {success, fail} from './result';
66

77
import build from './build';
@@ -19,7 +19,7 @@ program
1919
.option('-c, --create [name]', 'tutorial name')
2020
.option('-p, --publish [version]',
2121
'publish tutorial to npm with new version number')
22-
.option('-t, --tutorials', 'list of tutorial packages')
22+
.option('-t, --tutorials', 'list of local tutorial packages')
2323
.option('-s, --search [query]', 'search for tutorial package')
2424
.option('-r, --run', 'run tutorial')
2525
.parse(process.argv);
@@ -55,9 +55,13 @@ if (program.build) {
5555
fail();
5656
} else {
5757
process.stdout.write('\n');
58-
tuts.forEach((tut) => {
59-
process.stdout.write(` ${tut.name} : ${tut.version}\n`);
60-
});
58+
if (tuts.length < 1) {
59+
process.stdout.write(yellow(` No tutorials in this directory.`));
60+
} else {
61+
tuts.forEach((tut) => {
62+
process.stdout.write(` ${tut.name} : ${tut.version}\n`);
63+
});
64+
}
6165
}
6266

6367
} else if (program.publish) {

src/list/list.ts

Lines changed: 0 additions & 6 deletions
This file was deleted.

src/tutorials/find-tutorials.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ export default function findTutorials(
99
): Tutorial.Info[] {
1010
if (!!deps && Object.keys(deps).length > 0) {
1111
return (Object.keys(deps)
12+
// map over possible tutorials
13+
// filter to only packages with a coderoad.json file
1214
.filter((name: string) => isTutorial(dir, name))
1315
.map(function(name: string) {
1416
const pathToTutorialPackageJson = join(

src/tutorials/is-tutorial.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,21 @@ export function isTutorial(dir: string, name: string): boolean {
1414
return false;
1515
}
1616
// main path to coderoad.json
17-
let packageJson = JSON.parse(readFileSync(pathToTutorialPackageJson, 'utf8'));
18-
if (!packageJson.main && packageJson.main.match(/coderoad.json$/)) {
19-
console.log(`Error with ${name}: main does not load a coderoad.json file. ${tutorialError}`);
17+
let pj = JSON.parse(readFileSync(pathToTutorialPackageJson, 'utf8'));
18+
19+
if (!pj.hasOwnProperty('main') || !pj.main.match(/coderoad.json$/)) {
20+
// console.log(`Error with ${name}: main does not load a coderoad.json file. ${tutorialError}`);
2021
return false;
2122
}
2223
// coderoad.json file exists
2324
let pathToCoderoadJson = join(
24-
dir, 'node_modules', name, packageJson.main
25+
dir, 'node_modules', name, pj.main
2526
);
2627
if (!fileExists(pathToCoderoadJson)) {
2728
console.log(`Error with ${name}: no coderoad.json file. ${tutorialError}`);
2829
return false;
2930
};
30-
if (!packageJson.config || !packageJson.config.runner) {
31+
if (!pj.config || !pj.config.runner) {
3132
console.log(`Error with ${name}: no test runner specified. ${tutorialError}`);
3233
return false;
3334
}

tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
"src/create/index.ts",
3232
"src/create/validate.ts",
3333
"src/create/write-demo.ts",
34-
"src/list/list.ts",
3534
"src/packageJson/get.ts",
3635
"src/publish/index.ts",
3736
"src/publish/validate.ts",
@@ -41,11 +40,13 @@
4140
"src/tutorials/index.ts",
4241
"src/tutorials/is-tutorial.ts",
4342
"src/tutorials/update.ts",
43+
"src/typings/atom-plugin-command-line/index.d.ts",
4444
"src/typings/chalk/chalk.d.ts",
4545
"src/typings/commander/commander.d.ts",
4646
"src/typings/cr.d.ts",
4747
"src/typings/es6-promise/es6-promise.d.ts",
4848
"src/typings/globals.d.ts",
49+
"src/typings/node-file-exists/index.d.ts",
4950
"src/typings/node/node.d.ts",
5051
"src/typings/prompt/prompt.d.ts",
5152
"src/typings/tsd.d.ts",

0 commit comments

Comments
 (0)