Skip to content

Commit 7d1287f

Browse files
committed
setup setup reducer
1 parent 796f1ce commit 7d1287f

File tree

18 files changed

+118
-171
lines changed

18 files changed

+118
-171
lines changed

lib/actions/actionTypes.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"use strict";
22
exports.SET_PROJECT = 'SET_PROJECT';
3+
exports.SET_SETUP = 'SET_SETUP';
34
exports.LOAD_TUTORIALS = 'LOAD_TUTORIALS';
45
exports.SET_ROUTE = 'SET_ROUTE';
56
exports.SET_PAGE = 'SET_PAGE';

lib/actions/actions.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ function setProject() {
66
return { type: Type.SET_PROJECT };
77
}
88
exports.setProject = setProject;
9+
function setSetup(setup) {
10+
return { type: Type.SET_SETUP, payload: setup };
11+
}
12+
exports.setSetup = setSetup;
913
function setProgress() {
1014
return { type: Type.SET_PROGRESS };
1115
}

lib/components/start/setup.js

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
var React = require('react');
33
var material_ui_1 = require('material-ui');
44
var _components_1 = require('../_components');
5-
var start_1 = require('../../services/start');
5+
var exists_1 = require('../../services/exists');
6+
var path = require('path');
67
var editor_1 = require('../../atom/editor');
78
exports.SetupGuide = function (_a) {
89
var tutorials = _a.tutorials;
@@ -19,7 +20,7 @@ exports.SetupGuide = function (_a) {
1920
warnings.push({
2021
key: 'noPackageJson',
2122
title: 'Create a `package.json` file',
22-
click: start_1.createPackageJson,
23+
click: createPackageJson,
2324
text: '`npm init`'
2425
});
2526
}
@@ -31,5 +32,24 @@ exports.SetupGuide = function (_a) {
3132
text: '`npm i --save coderoad-functional-school`'
3233
});
3334
}
34-
return (React.createElement("div", {className: 'setup'}, React.createElement(material_ui_1.List, {subheader: 'Setup'}, warnings.map(function (w) { return React.createElement(material_ui_1.ListItem, {key: w.key, primaryText: w.title, onClick: w.click}, React.createElement(_components_1.MarkdownText, {text: w.text})); }))));
35+
return (React.createElement("div", {className: 'setup'}, React.createElement(material_ui_1.List, {subheader: 'Setup'}, warnings.map(function (w) { return React.createElement(material_ui_1.ListItem, {key: w.key, primaryText: w.title, onClick: w.click}, React.createElement(_components_1.MarkdownText, {text: w.text})); })), React.createElement("br", null), React.createElement(material_ui_1.RaisedButton, {label: 'Verify Setup', secondary: true, onTouchTap: checkSetup})));
3536
};
37+
var packageData = "{\n \"name\": \"demo\",\n \"dependencies\": {\n \"coderoad-functional-school\": \"^0.1.9\"\n }\n}";
38+
function createPackageJson() {
39+
var packagePath = path.join(window.coderoad.dir, 'package.json');
40+
return new Promise(function (resolve, reject) {
41+
editor_1.open(packagePath);
42+
setTimeout(function () {
43+
resolve();
44+
});
45+
}).then(function () {
46+
editor_1.set(packageData);
47+
window.coderoad.setup.hasPackageJson = true;
48+
});
49+
}
50+
function checkSetup() {
51+
var packagePath = path.join(window.coderoad.dir, 'package.json');
52+
if (exists_1.fileExists(packagePath)) {
53+
window.coderoad.setup.hasPackageJson = true;
54+
}
55+
}

