Skip to content

Commit 41beede

Browse files
authored
Merge pull request #114 from code-dot-org/cpirich/export-demo-as-dist-main-with-urlloader-for-images
Export demo for consumption within Code Studio
2 parents 3a93be2 + 8ff4a84 commit 41beede

File tree

12 files changed

+260
-110
lines changed

12 files changed

+260
-110
lines changed

package.json

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
{
22
"name": "@code-dot-org/ml-activities",
3-
"version": "0.0.1",
3+
"version": "0.0.2",
44
"description": "",
55
"main": "dist/main.js",
66
"jest": {
7-
"testEnvironment": "node"
7+
"testEnvironment": "node",
8+
"moduleNameMapper": {
9+
".+\\.(jpg|jpeg|png)$": "identity-obj-proxy"
10+
}
811
},
912
"scripts": {
1013
"build": "webpack -p",
@@ -19,7 +22,7 @@
1922
},
2023
"repository": {
2124
"type": "git",
22-
"url": "git+ssh://git@github.com/code-dot-org/dance-party.git"
25+
"url": "git+ssh://git@github.com/code-dot-org/ml-activities.git"
2326
},
2427
"author": "",
2528
"license": "Apache-2.0",
@@ -45,6 +48,8 @@
4548
"css-loader": "^3.2.0",
4649
"eslint": ">=4.18.2",
4750
"eslint-plugin-react": "^7.11.0",
51+
"idempotent-babel-polyfill": "6.26.0-1",
52+
"identity-obj-proxy": "^3.0.0",
4853
"jest": "^15.0.0",
4954
"jquery": "1.12.1",
5055
"jquery-ui": "^1.12.1",
@@ -60,6 +65,7 @@
6065
"react-dom": "~15.4.0",
6166
"react-test-renderer": "~15.4.0",
6267
"style-loader": "^1.0.0",
68+
"url-loader": "^2.2.0",
6369
"webpack": "4.19.1",
6470
"webpack-cli": "^3.3.6",
6571
"webpack-dev-server": "^3.1.4",

src/demo/helpers.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import queryString from 'query-string';
22
import {Modes} from './constants';
33
import {FishBodyPart} from '../utils/fishData';
4+
import underwaterBackground from '../../public/images/underwater-background.png';
45

56
export const backgroundPathForMode = mode => {
67
let imgName;
@@ -11,7 +12,8 @@ export const backgroundPathForMode = mode => {
1112
// Temporarily show background for every mode.
1213
imgName = 'underwater';
1314

14-
return imgName ? backgroundPath(imgName) : null;
15+
// TODO: fix this
16+
return imgName ? underwaterBackground : null;
1517
};
1618

1719
export const backgroundPath = imgName => {

src/demo/models/loading.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import 'babel-polyfill';
1+
import 'idempotent-babel-polyfill';
22
import {initRenderer} from '../renderer';
33
import {setState} from '../state';
44
import {Modes} from '../constants';

src/demo/models/pond.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import 'babel-polyfill';
1+
import 'idempotent-babel-polyfill';
22
import _ from 'lodash';
33
import {setState, getState} from '../state';
44
import constants, {ClassType} from '../constants';

src/demo/models/predict.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import 'babel-polyfill';
1+
import 'idempotent-babel-polyfill';
22
import {setState} from '../state';
33
import {generateOcean} from '../../utils/generateOcean';
44

src/demo/models/train.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import 'babel-polyfill';
1+
import 'idempotent-babel-polyfill';
22
import {setState, getState} from '../state';
33
import {ClassType} from '../constants';
44
import SimpleTrainer from '../../utils/SimpleTrainer';

src/demo/renderer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import 'babel-polyfill';
1+
import 'idempotent-babel-polyfill';
22
import {getState, setState} from './state';
33
import constants, {Modes, ClassType} from './constants';
44
import CanvasCache from './canvasCache';

src/demo/ui.jsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {Modes, DataSet} from './constants';
66
import {toMode} from './toMode';
77
import {init as initModel} from './models';
88
import {onClassifyFish} from './models/train';
9+
import aiBotClosed from '../../public/images/ai-bot-closed.png';
910

1011
const styles = {
1112
header: {
@@ -217,7 +218,7 @@ class ActivityIntro extends React.Component {
217218
Next, you’re going to teach A.I. a new word just by showing examples
218219
of that type of fish.
219220
</div>
220-
<img style={styles.activityIntroBot} src="images/ai-bot-closed.png" />
221+
<img style={styles.activityIntroBot} src={aiBotClosed} />
221222
<Footer>
222223
<Button
223224
style={styles.continueButton}
@@ -318,7 +319,7 @@ class TrainingIntro extends React.Component {
318319
Now let's teach A.I. what <b>{state.word.toUpperCase()}</b> fish look
319320
like.
320321
</div>
321-
<img style={styles.trainingIntroBot} src="images/ai-bot-closed.png" />
322+
<img style={styles.trainingIntroBot} src={aiBotClosed} />
322323
<Footer>
323324
<Button
324325
style={styles.continueButton}
@@ -344,7 +345,7 @@ class Train extends React.Component {
344345
<Body>
345346
<Header>A.I. Training</Header>
346347
<div style={trainQuestionTextStyle}>{questionText}</div>
347-
<img style={styles.trainBot} src="images/ai-bot-closed.png" />
348+
<img style={styles.trainBot} src={aiBotClosed} />
348349
<Button
349350
style={styles.trainButtonYes}
350351
onClick={() => onClassifyFish(true)}
@@ -377,7 +378,7 @@ class Predict extends React.Component {
377378
return (
378379
<Body>
379380
<Header>A.I. Sorting</Header>
380-
<img style={styles.predictBot} src="images/ai-bot-closed.png" />
381+
<img style={styles.predictBot} src={aiBotClosed} />
381382
<Footer>
382383
{state.canSkipPredict && (
383384
<Button
@@ -406,7 +407,7 @@ class Pond extends React.Component {
406407
<Body>
407408
<Header>A.I. Results</Header>
408409
<div style={styles.pondText}>{pondText}</div>
409-
<img style={styles.pondBot} src="images/ai-bot-closed.png" />
410+
<img style={styles.pondBot} src={aiBotClosed} />
410411
</Body>
411412
);
412413
}

src/index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export {init as initModel} from './demo/models';
2+
export {default as constants} from './demo/constants';
3+
export {Modes} from './demo/constants';
4+
export * from './demo/state';
5+
export {render as renderCanvas} from './demo/renderer';
6+
export {default as UI} from './demo/ui';

0 commit comments

Comments
 (0)