@@ -5,10 +5,16 @@ const { execSync } = require("child_process");
55let colors = require ( "colors" ) ;
66
77let projectName = process . argv [ 2 ] ;
8+ let projectType = process . argv [ 3 ] ;
9+
810const currentPath = process . cwd ( ) ;
911const projectPath = path . join ( currentPath , projectName ) ;
10- const git_repo =
12+ const basicRepo =
1113 "https://github.com/rescript-lang/rescript-project-template.git" ;
14+ const defaultRepo = "https://github.com/mahezsh/rescript-template-default.git" ;
15+ const nextJsRepo = "https://github.com/ryyppy/rescript-nextjs-template.git" ;
16+ const graphqlRepo = "https://github.com/mahezsh/rescript-template-graphql.git" ;
17+ const sbRepo = "https://github.com/mahezsh/rescript-template-storybook.git" ;
1218
1319try {
1420 fs . mkdirSync ( projectPath ) ;
@@ -27,22 +33,58 @@ try {
2733
2834async function main ( ) {
2935 try {
30- console . log ( `Creating a new Rescript app in` , `${ projectPath } \n` . green ) ;
31- execSync ( `git clone --depth 1 ${ git_repo } ${ projectPath } ` ) ;
32- process . chdir ( projectPath ) ;
33- console . log ( "\nInstalling packages. This might take a couple of seconds." ) ;
34- execSync ( "npm install" ) ;
35- execSync ( `find . | grep "\.git/" | xargs rm -rf` ) ;
36- execSync ( "git init" ) ;
37- console . log ( `\nInitialized a git repository.` ) ;
36+ let repoUrl = basicRepo ;
37+ let templateName = "default" ;
38+
39+ switch ( projectType ) {
40+ case "-b" || "--basic" :
41+ repoUrl = basicRepo ;
42+ templateName = "basic" ;
43+ break ;
44+ case "-d" || "--default" || undefined :
45+ repoUrl = defaultRepo ;
46+ templateName = "default" ;
47+ break ;
48+ case "-nx" || "--nextjs" :
49+ repoUrl = nextJsRepo ;
50+ templateName = "nextJS" ;
51+ break ;
52+ case "-gql" || "--graphql" :
53+ repoUrl = graphqlRepo ;
54+ templateName = "graphQL" ;
55+ break ;
56+ case "-sb" || "--storybook" :
57+ repoUrl = sbRepo ;
58+ templateName = "storybook" ;
59+ break ;
60+ }
3861 console . log (
39- `\nSuccess!` . green ,
40- `Created ${ projectName } at ` ,
41- `${ projectPath } ` . green
62+ `\nCreating a new Rescript app in` ,
63+ `${ projectPath } ` . green ,
64+ `from` ,
65+ `${ templateName } ` . blue ,
66+ `template\n`
4267 ) ;
68+ execSync ( `git clone --depth 1 ${ basicRepo } ${ projectPath } ` ) ;
69+ process . chdir ( projectPath ) ;
70+ houseKeeping ( ) ;
4371 console . log ( `\nHappy hacking!\n` ) ;
4472 } catch ( error ) {
4573 console . log ( error ) ;
4674 }
4775}
76+
77+ async function houseKeeping ( ) {
78+ console . log ( "\nInstalling packages. This might take a couple of seconds." ) ;
79+ execSync ( "npm install" ) ;
80+ execSync ( `find . | grep "\.git/" | xargs rm -rf` ) ;
81+ execSync ( "git init" ) ;
82+ console . log ( `\nInitialized a git repository.` ) ;
83+ console . log (
84+ `\nSuccess!` . green ,
85+ `Created ${ projectName } at` ,
86+ `${ projectPath } ` . green
87+ ) ;
88+ }
89+
4890main ( ) ;
0 commit comments