Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitab3a123

Browse files
committed
unminified code in src
1 parent6d7c878 commitab3a123

File tree

166 files changed

+5973
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

166 files changed

+5973
-0
lines changed

‎.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
src

‎lib/src/_base.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// Store
2+
export{store,initialState,dispatch}from'./store/store';
3+
4+
// Reducers
5+
export{defaultasreducer}from'./reducers/reducer';

‎lib/src/actions/actionTypes.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/**
2+
* Action Types
3+
*/
4+
5+
6+
// Project
7+
exportconstSET_PROJECT='SET_PROJECT';
8+
exportconstLOAD_TUTORIALS='LOAD_TUTORIALS';
9+
10+
// Navigation
11+
exportconstSET_ROUTE='SET_ROUTE';
12+
13+
// Page
14+
exportconstSET_PAGE='SET_PAGE';
15+
exportconstNEXT_PAGE='NEXT_PAGE';
16+
17+
// Position
18+
exportconstSET_POSITION='SET_POSITION';
19+
20+
// Progress
21+
exportconstSET_PROGRESS='SET_PROGRESS';
22+
exportconstPAGE_COMPLETE='PAGE_COMPLETE';
23+
exportconstCHAPTER_COMPLETE='CHAPTER_COMPLETE';
24+
exportconstPROJECT_COMPLETE='PROJECT_COMPLETE';
25+
26+
// Tasks
27+
exportconstSET_TASK_POSITION='SET_TASK_POSITION';
28+
exportconstEDITOR_ACTIONS='EDITOR_ACTIONS';
29+
exportconstSHOW_HINT='SHOW_HINT';
30+
exportconstSHOW_SOLUTION='SHOW_SOLUTION';
31+
32+
// Tests
33+
exportconstRUN_TESTS='RUN_TESTS';
34+
exportconstTEST_COMPLETE='TEST_COMPLETE';
35+
exportconstTEST_RESULT='TEST_RESULT';
36+
37+
// Log
38+
exportconstTOGGLE_LOG='CHECK_LOG';
39+
exportconstLOG_MESSAGE='LOG_MESSAGE';
40+
41+
// Alert
42+
exportconstTOGGLE_ALERT='TOGGLE_ALERT';
43+
exportconstREPLAY_ALERT='SHOW_ALERT';
44+
45+
exportconstNULL='NULL';

‎lib/src/actions/actions.spec.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// import * as Action from '../../lib/actions/actions';
2+
// import {expect} from 'chai';
3+
//
4+
// xdescribe('action creators: ', () => {
5+
//
6+
// it('setProject', () => {
7+
// expect(Action.setProject('./path/to/file.js'))
8+
// .to.deep.equal({ type: 'SET_PROJECT', payload: { filePath: './path/to/file.js' }});
9+
// });
10+
//
11+
// it('setPage with no input', () => {
12+
// expect(Action.setPage())
13+
// .to.deep.equal({ type: 'SET_PAGE', payload: { position: { chapter: 0, page: 0, task: 0 }}});
14+
// });
15+
//
16+
// it('setPage with input', () => {
17+
// expect(Action.setPage({ chapter: 1, page: 1, task: 1 }))
18+
// .to.deep.equal({ type: 'SET_PAGE', payload: { position: { chapter: 1, page: 1, task: 1 }}});
19+
// });
20+
//
21+
// it('setRoute', () => {
22+
// expect(Action.setRoute('page')).to.deep.equal({ type: 'SET_ROUTE', payload: { route: 'page' }});
23+
// });
24+
//
25+
// it('setPosition', () => {
26+
// const position = { chapter: 0, page: 1, task: 2 };
27+
// const action = Action.setPosition(position);
28+
// expect(action).to.deep.equal({ type: 'SET_POSITION', payload: { position }});
29+
// });
30+
//
31+
// it('nextTask', (taskLength: number) => {
32+
// const action = Action.nextTask();
33+
// expect(action).to.deep.equal({ type: 'NEXT_TASK', payload: { taskLength }});
34+
// });
35+
//
36+
// it('prevTask', () => {
37+
// const action = Action.prevTask();
38+
// expect(action).to.deep.equal({ type: 'PREV_TASK' });
39+
// });
40+
//
41+
// it('setCompleted with lowercase input', () => {
42+
// const position = { chapter: 0, page: 0, task: 0 };
43+
// const action = Action.setCompleted('task', true, position);
44+
// expect(action)
45+
// .to.deep.equal({ type: 'SET_COMPLETED', payload: { target: 'TASK', completed: true, position }});
46+
// });
47+
//
48+
// });

