@@ -13,24 +13,50 @@ let updatePackageJson = async () =>
13
13
config -> Dict .set ("scripts" , Object (scripts ))
14
14
scripts
15
15
}
16
+ scripts -> Dict .set ("res:build" , String ("rescript" ))
17
+ scripts -> Dict .set ("res:clean" , String ("rescript clean" ))
16
18
scripts -> Dict .set ("res:dev" , String ("rescript build -w" ))
17
19
| _ => ()
18
20
}
19
21
)
20
22
21
- let updateRescriptJson = async (~projectName , ~sourceDir ) =>
23
+ let updateRescriptJson = async (~projectName , ~sourceDir , ~ moduleSystem , ~ suffix ) =>
22
24
await JsonUtils .updateJsonFile ("rescript.json" , json =>
23
25
switch json {
24
26
| Object (config ) =>
25
27
config -> Dict .set ("name" , String (projectName ))
28
+ config -> Dict .set ("suffix" , String (suffix ))
26
29
switch config -> Dict .get ("sources" ) {
27
30
| Some (Object (sources )) => sources -> Dict .set ("dir" , String (sourceDir ))
28
31
| _ => ()
29
32
}
33
+ switch config -> Dict .get ("package-specs" ) {
34
+ | Some (Object (sources )) => sources -> Dict .set ("module" , String (moduleSystem ))
35
+ | _ => ()
36
+ }
30
37
| _ => ()
31
38
}
32
39
)
33
40
41
+ let getSuffixForModuleSystem = moduleSystem =>
42
+ switch moduleSystem {
43
+ | "es6" => ".res.mjs"
44
+ | _ => ".res.js"
45
+ }
46
+
47
+ let moduleSystemOptions = [
48
+ {
49
+ P .value : "commonjs" ,
50
+ label : "CommonJS" ,
51
+ hint : "Use require syntax and .res.js extension" ,
52
+ },
53
+ {
54
+ value : "es6" ,
55
+ label : "ES6" ,
56
+ hint : "Use import syntax and .res.mjs extension" ,
57
+ },
58
+ ]
59
+
34
60
let addToExistingProject = async (~projectName ) => {
35
61
let versions = await RescriptVersions .promptVersions ()
36
62
@@ -41,6 +67,17 @@ let addToExistingProject = async (~projectName) => {
41
67
initialValue : "src" ,
42
68
})-> P .resultOrRaise
43
69
70
+ let moduleSystem = await P .select ({
71
+ message : "What module system will you use?" ,
72
+ options : moduleSystemOptions ,
73
+ })-> P .resultOrRaise
74
+
75
+ let suffix = moduleSystem -> getSuffixForModuleSystem
76
+
77
+ let shouldCheckJsFilesIntoGit = await P .confirm ({
78
+ message : ` Do you want to check generated ${suffix} files into git?` ,
79
+ })-> P .resultOrRaise
80
+
44
81
let templatePath = CraPaths .getTemplatePath (~templateName = Templates .basicTemplateName )
45
82
let projectPath = Process .cwd ()
46
83
let gitignorePath = Path .join2 (projectPath , ".gitignore" )
@@ -62,8 +99,12 @@ let addToExistingProject = async (~projectName) => {
62
99
await Fs .Promises .copyFile (Path .join2 (templatePath , "_gitignore" ), gitignorePath )
63
100
}
64
101
102
+ if ! shouldCheckJsFilesIntoGit {
103
+ await Fs .Promises .appendFile (gitignorePath , ` **/*${suffix}${Os.eol}` )
104
+ }
105
+
65
106
await updatePackageJson ()
66
- await updateRescriptJson (~projectName , ~sourceDir )
107
+ await updateRescriptJson (~projectName , ~sourceDir , ~ moduleSystem , ~ suffix )
67
108
68
109
if ! Fs .existsSync (sourceDirPath ) {
69
110
await Fs .Promises .mkdir (sourceDirPath )
0 commit comments