-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Rickard Natt och Dag
committed
Nov 16, 2020
1 parent
c2ad3a6
commit d92a612
Showing
17 changed files
with
336 additions
and
8 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
pub mod add; | ||
pub mod github_actions; | ||
pub mod rescript; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
use crate::utils::helpers; | ||
use colored::*; | ||
use copy_dir::copy_dir; | ||
use handlebars::Handlebars; | ||
use helpers::Result; | ||
use serde_json::json; | ||
use std::{env, fs}; | ||
|
||
fn update_file(dir: &str, filename: &str) -> Result<()> { | ||
let reg = Handlebars::new(); | ||
let file = &fs::read(format!("{}/{}", dir, filename))?; | ||
let file: String = String::from_utf8_lossy(file).parse()?; | ||
let output = reg.render_template(&file, &json!({ "name": dir }))?; | ||
|
||
fs::write(&format!("{}/{}", dir, filename), output)?; | ||
|
||
Ok(()) | ||
} | ||
|
||
pub fn run(name: String) -> Result<()> { | ||
let rescript_template = concat!(env!("CARGO_MANIFEST_DIR"), "/src/templates/rescript"); | ||
copy_dir(rescript_template, &name)?; | ||
|
||
// Update files with template names | ||
update_file(&name, "package.json")?; | ||
update_file(&name, "bsconfig.json")?; | ||
update_file(&name, "README.md")?; | ||
update_file(&name, "public/index.html")?; | ||
|
||
println!( | ||
" | ||
{title} | ||
-------------------- | ||
Install dependencies | ||
* cd {name} | ||
* {install} | ||
Start the app by opening two terminal tabs and | ||
running the following commands: | ||
* {compiler} (start compiler) | ||
* {server} (start development server on port 3000) | ||
", | ||
title = "ReScript setup completed".green(), | ||
name = &name.green(), | ||
compiler = "npm start".blue(), | ||
server = "npm run server".blue(), | ||
install = "npm install".blue(), | ||
); | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# {{ name }} | ||
|
||
## Run Project | ||
|
||
```sh | ||
npm install | ||
npm start | ||
# in another tab | ||
npm run server | ||
``` | ||
|
||
When both processes are running, open a browser at http://localhost:3000 | ||
|
||
## Build for Production | ||
|
||
```sh | ||
npm run clean | ||
npm run build | ||
npm run webpack:production | ||
``` | ||
|
||
This will replace the development artifact `build/Index.js` for an optimized | ||
version as well as copy `public/index.html` into `build/`. You can then deploy the | ||
contents of the `build` directory (`index.html` and `Index.js`). | ||
|
||
If you make use of routing (via `ReasonReact.Router` or similar logic) ensure | ||
that server-side routing handles your routes or that 404's are directed back to | ||
`index.html` (which is how the dev server is set up). | ||
|
||
**To enable dead code elimination**, change `bsconfig.json`'s `package-specs` | ||
`module` from `"commonjs"` to `"es6"`. Then re-run the above 2 commands. This | ||
will allow Webpack to remove unused code. | ||
' | ||
|
||
## Build to Now | ||
|
||
This project includes building straight to [Now](https://zeit.co/) after Travis has validated | ||
tests and created a release. There are some steps that need to be taken to enable the setup. | ||
|
||
1. Get a token from your [Now dashboard](https://zeit.co/account/tokens) | ||
1. Set the token as `NOW_TOKEN` in Travis | ||
1. Uncomment the Now build steps in `.travis.yml` | ||
1. Add `now-build` to `package.json` scripts. Now runs this script during it build process: | ||
|
||
``` | ||
"now-build": "npm run build && npm run webpack:production" | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"name": "{{ name }}", | ||
"reason": { | ||
"react-jsx": 3 | ||
}, | ||
"sources": [ | ||
{ | ||
"dir": "src", | ||
"subdirs": true | ||
} | ||
], | ||
"package-specs": [ | ||
{ | ||
"module": "commonjs", | ||
"in-source": true | ||
} | ||
], | ||
"suffix": ".bs.js", | ||
"namespace": true, | ||
"bs-dependencies": ["reason-react"], | ||
"refmt": 3, | ||
"warnings": { | ||
"number": "+A-9-40-42-48", | ||
"error": "+A-3-40-42-44-102" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
{ | ||
"name": "{{ name }}", | ||
"version": "0.1.0", | ||
"scripts": { | ||
"build": "bsb -make-world", | ||
"start": "cross-env BS_WATCH_CLEAR=true bsb -make-world -w", | ||
"clean": "bsb -clean-world", | ||
"test": "is-ci test:ci test:watch", | ||
"test:ci": "jest", | ||
"test:watch": "jest --watch", | ||
"webpack": "webpack -w", | ||
"webpack:production": "NODE_ENV=production webpack", | ||
"server": "webpack serve" | ||
}, | ||
"keywords": [ | ||
"ReScript" | ||
], | ||
"author": "", | ||
"license": "MIT", | ||
"dependencies": { | ||
"react": "17.0.1", | ||
"react-dom": "17.0.1", | ||
"reason-react": "0.9.1" | ||
}, | ||
"devDependencies": { | ||
"autoprefixer": "10.0.2", | ||
"bs-platform": "8.3.3", | ||
"cross-env": "7.0.2", | ||
"css-loader": "5.0.1", | ||
"html-webpack-plugin": "4.5.0", | ||
"is-ci-cli": "2.1.2", | ||
"postcss-loader": "4.0.4", | ||
"style-loader": "2.0.0", | ||
"tailwindcss": "1.9.6", | ||
"webpack": "5.4.0", | ||
"webpack-cli": "4.2.0", | ||
"webpack-dev-server": "3.11.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
plugins: [require("tailwindcss"), require("autoprefixer")], | ||
}; |
Oops, something went wrong.