Skip to content

Commit 835b2fd

Browse files
committed
remove error messages & loading duplicate tutorials
1 parent 784dc6a commit 835b2fd

File tree

6 files changed

+25
-12
lines changed

6 files changed

+25
-12
lines changed

lib/tutorials/find-tutorials.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ function findTutorials(dir, deps) {
1010
.map(function (name) {
1111
var pathToTutorialPackageJson = path_1.join(dir, 'node_modules', name, 'package.json');
1212
if (!node_file_exists_1.default(pathToTutorialPackageJson)) {
13-
console.log("Error with " + name + ": no package.json file found. " + is_tutorial_1.tutorialError);
13+
console.log("Error with " + name + ": no package.json file found.");
1414
return {
1515
name: name,
1616
version: 'NOT INSTALLED'

lib/tutorials/index.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,17 @@ function tutorials(dir) {
88
console.log(chalk_1.red("No package.json available"));
99
return null;
1010
}
11+
var removeDups = {};
1112
return ([]
1213
.concat(find_tutorials_1.default(dir, pj.dependencies))
13-
.concat(find_tutorials_1.default(dir, pj.devDependencies)));
14+
.concat(find_tutorials_1.default(dir, pj.devDependencies))
15+
.filter(function (tutorial) {
16+
if (!removeDups.hasOwnProperty(tutorial.name) && removeDups[tutorial.name] !== tutorial.version) {
17+
removeDups[tutorial.name] = tutorial.version;
18+
return true;
19+
}
20+
return false;
21+
}));
1422
}
1523
Object.defineProperty(exports, "__esModule", { value: true });
1624
exports.default = tutorials;

lib/tutorials/is-tutorial.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@
22
var path_1 = require('path');
33
var fs_1 = require('fs');
44
var node_file_exists_1 = require('node-file-exists');
5-
exports.tutorialError = 'This is an error with the tutorial itself';
65
function isTutorial(dir, name) {
76
var pathToTutorialPackageJson = path_1.join(dir, 'node_modules', name, 'package.json');
87
if (!node_file_exists_1.default(pathToTutorialPackageJson)) {
9-
console.log("Error with " + name + ": no package.json file found. " + exports.tutorialError);
108
return false;
119
}
1210
var pj = JSON.parse(fs_1.readFileSync(pathToTutorialPackageJson, 'utf8'));
@@ -15,12 +13,10 @@ function isTutorial(dir, name) {
1513
}
1614
var pathToCoderoadJson = path_1.join(dir, 'node_modules', name, pj.main);
1715
if (!node_file_exists_1.default(pathToCoderoadJson)) {
18-
console.log("Error with " + name + ": no coderoad.json file. " + exports.tutorialError);
1916
return false;
2017
}
2118
;
2219
if (!pj.config || !pj.config.runner) {
23-
console.log("Error with " + name + ": no test runner specified. " + exports.tutorialError);
2420
return false;
2521
}
2622
return true;

src/tutorials/find-tutorials.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {join} from 'path';
22
import {readFileSync} from 'fs';
33
import fileExists from 'node-file-exists';
4-
import {isTutorial, tutorialError} from './is-tutorial';
4+
import {isTutorial} from './is-tutorial';
55
// import {canUpdateTutorial} from './update';
66

77
export default function findTutorials(
@@ -20,7 +20,7 @@ export default function findTutorials(
2020
// no package.json
2121
if (!fileExists(pathToTutorialPackageJson)) {
2222
console.log(
23-
`Error with ${name}: no package.json file found. ${tutorialError}`
23+
`Error with ${name}: no package.json file found.`
2424
);
2525
return {
2626
name,

src/tutorials/index.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,17 @@ export default function tutorials(dir: string): string[] {
1010
return null;
1111
}
1212

13+
let removeDups = {};
14+
1315
return ([]
1416
.concat(findTutorials(dir, pj.dependencies))
1517
.concat(findTutorials(dir, pj.devDependencies))
18+
.filter((tutorial) => {
19+
if (!removeDups.hasOwnProperty(tutorial.name) && removeDups[tutorial.name] !== tutorial.version) {
20+
removeDups[tutorial.name] = tutorial.version;
21+
return true;
22+
}
23+
return false;
24+
})
1625
);
1726
}

src/tutorials/is-tutorial.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ import {join} from 'path';
22
import {readFileSync} from 'fs';
33
import fileExists from 'node-file-exists';
44

5-
export const tutorialError = 'This is an error with the tutorial itself';
5+
// export const tutorialError = 'This is an error with the tutorial itself';
66

77
export function isTutorial(dir: string, name: string): boolean {
88
// has package.json
99
const pathToTutorialPackageJson = join(
1010
dir, 'node_modules', name, 'package.json'
1111
);
1212
if (!fileExists(pathToTutorialPackageJson)) {
13-
console.log(`Error with ${name}: no package.json file found. ${tutorialError}`);
13+
// console.log(`Error with ${name}: no package.json file found. ${tutorialError}`);
1414
return false;
1515
}
1616
// main path to coderoad.json
@@ -25,11 +25,11 @@ export function isTutorial(dir: string, name: string): boolean {
2525
dir, 'node_modules', name, pj.main
2626
);
2727
if (!fileExists(pathToCoderoadJson)) {
28-
console.log(`Error with ${name}: no coderoad.json file. ${tutorialError}`);
28+
// console.log(`Error with ${name}: no coderoad.json file. ${tutorialError}`);
2929
return false;
3030
};
3131
if (!pj.config || !pj.config.runner) {
32-
console.log(`Error with ${name}: no test runner specified. ${tutorialError}`);
32+
// console.log(`Error with ${name}: no test runner specified. ${tutorialError}`);
3333
return false;
3434
}
3535

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy