catalyst-core 0.0.1-beta.4 → 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.
Files changed (58) hide show
  1. package/.eslintignore +5 -5
  2. package/.eslintrc +0 -1
  3. package/.husky/commit-msg +1 -0
  4. package/.husky/pre-commit +1 -0
  5. package/babel.config.json +1 -0
  6. package/bin/catalyst.js +1 -4
  7. package/caching.js +1 -16
  8. package/changelog.md +5 -19
  9. package/commitlint.config.js +11 -0
  10. package/index.js +1 -16
  11. package/logger.js +3 -92
  12. package/package.json +89 -87
  13. package/router/ClientRouter.js +2 -18
  14. package/router/ServerRouter.js +1 -19
  15. package/router.js +1 -16
  16. package/scripts/build.js +9 -41
  17. package/scripts/checkVersion.js +1 -5
  18. package/scripts/devBuild.js +9 -41
  19. package/scripts/devServe.js +4 -42
  20. package/scripts/loadEnvironmentVariables.js +4 -23
  21. package/scripts/loadScriptsBeforeServerStarts.js +5 -47
  22. package/scripts/resiterAliases.js +29 -0
  23. package/scripts/scriptUtils.js +2 -0
  24. package/scripts/serve.js +4 -42
  25. package/scripts/start.js +5 -34
  26. package/scripts/validator.js +1 -127
  27. package/server/expressServer.js +8 -49
  28. package/server/renderer/document/Body.js +6 -28
  29. package/server/renderer/document/Head.js +5 -39
  30. package/server/renderer/document/index.js +1 -27
  31. package/server/renderer/extract.js +6 -72
  32. package/server/renderer/handler.js +14 -237
  33. package/server/renderer/index.js +1 -12
  34. package/server/renderer/render.js +8 -71
  35. package/server/startServer.js +6 -66
  36. package/server/utils/userAgentUtil.js +3 -45
  37. package/server/utils/validator.js +1 -127
  38. package/webpack/babel-plugins/remove-client.plugin.js +3 -29
  39. package/webpack/babel-plugins/remove-ssr.plugin.js +3 -19
  40. package/webpack/babel.config.client.js +1 -24
  41. package/webpack/babel.config.ssr.js +1 -24
  42. package/webpack/base.babel.js +8 -175
  43. package/webpack/development.client.babel.js +4 -85
  44. package/webpack/production.client.babel.js +4 -78
  45. package/webpack/production.ssr.babel.js +4 -61
  46. package/webpack/scssParams.js +5 -47
  47. package/router/index.js +0 -32
  48. package/scripts/prepare.js +0 -19
  49. package/scripts/registerAliases.js +0 -30
  50. package/server/mainIndex.js +0 -65
  51. package/server/mainServer.js +0 -70
  52. package/server/renderer/userAgentUtil.js +0 -55
  53. package/server/utils/metaTags.js +0 -13
  54. package/webpack/babel.config.js +0 -20
  55. package/webpack/plugins/mime-types.js +0 -82
  56. package/webpack/plugins/route-manifest-copy.js +0 -122
  57. package/webpack/plugins/route-manifest-plugin.js +0 -122
  58. package/webpack/plugins/upload-assets-plugin.js +0 -181
