-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
executable file
·47 lines (42 loc) · 1.14 KB
/
index.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
#!/usr/bin/env node
"use strict";
const path = require("path");
const commander = require("commander");
const {
spawn,
fs: { requireSafe }
} = require("./node_modules/batman-cli/lib/utils");
const APP_PATH = process.cwd();
const pathJoin = path.join.bind();
const className = mainFile => mainFile.replace(/\//g, ".").replace(".java", "");
const njavaConfig = Object.assign(
{
bin: "Main.java"
},
requireSafe(pathJoin(APP_PATH, "/.njavarc.json"))
);
commander
.version("1.0.0")
.option(
"-i, --init [projectName]",
"Create a sample node java working project"
);
commander.on("--help", function () {
console.log("\n###### Working on IT ######\n");
});
commander.parse(process.argv);
if (commander.init) {
const projectName = typeof commander.init === "string" ? commander.init : "";
spawn(
`cp -r ${pathJoin(__dirname, "example")} ${pathJoin(
APP_PATH,
projectName || "example"
)}`
);
} else {
spawn(
`cd src/main/java/ && javac -d classes ${
njavaConfig.bin
} && java -cp classes ${className(njavaConfig.bin)}`
);
}