Skip to content

Commit 1d59981

Browse files
committed
feat(recipes): add basic recipes
1 parent fe48fdf commit 1d59981

File tree

47 files changed

+777
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+777
-0
lines changed

recipes/basic/config.js

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
const getConfig = () => {
2+
return {
3+
bundler: "webpack",
4+
ui: "material-ui",
5+
state: "redux",
6+
buildDir: "public",
7+
sourceDir: {
8+
main: "src",
9+
static: "static",
10+
assets: "assets",
11+
images: "images",
12+
containers: "modules",
13+
i18n: "i18n",
14+
components: "components",
15+
businessLogic: "blocks",
16+
userInterface: "widgets",
17+
utility: "utils",
18+
hooks: "hooks",
19+
theme: "theme",
20+
store: "store",
21+
services: "services",
22+
locales: "translations",
23+
},
24+
modules: {
25+
signIn: "SignIn",
26+
dashboard: "Dashboard",
27+
},
28+
canAdd: {
29+
eslint: true,
30+
prettier: true,
31+
husky: true,
32+
hookForm: true,
33+
routes: true,
34+
utils: true,
35+
static: true,
36+
i18n: true,
37+
modules: true,
38+
componentsCopy: false,
39+
fullComponents: true,
40+
},
41+
};
42+
};
43+
44+
const getModulesList = () => {
45+
return [
46+
"reactWithI18n",
47+
"router",
48+
"utils"
49+
];
50+
};
51+
52+
const getDevModulesList = () => {
53+
return [
54+
"webpack",
55+
"webpackPlugins",
56+
"webpackLoaders",
57+
"babel"
58+
];
59+
};
60+
61+
module.exports = {
62+
getConfig,
63+
getModulesList,
64+
getDevModulesList,
65+
};

recipes/basic/snippets/.babelrc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"presets": [
3+
[
4+
"@babel/preset-env",
5+
{
6+
"targets": {
7+
"node": "current"
8+
}
9+
}
10+
],
11+
"@babel/preset-react"
12+
]
13+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": ["airbnb-base", "prettier"]
3+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"arrowParens": "always",
3+
"bracketSpacing": true,
4+
"embeddedLanguageFormatting": "auto",
5+
"htmlWhitespaceSensitivity": "css",
6+
"insertPragma": false,
7+
"jsxBracketSameLine": false,
8+
"jsxSingleQuote": false,
9+
"printWidth": 80,
10+
"proseWrap": "preserve",
11+
"quoteProps": "as-needed",
12+
"requirePragma": false,
13+
"semi": false,
14+
"singleQuote": true,
15+
"tabWidth": 2,
16+
"trailingComma": "es5",
17+
"useTabs": false,
18+
"vueIndentScriptAndStyle": false
19+
}

