-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.ls
More file actions
63 lines (63 loc) · 1.51 KB
/
cli.ls
File metadata and controls
63 lines (63 loc) · 1.51 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
``__dirname = process.cwd();``
let
require! {
fs
path
yargs
\./livescript.min.js
}
{argv} = yargs
.command "ls2 <filepath>" "Run filepath"
.command "ls2 -c <src> <dist>" "Compile src to dist"
.option \c,
alias: \compile
type: \array
describe: "Compile src to dist"
.option \b,
alias: \bare
type: \boolean
default: no
describe: "Compile without the top-level function wrapper"
.option \e,
alias: \header
type: \boolean
default: yes
describe: "Add the \"Generated by\" header"
.option \n,
type: \boolean
describe: "Negate of --header"
.alias \h \help
.alias \v \version
switch
| argv.compile
let
if argv.compile.length < 2
throw Error "Missing <src> or <dist> args"
else
[src, dist] = argv.compile
{bare, header} = argv
src = path.resolve __dirname, src
dist = path.resolve __dirname, dist
header = no if argv.n
code = fs.readFileSync src, \utf8
code = livescript.compile code,
bare: bare
header: header
fs.writeFileSync dist, code
else
let
[filepath] = argv._
if filepath
require = global.require = (file) ->
if /^\.{0,2}\//test file
module.require path.resolve __dirname, file
else
module.require file
if not filepath.endsWith \.ls
filepath += \.ls
filepath = path.resolve __dirname, filepath
code = fs.readFileSync filepath, \utf8
code = livescript.compile code
code = "delete code;#code"
do (fs, path, yargs, livescript, argv, filepath) !->
eval code