Skip to content

Commit 9dee2cc

Browse files
committed
Update templates and script for ReScript 11 + Core
1 parent 3e1269d commit 9dee2cc

File tree

10 files changed

+894
-1624
lines changed

10 files changed

+894
-1624
lines changed

index.mjs

Lines changed: 26 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ import { promisify } from "util";
99
import { glob } from "glob";
1010
import c from "picocolors";
1111

12-
const rescriptVersion = "10.1";
13-
1412
// Get __dirname in an ES6 module
1513
const __filename = fileURLToPath(import.meta.url);
1614
const __dirname = path.dirname(__filename);
@@ -31,7 +29,6 @@ const templates = [
3129
// value: "rescript-template-nextjs",
3230
// label: "Next.js",
3331
// hint: "Next.js, Tailwind CSS",
34-
// incompatibleWithCore: true,
3532
// },
3633
];
3734

@@ -71,30 +68,14 @@ async function updatePackageJson(projectName) {
7168
);
7269
}
7370

74-
async function updateBsconfigJson(projectName, withCore) {
75-
await updateFile("bsconfig.json", contents => {
71+
async function updateRescriptJson(projectName, withCore) {
72+
await updateFile("rescript.json", contents => {
7673
const config = JSON.parse(contents);
77-
7874
config["name"] = projectName;
79-
80-
if (withCore) {
81-
config["bs-dependencies"] = [...(config["bs-dependencies"] || []), "@rescript/core"];
82-
config["bsc-flags"] = [...(config["bsc-flags"] || []), "-open RescriptCore"];
83-
}
84-
8575
return JSON.stringify(config, null, 2);
8676
});
8777
}
8878

89-
async function coreify() {
90-
const resFiles = await glob("src/**/*.res");
91-
for (const resFile of resFiles) {
92-
await updateFile(resFile, contents =>
93-
contents.replace("Js.log", "Console.log").replace("string_of_int", "Int.toString")
94-
);
95-
}
96-
}
97-
9879
async function renameGitignore() {
9980
await fs.promises.rename("_gitignore", ".gitignore");
10081
}
@@ -108,8 +89,10 @@ function getVersion() {
10889
async function main() {
10990
console.clear();
11091

111-
const versionString = `for ReScript ${rescriptVersion} ${c.dim("(" + getVersion() + ")")}`;
112-
p.intro(`${c.bgCyan(c.black(` create-rescript-app `))} ${versionString}`);
92+
p.intro(`${c.bgCyan(c.black(` create-rescript-app `))} ${c.dim("(" + getVersion() + ")")}`);
93+
p.note(
94+
'Create a new ReScript 11 project with modern defaults\n("Core" standard library, JSX 4 automatic mode)'
95+
);
11396

11497
const projectName = await p.text({
11598
message: "What is the name of your new ReScript project?",
@@ -124,14 +107,17 @@ async function main() {
124107
});
125108
checkCancel(templateName);
126109

127-
const incompatibleWithCore = templates.find(t => t.value === templateName).incompatibleWithCore;
110+
const rescriptVersion = await p.text({
111+
message: "ReScript version? (keep the default if unsure)",
112+
initialValue: "11.0.0-rc.7",
113+
});
114+
checkCancel(rescriptVersion);
128115

129-
const withCore =
130-
!incompatibleWithCore &&
131-
(await p.confirm({
132-
message: "Add the new @rescript/core standard library?",
133-
}));
134-
checkCancel(withCore);
116+
const rescriptCoreVersion = await p.text({
117+
message: "ReScript Core version? (keep the default if unsure)",
118+
initialValue: "0.6.0",
119+
});
120+
checkCancel(rescriptCoreVersion);
135121

136122
const templatePath = path.join(__dirname, "templates", templateName);
137123
const projectPath = path.join(process.cwd(), projectName);
@@ -145,22 +131,23 @@ async function main() {
145131

146132
await renameGitignore();
147133
await updatePackageJson(projectName);
148-
await updateBsconfigJson(projectName, withCore);
149-
await coreify();
134+
await updateRescriptJson(projectName);
150135

151-
const packages = [`rescript@${rescriptVersion}`];
152-
if (withCore) {
153-
packages.push("@rescript/core");
154-
}
136+
const packages = [`rescript@${rescriptVersion}`, `@rescript/core@${rescriptCoreVersion}`];
155137

156138
await promisify(exec)("npm add " + packages.join(" "));
157139
await promisify(exec)("git init");
158140
s.stop("Project created.");
159141

160-
p.note(`cd ${projectName}\nnpm run res:dev`, "Next steps");
161-
p.outro(`Happy hacking! See ${c.cyan("README.md")} for more information.`);
142+
p.note(
143+
`Your project ${c.cyan(projectName)} was created successfully.\nChange to the ${c.cyan(
144+
projectName
145+
)} folder and view ${c.cyan("README.md")} for more information.`,
146+
"Next steps"
147+
);
148+
p.outro(`Happy hacking!`);
162149
} catch (error) {
163-
s.stop("Installation error.");
150+
s.stop(`Installation error: ${error}`);
164151

165152
p.outro(`Project creation failed.`);
166153

templates/rescript-template-basic/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"author": "",
1313
"license": "MIT",
1414
"dependencies": {
15-
"rescript": "^10.1.2"
15+
"@rescript/core": "^0.6.0",
16+
"rescript": "^11.0.0-rc.7"
1617
}
1718
}

templates/rescript-template-basic/bsconfig.json renamed to templates/rescript-template-basic/rescript.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"module": "commonjs",
99
"in-source": true
1010
},
11-
"suffix": ".bs.js",
12-
"bs-dependencies": []
11+
"suffix": ".res.js",
12+
"bs-dependencies": ["@rescript/core"],
13+
"bsc-flags": ["-open RescriptCore"]
1314
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Js.log("Hello, World!")
1+
Console.log("Hello, world!")

templates/rescript-template-vite/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
<body>
1212
<div id="root"></div>
13-
<script type="module" src="/src/Main.bs.mjs"></script>
13+
<script type="module" src="/src/Main.res.mjs"></script>
1414
</body>
1515

1616
</html>

0 commit comments

Comments
 (0)