Skip to content

Commit ff9e308

Browse files
committed
Initial import of webworker implementation
1 parent 225370e commit ff9e308

25 files changed

+711
-309
lines changed

.babelrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"presets": ["es2015", "react", "stage-0"]
3+
}

.eslintrc.json

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
{
2+
"parser": "babel-eslint",
23
"env": {
34
"browser": true,
45
"commonjs": true,
5-
"es6": true
6+
"es6": true,
7+
"jest": true
68
},
79
"extends": "eslint:recommended",
810
"parserOptions": {
@@ -12,14 +14,31 @@
1214
},
1315
"sourceType": "module"
1416
},
15-
"plugins": ["react"],
17+
"plugins": ["prettier", "react"],
1618
"globals": {
17-
"__DEV__": true
19+
"__DEV__": true,
20+
"NODE_ENV": true,
21+
"__DEV__": true,
22+
"__PROD__": true,
23+
"__TEST__": true,
24+
"__COVERAGE__": true,
25+
"__BASENAME__": true,
26+
"API_SERVER_HOST": true,
27+
"S3_SERVER_HOST": true,
28+
"SNIPPET_BUCKET_URL": true
1829
},
1930
"rules": {
2031
"indent": ["error", 2],
2132
"linebreak-style": ["error", "unix"],
2233
"quotes": ["error", "single"],
2334
"semi": ["error", "always"]
24-
}
35+
},
36+
"prettier/prettier": [
37+
"error",
38+
{
39+
"printWidth": 80,
40+
"trailingComma": "all",
41+
"singleQuote": true
42+
}
43+
]
2544
}

