forked from RobLoach/node-raylib
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnode-raylib
More file actions
executable file
·71 lines (56 loc) · 1.56 KB
/
node-raylib
File metadata and controls
executable file
·71 lines (56 loc) · 1.56 KB
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
#!/usr/bin/env node
// sometimes eval is not evil...
/* eslint no-eval: 0 */
const fs = require('fs')
const path = require('path')
const raylib = require('..')
const pkg = require('../package.json')
const usage = `
${pkg.description}
Usage
$ node-raylib [file]
Examples
$ node-raylib - runs data/index.js or index.js
$ node-raylib core_basic_window.js
`
// find best file for enry-point
let filename = process.argv[2]
if (filename === '--help') {
console.error(usage)
process.exit(1)
}
if (filename === '--version') {
console.log(pkg.version)
process.exit(0)
}
if (!filename) {
const f1 = path.join(process.cwd(), 'data', 'index.js')
const f2 = path.join(process.cwd(), 'index.js')
if (raylib.FileExists(f1)) {
filename = f1
} else if (raylib.FileExists(f2)) {
filename = f2
}
else {
console.error(usage)
process.exit(0)
}
}
if (!raylib.FileExists(filename)) {
console.error('Provided file does not exist.')
console.error(usage)
process.exit(1)
}
// Add a "raylib" module alias for when it's not found.
const moduleAlias = require('module-alias')
moduleAlias.addAlias('raylib', path.join(__dirname, '..'))
// Retrieve the context of the file.
const realpath = fs.realpathSync(filename)
// Switch to the file's directory so that file loading works.
process.chdir(path.dirname(realpath))
// Inject raylib as a global variable.
global.raylib = raylib
// Load up the module's path.
require(realpath)
// load the file, but don't require it (so you can use this file in an exe bundler)
eval(fs.readFileSync(realpath))