forked from sctb/lumen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsystem.l
63 lines (49 loc) · 1.43 KB
/
system.l
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
(define fs (require "fs"))
(define child-process (require "child_process"))
(define path (require "path"))
(define process (require "process"))
(define read-file (path (o mode 'text))
(if (= mode 'text)
(fs .read-file-sync path "utf8" .replace |/\r/g| "")
(fs .read-file-sync path)))
(define write-file (path data)
(fs .write-file-sync path data "utf8"))
(define file-exists? (path)
(and (fs .exists-sync path "utf8")
(fs .stat-sync path (.is-file))))
(define directory-exists? (path)
(and (fs .exists-sync path "utf8")
(fs .stat-sync path (.is-directory))))
(define path-separator
(path .sep))
(define path-join parts
(or (reduce (fn (x y) (cat x path-separator y)) parts) ""))
(define get-environment-variable (name)
(process .env [name]))
(define set-environment-variable (name value)
(set (process .env [name]) value))
(define write (x cb)
(let out (process .stdout)
(out .write x cb)))
(define exit (code)
(process .exit code))
(define argv
(cut (process .argv) 2))
(define reload (module)
(wipe (require .cache [(require .resolve module)]))
(require module))
(define shell (command)
(child-process .exec-sync command (.to-string)))
(export read-file
write-file
file-exists?
directory-exists?
path-separator
path-join
get-environment-variable
set-environment-variable
write
exit
argv
reload
shell)