Skip to content

Commit 4f8678d

Browse files
committed
Automatically detect and use Skulpt distribution.
1 parent 111afc3 commit 4f8678d

File tree

6 files changed

+53
-28
lines changed

6 files changed

+53
-28
lines changed

package.json

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"btest": "node support/run/brun.js -t",
2020
"doc": "echo 'Building Documentation in docs/ProgMan' && jsdoc -c jsdoc.json HACKING.md",
2121
"dist": "npm run build && npm run testopt && npm run test3opt && npm run doc && node support/build/copy2docs.js",
22-
"repl": "npm run devbuild && node repl/repl.js dist/skulpt.js",
22+
"repl": "node repl/repl.js",
2323
"prebuild": "node support/build/wrapmodules.js internal",
2424
"build": "webpack --mode production",
2525
"postbuild": "node support/build/wrapmodules.js builtin",
@@ -31,15 +31,11 @@
3131
"testopt": "node test/testwrapper.js -o && node test/testunit.js -o",
3232
"test3": "node test/testunit.js skulpt.js --python3",
3333
"test3opt": "node test/testunit.js -o --python3",
34-
"run": "node test/runfile.js -p",
35-
"run3": "node test/runfile.js --python3 -p",
36-
"runopt": "node test/runfile.js -o -p",
37-
"run3opt": "node test/runfile.js -o --python3 -p",
38-
"preprofile": "npm run build",
39-
"profile": "node --prof --no-logfile-per-isolate --log-internal-timer-events test/runfile.js -o -p",
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",
4037
"postprofile": "node --prof-process v8.log",
41-
"preprofile3": "npm run build",
42-
"profile3": "node --prof --no-logfile-per-isolate --log-internal-timer-events test/runfile.js -o --python3 -p",
38+
"profile3": "node --prof --no-logfile-per-isolate --log-internal-timer-events support/run/runfile.js -o --python3 -p",
4339
"postprofile3": "node --prof-process v8.log"
4440
},
4541
"repository": {

repl/repl.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
require('../' + process.argv[2]);
1+
const reqskulpt = require('../support/run/require-skulpt').requireSkulpt;
2+
3+
// Import Skulpt
4+
var skulpt = reqskulpt(false);
5+
if (skulpt === null) {
6+
process.exit(1);
7+
}
28

39
var readlineSync = require('readline-sync');
410
var fs = require('fs');

support/run/require-skulpt.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
const chalk = require('chalk');
2+
3+
module.exports = {
4+
requireSkulpt: function (requireOptimized) {
5+
var skulpt;
6+
7+
try {
8+
skulpt = require("../../dist/skulpt.min.js");
9+
console.log(chalk.green("Using skulpt.min.js"));
10+
} catch (err) {
11+
if (requireOptimized) {
12+
skulpt = null;
13+
console.log(chalk.red("No optimized skulpt distribution, run 'npm run build' first."));
14+
} else {
15+
try {
16+
skulpt = require("../../dist/skulpt.js");
17+
console.log(chalk.blue("Using skulpt.js"));
18+
} catch (err) {
19+
skulpt = null;
20+
console.log(chalk.red("No skulpt distribution, run 'npm run build' or 'npm run devbuild' first."));
21+
}
22+
}
23+
}
24+
25+
return skulpt;
26+
}
27+
}

test/runfile.js renamed to support/run/runfile.js

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

56
function run (python3, opt, filename) {
67
// Import Skulpt
7-
var skulptname = 'skulpt.js';
8-
if (opt) {
9-
skulptname = 'skulpt.min.js';
8+
var skulpt = reqskulpt(opt);
9+
if (skulpt === null) {
10+
process.exit(1);
1011
}
11-
require('../dist/' + skulptname);
12+
1213
Sk.js_beautify = require('js-beautify').js;
1314

1415
var pyver, starttime, endtime, elapsed;

test/testunit.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
const fs = require('fs');
22
const path = require('path');
33
const program = require('commander');
4+
const reqskulpt = require('../support/run/require-skulpt').requireSkulpt;
45

56
function test (python3, opt) {
67
var startime, endtime, elapsed;
78

89
// Import Skulpt
9-
var skulptname = 'skulpt.js';
10-
if (opt) {
11-
skulptname = 'skulpt.min.js';
10+
var skulpt = reqskulpt(false);
11+
if (skulpt === null) {
12+
process.exit(1);
1213
}
13-
require('../dist/' + skulptname);
14+
1415
Sk.js_beautify = require('js-beautify').js;
1516

1617
// Setup for appropriate Python version

test/testwrapper.js

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,10 @@
1-
const program = require('commander');
2-
3-
program
4-
.option('-o, --opt', 'use optimized skulpt')
5-
.parse(process.argv);
1+
const reqskulpt = require('../support/run/require-skulpt').requireSkulpt;
62

73
// Import Skulpt
8-
var skulptname = 'skulpt.js';
9-
if (program.opt) {
10-
skulptname = 'skulpt.min.js';
4+
var skulpt = reqskulpt(false);
5+
if (skulpt === null) {
6+
process.exit(1);
117
}
12-
require('../dist/' + skulptname);
138

149
// Run tests
1510
require('./test.js');
16-

0 commit comments

Comments
 (0)