@@ -13,24 +13,50 @@ let updatePackageJson = async () =>
1313 config -> Dict .set ("scripts" , Object (scripts ))
1414 scripts
1515 }
16+ scripts -> Dict .set ("res:build" , String ("rescript" ))
17+ scripts -> Dict .set ("res:clean" , String ("rescript clean" ))
1618 scripts -> Dict .set ("res:dev" , String ("rescript build -w" ))
1719 | _ => ()
1820 }
1921 )
2022
21- let updateRescriptJson = async (~projectName , ~sourceDir ) =>
23+ let updateRescriptJson = async (~projectName , ~sourceDir , ~ moduleSystem , ~ suffix ) =>
2224 await JsonUtils .updateJsonFile ("rescript.json" , json =>
2325 switch json {
2426 | Object (config ) =>
2527 config -> Dict .set ("name" , String (projectName ))
28+ config -> Dict .set ("suffix" , String (suffix ))
2629 switch config -> Dict .get ("sources" ) {
2730 | Some (Object (sources )) => sources -> Dict .set ("dir" , String (sourceDir ))
2831 | _ => ()
2932 }
33+ switch config -> Dict .get ("package-specs" ) {
34+ | Some (Object (sources )) => sources -> Dict .set ("module" , String (moduleSystem ))
35+ | _ => ()
36+ }
3037 | _ => ()
3138 }
3239 )
3340
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+ 3460let addToExistingProject = async (~projectName ) => {
3561 let versions = await RescriptVersions .promptVersions ()
3662
@@ -41,6 +67,17 @@ let addToExistingProject = async (~projectName) => {
4167 initialValue : "src" ,
4268 })-> P .resultOrRaise
4369
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+ 4481 let templatePath = CraPaths .getTemplatePath (~templateName = Templates .basicTemplateName )
4582 let projectPath = Process .cwd ()
4683 let gitignorePath = Path .join2 (projectPath , ".gitignore" )
@@ -62,8 +99,12 @@ let addToExistingProject = async (~projectName) => {
6299 await Fs .Promises .copyFile (Path .join2 (templatePath , "_gitignore" ), gitignorePath )
63100 }
64101
102+ if ! shouldCheckJsFilesIntoGit {
103+ await Fs .Promises .appendFile (gitignorePath , ` **/*${suffix}${Os.eol}` )
104+ }
105+ 65106 await updatePackageJson ()
66- await updateRescriptJson (~projectName , ~sourceDir )
107+ await updateRescriptJson (~projectName , ~sourceDir , ~ moduleSystem , ~ suffix )
67108
68109 if ! Fs .existsSync (sourceDirPath ) {
69110 await Fs .Promises .mkdir (sourceDirPath )
0 commit comments