-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathMain.res
More file actions
71 lines (59 loc) · 2.24 KB
/
Main.res
File metadata and controls
71 lines (59 loc) · 2.24 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
open Node
module C = PicoColors
module P = ClackPrompts
let getVersion = async () => {
let json = await JsonUtils.readJsonFile(CraPaths.packageJsonPath)
json->JsonUtils.getStringValue(~fieldName="version")->Option.getOr("")
}
let handleError = async (~outro, perform) =>
try await perform() catch {
| JsExn(error) =>
P.Log.error("Error: " ++ error->ErrorUtils.getErrorMessage)
P.outro(outro)
Process.exitWithCode(1)
}
let run = async () => {
let version = await getVersion()
P.intro(C.dim(`create-rescript-app ${version}`))
P.note(
~title="Welcome to ReScript!",
~message=`${C.cyan("Fast, Simple, Fully Typed JavaScript from the Future")}
https://rescript-lang.org`,
)
let packageJsonPath = Path.join2(Process.cwd(), "package.json")
let rescriptJsonPath = Path.join2(Process.cwd(), "rescript.json")
let bsconfigJsonPath = Path.join2(Process.cwd(), "bsconfig.json")
if CI.isRunningInCI {
P.note(~title="CI Mode", ~message="Running in CI, will create a test project")
await handleError(~outro="Project creation failed.", async () => {
await NewProject.createNewProject()
P.outro("CI test completed successfully.")
})
} else if Fs.existsSync(rescriptJsonPath) || Fs.existsSync(bsconfigJsonPath) {
ExistingRescriptProject.showUpgradeHint()
P.outro("No changes were made to your project.")
} else if Fs.existsSync(packageJsonPath) {
let packageJson = await JsonUtils.readJsonFile(packageJsonPath)
let projectName =
packageJson->JsonUtils.getStringValue(~fieldName="name")->Option.getOr("unknown")
let addToExistingProject = await P.confirm({
message: `Detected a package.json file. Do you want to add ReScript to "${projectName}"?`,
})->P.resultOrRaise
if addToExistingProject {
await handleError(~outro="Adding to project failed.", async () => {
await ExistingJsProject.addToExistingProject(~projectName)
P.outro("Happy hacking!")
})
} else {
P.outro("No changes were made to your project.")
}
} else {
await handleError(~outro="Project creation failed.", async () => {
await NewProject.createNewProject()
P.outro("Happy hacking!")
})
}
}
try await run() catch {
| P.Canceled => P.cancel("Canceled.")
}