lib/reducers/reducer.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ var run_tests_1 = require('./run-tests/run-tests');
1414
var editor_actions_1 = require('./editor-actions/editor-actions');
1515
var tutorials_1 = require('./tutorials/tutorials');
1616
var log_1 = require('./log/log');
17+
var setup_1 = require('./setup/setup');
1718
Object.defineProperty(exports, "__esModule", { value: true });
1819
exports.default = redux_1.combineReducers({
1920
project: project_1.default,
@@ -29,5 +30,6 @@ exports.default = redux_1.combineReducers({
2930
runTests: run_tests_1.default,
3031
editorActions: editor_actions_1.default,
3132
tutorials: tutorials_1.default,
32-
log: log_1.default
33+
log: log_1.default,
34+
setup: setup_1.default
3335
});

lib/reducers/setup/setup.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
"use strict";
2+
var Type = require('../../actions/actionTypes');
3+
var defaultSetup = {
4+
hasDirectory: false,
5+
hasPackageJson: false,
6+
hasTutorialDep: false,
7+
hasTutorial: false,
8+
hasTestRunner: false
9+
};
10+
function setupReducer(setup, action) {
11+
if (setup === void 0) { setup = defaultSetup; }
12+
switch (action.type) {
13+
case Type.SET_SETUP:
14+
return Object.assign(setup, action.payload);
15+
default:
16+
return setup;
17+
}
18+
}
19+
Object.defineProperty(exports, "__esModule", { value: true });
20+
exports.default = setupReducer;

lib/services/polyfills.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"use strict";
22
function loadPolyfills() {
3-
if (typeof Object.assign != 'function') {
3+
if (typeof Object.assign !== 'function') {
44
(function () {
55
Object.assign = function (target) {
66
'use strict';

src/actions/actionTypes.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
// Project
77
export const SET_PROJECT = 'SET_PROJECT';
8+
export const SET_SETUP = 'SET_SETUP';
89
export const LOAD_TUTORIALS = 'LOAD_TUTORIALS';
910

1011
// Navigation

src/actions/actions.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ export function setProject(): CR.Action {
88
return { type: Type.SET_PROJECT };
99
}
1010

11+
export function setSetup(setup: CR.Setup): CR.Action {
12+
return { type: Type.SET_SETUP, payload: setup };
13+
}
14+
1115
export function setProgress(): CR.Action {
1216
return { type: Type.SET_PROGRESS };
1317
}

src/components/projects/setup.tsx

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

src/components/projects/start.tsx

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

src/components/projects/tutorials.tsx

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

src/components/start/setup.tsx

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import * as React from 'react';
2-
import {List, ListItem} from 'material-ui';
2+
import {List, ListItem, RaisedButton} from 'material-ui';
33
import {MarkdownText} from '../_components';
4-
import {createPackageJson} from '../../services/start';
5-
import {openFolder} from '../../atom/editor';
4+
import {fileExists} from '../../services/exists';
5+
import * as path from 'path';
6+
import {open, set, openFolder} from '../../atom/editor';
67

78
export const SetupGuide = ({tutorials}) => {
89
let warnings = [];
@@ -45,5 +46,37 @@ export const SetupGuide = ({tutorials}) => {
4546
</ListItem>)}
4647

4748
</List>
49+
50+
<br />
51+
<RaisedButton label='Verify Setup' secondary={true} onTouchTap={checkSetup} />
4852
</div>);
4953
};
54+
55+
const packageData = `{
56+
"name": "demo",
57+
"dependencies": {
58+
"coderoad-functional-school": "^0.1.9"
59+
}
60+
}`;
61+
62+
function createPackageJson() {
63+
const packagePath = path.join(window.coderoad.dir, 'package.json');
64+
return new Promise((resolve, reject) => {
65+
open(packagePath);
66+
setTimeout(function() {
67+
resolve();
68+
});
69+
}).then(function() {
70+
set(packageData);
71+
window.coderoad.setup.hasPackageJson = true;
72+
});
73+
}
74+
75+
// verify package.json, tutorial installed
76+
function checkSetup() {
77+
const packagePath = path.join(window.coderoad.dir, 'package.json');
78+
if (fileExists(packagePath)) {
79+
window.coderoad.setup.hasPackageJson = true;
80+
}
81+
82+
}

src/reducers/reducer.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import runTests from './run-tests/run-tests';
1414
import editorActions from './editor-actions/editor-actions';
1515
import tutorials from './tutorials/tutorials';
1616
import log from './log/log';
17+
import setup from './setup/setup';
1718

1819
export default combineReducers({
1920
project: project,
@@ -29,5 +30,6 @@ export default combineReducers({
2930
runTests: runTests,
3031
editorActions: editorActions,
3132
tutorials: tutorials,
32-
log: log
33+
log: log,
34+
setup: setup
3335
});

src/reducers/setup/setup.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import * as Type from '../../actions/actionTypes';
2+
3+
const defaultSetup: CR.Setup = {
4+
hasDirectory: false,
5+
hasPackageJson: false,
6+
hasTutorialDep: false,
7+
hasTutorial: false,
8+
hasTestRunner: false
9+
};
10+
11+
export default function setupReducer(setup = defaultSetup, action: CR.Action): CR.Setup {
12+
switch (action.type) {
13+
case Type.SET_SETUP:
14+
return Object.assign(setup, action.payload);
15+
default:
16+
return setup;
17+
}
18+
}

src/services/polyfills.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
export default function loadPolyfills() {
22
// Object.assign temporary polyfill
3-
if (typeof Object.assign != 'function') {
3+
if (typeof Object.assign !== 'function') {
44
(function() {
55
Object.assign = function(target) {
66
'use strict';

src/services/start.ts

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

src/typings/cr/cr.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,10 @@ declare namespace CR {
111111
}
112112

113113
interface Setup {
114+
hasDirectory?: boolean;
114115
hasPackageJson?: boolean;
115116
hasTutorial?: boolean;
117+
hasTutorialDep?: boolean;
116118
hasTestRunner?: boolean;
117119
}
118120

0 commit comments

Comments
 (0)