recipes/basic/snippets/index.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
const shell = require('shelljs')
2+
const { getWebPackConfig } = require('./webpack.config')
3+
const rootIndex = require('./sources/index')
4+
const rootApp = require('./sources/App')
5+
const rootRoutes = require('./sources/Routes')
6+
const withI18n = require('./sources/withI18n')
7+
const signInModule = require('./sources/SignIn')
8+
const dashboardModule = require('./sources/Dashboard')
9+
const pageLoaderBlock = require('./sources/PageLoader')
10+
const sidebarBlock = require('./sources/Sidebar')
11+
const topBarBlock = require('./sources/TopBar')
12+
13+
const sourceCodes = {
14+
'index.js': rootIndex,
15+
'App.js': rootApp,
16+
'Routes.js': rootRoutes,
17+
'withI18n.js': withI18n,
18+
'SignIn.js': signInModule,
19+
'Dashboard.js': dashboardModule,
20+
'PageLoader.js': pageLoaderBlock,
21+
'Sidebar.js': sidebarBlock,
22+
'TopBar.js': topBarBlock,
23+
}
24+
25+
const getFileContent = (fileName) => {
26+
return shell.cat(`${__dirname}/${fileName}`)
27+
}
28+
29+
const getDynamicSourceCode = (fileName, appName, baseConfig) => {
30+
const { getSourceCode } = sourceCodes[fileName]
31+
return getSourceCode(appName, baseConfig)
32+
}
33+
module.exports = {
34+
getFileContent,
35+
getWebPackConfig,
36+
getDynamicSourceCode,
37+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
function getSourceCode(appName, { sourceDir }) {
2+
return `import React from 'react'
3+
import { BrowserRouter as Router } from 'react-router-dom'
4+
import { createBrowserHistory } from 'history'
5+
6+
import Routes from './Routes'
7+
8+
// Block Components.
9+
import { ErrorHandler, PageLoader } from '@${appName}/${sourceDir.businessLogic}'
10+
11+
import { withTranslation } from '@${appName}/${sourceDir.i18n}'
12+
13+
const browserHistory = createBrowserHistory()
14+
15+
function App() {
16+
return (
17+
<>
18+
<ErrorHandler>
19+
<PageLoader />
20+
<Router history={browserHistory}>
21+
<Routes />
22+
</Router>
23+
</ErrorHandler>
24+
</>
25+
)
26+
}
27+
28+
export default withTranslation(App)
29+
`
30+
}
31+
32+
module.exports = {
33+
getSourceCode,
34+
};
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
function getSourceCode(appName, { sourceDir }) {
2+
return `import React, { useState } from 'react'
3+
import { useHistory } from 'react-router-dom'
4+
import PropTypes from 'prop-types'
5+
6+
import { I18nMsg } from '@${appName}/${sourceDir.i18n}'
7+
8+
// Utils.
9+
import { RoutePaths } from '@${appName}/${sourceDir.utility}'
10+
11+
const Dashboard = (props) => {
12+
let history = useHistory()
13+
return (
14+
<>
15+
<section>
16+
<div>
17+
<h1>
18+
<I18nMsg id="dashboard" /> goes here
19+
</h1>
20+
<button
21+
onClick={() => {
22+
history.push(RoutePaths.SignIn)
23+
}}
24+
>
25+
Click back
26+
</button>
27+
</div>
28+
</section>
29+
</>
30+
)
31+
}
32+
33+
Dashboard.propTypes = {
34+
title: PropTypes.string,
35+
}
36+
37+
export default Dashboard
38+
`
39+
}
40+
41+
module.exports = {
42+
getSourceCode,
43+
};
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
function getSourceCode(appName, { sourceDir }) {
2+
return `import React, { Fragment } from 'react'
3+
4+
// UI Components.
5+
import { Spinner } from '@${appName}/${sourceDir.userInterface}'
6+
7+
export default function PageLoader({ loading }) {
8+
// Add your business logic with store condition.
9+
return <Fragment>{loading && <Spinner />}</Fragment>
10+
}
11+
`
12+
}
13+
14+
module.exports = {
15+
getSourceCode,
16+
};
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
function getSourceCode(appName, { sourceDir, modules }) {
2+
return `import React, { Suspense } from 'react'
3+
import { Route, Switch, Redirect } from 'react-router-dom'
4+
5+
// Block Components.
6+
import { PageLoader } from '@${appName}/${sourceDir.businessLogic}'
7+
8+
// Utils.
9+
import { RoutePaths } from '@${appName}/${sourceDir.utility}'
10+
11+
const SignInModule = React.lazy(() =>
12+
import(/* webpackChunkName: "${sourceDir.containers}/${modules.signIn}" */ './${sourceDir.containers}/${modules.signIn}')
13+
)
14+
const DashboardModule = React.lazy(() =>
15+
import(/* webpackChunkName: "${sourceDir.containers}/${modules.dashboard}" */ './${sourceDir.containers}/${modules.dashboard}')
16+
)
17+
18+
const Routes = () => {
19+
return (
20+
<Suspense fallback={<PageLoader />}>
21+
<Switch>
22+
<Route path={RoutePaths.SignIn} exact component={SignInModule} />
23+
<Route path={RoutePaths.Dashboard} component={DashboardModule} />
24+
<Redirect to={RoutePaths.NotFound} />
25+
</Switch>
26+
</Suspense>
27+
)
28+
}
29+
30+
export default Routes
31+
`
32+
}
33+
34+
module.exports = {
35+
getSourceCode,
36+
};
37+
38+
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
function getSourceCode(appName, { sourceDir }) {
2+
return `import React from 'react'
3+
import PropTypes from 'prop-types'
4+
import { useI18n } from '@${appName}/${sourceDir.i18n}'
5+
6+
// Domain Components.
7+
import SidebarNav from './SidebarNav'
8+
9+
// Utils.
10+
import { RoutePaths } from '@${appName}/${sourceDir.utility}'
11+
12+
const Sidebar = (props) => {
13+
const { open, variant, onClose, className, ...rest } = props
14+
const { formatMessage } = useI18n()
15+
16+
const pages = [
17+
{
18+
title: formatMessage({ id: 'dashboard' }),
19+
href: RoutePaths.dashboard,
20+
icon: '',
21+
},
22+
{
23+
title: formatMessage({ id: 'other_module' }),
24+
href: RoutePaths.dashboard,
25+
icon: '',
26+
},
27+
]
28+
29+
return (
30+
<section>
31+
<div {...rest}>
32+
<SidebarNav pages={pages} />
33+
</div>
34+
</section>
35+
)
36+
}
37+
38+
Sidebar.propTypes = {
39+
className: PropTypes.string,
40+
onClose: PropTypes.func,
41+
open: PropTypes.bool.isRequired,
42+
variant: PropTypes.string.isRequired,
43+
}
44+
45+
export default Sidebar
46+
`
47+
}
48+
49+
module.exports = {
50+
getSourceCode,
51+
};

0 commit comments

Comments
 (0)