Skip to content

Commit 0368931

Browse files
committed
fix publish import, coderoad tutorials lists tutorials
1 parent 86ea654 commit 0368931

File tree

13 files changed

+88
-22
lines changed

13 files changed

+88
-22
lines changed

lib/cli.js

100644100755
Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,17 @@ else if (program.search) {
4040
search_1.default(query);
4141
}
4242
else if (program.tutorials) {
43-
tutorials_1.default();
43+
process.stdout.write("List of tutorial packages in this directory...");
44+
var tuts = tutorials_1.default();
45+
if (!tuts) {
46+
result_1.fail();
47+
}
48+
else {
49+
process.stdout.write('\n\n');
50+
tuts.forEach(function (tut) {
51+
process.stdout.write(" " + tut.name + " : " + tut.version + "\n");
52+
});
53+
}
4454
}
4555
else if (program.publish) {
4656
var version = program.args[0];

lib/packageJson/get.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
"use strict";
2+
var node_file_exists_1 = require('node-file-exists');
3+
var fs_1 = require('fs');
4+
function getPackageJson() {
5+
var pathToPJ = './package.json';
6+
if (!node_file_exists_1.default(pathToPJ)) {
7+
return null;
8+
}
9+
var pj = fs_1.readFileSync(pathToPJ, 'utf8');
10+
return JSON.parse(pj);
11+
}
12+
Object.defineProperty(exports, "__esModule", { value: true });
13+
exports.default = getPackageJson;

lib/publish/validate.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
"use strict";
22
var fs = require('fs');
33
var chalk_1 = require('chalk');
4-
var file_1 = require('../tools/file');
4+
var node_file_exists_1 = require('node-file-exists');
55
function incrementVersion(version) {
66
var finalDot = version.lastIndexOf('.');
77
var start = version.substring(0, finalDot + 1);
88
var patch = parseInt(version.substring(finalDot + 1, version.length), 10) + 1;
99
return start + patch;
1010
}
1111
function versionIsGreaterThanCurrent(version) {
12-
if (!file_1.fileExists('package.json')) {
12+
if (!node_file_exists_1.default('package.json')) {
1313
console.log(chalk_1.yellow("\n No available package.json file.Create one.\n > npm init\n "));
1414
process.exit(1);
1515
}

lib/tutorials/find-tutorials.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ var fs_1 = require('fs');
44
var node_file_exists_1 = require('node-file-exists');
55
var is_tutorial_1 = require('./is-tutorial');
66
var update_1 = require('./update');
7-
function searchForTutorials(dir, deps) {
7+
function findTutorials(dir, deps) {
88
if (!!deps && Object.keys(deps).length > 0) {
99
return (Object.keys(deps)
1010
.filter(function (name) { return is_tutorial_1.isTutorial(dir, name); })
@@ -30,4 +30,5 @@ function searchForTutorials(dir, deps) {
3030
return [];
3131
}
3232
}
33-
exports.searchForTutorials = searchForTutorials;
33+
Object.defineProperty(exports, "__esModule", { value: true });
34+
exports.default = findTutorials;

lib/tutorials/index.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
11
"use strict";
22
var chalk_1 = require('chalk');
3+
var find_tutorials_1 = require('./find-tutorials');
4+
var get_1 = require('../packageJson/get');
35
function tutorials() {
4-
console.log("List of tutorial packages in this directory...\n");
5-
console.log(chalk_1.yellow('This feature is not yet implemented'));
6+
var pj = get_1.default();
7+
if (!pj) {
8+
console.log(chalk_1.red("No package.json available"));
9+
return false;
10+
}
11+
return ([]
12+
.concat(find_tutorials_1.default(process.cwd(), pj.dependencies))
13+
.concat(find_tutorials_1.default(process.cwd(), pj.devDependencies)));
614
}
715
Object.defineProperty(exports, "__esModule", { value: true });
816
exports.default = tutorials;

lib/tutorials/update.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@ function tutorialUpdate(name) {
55
}
66
exports.tutorialUpdate = tutorialUpdate;
77
function canUpdateTutorial(name, currentVersion) {
8-
if (!navigator.onLine) {
9-
return null;
10-
}
8+
return null;
119
return (atom_plugin_command_line_1.default('npm', "outdated " + name).then(function (res) {
1210
console.log(res);
1311
if (res.length > 0) {

src/cli.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,15 @@ if (program.build) {
3030
const tutorial = program.args[0] || 'tutorial/tutorial.md';
3131
const output = 'coderoad.json';
3232
process.stdout.write(grey(`building coderoad.json for ${tutorial}...`));
33+
// run build
3334
if (!build(tutorial, output)) {
3435
fail();
3536
}
3637

3738
} else if (program.create) {
3839
const packageName = program.args[0];
3940
process.stdout.write(`Creating demo tutorial "coderoad-${packageName}"...`);
41+
// run create
4042
if (!create(packageName)) {
4143
fail();
4244
}
@@ -46,7 +48,17 @@ if (program.build) {
4648
search(query);
4749

4850
} else if (program.tutorials) {
49-
tutorials();
51+
// run find tutorials
52+
process.stdout.write(`List of tutorial packages in this directory...`);
53+
const tuts = tutorials();
54+
if (!tuts) {
55+
fail();
56+
} else {
57+
process.stdout.write('\n\n')
58+
tuts.forEach((tut) => {
59+
process.stdout.write(` ${tut.name} : ${tut.version}\n`);
60+
});
61+
}
5062

5163
} else if (program.publish) {
5264
const version = program.args[0];

src/packageJson/get.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import fileExists from 'node-file-exists';
2+
import {readFileSync} from 'fs';
3+
4+
export default function getPackageJson(): PackageJson {
5+
const pathToPJ = './package.json';
6+
if (!fileExists(pathToPJ)) { return null; }
7+
const pj = readFileSync(pathToPJ, 'utf8');
8+
return JSON.parse(pj);
9+
}

src/publish/validate.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import * as fs from 'fs';
22
import {yellow} from 'chalk';
3-
import {fileExists} from '../tools/file';
4-
3+
import fileExists from 'node-file-exists';
54

65
function incrementVersion(version: string): string {
76
let finalDot = version.lastIndexOf('.');

src/tutorials/find-tutorials.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ import fileExists from 'node-file-exists';
44
import {isTutorial, tutorialError} from './is-tutorial';
55
import {canUpdateTutorial} from './update';
66

7-
export function searchForTutorials(dir: string, deps: Object): Tutorial.Info[] {
7+
export default function findTutorials(
8+
dir: string, deps: Object
9+
): Tutorial.Info[] {
810
if (!!deps && Object.keys(deps).length > 0) {
911
return (Object.keys(deps)
1012
.filter((name: string) => isTutorial(dir, name))

src/tutorials/index.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,19 @@
1-
import {yellow} from 'chalk';
1+
import {yellow, red} from 'chalk';
2+
import findTutorials from './find-tutorials';
3+
import getPackageJson from '../packageJson/get';
24

3-
export default function tutorials(): void {
4-
console.log(`List of tutorial packages in this directory...\n`);
5-
console.log(yellow('This feature is not yet implemented'));
6-
// getTutorials();
5+
export default function tutorials(): string[] | boolean {
6+
// console.log(yellow('This feature is not yet implemented'));
7+
8+
const pj: PackageJson = getPackageJson();
9+
10+
if (!pj) {
11+
console.log(red(`No package.json available`))
12+
return false;
13+
}
14+
15+
return ([]
16+
.concat(findTutorials(process.cwd(), pj.dependencies))
17+
.concat(findTutorials(process.cwd(), pj.devDependencies))
18+
);
719
}

src/tutorials/update.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ export function tutorialUpdate(name: string): void {
1313
export function canUpdateTutorial(
1414
name: string, currentVersion: string
1515
): Promise<boolean> {
16-
if (!navigator.onLine) {
17-
return null;
18-
}
16+
return null;
17+
// if (global.hasOwnProperty('navigator') || !global.navigator.onLine) {
18+
// return null;
19+
// }
1920
return (commandLine(
2021
'npm', `outdated ${name}`
2122
).then(

tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"src/create/validate.ts",
3333
"src/create/write-demo.ts",
3434
"src/list/list.ts",
35+
"src/packageJson/get.ts",
3536
"src/publish/index.ts",
3637
"src/publish/validate.ts",
3738
"src/search/index.ts",

0 commit comments

Comments
 (0)