catalyst-core 0.0.1-beta.2

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 (106) hide show
  1. package/.prettierignore +2 -0
  2. package/.prettierrc.json +7 -0
  3. package/LICENSE +9 -0
  4. package/README.md +132 -0
  5. package/babel.config.json +24 -0
  6. package/bin/catalyst.js +41 -0
  7. package/caching.js +16 -0
  8. package/checkVersion.js +3 -0
  9. package/config/config.js +24 -0
  10. package/config.json +8 -0
  11. package/index.js +16 -0
  12. package/logger/index.js +96 -0
  13. package/package.json +87 -0
  14. package/packages/create-framework-app/node_modules/.package-lock.json +249 -0
  15. package/packages/create-framework-app/templates/redux-js/node_modules/@babel/core/lib/config/caching.js +261 -0
  16. package/packages/create-framework-app/templates/redux-js/node_modules/@remix-run/router/dist/router.js +4327 -0
  17. package/packages/create-framework-app/templates/redux-js/node_modules/catalyst/router.js +15 -0
  18. package/packages/create-framework-app/templates/redux-js/node_modules/http-proxy-middleware/dist/router.js +46 -0
  19. package/reducer/index.js +88 -0
  20. package/reducer/loadableConfigReducer.js +19 -0
  21. package/router/ClientRouter.js +15 -0
  22. package/router/ServerRouter.js +28 -0
  23. package/router/index.js +32 -0
  24. package/router.js +16 -0
  25. package/scripts/build.js +27 -0
  26. package/scripts/loadEnvironmentVariables.js +37 -0
  27. package/scripts/loadScriptsBeforeServerStarts.js +55 -0
  28. package/scripts/prepare.js +19 -0
  29. package/scripts/registerAliases.js +30 -0
  30. package/scripts/serve.js +27 -0
  31. package/scripts/start.js +28 -0
  32. package/scripts/validator.js +99 -0
  33. package/server/mainIndex.js +65 -0
  34. package/server/mainServer.js +70 -0
  35. package/server/renderer/document/Body.js +37 -0
  36. package/server/renderer/document/Head.js +44 -0
  37. package/server/renderer/document/index.js +25 -0
  38. package/server/renderer/extract.js +86 -0
  39. package/server/renderer/handler.js +228 -0
  40. package/server/renderer/index.js +13 -0
  41. package/server/renderer/render.js +71 -0
  42. package/server/renderer/userAgentUtil.js +55 -0
  43. package/server/utils/validator.js +98 -0
  44. package/store/index.dev.js +73 -0
  45. package/store/index.js +25 -0
  46. package/store/index.prod.js +66 -0
  47. package/tsconfig.json +110 -0
  48. package/types/caching.d.ts +1 -0
  49. package/types/config/config.d.ts +19 -0
  50. package/types/index.d.ts +1 -0
  51. package/types/logger/index.d.ts +14 -0
  52. package/types/reducer/index.d.ts +22 -0
  53. package/types/reducer/loadableConfigReducer.d.ts +9 -0
  54. package/types/router/ClientRouter.d.ts +5 -0
  55. package/types/router/ServerRouter.d.ts +7 -0
  56. package/types/router/index.d.ts +8 -0
  57. package/types/router.d.ts +1 -0
  58. package/types/scripts/build.d.ts +1 -0
  59. package/types/scripts/loadEnvironmentVariables.d.ts +5 -0
  60. package/types/scripts/loadScriptsBeforeServerStarts.d.ts +1 -0
  61. package/types/scripts/prepare.d.ts +1 -0
  62. package/types/scripts/registerAliases.d.ts +1 -0
  63. package/types/scripts/serve.d.ts +1 -0
  64. package/types/scripts/start.d.ts +1 -0
  65. package/types/scripts/validator.d.ts +9 -0
  66. package/types/scripts/verifyConfig.d.ts +1 -0
  67. package/types/server/mainIndex.d.ts +1 -0
  68. package/types/server/mainServer.d.ts +2 -0
  69. package/types/server/renderer/document/Body.d.ts +11 -0
  70. package/types/server/renderer/document/Head.d.ts +11 -0
  71. package/types/server/renderer/document/index.d.ts +2 -0
  72. package/types/server/renderer/extract.d.ts +18 -0
  73. package/types/server/renderer/handler.d.ts +6 -0
  74. package/types/server/renderer/index.d.ts +2 -0
  75. package/types/server/renderer/render.d.ts +38 -0
  76. package/types/server/renderer/userAgentUtil.d.ts +1 -0
  77. package/types/store/index.d.ts +11 -0
  78. package/types/store/index.dev.d.ts +8 -0
  79. package/types/store/index.prod.d.ts +8 -0
  80. package/types/webpack/babel-plugins/remove-client.plugin.d.ts +10 -0
  81. package/types/webpack/babel-plugins/remove-ssr.plugin.d.ts +10 -0
  82. package/types/webpack/babel.config.client.d.ts +21 -0
  83. package/types/webpack/babel.config.d.ts +16 -0
  84. package/types/webpack/babel.config.ssr.d.ts +21 -0
  85. package/types/webpack/base.babel.d.ts +184 -0
  86. package/types/webpack/development.client.babel.d.ts +1 -0
  87. package/types/webpack/plugins/mime-types.d.ts +78 -0
  88. package/types/webpack/plugins/route-manifest-plugin.d.ts +1 -0
  89. package/types/webpack/plugins/upload-assets-plugin.d.ts +1 -0
  90. package/types/webpack/production.client.babel.d.ts +174 -0
  91. package/types/webpack/production.ssr.babel.d.ts +2 -0
  92. package/types/webpack/scssParams.d.ts +2 -0
  93. package/webpack/babel-plugins/remove-client.plugin.js +31 -0
  94. package/webpack/babel-plugins/remove-ssr.plugin.js +21 -0
  95. package/webpack/babel.config.client.js +24 -0
  96. package/webpack/babel.config.js +20 -0
  97. package/webpack/babel.config.ssr.js +24 -0
  98. package/webpack/base.babel.js +174 -0
  99. package/webpack/development.client.babel.js +82 -0
  100. package/webpack/plugins/mime-types.js +82 -0
  101. package/webpack/plugins/route-manifest-copy.js +122 -0
  102. package/webpack/plugins/route-manifest-plugin.js +122 -0
  103. package/webpack/plugins/upload-assets-plugin.js +181 -0
  104. package/webpack/production.client.babel.js +79 -0
  105. package/webpack/production.ssr.babel.js +61 -0
  106. package/webpack/scssParams.js +31 -0
