create-catalyst-app 0.0.1-beta.3 → 0.0.1-beta.5

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 CHANGED
@@ -1,6 +1,6 @@
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`. 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
6
  npx create-catalyst-app@latest
@@ -24,6 +24,7 @@ Next, select your preferred state management tool from the provided options.
24
24
  Following your selection, a default template will be cloned into the directory, and all necessary packages will be installed.
25
25
 
26
26
  ## Getting Started
27
+
27
28
  Commence development by initiating the application in development mode with the following commands:
28
29
 
29
30
  Navigate into the directory
@@ -31,7 +32,9 @@ Navigate into the directory
31
32
  ```bash
32
33
  cd my-app
33
34
  ```
35
+
34
36
  For running the application in development mode, run:
37
+
35
38
  ```bash
36
39
  npm run start
37
40
  ```
@@ -49,4 +52,5 @@ npm run serve
49
52
  ```
50
53
 
51
54
  ## Documentation
55
+
52
56
  Explore the complete documentation at [https://catalyst.1mg.com](https://catalyst.1mg.com).
package/package.json CHANGED
@@ -1,22 +1,19 @@
1
1
  {
2
2
  "name": "create-catalyst-app",
3
3
  "bin": "scripts/cli.cjs",
4
- "version": "0.0.1-beta.3",
4
+ "version": "0.0.1-beta.5",
5
5
  "description": "cli package to scaffold Catalyst application",
6
- "main": "index.js",
7
- "scripts": {
8
- "start": "node index.js"
9
- },
10
6
  "dependencies": {
11
7
  "commander": "^8.2.0",
12
8
  "fs": "^0.0.1-security",
13
9
  "https": "^1.0.0",
14
10
  "picocolors": "^0.1.0",
15
11
  "prompts": "^2.4.0",
16
- "tar": "6.1.15"
12
+ "tar": "^6.2.1",
13
+ "validate-npm-package-name": "^5.0.0"
17
14
  },
18
15
  "devDependencies": {
19
16
  "prettier": "^3.2.5"
20
17
  },
21
- "license":"MIT"
18
+ "license": "MIT"
22
19
  }
package/scripts/cli.cjs CHANGED
@@ -3,14 +3,13 @@ const { execSync } = require("child_process")
3
3
  const Commander = require("commander")
4
4
  const { Option } = require("commander")
5
5
  const prompts = require("prompts")
6
- const { red, green, cyan } = require("picocolors")
7
-
8
- const packageJson = require("../package.json")
6
+ const { red, green, cyan, bold } = require("picocolors")
9
7
  const tar = require("tar")
10
8
  const path = require("path")
11
9
  const fs = require("fs")
10
+ var validate = require("validate-npm-package-name")
11
+ const packageJson = require("../package.json")
12
12
 
13
- // Hardcoded branch
14
13
  let projectName = null
15
14
  const program = new Commander.Command()
16
15
  .version(packageJson.version)
@@ -31,11 +30,21 @@ const program = new Commander.Command()
31
30
  // Use options provided through commander or prompt the user
32
31
  validateOptions(cmd)
33
32
  const projectName = folderName || (await promptProjectName())
33
+ let isNameValid = validate(projectName)
34
+ if (!isNameValid.validForNewPackages) {
35
+ isNameValid?.warnings?.forEach?.((item) => console.log(red(item)))
36
+ isNameValid?.errors?.forEach?.((item) => console.log(red(item)))
37
+ process.exit(1)
38
+ }
39
+ let projectPath = path.join(process.cwd(), projectName)
40
+ if (fs.existsSync(projectPath)) {
41
+ console.log(red(`${projectName} already exists, try again.`))
42
+ process.exit(1)
43
+ }
34
44
  const language = "js"
35
45
  const projectDescription = await promptDescription()
36
46
  const stateManagement = cmd.stateManagement || (await promptStateManagement())
37
47
 
38
-
39
48
  // Define mapping of options to repository suffixes
40
49
  const repositorySuffixes = {
41
50
  js: "js",
@@ -53,33 +62,41 @@ const program = new Commander.Command()
53
62
  const subDirectoriesToExtract = [commonCodeDirectory, selectedTemplateCode]
54
63
  const extractionDestination = `/${projectName}/`
55
64
  let tempDir
56
- ; (() => {
57
- try {
58
- let projectPath = path.join(process.cwd(), projectName);
59
-
60
- if(fs.existsSync(projectPath)){
61
- console.log(`${projectName} already exists, try again.`)
62
- process.exit(1)
63
- }
64
- tempDir = createTempDir()
65
-
66
- const packageFilePath = packNpmPackage(packageName, packageVersion, tempDir)
67
-
68
- extractSubdirectory(packageFilePath)
69
- createGitignore(projectName)
70
-
71
- execSync(
72
- `cd ${projectName} && npm i && npm pkg set name=${projectName} ${projectDescription ? `description="${projectDescription}"` : ""} && git init --quiet`,
73
- { stdio: "inherit" }
74
- )
75
- deleteDirectory(tempDir)
76
- } catch (error) {
77
- deleteDirectory(tempDir)
78
- console.error(`Error: ${error.message}`)
79
- process.exit(1)
80
- }
81
- })()
65
+ ;(() => {
66
+ try {
67
+ tempDir = createTempDir()
68
+
69
+ const packageFilePath = packNpmPackage(packageName, packageVersion, tempDir)
70
+
71
+ extractSubdirectory(packageFilePath)
72
+ createGitignore(projectName)
82
73
 
74
+ execSync(
75
+ `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"`,
76
+ { stdio: "inherit" }
77
+ )
78
+
79
+ console.log(`\n${green(bold("Success!"))} created ${projectName} at ${projectPath}`)
80
+ console.log("Inside this directory, you can run the following commands.")
81
+
82
+ console.log(cyan(bold(" \n npm run start")))
83
+ console.log(" Starts the development server ")
84
+
85
+ console.log(cyan(bold("\n npm run build")))
86
+ console.log(" Bundles the app for production ")
87
+
88
+ console.log(cyan(bold("\n npm run serves")))
89
+ console.log(" Serves the production build ")
90
+
91
+ console.log("\nWe suggest you to begin, by running")
92
+ console.log(` ${cyan("cd")} ${projectName} && ${cyan("npm start")} \n\n`)
93
+ } catch (error) {
94
+ console.error(`Error: ${error.message}`)
95
+ process.exit(1)
96
+ } finally {
97
+ deleteDirectory(tempDir)
98
+ }
99
+ })()
83
100
  function packNpmPackage(packageName, packageVersion, tempDir) {
84
101
  const tarballFileName = `${packageName}-${packageVersion}.tgz`
85
102
  const tarballFilePath = path.join(tempDir, tarballFileName)
@@ -174,10 +191,10 @@ async function promptProjectName() {
174
191
  if (!res.path || projectName === "") {
175
192
  console.log(
176
193
  "\nPlease specify the project directory:\n" +
177
- ` ${cyan(program.name())} ${green("<project-directory>")}\n` +
178
- "For example:\n" +
179
- ` ${cyan(program.name())} ${green("my-next-app")}\n\n` +
180
- `Run ${cyan(`${program.name()} --help`)} to see all options.`
194
+ ` ${cyan(program.name())} ${green("<project-directory>")}\n` +
195
+ "For example:\n" +
196
+ ` ${cyan(program.name())} ${green("my-next-app")}\n\n` +
197
+ `Run ${cyan(`${program.name()} --help`)} to see all options.`
181
198
  )
182
199
  process.exit(1)
183
200
  }
@@ -223,20 +240,14 @@ function deleteDirectory(dirPath) {
223
240
 
224
241
  // Function to create a .gitignore file with the hardcoded patterns
225
242
  function createGitignore(projectName) {
243
+ const gitiIgnorePatterns = ["node_modules", "build", "logs"]
226
244
 
227
- const gitiIgnorePatterns = [
228
- 'node_modules',
229
- 'build',
230
- 'logs'
231
- ];
232
-
233
- const gitignorePath = path.join(process.cwd(), projectName, '.gitignore');
245
+ const gitignorePath = path.join(process.cwd(), projectName, ".gitignore")
234
246
 
235
247
  if (fs.existsSync(gitignorePath)) {
236
- console.log('.gitignore already exists. Please rename or remove it before running the script.');
237
- return;
248
+ console.log(".gitignore already exists. Please rename or remove it before running the script.")
249
+ return
238
250
  }
239
251
 
240
- fs.writeFileSync(gitignorePath, gitiIgnorePatterns.join('\n'));
252
+ fs.writeFileSync(gitignorePath, gitiIgnorePatterns.join("\n"))
241
253
  }
242
-
@@ -0,0 +1 @@
1
+ **/build/*
@@ -0,0 +1,28 @@
1
+ {
2
+ "rules": {
3
+ "react-hooks/exhaustive-deps": "error" // Checks effect dependencies
4
+ },
5
+ "env": {
6
+ "browser": true,
7
+ "es6": true,
8
+ "node": true
9
+ },
10
+ "extends": [
11
+ "eslint:recommended",
12
+ "plugin:react/recommended",
13
+ ],
14
+ "parserOptions": {
15
+ "sourceType": "module",
16
+ "ecmaVersion": "latest"
17
+ },
18
+ "plugins": [
19
+ "react",
20
+ "react-hooks"
21
+ ],
22
+ "settings": {
23
+ "react": {
24
+ "pragma": "React",
25
+ "version": "detect"
26
+ }
27
+ }
28
+ }
@@ -1,6 +1,6 @@
1
1
  ## Getting Started
2
2
 
3
- Commence development by initiating the the following commands:
3
+ Commence development by initiating the the following commands:
4
4
 
5
5
  For running the application in development mode, run:
6
6
 
@@ -1,27 +1,16 @@
1
- const apiInstance = () => {
2
- const fetchFunction = async (url, options) => {
3
- let baseURL = process.env.API_URL
4
- let finalUrl = baseURL + url
1
+ const fetchFunction = (url, options) => {
2
+ let baseURL = process.env.API_URL
3
+ let finalUrl = baseURL + url
5
4
 
6
- // Request Interceptor - modify request here
5
+ // Request Interceptor - modify request here
7
6
 
8
- // Add query params
9
- if (Object.keys(options?.params).length > 0) {
10
- finalUrl = url + "?" + new URLSearchParams(options.params)
11
- }
12
-
13
- return fetch(finalUrl, options).then(async (response) => {
14
- const parsedResponse = await response.json()
15
- // Response Interceptor - modify response here
16
- return parsedResponse
7
+ return fetch(finalUrl, options)
8
+ .then(response => {
9
+ return response.json().then(parsedResponse => {
10
+ // Response Interceptor - modify response here
11
+ return parsedResponse
12
+ })
17
13
  })
18
- }
19
- return {
20
- get: fetchFunction,
21
- post: fetchFunction,
22
- delete: fetchFunction,
23
- patch: fetchFunction,
24
- put: fetchFunction,
25
- }
26
14
  }
27
- export default apiInstance
15
+
16
+ export default fetchFunction
@@ -6,10 +6,7 @@
6
6
  "BUILD_OUTPUT_PATH": "build",
7
7
  "PUBLIC_STATIC_ASSET_PATH": "/assets/",
8
8
  "PUBLIC_STATIC_ASSET_URL": "http://localhost:3005",
9
- "NODE_ENV": "development",
10
9
  "API_URL": "",
11
10
  "ANALYZE_BUNDLE": false,
12
- "CLIENT_ENV_VARIABLES": [
13
- "API_URL"
14
- ]
11
+ "CLIENT_ENV_VARIABLES": ["API_URL"]
15
12
  }
@@ -4,8 +4,7 @@ import { Head, Body } from "catalyst-core"
4
4
  function Document(props) {
5
5
  return (
6
6
  <html lang="en">
7
- <Head {...props}>
8
- </Head>
7
+ <Head {...props}></Head>
9
8
  <Body {...props} />
10
9
  </html>
11
10
  )
@@ -8,10 +8,4 @@ const routes = [
8
8
  },
9
9
  ]
10
10
 
11
- /**
12
- * Making the routes array compatible with the format accepted by createBrowserRouter
13
- * API on the client side
14
- * https://reactrouter.com/en/main/routers/create-browser-router
15
- */
16
-
17
11
  export default routes
@@ -7,7 +7,7 @@ import clientRouter from "catalyst-core/router/ClientRouter"
7
7
 
8
8
  window.addEventListener("load", () => {
9
9
  loadableReady(() => {
10
- const { __ROUTER_INITIAL_DATA__: routerInitialData, __INITIAL_STATE__ } = window
10
+ const { __ROUTER_INITIAL_DATA__: routerInitialData } = window
11
11
 
12
12
  const router = clientRouter({ routerInitialState: routerInitialData })
13
13
 
@@ -4,7 +4,10 @@
4
4
  "scripts": {
5
5
  "start": "catalyst start",
6
6
  "build": "catalyst build",
7
- "serve": "catalyst serve"
7
+ "serve": "catalyst serve",
8
+ "lint": "eslint .",
9
+ "devBuild": "catalyst devBuild",
10
+ "devServe": "catalyst devServe"
8
11
  },
9
12
  "_moduleAliases": {
10
13
  "@api": "api.js",
@@ -16,7 +19,12 @@
16
19
  },
17
20
  "dependencies": {
18
21
  "@loadable/component": "^5.16.3",
19
- "@tata1mg/router": "^0.0.1-beta.0",
20
- "catalyst-core": "^0.0.1-beta.3"
22
+ "@tata1mg/router": "^0.0.1-beta.1",
23
+ "catalyst-core": "^0.0.1-beta.4"
24
+ },
25
+ "devDependencies": {
26
+ "eslint": "^8.26.0",
27
+ "eslint-plugin-react": "^7.34.1",
28
+ "eslint-plugin-react-hooks": "^4.6.0"
21
29
  }
22
30
  }
@@ -3,7 +3,27 @@ import { RouterDataProvider, MetaTag } from "@tata1mg/router"
3
3
  import App from "@containers/App"
4
4
  import routes from "./index.js"
5
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
+
6
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
+
7
27
  return [
8
28
  {
9
29
  element: (
@@ -12,13 +32,7 @@ export const preparedRoutes = ({ routerInitialState }) => {
12
32
  <App />
13
33
  </RouterDataProvider>
14
34
  ),
15
- children: getRoutes()?.map((route, index) => {
16
- const Component = route.component
17
- return {
18
- ...route,
19
- element: <Component key={index} />,
20
- }
21
- }),
35
+ children: getPreparedRoutes(routes),
22
36
  },
23
37
  ]
24
38
  }
@@ -4,7 +4,10 @@
4
4
  "scripts": {
5
5
  "start": "catalyst start",
6
6
  "build": "catalyst build",
7
- "serve": "catalyst serve"
7
+ "serve": "catalyst serve",
8
+ "lint": "eslint .",
9
+ "devBuild": "catalyst devBuild",
10
+ "devServe": "catalyst devServe"
8
11
  },
9
12
  "_moduleAliases": {
10
13
  "@api": "api.js",
@@ -17,9 +20,14 @@
17
20
  },
18
21
  "dependencies": {
19
22
  "@loadable/component": "^5.16.3",
20
- "@tata1mg/router": "^0.0.1-beta.0",
21
- "catalyst-core": "^0.0.1-beta.3",
23
+ "@tata1mg/router": "^0.0.1-beta.1",
24
+ "catalyst-core": "^0.0.1-beta.4",
22
25
  "@reduxjs/toolkit": "1.9.3",
23
26
  "react-redux": "^8.1.3"
27
+ },
28
+ "devDependencies": {
29
+ "eslint": "^8.26.0",
30
+ "eslint-plugin-react": "^7.34.1",
31
+ "eslint-plugin-react-hooks": "^4.6.0"
24
32
  }
25
33
  }
@@ -17,4 +17,3 @@ export const shellReducer = (state = defaultState, action) => {
17
17
  return state
18
18
  }
19
19
  }
20
-
@@ -3,7 +3,27 @@ import { RouterDataProvider, MetaTag } from "@tata1mg/router"
3
3
  import App from "@containers/App"
4
4
  import routes from "./index.js"
5
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
+
6
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
+
7
27
  return [
8
28
  {
9
29
  element: (
@@ -12,13 +32,7 @@ export const preparedRoutes = ({ store, routerInitialState }) => {
12
32
  <App />
13
33
  </RouterDataProvider>
14
34
  ),
15
- children: getRoutes()?.map((route, index) => {
16
- const Component = route.component
17
- return {
18
- ...route,
19
- element: <Component key={index} />,
20
- }
21
- }),
35
+ children: getPreparedRoutes(routes),
22
36
  },
23
37
  ]
24
38
  }
@@ -4,7 +4,10 @@
4
4
  "scripts": {
5
5
  "start": "catalyst start",
6
6
  "build": "catalyst build",
7
- "serve": "catalyst serve"
7
+ "serve": "catalyst serve",
8
+ "lint": "eslint .",
9
+ "devBuild": "catalyst devBuild",
10
+ "devServe": "catalyst devServe"
8
11
  },
9
12
  "_moduleAliases": {
10
13
  "@api": "api.js",
@@ -17,9 +20,14 @@
17
20
  },
18
21
  "dependencies": {
19
22
  "@loadable/component": "^5.16.3",
20
- "@tata1mg/router": "^0.0.1-beta.0",
21
- "catalyst-core": "^0.0.1-beta.3",
23
+ "@tata1mg/router": "^0.0.1-beta.1",
24
+ "catalyst-core": "^0.0.1-beta.4",
22
25
  "@reduxjs/toolkit": "1.9.3",
23
26
  "react-redux": "^8.1.3"
27
+ },
28
+ "devDependencies": {
29
+ "eslint": "^8.26.0",
30
+ "eslint-plugin-react": "^7.34.1",
31
+ "eslint-plugin-react-hooks": "^4.6.0"
24
32
  }
25
33
  }
@@ -3,7 +3,27 @@ import { RouterDataProvider, MetaTag } from "@tata1mg/router"
3
3
  import App from "@containers/App"
4
4
  import routes from "./index.js"
5
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
+
6
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
+
7
27
  return [
8
28
  {
9
29
  element: (
@@ -12,13 +32,7 @@ export const preparedRoutes = ({ store, routerInitialState }) => {
12
32
  <App />
13
33
  </RouterDataProvider>
14
34
  ),
15
- children: getRoutes()?.map((route, index) => {
16
- const Component = route.component
17
- return {
18
- ...route,
19
- element: <Component key={index} />,
20
- }
21
- }),
35
+ children: getPreparedRoutes(routes),
22
36
  },
23
37
  ]
24
38
  }
@@ -1,26 +0,0 @@
1
- {
2
- "presets": [
3
- [
4
- "@babel/preset-env",
5
- {
6
- "targets": {
7
- "node": "current"
8
- }
9
- }
10
- ],
11
- "@babel/preset-react"
12
- ],
13
- "plugins": [
14
- "@babel/plugin-proposal-object-rest-spread",
15
- "transform-es2015-modules-commonjs",
16
- "transform-class-properties",
17
- "dynamic-import-node",
18
- "@loadable/babel-plugin"
19
- ],
20
- "env": {
21
- "test": {
22
- "presets": ["@babel/preset-react"]
23
- }
24
- },
25
- "ignore": ["__TEST__"]
26
- }