Skip to content

Commit 10595dd

Browse files
committed
Consolidate scripts.
1 parent 4f8678d commit 10595dd

File tree

5 files changed

+51
-49
lines changed

5 files changed

+51
-49
lines changed

package.json

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,10 @@
99
"regenparser": "node support/build/regenparser.js",
1010
"prebrun": "npm run devbuild",
1111
"brun": "node support/run/brun.js -p",
12-
"prebrundebug": "npm run devbuild",
13-
"brundebug": "node support/run/brun.js -d -p",
14-
"prebrun3": "npm run devbuild",
15-
"brun3": "node support/run/brun.js --python3 -p",
16-
"brun3debug": "node support/run/brun.js -d -p",
17-
"brun3debug": "node support/run/brun.js --python3 -d -p",
1812
"prebtest": "npm run devbuild && node support/build/wrapmodules.js unit2 && node support/build/wrapmodules.js unit3",
1913
"btest": "node support/run/brun.js -t",
2014
"doc": "echo 'Building Documentation in docs/ProgMan' && jsdoc -c jsdoc.json HACKING.md",
21-
"dist": "npm run build && npm run testopt && npm run test3opt && npm run doc && node support/build/copy2docs.js",
15+
"dist": "npm run build && npm run test && npm run doc && node support/build/copy2docs.js",
2216
"repl": "node repl/repl.js",
2317
"prebuild": "node support/build/wrapmodules.js internal",
2418
"build": "webpack --mode production",
@@ -27,16 +21,10 @@
2721
"devbuild": "webpack --mode development",
2822
"postdevbuild": "node support/build/wrapmodules.js builtin",
2923
"watch": "webpack --watch --mode development",
30-
"test": "node test/testwrapper.js && node test/testunit.js",
31-
"testopt": "node test/testwrapper.js -o && node test/testunit.js -o",
32-
"test3": "node test/testunit.js skulpt.js --python3",
33-
"test3opt": "node test/testunit.js -o --python3",
34-
"run": "node support/run/runfile.js -p",
35-
"run3": "node support/run/runfile.js --python3 -p",
36-
"profile": "node --prof --no-logfile-per-isolate --log-internal-timer-events support/run/runfile.js -o -p",
37-
"postprofile": "node --prof-process v8.log",
38-
"profile3": "node --prof --no-logfile-per-isolate --log-internal-timer-events support/run/runfile.js -o --python3 -p",
39-
"postprofile3": "node --prof-process v8.log"
24+
"test": "node test/testwrapper.js && node test/testunit.js && node test/testunit.js --python3",
25+
"start": "node support/run/runfile.js",
26+
"profile": "node --prof --no-logfile-per-isolate --log-internal-timer-events support/run/runfile.js -o",
27+
"postprofile": "node --prof-process v8.log"
4028
},
4129
"repository": {
4230
"type": "git",

support/run/brun.js

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ function getFileNames (dir) {
2727
return filelist;
2828
}
2929

30-
function brun (test, python3, debug, fname) {
30+
function brun (test, fname) {
3131
var app = express();
3232

3333
// set the view engine to ejs
@@ -56,8 +56,7 @@ function brun (test, python3, debug, fname) {
5656
res.render(path.resolve('support', 'run', 'test_template'), {
5757
test2: JSON.stringify(unit2),
5858
test3: JSON.stringify(unit3),
59-
files: filecontents,
60-
debug_mode: "false"
59+
files: filecontents
6160
});
6261
});
6362

@@ -89,20 +88,10 @@ function brun (test, python3, debug, fname) {
8988
// Test file
9089
var prog = fs.readFileSync(fname, 'utf8');
9190

92-
// Python version
93-
var pyver;
94-
if (python3) {
95-
pyver = "Sk.python3";
96-
} else {
97-
pyver = "Sk.python2";
98-
}
99-
10091
// index page
10192
app.get('/', function (req, res) {
10293
res.render(path.resolve('support', 'run', 'run_template'), {
103-
code: prog,
104-
debug_mode: debug ? "true" : "false",
105-
p3: pyver
94+
code: prog
10695
});
10796
});
10897
}
@@ -114,8 +103,6 @@ function brun (test, python3, debug, fname) {
114103

115104
program
116105
.option('-t, --test', 'Run test suites')
117-
.option('--python3', 'Python 3')
118-
.option('-d, --debug', 'Debug')
119106
.option('-p, --program <file>', 'file to run')
120107
.parse(process.argv);
121108

@@ -124,4 +111,4 @@ if (!program.test && !program.program) {
124111
process.exit();
125112
}
126113

127-
brun(program.test, program.python3, program.debug, program.program);
114+
brun(program.test, program.program);

support/run/run_template.ejs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<html>
33
<head>
44
<title></title>
5+
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.10.0/beautify.min.js"></script>
56
<script src="skulpt.js" type="text/javascript"></script>
67
<script src="skulpt-stdlib.js" type="text/javascript"></script>
78
</head>
@@ -11,6 +12,7 @@
1112
<p>Remember that you can add a debugger statement to your Python below or in the Skulpt Javascript.</p>
1213

1314
<script type="text/javascript">
15+
Sk.js_beautify = js_beautify;
1416
1517
function outf(text) {
1618
var mypre = document.getElementById(Sk.pre);
@@ -36,7 +38,7 @@ function builtinRead(x) {
3638
return file;
3739
}
3840
39-
function runit(myDiv) {
41+
function runit(myDiv, pyver) {
4042
var prog = document.getElementById(myDiv+"_code").value;
4143
var mypre = document.getElementById(myDiv+"_pre");
4244
@@ -59,13 +61,22 @@ function runit(myDiv) {
5961
6062
Sk.pre = myDiv+"_pre";
6163
64+
var future;
65+
if (pyver == "python2") {
66+
future = Sk.python2;
67+
} else if (pyver == "python3") {
68+
future = Sk.python3;
69+
}
70+
71+
var debug = document.getElementById("debug").checked;
72+
6273
Sk.configure({
6374
output:outf,
6475
read: builtinRead,
6576
inputfunTakesPrompt: true,
6677
debugout: showjs,
67-
debugging: <%= debug_mode %>,
68-
__future__: <%= p3 %>
78+
debugging: debug,
79+
__future__: future
6980
});
7081
7182
Sk.onBeforeImport = function() {
@@ -99,7 +110,11 @@ function runit(myDiv) {
99110
<textarea edit_id="eta_5" id="runbrowser_code" cols="72" rows="20" style="font-family: 'Lucida Console', Monaco, monospace;">
100111
<%- code %>
101112
</textarea>
102-
<button onclick="runit('runbrowser')" type="button">Run</button>
113+
<br>
114+
<input type="checkbox" id="debug">Debug</input>
115+
<br>
116+
<button onclick="runit('runbrowser', 'python2')" type="button">Run Python 2</button>
117+
<button onclick="runit('runbrowser', 'python3')" type="button">Run Python 3</button>
103118
</form>
104119

105120
<h3>Canvas</h3>

support/run/runfile.js

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const fs = require('fs');
22
const path = require('path');
33
const program = require('commander');
4+
const chalk = require('chalk');
45
const reqskulpt = require('./require-skulpt').requireSkulpt;
56

67
function run (python3, opt, filename) {
@@ -47,14 +48,22 @@ function run (python3, opt, filename) {
4748
}
4849

4950
program
50-
.option('--python3', 'Python 3')
5151
.option('-o, --opt', 'use optimized skulpt')
52-
.option('-p, --program <file>', 'file to run')
5352
.parse(process.argv);
5453

55-
if (!program.program) {
56-
console.log("error: option `-p, --program <file>' must specify a program to run");
57-
process.exit();
54+
if (program.args.length != 2) {
55+
console.log(chalk.red("error: must specify python version (py2/py3) and python program to run"));
56+
process.exit(1);
5857
}
5958

60-
run(program.python3, program.opt, program.program);
59+
var py3;
60+
if (program.args[0] == "py2") {
61+
py3 = false;
62+
} else if (program.args[0] == "py3") {
63+
py3 = true;
64+
} else {
65+
console.log(chalk.red("error: must specify python version ('py2' or 'py3'), not '" + program.args[0] + "'"));
66+
process.exit(1);
67+
}
68+
69+
run(py3, program.opt, program.args[1]);

test/testunit.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ function test (python3, opt) {
99
// Import Skulpt
1010
var skulpt = reqskulpt(false);
1111
if (skulpt === null) {
12-
process.exit(1);
12+
process.exit(1);
1313
}
14-
14+
1515
Sk.js_beautify = require('js-beautify').js;
1616

1717
// Setup for appropriate Python version
@@ -53,11 +53,14 @@ function test (python3, opt) {
5353

5454
function runtest (tests, passed, failed) {
5555
if (tests.length == 0) {
56-
endtime = Date.now();
57-
elapsed = (endtime - starttime) / 1000;
56+
endtime = Date.now();
57+
elapsed = (endtime - starttime) / 1000;
5858
console.log("Summary");
5959
console.log("Passed: " + passed + " Failed: " + failed);
60-
console.log("Total run time for all unit tests: " + elapsed.toString() + "s");
60+
console.log("Total run time for all unit tests: " + elapsed.toString() + "s");
61+
if (failed > 0) {
62+
process.exit(1);
63+
}
6164
return;
6265
}
6366

0 commit comments

Comments
 (0)