@@ -0,0 +1,181 @@
1
+ "use strict";
2
+
3
+ const fs = require("fs"),
4
+ AWS = require("aws-sdk"),
5
+ path = require("path"),
6
+ mimeTypeByExtension = require("./mime-types");
7
+ const getContentType = filePath => {
8
+ const extname = path.extname(filePath);
9
+ const pathChunks = filePath.split(".");
10
+ const chunkLength = pathChunks.length;
11
+ const extension = extname === ".br" || extname === ".gz" ? pathChunks[chunkLength - 2] : pathChunks[chunkLength - 1];
12
+ switch (extension) {
13
+ case "svg":
14
+ return "image/svg+xml";
15
+ case "css":
16
+ return "text/css";
17
+ default:
18
+ return mimeTypeByExtension[extension] || "text/plain";
19
+ }
20
+ };
21
+ /* eslint-disable */
22
+ const uploadImages = async ({
23
+ assetsDir,
24
+ s3BucketName,
25
+ s3Folder,
26
+ exclude
27
+ }) => {
28
+ // picks aws keys directly from the ec2 instance
29
+ const s3 = new AWS.S3({
30
+ signatureVersion: "v4"
31
+ }),
32
+ // cloudfront = new AWS.CloudFront(),
33
+ s3PathForUpload = relativeFilePath => `${s3Folder}/${relativeFilePath}`,
34
+ allFilesIn = function (dir, filelist, parent) {
35
+ const files = fs.readdirSync(dir);
36
+ filelist = filelist || [];
37
+ files.forEach(function (file) {
38
+ if (fs.statSync(dir + file).isDirectory()) {
39
+ filelist = allFilesIn(dir + file + "/", filelist, (parent ? parent + "/" : "") + file);
40
+ } else {
41
+ filelist.push(parent ? parent + "/" + file : file);
42
+ }
43
+ });
44
+ return filelist;
45
+ },
46
+ uploadFile = (filePath, targetPath) => {
47
+ //eslint-disable-next-line
48
+ fs.readFile(filePath, (error, fileContent) => {
49
+ if (error) {
50
+ throw error;
51
+ }
52
+ if (!exclude.test(filePath)) {
53
+ const fileStream = fs.createReadStream(filePath);
54
+ fileStream.on("error", function (err) {
55
+ console.dir({
56
+ service_name: "pwa-dweb-node-server",
57
+ loglevel: "error",
58
+ version: "v2",
59
+ message: "File Error",
60
+ traceback: err
61
+ });
62
+ });
63
+ s3.upload({
64
+ Bucket: s3BucketName,
65
+ Key: targetPath,
66
+ Body: fileStream,
67
+ ContentType: getContentType(filePath),
68
+ ACL: "public-read",
69
+ XRobotsTag: "noindex, nofollow",
70
+ CacheControl: "max-age=31536000"
71
+ }, (err, data) => {
72
+ if (err) {
73
+ console.log(`Failed uploading : '${filePath}'!`, err);
74
+ }
75
+ });
76
+ }
77
+ });
78
+ },
79
+ emptyBucket = async () => {
80
+ /* eslint-disable-line */
81
+ /* eslint-disable-line */
82
+ const dir = "pwa-app/staging";
83
+ var params = {
84
+ Bucket: s3BucketName,
85
+ Prefix: dir
86
+ };
87
+ const listedObjects = await s3.listObjectsV2(params).promise();
88
+ console.dir({
89
+ service_name: "pwa-dweb-node-server",
90
+ loglevel: "info",
91
+ version: "v2",
92
+ message: `\n listed objects ${listedObjects}`
93
+ });
94
+ if (listedObjects.Contents.length === 0) {
95
+ console.dir({
96
+ service_name: "pwa-dweb-node-server",
97
+ loglevel: "info",
98
+ version: "v2",
99
+ message: " No files on S3 "
100
+ });
101
+ return;
102
+ }
103
+ const deleteParams = {
104
+ Bucket: s3BucketName,
105
+ Delete: {
106
+ Objects: []
107
+ }
108
+ };
109
+ listedObjects.Contents.forEach(({
110
+ Key
111
+ }) => {
112
+ deleteParams.Delete.Objects.push({
113
+ Key
114
+ });
115
+ });
116
+ console.dir({
117
+ service_name: "pwa-dweb-node-server",
118
+ loglevel: "info",
119
+ version: "v2",
120
+ message: `Removing ${deleteParams.Delete.Objects.length} items from ${dir}`
121
+ });
122
+ await s3.deleteObjects(deleteParams).promise();
123
+ if (listedObjects.IsTruncated) await emptyBucket();
124
+ },
125
+ /* following code is not being used */
126
+ // inValidateCache = () => {
127
+ // /* eslint-disable-line */
128
+ // /* eslint-disable-line */
129
+ // let randomString = Math.random().toString(36).substring(7)
130
+
131
+ // const params = {
132
+ // DistributionId: process.env.DISTRIBUTION_ID,
133
+ // /* required */
134
+ // InvalidationBatch: {
135
+ // /* required */
136
+ // CallerReference: randomString,
137
+ // /* required */
138
+ // Paths: {
139
+ // /* required */
140
+ // Quantity: 1,
141
+ // /* required */
142
+ // Items: [`/pwa-app/${process.env.BUILD_ENV}/*`],
143
+ // },
144
+ // },
145
+ // }
146
+ // cloudfront.createInvalidation(params, function (err, data) {
147
+ // if (err) console.log(err, err.stack)
148
+ // // an error occurred
149
+ // else console.log("Cache Invalidation Successful", data) // successful response
150
+ // })
151
+ // },
152
+ relativePaths = allFilesIn(assetsDir, []);
153
+
154
+ // Remove files from bucket
155
+ // await emptyBucket(`${process.env.S3_FOLDER}/${process.env.BUILD_ENV}`);
156
+ // await emptyBucket();
157
+ relativePaths.forEach(relativePath => {
158
+ const fullPathToFile = path.join(assetsDir, relativePath),
159
+ s3FolderPath = s3PathForUpload(relativePath);
160
+ if (!fs.lstatSync(fullPathToFile).isDirectory()) {
161
+ uploadFile(fullPathToFile, s3FolderPath);
162
+ }
163
+ });
164
+
165
+ // console.log("==============================================");
166
+ // console.log("==========Starting cache invalidation=========");
167
+ // console.log("==============================================");
168
+
169
+ // if (process.env.BUILD_ENV === "production") inValidateCache();
170
+ };
171
+
172
+ const UploadAssetsPlugin = function (options) {
173
+ this.options = options;
174
+ };
175
+ UploadAssetsPlugin.prototype.apply = function (compiler) {
176
+ compiler.hooks.done.tap("UploadAssetsPlugin", () => {
177
+ uploadImages(this.options);
178
+ });
179
+ };
180
+ module.exports = UploadAssetsPlugin;
181
+ /* eslint-enable */
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _base = _interopRequireDefault(require("./base.babel"));
8
+ var _miniCssExtractPlugin = _interopRequireDefault(require("mini-css-extract-plugin"));
9
+ var _path = _interopRequireDefault(require("path"));
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 plugins = require(_path.default.join(process.env.src_path, "webpackConfig.js"));
17
+ const catalystConfig = require(_path.default.resolve(__dirname, "..", "config.json"));
18
+ const isSSR = !!process.env.SSR || false;
19
+ const clientConfig = mergeWithCustomize({
20
+ customizeArray: customizeArray({
21
+ entry: "prepend",
22
+ plugins: "append",
23
+ module: "prepend"
24
+ }),
25
+ customizeObject: customizeObject({
26
+ entry: "prepend",
27
+ plugins: "append",
28
+ module: "prepend"
29
+ })
30
+ })(_base.default, {
31
+ mode: "production",
32
+ optimization: {
33
+ runtimeChunk: "single",
34
+ moduleIds: "deterministic",
35
+ splitChunks: {
36
+ cacheGroups: {
37
+ commonVendor: {
38
+ chunks: "all",
39
+ test: /[\\/]node_modules[\\/](react|react-dom|react-redux|react-router|react-router-dom|redux|redux-thunk|axios|react-loadable-visibility|react-helmet-async|react-google-recaptcha|normalize.css|react-detect-offline|react-side-effect|react-fast-compare|react-async-script|babel|history|@tata1mg|@loadable\/component|framer-motion|pwa|)[\\/]/,
40
+ name: "commonVendor",
41
+ minSize: 400000,
42
+ maxSize: 400000
43
+ },
44
+ utilityVendor: {
45
+ maxInitialRequests: Infinity,
46
+ chunks: "all",
47
+ // minSize: 0, // Enable to replicate stand alone chunking for all packages
48
+ reuseExistingChunk: true,
49
+ // Disable to replicate stand alone chunking for all packages
50
+ minRemainingSize: 1000,
51
+ // Disable to replicate stand alone chunking for all packages
52
+ minSize: 1000,
53
+ maxSize: 120000,
54
+ test: /[\\/]node_modules[\\/]/,
55
+ name(module) {
56
+ const moduleFileName = module.identifier().split("/").reverse().slice(0, 3).reduce((item, current) => {
57
+ item = current + "." + item;
58
+ return item;
59
+ }, []);
60
+ return `npm.${moduleFileName}`;
61
+ }
62
+ }
63
+ },
64
+ chunks: "all",
65
+ name(module) {
66
+ const moduleFileName = module.identifier().split("/").reverse().slice(0, 3).reduce((item, current) => {
67
+ item = current + "." + item;
68
+ return item;
69
+ }, []);
70
+ return `npm.${moduleFileName}`;
71
+ }
72
+ }
73
+ },
74
+ plugins: [new _miniCssExtractPlugin.default({
75
+ filename: catalystConfig.cssChunkFileName,
76
+ ignoreOrder: true
77
+ }), ...plugins.clientPlugins]
78
+ });
79
+ var _default = exports.default = clientConfig;
@@ -0,0 +1,61 @@
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.ssrPrugins],
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.OUTPUT_PATH, "renderer"),
56
+ chunkFilename: catalystConfig.chunkFileNameDev,
57
+ filename: "handler.js",
58
+ libraryTarget: "commonjs"
59
+ }
60
+ });
61
+ var _default = exports.default = ssrConfig;
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.urlFor = exports.fontUrl = void 0;
7
+ /**
8
+ * @description generate assets url according to enviorment
9
+ * @returns returns path required for loading assets according to enviorment
10
+ */
11
+ const urlFor = () => {
12
+ const isDev = process.env.NODE_ENV !== "production",
13
+ isLocalBuild = process.env.BUILD_ENV === "localBuild";
14
+ const localPath = JSON.stringify(`${process.env.SERVER_PATH + process.env.LOCAL_ASSET_PATH}`);
15
+ const cdnPath = JSON.stringify(`${process.env.PUBLIC_ASSET_PATH}images/`);
16
+ return isDev || isLocalBuild ? localPath : cdnPath;
17
+ };
18
+
19
+ /**
20
+ * @description generate assets font url according to enviorment
21
+ * @returns returns path required for loading fonts according to enviorment
22
+ */
23
+ exports.urlFor = urlFor;
24
+ const fontUrl = () => {
25
+ const isDev = process.env.NODE_ENV !== "production",
26
+ isLocalBuild = process.env.BUILD_ENV === "localBuild";
27
+ const localPath = JSON.stringify(`${process.env.SERVER_PATH + process.env.LOCAL_ASSET_PATH}`);
28
+ const cdnPath = JSON.stringify(`${process.env.PUBLIC_ASSET_PATH}fonts/`);
29
+ return isDev || isLocalBuild ? localPath : cdnPath;
30
+ };
31
+ exports.fontUrl = fontUrl;