‎lib/src/actions/actions.ts

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
'use strict';
2+
import*asTypefrom'./actionTypes';
3+
import{store}from'../_base';
4+
importPackagefrom'../services/package';
5+
const_=require('lodash');
6+
7+
/* Project */
8+
exportfunctionsetProject():Action{
9+
return{type:Type.SET_PROJECT};
10+
}
11+
12+
exportfunctionsetProgress():Action{
13+
return{type:Type.SET_PROGRESS};
14+
}
15+
16+
/* Navigation */
17+
exportfunctionsetRoute(route:string):Action{
18+
return{type:Type.SET_ROUTE,payload:{ route}};
19+
}
20+
21+
/* Position */
22+
exportfunctionsetPosition(position:cr.Position):Action{
23+
return{type:Type.SET_POSITION,payload:{ position}};
24+
}
25+
26+
exportfunctionloadTutorial(name){
27+
Package.selectPackage(name);
28+
store.dispatch(setProject());
29+
store.dispatch(setPosition({chapter:0,page:0}));
30+
store.dispatch(setProgress());
31+
}
32+
33+
exportfunctiontoggleLog():Action{
34+
letopen=!store.getState().log.open;
35+
return{type:Type.TOGGLE_LOG,payload:{ open}};
36+
}
37+
38+
exportfunctionlogMessage(message:string):Action{
39+
return{type:Type.LOG_MESSAGE,payload:{ message}};
40+
}
41+
42+
/* Page */
43+
export{setPage,nextPage}from'./page-actions';
44+
45+
/* Progress */
46+
export{pageComplete,chapterComplete,projectComplete}from'./progress-actions';
47+
48+
/* Tasks */
49+
export{setTaskPosition,showHint,runTests,testComplete,testResult}from'./task-actions';
50+
51+
/* Tutorials */
52+
export{loadTutorials}from'./tutorials';
53+
54+
/* Alert */
55+
export{toggleAlert,replayAlert}from'./alert';

‎lib/src/actions/alert.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import{store}from'../_base';
2+
import*asTypefrom'./actionTypes';
3+
4+
exportfunctiontoggleAlert(alert?:cr.Alert):Action{
5+
constisOpen=store.getState().alert.open;
6+
if(!alert){
7+
alert={message:'',action:'',open:false};
8+
}else{
9+
alert=_.assign(alert,{open:!isOpen});
10+
}
11+
return{type:Type.TOGGLE_ALERT,payload:{ alert}};
12+
}
13+
14+
exportfunctionreplayAlert():Action{
15+
return{type:Type.REPLAY_ALERT};
16+
}

‎lib/src/actions/page-actions.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import*asTypefrom'./actionTypes';
2+
import*asActionfrom'./actions';
3+
import{store}from'../_base';
4+
importPackagefrom'../services/package';
5+
const_=require('lodash');
6+
7+
exportfunctionsetPage(selectedPosition:cr.Position={chapter:0,page:0}):Action{
8+
constpage=Package.getPage(selectedPosition);
9+
consttasks=Package.getTasks(selectedPosition);
10+
consttaskTests:cr.TaskTest[]=_.flatten(tasks.map((task)=>task.tests||[]));
11+
letactions:string[]=tasks.map((task)=>task.actions||[]);
12+
return{type:Type.SET_PAGE,payload:{ page, tasks,position:selectedPosition, taskTests, actions}};
13+
}
14+
15+
exportfunctionnextPage():Action{
16+
constposition=store.getState().position;
17+
constnextPosition=Package.getNextPosition(position);
18+
returnsetPage(nextPosition);
19+
}

‎lib/src/actions/progress-actions.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import*asTypefrom'./actionTypes';
2+
import{store}from'../_base';
3+
4+
exportfunctionpageComplete(){
5+
constposition=store.getState().position;
6+
constpageLength=store.getState().progress.chapters[position.chapter].pages.length;
7+
constaction={type:Type.PAGE_COMPLETE,payload:{ position}};
8+
if(position.page>=pageLength-1){
9+
store.dispatch(chapterComplete());
10+
returnaction;
11+
}
12+
returnaction;
13+
}
14+
15+
exportfunctionchapterComplete():Action{
16+
constchapter=store.getState().position.chapter;
17+
constchapterLength=store.getState().progress.chapters.length;
18+
constaction={type:Type.CHAPTER_COMPLETE,payload:{ chapter}};
19+
if(chapter>=chapterLength-1){
20+
store.dispatch(projectComplete());
21+
returnaction;
22+
}
23+
returnaction;
24+
}
25+
26+
exportfunctionprojectComplete():Action{
27+
return{type:Type.PROJECT_COMPLETE};
28+
}

‎lib/src/actions/task-actions.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import*asTypefrom'./actionTypes';
2+
import*asActionfrom'./actions';
3+
import{store}from'../_base';
4+
5+
functioncheckPageComplete(taskPosition:number){
6+
consttaskLength:number=store.getState().taskTests.length;
7+
if(taskPosition>taskLength){
8+
store.dispatch(Action.pageComplete());
9+
}
10+
}
11+
12+
exportfunctionsetTaskPosition(taskPosition:number):Action{
13+
constcurrentTaskPosition=store.getState().taskPosition;
14+
if(currentTaskPosition===taskPosition){
15+
return{type:Type.NULL};
16+
}
17+
checkPageComplete(taskPosition);
18+
return{type:Type.SET_TASK_POSITION,payload:{ taskPosition}};
19+
}
20+
21+
exportfunctionshowHint():Action{
22+
return{type:Type.SHOW_HINT};
23+
}
24+
25+
exportfunctionrunTests():Action{
26+
return{type:Type.RUN_TESTS};
27+
}
28+
29+
exportfunctiontestResult(result):Action{
30+
letactions=store.getState().editorActions;
31+
return{type:Type.TEST_RESULT,payload:{ result, actions}};
32+
}
33+
34+
exportfunctiontestComplete():Action{
35+
return{type:Type.TEST_COMPLETE};
36+
}

‎lib/src/actions/tutorials.ts

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import{store}from'../_base';
2+
import*asActionfrom'./actions';
3+
import*aspathfrom'path';
4+
import*asfsfrom'fs';
5+
import*asTypefrom'./actionTypes';
6+
import{fileExists}from'../services/exists';
7+
8+
exportfunctionloadTutorials():Action{
9+
lettutorials=[];
10+
if(global.coderoad.dir){
11+
letpackageJson=loadRootPackageJson();
12+
if(!packageJson){
13+
global.coderoad.package=null;
14+
letmessage='No package.json file available. Try running "npm init --y" in terminal';
15+
console.log(message);
16+
store.dispatch(Action.toggleAlert({ message,action:'tip',duration:6000}));
17+
}else{
18+
tutorials=[]
19+
.concat(searchForTutorials(packageJson.dependencies))
20+
.concat(searchForTutorials(packageJson.devDependencies));
21+
}
22+
}
23+
return{type:Type.LOAD_TUTORIALS,payload:{ tutorials}};
24+
}
25+
26+
27+
functionloadRootPackageJson(){
28+
letpathToPackageJson=path.join(global.coderoad.dir,'package.json');
29+
if(fileExists(pathToPackageJson)){
30+
returnJSON.parse(fs.readFileSync(pathToPackageJson,'utf8'));
31+
}
32+
returnfalse;
33+
}
34+
35+
functionisTutorial(name):boolean{
36+
letpathToTutorialPackageJson=path.join(global.coderoad.dir,'node_modules',name,'package.json');
37+
if(fileExists(pathToTutorialPackageJson)){
38+
// has package.json
39+
letpackageJson=JSON.parse(fs.readFileSync(pathToTutorialPackageJson,'utf8'));
40+
// main path to coderoad.json
41+
if(packageJson.main&&packageJson.main.match(/coderoad.json$/)){
42+
letpathToCoderoadJson=path.join(global.coderoad.dir,'node_modules',name,packageJson.main);
43+
// coderoad.json file exists
44+
if(fileExists(pathToCoderoadJson)){
45+
returntrue;
46+
}
47+
}
48+
}
49+
returnfalse;
50+
}
51+
52+
functionsearchForTutorials(location):string[]{
53+
if(!!location&&Object.keys(location).length>0){
54+
returnObject.keys(location).filter((name)=>isTutorial(name));
55+
}else{
56+
return[];
57+
}
58+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp