Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
wyze committed Mar 30, 2017
0 parents commit 32e8e56
Show file tree
Hide file tree
Showing 32 changed files with 5,096 additions and 0 deletions.
14 changes: 14 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# editorconfig.org

root = true

[*]
charset = utf-8
end_of_line = lf
indent_size = 2
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true

[*.md]
trim_trailing_whitespace = false
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
* text=auto
*.js text eol=lf
15 changes: 15 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Dependencies
node_modules

# Build
dist
lib
.merlin

# Logs
*.log
npm-debug.log*
yarn-error.log

# macOS
.*DS_Store
21 changes: 21 additions & 0 deletions bsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "reasonable",
"reason": {
"react-jsx": true
},
"bs-dependencies": [
"reason-react",
"reason-js",
"reductive"
],
"sources": [
{
"dir": "src",
"subdirs": [
"components",
"reductive",
"styles"
]
}
]
}
2 changes: 2 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
## Change Log

11 changes: 11 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Calculator in Reason</title>
</head>
<body>
<div class="root"></div>
<script src="bundle.js"></script>
</body>
</html>
21 changes: 21 additions & 0 deletions license
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) Neil Kistner <[email protected]> (neilkistner.com)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
48 changes: 48 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"name": "reason-calculator",
"private": true,
"version": "0.0.0",
"repository": "wyze/reason-calculator",
"author": {
"name": "Neil Kistner",
"email": "[email protected]",
"url": "neilkistner.com"
},
"license": "MIT",
"scripts": {
"build": "npm-run-all build:*",
"build:bsb": "bsb -make-world",
"build:webpack": "webpack -p",
"changelog": "changelog-maker --filter-release -- wyze reason-calculator",
"clean": "npm-run-all clean:*",
"clean:bsb": "bsb -clean-world",
"clean:project": "rimraf dist lib .merlin",
"deploy": "surge dist reason-calculator.surge.sh",
"dev": "npm-run-all --parallel dev:*",
"dev:bsb": "npm run build:bsb -- -w",
"dev:webpack": "webpack-dev-server -w",
"np": "np --no-publish --yolo",
"prebuild": "npm run clean",
"predeploy": "npm-run-all build np",
"version": "node scripts/version.js"
},
"devDependencies": {
"bs-platform": "^1.6.0",
"changelog-maker": "^2.2.5",
"execa": "^0.6.3",
"glamor": "^2.20.24",
"np": "^2.13.1",
"npm-run-all": "^4.0.2",
"react": "^15.4.2",
"react-dom": "^15.4.2",
"read-pkg": "^2.0.0",
"reason-js": "^0.3.0",
"reason-react": "^0.1.0",
"reductive": "git+https://github.com/reasonml/reductive.git",
"rimraf": "^2.6.1",
"surge": "^0.19.0",
"webpack": "^2.3.1",
"webpack-dev-server": "^2.4.2",
"webpack-html-plugin": "^0.1.1"
}
}
48 changes: 48 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# reason-calculator

[![Website][website-image]][website-url]
[![dependencies][deps-image]][deps-url]
[![devDependencies][depsdev-image]][depsdev-url]

