Skip to content

Commit df9cf53

Browse files
authored
Merge pull request #1 from mahezsh/multiple-templates
Multiple templates
2 parents 1c8535a + 001633f commit df9cf53

File tree

4 files changed

+97
-12
lines changed

4 files changed

+97
-12
lines changed

Readme.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,38 @@
22

33
Create ReScript apps with no build configuration.
44

5+
## Quick Start
6+
7+
```sh
8+
npx create-rescript-app my-app
9+
cd my-app
10+
npm start
11+
```
12+
13+
## Install options
14+
15+
| Template | short cmd | long cmd |
16+
| :------------------------------- | :-------: | ----------: |
17+
| Basic | -b | --basic |
18+
| Default / CRA equivalent (React) | -d | --default |
19+
| NextJS | -nx | --nextjs |
20+
| GraphQL | -gql | --graphql |
21+
| Storybook | -sb | --storybook |
22+
23+
### Bootstrap a ReScript app with Graphql
24+
25+
```sh
26+
npx create-rescript-app my-app -gql
27+
```
28+
29+
### Bootstrap a ReScript app with Storybook
30+
31+
```sh
32+
npx create-rescript-app my-app -sb
33+
```
34+
35+
### Bootstrap a NextJS app with ReScript
36+
37+
```sh
38+
npx create-rescript-app my-app -nx
39+
```

index.js

Lines changed: 54 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,16 @@ const { execSync } = require("child_process");
55
let colors = require("colors");
66

77
let projectName = process.argv[2];
8+
let projectType = process.argv[3];
9+
810
const currentPath = process.cwd();
911
const 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

1319
try {
1420
fs.mkdirSync(projectPath);
@@ -27,22 +33,58 @@ try {
2733

2834
async 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+
4890
main();

package-lock.json

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@
2525
"url": "https://github.com/mahezsh/create-rescript-app/issues"
2626
},
2727
"homepage": "https://github.com/mahezsh/create-rescript-app#readme",
28+
"keywords": [
29+
"rescript",
30+
"bootstrap rescript",
31+
"rescript app",
32+
"rescript start"
33+
],
2834
"bin": {
2935
"create-rescript-app": "index.js"
3036
}

0 commit comments

Comments
 (0)