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
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@ Frontend framework with server rendering support for web applications.
|
|
|
5
5
|
## Table of Contents
|
|
6
6
|
|
|
7
7
|
- Overview
|
|
8
|
-
-
|
|
8
|
+
- Installation
|
|
9
9
|
- Data Fetching with Catalyst
|
|
10
10
|
- serverFetcher
|
|
11
11
|
- clientFetcher
|
|
@@ -17,28 +17,41 @@ Frontend framework with server rendering support for web applications.
|
|
|
17
17
|
This package provides a way to proxy your request through your server. It allows you to cache your incoming request to improve your server response time.
|
|
18
18
|
|
|
19
19
|
|
|
20
|
-
##
|
|
21
|
-
Run the following commands in the directory where you want to scaffold catalyst app.
|
|
20
|
+
## Installation
|
|
22
21
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
**System Requirements**
|
|
23
|
+
|
|
24
|
+
- Node version 20.4.0 or later
|
|
25
|
+
- macOS and Linux are supported
|
|
26
26
|
|
|
27
|
-
if this steps fails, make sure .npmrc file exists and token used is a valid one.
|
|
28
27
|
|
|
29
|
-
|
|
28
|
+
**Automatic Installation**
|
|
30
29
|
|
|
31
|
-
|
|
30
|
+
- Run the following commands in the directory where you want to set up the Catalyst app.
|
|
32
31
|
|
|
33
|
-
After selecting options
|
|
34
32
|
```js
|
|
35
|
-
|
|
33
|
+
npx create-catalyst-app@latest
|
|
36
34
|
```
|
|
37
|
-
|
|
35
|
+
|
|
36
|
+
If successful, you will see the following prompts in your terminal.
|
|
37
|
+
|
|
38
|
+
- Enter the name of your Catalyst application.
|
|
39
|
+
- Choose state management.
|
|
40
|
+
- Once packages are installed,start the development server by running the following command.
|
|
41
|
+
|
|
38
42
|
```js
|
|
39
|
-
npm run start
|
|
43
|
+
cd project-name && npm run start
|
|
40
44
|
```
|
|
41
45
|
|
|
46
|
+
- Navigate to http://localhost:3005
|
|
47
|
+
|
|
48
|
+
The dev server should be running now.
|
|
49
|
+
|
|
50
|
+
Visit our official documentation:
|
|
51
|
+
https://catalyst.1mg.com/public_docs/content/installation
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
|
|
42
55
|
## Data Fetching with Catalyst
|
|
43
56
|
|
|
44
57
|
we have serverFetcher function for fetching with SSR and clientFetcher function for fetching during client side rendering and navigations.
|
package/bin/catalyst.js
CHANGED
|
@@ -6,11 +6,11 @@ process.on('unhandledRejection', err => {
|
|
|
6
6
|
const { spawnSync } = require('node:child_process');
|
|
7
7
|
const args = process.argv.slice(2);
|
|
8
8
|
const scriptIndex = args.findIndex(
|
|
9
|
-
x => x === 'build' || x === 'start' || x=== '
|
|
9
|
+
x => x === 'build' || x === 'start' || x=== 'serve'
|
|
10
10
|
);
|
|
11
11
|
const script = scriptIndex === -1 ? args[0] : args[scriptIndex];
|
|
12
12
|
const nodeArgs = scriptIndex > 0 ? args.slice(0, scriptIndex) : [];
|
|
13
|
-
if (['build', 'start', '
|
|
13
|
+
if (['build', 'start', 'serve'].includes(script)) {
|
|
14
14
|
const result = spawnSync(
|
|
15
15
|
process.execPath,
|
|
16
16
|
nodeArgs
|
|
@@ -37,5 +37,4 @@ if (['build', 'start', 'prepare', 'serve'].includes(script)) {
|
|
|
37
37
|
process.exit(result.status);
|
|
38
38
|
} else {
|
|
39
39
|
console.log('Unknown script "' + script + '".');
|
|
40
|
-
console.log('Perhaps you need to update framework?');
|
|
41
40
|
}
|
package/config.json
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"cssModulesIdentifierDev": "[name]__[local]",
|
|
3
3
|
"cssModulesIdentifierProd": "[name]__[local]__[hash:base64:5]",
|
|
4
|
-
"analyzeBundle": false,
|
|
5
4
|
"chunkFileNameDev": "[name].bundle.js",
|
|
6
5
|
"chunkFileNameProd": "[name].[contenthash].js",
|
|
7
6
|
"cssChunkFileName": "[name].[contenthash].css"
|
package/{LICENSE → license}
RENAMED
|
@@ -6,4 +6,5 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
|
6
6
|
|
|
7
7
|
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
8
|
|
|
9
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
10
|
+
|
|
@@ -10,13 +10,13 @@ const {
|
|
|
10
10
|
} = winston;
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
|
-
* @description Logger library with rotational strategy. Creates a logs folder in root.
|
|
13
|
+
* @description Logger library with rotational strategy. Creates a logs folder in root.
|
|
14
14
|
* With debug, error and info log directories with their respective log files.
|
|
15
|
-
*
|
|
15
|
+
*
|
|
16
16
|
* @format Logstash with timestamp
|
|
17
17
|
* @param config { @enableDebugLogs: Bool // default: true }
|
|
18
18
|
* @returns loggerInstance
|
|
19
|
-
*
|
|
19
|
+
*
|
|
20
20
|
*/
|
|
21
21
|
const configureLogger = (config = {}) => {
|
|
22
22
|
const {
|
|
@@ -25,7 +25,7 @@ const configureLogger = (config = {}) => {
|
|
|
25
25
|
enableConsoleLogging = true
|
|
26
26
|
} = config;
|
|
27
27
|
const consoleTransport = new transports.Console({
|
|
28
|
-
level:
|
|
28
|
+
level: "debug"
|
|
29
29
|
});
|
|
30
30
|
const fileTransport = (type = "info") => {
|
|
31
31
|
return new DailyRotateFile({
|
|
@@ -39,7 +39,7 @@ const configureLogger = (config = {}) => {
|
|
|
39
39
|
};
|
|
40
40
|
const infoLogger = createLogger({
|
|
41
41
|
format: format.combine(format.timestamp({
|
|
42
|
-
format:
|
|
42
|
+
format: "YYYY-MM-DD HH:mm:ss"
|
|
43
43
|
}), format.json()),
|
|
44
44
|
defaultMeta: {
|
|
45
45
|
loglevel: "info"
|
|
@@ -47,7 +47,7 @@ const configureLogger = (config = {}) => {
|
|
|
47
47
|
});
|
|
48
48
|
const debugLogger = createLogger({
|
|
49
49
|
format: format.combine(format.timestamp({
|
|
50
|
-
format:
|
|
50
|
+
format: "YYYY-MM-DD HH:mm:ss"
|
|
51
51
|
}), format.json()),
|
|
52
52
|
defaultMeta: {
|
|
53
53
|
loglevel: "debug"
|
|
@@ -55,7 +55,7 @@ const configureLogger = (config = {}) => {
|
|
|
55
55
|
});
|
|
56
56
|
const errorLogger = createLogger({
|
|
57
57
|
format: format.combine(format.timestamp({
|
|
58
|
-
format:
|
|
58
|
+
format: "YYYY-MM-DD HH:mm:ss"
|
|
59
59
|
}), format.json()),
|
|
60
60
|
defaultMeta: {
|
|
61
61
|
loglevel: "error"
|
|
@@ -67,9 +67,9 @@ const configureLogger = (config = {}) => {
|
|
|
67
67
|
errorLogger.add(consoleTransport);
|
|
68
68
|
}
|
|
69
69
|
if (enableFileLogging && JSON.parse(enableFileLogging)) {
|
|
70
|
-
infoLogger.add(fileTransport(
|
|
71
|
-
debugLogger.add(fileTransport(
|
|
72
|
-
errorLogger.add(fileTransport(
|
|
70
|
+
infoLogger.add(fileTransport("info"));
|
|
71
|
+
debugLogger.add(fileTransport("debug"));
|
|
72
|
+
errorLogger.add(fileTransport("error"));
|
|
73
73
|
}
|
|
74
74
|
const Logger = {
|
|
75
75
|
debug: () => {},
|
package/package.json
CHANGED
|
@@ -1,18 +1,24 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "catalyst-core",
|
|
3
|
-
"version": "0.0.1-beta.
|
|
3
|
+
"version": "0.0.1-beta.3",
|
|
4
4
|
"main": "index.js",
|
|
5
|
-
"description": "
|
|
5
|
+
"description": "Web framework that provides great performance out of the box",
|
|
6
6
|
"bin": {
|
|
7
|
-
"catalyst": "
|
|
7
|
+
"catalyst": "bin/catalyst.js"
|
|
8
8
|
},
|
|
9
9
|
"scripts": {
|
|
10
10
|
"prepare": "babel src --out-dir . ",
|
|
11
|
-
"start": "
|
|
12
|
-
"
|
|
13
|
-
"
|
|
11
|
+
"start": "node ./scripts/checkVersion && npm run start:client & npm run start:server",
|
|
12
|
+
"start:client": "npx babel-node -r ./scripts/loadScriptsBeforeServerStarts.js webpack/development.client.babel --no-warnings=ExperimentalWarning --no-warnings=BABEL",
|
|
13
|
+
"start:server": "npx babel-node -r ./scripts/loadScriptsBeforeServerStarts.js ./server/startServer.js --watch-path=${npm_config_src_path}/server --watch-path=${npm_config_src_path}/src --ignore='__IGNORE__' --no-warnings=ExperimentalWarning --no-warnings=BABEL",
|
|
14
|
+
"build": "node ./scripts/checkVersion && npm run build:prepare && npm run build:client && npm run build:ssr && npm run build:server",
|
|
15
|
+
"build:prepare": "rm -rf ${npm_config_src_path}/${build_output_path} & node ./scripts/loadScriptsBeforeServerStarts.js",
|
|
16
|
+
"build:client": "APPLICATION=${npm_config_app_name} NODE_ENV=production webpack --config ./webpack/production.client.babel.js --progress",
|
|
17
|
+
"build:ssr": "APPLICATION=${npm_config_app_name} NODE_ENV=production SSR=true webpack --config ./webpack/production.ssr.babel.js --progress",
|
|
18
|
+
"build:server": "APPLICATION=${npm_config_app_name} NODE_ENV=production npx babel ./server --out-dir ${npm_config_src_path}/${build_output_path} --ignore '**/*.test.js,./server/renderer/handler.js' && APPLICATION=${npm_config_app_name} npx babel ${npm_config_src_path}/server --out-dir ${npm_config_src_path}/${build_output_path}",
|
|
19
|
+
"serve": "APPLICATION=${npm_config_app_name} NODE_ENV=production node -r ./scripts/loadScriptsBeforeServerStarts.js ${npm_config_src_path}/${build_output_path}/startServer.js",
|
|
20
|
+
"prepublishOnly": "npm i && npm run prepare"
|
|
14
21
|
},
|
|
15
|
-
"author": "",
|
|
16
22
|
"license": "MIT",
|
|
17
23
|
"dependencies": {
|
|
18
24
|
"@babel/cli": "^7.23.0",
|
|
@@ -29,11 +35,8 @@
|
|
|
29
35
|
"@loadable/webpack-plugin": "^5.15.2",
|
|
30
36
|
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.11",
|
|
31
37
|
"@svgr/webpack": "^8.1.0",
|
|
32
|
-
"@tata1mg/router": "^0.0.1-
|
|
33
|
-
"acorn-loose": "^8.4.0",
|
|
38
|
+
"@tata1mg/router": "^0.0.1-beta.0",
|
|
34
39
|
"app-root-path": "^3.1.0",
|
|
35
|
-
"aws-sdk": "^2.1490.0",
|
|
36
|
-
"axios": "^0.19.2",
|
|
37
40
|
"babel-loader": "^9.1.3",
|
|
38
41
|
"babel-plugin-dynamic-import-node": "^2.3.3",
|
|
39
42
|
"babel-plugin-syntax-dynamic-import": "^6.18.0",
|
|
@@ -42,24 +45,20 @@
|
|
|
42
45
|
"babel-plugin-transform-export-extensions": "^6.22.0",
|
|
43
46
|
"babel-plugin-transform-react-remove-prop-types": "^0.4.24",
|
|
44
47
|
"body-parser": "^1.20.2",
|
|
48
|
+
"chokidar": "^3.6.0",
|
|
45
49
|
"compression": "^1.7.4",
|
|
46
50
|
"cookie-parser": "^1.4.6",
|
|
47
51
|
"css-hot-loader": "^1.4.4",
|
|
48
52
|
"css-loader": "^6.8.1",
|
|
49
53
|
"css-modules-require-hook": "^4.2.3",
|
|
50
|
-
"dotenv-webpack": "^8.0.1",
|
|
51
|
-
"esm-module-alias": "^2.0.3",
|
|
52
54
|
"express": "^4.18.2",
|
|
53
55
|
"express-static-gzip": "^2.1.7",
|
|
54
56
|
"file-loader": "^6.2.0",
|
|
55
|
-
"helmet": "^7.0.0",
|
|
56
57
|
"html-loader": "^4.2.0",
|
|
57
58
|
"img-loader": "^4.0.0",
|
|
58
59
|
"isomorphic-dompurify": "^1.13.0",
|
|
59
|
-
"lodash.template": "^4.5.0",
|
|
60
60
|
"mini-css-extract-plugin": "^2.7.6",
|
|
61
61
|
"module-alias": "^2.2.3",
|
|
62
|
-
"node-dev": "^7.4.3",
|
|
63
62
|
"picocolors": "^1.0.0",
|
|
64
63
|
"postcss-loader": "^7.3.3",
|
|
65
64
|
"react": "^18.2.0",
|
|
@@ -68,17 +67,16 @@
|
|
|
68
67
|
"react-refresh": "^0.14.0",
|
|
69
68
|
"react-router-dom": "^6.16.0",
|
|
70
69
|
"redux": "^4.2.1",
|
|
71
|
-
"redux-logger": "^3.0.6",
|
|
72
|
-
"redux-thunk": "^2.4.2",
|
|
73
70
|
"sass": "^1.69.5",
|
|
74
71
|
"sass-loader": "^13.3.2",
|
|
75
72
|
"sass-resources-loader": "^2.2.5",
|
|
76
73
|
"ua-parser-js": "^1.0.37",
|
|
74
|
+
"url": "^0.11.3",
|
|
77
75
|
"url-loader": "^4.1.1",
|
|
78
76
|
"webpack": "^5.88.2",
|
|
79
77
|
"webpack-bundle-analyzer": "^4.9.1",
|
|
80
78
|
"webpack-cli": "^5.1.4",
|
|
81
|
-
"webpack-dev-server": "^4.15.
|
|
79
|
+
"webpack-dev-server": "^4.15.2",
|
|
82
80
|
"webpack-merge": "^5.9.0",
|
|
83
81
|
"webpack-node-externals": "^3.0.0",
|
|
84
82
|
"winston": "^3.11.0",
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@tata1mg/router'
|
package/router/ClientRouter.js
CHANGED
|
@@ -4,12 +4,16 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
var
|
|
8
|
-
var
|
|
9
|
-
// FRAMEWORK COMMENT THIS IS JUST FOR THE APP
|
|
10
|
-
|
|
7
|
+
var _router = require("@tata1mg/router");
|
|
8
|
+
var _utils = require("@routes/utils.js");
|
|
11
9
|
/**
|
|
12
10
|
* @returns returns browsers routers (client routes)
|
|
13
|
-
*/
|
|
14
|
-
const clientRouter = (
|
|
11
|
+
*/
|
|
12
|
+
const clientRouter = ({
|
|
13
|
+
store,
|
|
14
|
+
routerInitialState
|
|
15
|
+
}) => (0, _router.createBrowserRouter)((0, _utils.preparedRoutes)({
|
|
16
|
+
store,
|
|
17
|
+
routerInitialState
|
|
18
|
+
}));
|
|
15
19
|
var _default = exports.default = clientRouter;
|
package/router/ServerRouter.js
CHANGED
|
@@ -5,22 +5,13 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
var _router = require("@tata1mg/router");
|
|
8
|
-
|
|
9
|
-
const {
|
|
10
|
-
preparedRoutes
|
|
11
|
-
} = require(`${process.env.src_path}/src/js/routes/index.js`);
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* @description return
|
|
15
|
-
* @param {object} reduxData - redux data
|
|
16
|
-
* @returns returns server routes
|
|
17
|
-
*/
|
|
8
|
+
var _utils = require("@routes/utils.js");
|
|
18
9
|
const ServerRouter = reduxData => {
|
|
19
10
|
const {
|
|
20
11
|
store,
|
|
21
12
|
intialData
|
|
22
13
|
} = reduxData;
|
|
23
|
-
return (0, _router.useRoutes)(preparedRoutes({
|
|
14
|
+
return (0, _router.useRoutes)((0, _utils.preparedRoutes)({
|
|
24
15
|
store,
|
|
25
16
|
routerInitialState: intialData
|
|
26
17
|
}));
|
package/scripts/build.js
CHANGED
|
@@ -6,21 +6,27 @@ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key i
|
|
|
6
6
|
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
7
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
8
|
const {
|
|
9
|
-
spawnSync
|
|
10
|
-
execSync
|
|
9
|
+
spawnSync
|
|
11
10
|
} = require("child_process");
|
|
12
11
|
const path = require("path");
|
|
13
12
|
const {
|
|
14
13
|
name
|
|
15
14
|
} = require(`${process.env.PWD}/package.json`);
|
|
15
|
+
const {
|
|
16
|
+
BUILD_OUTPUT_PATH
|
|
17
|
+
} = require(`${process.env.PWD}/config/config.json`);
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* @description - creates a production build of the application.
|
|
21
|
+
*/
|
|
16
22
|
function start() {
|
|
17
|
-
console.log("Running start....");
|
|
18
23
|
const dirname = path.resolve(__dirname, "../");
|
|
19
24
|
spawnSync("npm", ["run", "build", `--src_path=${process.env.PWD}`, `--app_name=${name || "catalyst_app"}`], {
|
|
20
25
|
cwd: dirname,
|
|
21
26
|
stdio: "inherit",
|
|
22
27
|
env: _objectSpread(_objectSpread({}, process.env), {}, {
|
|
23
|
-
src_path: process.env.PWD
|
|
28
|
+
src_path: process.env.PWD,
|
|
29
|
+
build_output_path: BUILD_OUTPUT_PATH
|
|
24
30
|
})
|
|
25
31
|
});
|
|
26
32
|
}
|
|
@@ -4,34 +4,21 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
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; }
|
|
9
|
-
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; }
|
|
10
|
-
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
11
|
-
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); }
|
|
12
|
-
const catalystConfig = require("../config/config.js");
|
|
7
|
+
const appConfig = require(`${process.env.src_path}/config/config.json`);
|
|
13
8
|
const {
|
|
14
|
-
validatePackageJson,
|
|
15
9
|
validateConfigFile
|
|
16
|
-
} = require("
|
|
17
|
-
const envConfig = require(`${process.env.src_path}/config/config.json`);
|
|
18
|
-
const packageJSON = require(`${process.env.src_path}/package.json`);
|
|
19
|
-
const env = process.env.NODE_ENV || "developmemt";
|
|
20
|
-
const config = _objectSpread(_objectSpread({}, catalystConfig), validateConfigFile(envConfig) ? envConfig : {});
|
|
10
|
+
} = require("./validator.js");
|
|
21
11
|
|
|
22
12
|
/**
|
|
23
13
|
* @description stores all config.json key value into process.env before server starts.
|
|
24
14
|
*/
|
|
25
15
|
const loadEnvironmentVariables = () => {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
process.env.SERVER_SIDE_RENDER = true;
|
|
33
|
-
if (process.env.BUILD_ENV === "localBuild" && env === "production") {
|
|
34
|
-
process.env.LOCAL_BUILD_PUBLIC_ASSET_PATH = config.SERVER_PATH + config.LOCAL_ASSET_PATH;
|
|
16
|
+
if (validateConfigFile(appConfig)) {
|
|
17
|
+
for (let k in appConfig) {
|
|
18
|
+
// below code provides support for object handling present in config.
|
|
19
|
+
// However, for usage on client the client logic in define plugin needs to be checked and updated
|
|
20
|
+
process.env[k] = typeof appConfig[k] === "object" ? JSON.stringify(appConfig[k]) : appConfig[k];
|
|
21
|
+
}
|
|
35
22
|
}
|
|
36
23
|
};
|
|
37
24
|
var _default = exports.default = loadEnvironmentVariables;
|
|
@@ -4,8 +4,8 @@ var _cssModulesRequireHook = _interopRequireDefault(require("css-modules-require
|
|
|
4
4
|
var _path = _interopRequireDefault(require("path"));
|
|
5
5
|
var _moduleAlias = _interopRequireDefault(require("module-alias"));
|
|
6
6
|
var _loadEnvironmentVariables = _interopRequireDefault(require("./loadEnvironmentVariables"));
|
|
7
|
-
var _logger = require("../logger");
|
|
8
|
-
var _validator = require("./validator");
|
|
7
|
+
var _logger = require("../logger.js");
|
|
8
|
+
var _validator = require("./validator.js");
|
|
9
9
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
10
10
|
const {
|
|
11
11
|
cssModulesIdentifierDev
|
|
@@ -13,41 +13,33 @@ const {
|
|
|
13
13
|
const {
|
|
14
14
|
_moduleAliases
|
|
15
15
|
} = require(`${process.env.src_path}/package.json`);
|
|
16
|
-
//
|
|
17
|
-
// the directory to match the current build directory (e.g. /dist)
|
|
18
|
-
// This ensures that all alises are properly referencing the babel-built
|
|
19
|
-
// server files
|
|
16
|
+
// stores your config keys in enviorments variables
|
|
20
17
|
(0, _loadEnvironmentVariables.default)();
|
|
18
|
+
|
|
19
|
+
// creates logger instance with provided config and stores them at global level.
|
|
21
20
|
(0, _logger.configureLogger)({
|
|
22
21
|
enableDebugLogs: process.env.ENABLE_DEBUG_LOGS,
|
|
23
22
|
enableFileLogging: process.env.ENABLE_FILE_LOGGING,
|
|
24
23
|
enableConsoleLogging: process.env.ENABLE_CONSOLE_LOGGING
|
|
25
24
|
});
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
SERVER_SIDE_RENDER: process.env["SERVER_SIDE_RENDER"] === "true"
|
|
29
|
-
};
|
|
25
|
+
|
|
26
|
+
// resolves module alias imports
|
|
30
27
|
if ((0, _validator.validateModuleAlias)(_moduleAliases)) {
|
|
31
28
|
_moduleAlias.default.addAliases(Object.keys(_moduleAliases || []).reduce((resultMap, aliasName) => {
|
|
32
29
|
const aliasPath = _moduleAliases[aliasName];
|
|
33
|
-
|
|
34
|
-
if (sym === "$") {
|
|
30
|
+
if (aliasPath.includes("server")) {
|
|
35
31
|
if (process.env.NODE_ENV !== "production") {
|
|
36
32
|
resultMap[aliasName] = _path.default.join(process.env.src_path, aliasPath);
|
|
37
33
|
} else {
|
|
38
|
-
resultMap[aliasName] = _path.default.join(process.env.src_path, process.env.
|
|
34
|
+
resultMap[aliasName] = _path.default.join(process.env.src_path, process.env.BUILD_OUTPUT_PATH);
|
|
39
35
|
}
|
|
40
|
-
} else
|
|
41
|
-
resultMap[aliasName] = _path.default.join(process.env.src_path, aliasPath);
|
|
42
|
-
} else {
|
|
43
|
-
resultMap[aliasName] = _path.default.join(process.env.src_path, aliasPath);
|
|
44
|
-
}
|
|
36
|
+
} else resultMap[aliasName] = _path.default.join(process.env.src_path, aliasPath);
|
|
45
37
|
return resultMap;
|
|
46
38
|
}, {}));
|
|
47
39
|
}
|
|
48
|
-
// import hook before routes
|
|
49
40
|
|
|
50
|
-
|
|
41
|
+
// compile css-variables in realtime in dev mode.
|
|
42
|
+
if (process.env.NODE_ENV === "development") (0, _cssModulesRequireHook.default)({
|
|
51
43
|
extensions: [".scss", ".css"],
|
|
52
44
|
generateScopedName: cssModulesIdentifierDev,
|
|
53
45
|
devMode: true,
|
package/scripts/serve.js
CHANGED
|
@@ -6,21 +6,28 @@ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key i
|
|
|
6
6
|
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
7
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
8
|
const {
|
|
9
|
-
spawnSync
|
|
10
|
-
execSync
|
|
9
|
+
spawnSync
|
|
11
10
|
} = require("child_process");
|
|
12
11
|
const path = require("path");
|
|
13
12
|
const {
|
|
14
13
|
name
|
|
15
14
|
} = require(`${process.env.PWD}/package.json`);
|
|
15
|
+
const {
|
|
16
|
+
BUILD_OUTPUT_PATH
|
|
17
|
+
} = require(`${process.env.PWD}/config/config.json`);
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* @description - Serves production build of the application.
|
|
21
|
+
*/
|
|
22
|
+
|
|
16
23
|
function start() {
|
|
17
|
-
console.log("Running start....");
|
|
18
24
|
const dirname = path.resolve(__dirname, "../");
|
|
19
25
|
spawnSync("npm", ["run", "serve", `--src_path=${process.env.PWD}`, `--app_name=${name || "catalyst_app"}`], {
|
|
20
26
|
cwd: dirname,
|
|
21
27
|
stdio: "inherit",
|
|
22
28
|
env: _objectSpread(_objectSpread({}, process.env), {}, {
|
|
23
|
-
src_path: process.env.PWD
|
|
29
|
+
src_path: process.env.PWD,
|
|
30
|
+
build_output_path: BUILD_OUTPUT_PATH
|
|
24
31
|
})
|
|
25
32
|
});
|
|
26
33
|
}
|
package/scripts/start.js
CHANGED
|
@@ -6,16 +6,14 @@ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key i
|
|
|
6
6
|
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
7
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
8
|
const {
|
|
9
|
-
spawnSync
|
|
10
|
-
execSync
|
|
9
|
+
spawnSync
|
|
11
10
|
} = require("child_process");
|
|
12
11
|
const path = require("path");
|
|
13
12
|
|
|
14
13
|
/**
|
|
15
|
-
* @description - starts
|
|
14
|
+
* @description - starts webpack dev server and node server.
|
|
16
15
|
*/
|
|
17
16
|
function start() {
|
|
18
|
-
console.log("Running start....");
|
|
19
17
|
const dirname = path.resolve(__dirname, "../");
|
|
20
18
|
spawnSync("npm", ["run", "start", `--src_path=${process.env.PWD}`], {
|
|
21
19
|
cwd: dirname,
|
package/scripts/validator.js
CHANGED
|
@@ -7,7 +7,7 @@ const handleError = e => {
|
|
|
7
7
|
const validatePreInitServer = fn => {
|
|
8
8
|
try {
|
|
9
9
|
if (!fn) throw new Error("preServerInit named function should be defined in server/index.js");
|
|
10
|
-
if (typeof fn !==
|
|
10
|
+
if (typeof fn !== "function") throw new Error("preServerInit should be function present in server/index.js");
|
|
11
11
|
return true;
|
|
12
12
|
} catch (e) {
|
|
13
13
|
handleError(e);
|
|
@@ -16,7 +16,7 @@ const validatePreInitServer = fn => {
|
|
|
16
16
|
const validateMiddleware = fn => {
|
|
17
17
|
try {
|
|
18
18
|
if (!fn) throw new Error("addMiddlewares named function not found in server/server.js");
|
|
19
|
-
if (typeof fn !==
|
|
19
|
+
if (typeof fn !== "function") throw new Error("addMiddlewares should be function present in server/server.js");
|
|
20
20
|
return true;
|
|
21
21
|
} catch (e) {
|
|
22
22
|
handleError(e);
|
|
@@ -25,7 +25,7 @@ const validateMiddleware = fn => {
|
|
|
25
25
|
const validateReducerFunction = fn => {
|
|
26
26
|
try {
|
|
27
27
|
if (!fn) throw new Error("reducer not found in src/js/containers/App/reducer");
|
|
28
|
-
if (typeof fn !==
|
|
28
|
+
if (typeof fn !== "function") throw new Error("reducer should present in src/js/containers/App/reducer");
|
|
29
29
|
return true;
|
|
30
30
|
} catch (e) {
|
|
31
31
|
handleError(e);
|
|
@@ -34,7 +34,24 @@ const validateReducerFunction = fn => {
|
|
|
34
34
|
const validateConfigFile = obj => {
|
|
35
35
|
try {
|
|
36
36
|
if (!obj) throw new Error("config not found in config folder");
|
|
37
|
-
if (typeof obj !==
|
|
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
|
+
CLIENT_ENV_VARIABLES: [],
|
|
49
|
+
ANALYZE_BUNDLE: ""
|
|
50
|
+
};
|
|
51
|
+
for (let key in requiredConfigKeys) {
|
|
52
|
+
if (!(key in obj)) throw new Error(`${key} key not found inside config.json`);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
38
55
|
return true;
|
|
39
56
|
} catch (e) {
|
|
40
57
|
handleError(e);
|
|
@@ -43,7 +60,7 @@ const validateConfigFile = obj => {
|
|
|
43
60
|
const validatePackageJson = obj => {
|
|
44
61
|
try {
|
|
45
62
|
if (!obj) throw new Error("package.json not found in the project");
|
|
46
|
-
if (typeof obj !==
|
|
63
|
+
if (typeof obj !== "object") throw new Error("package.json should be defined in project root directory");
|
|
47
64
|
return true;
|
|
48
65
|
} catch (e) {
|
|
49
66
|
handleError(e);
|
|
@@ -52,7 +69,20 @@ const validatePackageJson = obj => {
|
|
|
52
69
|
const validateModuleAlias = obj => {
|
|
53
70
|
try {
|
|
54
71
|
if (!obj) throw new Error("moduleAliases not found in package.json file present in root directory.");
|
|
55
|
-
if (typeof obj !==
|
|
72
|
+
if (typeof obj !== "object") throw new Error("moduleAliases named object should be exported from package.json");
|
|
73
|
+
if (typeof obj === "object") {
|
|
74
|
+
const requiredModuleAliases = {
|
|
75
|
+
"@api": "api.js",
|
|
76
|
+
"@containers": "src/js/containers",
|
|
77
|
+
"@server": "server",
|
|
78
|
+
"@config": "config",
|
|
79
|
+
"@css": "src/static/css",
|
|
80
|
+
"@routes": "src/js/routes/"
|
|
81
|
+
};
|
|
82
|
+
for (let key in requiredModuleAliases) {
|
|
83
|
+
if (!(key in obj)) throw new Error(`${key} module alias not defined inside package.json`);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
56
86
|
return true;
|
|
57
87
|
} catch (e) {
|
|
58
88
|
handleError(e);
|
|
@@ -61,7 +91,7 @@ const validateModuleAlias = obj => {
|
|
|
61
91
|
const validateConfigureStore = fn => {
|
|
62
92
|
try {
|
|
63
93
|
if (!fn) throw new Error("configureStore not found in file src/js/store/index.js");
|
|
64
|
-
if (typeof fn !==
|
|
94
|
+
if (typeof fn !== "function") throw new Error("configureStore should be function exported from src/js/store/index.js");
|
|
65
95
|
return true;
|
|
66
96
|
} catch (e) {
|
|
67
97
|
handleError(e);
|
|
@@ -69,8 +99,8 @@ const validateConfigureStore = fn => {
|
|
|
69
99
|
};
|
|
70
100
|
const validateGetRoutes = fn => {
|
|
71
101
|
try {
|
|
72
|
-
if (!fn) throw new Error("getRoutes not found in file src/js/
|
|
73
|
-
if (typeof fn !==
|
|
102
|
+
if (!fn) throw new Error("getRoutes not found in file src/js/routes/utils.js");
|
|
103
|
+
if (typeof fn !== "function") throw new Error("getRoutes should be function exported from src/js/routers/index.js");
|
|
74
104
|
return true;
|
|
75
105
|
} catch (e) {
|
|
76
106
|
handleError(e);
|
|
@@ -79,7 +109,7 @@ const validateGetRoutes = fn => {
|
|
|
79
109
|
const validateCustomDocument = fn => {
|
|
80
110
|
try {
|
|
81
111
|
if (!fn) throw new Error("document not found in file server/document.js");
|
|
82
|
-
if (typeof fn !==
|
|
112
|
+
if (typeof fn !== "function") throw new Error("document should be a react component exported from server/document.js");
|
|
83
113
|
return true;
|
|
84
114
|
} catch (e) {
|
|
85
115
|
handleError(e);
|
|
@@ -90,7 +120,6 @@ module.exports = {
|
|
|
90
120
|
validateConfigureStore,
|
|
91
121
|
validateCustomDocument,
|
|
92
122
|
validateGetRoutes,
|
|
93
|
-
validateModuleAlias,
|
|
94
123
|
validatePackageJson,
|
|
95
124
|
validateReducerFunction,
|
|
96
125
|
validateModuleAlias,
|