> A calculator built with [Reason](https://github.com/facebook/reason) and [reason-react](https://github.com/reasonml/reason-react).
## Live Demo

https://reason-calculator.surge.sh

## Setup

```sh
$ git clone https://github.com/wyze/reason-calculator.git
$ cd reason-calculator
$ yarn # or `npm install`
```

## Development

```sh
$ npm run dev
```

## Build

```sh
$ npm run build
```

## Change Log

> [Full Change Log](changelog.md)
## License

MIT © [Neil Kistner](https://neilkistner.com)

[website-image]: https://img.shields.io/website-up-down-green-red/https/reason-calculator.surge.sh.svg?style=flat-square
[website-url]: https://reason-calculator.surge.sh

[deps-image]: https://img.shields.io/david/wyze/reason-calculator.svg?style=flat-square
[deps-url]: https://david-dm.org/wyze/reason-calculator

[depsdev-image]: https://img.shields.io/david/dev/wyze/reason-calculator.svg?style=flat-square
[depsdev-url]: https://david-dm.org/wyze/reason-calculator?type=dev
67 changes: 67 additions & 0 deletions scripts/version.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
const execa = require('execa')
const readFile = require('fs').readFileSync
const readPkg = require('read-pkg')
const writeFile = require('fs').writeFileSync

// get version from pkg.json
const getVersionAndUrl =
({ repository: { url }, version }) => ({ url, version })

// npm run changelog (and grab output)
const getChanges = ({ url, version }) => {
const { stdout } = execa.sync('npm', [ 'run', 'changelog', '--silent' ])
const changes = stdout.trim().split(' \n')

return { changes, url, version }
}

// modify changelog.md
const updateChangelog = ({ changes, url, version }) => {
const file = 'changelog.md'
const changelog = readFile(file).toString().split('\n')
const date = new Date().toJSON().split('T').shift()
const tag = `v${version}`
const repo = url.replace(/\.?git(?!hub)\+?/g, '')
const header = `### [${tag}](${repo}/releases/tag/${tag}) (${date})`
const formatted = [ header, '', ...changes ]

writeFile(
file,
[
...changelog.slice(0, 2),
...formatted,
...changelog.slice(1),
].join('\n')
)

return formatted
}

// modify readme.md
const updateReadme = formatted => {
const file = 'readme.md'
const readme = readFile(file).toString().split('\n')
const start = '> [Full Change Log](changelog.md)'
const end = '## License'

writeFile(
file,
[
...readme.slice(0, readme.indexOf(start) + 2),
...formatted,
...readme.slice(readme.indexOf(end) - 1),
].join('\n')
)
}

// git add
const runGitAdd = () => {
execa.sync('git', [ 'add', '--all' ])
}

readPkg()
.then(getVersionAndUrl)
.then(getChanges)
.then(updateChangelog)
.then(updateReadme)
.then(runGitAdd)
33 changes: 33 additions & 0 deletions src/components/App.re
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
module App = {
include ReactRe.Component;
let name = "App";

type props = {
dispatch: Store.action => unit,
state: Store.state,
};

let className: string =
Styles.make
alignItems::"center"
display::"flex"
flexDirection::"column"
()
|> Styles.className;

let render { props: { dispatch, state: { operations } } } => {
let output = Operation.getInput operations;

<main className>
<Hero />
<Calculator>
<Display output />
<Buttons dispatch />
</Calculator>
</main>;
};
};

include ReactRe.CreateComponent App;

let createElement ::state ::dispatch => wrapProps { dispatch, state };
21 changes: 21 additions & 0 deletions src/components/ButtonGroup.re
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module ButtonGroup = {
include ReactRe.Component;
let name = "ButtonGroup";

type props = {
children: list ReactRe.reactElement,
};

let className: string =
Styles.make display::"flex" () |> Styles.className;

let render { props: { children } } =>
<div className>
(ReactRe.listToElement children)
</div>;
};

include ReactRe.CreateComponent ButtonGroup;

let createElement ::children =>
wrapProps { children: children } ::children;
42 changes: 42 additions & 0 deletions src/components/Buttons.re
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
module Buttons = {
include ReactRe.Component;
let name = "Buttons";

type props = {
dispatch: Store.action => unit,
};

let render { props: { dispatch } } =>
<div>
<ButtonGroup>
<ClearButton dispatch />
<OperationButton dispatch action=Divide />
</ButtonGroup>
<ButtonGroup>
<ValueButton dispatch value="7" />
<ValueButton dispatch value="8" />
<ValueButton dispatch value="9" />
<OperationButton dispatch action=Multiply />
</ButtonGroup>
<ButtonGroup>
<ValueButton dispatch value="4" />
<ValueButton dispatch value="5" />
<ValueButton dispatch value="6" />
<OperationButton dispatch action=Subtract />
</ButtonGroup>
<ButtonGroup>
<ValueButton dispatch value="1" />
<ValueButton dispatch value="2" />
<ValueButton dispatch value="3" />
<OperationButton dispatch action=Add />
</ButtonGroup>
<ButtonGroup>
<ValueButton dispatch expand=true value="0" />
<OperationButton dispatch action=Equals />
</ButtonGroup>
</div>;
};

include ReactRe.CreateComponent Buttons;

let createElement ::dispatch => wrapProps { dispatch: dispatch };
26 changes: 26 additions & 0 deletions src/components/Calculator.re
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
module Calculator = {
include ReactRe.Component;
let name = "Calculator";

type props = {
children: list ReactRe.reactElement,
};

let className: string =
Styles.make
background::"#838383"
borderRadius::"5px"
overflow::"hidden"
width::"14em"
()
|> Styles.className;

let render { props: { children } } =>
<div className>
(ReactRe.listToElement children)
</div>;
};

include ReactRe.CreateComponent Calculator;

let createElement ::children => wrapProps { children: children } ::children;
Loading

0 comments on commit 32e8e56

Please sign in to comment.