catalyst-core-internal 0.0.1-beta.37 → 0.0.1-beta.38
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/caching.js +1 -0
- package/index.js +1 -0
- package/logger.js +10 -0
- package/package.json +2 -2
- package/router.js +1 -0
- package/AssetsCache.js +0 -114
- package/run.sh +0 -4
package/caching.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});var _apiCaching=require("@tata1mg/api-caching");Object.keys(_apiCaching).forEach(function(key){if(key==="default"||key==="__esModule")return;if(key in exports&&exports[key]===_apiCaching[key])return;Object.defineProperty(exports,key,{enumerable:true,get:function(){return _apiCaching[key];}});});
|
package/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});var _index=require("./server/renderer/document/index");Object.keys(_index).forEach(function(key){if(key==="default"||key==="__esModule")return;if(key in exports&&exports[key]===_index[key])return;Object.defineProperty(exports,key,{enumerable:true,get:function(){return _index[key];}});});
|
package/logger.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";const winston=require("winston");const DailyRotateFile=require("winston-daily-rotate-file");const pc=require("picocolors");const{createLogger,format,transports}=winston;/**
|
|
2
|
+
* @description Logger library with rotational strategy. Creates a logs folder in root.
|
|
3
|
+
* With debug, error and info log directories with their respective log files.
|
|
4
|
+
*
|
|
5
|
+
* @format Logstash with timestamp
|
|
6
|
+
* @param config { @enableDebugLogs: Bool // default: true }
|
|
7
|
+
* @returns loggerInstance
|
|
8
|
+
*
|
|
9
|
+
*/const configureLogger=(config={})=>{const{enableDebugLogs=true,enableFileLogging=true,enableConsoleLogging=true}=config;const consoleTransport=new transports.Console({level:"debug"});const fileTransport=(type="info")=>{return new DailyRotateFile({filename:`${process.env.src_path}/logs/${type}/%DATE%.${type}.log`,datePattern:"YYYY-MM-DD",maxFiles:"3d",// Logs will be removed after 2days,
|
|
10
|
+
loglevel:type,level:type});};const infoLogger=createLogger({format:format.combine(format.timestamp({format:"YYYY-MM-DD HH:mm:ss"}),format.json()),defaultMeta:{loglevel:"info"}});const debugLogger=createLogger({format:format.combine(format.timestamp({format:"YYYY-MM-DD HH:mm:ss"}),format.json()),defaultMeta:{loglevel:"debug"}});const errorLogger=createLogger({format:format.combine(format.timestamp({format:"YYYY-MM-DD HH:mm:ss"}),format.json()),defaultMeta:{loglevel:"error"}});if(enableConsoleLogging&&JSON.parse(enableConsoleLogging)){infoLogger.add(consoleTransport);debugLogger.add(consoleTransport);errorLogger.add(consoleTransport);}if(enableFileLogging&&JSON.parse(enableFileLogging)){infoLogger.add(fileTransport("info"));debugLogger.add(fileTransport("debug"));errorLogger.add(fileTransport("error"));}const Logger={debug:()=>{},error:msg=>{console.log(pc.red(pc.bold("ERROR: "+JSON.stringify(msg))));errorLogger.error(msg);},info:msg=>{console.log(pc.green(pc.bold("INFO: "+JSON.stringify(msg))));infoLogger.info(msg);}};if(enableDebugLogs&&JSON.parse(enableDebugLogs)){Logger.debug=msg=>{console.log(pc.yellow(pc.bold("DEBUG: "+JSON.stringify(msg))));debugLogger.debug(msg);};}if(global)global.logger=Logger;return Logger;};module.exports={configureLogger};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "catalyst-core-internal",
|
|
3
|
-
"version": "0.0.1-beta.
|
|
3
|
+
"version": "0.0.1-beta.38",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"description": "Web framework that provides great performance out of the box",
|
|
6
6
|
"bin": {
|
|
@@ -109,4 +109,4 @@
|
|
|
109
109
|
"prettier . --write"
|
|
110
110
|
]
|
|
111
111
|
}
|
|
112
|
-
}
|
|
112
|
+
}
|
package/router.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});var _router=require("@tata1mg/router");Object.keys(_router).forEach(function(key){if(key==="default"||key==="__esModule")return;if(key in exports&&exports[key]===_router[key])return;Object.defineProperty(exports,key,{enumerable:true,get:function(){return _router[key];}});});
|
package/AssetsCache.js
DELETED
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
class AssetsCache {
|
|
2
|
-
constructor() {
|
|
3
|
-
this.cssCache = new Map()
|
|
4
|
-
this.preloadJSLinkCache = new Map()
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
async cacheCss(key, data) {
|
|
8
|
-
let pageCss = ""
|
|
9
|
-
let listOfCachedAssets = new Map()
|
|
10
|
-
if (Array.isArray(data)) {
|
|
11
|
-
try {
|
|
12
|
-
if (process.env.NODE_ENV === "production") {
|
|
13
|
-
data.map((assetChunk) => {
|
|
14
|
-
const assetPathArr = assetChunk.key.split("/")
|
|
15
|
-
const assetName = assetPathArr[assetPathArr.length - 1]
|
|
16
|
-
const ext = path.extname(assetName)
|
|
17
|
-
|
|
18
|
-
if (ext === ".css") {
|
|
19
|
-
// if css file has not already been cached, add the content of this CSS file in pageCSS
|
|
20
|
-
if (
|
|
21
|
-
!listOfCachedAssets.get(assetName) &&
|
|
22
|
-
!this.cssCache.get(key)?.listOfCachedAssets?.get(assetName)
|
|
23
|
-
) {
|
|
24
|
-
pageCss += fs.readFileSync(
|
|
25
|
-
path.resolve(
|
|
26
|
-
process.env.src_path,
|
|
27
|
-
`${process.env.BUILD_OUTPUT_PATH}/public`,
|
|
28
|
-
assetName
|
|
29
|
-
)
|
|
30
|
-
)
|
|
31
|
-
listOfCachedAssets.set(assetName, true)
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
})
|
|
35
|
-
} else {
|
|
36
|
-
const cssRequests = data.map((file) => {
|
|
37
|
-
const ext = path.extname(file.key)
|
|
38
|
-
if (ext === ".css") {
|
|
39
|
-
return getAssetFromWebpackDevServer(file.key)
|
|
40
|
-
}
|
|
41
|
-
})
|
|
42
|
-
const resolvedCss = await Promise.all(cssRequests)
|
|
43
|
-
resolvedCss.forEach((cssContent) => {
|
|
44
|
-
pageCss += cssContent
|
|
45
|
-
})
|
|
46
|
-
}
|
|
47
|
-
} catch (error) {
|
|
48
|
-
if (process.env.NODE_ENV == "development") {
|
|
49
|
-
console.log(
|
|
50
|
-
"Error While Extracting The Chunk: ",
|
|
51
|
-
path.resolve(process.env.src_path, `${process.env.BUILD_OUTPUT_PATH}/public`)
|
|
52
|
-
)
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
// if css cache exists for a route and there are some uncached css, add that css to the cache
|
|
57
|
-
// this will run on subsequent hits and will add css of uncached widgets to the cache
|
|
58
|
-
if (process.cssCache[key]) {
|
|
59
|
-
if (pageCss !== "") {
|
|
60
|
-
let existingListOfCachedAssets = process.cssCache[key].listOfCachedAssets
|
|
61
|
-
const newPageCSS = process.cssCache[key].pageCss + pageCss
|
|
62
|
-
let newListOfCachedAssets = { ...existingListOfCachedAssets, ...listOfCachedAssets }
|
|
63
|
-
process.cssCache[key] = { pageCss: newPageCSS, listOfCachedAssets: newListOfCachedAssets }
|
|
64
|
-
}
|
|
65
|
-
} else {
|
|
66
|
-
// create css cache for a page. This will run on the first hit.
|
|
67
|
-
this.cssCache.set(key, { pageCss, listOfCachedAssets })
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
fetchCss(key) {
|
|
72
|
-
return this.cssCache.get(key).pageCss
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
cachePreloadJSLinks(key, data) {
|
|
76
|
-
let preloadJSLinks = []
|
|
77
|
-
if (Array.isArray(data)) {
|
|
78
|
-
try {
|
|
79
|
-
preloadJSLinks = data.filter((asset) => asset?.props?.as === "script")
|
|
80
|
-
} catch (error) {
|
|
81
|
-
console.dir({
|
|
82
|
-
service_name: `pwa-${process.env.APPLICATION}-node-server`,
|
|
83
|
-
loglevel: "error",
|
|
84
|
-
version: "v2",
|
|
85
|
-
message: "\n \n =====> Error While Extracting The Chunk: \n ",
|
|
86
|
-
traceback: error,
|
|
87
|
-
})
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
console.dir({
|
|
91
|
-
service_name: "pwa-node-server",
|
|
92
|
-
loglevel: "info",
|
|
93
|
-
version: "v2",
|
|
94
|
-
message: `\n========= Cached For preloadJSLinkCache: ${key} ============\n`,
|
|
95
|
-
})
|
|
96
|
-
this.preloadJSLinkCache.set(key, preloadJSLinks)
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
fetchPreloadJSLinks(key) {
|
|
100
|
-
return this.preloadJSLinkCache.get(key)
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
async getAssetFromWebpackDevServer(assetPath = "") {
|
|
104
|
-
try {
|
|
105
|
-
if (process.env.NODE_ENV !== "production") {
|
|
106
|
-
const response = await fetch(assetPath)
|
|
107
|
-
const textContent = await response.text()
|
|
108
|
-
return textContent
|
|
109
|
-
}
|
|
110
|
-
} catch (error) {
|
|
111
|
-
console.log("Unable to fetch asset from webpack dev server", error)
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
}
|
package/run.sh
DELETED