Skip to content

Commit

Permalink
added new react templates with ejs delimiter
Browse files Browse the repository at this point in the history
  • Loading branch information
zthomas committed Nov 9, 2019
1 parent a45d4ab commit 83a1374
Show file tree
Hide file tree
Showing 128 changed files with 5,727 additions and 648 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -2,3 +2,4 @@ main-packr.go
packrd
/commit0
.history/
tmp/
2 changes: 1 addition & 1 deletion go.mod
Expand Up @@ -18,4 +18,4 @@ require (
golang.org/x/sys v0.0.0-20191010194322-b09406accb47 // indirect
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
gopkg.in/yaml.v2 v2.2.5
)
)
18 changes: 0 additions & 18 deletions internal/config/react.go
Expand Up @@ -4,20 +4,6 @@ type reactApp struct {
Name string
}

type reactHeader struct {
Enabled bool
}

type reactSidenavItem struct {
Path string
Label string
Icon string
}
type reactSidenav struct {
Enabled bool
Items []reactSidenavItem
}

type reactAccount struct {
Enabled bool
Required bool
Expand All @@ -31,9 +17,5 @@ type reactView struct {
type frontend struct {
Framework string
App reactApp
Account reactAccount
Header reactHeader
Sidenav reactSidenav
Views []reactView
CI CI
}
19 changes: 18 additions & 1 deletion internal/templator/templator.go
Expand Up @@ -60,7 +60,7 @@ func NewTemplator(box *packr.Box) *Templator {
GitIgnore: NewSingleFileTemplator(box, "util/gitignore.tmpl"),
Readme: NewSingleFileTemplator(box, "util/README.tmpl"),
Docker: NewDockerFileTemplator(box),
React: NewDirectoryTemplator(box, "react"),
React: NewEJSDirectoryTemplator(box, "react"),
Kubernetes: NewDirectoryTemplator(box, "kubernetes"),
CI: NewCITemplator(box),
}
Expand Down Expand Up @@ -154,6 +154,23 @@ func NewDirectoryTemplator(box *packr.Box, dir string) *DirectoryTemplator {
}
}

// TODO standardize and consolidate the templating syntax, also allow for a config struct to change delimiters
// NewEJSDirectoryTemplator
func NewEJSDirectoryTemplator(box *packr.Box, dir string) *DirectoryTemplator {
templates := []*template.Template{}
for _, file := range getFileNames(box, dir) {
templateSource, _ := box.FindString(file)
template, err := template.New(file).Delims("<%=", "%>").Funcs(util.FuncMap).Parse(templateSource)
if err != nil {
panic(err)
}
templates = append(templates, template)
}
return &DirectoryTemplator{
Templates: templates,
}
}

func getFileNames(box *packr.Box, dir string) []string {
keys := []string{}
box.WalkPrefix(dir, func(path string, info file.File) error {
Expand Down
23 changes: 0 additions & 23 deletions templates/commit0/commit0.tmpl
Expand Up @@ -17,32 +17,9 @@ frontend:
framework: react
ci:
system: circleci
buildImage: react/react
buildTag: 1234
buildCommand: make build
testCommand: make test
app:
name: {{.}}
header:
enabled: true
account:
enabled: true
required: false
sidenav:
enabled: true
items:
- path: /
label: Home
icon: home
- path: /account
label: Account
icon: account_circle
views:
- path: /account
component: account
- path: /
component: home


services:
- name: User
Expand Down
6 changes: 6 additions & 0 deletions templates/react/.env
@@ -0,0 +1,6 @@
# https://create-react-app.dev/docs/adding-custom-environment-variables
REACT_APP_HOST=http://localhost:3000
REACT_APP_AUTH_DOMAIN=
REACT_APP_AUTH_CLIENT_ID=
REACT_APP_GRAPHQL_HOST=http://localhost:4000
REACT_APP_FILE_HOST=http://localhost:4000
52 changes: 52 additions & 0 deletions templates/react/.github/workflows/deploy.yml
@@ -0,0 +1,52 @@
name: Build and Deploy

on: push

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v1

# https://github.com/marketplace/actions/setup-node-js-for-use-with-actions
- name: Setup Node
uses: actions/setup-node@v1
with:
node-version: '12.x'

- run: npm install

- run: npm run build

- name: upload build artifacts
uses: actions/upload-artifact@v1
with:
name: build
path: build

publish:
needs: build
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v1
with:
fetch-depth: 1

- name: Download build artifacts
uses: actions/download-artifact@v1
with:
name: build

# https://github.com/opspresso/action-s3-sync
- name: Publish to AWS S3
uses: opspresso/action-s3-sync@master
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_REGION: "us-west-2"
FROM_PATH: "./build"
DEST_PATH: "s3://<%= .Config.Frontend.App.Name %>"
OPTIONS: "--acl public-read"
5 changes: 4 additions & 1 deletion templates/react/.gitignore
Expand Up @@ -4,20 +4,23 @@
/node_modules
/.pnp
.pnp.js
/package-lock.json

# testing
/coverage
test-report.xml

# production
/build

# misc
.DS_Store
.vscode
.env.local
.env.development.local
.env.test.local
.env.production.local
.idea/
.firebase/

npm-debug.log*
yarn-debug.log*
Expand Down
7 changes: 7 additions & 0 deletions templates/react/.prettierignore
@@ -0,0 +1,7 @@
node_modules
.vscode
build
.expo
.next
assets
static
5 changes: 5 additions & 0 deletions templates/react/.prettierrc.js
@@ -0,0 +1,5 @@
module.exports = {
semi: false,
singleQuote: true,
trailingComma: 'es5',
}
91 changes: 52 additions & 39 deletions templates/react/README.md
@@ -1,68 +1,81 @@
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).

## Available Scripts

In the project directory, you can run:
## Key Features

### `npm start`
- Dynamic loading of application
- Session handling
- Simple Routing using React Enroute
- Redux state management
- Simple server side rendering (React-snap) and SEO tag management (React-helmet)
- Redux Saga for side effect management
- Minimalist theme for MUI
- Simple language management, designed to be compatible and easily swappable with i18next
- Logger / analytics service
- In memory Localstorage fallback
- ScourJs as a immutability helper (optional)

Runs the app in the development mode.<br />
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.

The page will reload if you make edits.<br />
You will also see any lint errors in the console.
https://auth0.com/docs/universal-login
https://trellis.auth0.com/authorize?response_type=token&client_id=e8Sk7ToG3y7fJMpNN006iVhEU1W2yONN&redirect_uri=http://localhost:3000/auth/callback&state=STATE
&connection=CONNECTION

### `npm test`
## Code Formatting

Launches the test runner in the interactive watch mode.<br />
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
- following [AirBnB styleguide](https://github.com/airbnb/javascript)
- linting is built into react-scripts (CRA config source)[https://github.com/facebook/create-react-app/blob/master/packages/eslint-config-react-app/index.js]
- use prettier to automatically format code

### `npm run build`
## Styles

Builds the app for production to the `build` folder.<br />
It correctly bundles React in production mode and optimizes the build for the best performance.
We are using a hybrid approach to styling. The preferred system is CSS modules for its simplicity and statically compiled performance. However MUI forces us to use their style and theming system.

The build is minified and the filenames include the hashes.<br />
Your app is ready to be deployed!
- use MUI css-in-js styling for theme and theme dependent styling
- use CSS modules for components that are independent and reusable. Can support using css variable overrides to customize it.
- share variables using css variables
- using some global styles for reset css and libraries like animate.css

See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
## Documentation

### `npm run eject`
- use http://documentation.js.org/ it supports Flow syntax

**Note: this is a one-way operation. Once you `eject`, you can’t go back!**
## Formatting

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.
## Tools:

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.
We should strive to use minimalistic tools or write your own

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.
- https://bundlephobia.com/result?p=dayjs@1.7.8
- https://github.com/zalmoxisus/redux-devtools-extension

## Learn More
## Bundling / Codesplitting

You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
https://facebook.github.io/create-react-app/docs/code-splitting
https://reactjs.org/docs/code-splitting.html

To learn React, check out the [React documentation](https://reactjs.org/).

### Code Splitting
## Available Scripts

This section has moved here: https://facebook.github.io/create-react-app/docs/code-splitting
In the project directory, you can run:

### Analyzing the Bundle Size
### `npm start`

This section has moved here: https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size
Runs the app in the development mode.<br>
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.

### Making a Progressive Web App
The page will reload if you make edits.<br>
You will also see any lint errors in the console.

This section has moved here: https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app
### `npm test`

### Advanced Configuration
Launches the test runner in the interactive watch mode.<br>
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.

This section has moved here: https://facebook.github.io/create-react-app/docs/advanced-configuration
### `npm run build`

### Deployment
Builds the app for production to the `build` folder.<br>
It correctly bundles React in production mode and optimizes the build for the best performance.

This section has moved here: https://facebook.github.io/create-react-app/docs/deployment
The build is minified and the filenames include the hashes.<br>
Your app is ready to be deployed!

### `npm run build` fails to minify
See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.

This section has moved here: https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify
You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
5 changes: 0 additions & 5 deletions templates/react/jsconfig.json

This file was deleted.

0 comments on commit 83a1374

Please sign in to comment.