@@ -1,61 +1,4 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
- var _webpackNodeExternals = _interopRequireDefault(require("webpack-node-externals"));
8
- var _path = _interopRequireDefault(require("path"));
9
- var _base = _interopRequireDefault(require("./base.babel"));
10
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
- const {
12
- mergeWithCustomize,
13
- customizeArray,
14
- customizeObject
15
- } = require("webpack-merge");
16
- const rootWorkspacePath = require("app-root-path");
17
- const catalystConfig = require(_path.default.resolve(__dirname, "..", "config.json"));
18
- const plugins = require(_path.default.join(process.env.src_path, "webpackConfig.js"));
19
- const ssrConfig = mergeWithCustomize({
20
- customizeArray: customizeArray({
21
- entry: "replace",
22
- optimization: "replace",
23
- plugins: "prepend"
24
- }),
25
- customizeObject: customizeObject({
26
- entry: "replace",
27
- optimization: "replace",
28
- plugins: "prepend"
29
- })
30
- })(_base.default, {
31
- mode: "production",
32
- optimization: {
33
- splitChunks: {
34
- chunks: "all",
35
- minSize: 10000000,
36
- name: false
37
- }
38
- },
39
- plugins: [...plugins.ssrPlugins],
40
- target: "node",
41
- entry: {
42
- handler: _path.default.resolve(__dirname, "..", "./server/renderer/handler.js")
43
- },
44
- externals: [
45
- // images are handled by isomorphic webpack.
46
- // html files are required directly
47
- /\.(html|png|gif|jpg)$/,
48
- // treat all node modules as external to keep this bundle small
49
- (0, _webpackNodeExternals.default)({
50
- modulesDir: _path.default.resolve(process.env.src_path, "./node_modules")
51
- }), (0, _webpackNodeExternals.default)({
52
- modulesDir: _path.default.join(rootWorkspacePath.path, "./node_modules")
53
- })],
54
- output: {
55
- path: _path.default.join(process.env.src_path, process.env.BUILD_OUTPUT_PATH, "/renderer"),
56
- chunkFilename: catalystConfig.chunkFileNameProd,
57
- filename: "handler.js",
58
- libraryTarget: "commonjs"
59
- }
60
- });
61
- var _default = exports.default = ssrConfig;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.default=void 0;var _webpackNodeExternals=_interopRequireDefault(require("webpack-node-externals"));var _path=_interopRequireDefault(require("path"));var _base=_interopRequireDefault(require("./base.babel"));function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj};}const{mergeWithCustomize,customizeArray,customizeObject}=require("webpack-merge");const rootWorkspacePath=require("app-root-path");const catalystConfig=require(_path.default.resolve(__dirname,"..","config.json"));const plugins=require(_path.default.join(process.env.src_path,"webpackConfig.js"));const ssrConfig=mergeWithCustomize({customizeArray:customizeArray({entry:"replace",optimization:"replace",plugins:"prepend"}),customizeObject:customizeObject({entry:"replace",optimization:"replace",plugins:"prepend"})})(_base.default,{mode:"production",stats:"errors-only",optimization:{splitChunks:{chunks:"all",minSize:10000000,name:false}},plugins:[...plugins.ssrPlugins],target:"node",entry:{handler:_path.default.resolve(__dirname,"..","./server/renderer/handler.js")},externals:[// images are handled by isomorphic webpack.
2
+ // html files are required directly
3
+ /\.(html|png|gif|jpg)$/,// treat all node modules as external to keep this bundle small
4
+ (0,_webpackNodeExternals.default)({modulesDir:_path.default.resolve(process.env.src_path,"./node_modules")}),(0,_webpackNodeExternals.default)({modulesDir:_path.default.join(rootWorkspacePath.path,"./node_modules")})],output:{path:_path.default.join(process.env.src_path,process.env.BUILD_OUTPUT_PATH,"/renderer"),chunkFilename:catalystConfig.chunkFileNameProd,filename:"handler.js",libraryTarget:"commonjs"}});var _default=exports.default=ssrConfig;
@@ -1,51 +1,9 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.imageUrl = exports.fontUrl = void 0;
7
- /**
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.imageUrl=exports.fontUrl=void 0;/**
8
2
  * @description generate assets url according to enviorment
9
3
  * @returns returns path required for loading assets according to enviorment
10
- */
11
- const imageUrl = () => {
12
- const {
13
- PUBLIC_STATIC_ASSET_URL,
14
- PUBLIC_STATIC_ASSET_PATH,
15
- IS_DEV_COMMAND,
16
- NODE_SERVER_HOSTNAME,
17
- NODE_SERVER_PORT
18
- } = process.env;
19
- let publicPath = `${PUBLIC_STATIC_ASSET_URL}${PUBLIC_STATIC_ASSET_PATH}`;
20
-
21
- // serves assets from localhost on running devBuild and devServe command
22
- if (JSON.parse(IS_DEV_COMMAND)) {
23
- publicPath = `http://${NODE_SERVER_HOSTNAME}:${NODE_SERVER_PORT}/${PUBLIC_STATIC_ASSET_PATH}`;
24
- }
25
- const imagePath = JSON.stringify(`${publicPath}images/`);
26
- return imagePath;
27
- };
28
-
29
- /**
4
+ */const imageUrl=()=>{const{PUBLIC_STATIC_ASSET_URL,PUBLIC_STATIC_ASSET_PATH,IS_DEV_COMMAND,NODE_SERVER_HOSTNAME,NODE_SERVER_PORT}=process.env;let publicPath=`${PUBLIC_STATIC_ASSET_URL}${PUBLIC_STATIC_ASSET_PATH}`;// serves assets from localhost on running devBuild and devServe command
5
+ if(JSON.parse(IS_DEV_COMMAND)){publicPath=`http://${NODE_SERVER_HOSTNAME}:${NODE_SERVER_PORT}/${PUBLIC_STATIC_ASSET_PATH}`;}const imagePath=JSON.stringify(`${publicPath}images/`);return imagePath;};/**
30
6
  * @description generate assets font url according to enviorment
31
7
  * @returns returns path required for loading fonts according to enviorment
32
- */
33
- exports.imageUrl = imageUrl;
34
- const fontUrl = () => {
35
- const {
36
- PUBLIC_STATIC_ASSET_URL,
37
- PUBLIC_STATIC_ASSET_PATH,
38
- IS_DEV_COMMAND,
39
- NODE_SERVER_HOSTNAME,
40
- NODE_SERVER_PORT
41
- } = process.env;
42
- let publicPath = `${PUBLIC_STATIC_ASSET_URL}${PUBLIC_STATIC_ASSET_PATH}`;
43
-
44
- // serves assets from localhost on running devBuild and devServe command
45
- if (JSON.parse(IS_DEV_COMMAND)) {
46
- publicPath = `http://${NODE_SERVER_HOSTNAME}:${NODE_SERVER_PORT}/${PUBLIC_STATIC_ASSET_PATH}`;
47
- }
48
- const fontPath = JSON.stringify(`${publicPath}fonts/`);
49
- return fontPath;
50
- };
51
- exports.fontUrl = fontUrl;
8
+ */exports.imageUrl=imageUrl;const fontUrl=()=>{const{PUBLIC_STATIC_ASSET_URL,PUBLIC_STATIC_ASSET_PATH,IS_DEV_COMMAND,NODE_SERVER_HOSTNAME,NODE_SERVER_PORT}=process.env;let publicPath=`${PUBLIC_STATIC_ASSET_URL}${PUBLIC_STATIC_ASSET_PATH}`;// serves assets from localhost on running devBuild and devServe command
9
+ if(JSON.parse(IS_DEV_COMMAND)){publicPath=`http://${NODE_SERVER_HOSTNAME}:${NODE_SERVER_PORT}/${PUBLIC_STATIC_ASSET_PATH}`;}const fontPath=JSON.stringify(`${publicPath}fonts/`);return fontPath;};exports.fontUrl=fontUrl;
package/router/index.js DELETED
@@ -1,32 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.preparedRoutes = exports.default = void 0;
7
- var _react = _interopRequireDefault(require("react"));
8
- var _validator = require("../scripts/validator.js");
9
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
10
- const {
11
- default: routes
12
- } = require(`${process.env.src_path}src/js/routes/index.js`);
13
- /**
14
- * @description prepares routes from routes defined inside template.
15
- * Adds path and element key inside each route.
16
- * @returns returns routes list after modifiing template routes
17
- */
18
-
19
- const getRoutes = (0, _validator.validateGetRoutes)(routes) ? routes : [];
20
- const preparedRoutes = () => {
21
- return getRoutes()?.map((route, index) => {
22
- const Component = route.element;
23
- return {
24
- path: route.path,
25
- element: /*#__PURE__*/_react.default.createElement(Component, {
26
- key: index
27
- })
28
- };
29
- });
30
- };
31
- exports.preparedRoutes = preparedRoutes;
32
- var _default = exports.default = getRoutes;
@@ -1,19 +0,0 @@
1
- "use strict";
2
-
3
- const {
4
- spawnSync
5
- } = require("child_process");
6
- const path = require("path");
7
-
8
- /**
9
- * @description - it creates build and generate types requried for function definations.
10
- */
11
- function prepare() {
12
- console.log("Running prepare....");
13
- const dirname = path.resolve(__dirname, "../");
14
- spawnSync("npm", ["run", "prepare"], {
15
- cwd: dirname,
16
- stdio: 'inherit'
17
- });
18
- }
19
- prepare();
@@ -1,30 +0,0 @@
1
- "use strict";
2
-
3
- var _path = _interopRequireDefault(require("path"));
4
- var _moduleAlias = _interopRequireDefault(require("module-alias"));
5
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
6
- const pjp = process.env.src_path + `/package.json`;
7
- const cfg = `${process.env.src_path}/config/config`;
8
- // const config = require(cfg)
9
- // const { _moduleAliases } = require(pjp)
10
- const config = require(`${process.env.src_path}/config/config`);
11
- const {
12
- _moduleAliases
13
- } = require(`${process.env.src_path}/package.json`);
14
-
15
- // Add module aliases, but for server aliases (prefix by the `$` symbol), change
16
- // the directory to match the current build directory (e.g. /dist)
17
- // This ensures that all alises are properly referencing the babel-built
18
- // server files
19
- _moduleAlias.default.addAliases(Object.keys(_moduleAliases || []).reduce((resultMap, aliasName) => {
20
- const aliasPath = _moduleAliases[aliasName];
21
- const sym = aliasName[0];
22
- if (sym === "$") {
23
- resultMap[aliasName] = _path.default.join(process.env.src_path, aliasPath.split("/").slice(1).join("/"));
24
- } else if (aliasPath.includes("templates")) {
25
- resultMap[aliasName] = _path.default.join(process.env.src_path, aliasPath);
26
- } else {
27
- resultMap[aliasName] = _path.default.join(process.env.src_path, aliasPath);
28
- }
29
- return resultMap;
30
- }, {}));
@@ -1,65 +0,0 @@
1
- "use strict";
2
-
3
- var _index = require("$server/index.js");
4
- var _mainServer = require("./mainServer.js");
5
- var _mainServer2 = _interopRequireDefault(_mainServer);
6
- var _validator = require("./utils/validator.js");
7
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
8
- // import("../scripts/registerAliases.js")
9
- const env = process.env.NODE_ENV || "development";
10
- // function defined on user which needs to be run before server starts
11
- if ((0, _validator.validatePreInitServer)(_index.preServerInit)) (0, _index.preServerInit)();
12
- process.on("uncaughtException", (err, origin) => {
13
- console.log(">>>>", process.stderr.fd);
14
- console.log(`Caught exception: ${err}\n` + `Exception origin: ${origin}`);
15
- });
16
- process.on("SIGINT", function (data) {
17
- console.log("SIGINT");
18
- console.log(data);
19
- process.exit(0);
20
- });
21
- process.on("uncaughtExceptionMonitor", (err, origin) => {
22
- console.log(">>>>>", err, origin);
23
- });
24
- process.on("message", function (msg) {
25
- if (msg == "shutdown") {
26
- console.log("Closing all connections...");
27
- setTimeout(function () {
28
- console.log("Finished closing connections");
29
- process.exit(0);
30
- }, 1500);
31
- }
32
- });
33
- process.loadableConfig = {
34
- CLIENT_ONLY_RENDER: process.env["CLIENT_ONLY_RENDER"] === "true",
35
- SERVER_SIDE_RENDER: process.env["SERVER_SIDE_RENDER"] === "true"
36
- };
37
- if (env === "development") {
38
- // In development, we compile css-modules on the fly on the server. This is
39
- // not necessary in production since we build renderer and server files with
40
- // webpack and babel.
41
- // import("css-modules-require-hook").then((methods) => {
42
- // console.log(">>>>css-modules")
43
- // methods.default({
44
- // extensions: [".scss"],
45
- // generateScopedName: "[name]__[local]",
46
- // devMode: true,
47
- // })
48
- // })
49
- // Add better stack tracing for promises in dev mode
50
- process.on("unhandledRejection", r => console.debug(r));
51
- }
52
- const port = process.env.PORT || process.env.APPLICATION_PORT || 3000;
53
- const host = env === "development" ? "localhost" : process.env.DEV_SERVER_HOSTNAME;
54
- // import("./server.js").then((server) => {
55
- _mainServer2.default.listen(port, error => {
56
- if (error) {
57
- console.log("Server Starting Error");
58
- } else {
59
- console.log(`Application server mounted on http://${host}:${port}.`);
60
- }
61
- });
62
-
63
- // })
64
-
65
- /* eslint-enable */
@@ -1,70 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- var _path = require("path");
7
- var _path2 = _interopRequireDefault(_path);
8
- var _express = require("express");
9
- var _express2 = _interopRequireDefault(_express);
10
- var _bodyParser = require("body-parser");
11
- var _bodyParser2 = _interopRequireDefault(_bodyParser);
12
- var _compression = require("compression");
13
- var _compression2 = _interopRequireDefault(_compression);
14
- var _cookieParser = require("cookie-parser");
15
- var _cookieParser2 = _interopRequireDefault(_cookieParser);
16
- var _expressStaticGzip = require("express-static-gzip");
17
- var _expressStaticGzip2 = _interopRequireDefault(_expressStaticGzip);
18
- var _renderer = require("./renderer");
19
- var _renderer2 = _interopRequireDefault(_renderer);
20
- var _server = require("$server/server.js");
21
- var _validator = require("./utils/validator");
22
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
23
- const env = process.env.NODE_ENV || "development";
24
- const app = (0, _express2.default)();
25
-
26
- //Use-case: We are using body-parser here for widget-factory,
27
- //we need to extract the body of request which Native will hit at our end.
28
- app.use(_bodyParser2.default.json());
29
-
30
- // This change is added to accommodate “byetstream array”
31
- // which is octet-stream format coming from android!
32
- app.use(_bodyParser2.default.raw({
33
- type: "application/*"
34
- }));
35
-
36
- // parse cookies!
37
- app.use((0, _cookieParser2.default)());
38
-
39
- // Apply custom midlewares
40
- if ((0, _validator.validateMiddleware)(_server.addMiddlewares)) (0, _server.addMiddlewares)(app);
41
-
42
- // gzip
43
- app.use((0, _compression2.default)());
44
-
45
- // We upload the assets on our s3 bucket and serve them through our CDN.
46
- // However if our CDN is down all we have to do is change the PUBLIC_ASSET_PATH in basecamp
47
- // to "node_server_ip/assets" (Example: http://13.127.237.229:8443/assets) to serve the assets from our node server.
48
- // When we make production builds on our local system we change the PUBLIC_ASSET_PATH to "http://localhost:3005/assets/".
49
- // In this case all the asset requests are made to the node server running on our local system and are served locally.
50
- if (env === "production") {
51
- app.use("/assets", (0, _expressStaticGzip2.default)(_path2.default.join(__dirname, "../" + process.env.PUBLIC_OUTPUT_PATH), {
52
- enableBrotli: true,
53
- orderPreference: ["br", "gzip", "deflate"]
54
- }), (0, _expressStaticGzip2.default)(_path2.default.join(__dirname, "../src/static/images"), {
55
- enableBrotli: true,
56
- orderPreference: ["br", "gzip", "deflate"]
57
- }), (0, _expressStaticGzip2.default)(_path2.default.join(__dirname, "../src/static/fonts"), {
58
- enableBrotli: true,
59
- orderPreference: ["br", "gzip", "deflate"]
60
- }), (0, _expressStaticGzip2.default)(_path2.default.join(__dirname, "../src/js/lib"), {
61
- enableBrotli: true,
62
- orderPreference: ["br", "gzip", "deflate"]
63
- }));
64
- } else {
65
- app.use("/assets", _express2.default.static(_path2.default.join(__dirname, "../" + process.env.PUBLIC_OUTPUT_PATH)), _express2.default.static(_path2.default.join(__dirname, `../${process.env.APPLICATION}/src/static/images`)), _express2.default.static(_path2.default.join(__dirname, `../${process.env.APPLICATION}/src/static/fonts`)), _express2.default.static(_path2.default.join(__dirname, `../${process.env.APPLICATION}/src/js/lib`)));
66
- }
67
-
68
- // handles document request
69
- app.use("*", _renderer2.default);
70
- exports.default = app;
@@ -1,55 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.getUserAgentDetails = undefined;
7
- var _uaParserJs = require("ua-parser-js");
8
- var _uaParserJs2 = _interopRequireDefault(_uaParserJs);
9
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
10
- function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
11
- function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
12
- function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
13
- function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
14
- function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
15
- const googleBots = {
16
- "APIs-Google": "APIs-Google",
17
- AdSense: "Mediapartners-Google",
18
- "AdsBot Mobile Web Android": "AdsBot-Google-Mobile",
19
- "AdsBot Mobile Web": "AdsBot-Google-Mobile",
20
- AdsBot: "AdsBot-Google",
21
- "Mobile AdSense": "Mediapartners-Google",
22
- "Mobile Apps Android": "AdsBot-Google-Mobile-Apps",
23
- Feedfetcher: "FeedFetcher-Google",
24
- "Google Read Aloud": "Google-Read-Aloud",
25
- "Duplex on the Web": "DuplexWeb-Google",
26
- "Google Favicon": "Google Favicon",
27
- "Web Light": "googleweblight",
28
- "Amp crawler": "Google-AMPHTM",
29
- Googlebot: "Googlebot"
30
- };
31
-
32
- /**
33
- * check if user agent contains bot data
34
- * @param {string} ua - user agent
35
- * @return {string|null}
36
- */
37
- const getGoogleBot = ua => {
38
- for (let key in googleBots) {
39
- if (ua.includes(googleBots[key])) return key;
40
- }
41
- return null;
42
- };
43
-
44
- /**
45
- * returns object which contains google bot and user-agent info
46
- * @param {string} ua - user agent
47
- * @return {object} - returns user agent
48
- */
49
- const getUserAgentDetails = exports.getUserAgentDetails = ua => {
50
- const agentDetails = (0, _uaParserJs2.default)(ua);
51
- const googleBot = getGoogleBot(ua);
52
- return _objectSpread(_objectSpread({}, agentDetails), {}, {
53
- googleBot
54
- });
55
- };
@@ -1,13 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.mergeMetaTags = void 0;
7
- const mergeMetaTags = (parentTags, childTags) => {};
8
- exports.mergeMetaTags = mergeMetaTags;
9
- const typesOfMeta = {};
10
-
11
- // type
12
- // props
13
- // children
@@ -1,20 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
- var _default = exports.default = {
8
- "presets": [["@babel/preset-env", {
9
- "targets": {
10
- "node": "current"
11
- }
12
- }], "@babel/preset-react"],
13
- "plugins": ["@babel/plugin-proposal-object-rest-spread", "transform-class-properties", "dynamic-import-node", "@loadable/babel-plugin"],
14
- "env": {
15
- "test": {
16
- "presets": ["@babel/preset-react"]
17
- }
18
- },
19
- "ignore": ["__TEST__"]
20
- };
@@ -1,82 +0,0 @@
1
- "use strict";
2
-
3
- module.exports = {
4
- m4a: "audio/mp4",
5
- f4a: "audio/mp4",
6
- f4b: "audio/mp4",
7
- oga: "audio/ogg",
8
- ogg: "audio/ogg",
9
- mid: "audio/&",
10
- midi: "audio/&",
11
- mp3: "audio/&",
12
- wav: "audio/&",
13
- js: "application/javascript",
14
- jsonp: "application/javascript",
15
- json: "application/json",
16
- doc: "application/msword",
17
- dot: "application/msword",
18
- bin: "application/octet-stream",
19
- ai: "application/postscript",
20
- pptx: "application/vnd.openxmlformats-officedocument.presentationml.presentation",
21
- xlsx: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
22
- docx: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
23
- xla: "application/vnd.ms-excel",
24
- xls: "application/vnd.ms-excel",
25
- xlt: "application/vnd.ms-excel",
26
- eot: "application/vnd.ms-fontobject",
27
- pot: "application/vnd.ms-powerpoint",
28
- ppa: "application/vnd.ms-powerpoint",
29
- pps: "application/vnd.ms-powerpoint",
30
- ppt: "application/vnd.ms-powerpoint",
31
- swf: "application/x-shockwave-flash",
32
- atom: "application/xml",
33
- rdf: "application/xml",
34
- rss: "application/xml",
35
- xml: "application/xml",
36
- pdf: "application/&",
37
- rtf: "application/&",
38
- zip: "application/&",
39
- otf: "font/opentype",
40
- ttf: "font/&",
41
- ttc: "font/&",
42
- woff: "font/&",
43
- jpe: "image/jpeg",
44
- jpeg: "image/jpeg",
45
- jpg: "image/jpeg",
46
- svg: "image/svg+xml",
47
- svgz: "image/svg+xml",
48
- psd: "image/vnd.adobe.photoshop",
49
- ico: "image/vnd.microsoft.icon",
50
- bmp: "image/&",
51
- ief: "image/&",
52
- gif: "image/&",
53
- png: "image/&",
54
- tif: "image/&",
55
- tiff: "image/&",
56
- webp: "image/&",
57
- appcache: "text/cache-manifest",
58
- manifest: "text/cache-manifest",
59
- txt: "text/plain",
60
- htc: "text/x-component",
61
- vcf: "text/x-vcard",
62
- css: "text/&",
63
- html: "text/&",
64
- php: "text/&",
65
- vtt: "text/&",
66
- markdown: "text/x-&",
67
- md: "text/x-&",
68
- mp4: "video/mp4",
69
- m4v: "video/mp4",
70
- f4v: "video/mp4",
71
- f4p: "video/mp4",
72
- ogv: "video/ogg",
73
- mov: "video/quicktime",
74
- qt: "video/quicktime",
75
- avi: "video/&",
76
- mpg: "video/&",
77
- vdo: "video/&",
78
- viv: "video/&",
79
- vivo: "video/&",
80
- webm: "video/&",
81
- flv: "video/x-&"
82
- };
@@ -1,122 +0,0 @@
1
- "use strict";
2
-
3
- function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
4
- function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
5
- function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
6
- function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
7
- function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
8
- const NAME = "route-manifest-plugin";
9
- const fs = require("fs");
10
- const path = require("path");
11
- const acornLoose = require("acorn-loose");
12
- const zlib = require("zlib");
13
- const generateMappingToOrigin = (pathToRoutesFile, routesVariableName) => {
14
- const fileContent = fs.readFileSync(path.resolve(pathToRoutesFile), "utf-8");
15
- const ast = acornLoose.parse(fileContent, {
16
- ecmaVersion: 2020
17
- });
18
- const routes = [];
19
- const componentMapping = {};
20
- const getValue = valueObj => {
21
- switch (valueObj.type) {
22
- case "Literal":
23
- return valueObj.value;
24
- case "Identifier":
25
- return valueObj.name;
26
- default:
27
- return "";
28
- }
29
- };
30
- ast.body.forEach(declarationBlock => {
31
- declarationBlock?.declarations?.forEach(variableDeclaration => {
32
- if (variableDeclaration?.id?.name === routesVariableName) {
33
- const objectExpression = variableDeclaration?.init?.elements;
34
- objectExpression.forEach(obj => {
35
- const route = {};
36
- obj?.properties.forEach(property => {
37
- if (property) route[property.key.name] = getValue(property.value);
38
- });
39
- routes.push(route);
40
- });
41
- }
42
- if (variableDeclaration?.init?.type === "CallExpression" && variableDeclaration?.init?.callee?.name === "loadable") {
43
- const componentName = variableDeclaration?.id?.name;
44
- const importArgument = variableDeclaration?.init?.arguments?.[0]; // import is first argument in loadable;
45
- componentMapping[componentName] = importArgument?.body?.source?.value;
46
- }
47
- });
48
- });
49
- const mappedRoutes = routes.map(route => _objectSpread(_objectSpread({}, route), {}, {
50
- origin: componentMapping[route.component] || ""
51
- }));
52
- return mappedRoutes;
53
- };
54
- const RoutesManifestPlugin = function (options) {
55
- this.options = options;
56
- };
57
- RoutesManifestPlugin.prototype.run = function (bundle, options) {
58
- const {
59
- pathToRoutesFile,
60
- routesVariableName
61
- } = options;
62
- const mappedRoutes = generateMappingToOrigin(pathToRoutesFile, routesVariableName);
63
- const {
64
- publicPath,
65
- chunks
66
- } = bundle.getStats().toJson();
67
- const originToChunksMapping = {};
68
- const originToChildrenMapping = {};
69
- chunks.forEach(chunk => {
70
- chunk.origins.forEach(origin => {
71
- originToChunksMapping[origin.request] = [...(originToChunksMapping[origin.request] || []), ...chunk.files.map(file => `${publicPath}${file}`)];
72
- chunk.children.forEach(childId => {
73
- const chunk = chunks.find(chunk => chunk.id === childId);
74
- originToChildrenMapping[origin.request] = [...(originToChildrenMapping[origin.request] || []), ...chunk.files.map(file => `${publicPath}${file}`)];
75
- });
76
- });
77
- });
78
- mappedRoutes.forEach(mappedRoute => {
79
- mappedRoute.chunks = [...new Set(originToChunksMapping[mappedRoute.origin])];
80
- mappedRoute.children = [...new Set(originToChildrenMapping[mappedRoute.origin])];
81
- });
82
- return mappedRoutes;
83
- };
84
- RoutesManifestPlugin.prototype.apply = function (compiler) {
85
- if (compiler.hooks !== void 0) {
86
- compiler.hooks.emit.tap(NAME, compilation => {
87
- const assetsMappingJson = this.run(compilation, this.options);
88
- const stringifiedAssetsMappingJson = JSON.stringify(assetsMappingJson);
89
- const compressedGzip = zlib.gzipSync(stringifiedAssetsMappingJson);
90
- const compressedBrotli = zlib.brotliCompressSync(stringifiedAssetsMappingJson);
91
- compilation.assets["route-manifest.json.gz"] = {
92
- source: function () {
93
- return compressedGzip;
94
- },
95
- size: function () {
96
- return compressedGzip.length;
97
- }
98
- };
99
- compilation.assets["route-manifest.json.br"] = {
100
- source: function () {
101
- return compressedBrotli;
102
- },
103
- size: function () {
104
- return compressedBrotli.length;
105
- }
106
- };
107
- compilation.assets["route-manifest.json"] = {
108
- source: function () {
109
- return stringifiedAssetsMappingJson;
110
- },
111
- size: function () {
112
- return stringifiedAssetsMappingJson.length;
113
- }
114
- };
115
- });
116
- } else {
117
- compiler.plugin("emit", bundle => {
118
- this.run(bundle, this.options);
119
- });
120
- }
121
- };
122
- module.exports = RoutesManifestPlugin;