Skip to content

Commit 0bf9db1

Browse files
committed
various fixes, minor
1 parent 6defdf2 commit 0bf9db1

35 files changed

+121
-105
lines changed

lib/reducers/checks/action-setup.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
"use strict";
2-
var path = require('path');
2+
var path_1 = require('path');
33
var editor_1 = require('../../atom/editor');
44
var actions_1 = require('../../atom/actions');
55
var store_1 = require('../../store/store');
66
var actions_2 = require('../../actions/actions');
77
var packageData = "{\n \"name\": \"demo\",\n \"dependencies\": {\n \"coderoad-functional-school\": \"^0.2.1\"\n }\n}";
88
function createPackageJson() {
9-
var packagePath = path.join(window.coderoad.dir, 'package.json');
9+
var packagePath = path_1.join(window.coderoad.dir, 'package.json');
1010
return new Promise(function (resolve, reject) {
1111
editor_1.open(packagePath);
1212
setTimeout(function () {

lib/reducers/editor-actions/action-helpers.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@ function getCommand(actionString) {
1111
}
1212
exports.getCommand = getCommand;
1313
function getParams(actionString) {
14+
var parser = new parser_1.ParseParams;
1415
var command = getCommand(actionString);
1516
var params = actionString.substring(command.length + 1, actionString.length - 1);
1617
if (!params.length) {
1718
console.error('Error loading editor action params ', actionString);
1819
return null;
1920
}
20-
var paramsList = parser_1.parseParams.getParams(params);
21+
var paramsList = parser.getParams(params);
2122
return paramsList;
2223
}
2324
exports.getParams = getParams;

lib/reducers/editor-actions/actions.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"use strict";
2-
var Editor = require('../../atom/editor');
2+
var editor_1 = require('../../atom/editor');
33
var actions_1 = require('../../atom/actions');
44
var action_helpers_1 = require('./action-helpers');
55
var Type = {
@@ -18,7 +18,7 @@ function editorActions(actionString) {
1818
var file = obj.param;
1919
var options = obj.options;
2020
if (params.length === 1) {
21-
Editor.open(file, options);
21+
editor_1.open(file, options);
2222
setTimeout(function () {
2323
resolve();
2424
}, 100);
@@ -28,7 +28,7 @@ function editorActions(actionString) {
2828
if (params.length === 1) {
2929
var content_1 = params[0];
3030
setTimeout(function () {
31-
Editor.set(content_1);
31+
editor_1.set(content_1);
3232
resolve(true);
3333
});
3434
}
@@ -37,7 +37,7 @@ function editorActions(actionString) {
3737
if (params.length === 1) {
3838
var content_2 = params[0];
3939
setTimeout(function () {
40-
Editor.insert(content_2, {});
40+
editor_1.insert(content_2, {});
4141
resolve(true);
4242
});
4343
}

lib/reducers/editor-actions/editor-actions.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"use strict";
2-
var Type = require('../../actions/actionTypes');
2+
var actionTypes_1 = require('../../actions/actionTypes');
33
var times = require('lodash').times;
44
var actions_1 = require('./actions');
55
function handleEditorActions(actionArray) {
@@ -12,12 +12,12 @@ var actions;
1212
function editorActionsReducer(editorActions, action) {
1313
if (editorActions === void 0) { editorActions = []; }
1414
switch (action.type) {
15-
case Type.SET_PAGE:
15+
case actionTypes_1.SET_PAGE:
1616
actions = action.payload.actions;
1717
currentTaskPosition = 0;
1818
handleEditorActions(actions.shift());
1919
return actions;
20-
case Type.TEST_RESULT:
20+
case actionTypes_1.TEST_RESULT:
2121
actions = action.payload.actions;
2222
var nextTaskPosition = action.payload.result.taskPosition;
2323
if (nextTaskPosition > currentTaskPosition) {

lib/reducers/editor-actions/parser.js

+16-10
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
"use strict";
2-
exports.parseParams = {
3-
trim: function (text) {
2+
var ParseParams = (function () {
3+
function ParseParams() {
4+
this.reset();
5+
}
6+
ParseParams.prototype.trim = function (text) {
47
text = text.trim();
58
var firstBracket = text.charAt(0).match(/["']/);
69
if (firstBracket && !!text.charAt(text.length - 1).match(firstBracket[0])) {
710
text = text.substring(1, text.length - 1);
811
}
912
return text;
10-
},
11-
addBreak: function (char, index) {
13+
};
14+
ParseParams.prototype.addBreak = function (char, index) {
1215
switch (char) {
1316
case '(':
1417
this.round += 1;
@@ -39,19 +42,22 @@ exports.parseParams = {
3942
else {
4043
this.current += char;
4144
}
42-
},
43-
getParams: function (text) {
45+
};
46+
ParseParams.prototype.getParams = function (text) {
4447
this.reset();
4548
for (var i = 0; i < text.length; i++) {
4649
this.addBreak(text[i], i);
4750
}
4851
return this.params.concat(this.trim(this.current));
49-
},
50-
reset: function () {
52+
};
53+
ParseParams.prototype.reset = function () {
5154
this.round = 0;
5255
this.square = 0;
5356
this.curly = 0;
5457
this.current = '';
5558
this.params = [];
56-
}
57-
};
59+
};
60+
return ParseParams;
61+
}());
62+
exports.ParseParams = ParseParams;
63+
;

lib/reducers/route/route.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"use strict";
22
var actionTypes_1 = require('../../actions/actionTypes');
3-
var defaultRoute = 'tutorials';
3+
var defaultRoute = 'start';
44
function routeReducer(route, action) {
55
if (route === void 0) { route = defaultRoute; }
66
switch (action.type) {

lib/reducers/tutorials/update-tutorial.js

-13
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,6 @@
22
var command_line_1 = require('../../services/command-line');
33
var store_1 = require('../../store/store');
44
var actions_1 = require('../../actions/actions');
5-
function canUpdateTutorial(name, currentVersion) {
6-
return (command_line_1.default('npm', "outdated " + name)
7-
.then(function (res) {
8-
if (res.length > 0) {
9-
var match = res.match(/[0-9\.]+\s+[0-9\.]+\s+([0-9\.]+)/);
10-
if (match.length >= 2) {
11-
return match[1];
12-
}
13-
}
14-
return null;
15-
}));
16-
}
17-
exports.canUpdateTutorial = canUpdateTutorial;
185
function updateTutorial(name) {
196
command_line_1.default('npm', "install --save-dev " + name)
207
.then(function () {

lib/services/exists.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
"use strict";
2-
var fs = require('fs');
2+
var fs_1 = require('fs');
33
function fileExists(pathToFile) {
44
try {
5-
fs.accessSync(pathToFile, fs.F_OK);
5+
fs_1.accessSync(pathToFile, fs_1.F_OK);
66
}
77
catch (e) {
88
if (e) {

lib/services/package.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -25,25 +25,25 @@ var PackageService = (function () {
2525
project: {},
2626
chapters: []
2727
};
28-
this.config = {};
28+
this.packageJson = null;
2929
}
3030
PackageService.prototype.selectPackage = function (packageName) {
3131
var packagePath = path_1.join(window.coderoad.dir, 'node_modules', packageName);
32-
this.config = require(path_1.join(packagePath, 'package.json'));
33-
store_1.store.dispatch(actions_1.setGlobals(this.config));
34-
this.data = require(path_1.join(packagePath, this.config.main));
32+
this.packageJson = require(path_1.join(packagePath, 'package.json'));
33+
store_1.store.dispatch(actions_1.setGlobals(this.packageJson));
34+
this.data = require(path_1.join(packagePath, this.packageJson.main));
3535
this.packageName = packageName;
3636
};
3737
PackageService.prototype.page = function (_a) {
3838
var chapter = _a.chapter, page = _a.page;
3939
return cloneDeep(this.data.chapters[chapter].pages[page]);
4040
};
41-
PackageService.prototype.getConfig = function () {
42-
return this.config;
41+
PackageService.prototype.getPackage = function () {
42+
return this.packageJson;
4343
};
4444
PackageService.prototype.configTaskTests = function (tasks) {
4545
var _this = this;
46-
var config = this.config.config;
46+
var config = this.packageJson.config;
4747
return !tasks ? [] : tasks.map(function (task) {
4848
if (task.tests) {
4949
task.tests = task.tests.map(function (test) {

src/reducers/checks/action-setup.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as path from 'path';
1+
import {join} from 'path';
22
import {open, set} from '../../atom/editor';
33
import {openFolder, openTerminal} from '../../atom/actions';
44
import commandLine from '../../services/command-line';
@@ -13,7 +13,7 @@ const packageData = `{
1313
}`;
1414

1515
export function createPackageJson(): Promise<void> {
16-
const packagePath = path.join(window.coderoad.dir, 'package.json');
16+
const packagePath = join(window.coderoad.dir, 'package.json');
1717
return new Promise((resolve, reject) => {
1818
open(packagePath);
1919
setTimeout(function() {

src/reducers/editor-actions/action-helpers.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {parseParams} from './parser';
1+
import {ParseParams} from './parser';
22

33
export function getCommand(actionString: string): string {
44
// content before bracket
@@ -12,13 +12,14 @@ export function getCommand(actionString: string): string {
1212

1313
export function getParams(actionString: string): string[] {
1414
// content in brackets, split by comma
15+
let parser = new ParseParams;
1516
let command = getCommand(actionString);
1617
let params = actionString.substring(command.length + 1, actionString.length - 1); // trim brackets
1718
if (!params.length) {
1819
console.error('Error loading editor action params ', actionString);
1920
return null;
2021
}
21-
let paramsList: string[] = parseParams.getParams(params);
22+
let paramsList: string[] = parser.getParams(params);
2223
return paramsList;
2324
}
2425

src/reducers/editor-actions/actions.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as Editor from '../../atom/editor';
1+
import {open, set, insert} from '../../atom/editor';
22
import {openDevTools} from '../../atom/actions';
33
import {getCommand, getParams, getOptions} from './action-helpers';
44

@@ -19,7 +19,7 @@ export function editorActions(actionString: string): Promise<void> {
1919
let file = obj.param;
2020
let options = obj.options;
2121
if (params.length === 1) {
22-
Editor.open(file, options);
22+
open(file, options);
2323
setTimeout(function() {
2424
resolve();
2525
}, 100);
@@ -30,7 +30,7 @@ export function editorActions(actionString: string): Promise<void> {
3030
let content = params[0];
3131

3232
setTimeout(function() {
33-
Editor.set(content);
33+
set(content);
3434
resolve(true);
3535
});
3636
}
@@ -41,7 +41,7 @@ export function editorActions(actionString: string): Promise<void> {
4141
let content: string = params[0];
4242
// let options: object = obj.options;
4343
setTimeout(function() {
44-
Editor.insert(content, {});
44+
insert(content, {});
4545
resolve(true);
4646
});
4747
}

src/reducers/editor-actions/editor-actions.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as Type from '../../actions/actionTypes';
1+
import {SET_PAGE, TEST_RESULT} from '../../actions/actionTypes';
22
const {times} = require('lodash');
33
import {editorActions} from './actions';
44

@@ -16,12 +16,12 @@ var actions;
1616
*/
1717
export default function editorActionsReducer(editorActions = [], action: CR.Action): string[] {
1818
switch (action.type) {
19-
case Type.SET_PAGE:
19+
case SET_PAGE:
2020
actions = action.payload.actions;
2121
currentTaskPosition = 0;
2222
handleEditorActions(actions.shift());
2323
return actions;
24-
case Type.TEST_RESULT:
24+
case TEST_RESULT:
2525
actions = action.payload.actions;
2626
let nextTaskPosition = action.payload.result.taskPosition;
2727
if (nextTaskPosition > currentTaskPosition) {

src/reducers/editor-actions/parser.ts

+12-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
1-
export const parseParams = {
1+
export class ParseParams {
2+
round: number;
3+
square: number;
4+
curly: number;
5+
current: string;
6+
params: string[];
7+
constructor() {
8+
this.reset();
9+
}
210
trim(text: string): string {
311
text = text.trim();
412
var firstBracket = text.charAt(0).match(/["']/);
513
if (firstBracket && !!text.charAt(text.length - 1).match(firstBracket[0])) {
614
text = text.substring(1, text.length - 1); // trim quotes
715
}
816
return text;
9-
},
17+
}
1018
addBreak(char: string, index: number): void {
1119
switch (char) {
1220
case '(':
@@ -37,14 +45,14 @@ export const parseParams = {
3745
} else {
3846
this.current += char;
3947
}
40-
},
48+
}
4149
getParams(text: string): string[] {
4250
this.reset();
4351
for (let i = 0; i < text.length; i++) {
4452
this.addBreak(text[i], i);
4553
}
4654
return this.params.concat(this.trim(this.current));
47-
},
55+
}
4856
reset(): void {
4957
this.round = 0;
5058
this.square = 0;

src/reducers/globals/globals.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ const defaultGlobals = {
77
win: null
88
};
99

10-
export default function globalReducer(globals = defaultGlobals, action: CR.Action): CR.Coderoad {
10+
export default function globalReducer(globals = defaultGlobals,
11+
action: CR.Action): CR.Coderoad {
1112
switch (action.type) {
1213
case SET_GLOBALS:
1314
let coderoad = Object.assign({}, setGlobals(action.payload.packageJson), window.coderoad);

src/reducers/globals/set-globals.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export function setGlobals(packageJson: PackageJson): CR.Coderoad {
1616
}, window.coderoad);
1717
}
1818

19-
function loadRunnerDep(packageJson: PackageJson) {
19+
function loadRunnerDep(packageJson: PackageJson): () => any {
2020
// test runner dir
2121
let flatDep = join(window.coderoad.dir, 'node_modules', packageJson.config.testRunner, 'package.json');
2222
let treeDep = join(window.coderoad.dir, 'node_modules',

src/reducers/hint-position/hint-position.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import {
22
SET_PAGE, TEST_RESULT, SET_HINT_POSITION
33
} from '../../actions/actionTypes';
44

5-
export default function hintPositionReducer(hintPosition = 0, action: CR.Action): number {
5+
export default function hintPositionReducer(hintPosition = 0,
6+
action: CR.Action): number {
67
switch (action.type) {
78
case SET_PAGE:
89
return 0;

src/reducers/log/log.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ let defaultLog = {
77
open: false
88
};
99

10-
export default function logReducer(log = defaultLog, action: CR.Action): CR.Log {
10+
export default function logReducer(log = defaultLog,
11+
action: CR.Action): CR.Log {
1112
switch (action.type) {
1213
case TOGGLE_LOG:
1314
return {

src/reducers/page/page.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ const defaultPage: CR.Page = {
88
completed: false
99
};
1010

11-
export default function pageReducer(page = defaultPage, action: CR.Action): CR.Page {
11+
export default function pageReducer(page = defaultPage,
12+
action: CR.Action): CR.Page {
1213
switch (action.type) {
1314
case SET_PAGE:
1415
return action.payload.page;

src/reducers/position/position.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ const defaultPosition: CR.Position = {
77
page: 0
88
};
99

10-
export default function positionReducer(position = defaultPosition, action: CR.Action): CR.Position {
10+
export default function positionReducer(position = defaultPosition,
11+
action: CR.Action): CR.Position {
1112
switch (action.type) {
1213
case SET_PAGE:
1314
case SET_POSITION:

0 commit comments

Comments
 (0)