-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathseen-cli.ts
More file actions
executable file
·99 lines (90 loc) · 3.44 KB
/
seen-cli.ts
File metadata and controls
executable file
·99 lines (90 loc) · 3.44 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/usr/bin/env node
import { execSync } from "child_process";
import { program } from "commander";
import { argv } from "process";
import { dirname, resolve } from "path";
import { existsSync, mkdirSync } from "fs";
program //
.name("seen")
.description("An all-in-one CLI program for SeenKit.")
.version("1.0.0");
// Build ////////////////////////////////////////////////////////////////////////
{
enum SeenKitPlatform {
kAndroid = "android",
kIOS = "ios",
kMacOS = "macos",
kLinux = "linux",
kWeb = "web",
kWindows = "windows",
}
const PLATFORMS = Object.values(SeenKitPlatform).join("/");
function isSeenKitPlatform(platform: unknown): platform is SeenKitPlatform {
if (typeof platform !== "string") {
return false;
}
const values = Object.values(SeenKitPlatform) as string[];
return values.includes(platform);
}
const PROJECT_COMMANDS = {
[SeenKitPlatform.kAndroid]: "",
[SeenKitPlatform.kIOS]: `cmake . -B build-ios \
-G Xcode \
-DCMAKE_TOOLCHAIN_FILE=cmake/ios.toolchain.cmake \
-DPLATFORM=OS64COMBINED
open -a /Applications/Xcode.app build-ios`,
[SeenKitPlatform.kMacOS]: `cmake . -B build-macos -G Xcode
open -a /Applications/Xcode.app build-macos`,
[SeenKitPlatform.kLinux]: "",
[SeenKitPlatform.kWeb]: "",
[SeenKitPlatform.kWindows]: "",
};
const BUILD_COMMANDS = {
[SeenKitPlatform.kAndroid]: "",
[SeenKitPlatform.kIOS]: `cmake . -B build-ios \
-G Xcode \
-DCMAKE_TOOLCHAIN_FILE=cmake/ios.toolchain.cmake \
-DPLATFORM=OS64COMBINED
cmake --build ./build-ios --target seen --config Release`,
[SeenKitPlatform.kMacOS]: `cmake . -B build-macos -G Xcode
cmake --build build-macos --target seen --config Release`,
[SeenKitPlatform.kLinux]: "",
[SeenKitPlatform.kWeb]: "",
[SeenKitPlatform.kWindows]: "",
};
program
.command("build")
.description("build SeenKit to platform-specific library")
.argument("<platform>", `specify SeenKit target platform (${PLATFORMS})`)
.option("--project", "try to generate a SeenKit library project if possible", false)
.action((platform?: SeenKitPlatform, option?: { project: boolean }) => {
if (!isSeenKitPlatform(platform)) {
return;
}
const command = option?.project ? PROJECT_COMMANDS[platform] : BUILD_COMMANDS[platform];
execSync(command, { stdio: "inherit" });
});
}
// Bundle ////////////////////////////////////////////////////////////////////////
{
program
.command("tsb")
.description("TypeScript bundler designed for SeenKit")
.option("-o, --output <output>", "bundle output path", "demo.seen")
.action((option: { output: string }) => {
const output = resolve(option.output);
const outputDir = dirname(output);
if (!existsSync(outputDir)) {
mkdirSync(outputDir, { recursive: true });
}
// TODO(Autokaka): Make this generic and cross-platform...
const commands = [
`npx tstl --luaBundle ${outputDir}/main.lua`,
`cd ${outputDir}`,
`zip demo.seen main.lua`,
`rm main.lua`,
];
execSync(commands.join(" && "), { stdio: "inherit" });
});
}
program.parse(argv);