Skip to content

Commit 03c619f

Browse files
committed
Rearrange website directory and change webpack config
1 parent a796b13 commit 03c619f

9 files changed

Lines changed: 180 additions & 137 deletions

File tree

wasm/app/bootstrap.js

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

wasm/app/index.html

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

wasm/app/index.js

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

wasm/app/package.json

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,31 @@
11
{
2-
"name": "app",
3-
"version": "1.0.0",
4-
"description": "",
5-
"main": "index.js",
6-
"dependencies": {
7-
"hello-wasm-pack": "^0.1.0",
8-
"webpack": "^4.16.3",
9-
"webpack-cli": "^3.1.0",
10-
"webpack-dev-server": "^3.1.5",
11-
"copy-webpack-plugin": "^4.5.2"
12-
},
13-
"devDependencies": {},
14-
"scripts": {
15-
"test": "echo \"Error: no test specified\" && exit 1"
16-
},
17-
"repository": {
18-
"type": "git",
19-
"url": "git+https://github.com/RustPython/RustPython.git"
20-
},
21-
"author": "Ryan Liddle",
22-
"license": "MIT",
23-
"bugs": {
24-
"url": "https://github.com/RustPython/RustPython/issues"
25-
},
26-
"homepage": "https://github.com/RustPython/RustPython#readme"
2+
"name": "app",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"dependencies": {
7+
"codemirror": "^5.42.0"
8+
},
9+
"devDependencies": {
10+
"webpack": "^4.16.3",
11+
"webpack-cli": "^3.1.0",
12+
"webpack-dev-server": "^3.1.5",
13+
"copy-webpack-plugin": "^4.5.2",
14+
"mini-css-extract-plugin": "^0.5.0",
15+
"html-webpack-plugin": "^3.2.0",
16+
"css-loader": "^2.0.1"
17+
},
18+
"scripts": {
19+
"test": "echo \"Error: no test specified\" && exit 1"
20+
},
21+
"repository": {
22+
"type": "git",
23+
"url": "git+https://github.com/RustPython/RustPython.git"
24+
},
25+
"author": "Ryan Liddle",
26+
"license": "MIT",
27+
"bugs": {
28+
"url": "https://github.com/RustPython/RustPython/issues"
29+
},
30+
"homepage": "https://github.com/RustPython/RustPython#readme"
2731
}

wasm/app/src/bootstrap.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import './style.css';
2+
import 'codemirror/lib/codemirror.css';
3+
4+
// A dependency graph that contains any wasm must all be imported
5+
// asynchronously. This `bootstrap.js` file does the single async import, so
6+
// that no one else needs to worry about it again.
7+
import('./index.js').catch(e => {
8+
console.error('Error importing `index.js`:', e);
9+
document.getElementById('error').textContent = e;
10+
});

wasm/app/src/index.html

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8" />
5+
<title>RustPython Demo</title>
6+
</head>
7+
<body>
8+
<h1>RustPython Demo</h1>
9+
<p>
10+
RustPython is a Python interpreter writter in Rust. This demo is
11+
compiled from Rust to WebAssembly so it runs in the browser
12+
</p>
13+
<p>Please input your python code below and click <kbd>Run</kbd>:</p>
14+
<p>
15+
Alternatively, open up your browser's devtools and play with
16+
<code>rp.eval_py('print("a")')</code>
17+
</p>
18+
<textarea id="code">
19+
n1 = 0
20+
n2 = 1
21+
count = 0
22+
until = 10
23+
24+
print("These are the first " + str(until) + " number in a Fibonacci sequence:")
25+
26+
while count < until:
27+
print(n1)
28+
n1, n2 = n2, n1 + n2
29+
count += 1
30+
31+
</textarea>
32+
<button id="run-btn">Run &#9655;</button>
33+
<div id="error"></div>
34+
<h3>Standard Output</h3>
35+
<textarea id="console">Loading...</textarea>
36+
37+
<a href="https://github.com/RustPython/RustPython">
38+
<img
39+
style="position: absolute; top: 0; right: 0; border: 0;"
40+
src="https://s3.amazonaws.com/github/ribbons/forkme_right_green_007200.png"
41+
alt="Fork me on GitHub"
42+
/>
43+
</a>
44+
</body>
45+
</html>

wasm/app/src/index.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import * as rp from '../../pkg';
2+
import CodeMirror from 'codemirror';
3+
import 'codemirror/mode/python/python';
4+
import 'codemirror/addon/comment/comment';
5+
6+
// so people can play around with it
7+
window.rp = rp;
8+
9+
const editor = CodeMirror.fromTextArea(document.getElementById('code'), {
10+
extraKeys: {
11+
'Ctrl-Enter': runCodeFromTextarea,
12+
'Cmd-Enter': runCodeFromTextarea,
13+
'Shift-Tab': 'indentLess',
14+
'Ctrl-/': 'toggleComment',
15+
'Cmd-/': 'toggleComment'
16+
},
17+
mode: 'text/x-python',
18+
indentUnit: 4,
19+
autofocus: true
20+
});
21+
22+
function runCodeFromTextarea() {
23+
const consoleElement = document.getElementById('console');
24+
const errorElement = document.getElementById('error');
25+
26+
// Clean the console and errors
27+
consoleElement.value = '';
28+
errorElement.textContent = '';
29+
30+
const code = editor.getValue();
31+
try {
32+
rp.run_from_textbox(code);
33+
} catch (e) {
34+
errorElement.textContent = e;
35+
console.error(e);
36+
}
37+
}
38+
39+
document
40+
.getElementById('run-btn')
41+
.addEventListener('click', runCodeFromTextarea);
42+
43+
runCodeFromTextarea(); // Run once for demo

wasm/app/src/style.css

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
textarea {
2+
font-family: monospace;
3+
resize: none;
4+
}
5+
6+
#code {
7+
height: 35vh;
8+
width: calc(100% - 3px);
9+
}
10+
11+
.CodeMirror {
12+
border: 1px solid #ddd;
13+
height: 35vh !important;
14+
}
15+
16+
#console {
17+
height: 35vh;
18+
width: calc(100% - 3px);
19+
}
20+
21+
#run-btn {
22+
width: 6em;
23+
height: 2em;
24+
font-size: 24px;
25+
}
26+
27+
#error {
28+
color: tomato;
29+
margin-top: 10px;
30+
font-family: monospace;
31+
}

wasm/app/webpack.config.js

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,26 @@
1-
const CopyWebpackPlugin = require("copy-webpack-plugin");
1+
const HtmlWebpackPlugin = require('html-webpack-plugin');
2+
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
23
const path = require('path');
34

45
module.exports = {
5-
entry: "./bootstrap.js",
6-
output: {
7-
path: path.resolve(__dirname, "dist"),
8-
filename: "bootstrap.js",
9-
},
10-
mode: "development",
11-
plugins: [
12-
new CopyWebpackPlugin(['index.html'])
13-
],
6+
entry: './src/bootstrap.js',
7+
output: {
8+
path: path.resolve(__dirname, 'dist'),
9+
filename: 'bootstrap.js'
10+
},
11+
mode: 'development',
12+
module: {
13+
rules: [
14+
{ test: /\.css$/, use: [MiniCssExtractPlugin.loader, 'css-loader'] }
15+
]
16+
},
17+
plugins: [
18+
new HtmlWebpackPlugin({
19+
filename: 'index.html',
20+
template: 'src/index.html'
21+
}),
22+
new MiniCssExtractPlugin({
23+
filename: 'styles.css'
24+
})
25+
]
1426
};

0 commit comments

Comments
 (0)