config/project.config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ const config = {
3030
// ----------------------------------
3131
// API Server Configuration
3232
// ----------------------------------
33-
api_server_host: 'http://localhost:8000/', // use string 'localhost' to prevent exposure on local network
34-
s3_server_host: 'http://staging.es6console.com/',
33+
api_server_host: 'http://localhost:3000/', // use string 'localhost' to prevent exposure on local network
34+
s3_server_host: 'http://localhost:8001/',
3535

3636
// ----------------------------------
3737
// AWS Configuration

config/webpack.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ if (__DEV__) {
9292
debug('Enabling plugins for live development (HMR, NoErrors).');
9393
webpackConfig.plugins.push(
9494
new webpack.HotModuleReplacementPlugin(),
95+
new webpack.NamedModulesPlugin(),
9596
new webpack.NoErrorsPlugin()
9697
);
9798
} else if (__PROD__) {

package.json

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,38 @@
105105
},
106106
"author": "Matthisk Heimensen <m@tthisk.nl> (http://matthisk.nl)",
107107
"license": "MIT",
108+
"jest": {
109+
"cacheDirectory": "<rootDir>/test/.cache",
110+
"setupTestFrameworkScriptFile": "./node_modules/jest-enzyme/lib/index.js",
111+
"transform": {
112+
"\\.(js|jsx)$": "babel-jest"
113+
},
114+
"testRegex": "(\\.(test|spec))\\.(ts|tsx|js|jsx)$",
115+
"moduleDirectories": [
116+
"node_modules",
117+
"src"
118+
],
119+
"unmockedModulePathPatterns": [
120+
"<rootDir>/node_modules/react",
121+
"<rootDir>/node_modules/react-dom",
122+
"<rootDir>/node_modules/react-addons-test-utils",
123+
"enzyme"
124+
],
125+
"moduleFileExtensions": [
126+
"js",
127+
"json",
128+
"jsx"
129+
],
130+
"collectCoverageFrom": [
131+
"**/*.{js,jsx}"
132+
]
133+
},
108134
"dependencies": {
109135
"babel-core": "^6.17.0",
110136
"babel-eslint": "^7.1.0",
111137
"babel-loader": "^6.2.5",
112138
"babel-plugin-istanbul": "^3.0.0",
139+
"babel-plugin-transform-remove-console": "^6.8.4",
113140
"babel-plugin-transform-runtime": "^6.15.0",
114141
"babel-polyfill": "~6.22.0",
115142
"babel-preset-es2015": "^6.14.0",
@@ -162,19 +189,26 @@
162189
"yargs": "^6.3.0"
163190
},
164191
"devDependencies": {
192+
"babel-eslint": "^7.2.3",
193+
"babel-jest": "^20.0.3",
194+
"babel-plugin-transform-remove-console": "^6.8.4",
165195
"chai": "^3.4.1",
166196
"chai-as-promised": "^6.0.0",
167197
"chai-enzyme": "^0.6.1",
168198
"cheerio": "^0.22.0",
169199
"codecov": "^1.0.1",
170-
"enzyme": "^2.0.0",
200+
"enzyme": "^2.9.1",
171201
"eslint": "^3.0.1",
202+
"eslint-config-prettier": "^2.3.0",
172203
"eslint-config-standard": "^6.0.0",
173204
"eslint-config-standard-react": "^4.0.0",
174205
"eslint-plugin-babel": "^4.0.0",
206+
"eslint-plugin-prettier": "^2.1.2",
175207
"eslint-plugin-promise": "^3.0.0",
176208
"eslint-plugin-react": "^6.10.3",
177209
"eslint-plugin-standard": "^2.0.0",
210+
"jest": "^20.0.4",
211+
"jest-enzyme": "^3.6.1",
178212
"karma": "^1.0.0",
179213
"karma-coverage": "^1.0.0",
180214
"karma-mocha": "^1.0.1",
@@ -186,8 +220,10 @@
186220
"mocha": "^3.0.1",
187221
"nodemon": "~1.11.0",
188222
"phantomjs-prebuilt": "^2.1.12",
223+
"prettier": "^1.5.3",
189224
"react-addons-test-utils": "^15.0.0",
190225
"redbox-react": "^1.2.10",
226+
"regenerator-runtime": "^0.10.5",
191227
"rimraf": "^2.5.4",
192228
"sinon": "^1.17.5",
193229
"sinon-chai": "^2.8.0",

src/compilers/babel6.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,22 @@
11
import Base from './base';
22

3+
import removeConsolePlugin from 'babel-plugin-transform-remove-console';
4+
35
import $script from 'scriptjs';
46

57
export default class Babel extends Base {
68
loadCompiler() {
7-
$script(['https://unpkg.com/babel-standalone@6.15.0/babel.min.js'],() => {
9+
$script(['https://unpkg.com/babel-standalone@6.25.0/babel.min.js'],() => {
810
this.compiler = window.Babel;
11+
this.compiler.registerPlugin('transform-remove-console', removeConsolePlugin);
912
this.resolveFuture();
1013
});
1114
}
1215

16+
transform(input, options) {
17+
return this.compiler.transform(input, options);
18+
}
19+
1320
compile( input, options ) {
1421
this._checkIfCompilerIsLoaded();
1522

src/components/Console/Console.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class _Console extends Component {
2929
this.jsconsole = new JSConsole(node, {
3030
mode: 'javascript',
3131
theme: 'default',
32-
evaluate: this.props.runCode,
32+
evaluate: async (consoleCode) => this.props.runCode(this.props.es5code, consoleCode),
3333
commands: {
3434
'help': function() {
3535
this.print(HELP_TEXT);
@@ -57,6 +57,11 @@ class _Console extends Component {
5757
this.props.flushBuffer();
5858
}
5959

60+
if (this.props.out) {
61+
this.jsconsole.renderResult(this.props.in, this.props.out);
62+
this.props.flushResult();
63+
}
64+
6065
this.jsconsole.output.refresh();
6166
}
6267

@@ -85,7 +90,10 @@ class _Console extends Component {
8590
}
8691

8792
function mapStateToProps(state) {
88-
return state.ide.console;
93+
return {
94+
...state.ide.console,
95+
es5code: state.ide.editors.es5.code,
96+
};
8997
}
9098

9199
export default connect(mapStateToProps, actionCreators)(_Console);

src/components/Console/jsconsole.js

Lines changed: 13 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import CodeMirror from 'codemirror';
22

3-
import { sandbox } from 'sandbox';
3+
import { sandbox } from 'utils/sandbox';
4+
import { complexFormatter } from 'utils';
45

56
import 'codemirror/lib/codemirror.css';
67
import 'codemirror/theme/eclipse.css';
@@ -21,6 +22,7 @@ class Console {
2122
this.historyIndex = -1;
2223
this.events = {};
2324
this.commands = options.commands || {};
25+
this.evaluate = options.evaluate;
2426

2527
var enter = () => {
2628
var text = this.input.getValue().trim();
@@ -231,45 +233,18 @@ class Console {
231233
break;
232234
case 'object':
233235
case 'array':
234-
// Todo: pretty print object output
235-
output.formatted = JSON.stringify(value);
236+
output.formatted = complexFormatter(value);
236237
break;
237238
case 'error':
238-
output.formatted = value.message.trim();
239+
output.formatted = JSON.stringify(value.message.trim());
239240
break;
240241
default:
241242
output.formatted = value.toString().trim();
242243
}
243244
return output;
244245
}
245246

246-
evaluate(code) {
247-
let match = /\:(\w+)/.exec(code);
248-
249-
if (match) {
250-
let fn = this.commands[match[1]];
251-
252-
if (fn) {
253-
fn.call(this, code);
254-
this.resetInput();
255-
return;
256-
}
257-
}
258-
259-
let out = sandbox.runCode(code);
260-
261-
if (out.logBuffer.length) {
262-
out.logBuffer.forEach((msg) => {
263-
this.print(msg);
264-
});
265-
}
266-
267-
return out;
268-
}
269-
270-
exec(text) {
271-
this.isEvaluating = true;
272-
var rv = this.evaluate(text);
247+
renderResult(text, rv) {
273248
if (!rv) return;
274249
this.isEvaluating = false;
275250
var doc = this.input.getDoc();
@@ -281,7 +256,8 @@ class Console {
281256
} else if (rv.recoverable) {
282257
CodeMirror.commands.newlineAndIndent(this.input);
283258
} else {
284-
this.appendEntry(text, rv.completionValue);
259+
if (rv.hasOwnProperty('completionValue'))
260+
this.appendEntry(text, rv.completionValue);
285261
this.addHistory(text);
286262
this.resetInput();
287263
}
@@ -292,6 +268,11 @@ class Console {
292268
});
293269
}
294270

271+
async exec(text) {
272+
this.isEvaluating = true;
273+
await this.evaluate(text);
274+
}
275+
295276
resetInput(text = '') {
296277
this.input.setValue(text.toString());
297278
this.input.execCommand('goDocEnd');

src/components/Header/Header.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import 'react-select/dist/react-select.css';
1212

1313
export const Header = ({
1414
code,
15+
es5code,
1516
transformCode,
1617
runCode,
1718
editorConfig,
@@ -30,7 +31,7 @@ export const Header = ({
3031

3132
<Toolbar>
3233
<Toolbar.Item icon="video play outline"
33-
onClick={e => runCode()}>
34+
onClick={() => runCode(es5code)}>
3435
Run
3536
</Toolbar.Item>
3637
<Toolbar.Item icon="save"
@@ -103,10 +104,11 @@ export const Header = ({
103104
</div>
104105
);
105106

106-
function mapStateToProps(state, ownProps) {
107+
function mapStateToProps(state) {
107108
return {
108109
editorConfig: state.ide.editorConfig,
109110
code: state.ide.editors['es6'].code,
111+
es5code: state.ide.editors['es5'].code,
110112
availableThemes: ['default'].concat(state.themes.available),
111113
};
112114
}

src/containers/AppContainer.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { Provider } from 'react-redux'
55
import { DEFAULT_COMPILER } from 'compilers'
66
import {
77
selectCompiler,
8-
runCode,
98
} from 'store/ide'
109
import { loadExamples } from 'store/examples'
1110
import { loadThemes } from 'store/themes'

0 commit comments

Comments
 (0)