create-catalyst-app-internal 0.0.3-canary.2 → 0.0.3-canary.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Readme.md +2 -2
- package/package.json +1 -1
- package/scripts/cli.cjs +56 -1
- package/templates/common/server/document.js +1 -1
- package/templates/common/webpackConfig.js +1 -0
- package/templates/none-js/client/index.js +1 -1
- package/templates/none-js/package.json +4 -4
- package/templates/none-ts/client/index.js +23 -0
- package/templates/none-ts/package.json +40 -0
- package/templates/none-ts/src/js/containers/App/index.js +16 -0
- package/templates/none-ts/src/js/routes/utils.js +42 -0
- package/templates/none-ts/tsconfig.json +13 -0
- package/templates/none-ts/types.d.ts +4 -0
- package/templates/redux-js/client/index.js +1 -1
- package/templates/redux-js/package.json +4 -4
- package/templates/redux-ts/client/index.js +28 -0
- package/templates/redux-ts/package.json +43 -0
- package/templates/redux-ts/src/js/containers/App/actions.js +17 -0
- package/templates/redux-ts/src/js/containers/App/index.js +16 -0
- package/templates/redux-ts/src/js/containers/App/reducer.js +19 -0
- package/templates/redux-ts/src/js/routes/utils.js +42 -0
- package/templates/redux-ts/src/js/store/index.js +28 -0
- package/templates/redux-ts/tsconfig.json +13 -0
- package/templates/redux-ts/types.d.ts +4 -0
- package/templates/rtk-js/client/index.js +1 -1
- package/templates/rtk-js/package.json +4 -4
- package/templates/rtk-ts/client/index.js +28 -0
- package/templates/rtk-ts/package.json +43 -0
- package/templates/rtk-ts/src/js/containers/App/index.js +16 -0
- package/templates/rtk-ts/src/js/containers/App/reducer.js +18 -0
- package/templates/rtk-ts/src/js/routes/utils.js +42 -0
- package/templates/rtk-ts/src/js/store/index.js +28 -0
- package/templates/rtk-ts/tsconfig.json +13 -0
- package/templates/rtk-ts/types.d.ts +4 -0
- package/templates/tailwind/postcss.config.js +5 -0
- package/templates/tailwind/src/static/css/base/index.scss +2 -0
package/Readme.md
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
# Creating a Catalyst App
|
|
2
2
|
|
|
3
|
-
Scaffold your Catalyst app swiftly with `create-catalyst-app`. This tool expedites the process by initializing your project with predefined configurations. To kickstart your project, execute the following command:
|
|
3
|
+
Scaffold your Catalyst app swiftly with `create-catalyst-app-internal`. This tool expedites the process by initializing your project with predefined configurations. To kickstart your project, execute the following command:
|
|
4
4
|
|
|
5
5
|
```bash
|
|
6
|
-
npx create-catalyst-app@latest
|
|
6
|
+
npx create-catalyst-app-internal@latest
|
|
7
7
|
```
|
|
8
8
|
|
|
9
9
|
Upon execution, you'll be prompted to name your project. Once named, a template will be cloned into the specified directory.
|
package/package.json
CHANGED
package/scripts/cli.cjs
CHANGED
|
@@ -33,6 +33,8 @@ const program = new Commander.Command()
|
|
|
33
33
|
return
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
+
console.log(cyan(`Using create-catalyst-app-internal version ${bold(packageJson.version)}`))
|
|
37
|
+
|
|
36
38
|
// Use options provided through commander or prompt the user
|
|
37
39
|
validateOptions(cmd)
|
|
38
40
|
const projectName = folderName || (await promptProjectName())
|
|
@@ -47,8 +49,9 @@ const program = new Commander.Command()
|
|
|
47
49
|
console.log(red(`${projectName} already exists, try again.`))
|
|
48
50
|
process.exit(1)
|
|
49
51
|
}
|
|
50
|
-
const language = "js"
|
|
51
52
|
const projectDescription = await promptDescription()
|
|
53
|
+
const language = await promptTypescript()
|
|
54
|
+
const tailWindSupport = await promptTailwind()
|
|
52
55
|
const stateManagement = cmd.stateManagement || (await promptStateManagement())
|
|
53
56
|
|
|
54
57
|
// Define mapping of options to repository suffixes
|
|
@@ -65,7 +68,11 @@ const program = new Commander.Command()
|
|
|
65
68
|
|
|
66
69
|
const commonCodeDirectory = "package/templates/common"
|
|
67
70
|
const selectedTemplateCode = `package/templates/${repositorySuffixes[stateManagement]}-${repositorySuffixes[language]}`
|
|
71
|
+
const tailwindCodeDirectory = "package/templates/tailwind"
|
|
72
|
+
|
|
68
73
|
const subDirectoriesToExtract = [commonCodeDirectory, selectedTemplateCode]
|
|
74
|
+
if (tailWindSupport) subDirectoriesToExtract.push(tailwindCodeDirectory)
|
|
75
|
+
|
|
69
76
|
const extractionDestination = `/${projectName}/`
|
|
70
77
|
let tempDir
|
|
71
78
|
;(() => {
|
|
@@ -77,6 +84,8 @@ const program = new Commander.Command()
|
|
|
77
84
|
extractSubdirectory(packageFilePath)
|
|
78
85
|
createGitignore(projectName)
|
|
79
86
|
|
|
87
|
+
if (tailWindSupport) setupTailwind(projectName)
|
|
88
|
+
|
|
80
89
|
execSync(
|
|
81
90
|
`cd ${projectName} && npm i && npm pkg set name=${projectName} ${projectDescription ? `description="${projectDescription}"` : ""} && git init --quiet && git add . && git commit -m "initial commit from Create Catalyst App"`,
|
|
82
91
|
{ stdio: "inherit" }
|
|
@@ -150,6 +159,9 @@ const program = new Commander.Command()
|
|
|
150
159
|
if (entry.path.startsWith(selectedTemplateCode)) {
|
|
151
160
|
entry.path = entry.path.replace(selectedTemplateCode, extractionDestination)
|
|
152
161
|
}
|
|
162
|
+
if (entry.path.startsWith(tailwindCodeDirectory)) {
|
|
163
|
+
entry.path = entry.path.replace(tailwindCodeDirectory, extractionDestination)
|
|
164
|
+
}
|
|
153
165
|
},
|
|
154
166
|
})
|
|
155
167
|
} catch (e) {
|
|
@@ -218,6 +230,49 @@ async function promptDescription() {
|
|
|
218
230
|
} else return null
|
|
219
231
|
}
|
|
220
232
|
|
|
233
|
+
async function promptTypescript() {
|
|
234
|
+
const response = await prompts({
|
|
235
|
+
type: "select",
|
|
236
|
+
name: "typescript",
|
|
237
|
+
message: "Would you like to use TypeScript?",
|
|
238
|
+
choices: [
|
|
239
|
+
{ title: "Yes", value: "ts" },
|
|
240
|
+
{ title: "No", value: "js" },
|
|
241
|
+
],
|
|
242
|
+
})
|
|
243
|
+
|
|
244
|
+
return response.typescript
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
async function promptTailwind() {
|
|
248
|
+
const response = await prompts({
|
|
249
|
+
type: "select",
|
|
250
|
+
name: "tailwind",
|
|
251
|
+
message: "Would you like to use Tailwind CSS?",
|
|
252
|
+
choices: [
|
|
253
|
+
{ title: "Yes", value: true },
|
|
254
|
+
{ title: "No", value: false },
|
|
255
|
+
],
|
|
256
|
+
})
|
|
257
|
+
return response.tailwind
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
async function setupTailwind(projectName) {
|
|
261
|
+
try {
|
|
262
|
+
const packageJsonPath = path.join(process.cwd(), projectName, "package.json")
|
|
263
|
+
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf8"))
|
|
264
|
+
packageJson.dependencies = {
|
|
265
|
+
...(packageJson.dependencies || {}),
|
|
266
|
+
tailwindcss: "^4.1.4",
|
|
267
|
+
"@tailwindcss/postcss": "^4.1.4",
|
|
268
|
+
}
|
|
269
|
+
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2))
|
|
270
|
+
} catch (error) {
|
|
271
|
+
console.log("Error while setting up tailwind:", error)
|
|
272
|
+
process.exit(1)
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
|
|
221
276
|
function validateOptions(cmd) {
|
|
222
277
|
// Validate language option
|
|
223
278
|
if (cmd.lang && !["js", "ts"].includes(cmd.lang.toLowerCase())) {
|
|
@@ -3,7 +3,7 @@ import "./styles"
|
|
|
3
3
|
import { hydrateRoot } from "react-dom/client"
|
|
4
4
|
import { loadableReady } from "@loadable/component"
|
|
5
5
|
import { RouterProvider } from "@tata1mg/router"
|
|
6
|
-
import clientRouter from "catalyst-core
|
|
6
|
+
import clientRouter from "catalyst-core/router/ClientRouter"
|
|
7
7
|
|
|
8
8
|
window.addEventListener("load", () => {
|
|
9
9
|
loadableReady(() => {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"name": "create-catalyst-app-starter",
|
|
2
|
+
"name": "create-catalyst-app-internal-starter",
|
|
3
3
|
"version": "1.0.0",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"start": "catalyst start",
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"buildApp": "catalyst buildApp",
|
|
12
12
|
"buildApp:ios": "catalyst buildApp:ios",
|
|
13
13
|
"buildApp:android": "catalyst buildApp:android",
|
|
14
|
-
"setupEmulator"
|
|
14
|
+
"setupEmulator": "catalyst setupEmulator",
|
|
15
15
|
"setupEmulator:ios": "catalyst setupEmulator:ios",
|
|
16
16
|
"setupEmulator:android": "catalyst setupEmulator:android"
|
|
17
17
|
},
|
|
@@ -25,8 +25,8 @@
|
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"@loadable/component": "^5.16.3",
|
|
28
|
-
"@tata1mg/router": "^0.0.1-beta.
|
|
29
|
-
"catalyst-core": "
|
|
28
|
+
"@tata1mg/router": "^0.0.1-beta.7",
|
|
29
|
+
"catalyst-core": "0.0.3-canary.20"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"eslint": "^8.26.0",
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import React from "react"
|
|
2
|
+
import "./styles"
|
|
3
|
+
import { hydrateRoot } from "react-dom/client"
|
|
4
|
+
import { loadableReady } from "@loadable/component"
|
|
5
|
+
import { RouterProvider } from "@tata1mg/router"
|
|
6
|
+
import clientRouter from "catalyst-core/router/ClientRouter"
|
|
7
|
+
|
|
8
|
+
window.addEventListener("load", () => {
|
|
9
|
+
loadableReady(() => {
|
|
10
|
+
const { __ROUTER_INITIAL_DATA__: routerInitialData } = window
|
|
11
|
+
|
|
12
|
+
const router = clientRouter({ routerInitialState: routerInitialData })
|
|
13
|
+
|
|
14
|
+
const Application = (
|
|
15
|
+
<React.StrictMode>
|
|
16
|
+
<RouterProvider router={router} />
|
|
17
|
+
</React.StrictMode>
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
const container = document.getElementById("app")
|
|
21
|
+
hydrateRoot(container, Application)
|
|
22
|
+
})
|
|
23
|
+
})
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "create-catalyst-app-internal-starter",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"scripts": {
|
|
5
|
+
"start": "catalyst start",
|
|
6
|
+
"build": "npm run typecheck && catalyst build",
|
|
7
|
+
"serve": "catalyst serve",
|
|
8
|
+
"lint": "eslint .",
|
|
9
|
+
"devBuild": "catalyst devBuild",
|
|
10
|
+
"devServe": "catalyst devServe",
|
|
11
|
+
"buildApp": "catalyst buildApp",
|
|
12
|
+
"buildApp:ios": "catalyst buildApp:ios",
|
|
13
|
+
"buildApp:android": "catalyst buildApp:android",
|
|
14
|
+
"setupEmulator": "catalyst setupEmulator",
|
|
15
|
+
"setupEmulator:ios": "catalyst setupEmulator:ios",
|
|
16
|
+
"setupEmulator:android": "catalyst setupEmulator:android",
|
|
17
|
+
"typecheck": "tsc --noEmit"
|
|
18
|
+
},
|
|
19
|
+
"_moduleAliases": {
|
|
20
|
+
"@api": "api.js",
|
|
21
|
+
"@containers": "src/js/containers",
|
|
22
|
+
"@server": "server",
|
|
23
|
+
"@config": "config",
|
|
24
|
+
"@css": "src/static/css",
|
|
25
|
+
"@routes": "src/js/routes/"
|
|
26
|
+
},
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"@loadable/component": "^5.16.3",
|
|
29
|
+
"@tata1mg/router": "^0.0.1-beta.7",
|
|
30
|
+
"catalyst-core": "0.0.3-canary.20"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"eslint": "^8.26.0",
|
|
34
|
+
"typescript": "^5.8.3",
|
|
35
|
+
"@types/react": "^18.2.0",
|
|
36
|
+
"@types/react-dom": "^18.2.0",
|
|
37
|
+
"eslint-plugin-react": "^7.34.1",
|
|
38
|
+
"eslint-plugin-react-hooks": "^4.6.0"
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import React from "react"
|
|
2
|
+
import { Outlet } from "@tata1mg/router"
|
|
3
|
+
|
|
4
|
+
const App = () => {
|
|
5
|
+
return (
|
|
6
|
+
<>
|
|
7
|
+
<Outlet />
|
|
8
|
+
</>
|
|
9
|
+
)
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
App.serverSideFunction = () => {
|
|
13
|
+
return new Promise((resolve) => resolve())
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export default App
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import React from "react"
|
|
2
|
+
import { RouterDataProvider, MetaTag } from "@tata1mg/router"
|
|
3
|
+
import App from "@containers/App"
|
|
4
|
+
import routes from "./index.js"
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Making the routes array compatible with the format accepted by createBrowserRouter
|
|
8
|
+
* API on the client side
|
|
9
|
+
* https://reactrouter.com/en/main/routers/create-browser-router
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
export const preparedRoutes = ({ routerInitialState }) => {
|
|
13
|
+
const getPreparedRoutes = (routes) => {
|
|
14
|
+
return routes.map((route, index) => {
|
|
15
|
+
const Component = route.component
|
|
16
|
+
const routeToRender = {
|
|
17
|
+
...route,
|
|
18
|
+
element: <Component key={index} />,
|
|
19
|
+
}
|
|
20
|
+
if (route.children) {
|
|
21
|
+
routeToRender.children = getPreparedRoutes(route.children)
|
|
22
|
+
}
|
|
23
|
+
return routeToRender
|
|
24
|
+
})
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return [
|
|
28
|
+
{
|
|
29
|
+
element: (
|
|
30
|
+
<RouterDataProvider config={{}} initialState={routerInitialState}>
|
|
31
|
+
<MetaTag />
|
|
32
|
+
<App />
|
|
33
|
+
</RouterDataProvider>
|
|
34
|
+
),
|
|
35
|
+
children: getPreparedRoutes(routes),
|
|
36
|
+
},
|
|
37
|
+
]
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export const getRoutes = () => {
|
|
41
|
+
return routes
|
|
42
|
+
}
|
|
@@ -4,7 +4,7 @@ import { hydrateRoot } from "react-dom/client"
|
|
|
4
4
|
import { loadableReady } from "@loadable/component"
|
|
5
5
|
import { Provider } from "react-redux"
|
|
6
6
|
import { RouterProvider } from "@tata1mg/router"
|
|
7
|
-
import clientRouter from "catalyst-core
|
|
7
|
+
import clientRouter from "catalyst-core/router/ClientRouter"
|
|
8
8
|
import configureStore from "@store"
|
|
9
9
|
|
|
10
10
|
window.addEventListener("load", () => {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"name": "create-catalyst-app-starter",
|
|
2
|
+
"name": "create-catalyst-app-internal-starter",
|
|
3
3
|
"version": "1.0.0",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"start": "catalyst start",
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"buildApp": "catalyst buildApp",
|
|
12
12
|
"buildApp:ios": "catalyst buildApp:ios",
|
|
13
13
|
"buildApp:android": "catalyst buildApp:android",
|
|
14
|
-
"setupEmulator"
|
|
14
|
+
"setupEmulator": "catalyst setupEmulator",
|
|
15
15
|
"setupEmulator:ios": "catalyst setupEmulator:ios",
|
|
16
16
|
"setupEmulator:android": "catalyst setupEmulator:android"
|
|
17
17
|
},
|
|
@@ -26,8 +26,8 @@
|
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"@loadable/component": "^5.16.3",
|
|
29
|
-
"@tata1mg/router": "^0.0.1-beta.
|
|
30
|
-
"catalyst-core
|
|
29
|
+
"@tata1mg/router": "^0.0.1-beta.7",
|
|
30
|
+
"catalyst-core": "0.0.3-canary.20",
|
|
31
31
|
"@reduxjs/toolkit": "1.9.3",
|
|
32
32
|
"react-redux": "^8.1.3"
|
|
33
33
|
},
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import React from "react"
|
|
2
|
+
import "./styles"
|
|
3
|
+
import { hydrateRoot } from "react-dom/client"
|
|
4
|
+
import { loadableReady } from "@loadable/component"
|
|
5
|
+
import { Provider } from "react-redux"
|
|
6
|
+
import { RouterProvider } from "@tata1mg/router"
|
|
7
|
+
import clientRouter from "catalyst-core/router/ClientRouter"
|
|
8
|
+
import configureStore from "@store"
|
|
9
|
+
|
|
10
|
+
window.addEventListener("load", () => {
|
|
11
|
+
loadableReady(() => {
|
|
12
|
+
const { __ROUTER_INITIAL_DATA__: routerInitialData, __INITIAL_STATE__ } = window
|
|
13
|
+
const store = configureStore(__INITIAL_STATE__ || {})
|
|
14
|
+
|
|
15
|
+
const router = clientRouter({ store, routerInitialState: routerInitialData })
|
|
16
|
+
|
|
17
|
+
const Application = (
|
|
18
|
+
<Provider store={store} serverState={__INITIAL_STATE__}>
|
|
19
|
+
<React.StrictMode>
|
|
20
|
+
<RouterProvider router={router} />
|
|
21
|
+
</React.StrictMode>
|
|
22
|
+
</Provider>
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
const container = document.getElementById("app")
|
|
26
|
+
hydrateRoot(container, Application)
|
|
27
|
+
})
|
|
28
|
+
})
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "create-catalyst-app-internal-starter",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"scripts": {
|
|
5
|
+
"start": "catalyst start",
|
|
6
|
+
"build": "npm run typecheck && catalyst build",
|
|
7
|
+
"serve": "catalyst serve",
|
|
8
|
+
"lint": "eslint .",
|
|
9
|
+
"devBuild": "catalyst devBuild",
|
|
10
|
+
"devServe": "catalyst devServe",
|
|
11
|
+
"buildApp": "catalyst buildApp",
|
|
12
|
+
"buildApp:ios": "catalyst buildApp:ios",
|
|
13
|
+
"buildApp:android": "catalyst buildApp:android",
|
|
14
|
+
"setupEmulator": "catalyst setupEmulator",
|
|
15
|
+
"setupEmulator:ios": "catalyst setupEmulator:ios",
|
|
16
|
+
"setupEmulator:android": "catalyst setupEmulator:android",
|
|
17
|
+
"typecheck": "tsc --noEmit"
|
|
18
|
+
},
|
|
19
|
+
"_moduleAliases": {
|
|
20
|
+
"@api": "api.js",
|
|
21
|
+
"@containers": "src/js/containers",
|
|
22
|
+
"@server": "server",
|
|
23
|
+
"@config": "config",
|
|
24
|
+
"@css": "src/static/css",
|
|
25
|
+
"@routes": "src/js/routes/",
|
|
26
|
+
"@store": "src/js/store/index.js"
|
|
27
|
+
},
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"@loadable/component": "^5.16.3",
|
|
30
|
+
"@tata1mg/router": "^0.0.1-beta.7",
|
|
31
|
+
"catalyst-core": "0.0.3-canary.20",
|
|
32
|
+
"@reduxjs/toolkit": "1.9.3",
|
|
33
|
+
"react-redux": "^8.1.3"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"eslint": "^8.26.0",
|
|
37
|
+
"typescript": "^5.8.3",
|
|
38
|
+
"@types/react": "^18.2.0",
|
|
39
|
+
"@types/react-dom": "^18.2.0",
|
|
40
|
+
"eslint-plugin-react": "^7.34.1",
|
|
41
|
+
"eslint-plugin-react-hooks": "^4.6.0"
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
const createActionTypes = (prefix, actionTypeList = []) => {
|
|
2
|
+
const actionTypesObject = {}
|
|
3
|
+
actionTypeList.forEach((item) => {
|
|
4
|
+
actionTypesObject[item] = `${prefix}/${item}`
|
|
5
|
+
})
|
|
6
|
+
|
|
7
|
+
return actionTypesObject
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export default createActionTypes
|
|
11
|
+
|
|
12
|
+
export const ShellActions = createActionTypes("shellActions", ["REDUX_TEST"])
|
|
13
|
+
export const reduxTest = () => {
|
|
14
|
+
return {
|
|
15
|
+
type: ShellActions.REDUX_TEST,
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import React from "react"
|
|
2
|
+
import { Outlet } from "@tata1mg/router"
|
|
3
|
+
|
|
4
|
+
const App = () => {
|
|
5
|
+
return (
|
|
6
|
+
<>
|
|
7
|
+
<Outlet />
|
|
8
|
+
</>
|
|
9
|
+
)
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
App.serverSideFunction = () => {
|
|
13
|
+
return new Promise((resolve) => resolve())
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export default App
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ShellActions } from "./actions"
|
|
2
|
+
|
|
3
|
+
export const defaultState = {
|
|
4
|
+
testActionDispatched: false,
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export const shellReducer = (state = defaultState, action) => {
|
|
8
|
+
switch (action.type) {
|
|
9
|
+
case ShellActions.REDUX_TEST: {
|
|
10
|
+
return {
|
|
11
|
+
...state,
|
|
12
|
+
testActionDispatched: true,
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
default:
|
|
17
|
+
return state
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import React from "react"
|
|
2
|
+
import { RouterDataProvider, MetaTag } from "@tata1mg/router"
|
|
3
|
+
import App from "@containers/App"
|
|
4
|
+
import routes from "./index.js"
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Making the routes array compatible with the format accepted by createBrowserRouter
|
|
8
|
+
* API on the client side
|
|
9
|
+
* https://reactrouter.com/en/main/routers/create-browser-router
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
export const preparedRoutes = ({ store, routerInitialState }) => {
|
|
13
|
+
const getPreparedRoutes = (routes) => {
|
|
14
|
+
return routes.map((route, index) => {
|
|
15
|
+
const Component = route.component
|
|
16
|
+
const routeToRender = {
|
|
17
|
+
...route,
|
|
18
|
+
element: <Component key={index} />,
|
|
19
|
+
}
|
|
20
|
+
if (route.children) {
|
|
21
|
+
routeToRender.children = getPreparedRoutes(route.children)
|
|
22
|
+
}
|
|
23
|
+
return routeToRender
|
|
24
|
+
})
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return [
|
|
28
|
+
{
|
|
29
|
+
element: (
|
|
30
|
+
<RouterDataProvider config={{}} initialState={routerInitialState} fetcherArgs={{ store }}>
|
|
31
|
+
<MetaTag />
|
|
32
|
+
<App />
|
|
33
|
+
</RouterDataProvider>
|
|
34
|
+
),
|
|
35
|
+
children: getPreparedRoutes(routes),
|
|
36
|
+
},
|
|
37
|
+
]
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export const getRoutes = () => {
|
|
41
|
+
return routes
|
|
42
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { configureStore as createStore } from "@reduxjs/toolkit"
|
|
2
|
+
import { combineReducers } from "redux"
|
|
3
|
+
import { shellReducer } from "@containers/App/reducer.js"
|
|
4
|
+
import fetchInstance from "@api"
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Function that initializes the store with the initialstate and adds middlewares that can be used during action dispatch
|
|
8
|
+
* @param {object} initialState Default state
|
|
9
|
+
* @param {object} request Request object that we recieve on server, this is only recieved when store is initialized on the server.
|
|
10
|
+
* @return {object} The store itself
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
const configureStore = (initialState) => {
|
|
14
|
+
const api = fetchInstance
|
|
15
|
+
const store = createStore({
|
|
16
|
+
reducer: combineReducers({ shellReducer }),
|
|
17
|
+
middleware: (getDefaultMiddleware) =>
|
|
18
|
+
getDefaultMiddleware({
|
|
19
|
+
thunk: {
|
|
20
|
+
extraArgument: { api },
|
|
21
|
+
},
|
|
22
|
+
}),
|
|
23
|
+
preloadedState: initialState,
|
|
24
|
+
})
|
|
25
|
+
return store
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export default configureStore
|
|
@@ -4,7 +4,7 @@ import { hydrateRoot } from "react-dom/client"
|
|
|
4
4
|
import { loadableReady } from "@loadable/component"
|
|
5
5
|
import { Provider } from "react-redux"
|
|
6
6
|
import { RouterProvider } from "@tata1mg/router"
|
|
7
|
-
import clientRouter from "catalyst-core
|
|
7
|
+
import clientRouter from "catalyst-core/router/ClientRouter"
|
|
8
8
|
import configureStore from "@store"
|
|
9
9
|
|
|
10
10
|
window.addEventListener("load", () => {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"name": "create-catalyst-app-starter",
|
|
2
|
+
"name": "create-catalyst-app-internal-starter",
|
|
3
3
|
"version": "1.0.0",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"start": "catalyst start",
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"buildApp": "catalyst buildApp",
|
|
12
12
|
"buildApp:ios": "catalyst buildApp:ios",
|
|
13
13
|
"buildApp:android": "catalyst buildApp:android",
|
|
14
|
-
"setupEmulator"
|
|
14
|
+
"setupEmulator": "catalyst setupEmulator",
|
|
15
15
|
"setupEmulator:ios": "catalyst setupEmulator:ios",
|
|
16
16
|
"setupEmulator:android": "catalyst setupEmulator:android"
|
|
17
17
|
},
|
|
@@ -26,8 +26,8 @@
|
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"@loadable/component": "^5.16.3",
|
|
29
|
-
"@tata1mg/router": "^0.0.1-beta.
|
|
30
|
-
"catalyst-core
|
|
29
|
+
"@tata1mg/router": "^0.0.1-beta.7",
|
|
30
|
+
"catalyst-core": "0.0.3-canary.20",
|
|
31
31
|
"@reduxjs/toolkit": "1.9.3",
|
|
32
32
|
"react-redux": "^8.1.3"
|
|
33
33
|
},
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import React from "react"
|
|
2
|
+
import "./styles"
|
|
3
|
+
import { hydrateRoot } from "react-dom/client"
|
|
4
|
+
import { loadableReady } from "@loadable/component"
|
|
5
|
+
import { Provider } from "react-redux"
|
|
6
|
+
import { RouterProvider } from "@tata1mg/router"
|
|
7
|
+
import clientRouter from "catalyst-core/router/ClientRouter"
|
|
8
|
+
import configureStore from "@store"
|
|
9
|
+
|
|
10
|
+
window.addEventListener("load", () => {
|
|
11
|
+
loadableReady(() => {
|
|
12
|
+
const { __ROUTER_INITIAL_DATA__: routerInitialData, __INITIAL_STATE__ } = window
|
|
13
|
+
const store = configureStore(__INITIAL_STATE__ || {})
|
|
14
|
+
|
|
15
|
+
const router = clientRouter({ store, routerInitialState: routerInitialData })
|
|
16
|
+
|
|
17
|
+
const Application = (
|
|
18
|
+
<Provider store={store} serverState={__INITIAL_STATE__}>
|
|
19
|
+
<React.StrictMode>
|
|
20
|
+
<RouterProvider router={router} />
|
|
21
|
+
</React.StrictMode>
|
|
22
|
+
</Provider>
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
const container = document.getElementById("app")
|
|
26
|
+
hydrateRoot(container, Application)
|
|
27
|
+
})
|
|
28
|
+
})
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "create-catalyst-app-internal-starter",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"scripts": {
|
|
5
|
+
"start": "catalyst start",
|
|
6
|
+
"build": "npm run typecheck && catalyst build",
|
|
7
|
+
"serve": "catalyst serve",
|
|
8
|
+
"lint": "eslint .",
|
|
9
|
+
"devBuild": "catalyst devBuild",
|
|
10
|
+
"devServe": "catalyst devServe",
|
|
11
|
+
"buildApp": "catalyst buildApp",
|
|
12
|
+
"buildApp:ios": "catalyst buildApp:ios",
|
|
13
|
+
"buildApp:android": "catalyst buildApp:android",
|
|
14
|
+
"setupEmulator": "catalyst setupEmulator",
|
|
15
|
+
"setupEmulator:ios": "catalyst setupEmulator:ios",
|
|
16
|
+
"setupEmulator:android": "catalyst setupEmulator:android",
|
|
17
|
+
"typecheck": "tsc --noEmit"
|
|
18
|
+
},
|
|
19
|
+
"_moduleAliases": {
|
|
20
|
+
"@api": "api.js",
|
|
21
|
+
"@containers": "src/js/containers",
|
|
22
|
+
"@server": "server",
|
|
23
|
+
"@config": "config",
|
|
24
|
+
"@css": "src/static/css",
|
|
25
|
+
"@routes": "src/js/routes/",
|
|
26
|
+
"@store": "src/js/store/index.js"
|
|
27
|
+
},
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"@loadable/component": "^5.16.3",
|
|
30
|
+
"@tata1mg/router": "^0.0.1-beta.7",
|
|
31
|
+
"catalyst-core": "0.0.3-canary.20",
|
|
32
|
+
"@reduxjs/toolkit": "1.9.3",
|
|
33
|
+
"react-redux": "^8.1.3"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"eslint": "^8.26.0",
|
|
37
|
+
"typescript": "^5.8.3",
|
|
38
|
+
"@types/react": "^18.2.0",
|
|
39
|
+
"@types/react-dom": "^18.2.0",
|
|
40
|
+
"eslint-plugin-react": "^7.34.1",
|
|
41
|
+
"eslint-plugin-react-hooks": "^4.6.0"
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import React from "react"
|
|
2
|
+
import { Outlet } from "@tata1mg/router"
|
|
3
|
+
|
|
4
|
+
const App = () => {
|
|
5
|
+
return (
|
|
6
|
+
<>
|
|
7
|
+
<Outlet />
|
|
8
|
+
</>
|
|
9
|
+
)
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
App.serverSideFunction = () => {
|
|
13
|
+
return new Promise((resolve) => resolve())
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export default App
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { createSlice } from "@reduxjs/toolkit"
|
|
2
|
+
|
|
3
|
+
const initialState = {
|
|
4
|
+
testActionDispatched: false,
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export const appSlice = createSlice({
|
|
8
|
+
name: "shellReducer",
|
|
9
|
+
initialState: initialState,
|
|
10
|
+
reducers: {
|
|
11
|
+
reduxTest: (state) => {
|
|
12
|
+
state.testActionDispatched = true
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
export const { reduxTest } = appSlice.actions
|
|
18
|
+
export const shellReducer = appSlice.reducer
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import React from "react"
|
|
2
|
+
import { RouterDataProvider, MetaTag } from "@tata1mg/router"
|
|
3
|
+
import App from "@containers/App"
|
|
4
|
+
import routes from "./index.js"
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Making the routes array compatible with the format accepted by createBrowserRouter
|
|
8
|
+
* API on the client side
|
|
9
|
+
* https://reactrouter.com/en/main/routers/create-browser-router
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
export const preparedRoutes = ({ store, routerInitialState }) => {
|
|
13
|
+
const getPreparedRoutes = (routes) => {
|
|
14
|
+
return routes.map((route, index) => {
|
|
15
|
+
const Component = route.component
|
|
16
|
+
const routeToRender = {
|
|
17
|
+
...route,
|
|
18
|
+
element: <Component key={index} />,
|
|
19
|
+
}
|
|
20
|
+
if (route.children) {
|
|
21
|
+
routeToRender.children = getPreparedRoutes(route.children)
|
|
22
|
+
}
|
|
23
|
+
return routeToRender
|
|
24
|
+
})
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return [
|
|
28
|
+
{
|
|
29
|
+
element: (
|
|
30
|
+
<RouterDataProvider config={{}} initialState={routerInitialState} fetcherArgs={{ store }}>
|
|
31
|
+
<MetaTag />
|
|
32
|
+
<App />
|
|
33
|
+
</RouterDataProvider>
|
|
34
|
+
),
|
|
35
|
+
children: getPreparedRoutes(routes),
|
|
36
|
+
},
|
|
37
|
+
]
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export const getRoutes = () => {
|
|
41
|
+
return routes
|
|
42
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { configureStore as createStore } from "@reduxjs/toolkit"
|
|
2
|
+
import { combineReducers } from "redux"
|
|
3
|
+
import { shellReducer } from "@containers/App/reducer.js"
|
|
4
|
+
import fetchInstance from "@api"
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Function that initializes the store with the initialstate and adds middlewares that can be used during action dispatch
|
|
8
|
+
* @param {object} initialState Default state
|
|
9
|
+
* @param {object} request Request object that we recieve on server, this is only recieved when store is initialized on the server.
|
|
10
|
+
* @return {object} The store itself
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
const configureStore = (initialState) => {
|
|
14
|
+
const api = fetchInstance
|
|
15
|
+
const store = createStore({
|
|
16
|
+
reducer: combineReducers({ shellReducer }),
|
|
17
|
+
middleware: (getDefaultMiddleware) =>
|
|
18
|
+
getDefaultMiddleware({
|
|
19
|
+
thunk: {
|
|
20
|
+
extraArgument: { api },
|
|
21
|
+
},
|
|
22
|
+
}),
|
|
23
|
+
preloadedState: initialState,
|
|
24
|
+
})
|
|
25
|
+
return store
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export default configureStore
|