Skip to content

Commit 50d7436

Browse files
authored
Merge pull request #85 from commitdev/implement-poc-ui
Issue #59: Implement poc ui
2 parents c04455b + 05d34b6 commit 50d7436

31 files changed

+11579
-9
lines changed

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,8 @@ main-packr.go
22
packrd
33
/commit0
44
.history/
5-
tmp/
5+
tmp/
6+
7+
# Generated files from Config UI.
8+
intenral/ui/node_modules
9+
intenral/ui/build

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,14 @@ build-example-docker: clean-example
5252
clean-example:
5353
rm -rf example
5454

55+
watch-ui:
56+
cd internal/ui && yarn start
57+
5558
# builds
5659
build:
5760
CGO_ENABLED=0 packr2 build -o commit0
5861
packr2 clean
62+
cd internal/ui && yarn && yarn build
5963

6064
# Installs the CLI int your GOPATH
6165
install-go:

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,25 @@ cd test-app
8080
../../commit0 generate -c commit0.yml
8181
```
8282

83+
### Configuration UI
84+
85+
If you're working on the configuration UI locally, you can run just the ui by doing the following.
86+
87+
``` bash
88+
cd internal/ui
89+
yarn
90+
yarn start
91+
```
92+
93+
If you want to test the full integration with the go app, you'll need to do a build and run the app with `./commit0 ui`.
94+
95+
``` bash
96+
make build
97+
./commit0 ui
98+
```
99+
100+
[http://localhost:8080/](http://localhost:8080/)
101+
83102
### Architecture
84103
The project is built with GoLang and requires Docker
85104
- /cmd - the CLI command entry points

internal/api/create_project.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ func createProject(projectConfig util.ProjectConfiguration) string {
1818
t := templator.NewTemplator(templates)
1919
outDir := "./"
2020
rootDir := path.Join(outDir, projectConfig.ProjectName)
21-
log.Printf("Creating project %s.", projectConfig.ProjectName)
21+
log.Printf("Creating project %s.", projectConfig)
2222
err := os.MkdirAll(rootDir, os.ModePerm)
2323

2424
if os.IsExist(err) {

internal/api/generate_api.go

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ package api
22

33
import (
44
"encoding/json"
5-
"github.com/gorilla/mux"
65
"log"
76
"net/http"
87

8+
"github.com/gorilla/handlers"
9+
"github.com/gorilla/mux"
10+
911
"github.com/commitdev/commit0/internal/util"
1012
)
1113

@@ -19,7 +21,7 @@ func generateProject(w http.ResponseWriter, req *http.Request) {
1921
if err != nil {
2022
panic(err)
2123
}
22-
log.Println(projectConfig.ProjectName)
24+
log.Println(projectConfig)
2325
createProject(projectConfig)
2426
w.WriteHeader(http.StatusCreated)
2527
w.Write([]byte(`{"message": "Post successful"}`))
@@ -28,13 +30,23 @@ func generateProject(w http.ResponseWriter, req *http.Request) {
2830
w.WriteHeader(http.StatusNotFound)
2931
w.Write([]byte(`{"message": "Not found"}`))
3032
}
31-
3233
}
3334

3435
func Commit0Api() {
36+
// React Frontend is served on port 3000 while in development mode.
37+
allowOrigins := handlers.AllowedOrigins([]string{"http://localhost:3000"})
38+
allowedMethods := handlers.AllowedMethods([]string{"POST", "OPTIONS"})
39+
allowedHeaders := handlers.AllowedHeaders([]string{"content-type"})
40+
3541
var router = mux.NewRouter()
3642
var api = router.PathPrefix("/v1/generate").Subrouter()
3743
api.NotFoundHandler = http.HandlerFunc(generateProject)
3844

39-
log.Fatal(http.ListenAndServe(":8080", router))
45+
staticHandler := http.StripPrefix("/static/", http.FileServer(http.Dir("internal/ui/build/static")))
46+
router.PathPrefix("/static/").Handler(staticHandler)
47+
48+
buildHandler := http.FileServer(http.Dir("internal/ui/build"))
49+
router.PathPrefix("/").Handler(buildHandler)
50+
51+
log.Fatal(http.ListenAndServe(":8080", handlers.CORS(allowOrigins, allowedMethods, allowedHeaders)(router)))
4052
}

internal/ui/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
build

internal/ui/README.md

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
2+
3+
## Available Scripts
4+
5+
In the project directory, you can run:
6+
7+
### `yarn start`
8+
9+
Runs the app in the development mode.<br />
10+
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
11+
12+
The page will reload if you make edits.<br />
13+
You will also see any lint errors in the console.
14+
15+
### `yarn test`
16+
17+
Launches the test runner in the interactive watch mode.<br />
18+
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
19+
20+
### `yarn build`
21+
22+
Builds the app for production to the `build` folder.<br />
23+
It correctly bundles React in production mode and optimizes the build for the best performance.
24+
25+
The build is minified and the filenames include the hashes.<br />
26+
Your app is ready to be deployed!
27+
28+
See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
29+
30+
### `yarn eject`
31+
32+
**Note: this is a one-way operation. Once you `eject`, you can’t go back!**
33+
34+
If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
35+
36+
Instead, it will copy all the configuration files and the transitive dependencies (Webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.
37+
38+
You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.
39+
40+
## Learn More
41+
42+
You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
43+
44+
To learn React, check out the [React documentation](https://reactjs.org/).
45+
46+
### Code Splitting
47+
48+
This section has moved here: https://facebook.github.io/create-react-app/docs/code-splitting
49+
50+
### Analyzing the Bundle Size
51+
52+
This section has moved here: https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size
53+
54+
### Making a Progressive Web App
55+
56+
This section has moved here: https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app
57+
58+
### Advanced Configuration
59+
60+
This section has moved here: https://facebook.github.io/create-react-app/docs/advanced-configuration
61+
62+
### Deployment
63+
64+
This section has moved here: https://facebook.github.io/create-react-app/docs/deployment
65+
66+
### `yarn build` fails to minify
67+
68+
This section has moved here: https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify

internal/ui/package.json

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"name": "commit0-ui",
3+
"version": "0.1.0",
4+
"private": true,
5+
"dependencies": {
6+
"@material-ui/core": "^4.6.1",
7+
"@material-ui/icons": "^4.5.1",
8+
"@material-ui/lab": "^4.0.0-alpha.32",
9+
"axios": "^0.19.0",
10+
"react": "^16.11.0",
11+
"react-dom": "^16.11.0",
12+
"react-scripts": "3.2.0"
13+
},
14+
"scripts": {
15+
"start": "react-scripts start",
16+
"build": "react-scripts build",
17+
"test": "react-scripts test",
18+
"eject": "react-scripts eject"
19+
},
20+
"eslintConfig": {
21+
"extends": "react-app"
22+
},
23+
"browserslist": {
24+
"production": [
25+
">0.2%",
26+
"not dead",
27+
"not op_mini all"
28+
],
29+
"development": [
30+
"last 1 chrome version",
31+
"last 1 firefox version",
32+
"last 1 safari version"
33+
]
34+
}
35+
}

internal/ui/public/favicon.ico

31.3 KB
Binary file not shown.

internal/ui/public/index.html

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8" />
5+
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1" />
7+
<meta name="theme-color" content="#000000" />
8+
<meta
9+
name="description"
10+
content="Commit0 Project Generator"
11+
/>
12+
<link rel="apple-touch-icon" href="logo192.png" />
13+
<!--
14+
manifest.json provides metadata used when your web app is installed on a
15+
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
16+
-->
17+
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
18+
<!--
19+
Notice the use of %PUBLIC_URL% in the tags above.
20+
It will be replaced with the URL of the `public` folder during the build.
21+
Only files inside the `public` folder can be referenced from the HTML.
22+
23+
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
24+
work correctly both with client-side routing and a non-root public URL.
25+
Learn how to configure a non-root public URL by running `npm run build`.
26+
-->
27+
<title>Commit0</title>
28+
</head>
29+
<body>
30+
<noscript>You need to enable JavaScript to run this app.</noscript>
31+
<div id="root"></div>
32+
<!--
33+
This HTML file is a template.
34+
If you open it directly in the browser, you will see an empty page.
35+
36+
You can add webfonts, meta tags, or analytics to this file.
37+
The build step will place the bundled scripts into the <body> tag.
38+
39+
To begin the development, run `npm start` or `yarn start`.
40+
To create a production bundle, use `npm run build` or `yarn build`.
41+
-->
42+
</body>
43+
</html>

0 commit comments

Comments
 (0)