Skip to content

Commit dc36d13

Browse files
Sascha TimmeSascha Timme
authored andcommitted
Adapt for Reason
1 parent 6eabcfa commit dc36d13

File tree

11 files changed

+101
-47
lines changed

11 files changed

+101
-47
lines changed

config/paths.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ module.exports = {
7878
appBuild: resolveApp('build'),
7979
appPublic: resolveApp('public'),
8080
appHtml: resolveApp('public/index.html'),
81-
appIndexJs: resolveApp('src/index.js'),
81+
appIndexJs: resolveApp('lib/js/src/index.js'),
8282
appPackageJson: resolveApp('package.json'),
8383
appSrc: resolveApp('src'),
8484
yarnLockFile: resolveApp('yarn.lock'),
@@ -100,7 +100,7 @@ module.exports = {
100100
appBuild: resolveApp('build'),
101101
appPublic: resolveApp('public'),
102102
appHtml: resolveApp('public/index.html'),
103-
appIndexJs: resolveApp('src/index.js'),
103+
appIndexJs: resolveApp('lib/js/src/index.js'),
104104
appPackageJson: resolveApp('package.json'),
105105
appSrc: resolveApp('src'),
106106
yarnLockFile: resolveApp('yarn.lock'),

config/webpack.config.dev.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,9 @@ module.exports = {
133133
/\.(js|jsx)(\?.*)?$/,
134134
/\.css$/,
135135
/\.json$/,
136-
/\.svg$/
136+
/\.svg$/,
137+
/\.(re|ml)$/,
138+
/\.(rei|mli)$/
137139
],
138140
loader: 'url',
139141
query: {
@@ -179,6 +181,10 @@ module.exports = {
179181
query: {
180182
name: 'static/media/[name].[hash:8].[ext]'
181183
}
184+
},
185+
{
186+
test: /\.(re|ml)$/,
187+
loader: "bs"
182188
}
183189
// ** STOP ** Are you adding a new loader?
184190
// Remember to add the new extension(s) to the "url" loader exclusion list.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "react-scripts",
2+
"name": "reason-react-scripts",
33
"version": "0.9.4",
44
"description": "Configuration and scripts for Create React App.",
55
"repository": "facebookincubator/create-react-app",
@@ -33,6 +33,7 @@
3333
"case-sensitive-paths-webpack-plugin": "1.1.4",
3434
"chalk": "1.1.3",
3535
"connect-history-api-fallback": "1.3.0",
36+
"concurrently": "^3.4.0",
3637
"cross-spawn": "4.0.2",
3738
"css-loader": "0.26.1",
3839
"detect-port": "1.1.0",

scripts/init.js

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,11 @@ module.exports = function(appPath, appName, verbose, originalDirectory, template
2626

2727
// Setup the script rules
2828
appPackage.scripts = {
29-
'start': 'react-scripts start',
30-
'build': 'react-scripts build',
31-
'test': 'react-scripts test --env=jsdom',
32-
'eject': 'react-scripts eject'
29+
"bsb:build": "bsb -clean-world -make-world",
30+
"bsb:watch": "bsb -clean-world -make-world -w",
31+
"start": "bsb -clean-world -make-world && concurrently \"react-scripts start\" \"bsb -w\"",
32+
"build": "bsb -clean-world -make-world && react-scripts build",
33+
"test": "bsb -clean-world -make-world && concurrently \"react-scripts test --env=jsdom\" \"bsb -w\"",
3334
};
3435

3536
fs.writeFileSync(
@@ -46,6 +47,14 @@ module.exports = function(appPath, appName, verbose, originalDirectory, template
4647
var templatePath = template ? path.resolve(originalDirectory, template) : path.join(ownPath, 'template');
4748
if (fs.existsSync(templatePath)) {
4849
fs.copySync(templatePath, appPath);
50+
// update bsconfig name
51+
var bsconfig = require(path.join(appPath, 'bsconfig.json'));
52+
bsconfig.name = appName;
53+
54+
fs.writeFileSync(
55+
path.join(appPath, 'bsconfig.json'),
56+
JSON.stringify(bsconfig, null, 2)
57+
);
4958
} else {
5059
console.error('Could not locate supplied template: ' + chalk.green(templatePath));
5160
return;
@@ -97,7 +106,6 @@ module.exports = function(appPath, appName, verbose, originalDirectory, template
97106
// or template is presetend (via --internal-testing-template)
98107
if (!isReactInstalled(appPackage) || template) {
99108
console.log('Installing react and react-dom using ' + command + '...');
100-
console.log();
101109

102110
var proc = spawn.sync(command, args, {stdio: 'inherit'});
103111
if (proc.status !== 0) {
@@ -106,6 +114,31 @@ module.exports = function(appPath, appName, verbose, originalDirectory, template
106114
}
107115
}
108116

117+
// Install Reason stuff
118+
var command;
119+
var args;
120+
121+
// dependencies
122+
if (useYarn) {
123+
command = 'yarnpkg';
124+
args = ['add'];
125+
} else {
126+
command = 'npm';
127+
args = [
128+
'install',
129+
'--save',
130+
verbose && '--verbose'
131+
].filter(function(e) { return e; });
132+
}
133+
args.push('concurrently', 'bs-platform', 'reason-react', 'reason-js', "https://github.com/BuckleTypes/bs-jest.git");
134+
console.log('Installing reason-react and reason-js and bs-jest using ' + command + '...');
135+
136+
var proc = spawn.sync(command, args, {stdio: 'inherit'});
137+
if (proc.status !== 0) {
138+
console.error('`' + command + ' ' + args.join(' ') + '` failed');
139+
return;
140+
}
141+
109142
// Display the most elegant way to cd.
110143
// This needs to handle an undefined originalDirectory for
111144
// backward compatibility with old global-cli's.

template/__tests__/App.re

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
open Jest;
2+
open Expect;
3+
4+
test "renders without crashing" (fun () => {
5+
let div = ReasonJs.Dom.Document.createElement "div" ReasonJs.Dom.document;
6+
let render () => (ReactDOMRe.render <App /> div);
7+
expect render |> not_ |> toThrow;
8+
});

template/bsconfig.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"name" : "reason-react-example",
3+
"reason" : { "react-jsx" : true},
4+
"bs-dependencies": ["reason-react", "reason-js", "bs-jest"],
5+
"sources": [
6+
{
7+
"dir": "src"
8+
}
9+
]
10+
}

template/src/App.js

Lines changed: 0 additions & 21 deletions
This file was deleted.

template/src/App.re

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
let logo : string = [%bs.raw {|require("../../../src/logo.svg")|}];
2+
let css : string = [%bs.raw {|require("../../../src/App.css")|}];
3+
4+
5+
module App = {
6+
include ReactRe.Component;
7+
type props = unit;
8+
let name = "App";
9+
10+
let render { props } => {
11+
<div className="App">
12+
<div className="App-header">
13+
<img src={logo} className="App-logo" alt="logo" />
14+
<h2>(ReactRe.stringToElement "Welcome to Reason-React")</h2>
15+
</div>
16+
<p className="App-intro">
17+
(ReactRe.stringToElement "To get started, edit ")
18+
<code>(ReactRe.stringToElement "src/App.re")</code>
19+
(ReactRe.stringToElement " and save to reload.")
20+
</p>
21+
</div>
22+
}
23+
};
24+
25+
include ReactRe.CreateComponent App;
26+
27+
let createElement = wrapProps ();

template/src/App.test.js

Lines changed: 0 additions & 8 deletions
This file was deleted.

template/src/index.js

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)