Skip to content

Commit a6e3c05

Browse files
committed
optimize startup
1 parent d72b957 commit a6e3c05

File tree

7 files changed

+23
-38
lines changed

7 files changed

+23
-38
lines changed

CHANGELOG.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,14 @@ All notable changes to this project will be documented in this file.
33
This project adheres to [Semantic Versioning](http://semver.org/).
44

55
## [0.7.0] - in progress
6-
- move to '[email protected]'
6+
- update to 'react@15'
7+
- move to '[email protected]'
78
- much improved setup ui & checks
89
- check Node, NPM versions
910
- Stepper UI
11+
- loading tutorials
12+
- check for new versions
13+
- update tutorial button
1014
- remove 'lodash' dependency
1115
- attach hints to toolbar
1216

lib/reducers/checks/verify.js

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,22 @@
11
"use strict";
22
var check_system_1 = require('./check-system');
33
var root_package_1 = require('../../services/root-package');
4+
var check_tutorials_1 = require('../tutorials/check-tutorials');
45
var result = function (x) { return x; };
56
function allTrue(obj) {
67
return Object.values(obj).every(function (x) { return x === true; });
78
}
8-
function hasTutorialDep() {
9-
var tutorials = root_package_1.default.getTutorials();
10-
return !!tutorials && tutorials.length > 0;
11-
}
129
function setupVerify() {
1310
var dir = !!window.coderoad.dir;
1411
var packageJson = false;
1512
var tutorial = false;
1613
root_package_1.default.set();
14+
var pj = root_package_1.default.get();
1715
if (dir) {
18-
packageJson = !!root_package_1.default.get();
16+
packageJson = !!pj;
1917
}
2018
if (dir && packageJson) {
21-
tutorial = hasTutorialDep();
19+
tutorial = !!check_tutorials_1.searchForTutorials(pj.dependencies).length || !!check_tutorials_1.searchForTutorials(pj.devDependencies).length;
2220
}
2321
var checks = {
2422
system: {

lib/reducers/tutorials/tutorials.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,17 @@
22
var _types_1 = require('../../actions/_types');
33
var update_tutorial_1 = require('./update-tutorial');
44
var root_package_1 = require('../../services/root-package');
5+
var check_tutorials_1 = require('./check-tutorials');
56
function tutorialsReducer(tutorials, action) {
67
if (tutorials === void 0) { tutorials = []; }
78
switch (action.type) {
89
case _types_1.TUTORIAL_UPDATE:
910
update_tutorial_1.tutorialUpdate(action.payload.name);
1011
case _types_1.TUTORIALS_FIND:
11-
return root_package_1.default.getTutorials();
12+
var packageJson = root_package_1.default.get();
13+
return ([]
14+
.concat(check_tutorials_1.searchForTutorials(packageJson.dependencies))
15+
.concat(check_tutorials_1.searchForTutorials(packageJson.devDependencies)));
1216
default:
1317
return tutorials;
1418
}

lib/services/root-package.js

-11
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
var fs_1 = require('fs');
33
var exists_1 = require('./exists');
44
var path_1 = require('path');
5-
var check_tutorials_1 = require('../reducers/tutorials/check-tutorials');
65
var RootPackageService = (function () {
76
function RootPackageService() {
87
this.packageJson = null;
@@ -19,16 +18,6 @@ var RootPackageService = (function () {
1918
RootPackageService.prototype.get = function () {
2019
return this.packageJson;
2120
};
22-
RootPackageService.prototype.getTutorials = function () {
23-
if (this.packageJson) {
24-
return ([]
25-
.concat(check_tutorials_1.searchForTutorials(this.packageJson.dependencies))
26-
.concat(check_tutorials_1.searchForTutorials(this.packageJson.devDependencies)));
27-
}
28-
else {
29-
return null;
30-
}
31-
};
3221
return RootPackageService;
3322
}());
3423
Object.defineProperty(exports, "__esModule", { value: true });

src/reducers/checks/verify.ts

+4-8
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,25 @@
11
import {npmMinVersion, nodeMinVersion} from './check-system';
2-
// import {hasDirectory} from './check-setup';
32
import RootPackage from '../../services/root-package';
3+
import {searchForTutorials} from '../tutorials/check-tutorials';
44

55
const result = (x) => x;
66
function allTrue(obj: Object): boolean {
77
return Object.values(obj).every((x) => x === true);
88
}
99

10-
function hasTutorialDep(): boolean {
11-
const tutorials = RootPackage.getTutorials();
12-
return !!tutorials && tutorials.length > 0;
13-
}
14-
1510
export default function setupVerify(): CR.Checks {
1611
let dir = !!window.coderoad.dir;
1712
let packageJson = false;
1813
let tutorial = false;
1914

2015
RootPackage.set();
16+
let pj = RootPackage.get();
2117

2218
if (dir) {
23-
packageJson = !!RootPackage.get();
19+
packageJson = !!pj;
2420
}
2521
if (dir && packageJson) {
26-
tutorial = hasTutorialDep();
22+
tutorial = !!searchForTutorials(pj.dependencies).length || !!searchForTutorials(pj.devDependencies).length;
2723
}
2824

2925
let checks: CR.Checks = {

src/reducers/tutorials/tutorials.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {TUTORIAL_UPDATE, TUTORIALS_FIND} from '../../actions/_types';
22
import {tutorialUpdate} from './update-tutorial';
33
import RootPackage from '../../services/root-package';
4+
import {searchForTutorials} from './check-tutorials';
45

56
export default function tutorialsReducer(tutorials = [],
67
action: CR.Action): CR.Tutorial[] {
@@ -9,7 +10,10 @@ export default function tutorialsReducer(tutorials = [],
910
tutorialUpdate(action.payload.name);
1011
/* falls through */
1112
case TUTORIALS_FIND:
12-
return RootPackage.getTutorials();
13+
const packageJson = RootPackage.get();
14+
return ([]
15+
.concat(searchForTutorials(packageJson.dependencies))
16+
.concat(searchForTutorials(packageJson.devDependencies)));
1317
default:
1418
return tutorials;
1519
}

src/services/root-package.ts

-10
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import {readFileSync} from 'fs';
22
import {fileExists} from './exists';
33
import {join} from 'path';
4-
import {searchForTutorials} from '../reducers/tutorials/check-tutorials';
54

65
class RootPackageService {
76
packageJson: PackageJson;
@@ -20,14 +19,5 @@ class RootPackageService {
2019
get(): PackageJson {
2120
return this.packageJson;
2221
}
23-
getTutorials(): CR.Tutorial[] {
24-
if (this.packageJson) {
25-
return ([]
26-
.concat(searchForTutorials(this.packageJson.dependencies))
27-
.concat(searchForTutorials(this.packageJson.devDependencies)));
28-
} else {
29-
return null;
30-
}
31-
}
3222
}
3323
export default new RootPackageService();

0 commit comments

Comments
 (0)