-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathcli.ts
More file actions
50 lines (44 loc) · 1.46 KB
/
cli.ts
File metadata and controls
50 lines (44 loc) · 1.46 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
import { Command } from "@effect/cli";
import { BunContext, BunRuntime } from "@effect/platform-bun";
import { Effect, Layer } from "effect";
import { existsSync, renameSync, unlinkSync } from "fs";
import { listen } from "./commands/listen";
import { login } from "./commands/login";
import { migrate } from "./commands/migrate";
import { update } from "./commands/update";
import * as Migration from "./services/migration/migrate";
import * as OAuth from "./services/oauth";
import * as Polar from "./services/polar";
import { showUpdateNotice, checkForUpdateInBackground } from "./services/update-check";
import { VERSION } from "./version";
const mainCommand = Command.make("polar").pipe(
Command.withSubcommands([
login,
migrate,
listen,
update
])
);
const cli = Command.run(mainCommand, {
name: "Polar CLI",
version: VERSION,
});
const services = Layer.mergeAll(
OAuth.layer,
Polar.layer,
Migration.layer,
BunContext.layer
);
// Clean up stale files from Windows self-update
if (process.platform === "win32") {
// If .new exists, a previous update was interrupted — complete it
const pendingPath = process.execPath + ".new";
if (existsSync(pendingPath)) {
try { renameSync(pendingPath, process.execPath); } catch {}
}
try { unlinkSync(process.execPath + ".bak"); } catch {}
try { unlinkSync(pendingPath); } catch {}
}
showUpdateNotice();
checkForUpdateInBackground();
cli(process.argv).pipe(Effect.provide(services), BunRuntime.runMain);