catalyst-core 0.0.1-beta.2 → 0.0.1-beta.4
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/.eslintignore +9 -0
- package/.eslintrc +92 -0
- package/README.md +58 -43
- package/babel.config.json +1 -5
- package/bin/catalyst.js +35 -35
- package/changelog.md +26 -0
- package/config.json +1 -2
- package/{LICENSE → license} +2 -1
- package/{logger/index.js → logger.js} +13 -10
- package/package.json +87 -85
- package/router/ClientRouter.js +10 -6
- package/router/ServerRouter.js +2 -11
- package/scripts/build.js +26 -11
- package/scripts/checkVersion.js +5 -0
- package/scripts/devBuild.js +42 -0
- package/scripts/devServe.js +43 -0
- package/scripts/loadEnvironmentVariables.js +8 -21
- package/scripts/loadScriptsBeforeServerStarts.js +13 -21
- package/scripts/serve.js +27 -11
- package/scripts/start.js +19 -12
- package/scripts/validator.js +39 -11
- package/server/expressServer.js +50 -0
- package/server/renderer/document/Body.js +17 -18
- package/server/renderer/document/Head.js +7 -8
- package/server/renderer/document/index.js +2 -0
- package/server/renderer/extract.js +25 -24
- package/server/renderer/handler.js +220 -208
- package/server/renderer/index.js +6 -7
- package/server/renderer/render.js +32 -19
- package/server/startServer.js +66 -0
- package/server/utils/metaTags.js +13 -0
- package/server/utils/userAgentUtil.js +51 -0
- package/server/utils/validator.js +39 -10
- package/webpack/babel-plugins/remove-client.plugin.js +1 -1
- package/webpack/babel-plugins/remove-ssr.plugin.js +1 -1
- package/webpack/babel.config.client.js +3 -3
- package/webpack/babel.config.ssr.js +1 -1
- package/webpack/base.babel.js +37 -36
- package/webpack/development.client.babel.js +11 -8
- package/webpack/production.client.babel.js +1 -2
- package/webpack/production.ssr.babel.js +3 -3
- package/webpack/scssParams.js +35 -15
- package/.prettierignore +0 -2
- package/.prettierrc.json +0 -7
- package/checkVersion.js +0 -3
- package/config/config.js +0 -24
- package/packages/create-framework-app/node_modules/.package-lock.json +0 -249
- package/packages/create-framework-app/templates/redux-js/node_modules/@babel/core/lib/config/caching.js +0 -261
- package/packages/create-framework-app/templates/redux-js/node_modules/@remix-run/router/dist/router.js +0 -4327
- package/packages/create-framework-app/templates/redux-js/node_modules/catalyst/router.js +0 -15
- package/packages/create-framework-app/templates/redux-js/node_modules/http-proxy-middleware/dist/router.js +0 -46
- package/reducer/index.js +0 -88
- package/reducer/loadableConfigReducer.js +0 -19
- package/store/index.dev.js +0 -73
- package/store/index.js +0 -25
- package/store/index.prod.js +0 -66
- package/types/caching.d.ts +0 -1
- package/types/config/config.d.ts +0 -19
- package/types/index.d.ts +0 -1
- package/types/logger/index.d.ts +0 -14
- package/types/reducer/index.d.ts +0 -22
- package/types/reducer/loadableConfigReducer.d.ts +0 -9
- package/types/router/ClientRouter.d.ts +0 -5
- package/types/router/ServerRouter.d.ts +0 -7
- package/types/router/index.d.ts +0 -8
- package/types/router.d.ts +0 -1
- package/types/scripts/build.d.ts +0 -1
- package/types/scripts/loadEnvironmentVariables.d.ts +0 -5
- package/types/scripts/loadScriptsBeforeServerStarts.d.ts +0 -1
- package/types/scripts/prepare.d.ts +0 -1
- package/types/scripts/registerAliases.d.ts +0 -1
- package/types/scripts/serve.d.ts +0 -1
- package/types/scripts/start.d.ts +0 -1
- package/types/scripts/validator.d.ts +0 -9
- package/types/scripts/verifyConfig.d.ts +0 -1
- package/types/server/mainIndex.d.ts +0 -1
- package/types/server/mainServer.d.ts +0 -2
- package/types/server/renderer/document/Body.d.ts +0 -11
- package/types/server/renderer/document/Head.d.ts +0 -11
- package/types/server/renderer/document/index.d.ts +0 -2
- package/types/server/renderer/extract.d.ts +0 -18
- package/types/server/renderer/handler.d.ts +0 -6
- package/types/server/renderer/index.d.ts +0 -2
- package/types/server/renderer/render.d.ts +0 -38
- package/types/server/renderer/userAgentUtil.d.ts +0 -1
- package/types/store/index.d.ts +0 -11
- package/types/store/index.dev.d.ts +0 -8
- package/types/store/index.prod.d.ts +0 -8
- package/types/webpack/babel-plugins/remove-client.plugin.d.ts +0 -10
- package/types/webpack/babel-plugins/remove-ssr.plugin.d.ts +0 -10
- package/types/webpack/babel.config.client.d.ts +0 -21
- package/types/webpack/babel.config.d.ts +0 -16
- package/types/webpack/babel.config.ssr.d.ts +0 -21
- package/types/webpack/base.babel.d.ts +0 -184
- package/types/webpack/development.client.babel.d.ts +0 -1
- package/types/webpack/plugins/mime-types.d.ts +0 -78
- package/types/webpack/plugins/route-manifest-plugin.d.ts +0 -1
- package/types/webpack/plugins/upload-assets-plugin.d.ts +0 -1
- package/types/webpack/production.client.babel.d.ts +0 -174
- package/types/webpack/production.ssr.babel.d.ts +0 -2
- package/types/webpack/scssParams.d.ts +0 -2
package/.eslintignore
ADDED
package/.eslintrc
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
{
|
|
2
|
+
"parser": "@babel/eslint-parser",
|
|
3
|
+
"rules": {
|
|
4
|
+
"no-console": "error",
|
|
5
|
+
"react/prop-types": 1,
|
|
6
|
+
"react/display-name": [
|
|
7
|
+
0,
|
|
8
|
+
{
|
|
9
|
+
"ignoreTranspilerName": true
|
|
10
|
+
}
|
|
11
|
+
],
|
|
12
|
+
"react-hooks/exhaustive-deps": "error", // Checks effect dependencies
|
|
13
|
+
"no-prototype-builtins": "off",
|
|
14
|
+
"security/detect-possible-timing-attacks": "error",
|
|
15
|
+
"security/detect-child-process": "error",
|
|
16
|
+
"security/detect-eval-with-expression": "error",
|
|
17
|
+
"security/detect-new-buffer": "error",
|
|
18
|
+
"security/detect-no-csrf-before-method-override": "error",
|
|
19
|
+
"risxss/catch-potential-xss-react": [
|
|
20
|
+
"error",
|
|
21
|
+
{
|
|
22
|
+
"trustedLibraries": [
|
|
23
|
+
"@commonUtils"
|
|
24
|
+
]
|
|
25
|
+
}
|
|
26
|
+
],
|
|
27
|
+
"react/jsx-no-target-blank": [
|
|
28
|
+
0,
|
|
29
|
+
{
|
|
30
|
+
"enforceDynamicLinks": "never"
|
|
31
|
+
}
|
|
32
|
+
]
|
|
33
|
+
},
|
|
34
|
+
"env": {
|
|
35
|
+
"browser": true,
|
|
36
|
+
"es6": true,
|
|
37
|
+
"jest": true,
|
|
38
|
+
"node": true
|
|
39
|
+
},
|
|
40
|
+
"globals": {
|
|
41
|
+
"expect": true,
|
|
42
|
+
"__non_webpack_require__": true,
|
|
43
|
+
"logger": "readonly",
|
|
44
|
+
"AppCallbacks": "readonly"
|
|
45
|
+
},
|
|
46
|
+
"extends": [
|
|
47
|
+
"eslint:recommended",
|
|
48
|
+
"plugin:react/recommended"
|
|
49
|
+
],
|
|
50
|
+
"parserOptions": {
|
|
51
|
+
"sourceType": "module",
|
|
52
|
+
"ecmaFeatures": {
|
|
53
|
+
"experimentalObjectRestSpread": true,
|
|
54
|
+
"jsx": true
|
|
55
|
+
},
|
|
56
|
+
"babelOptions": {
|
|
57
|
+
"configFile": "./babel.config.json"
|
|
58
|
+
},
|
|
59
|
+
"ecmaVersion": 6
|
|
60
|
+
},
|
|
61
|
+
"plugins": [
|
|
62
|
+
"babel",
|
|
63
|
+
"react",
|
|
64
|
+
"react-hooks",
|
|
65
|
+
"security",
|
|
66
|
+
"risxss"
|
|
67
|
+
],
|
|
68
|
+
"settings": {
|
|
69
|
+
"react": {
|
|
70
|
+
"createClass": "createReactClass",
|
|
71
|
+
"pragma": "React",
|
|
72
|
+
"version": "detect"
|
|
73
|
+
},
|
|
74
|
+
"propWrapperFunctions": [
|
|
75
|
+
"forbidExtraProps",
|
|
76
|
+
{
|
|
77
|
+
"property": "freeze",
|
|
78
|
+
"object": "Object"
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
"property": "myFavoriteWrapper"
|
|
82
|
+
}
|
|
83
|
+
],
|
|
84
|
+
"linkComponents": [
|
|
85
|
+
"Hyperlink",
|
|
86
|
+
{
|
|
87
|
+
"name": "Link",
|
|
88
|
+
"linkAttribute": "to"
|
|
89
|
+
}
|
|
90
|
+
]
|
|
91
|
+
}
|
|
92
|
+
}
|
package/README.md
CHANGED
|
@@ -2,44 +2,53 @@
|
|
|
2
2
|
|
|
3
3
|
Frontend framework with server rendering support for web applications.
|
|
4
4
|
|
|
5
|
-
## Table of Contents
|
|
5
|
+
## Table of Contents
|
|
6
6
|
|
|
7
|
-
-
|
|
8
|
-
-
|
|
9
|
-
-
|
|
10
|
-
-
|
|
11
|
-
-
|
|
12
|
-
-
|
|
13
|
-
-
|
|
7
|
+
- Overview
|
|
8
|
+
- Installation
|
|
9
|
+
- Data Fetching with Catalyst
|
|
10
|
+
- serverFetcher
|
|
11
|
+
- clientFetcher
|
|
12
|
+
- refetch (for data revalidation)
|
|
13
|
+
- State Management
|
|
14
14
|
|
|
15
|
-
## Overview
|
|
15
|
+
## Overview
|
|
16
16
|
|
|
17
17
|
This package provides a way to proxy your request through your server. It allows you to cache your incoming request to improve your server response time.
|
|
18
18
|
|
|
19
|
+
## Installation
|
|
19
20
|
|
|
20
|
-
|
|
21
|
-
Run the following commands in the directory where you want to scaffold catalyst app.
|
|
21
|
+
**System Requirements**
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
if this steps fails, make sure .npmrc file exists and token used is a valid one.
|
|
23
|
+
- Node version 20.4.0 or later
|
|
24
|
+
- macOS and Linux are supported
|
|
28
25
|
|
|
29
|
-
|
|
26
|
+
**Automatic Installation**
|
|
30
27
|
|
|
31
|
-
|
|
28
|
+
- Run the following commands in the directory where you want to set up the Catalyst app.
|
|
32
29
|
|
|
33
|
-
After selecting options
|
|
34
30
|
```js
|
|
35
|
-
|
|
31
|
+
npx create-catalyst-app@latest
|
|
36
32
|
```
|
|
37
|
-
|
|
33
|
+
|
|
34
|
+
If successful, you will see the following prompts in your terminal.
|
|
35
|
+
|
|
36
|
+
- Enter the name of your Catalyst application.
|
|
37
|
+
- Choose state management.
|
|
38
|
+
- Once packages are installed,start the development server by running the following command.
|
|
39
|
+
|
|
38
40
|
```js
|
|
39
|
-
npm run start
|
|
41
|
+
cd project-name && npm run start
|
|
40
42
|
```
|
|
41
43
|
|
|
42
|
-
|
|
44
|
+
- Navigate to http://localhost:3005
|
|
45
|
+
|
|
46
|
+
The dev server should be running now.
|
|
47
|
+
|
|
48
|
+
Visit our official documentation:
|
|
49
|
+
https://catalyst.1mg.com/public_docs/content/installation
|
|
50
|
+
|
|
51
|
+
## Data Fetching with Catalyst
|
|
43
52
|
|
|
44
53
|
we have serverFetcher function for fetching with SSR and clientFetcher function for fetching during client side rendering and navigations.
|
|
45
54
|
|
|
@@ -48,18 +57,22 @@ we have serverFetcher function for fetching with SSR and clientFetcher function
|
|
|
48
57
|
server fetcher will get request, request params, search params and store (if project is setup with redux or rtk) as arguments. We can declare it as an async function and use await for fetching or use then chaining for data fetching.
|
|
49
58
|
|
|
50
59
|
if server fetcher is called for a route then client fetcher will not be called for that route, unless called with refetch.
|
|
60
|
+
|
|
51
61
|
```js
|
|
52
|
-
Home.serverFetcher = async ({ req,params,searchParams }, { store }) => {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
}
|
|
62
|
+
Home.serverFetcher = async ({ req, params, searchParams }, { store }) => {
|
|
63
|
+
store.dispatch(someAction())
|
|
64
|
+
const res = await fetch("some_url")
|
|
65
|
+
const json = await res.json()
|
|
66
|
+
return json
|
|
67
|
+
}
|
|
58
68
|
```
|
|
69
|
+
|
|
59
70
|
data returned from fetcher function will be accessible through useCurrentRouteData() hook provided by router.
|
|
71
|
+
|
|
60
72
|
```js
|
|
61
|
-
const [data,error,isFetched] = useCurrentRouteData()
|
|
73
|
+
const [data, error, isFetched] = useCurrentRouteData()
|
|
62
74
|
```
|
|
75
|
+
|
|
63
76
|
error and loading state would be handled by router.
|
|
64
77
|
|
|
65
78
|
**clientFetcher**
|
|
@@ -67,24 +80,25 @@ error and loading state would be handled by router.
|
|
|
67
80
|
client fetcher would be called on client side rendering and client side navigations. `store` would be available as a param in client side for dispatching redux/rtk actions.
|
|
68
81
|
|
|
69
82
|
```js
|
|
70
|
-
Home.clientFetcher = async ({route,location,params,searchParams,navigate},{store}) => {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
}
|
|
83
|
+
Home.clientFetcher = async ({ route, location, params, searchParams, navigate }, { store }) => {
|
|
84
|
+
store.dispatch(someAction())
|
|
85
|
+
const res = await fetch("some_url")
|
|
86
|
+
const json = await res.json()
|
|
87
|
+
return json
|
|
88
|
+
}
|
|
76
89
|
```
|
|
77
|
-
|
|
90
|
+
|
|
91
|
+
data returned from client fetcher function will be accessible through useCurrentRouteData() hook provided by router (hook for data access through client is same).
|
|
92
|
+
|
|
78
93
|
```js
|
|
79
|
-
const [data,error,isFetched] = useCurrentRouteData()
|
|
94
|
+
const [data, error, isFetched] = useCurrentRouteData()
|
|
80
95
|
```
|
|
81
96
|
|
|
82
|
-
|
|
83
97
|
**refetch (for data revalidation)**
|
|
84
98
|
|
|
85
99
|
refetch function can be used were we need to execute clientFetcher based on some condition(such as for infinite scroll or some state change inside container or onClick.)
|
|
86
100
|
|
|
87
|
-
We can pass arguments in refetch function which would
|
|
101
|
+
We can pass arguments in refetch function which would
|
|
88
102
|
|
|
89
103
|
```js
|
|
90
104
|
const [data,error,isFetched,refetch] = useCurrentRouteData()
|
|
@@ -94,20 +108,20 @@ useEffect(()=>{
|
|
|
94
108
|
},[arg])
|
|
95
109
|
|
|
96
110
|
clientFetcher = ({},{refetchArgument}) => {
|
|
97
|
-
|
|
111
|
+
|
|
98
112
|
const res = await api_call // refetchArg can be used as a param in api call
|
|
99
113
|
return res
|
|
100
114
|
}
|
|
101
115
|
|
|
102
116
|
```
|
|
103
117
|
|
|
104
|
-
|
|
105
118
|
## State Management
|
|
119
|
+
|
|
106
120
|
state management wrappers are defined in stateProvider.js file
|
|
107
121
|
|
|
108
122
|
store can be configured by manipulating store/index.js as per user requirements (custom middlewares etc can be added in this way.
|
|
109
123
|
|
|
110
|
-
initial state and request object would be provided in createStore function which will be called on server and client, we use the params to add additional arguments and middlewares in redux store.
|
|
124
|
+
initial state and request object would be provided in createStore function which will be called on server and client, we use the params to add additional arguments and middlewares in redux store.
|
|
111
125
|
|
|
112
126
|
```js
|
|
113
127
|
const configureStore = (initialState, cookies, requestObj, customHeaders) => {
|
|
@@ -129,4 +143,5 @@ export default configureStore
|
|
|
129
143
|
```
|
|
130
144
|
|
|
131
145
|
## Documentation
|
|
146
|
+
|
|
132
147
|
Visit https://catalyst.1mg.com to view the full documentation.
|
package/babel.config.json
CHANGED
|
@@ -10,11 +10,7 @@
|
|
|
10
10
|
],
|
|
11
11
|
"@babel/preset-react"
|
|
12
12
|
],
|
|
13
|
-
"plugins": [
|
|
14
|
-
"@babel/plugin-proposal-object-rest-spread",
|
|
15
|
-
"transform-class-properties",
|
|
16
|
-
"@loadable/babel-plugin"
|
|
17
|
-
],
|
|
13
|
+
"plugins": ["@loadable/babel-plugin"],
|
|
18
14
|
"env": {
|
|
19
15
|
"test": {
|
|
20
16
|
"presets": ["@babel/preset-react"]
|
package/bin/catalyst.js
CHANGED
|
@@ -1,41 +1,41 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
process.on(
|
|
4
|
-
throw err
|
|
5
|
-
})
|
|
6
|
-
const { spawnSync } = require(
|
|
7
|
-
const args = process.argv.slice(2)
|
|
2
|
+
"use strict"
|
|
3
|
+
process.on("unhandledRejection", (err) => {
|
|
4
|
+
throw err
|
|
5
|
+
})
|
|
6
|
+
const { spawnSync } = require("node:child_process")
|
|
7
|
+
const args = process.argv.slice(2)
|
|
8
8
|
const scriptIndex = args.findIndex(
|
|
9
|
-
|
|
10
|
-
)
|
|
11
|
-
const script = scriptIndex === -1 ? args[0] : args[scriptIndex]
|
|
12
|
-
const nodeArgs = scriptIndex > 0 ? args.slice(0, scriptIndex) : []
|
|
13
|
-
if ([
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
9
|
+
(x) => x === "build" || x === "start" || x === "serve" || x === "devBuild" || x === "devServe"
|
|
10
|
+
)
|
|
11
|
+
const script = scriptIndex === -1 ? args[0] : args[scriptIndex]
|
|
12
|
+
const nodeArgs = scriptIndex > 0 ? args.slice(0, scriptIndex) : []
|
|
13
|
+
if (["build", "start", "serve", "devBuild", "devServe"].includes(script)) {
|
|
14
|
+
const result = spawnSync(
|
|
15
|
+
process.execPath,
|
|
16
|
+
nodeArgs.concat(require.resolve("../scripts/" + script)).concat(args.slice(scriptIndex + 1)),
|
|
17
|
+
{ stdio: "inherit" }
|
|
18
|
+
)
|
|
19
|
+
if (result.signal) {
|
|
20
|
+
if (result.signal === "SIGKILL") {
|
|
21
|
+
/* eslint-disable no-console */
|
|
22
|
+
console.log(
|
|
23
|
+
"The build failed because the process exited too early. " +
|
|
24
|
+
"This probably means the system ran out of memory or someone called " +
|
|
25
|
+
"`kill -9` on the process."
|
|
26
|
+
)
|
|
27
|
+
} else if (result.signal === "SIGTERM") {
|
|
28
|
+
/* eslint-disable no-console */
|
|
29
|
+
console.log(
|
|
30
|
+
"The build failed because the process exited too early. " +
|
|
31
|
+
"Someone might have called `kill` or `killall`, or the system could " +
|
|
32
|
+
"be shutting down."
|
|
33
|
+
)
|
|
34
|
+
}
|
|
35
|
+
process.exit(1)
|
|
34
36
|
}
|
|
35
|
-
process.exit(
|
|
36
|
-
}
|
|
37
|
-
process.exit(result.status);
|
|
37
|
+
process.exit(result.status)
|
|
38
38
|
} else {
|
|
39
|
+
/* eslint-disable no-console */
|
|
39
40
|
console.log('Unknown script "' + script + '".');
|
|
40
|
-
console.log('Perhaps you need to update framework?');
|
|
41
41
|
}
|
package/changelog.md
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## [0.0.1-beta.4] - 05-08-2024
|
|
4
|
+
### Added
|
|
5
|
+
- Implemented dynamic metadata for nested routing.
|
|
6
|
+
- Dev build and dev serve configurations for a smoother development experience.([Refer documenatation](https://catalyst.1mg.com/public_docs/content/deployment))
|
|
7
|
+
- ESLint security rules for improved code security.
|
|
8
|
+
|
|
9
|
+
### Changed
|
|
10
|
+
- Security audit conducted on all packages.
|
|
11
|
+
- Removed Babel packages already included in the Babel preset.
|
|
12
|
+
- Updated router version to support nested routing. (0.0.1-beta.0 to 0.0.1-beta.1)
|
|
13
|
+
|
|
14
|
+
### Deprecated
|
|
15
|
+
- `metadataFunction` is deprecated and has been renamed to `setMetaData`.
|
|
16
|
+
|
|
17
|
+
### Removed
|
|
18
|
+
- Redundant Babel packages removed, reducing dependencies.
|
|
19
|
+
|
|
20
|
+
### Fixed
|
|
21
|
+
- Updated documentation to reflect the latest changes.
|
|
22
|
+
|
|
23
|
+
### Breaking Changes
|
|
24
|
+
- The `metadataFunction` has been renamed to `setMetaData`. Update your code accordingly.
|
|
25
|
+
- The `preparedRoutes` function now supports nested routing. Modify your routing setup to use this new functionality.
|
|
26
|
+
- For more information on handling these changes, please refer to the [migration guide](https://catalyst.1mg.com/content/migration_guide/0.0.1-beta.4) in the documentation.
|
package/config.json
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"cssModulesIdentifierDev": "[name]__[local]",
|
|
3
3
|
"cssModulesIdentifierProd": "[name]__[local]__[hash:base64:5]",
|
|
4
|
-
"analyzeBundle": false,
|
|
5
4
|
"chunkFileNameDev": "[name].bundle.js",
|
|
6
5
|
"chunkFileNameProd": "[name].[contenthash].js",
|
|
7
6
|
"cssChunkFileName": "[name].[contenthash].css"
|
|
8
|
-
}
|
|
7
|
+
}
|
package/{LICENSE → license}
RENAMED
|
@@ -6,4 +6,5 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
|
6
6
|
|
|
7
7
|
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
8
|
|
|
9
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
10
|
+
|
|
@@ -10,13 +10,13 @@ const {
|
|
|
10
10
|
} = winston;
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
|
-
* @description Logger library with rotational strategy. Creates a logs folder in root.
|
|
13
|
+
* @description Logger library with rotational strategy. Creates a logs folder in root.
|
|
14
14
|
* With debug, error and info log directories with their respective log files.
|
|
15
|
-
*
|
|
15
|
+
*
|
|
16
16
|
* @format Logstash with timestamp
|
|
17
17
|
* @param config { @enableDebugLogs: Bool // default: true }
|
|
18
18
|
* @returns loggerInstance
|
|
19
|
-
*
|
|
19
|
+
*
|
|
20
20
|
*/
|
|
21
21
|
const configureLogger = (config = {}) => {
|
|
22
22
|
const {
|
|
@@ -25,7 +25,7 @@ const configureLogger = (config = {}) => {
|
|
|
25
25
|
enableConsoleLogging = true
|
|
26
26
|
} = config;
|
|
27
27
|
const consoleTransport = new transports.Console({
|
|
28
|
-
level:
|
|
28
|
+
level: "debug"
|
|
29
29
|
});
|
|
30
30
|
const fileTransport = (type = "info") => {
|
|
31
31
|
return new DailyRotateFile({
|
|
@@ -39,7 +39,7 @@ const configureLogger = (config = {}) => {
|
|
|
39
39
|
};
|
|
40
40
|
const infoLogger = createLogger({
|
|
41
41
|
format: format.combine(format.timestamp({
|
|
42
|
-
format:
|
|
42
|
+
format: "YYYY-MM-DD HH:mm:ss"
|
|
43
43
|
}), format.json()),
|
|
44
44
|
defaultMeta: {
|
|
45
45
|
loglevel: "info"
|
|
@@ -47,7 +47,7 @@ const configureLogger = (config = {}) => {
|
|
|
47
47
|
});
|
|
48
48
|
const debugLogger = createLogger({
|
|
49
49
|
format: format.combine(format.timestamp({
|
|
50
|
-
format:
|
|
50
|
+
format: "YYYY-MM-DD HH:mm:ss"
|
|
51
51
|
}), format.json()),
|
|
52
52
|
defaultMeta: {
|
|
53
53
|
loglevel: "debug"
|
|
@@ -55,7 +55,7 @@ const configureLogger = (config = {}) => {
|
|
|
55
55
|
});
|
|
56
56
|
const errorLogger = createLogger({
|
|
57
57
|
format: format.combine(format.timestamp({
|
|
58
|
-
format:
|
|
58
|
+
format: "YYYY-MM-DD HH:mm:ss"
|
|
59
59
|
}), format.json()),
|
|
60
60
|
defaultMeta: {
|
|
61
61
|
loglevel: "error"
|
|
@@ -67,23 +67,26 @@ const configureLogger = (config = {}) => {
|
|
|
67
67
|
errorLogger.add(consoleTransport);
|
|
68
68
|
}
|
|
69
69
|
if (enableFileLogging && JSON.parse(enableFileLogging)) {
|
|
70
|
-
infoLogger.add(fileTransport(
|
|
71
|
-
debugLogger.add(fileTransport(
|
|
72
|
-
errorLogger.add(fileTransport(
|
|
70
|
+
infoLogger.add(fileTransport("info"));
|
|
71
|
+
debugLogger.add(fileTransport("debug"));
|
|
72
|
+
errorLogger.add(fileTransport("error"));
|
|
73
73
|
}
|
|
74
74
|
const Logger = {
|
|
75
75
|
debug: () => {},
|
|
76
76
|
error: msg => {
|
|
77
|
+
/* eslint-disable no-console */
|
|
77
78
|
console.log(pc.red(pc.bold("ERROR: " + JSON.stringify(msg))));
|
|
78
79
|
errorLogger.error(msg);
|
|
79
80
|
},
|
|
80
81
|
info: msg => {
|
|
82
|
+
/* eslint-disable no-console */
|
|
81
83
|
console.log(pc.green(pc.bold("INFO: " + JSON.stringify(msg))));
|
|
82
84
|
infoLogger.info(msg);
|
|
83
85
|
}
|
|
84
86
|
};
|
|
85
87
|
if (enableDebugLogs && JSON.parse(enableDebugLogs)) {
|
|
86
88
|
Logger.debug = msg => {
|
|
89
|
+
/* eslint-disable no-console */
|
|
87
90
|
console.log(pc.yellow(pc.bold("DEBUG: " + JSON.stringify(msg))));
|
|
88
91
|
debugLogger.debug(msg);
|
|
89
92
|
};
|