-
Notifications
You must be signed in to change notification settings - Fork 2
/
runtime-playground.js
executable file
·91 lines (82 loc) · 2.02 KB
/
runtime-playground.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/usr/bin/env node
require('shelljs/global')
require('colors')
config.fatal = true
var read = require('readline-sync')
var temp = require('tempfile')
var argv = require('minimist')(process.argv.slice(2))
var cmd = argv._.shift()
if (cmd === 'doctor') {
if (!which('qemu-system-x86_64')) {
echo('please install qemu'.red)
echo('on osx try: brew install qemu'.grey)
echo('not ok'.red)
}
else {
echo('ready to run'.green)
echo('try: runtime-playground demo'.grey)
exit(0)
}
exit(1)
}
else if (cmd === 'init') {
var dir = argv._.pop() || process.cwd()
ok = read.question('Create scaffolding in ' + dir.grey + '\nY/n > ').trim()
if (ok !== 'n' && ok !== 'N') {
doInit()
}
else {
echo('Abort: Nothing Created'.yellow)
}
}
else if (cmd === 'demo') {
echo('switch to qemu to view your system'.green)
echo('next: generate scaffolding with `runtime-playground init .`'.grey)
doQemu(__dirname + '/demo/init.js')
}
else if (cmd === 'run') {
var file = argv._.shift()
if (!file) {
echo('Please specify init file'.red)
exit(1)
}
else if (!test('-e', file)) {
echo(('File ' + file + ' does not exist').red)
exit(1)
}
else {
doQemu(file)
}
}
else {
echo(cat(__dirname + '/usage.txt').grey)
exit(1)
}
function doQemu(file) {
var tempfile = temp('.js')
var brfs = __dirname + '/node_modules/brfs'
var browserify = __dirname + '/node_modules/.bin/browserify -t ' + brfs + ' ' + file + ' -o ' + tempfile
if (exec(browserify).code !== 0) {
echo('browserify error'.red)
exit(1)
}
var qemu = [
'qemu-system-x86_64',
'-m 512',
'-smp 1',
'-s',
'-boot order=d',
'-netdev user,id=mynet0,hostfwd=tcp::5555-:80',
'-device rtl8139,netdev=mynet0,mac=1a:46:0b:ca:bc:7c',
'-kernel ' + __dirname + '/kernel.bin',
'-initrd ' + tempfile,
'-serial stdio',
'-localtime',
'-M pc',
].join(' ')
exec(qemu)
}
function doInit() {
echo('creating scaffolding'.green)
cp('-R', __dirname + '/scaffolding/*', process.cwd())
}