catalyst-core 0.0.1-beta.2 → 0.0.1-beta.3
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 +26 -13
- package/bin/catalyst.js +2 -3
- package/config.json +0 -1
- package/{LICENSE → license} +2 -1
- package/{logger/index.js → logger.js} +10 -10
- package/package.json +17 -19
- package/packages/create-framework-app/templates/redux-js/node_modules/catalyst/src/router.js +1 -0
- package/router/ClientRouter.js +10 -6
- package/router/ServerRouter.js +2 -11
- package/scripts/build.js +10 -4
- package/scripts/checkVersion.js +5 -0
- package/scripts/loadEnvironmentVariables.js +8 -21
- package/scripts/loadScriptsBeforeServerStarts.js +12 -20
- package/scripts/serve.js +11 -4
- package/scripts/start.js +2 -4
- package/scripts/validator.js +40 -11
- package/server/expressServer.js +50 -0
- package/server/renderer/document/Body.js +17 -18
- package/server/renderer/document/Head.js +6 -7
- package/server/renderer/document/index.js +2 -0
- package/server/renderer/extract.js +25 -24
- package/server/renderer/handler.js +212 -188
- package/server/renderer/index.js +6 -7
- package/server/renderer/render.js +21 -19
- package/server/startServer.js +65 -0
- package/server/utils/userAgentUtil.js +55 -0
- package/server/utils/validator.js +40 -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 +2 -2
- package/webpack/base.babel.js +29 -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 +19 -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/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
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
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.
|
|
38
|
+
// expressStaticGzip will compress the assets.
|
|
39
|
+
if (env === "production") {
|
|
40
|
+
app.use(process.env.PUBLIC_STATIC_ASSET_PATH, (0, _expressStaticGzip.default)(_path.default.join(process.env.src_path, `./${process.env.BUILD_OUTPUT_PATH}/public`), {
|
|
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;
|
|
@@ -4,33 +4,32 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.Body = Body;
|
|
7
|
-
var _react = require("react");
|
|
8
|
-
var _react2 = _interopRequireDefault(_react);
|
|
7
|
+
var _react = _interopRequireDefault(require("react"));
|
|
9
8
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
10
9
|
/**
|
|
11
10
|
* Body component which will be used in page component
|
|
12
|
-
* @param {object} initialState - redux store
|
|
13
|
-
* @param {object}
|
|
14
|
-
* @param {object}
|
|
15
|
-
* @param {object}
|
|
16
|
-
* @param {object}
|
|
17
|
-
* @param {object} fetcherData -
|
|
11
|
+
* @param {object} initialState - initial state object for redux store
|
|
12
|
+
* @param {object} firstFoldCss - style elements extracted for initial page load
|
|
13
|
+
* @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
|
+
* @param {object} fetcherData - contains data from executing serverFetcher function
|
|
18
17
|
*/
|
|
19
18
|
function Body(props) {
|
|
20
19
|
const {
|
|
21
|
-
initialState,
|
|
22
|
-
statusCode,
|
|
23
|
-
firstFoldCss,
|
|
24
|
-
firstFoldJS,
|
|
25
|
-
jsx,
|
|
26
|
-
fetcherData
|
|
20
|
+
initialState = {},
|
|
21
|
+
statusCode = "",
|
|
22
|
+
firstFoldCss = "",
|
|
23
|
+
firstFoldJS = "",
|
|
24
|
+
jsx = "",
|
|
25
|
+
fetcherData = {}
|
|
27
26
|
} = props;
|
|
28
|
-
return /*#__PURE__*/
|
|
27
|
+
return /*#__PURE__*/_react.default.createElement("body", null, firstFoldCss, firstFoldJS, jsx, /*#__PURE__*/_react.default.createElement("script", {
|
|
29
28
|
dangerouslySetInnerHTML: {
|
|
30
29
|
__html: `
|
|
31
|
-
window.__INITIAL_STATE__ = ${JSON.stringify(initialState)}
|
|
32
|
-
window.__STATUS_CODE__ = ${statusCode}
|
|
33
|
-
window.__ROUTER_INITIAL_DATA__ = ${JSON.stringify(fetcherData)}
|
|
30
|
+
window.__INITIAL_STATE__ = ${JSON.stringify(initialState)}
|
|
31
|
+
window.__STATUS_CODE__ = ${statusCode}
|
|
32
|
+
window.__ROUTER_INITIAL_DATA__ = ${JSON.stringify(fetcherData)}
|
|
34
33
|
`
|
|
35
34
|
}
|
|
36
35
|
}), props.children);
|
|
@@ -4,8 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.Head = Head;
|
|
7
|
-
var _react = require("react");
|
|
8
|
-
var _react2 = _interopRequireDefault(_react);
|
|
7
|
+
var _react = _interopRequireDefault(require("react"));
|
|
9
8
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
10
9
|
/**
|
|
11
10
|
* Head component which will be used in page rendering
|
|
@@ -25,18 +24,18 @@ function Head(props) {
|
|
|
25
24
|
publicAssetPath,
|
|
26
25
|
fetcherData
|
|
27
26
|
} = props;
|
|
28
|
-
return /*#__PURE__*/
|
|
27
|
+
return /*#__PURE__*/_react.default.createElement("head", null, /*#__PURE__*/_react.default.createElement("meta", {
|
|
29
28
|
charSet: "utf-8"
|
|
30
|
-
}), /*#__PURE__*/
|
|
29
|
+
}), /*#__PURE__*/_react.default.createElement("meta", {
|
|
31
30
|
name: "viewport",
|
|
32
31
|
content: "width=device-width, initial-scale=1"
|
|
33
|
-
}), publicAssetPath && /*#__PURE__*/
|
|
32
|
+
}), publicAssetPath && /*#__PURE__*/_react.default.createElement("link", {
|
|
34
33
|
rel: "preconnect",
|
|
35
34
|
href: publicAssetPath
|
|
36
|
-
}), publicAssetPath && /*#__PURE__*/
|
|
35
|
+
}), publicAssetPath && /*#__PURE__*/_react.default.createElement("link", {
|
|
37
36
|
rel: "dns-prefetch",
|
|
38
37
|
href: publicAssetPath
|
|
39
|
-
}), metaTagFunction && metaTagFunction(fetcherData), !isBot && pageJS, !isBot && /*#__PURE__*/
|
|
38
|
+
}), metaTagFunction && metaTagFunction(fetcherData), !isBot && pageJS, !isBot && /*#__PURE__*/_react.default.createElement("style", {
|
|
40
39
|
dangerouslySetInnerHTML: {
|
|
41
40
|
__html: pageCss
|
|
42
41
|
}
|
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
var _Head = require("./Head");
|
|
7
7
|
Object.keys(_Head).forEach(function (key) {
|
|
8
8
|
if (key === "default" || key === "__esModule") return;
|
|
9
|
+
if (key in exports && exports[key] === _Head[key]) return;
|
|
9
10
|
Object.defineProperty(exports, key, {
|
|
10
11
|
enumerable: true,
|
|
11
12
|
get: function () {
|
|
@@ -16,6 +17,7 @@ Object.keys(_Head).forEach(function (key) {
|
|
|
16
17
|
var _Body = require("./Body");
|
|
17
18
|
Object.keys(_Body).forEach(function (key) {
|
|
18
19
|
if (key === "default" || key === "__esModule") return;
|
|
20
|
+
if (key in exports && exports[key] === _Body[key]) return;
|
|
19
21
|
Object.defineProperty(exports, key, {
|
|
20
22
|
enumerable: true,
|
|
21
23
|
get: function () {
|
|
@@ -5,24 +5,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.cacheCSS = cacheCSS;
|
|
7
7
|
exports.cacheJS = cacheJS;
|
|
8
|
-
exports.default =
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const cachedCss = fetchCachedCSS(requestPath);
|
|
12
|
-
const cachedJS = fetchCachedJS(requestPath);
|
|
13
|
-
if (cachedCss || cachedJS) {
|
|
14
|
-
res.locals.pageJS = cachedJS;
|
|
15
|
-
res.locals.pageCss = cachedCss;
|
|
16
|
-
return;
|
|
17
|
-
}
|
|
18
|
-
} catch (error) {
|
|
19
|
-
console.log("Error while reading lodable stats:");
|
|
20
|
-
}
|
|
21
|
-
};
|
|
22
|
-
var _path = require("path");
|
|
23
|
-
var _path2 = _interopRequireDefault(_path);
|
|
24
|
-
var _fs = require("fs");
|
|
25
|
-
var _fs2 = _interopRequireDefault(_fs);
|
|
8
|
+
exports.default = _default;
|
|
9
|
+
var _path = _interopRequireDefault(require("path"));
|
|
10
|
+
var _fs = _interopRequireDefault(require("fs"));
|
|
26
11
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
27
12
|
/**
|
|
28
13
|
* Stores css chunks styles into cache in string format
|
|
@@ -39,11 +24,13 @@ function cacheCSS(key, data) {
|
|
|
39
24
|
data.map(assetChunk => {
|
|
40
25
|
const assetPathArr = assetChunk.key.split("/");
|
|
41
26
|
const assetName = assetPathArr[assetPathArr.length - 1];
|
|
42
|
-
const ext =
|
|
43
|
-
if (ext === ".css") pageCss +=
|
|
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));
|
|
44
29
|
});
|
|
45
30
|
} catch (error) {
|
|
46
|
-
|
|
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
|
+
}
|
|
47
34
|
}
|
|
48
35
|
}
|
|
49
36
|
process.cssCache[key] = pageCss;
|
|
@@ -64,7 +51,7 @@ function cacheJS(key, data) {
|
|
|
64
51
|
/**
|
|
65
52
|
* returns cached css
|
|
66
53
|
* @param {string} key - router path
|
|
67
|
-
* @return {string} - cached css
|
|
54
|
+
* @return {string} - cached css
|
|
68
55
|
*/
|
|
69
56
|
function fetchCachedCSS(key) {
|
|
70
57
|
return process.cssCache && process.cssCache[key] ? process.cssCache[key] : null;
|
|
@@ -73,7 +60,7 @@ function fetchCachedCSS(key) {
|
|
|
73
60
|
/**
|
|
74
61
|
* returns cached js
|
|
75
62
|
* @param {string} key - router path
|
|
76
|
-
* @return {string} - cached js
|
|
63
|
+
* @return {string} - cached js
|
|
77
64
|
*/
|
|
78
65
|
function fetchCachedJS(key) {
|
|
79
66
|
return process.jsCache && process.jsCache[key] ? process.jsCache[key] : null;
|
|
@@ -83,4 +70,18 @@ function fetchCachedJS(key) {
|
|
|
83
70
|
* stores css and js in cache
|
|
84
71
|
* @param {object} res - response object
|
|
85
72
|
* @param {string} route - route path
|
|
86
|
-
*/
|
|
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
|
+
}
|