catalyst-core-internal 0.0.1-beta.2 → 0.0.1-beta.21
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 +91 -0
- package/.husky/commit-msg +1 -0
- package/.husky/pre-commit +1 -0
- package/README.md +45 -43
- package/babel.config.json +2 -5
- package/bin/catalyst.js +33 -35
- package/caching.js +1 -16
- package/changelog.md +12 -0
- package/commitlint.config.js +11 -0
- package/config.json +1 -1
- package/index.js +1 -16
- package/license +10 -0
- package/logger.js +3 -89
- package/package.json +89 -83
- package/router/ClientRouter.js +2 -18
- package/router/ServerRouter.js +1 -19
- package/router.js +1 -16
- package/scripts/build.js +9 -28
- package/scripts/checkVersion.js +1 -5
- package/scripts/devBuild.js +10 -0
- package/scripts/devServe.js +5 -0
- package/scripts/loadEnvironmentVariables.js +4 -23
- package/scripts/loadScriptsBeforeServerStarts.js +5 -47
- package/scripts/resiterAliases.js +29 -0
- package/scripts/scriptUtils.js +2 -0
- package/scripts/serve.js +4 -29
- package/scripts/start.js +5 -25
- package/scripts/validator.js +1 -130
- package/server/expressServer.js +8 -49
- package/server/renderer/document/Body.js +6 -28
- package/server/renderer/document/Head.js +5 -39
- package/server/renderer/document/index.js +1 -27
- package/server/renderer/extract.js +6 -72
- package/server/renderer/handler.js +14 -241
- package/server/renderer/index.js +1 -12
- package/server/renderer/render.js +8 -60
- package/server/startServer.js +6 -65
- package/server/utils/userAgentUtil.js +3 -49
- package/server/utils/validator.js +1 -130
- package/webpack/babel-plugins/remove-client.plugin.js +3 -29
- package/webpack/babel-plugins/remove-ssr.plugin.js +3 -19
- package/webpack/babel.config.client.js +1 -24
- package/webpack/babel.config.ssr.js +1 -24
- package/webpack/base.babel.js +8 -167
- package/webpack/development.client.babel.js +4 -82
- package/webpack/production.client.babel.js +4 -78
- package/webpack/production.ssr.babel.js +4 -61
- package/webpack/scssParams.js +5 -31
- 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/catalyst/src/router.js +0 -1
- package/packages/create-framework-app/templates/redux-js/node_modules/http-proxy-middleware/dist/router.js +0 -46
- package/router/index.js +0 -32
- package/scripts/prepare.js +0 -19
- package/scripts/registerAliases.js +0 -30
- package/server/mainIndex.js +0 -65
- package/server/mainServer.js +0 -70
- package/server/renderer/userAgentUtil.js +0 -55
- 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/webpack/babel.config.js +0 -20
- package/webpack/plugins/mime-types.js +0 -82
- package/webpack/plugins/route-manifest-copy.js +0 -122
- package/webpack/plugins/route-manifest-plugin.js +0 -122
- package/webpack/plugins/upload-assets-plugin.js +0 -181
package/scripts/validator.js
CHANGED
|
@@ -1,130 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const pc = require("picocolors");
|
|
4
|
-
const handleError = e => {
|
|
5
|
-
console.log(pc.red("Failed to start server: "), e);
|
|
6
|
-
};
|
|
7
|
-
const validatePreInitServer = fn => {
|
|
8
|
-
try {
|
|
9
|
-
if (!fn) throw new Error("preServerInit named function should be defined in server/index.js");
|
|
10
|
-
if (typeof fn !== "function") throw new Error("preServerInit should be function present in server/index.js");
|
|
11
|
-
return true;
|
|
12
|
-
} catch (e) {
|
|
13
|
-
handleError(e);
|
|
14
|
-
}
|
|
15
|
-
};
|
|
16
|
-
const validateMiddleware = fn => {
|
|
17
|
-
try {
|
|
18
|
-
if (!fn) throw new Error("addMiddlewares named function not found in server/server.js");
|
|
19
|
-
if (typeof fn !== "function") throw new Error("addMiddlewares should be function present in server/server.js");
|
|
20
|
-
return true;
|
|
21
|
-
} catch (e) {
|
|
22
|
-
handleError(e);
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
|
-
const validateReducerFunction = fn => {
|
|
26
|
-
try {
|
|
27
|
-
if (!fn) throw new Error("reducer not found in src/js/containers/App/reducer");
|
|
28
|
-
if (typeof fn !== "function") throw new Error("reducer should present in src/js/containers/App/reducer");
|
|
29
|
-
return true;
|
|
30
|
-
} catch (e) {
|
|
31
|
-
handleError(e);
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
const validateConfigFile = obj => {
|
|
35
|
-
try {
|
|
36
|
-
if (!obj) throw new Error("config not found in config folder");
|
|
37
|
-
if (typeof obj !== "object") throw new Error("config object should be exported from config folder inside your project root directory");
|
|
38
|
-
if (typeof obj === "object") {
|
|
39
|
-
const requiredConfigKeys = {
|
|
40
|
-
NODE_SERVER_HOSTNAME: "",
|
|
41
|
-
NODE_SERVER_PORT: "",
|
|
42
|
-
WEBPACK_DEV_SERVER_HOSTNAME: "",
|
|
43
|
-
WEBPACK_DEV_SERVER_PORT: "",
|
|
44
|
-
BUILD_OUTPUT_PATH: "",
|
|
45
|
-
PUBLIC_STATIC_ASSET_PATH: "",
|
|
46
|
-
PUBLIC_STATIC_ASSET_URL: "",
|
|
47
|
-
NODE_ENV: "",
|
|
48
|
-
BUILD_ENV: "",
|
|
49
|
-
CLIENT_ENV_VARIABLES: [],
|
|
50
|
-
ANALYZE_BUNDLE: ""
|
|
51
|
-
};
|
|
52
|
-
for (let key in requiredConfigKeys) {
|
|
53
|
-
if (!(key in obj)) throw new Error(`${key} key not found inside config.json`);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
return true;
|
|
57
|
-
} catch (e) {
|
|
58
|
-
handleError(e);
|
|
59
|
-
}
|
|
60
|
-
};
|
|
61
|
-
const validatePackageJson = obj => {
|
|
62
|
-
try {
|
|
63
|
-
if (!obj) throw new Error("package.json not found in the project");
|
|
64
|
-
if (typeof obj !== "object") throw new Error("package.json should be defined in project root directory");
|
|
65
|
-
return true;
|
|
66
|
-
} catch (e) {
|
|
67
|
-
handleError(e);
|
|
68
|
-
}
|
|
69
|
-
};
|
|
70
|
-
const validateModuleAlias = obj => {
|
|
71
|
-
try {
|
|
72
|
-
if (!obj) throw new Error("moduleAliases not found in package.json file present in root directory.");
|
|
73
|
-
if (typeof obj !== "object") throw new Error("moduleAliases named object should be exported from package.json");
|
|
74
|
-
if (typeof obj === "object") {
|
|
75
|
-
const requiredModuleAliases = {
|
|
76
|
-
"@api": "api.js",
|
|
77
|
-
"@containers": "src/js/containers",
|
|
78
|
-
"@server": "server",
|
|
79
|
-
"@config": "config",
|
|
80
|
-
"@css": "src/static/css",
|
|
81
|
-
"@routes": "src/js/routes/",
|
|
82
|
-
"@store": "src/js/store/index.js"
|
|
83
|
-
};
|
|
84
|
-
for (let key in requiredModuleAliases) {
|
|
85
|
-
if (!(key in obj)) throw new Error(`${key} module alias not defined inside package.json`);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
return true;
|
|
89
|
-
} catch (e) {
|
|
90
|
-
handleError(e);
|
|
91
|
-
}
|
|
92
|
-
};
|
|
93
|
-
const validateConfigureStore = fn => {
|
|
94
|
-
try {
|
|
95
|
-
if (!fn) throw new Error("configureStore not found in file src/js/store/index.js");
|
|
96
|
-
if (typeof fn !== "function") throw new Error("configureStore should be function exported from src/js/store/index.js");
|
|
97
|
-
return true;
|
|
98
|
-
} catch (e) {
|
|
99
|
-
handleError(e);
|
|
100
|
-
}
|
|
101
|
-
};
|
|
102
|
-
const validateGetRoutes = fn => {
|
|
103
|
-
try {
|
|
104
|
-
if (!fn) throw new Error("getRoutes not found in file src/js/routes/utils.js");
|
|
105
|
-
if (typeof fn !== "function") throw new Error("getRoutes should be function exported from src/js/routers/index.js");
|
|
106
|
-
return true;
|
|
107
|
-
} catch (e) {
|
|
108
|
-
handleError(e);
|
|
109
|
-
}
|
|
110
|
-
};
|
|
111
|
-
const validateCustomDocument = fn => {
|
|
112
|
-
try {
|
|
113
|
-
if (!fn) throw new Error("document not found in file server/document.js");
|
|
114
|
-
if (typeof fn !== "function") throw new Error("document should be a react component exported from server/document.js");
|
|
115
|
-
return true;
|
|
116
|
-
} catch (e) {
|
|
117
|
-
handleError(e);
|
|
118
|
-
}
|
|
119
|
-
};
|
|
120
|
-
module.exports = {
|
|
121
|
-
validateConfigFile,
|
|
122
|
-
validateConfigureStore,
|
|
123
|
-
validateCustomDocument,
|
|
124
|
-
validateGetRoutes,
|
|
125
|
-
validatePackageJson,
|
|
126
|
-
validateReducerFunction,
|
|
127
|
-
validateModuleAlias,
|
|
128
|
-
validatePreInitServer,
|
|
129
|
-
validateMiddleware
|
|
130
|
-
};
|
|
1
|
+
"use strict";const pc=require("picocolors");const handleError=e=>{console.log(pc.red("Failed to start server: "),e);};const validatePreInitServer=fn=>{try{if(!fn)throw new Error("preServerInit named function should be defined in server/index.js");if(typeof fn!=="function")throw new Error("preServerInit should be function present in server/index.js");return true;}catch(e){handleError(e);}};const validateMiddleware=fn=>{try{if(!fn)throw new Error("addMiddlewares named function not found in server/server.js");if(typeof fn!=="function")throw new Error("addMiddlewares should be function present in server/server.js");return true;}catch(e){handleError(e);}};const validateReducerFunction=fn=>{try{if(!fn)throw new Error("reducer not found in src/js/containers/App/reducer");if(typeof fn!=="function")throw new Error("reducer should present in src/js/containers/App/reducer");return true;}catch(e){handleError(e);}};const validateConfigFile=obj=>{try{if(!obj)throw new Error("config not found in config folder");if(typeof obj!=="object")throw new Error("config object should be exported from config folder inside your project root directory");if(typeof obj==="object"){const requiredConfigKeys={NODE_SERVER_HOSTNAME:"",NODE_SERVER_PORT:"",WEBPACK_DEV_SERVER_HOSTNAME:"",WEBPACK_DEV_SERVER_PORT:"",BUILD_OUTPUT_PATH:"",PUBLIC_STATIC_ASSET_PATH:"",PUBLIC_STATIC_ASSET_URL:"",CLIENT_ENV_VARIABLES:[],ANALYZE_BUNDLE:""};for(let key in requiredConfigKeys){if(!(key in obj))throw new Error(`${key} key not found inside config.json`);}}return true;}catch(e){handleError(e);}};const validatePackageJson=obj=>{try{if(!obj)throw new Error("package.json not found in the project");if(typeof obj!=="object")throw new Error("package.json should be defined in project root directory");return true;}catch(e){handleError(e);}};const validateModuleAlias=obj=>{try{if(!obj)throw new Error("moduleAliases not found in package.json file present in root directory.");if(typeof obj!=="object")throw new Error("moduleAliases named object should be exported from package.json");if(typeof obj==="object"){const requiredModuleAliases={"@api":"api.js","@containers":"src/js/containers","@server":"server","@config":"config","@css":"src/static/css","@routes":"src/js/routes/"};for(let key in requiredModuleAliases){if(!(key in obj))throw new Error(`${key} module alias not defined inside package.json`);}}return true;}catch(e){handleError(e);}};const validateConfigureStore=fn=>{try{if(!fn)throw new Error("configureStore not found in file src/js/store/index.js");if(typeof fn!=="function")throw new Error("configureStore should be function exported from src/js/store/index.js");return true;}catch(e){handleError(e);}};const validateGetRoutes=fn=>{try{if(!fn)throw new Error("getRoutes not found in file src/js/routes/utils.js");if(typeof fn!=="function")throw new Error("getRoutes should be function exported from src/js/routers/index.js");return true;}catch(e){handleError(e);}};const validateCustomDocument=fn=>{try{if(!fn)throw new Error("document not found in file server/document.js");if(typeof fn!=="function")throw new Error("document should be a react component exported from server/document.js");return true;}catch(e){handleError(e);}};module.exports={validateConfigFile,validateConfigureStore,validateCustomDocument,validateGetRoutes,validatePackageJson,validateReducerFunction,validateModuleAlias,validatePreInitServer,validateMiddleware};
|
package/server/expressServer.js
CHANGED
|
@@ -1,50 +1,9 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
var _path = _interopRequireDefault(require("path"));
|
|
8
|
-
var _express = _interopRequireDefault(require("express"));
|
|
9
|
-
var _bodyParser = _interopRequireDefault(require("body-parser"));
|
|
10
|
-
var _compression = _interopRequireDefault(require("compression"));
|
|
11
|
-
var _cookieParser = _interopRequireDefault(require("cookie-parser"));
|
|
12
|
-
var _expressStaticGzip = _interopRequireDefault(require("express-static-gzip"));
|
|
13
|
-
var _renderer = _interopRequireDefault(require("./renderer"));
|
|
14
|
-
var _server = require("@server/server.js");
|
|
15
|
-
var _validator = require("./utils/validator");
|
|
16
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
17
|
-
const env = process.env.NODE_ENV || "development";
|
|
18
|
-
const app = (0, _express.default)();
|
|
19
|
-
|
|
20
|
-
// This middleware is being used to extract the body of the request
|
|
21
|
-
app.use(_bodyParser.default.json());
|
|
22
|
-
|
|
23
|
-
// This middleware has been added to accommodate “byetstream array”
|
|
24
|
-
app.use(_bodyParser.default.raw({
|
|
25
|
-
type: "application/*"
|
|
26
|
-
}));
|
|
27
|
-
|
|
28
|
-
// This middleware is being used to parse cookies!
|
|
29
|
-
app.use((0, _cookieParser.default)());
|
|
30
|
-
|
|
31
|
-
// All the middlewares defined by the user will run here.
|
|
32
|
-
if ((0, _validator.validateMiddleware)(_server.addMiddlewares)) (0, _server.addMiddlewares)(app);
|
|
33
|
-
|
|
34
|
-
// The middleware will attempt to compress response bodies for all request that traverse through the middleware
|
|
35
|
-
app.use((0, _compression.default)());
|
|
36
|
-
|
|
37
|
-
// This endpoint will serve the built assets from the node server. The requests will be made to PUBLIC_STATIC_ASSET_PATH which has been defined in the application config.
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.default=void 0;var _path=_interopRequireDefault(require("path"));var _express=_interopRequireDefault(require("express"));var _bodyParser=_interopRequireDefault(require("body-parser"));var _compression=_interopRequireDefault(require("compression"));var _cookieParser=_interopRequireDefault(require("cookie-parser"));var _expressStaticGzip=_interopRequireDefault(require("express-static-gzip"));var _renderer=_interopRequireDefault(require("./renderer"));var _server=require("@server/server.js");var _validator=require("./utils/validator");function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj};}const env=process.env.NODE_ENV||"development";const app=(0,_express.default)();// This middleware is being used to extract the body of the request
|
|
2
|
+
app.use(_bodyParser.default.json());// This middleware has been added to accommodate “byetstream array”
|
|
3
|
+
app.use(_bodyParser.default.raw({type:"application/*"}));// This middleware is being used to parse cookies!
|
|
4
|
+
app.use((0,_cookieParser.default)());// All the middlewares defined by the user will run here.
|
|
5
|
+
if((0,_validator.validateMiddleware)(_server.addMiddlewares))(0,_server.addMiddlewares)(app);// The middleware will attempt to compress response bodies for all request that traverse through the middleware
|
|
6
|
+
app.use((0,_compression.default)());// This endpoint will serve the built assets from the node server. The requests will be made to PUBLIC_STATIC_ASSET_PATH which has been defined in the application config.
|
|
38
7
|
// expressStaticGzip will compress the assets.
|
|
39
|
-
if
|
|
40
|
-
|
|
41
|
-
enableBrotli: true,
|
|
42
|
-
orderPreference: ["br", "gzip", "deflate"]
|
|
43
|
-
}));
|
|
44
|
-
} else {
|
|
45
|
-
app.use(process.env.PUBLIC_STATIC_ASSET_PATH, _express.default.static(_path.default.join(process.env.src_path, `./${process.env.BUILD_OUTPUT_PATH}/public`)));
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
// This middleware handles document requests.
|
|
49
|
-
app.use("*", _renderer.default);
|
|
50
|
-
var _default = exports.default = app;
|
|
8
|
+
if(env==="production"){app.use(process.env.PUBLIC_STATIC_ASSET_PATH,(0,_expressStaticGzip.default)(_path.default.join(process.env.src_path,`./${process.env.BUILD_OUTPUT_PATH}/public`),{enableBrotli:true,orderPreference:["br","gzip","deflate"]}));}else{app.use(process.env.PUBLIC_STATIC_ASSET_PATH,_express.default.static(_path.default.join(process.env.src_path,`./${process.env.BUILD_OUTPUT_PATH}/public`)));}// This middleware handles document requests.
|
|
9
|
+
app.use("*",_renderer.default);var _default=exports.default=app;
|
|
@@ -1,36 +1,14 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.Body = Body;
|
|
7
|
-
var _react = _interopRequireDefault(require("react"));
|
|
8
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
9
|
-
/**
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.Body=Body;var _react=_interopRequireDefault(require("react"));var _propTypes=_interopRequireDefault(require("prop-types"));function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj};}/**
|
|
10
2
|
* Body component which will be used in page component
|
|
3
|
+
* @param {object} jsx - page jsx code
|
|
4
|
+
* @param {object} statusCode - document request status code
|
|
11
5
|
* @param {object} initialState - initial state object for redux store
|
|
12
6
|
* @param {object} firstFoldCss - style elements extracted for initial page load
|
|
13
7
|
* @param {object} firstFoldJS - javascript elements extracted for initial page load
|
|
14
|
-
* @param {object} jsx - page jsx code
|
|
15
|
-
* @param {object} statusCode - document request status code
|
|
16
8
|
* @param {object} fetcherData - contains data from executing serverFetcher function
|
|
17
|
-
|
|
18
|
-
function Body(props) {
|
|
19
|
-
const {
|
|
20
|
-
initialState = {},
|
|
21
|
-
statusCode = "",
|
|
22
|
-
firstFoldCss = "",
|
|
23
|
-
firstFoldJS = "",
|
|
24
|
-
jsx = "",
|
|
25
|
-
fetcherData = {}
|
|
26
|
-
} = props;
|
|
27
|
-
return /*#__PURE__*/_react.default.createElement("body", null, firstFoldCss, firstFoldJS, jsx, /*#__PURE__*/_react.default.createElement("script", {
|
|
28
|
-
dangerouslySetInnerHTML: {
|
|
29
|
-
__html: `
|
|
9
|
+
* @param {object} children - contains any child elements defined within the component
|
|
10
|
+
*/function Body(props){const{jsx="",statusCode="",initialState={},firstFoldCss="",firstFoldJS="",fetcherData={},children}=props;return/*#__PURE__*/_react.default.createElement("body",null,firstFoldCss,firstFoldJS,jsx,/*#__PURE__*/_react.default.createElement("script",{/* eslint-disable */dangerouslySetInnerHTML:{__html:`
|
|
30
11
|
window.__INITIAL_STATE__ = ${JSON.stringify(initialState)}
|
|
31
12
|
window.__STATUS_CODE__ = ${statusCode}
|
|
32
13
|
window.__ROUTER_INITIAL_DATA__ = ${JSON.stringify(fetcherData)}
|
|
33
|
-
`
|
|
34
|
-
}
|
|
35
|
-
}), props.children);
|
|
36
|
-
}
|
|
14
|
+
`}}),children);}Body.propTypes={initialState:_propTypes.default.object,firstFoldCss:_propTypes.default.any,firstFoldJS:_propTypes.default.any,jsx:_propTypes.default.any,statusCode:_propTypes.default.string,fetcherData:_propTypes.default.object,children:_propTypes.default.node};
|
|
@@ -1,43 +1,9 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.Head = Head;
|
|
7
|
-
var _react = _interopRequireDefault(require("react"));
|
|
8
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
9
|
-
/**
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.Head=Head;var _react=_interopRequireDefault(require("react"));var _propTypes=_interopRequireDefault(require("prop-types"));function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj};}/**
|
|
10
2
|
* Head component which will be used in page rendering
|
|
3
|
+
* @param {boolean} isBot - checks if request is made by bot
|
|
11
4
|
* @param {string} pageCss - includes all styles for page css
|
|
12
5
|
* @param {object} pageJS - async scripts for loading chunks
|
|
13
|
-
* @param {
|
|
14
|
-
* @param {boolean} isBot - checks if request is made by bot
|
|
6
|
+
* @param {array} metaTags - user defined function which returns meta tags in array
|
|
15
7
|
* @param {string} publicAssetPath - public asset path for assets
|
|
16
|
-
* @param {object}
|
|
17
|
-
*/
|
|
18
|
-
function Head(props) {
|
|
19
|
-
const {
|
|
20
|
-
pageCss,
|
|
21
|
-
pageJS,
|
|
22
|
-
metaTagFunction,
|
|
23
|
-
isBot,
|
|
24
|
-
publicAssetPath,
|
|
25
|
-
fetcherData
|
|
26
|
-
} = props;
|
|
27
|
-
return /*#__PURE__*/_react.default.createElement("head", null, /*#__PURE__*/_react.default.createElement("meta", {
|
|
28
|
-
charSet: "utf-8"
|
|
29
|
-
}), /*#__PURE__*/_react.default.createElement("meta", {
|
|
30
|
-
name: "viewport",
|
|
31
|
-
content: "width=device-width, initial-scale=1"
|
|
32
|
-
}), publicAssetPath && /*#__PURE__*/_react.default.createElement("link", {
|
|
33
|
-
rel: "preconnect",
|
|
34
|
-
href: publicAssetPath
|
|
35
|
-
}), publicAssetPath && /*#__PURE__*/_react.default.createElement("link", {
|
|
36
|
-
rel: "dns-prefetch",
|
|
37
|
-
href: publicAssetPath
|
|
38
|
-
}), metaTagFunction && metaTagFunction(fetcherData), !isBot && pageJS, !isBot && /*#__PURE__*/_react.default.createElement("style", {
|
|
39
|
-
dangerouslySetInnerHTML: {
|
|
40
|
-
__html: pageCss
|
|
41
|
-
}
|
|
42
|
-
}), props.children);
|
|
43
|
-
}
|
|
8
|
+
* @param {object} children - contains any child elements defined within the component
|
|
9
|
+
*/function Head(props){const{pageCss,pageJS,metaTags,isBot,publicAssetPath,children}=props;return/*#__PURE__*/_react.default.createElement("head",null,/*#__PURE__*/_react.default.createElement("meta",{charSet:"utf-8"}),/*#__PURE__*/_react.default.createElement("meta",{name:"viewport",content:"width=device-width, initial-scale=1"}),publicAssetPath&&/*#__PURE__*/_react.default.createElement("link",{rel:"preconnect",href:publicAssetPath}),publicAssetPath&&/*#__PURE__*/_react.default.createElement("link",{rel:"dns-prefetch",href:publicAssetPath}),metaTags&&metaTags,!isBot&&pageJS,!isBot&&pageCss&&/*#__PURE__*/_react.default.createElement("style",{dangerouslySetInnerHTML:{__html:pageCss}}),children);}Head.propTypes={isBot:_propTypes.default.bool,pageJS:_propTypes.default.object,pageCss:_propTypes.default.string,metaTags:_propTypes.default.array,publicAssetPath:_propTypes.default.string,children:_propTypes.default.node};
|
|
@@ -1,27 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
var _Head = require("./Head");
|
|
7
|
-
Object.keys(_Head).forEach(function (key) {
|
|
8
|
-
if (key === "default" || key === "__esModule") return;
|
|
9
|
-
if (key in exports && exports[key] === _Head[key]) return;
|
|
10
|
-
Object.defineProperty(exports, key, {
|
|
11
|
-
enumerable: true,
|
|
12
|
-
get: function () {
|
|
13
|
-
return _Head[key];
|
|
14
|
-
}
|
|
15
|
-
});
|
|
16
|
-
});
|
|
17
|
-
var _Body = require("./Body");
|
|
18
|
-
Object.keys(_Body).forEach(function (key) {
|
|
19
|
-
if (key === "default" || key === "__esModule") return;
|
|
20
|
-
if (key in exports && exports[key] === _Body[key]) return;
|
|
21
|
-
Object.defineProperty(exports, key, {
|
|
22
|
-
enumerable: true,
|
|
23
|
-
get: function () {
|
|
24
|
-
return _Body[key];
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
});
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});var _Head=require("./Head");Object.keys(_Head).forEach(function(key){if(key==="default"||key==="__esModule")return;if(key in exports&&exports[key]===_Head[key])return;Object.defineProperty(exports,key,{enumerable:true,get:function(){return _Head[key];}});});var _Body=require("./Body");Object.keys(_Body).forEach(function(key){if(key==="default"||key==="__esModule")return;if(key in exports&&exports[key]===_Body[key])return;Object.defineProperty(exports,key,{enumerable:true,get:function(){return _Body[key];}});});
|
|
@@ -1,87 +1,21 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.cacheCSS = cacheCSS;
|
|
7
|
-
exports.cacheJS = cacheJS;
|
|
8
|
-
exports.default = _default;
|
|
9
|
-
var _path = _interopRequireDefault(require("path"));
|
|
10
|
-
var _fs = _interopRequireDefault(require("fs"));
|
|
11
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
12
|
-
/**
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.cacheCSS=cacheCSS;exports.cacheJS=cacheJS;exports.default=_default;var _path=_interopRequireDefault(require("path"));var _fs=_interopRequireDefault(require("fs"));function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj};}/**
|
|
13
2
|
* Stores css chunks styles into cache in string format
|
|
14
3
|
* @param {string} key - router path
|
|
15
4
|
* @param {object} data - css elements array extracted through loadable chunk extracter
|
|
16
|
-
*/
|
|
17
|
-
function cacheCSS(key, data) {
|
|
18
|
-
if (!process.cssCache) {
|
|
19
|
-
process.cssCache = {};
|
|
20
|
-
}
|
|
21
|
-
let pageCss = "";
|
|
22
|
-
if (Array.isArray(data)) {
|
|
23
|
-
try {
|
|
24
|
-
data.map(assetChunk => {
|
|
25
|
-
const assetPathArr = assetChunk.key.split("/");
|
|
26
|
-
const assetName = assetPathArr[assetPathArr.length - 1];
|
|
27
|
-
const ext = _path.default.extname(assetName);
|
|
28
|
-
if (ext === ".css") pageCss += _fs.default.readFileSync(_path.default.resolve(process.env.src_path, `${process.env.BUILD_OUTPUT_PATH}/public`, assetName));
|
|
29
|
-
});
|
|
30
|
-
} catch (error) {
|
|
31
|
-
if (process.env.NODE_ENV == "development") {
|
|
32
|
-
console.log("Error While Extracting The Chunk: ", _path.default.resolve(process.env.src_path, `${process.env.BUILD_OUTPUT_PATH}/public`, assetName));
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
process.cssCache[key] = pageCss;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
5
|
+
*/function cacheCSS(key,data){if(!process.cssCache){process.cssCache={};}let pageCss="";if(Array.isArray(data)){try{data.map(assetChunk=>{const assetPathArr=assetChunk.key.split("/");const assetName=assetPathArr[assetPathArr.length-1];const ext=_path.default.extname(assetName);if(ext===".css")pageCss+=_fs.default.readFileSync(_path.default.resolve(process.env.src_path,`${process.env.BUILD_OUTPUT_PATH}/public`,assetName));});}catch(error){if(process.env.NODE_ENV=="development"){console.log("Error While Extracting The Chunk: ",_path.default.resolve(process.env.src_path,`${process.env.BUILD_OUTPUT_PATH}/public`));}}}process.cssCache[key]=pageCss;}/**
|
|
40
6
|
* Stores javascript into cache
|
|
41
7
|
* @param {string} key - router path
|
|
42
8
|
* @param {object} data - js elements array extracted through loadable chunk extracter
|
|
43
|
-
*/
|
|
44
|
-
function cacheJS(key, data) {
|
|
45
|
-
if (!process.jsCache) {
|
|
46
|
-
process.jsCache = {};
|
|
47
|
-
}
|
|
48
|
-
process.jsCache[key] = data;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
9
|
+
*/function cacheJS(key,data){if(!process.jsCache){process.jsCache={};}process.jsCache[key]=data;}/**
|
|
52
10
|
* returns cached css
|
|
53
11
|
* @param {string} key - router path
|
|
54
12
|
* @return {string} - cached css
|
|
55
|
-
*/
|
|
56
|
-
function fetchCachedCSS(key) {
|
|
57
|
-
return process.cssCache && process.cssCache[key] ? process.cssCache[key] : null;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/**
|
|
13
|
+
*/function fetchCachedCSS(key){return process.cssCache&&process.cssCache[key]?process.cssCache[key]:null;}/**
|
|
61
14
|
* returns cached js
|
|
62
15
|
* @param {string} key - router path
|
|
63
16
|
* @return {string} - cached js
|
|
64
|
-
*/
|
|
65
|
-
function fetchCachedJS(key) {
|
|
66
|
-
return process.jsCache && process.jsCache[key] ? process.jsCache[key] : null;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/**
|
|
17
|
+
*/function fetchCachedJS(key){return process.jsCache&&process.jsCache[key]?process.jsCache[key]:null;}/**
|
|
70
18
|
* stores css and js in cache
|
|
71
19
|
* @param {object} res - response object
|
|
72
20
|
* @param {string} route - route path
|
|
73
|
-
*/
|
|
74
|
-
function _default(res, route) {
|
|
75
|
-
try {
|
|
76
|
-
const requestPath = route.path;
|
|
77
|
-
const cachedCss = fetchCachedCSS(requestPath);
|
|
78
|
-
const cachedJS = fetchCachedJS(requestPath);
|
|
79
|
-
if (cachedCss || cachedJS) {
|
|
80
|
-
res.locals.pageJS = cachedJS;
|
|
81
|
-
res.locals.pageCss = cachedCss;
|
|
82
|
-
return;
|
|
83
|
-
}
|
|
84
|
-
} catch (error) {
|
|
85
|
-
console.log("Error while caching your assets.");
|
|
86
|
-
}
|
|
87
|
-
}
|
|
21
|
+
*/function _default(res,route){try{const requestPath=route.path;const cachedCss=fetchCachedCSS(requestPath);const cachedJS=fetchCachedJS(requestPath);if(cachedCss||cachedJS){res.locals.pageJS=cachedJS;res.locals.pageCss=cachedCss;return;}}catch(error){console.log("Error while caching your assets.");}}
|