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.
- package/.eslintignore +5 -5
- package/.eslintrc +0 -1
- package/.husky/commit-msg +1 -0
- package/.husky/pre-commit +1 -0
- package/babel.config.json +1 -0
- package/bin/catalyst.js +1 -4
- package/caching.js +1 -16
- package/changelog.md +5 -19
- package/commitlint.config.js +11 -0
- package/index.js +1 -16
- package/logger.js +3 -92
- package/package.json +89 -87
- package/router/ClientRouter.js +2 -18
- package/router/ServerRouter.js +1 -19
- package/router.js +1 -16
- package/scripts/build.js +9 -41
- package/scripts/checkVersion.js +1 -5
- package/scripts/devBuild.js +9 -41
- package/scripts/devServe.js +4 -42
- package/scripts/loadEnvironmentVariables.js +4 -23
- package/scripts/loadScriptsBeforeServerStarts.js +5 -47
- package/scripts/resiterAliases.js +29 -0
- package/scripts/scriptUtils.js +2 -0
- package/scripts/serve.js +4 -42
- package/scripts/start.js +5 -34
- package/scripts/validator.js +1 -127
- package/server/expressServer.js +8 -49
- package/server/renderer/document/Body.js +6 -28
- package/server/renderer/document/Head.js +5 -39
- package/server/renderer/document/index.js +1 -27
- package/server/renderer/extract.js +6 -72
- package/server/renderer/handler.js +14 -237
- package/server/renderer/index.js +1 -12
- package/server/renderer/render.js +8 -71
- package/server/startServer.js +6 -66
- package/server/utils/userAgentUtil.js +3 -45
- package/server/utils/validator.js +1 -127
- package/webpack/babel-plugins/remove-client.plugin.js +3 -29
- package/webpack/babel-plugins/remove-ssr.plugin.js +3 -19
- package/webpack/babel.config.client.js +1 -24
- package/webpack/babel.config.ssr.js +1 -24
- package/webpack/base.babel.js +8 -175
- package/webpack/development.client.babel.js +4 -85
- package/webpack/production.client.babel.js +4 -78
- package/webpack/production.ssr.babel.js +4 -61
- package/webpack/scssParams.js +5 -47
- package/router/index.js +0 -32
- package/scripts/prepare.js +0 -19
- package/scripts/registerAliases.js +0 -30
- package/server/mainIndex.js +0 -65
- package/server/mainServer.js +0 -70
- package/server/renderer/userAgentUtil.js +0 -55
- package/server/utils/metaTags.js +0 -13
- package/webpack/babel.config.js +0 -20
- package/webpack/plugins/mime-types.js +0 -82
- package/webpack/plugins/route-manifest-copy.js +0 -122
- package/webpack/plugins/route-manifest-plugin.js +0 -122
- package/webpack/plugins/upload-assets-plugin.js +0 -181
package/scripts/devServe.js
CHANGED
|
@@ -1,43 +1,5 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const {
|
|
4
|
-
spawnSync
|
|
5
|
-
} = require("child_process");
|
|
6
|
-
const path = require("path");
|
|
7
|
-
const {
|
|
8
|
-
name
|
|
9
|
-
} = require(`${process.env.PWD}/package.json`);
|
|
10
|
-
const {
|
|
11
|
-
BUILD_OUTPUT_PATH
|
|
12
|
-
} = require(`${process.env.PWD}/config/config.json`);
|
|
13
|
-
function arrayToObject(array) {
|
|
14
|
-
const obj = {};
|
|
15
|
-
array.forEach(item => {
|
|
16
|
-
const [key, value] = item.split("=");
|
|
17
|
-
if (value) obj[key] = value;
|
|
18
|
-
});
|
|
19
|
-
return obj;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/**
|
|
1
|
+
"use strict";const path=require("path");const{spawnSync}=require("child_process");const{arrayToObject}=require("./scriptUtils");const{name}=require(`${process.env.PWD}/package.json`);const{BUILD_OUTPUT_PATH}=require(`${process.env.PWD}/config/config.json`);/**
|
|
23
2
|
* @description - Serves production build of the application.
|
|
24
|
-
*/
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const commandLineArguments = process.argv.slice(2);
|
|
28
|
-
const argumentsObject = arrayToObject(commandLineArguments);
|
|
29
|
-
const dirname = path.resolve(__dirname, "../");
|
|
30
|
-
spawnSync("npm", ["run", "serve", `--src_path=${process.env.PWD}`, `--app_name=${name || "catalyst_app"}`], {
|
|
31
|
-
cwd: dirname,
|
|
32
|
-
stdio: "inherit",
|
|
33
|
-
env: {
|
|
34
|
-
...process.env,
|
|
35
|
-
src_path: process.env.PWD,
|
|
36
|
-
build_output_path: BUILD_OUTPUT_PATH,
|
|
37
|
-
NODE_ENV: "production",
|
|
38
|
-
IS_DEV_COMMAND: true,
|
|
39
|
-
...argumentsObject
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
start();
|
|
3
|
+
*/function devServe(){const commandLineArguments=process.argv.slice(2);const argumentsObject=arrayToObject(commandLineArguments);const dirname=path.resolve(__dirname,"../");const command=`
|
|
4
|
+
APPLICATION=${name||"catalyst_app"} node -r ./scripts/loadScriptsBeforeServerStarts.js ${process.env.PWD}/${BUILD_OUTPUT_PATH}/startServer.js
|
|
5
|
+
`;spawnSync(command,[],{cwd:dirname,stdio:"inherit",shell:true,env:{...process.env,src_path:process.env.PWD,build_output_path:BUILD_OUTPUT_PATH,NODE_ENV:"production",IS_DEV_COMMAND:true,...argumentsObject}});}devServe();
|
|
@@ -1,24 +1,5 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
const appConfig = require(`${process.env.src_path}/config/config.json`);
|
|
8
|
-
const {
|
|
9
|
-
validateConfigFile
|
|
10
|
-
} = require("./validator.js");
|
|
11
|
-
|
|
12
|
-
/**
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.default=void 0;const appConfig=require(`${process.env.src_path}/config/config.json`);const{validateConfigFile}=require("./validator.js");/**
|
|
13
2
|
* @description stores all config.json key value into process.env before server starts.
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
|
|
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
|
-
}
|
|
22
|
-
}
|
|
23
|
-
};
|
|
24
|
-
var _default = exports.default = loadEnvironmentVariables;
|
|
3
|
+
*/const loadEnvironmentVariables=()=>{if(validateConfigFile(appConfig)){for(let k in appConfig){// below code provides support for object handling present in config.
|
|
4
|
+
// However, for usage on client the client logic in define plugin needs to be checked and updated
|
|
5
|
+
process.env[k]=typeof appConfig[k]==="object"?JSON.stringify(appConfig[k]):appConfig[k];}}};var _default=exports.default=loadEnvironmentVariables;
|
|
@@ -1,47 +1,5 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
var _loadEnvironmentVariables = _interopRequireDefault(require("./loadEnvironmentVariables"));
|
|
7
|
-
var _logger = require("../logger.js");
|
|
8
|
-
var _validator = require("./validator.js");
|
|
9
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
10
|
-
const {
|
|
11
|
-
cssModulesIdentifierDev
|
|
12
|
-
} = require(`${__dirname}/../config.json`);
|
|
13
|
-
const {
|
|
14
|
-
_moduleAliases
|
|
15
|
-
} = require(`${process.env.src_path}/package.json`);
|
|
16
|
-
// stores your config keys in enviorments variables
|
|
17
|
-
(0, _loadEnvironmentVariables.default)();
|
|
18
|
-
|
|
19
|
-
// creates logger instance with provided config and stores them at global level.
|
|
20
|
-
(0, _logger.configureLogger)({
|
|
21
|
-
enableDebugLogs: process.env.ENABLE_DEBUG_LOGS,
|
|
22
|
-
enableFileLogging: process.env.ENABLE_FILE_LOGGING,
|
|
23
|
-
enableConsoleLogging: process.env.ENABLE_CONSOLE_LOGGING
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
// resolves module alias imports
|
|
27
|
-
if ((0, _validator.validateModuleAlias)(_moduleAliases)) {
|
|
28
|
-
_moduleAlias.default.addAliases(Object.keys(_moduleAliases || []).reduce((resultMap, aliasName) => {
|
|
29
|
-
const aliasPath = _moduleAliases[aliasName];
|
|
30
|
-
if (aliasPath.includes("server")) {
|
|
31
|
-
if (process.env.NODE_ENV !== "production") {
|
|
32
|
-
resultMap[aliasName] = _path.default.join(process.env.src_path, aliasPath);
|
|
33
|
-
} else {
|
|
34
|
-
resultMap[aliasName] = _path.default.join(process.env.src_path, process.env.BUILD_OUTPUT_PATH);
|
|
35
|
-
}
|
|
36
|
-
} else resultMap[aliasName] = _path.default.join(process.env.src_path, aliasPath);
|
|
37
|
-
return resultMap;
|
|
38
|
-
}, {}));
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
// compile css-variables in realtime in dev mode.
|
|
42
|
-
if (process.env.NODE_ENV === "development") (0, _cssModulesRequireHook.default)({
|
|
43
|
-
extensions: [".scss", ".css"],
|
|
44
|
-
generateScopedName: cssModulesIdentifierDev,
|
|
45
|
-
devMode: true,
|
|
46
|
-
ignore: _path.default.join(process.env.src_path, "/src/static/css/base/(?!.*.scss$).*")
|
|
47
|
-
});
|
|
1
|
+
"use strict";var _cssModulesRequireHook=_interopRequireDefault(require("@dr.pogodin/css-modules-require-hook"));var _path=_interopRequireDefault(require("path"));var _moduleAlias=_interopRequireDefault(require("module-alias"));var _loadEnvironmentVariables=_interopRequireDefault(require("./loadEnvironmentVariables"));var _logger=require("../logger.js");var _validator=require("./validator.js");function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj};}const{cssModulesIdentifierDev}=require(`${__dirname}/../config.json`);const{_moduleAliases}=require(`${process.env.src_path}/package.json`);// stores your config keys in enviorments variables
|
|
2
|
+
(0,_loadEnvironmentVariables.default)();// creates logger instance with provided config and stores them at global level.
|
|
3
|
+
(0,_logger.configureLogger)({enableDebugLogs:process.env.ENABLE_DEBUG_LOGS,enableFileLogging:process.env.ENABLE_FILE_LOGGING,enableConsoleLogging:process.env.ENABLE_CONSOLE_LOGGING});// resolves module alias imports
|
|
4
|
+
if((0,_validator.validateModuleAlias)(_moduleAliases)){_moduleAlias.default.addAliases(Object.keys(_moduleAliases||[]).reduce((resultMap,aliasName)=>{const aliasPath=_moduleAliases[aliasName];if(aliasPath.includes("server")){if(process.env.NODE_ENV!=="production"){resultMap[aliasName]=_path.default.join(process.env.src_path,aliasPath);}else{resultMap[aliasName]=_path.default.join(process.env.src_path,process.env.BUILD_OUTPUT_PATH);}}else resultMap[aliasName]=_path.default.join(process.env.src_path,aliasPath);return resultMap;},{}));}// compile css-variables in realtime in dev mode.
|
|
5
|
+
if(process.env.NODE_ENV==="development")(0,_cssModulesRequireHook.default)({extensions:[".scss",".css"],generateScopedName:cssModulesIdentifierDev,devMode:true,ignore:_path.default.join(process.env.src_path,"/src/static/css/base/(?!.*.scss$).*")});
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import path from "path"
|
|
2
|
+
import moduleAlias from "module-alias"
|
|
3
|
+
import { _moduleAliases } from "../../package.json"
|
|
4
|
+
|
|
5
|
+
export const getTemplatePath = (file) => {
|
|
6
|
+
if (file) return path.resolve(__dirname, process.env.src_path, file)
|
|
7
|
+
else return path.resolve(__dirname, process.env.src_path)
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const getCatalystPath = (file) => {
|
|
11
|
+
if (file) return path.resolve(__dirname, "../", file)
|
|
12
|
+
else return path.resolve(__dirname, "..")
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
moduleAlias.addAliases(
|
|
16
|
+
Object.keys(_moduleAliases || []).reduce((resultMap, aliasName) => {
|
|
17
|
+
const aliasPath = _moduleAliases[aliasName]
|
|
18
|
+
|
|
19
|
+
if (aliasName.includes("@template")) {
|
|
20
|
+
resultMap[aliasName] = path.join(__dirname, process.env.src_path, aliasPath)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (aliasName.includes("@catalyst")) {
|
|
24
|
+
resultMap[aliasName] = path.join(__dirname, "../", aliasPath)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return resultMap
|
|
28
|
+
}, {})
|
|
29
|
+
)
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.arrayToObject=arrayToObject;exports.printBundleInformation=void 0;const fs=require("fs");const path=require("path");const util=require("node:util");const{gray,cyan}=require("picocolors");const{BUILD_OUTPUT_PATH}=require(`${process.env.PWD}/config/config.json`);// Function to get file size synchronously
|
|
2
|
+
function getFileSizeSync(filePath){try{const stats=fs.statSync(filePath);return stats.size;}catch(err){console.error(`Error getting bundle information for file ${filePath}: ${err}`);return null;}}const printBundleInformation=()=>{let bundleList=[];const directoryPath=path.join(process.env.PWD,`${BUILD_OUTPUT_PATH}/public`);try{const files=fs.readdirSync(directoryPath);files.forEach(file=>{if(!file.includes("txt")&&!file.includes("json")){const filePath=path.join(directoryPath,file);const fileSize=getFileSizeSync(filePath);if(fileSize!==null){bundleList.push({file,fileSize});}}});}catch(err){console.error("Unable to scan build folder: "+err);}bundleList.sort((a,b)=>b.fileSize-a.fileSize);bundleList.forEach(({file,fileSize})=>{const fileName=`${gray(`${BUILD_OUTPUT_PATH}/public/`)}${cyan(file)}`;const fileSizeInKb=(fileSize/1024).toFixed(2);const size=`\t${fileSizeInKb} kB`.padEnd(16);console.log(util.format(size,fileName));});};exports.printBundleInformation=printBundleInformation;function arrayToObject(array){const obj={};array.forEach(item=>{const[key,value]=item.split("=");if(value)obj[key]=value;});return obj;}
|
package/scripts/serve.js
CHANGED
|
@@ -1,43 +1,5 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const {
|
|
4
|
-
spawnSync
|
|
5
|
-
} = require("child_process");
|
|
6
|
-
const path = require("path");
|
|
7
|
-
const {
|
|
8
|
-
name
|
|
9
|
-
} = require(`${process.env.PWD}/package.json`);
|
|
10
|
-
const {
|
|
11
|
-
BUILD_OUTPUT_PATH
|
|
12
|
-
} = require(`${process.env.PWD}/config/config.json`);
|
|
13
|
-
function arrayToObject(array) {
|
|
14
|
-
const obj = {};
|
|
15
|
-
array.forEach(item => {
|
|
16
|
-
const [key, value] = item.split("=");
|
|
17
|
-
if (value) obj[key] = value;
|
|
18
|
-
});
|
|
19
|
-
return obj;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/**
|
|
1
|
+
"use strict";const path=require("path");const{spawnSync}=require("child_process");const{arrayToObject}=require("./scriptUtils");const{name}=require(`${process.env.PWD}/package.json`);const{BUILD_OUTPUT_PATH}=require(`${process.env.PWD}/config/config.json`);/**
|
|
23
2
|
* @description - Serves production build of the application.
|
|
24
|
-
*/
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const commandLineArguments = process.argv.slice(2);
|
|
28
|
-
const argumentsObject = arrayToObject(commandLineArguments);
|
|
29
|
-
const dirname = path.resolve(__dirname, "../");
|
|
30
|
-
spawnSync("npm", ["run", "serve", `--src_path=${process.env.PWD}`, `--app_name=${name || "catalyst_app"}`], {
|
|
31
|
-
cwd: dirname,
|
|
32
|
-
stdio: "inherit",
|
|
33
|
-
env: {
|
|
34
|
-
...process.env,
|
|
35
|
-
src_path: process.env.PWD,
|
|
36
|
-
build_output_path: BUILD_OUTPUT_PATH,
|
|
37
|
-
NODE_ENV: "production",
|
|
38
|
-
IS_DEV_COMMAND: false,
|
|
39
|
-
...argumentsObject
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
start();
|
|
3
|
+
*/function serve(){const commandLineArguments=process.argv.slice(2);const argumentsObject=arrayToObject(commandLineArguments);const dirname=path.resolve(__dirname,"../");const command=`
|
|
4
|
+
APPLICATION=${name||"catalyst_app"} node -r ./scripts/loadScriptsBeforeServerStarts.js ${process.env.PWD}/${BUILD_OUTPUT_PATH}/startServer.js
|
|
5
|
+
`;spawnSync(command,[],{cwd:dirname,stdio:"inherit",shell:true,env:{...process.env,src_path:process.env.PWD,build_output_path:BUILD_OUTPUT_PATH,NODE_ENV:"production",IS_DEV_COMMAND:false,...argumentsObject}});}serve();
|
package/scripts/start.js
CHANGED
|
@@ -1,35 +1,6 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const {
|
|
4
|
-
spawnSync
|
|
5
|
-
} = require("child_process");
|
|
6
|
-
const path = require("path");
|
|
7
|
-
function arrayToObject(array) {
|
|
8
|
-
const obj = {};
|
|
9
|
-
array.forEach(item => {
|
|
10
|
-
const [key, value] = item.split("=");
|
|
11
|
-
if (value) obj[key] = value;
|
|
12
|
-
});
|
|
13
|
-
return obj;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
/**
|
|
1
|
+
"use strict";const path=require("path");const{spawnSync}=require("child_process");const{arrayToObject}=require("./scriptUtils");const{name}=require(`${process.env.PWD}/package.json`);/**
|
|
17
2
|
* @description - starts webpack dev server and node server.
|
|
18
|
-
*/
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
const dirname = path.resolve(__dirname, "../");
|
|
23
|
-
spawnSync("npm", ["run", "start", `--src_path=${process.env.PWD}`], {
|
|
24
|
-
cwd: dirname,
|
|
25
|
-
stdio: "inherit",
|
|
26
|
-
env: {
|
|
27
|
-
...process.env,
|
|
28
|
-
src_path: process.env.PWD,
|
|
29
|
-
NODE_ENV: "development",
|
|
30
|
-
IS_DEV_COMMAND: false,
|
|
31
|
-
...argumentsObject
|
|
32
|
-
}
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
start();
|
|
3
|
+
*/function start(){const commandLineArguments=process.argv.slice(2);const argumentsObject=arrayToObject(commandLineArguments);const dirname=path.resolve(__dirname,"../");const command=`
|
|
4
|
+
node ./scripts/checkVersion
|
|
5
|
+
npx babel-node -r ./scripts/loadScriptsBeforeServerStarts.js webpack/development.client.babel --no-warnings=ExperimentalWarning --no-warnings=BABEL & npx babel-node -r ./scripts/loadScriptsBeforeServerStarts.js ./server/startServer.js --watch-path=${process.env.PWD}/server --watch-path=${process.env.PWD}/src --ignore='__IGNORE__' --no-warnings=ExperimentalWarning --no-warnings=BABEL
|
|
6
|
+
`;spawnSync(command,[],{cwd:dirname,stdio:"inherit",shell:true,env:{...process.env,src_path:process.env.PWD,NODE_ENV:"development",IS_DEV_COMMAND:false,APPLICATION:name||"catalyst_app",...argumentsObject}});}start();
|
package/scripts/validator.js
CHANGED
|
@@ -1,127 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const pc = require("picocolors");
|
|
4
|
-
const handleError = e => {
|
|
5
|
-
console.log(pc.red("Failed to start server: "), e);
|
|
6
|
-
};
|
|
7
|
-
const validatePreInitServer = fn => {
|
|
8
|
-
try {
|
|
9
|
-
if (!fn) throw new Error("preServerInit named function should be defined in server/index.js");
|
|
10
|
-
if (typeof fn !== "function") throw new Error("preServerInit should be function present in server/index.js");
|
|
11
|
-
return true;
|
|
12
|
-
} catch (e) {
|
|
13
|
-
handleError(e);
|
|
14
|
-
}
|
|
15
|
-
};
|
|
16
|
-
const validateMiddleware = fn => {
|
|
17
|
-
try {
|
|
18
|
-
if (!fn) throw new Error("addMiddlewares named function not found in server/server.js");
|
|
19
|
-
if (typeof fn !== "function") throw new Error("addMiddlewares should be function present in server/server.js");
|
|
20
|
-
return true;
|
|
21
|
-
} catch (e) {
|
|
22
|
-
handleError(e);
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
|
-
const validateReducerFunction = fn => {
|
|
26
|
-
try {
|
|
27
|
-
if (!fn) throw new Error("reducer not found in src/js/containers/App/reducer");
|
|
28
|
-
if (typeof fn !== "function") throw new Error("reducer should present in src/js/containers/App/reducer");
|
|
29
|
-
return true;
|
|
30
|
-
} catch (e) {
|
|
31
|
-
handleError(e);
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
const validateConfigFile = obj => {
|
|
35
|
-
try {
|
|
36
|
-
if (!obj) throw new Error("config not found in config folder");
|
|
37
|
-
if (typeof obj !== "object") throw new Error("config object should be exported from config folder inside your project root directory");
|
|
38
|
-
if (typeof obj === "object") {
|
|
39
|
-
const requiredConfigKeys = {
|
|
40
|
-
NODE_SERVER_HOSTNAME: "",
|
|
41
|
-
NODE_SERVER_PORT: "",
|
|
42
|
-
WEBPACK_DEV_SERVER_HOSTNAME: "",
|
|
43
|
-
WEBPACK_DEV_SERVER_PORT: "",
|
|
44
|
-
BUILD_OUTPUT_PATH: "",
|
|
45
|
-
PUBLIC_STATIC_ASSET_PATH: "",
|
|
46
|
-
PUBLIC_STATIC_ASSET_URL: "",
|
|
47
|
-
CLIENT_ENV_VARIABLES: [],
|
|
48
|
-
ANALYZE_BUNDLE: ""
|
|
49
|
-
};
|
|
50
|
-
for (let key in requiredConfigKeys) {
|
|
51
|
-
if (!(key in obj)) throw new Error(`${key} key not found inside config.json`);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
return true;
|
|
55
|
-
} catch (e) {
|
|
56
|
-
handleError(e);
|
|
57
|
-
}
|
|
58
|
-
};
|
|
59
|
-
const validatePackageJson = obj => {
|
|
60
|
-
try {
|
|
61
|
-
if (!obj) throw new Error("package.json not found in the project");
|
|
62
|
-
if (typeof obj !== "object") throw new Error("package.json should be defined in project root directory");
|
|
63
|
-
return true;
|
|
64
|
-
} catch (e) {
|
|
65
|
-
handleError(e);
|
|
66
|
-
}
|
|
67
|
-
};
|
|
68
|
-
const validateModuleAlias = obj => {
|
|
69
|
-
try {
|
|
70
|
-
if (!obj) throw new Error("moduleAliases not found in package.json file present in root directory.");
|
|
71
|
-
if (typeof obj !== "object") throw new Error("moduleAliases named object should be exported from package.json");
|
|
72
|
-
if (typeof obj === "object") {
|
|
73
|
-
const requiredModuleAliases = {
|
|
74
|
-
"@api": "api.js",
|
|
75
|
-
"@containers": "src/js/containers",
|
|
76
|
-
"@server": "server",
|
|
77
|
-
"@config": "config",
|
|
78
|
-
"@css": "src/static/css",
|
|
79
|
-
"@routes": "src/js/routes/"
|
|
80
|
-
};
|
|
81
|
-
for (let key in requiredModuleAliases) {
|
|
82
|
-
if (!(key in obj)) throw new Error(`${key} module alias not defined inside package.json`);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
return true;
|
|
86
|
-
} catch (e) {
|
|
87
|
-
handleError(e);
|
|
88
|
-
}
|
|
89
|
-
};
|
|
90
|
-
const validateConfigureStore = fn => {
|
|
91
|
-
try {
|
|
92
|
-
if (!fn) throw new Error("configureStore not found in file src/js/store/index.js");
|
|
93
|
-
if (typeof fn !== "function") throw new Error("configureStore should be function exported from src/js/store/index.js");
|
|
94
|
-
return true;
|
|
95
|
-
} catch (e) {
|
|
96
|
-
handleError(e);
|
|
97
|
-
}
|
|
98
|
-
};
|
|
99
|
-
const validateGetRoutes = fn => {
|
|
100
|
-
try {
|
|
101
|
-
if (!fn) throw new Error("getRoutes not found in file src/js/routes/utils.js");
|
|
102
|
-
if (typeof fn !== "function") throw new Error("getRoutes should be function exported from src/js/routers/index.js");
|
|
103
|
-
return true;
|
|
104
|
-
} catch (e) {
|
|
105
|
-
handleError(e);
|
|
106
|
-
}
|
|
107
|
-
};
|
|
108
|
-
const validateCustomDocument = fn => {
|
|
109
|
-
try {
|
|
110
|
-
if (!fn) throw new Error("document not found in file server/document.js");
|
|
111
|
-
if (typeof fn !== "function") throw new Error("document should be a react component exported from server/document.js");
|
|
112
|
-
return true;
|
|
113
|
-
} catch (e) {
|
|
114
|
-
handleError(e);
|
|
115
|
-
}
|
|
116
|
-
};
|
|
117
|
-
module.exports = {
|
|
118
|
-
validateConfigFile,
|
|
119
|
-
validateConfigureStore,
|
|
120
|
-
validateCustomDocument,
|
|
121
|
-
validateGetRoutes,
|
|
122
|
-
validatePackageJson,
|
|
123
|
-
validateReducerFunction,
|
|
124
|
-
validateModuleAlias,
|
|
125
|
-
validatePreInitServer,
|
|
126
|
-
validateMiddleware
|
|
127
|
-
};
|
|
1
|
+
"use strict";const pc=require("picocolors");const handleError=e=>{console.log(pc.red("Failed to start server: "),e);};const validatePreInitServer=fn=>{try{if(!fn)throw new Error("preServerInit named function should be defined in server/index.js");if(typeof fn!=="function")throw new Error("preServerInit should be function present in server/index.js");return true;}catch(e){handleError(e);}};const validateMiddleware=fn=>{try{if(!fn)throw new Error("addMiddlewares named function not found in server/server.js");if(typeof fn!=="function")throw new Error("addMiddlewares should be function present in server/server.js");return true;}catch(e){handleError(e);}};const validateReducerFunction=fn=>{try{if(!fn)throw new Error("reducer not found in src/js/containers/App/reducer");if(typeof fn!=="function")throw new Error("reducer should present in src/js/containers/App/reducer");return true;}catch(e){handleError(e);}};const validateConfigFile=obj=>{try{if(!obj)throw new Error("config not found in config folder");if(typeof obj!=="object")throw new Error("config object should be exported from config folder inside your project root directory");if(typeof obj==="object"){const requiredConfigKeys={NODE_SERVER_HOSTNAME:"",NODE_SERVER_PORT:"",WEBPACK_DEV_SERVER_HOSTNAME:"",WEBPACK_DEV_SERVER_PORT:"",BUILD_OUTPUT_PATH:"",PUBLIC_STATIC_ASSET_PATH:"",PUBLIC_STATIC_ASSET_URL:"",CLIENT_ENV_VARIABLES:[],ANALYZE_BUNDLE:""};for(let key in requiredConfigKeys){if(!(key in obj))throw new Error(`${key} key not found inside config.json`);}}return true;}catch(e){handleError(e);}};const validatePackageJson=obj=>{try{if(!obj)throw new Error("package.json not found in the project");if(typeof obj!=="object")throw new Error("package.json should be defined in project root directory");return true;}catch(e){handleError(e);}};const validateModuleAlias=obj=>{try{if(!obj)throw new Error("moduleAliases not found in package.json file present in root directory.");if(typeof obj!=="object")throw new Error("moduleAliases named object should be exported from package.json");if(typeof obj==="object"){const requiredModuleAliases={"@api":"api.js","@containers":"src/js/containers","@server":"server","@config":"config","@css":"src/static/css","@routes":"src/js/routes/"};for(let key in requiredModuleAliases){if(!(key in obj))throw new Error(`${key} module alias not defined inside package.json`);}}return true;}catch(e){handleError(e);}};const validateConfigureStore=fn=>{try{if(!fn)throw new Error("configureStore not found in file src/js/store/index.js");if(typeof fn!=="function")throw new Error("configureStore should be function exported from src/js/store/index.js");return true;}catch(e){handleError(e);}};const validateGetRoutes=fn=>{try{if(!fn)throw new Error("getRoutes not found in file src/js/routes/utils.js");if(typeof fn!=="function")throw new Error("getRoutes should be function exported from src/js/routers/index.js");return true;}catch(e){handleError(e);}};const validateCustomDocument=fn=>{try{if(!fn)throw new Error("document not found in file server/document.js");if(typeof fn!=="function")throw new Error("document should be a react component exported from server/document.js");return true;}catch(e){handleError(e);}};module.exports={validateConfigFile,validateConfigureStore,validateCustomDocument,validateGetRoutes,validatePackageJson,validateReducerFunction,validateModuleAlias,validatePreInitServer,validateMiddleware};
|
package/server/expressServer.js
CHANGED
|
@@ -1,50 +1,9 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
var _path = _interopRequireDefault(require("path"));
|
|
8
|
-
var _express = _interopRequireDefault(require("express"));
|
|
9
|
-
var _bodyParser = _interopRequireDefault(require("body-parser"));
|
|
10
|
-
var _compression = _interopRequireDefault(require("compression"));
|
|
11
|
-
var _cookieParser = _interopRequireDefault(require("cookie-parser"));
|
|
12
|
-
var _expressStaticGzip = _interopRequireDefault(require("express-static-gzip"));
|
|
13
|
-
var _renderer = _interopRequireDefault(require("./renderer"));
|
|
14
|
-
var _server = require("@server/server.js");
|
|
15
|
-
var _validator = require("./utils/validator");
|
|
16
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
17
|
-
const env = process.env.NODE_ENV || "development";
|
|
18
|
-
const app = (0, _express.default)();
|
|
19
|
-
|
|
20
|
-
// This middleware is being used to extract the body of the request
|
|
21
|
-
app.use(_bodyParser.default.json());
|
|
22
|
-
|
|
23
|
-
// This middleware has been added to accommodate “byetstream array”
|
|
24
|
-
app.use(_bodyParser.default.raw({
|
|
25
|
-
type: "application/*"
|
|
26
|
-
}));
|
|
27
|
-
|
|
28
|
-
// This middleware is being used to parse cookies!
|
|
29
|
-
app.use((0, _cookieParser.default)());
|
|
30
|
-
|
|
31
|
-
// All the middlewares defined by the user will run here.
|
|
32
|
-
if ((0, _validator.validateMiddleware)(_server.addMiddlewares)) (0, _server.addMiddlewares)(app);
|
|
33
|
-
|
|
34
|
-
// The middleware will attempt to compress response bodies for all request that traverse through the middleware
|
|
35
|
-
app.use((0, _compression.default)());
|
|
36
|
-
|
|
37
|
-
// This endpoint will serve the built assets from the node server. The requests will be made to PUBLIC_STATIC_ASSET_PATH which has been defined in the application config.
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.default=void 0;var _path=_interopRequireDefault(require("path"));var _express=_interopRequireDefault(require("express"));var _bodyParser=_interopRequireDefault(require("body-parser"));var _compression=_interopRequireDefault(require("compression"));var _cookieParser=_interopRequireDefault(require("cookie-parser"));var _expressStaticGzip=_interopRequireDefault(require("express-static-gzip"));var _renderer=_interopRequireDefault(require("./renderer"));var _server=require("@server/server.js");var _validator=require("./utils/validator");function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj};}const env=process.env.NODE_ENV||"development";const app=(0,_express.default)();// This middleware is being used to extract the body of the request
|
|
2
|
+
app.use(_bodyParser.default.json());// This middleware has been added to accommodate “byetstream array”
|
|
3
|
+
app.use(_bodyParser.default.raw({type:"application/*"}));// This middleware is being used to parse cookies!
|
|
4
|
+
app.use((0,_cookieParser.default)());// All the middlewares defined by the user will run here.
|
|
5
|
+
if((0,_validator.validateMiddleware)(_server.addMiddlewares))(0,_server.addMiddlewares)(app);// The middleware will attempt to compress response bodies for all request that traverse through the middleware
|
|
6
|
+
app.use((0,_compression.default)());// This endpoint will serve the built assets from the node server. The requests will be made to PUBLIC_STATIC_ASSET_PATH which has been defined in the application config.
|
|
38
7
|
// expressStaticGzip will compress the assets.
|
|
39
|
-
if
|
|
40
|
-
|
|
41
|
-
enableBrotli: true,
|
|
42
|
-
orderPreference: ["br", "gzip", "deflate"]
|
|
43
|
-
}));
|
|
44
|
-
} else {
|
|
45
|
-
app.use(process.env.PUBLIC_STATIC_ASSET_PATH, _express.default.static(_path.default.join(process.env.src_path, `./${process.env.BUILD_OUTPUT_PATH}/public`)));
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
// This middleware handles document requests.
|
|
49
|
-
app.use("*", _renderer.default);
|
|
50
|
-
var _default = exports.default = app;
|
|
8
|
+
if(env==="production"){app.use(process.env.PUBLIC_STATIC_ASSET_PATH,(0,_expressStaticGzip.default)(_path.default.join(process.env.src_path,`./${process.env.BUILD_OUTPUT_PATH}/public`),{enableBrotli:true,orderPreference:["br","gzip","deflate"]}));}else{app.use(process.env.PUBLIC_STATIC_ASSET_PATH,_express.default.static(_path.default.join(process.env.src_path,`./${process.env.BUILD_OUTPUT_PATH}/public`)));}// This middleware handles document requests.
|
|
9
|
+
app.use("*",_renderer.default);var _default=exports.default=app;
|
|
@@ -1,36 +1,14 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.Body = Body;
|
|
7
|
-
var _react = _interopRequireDefault(require("react"));
|
|
8
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
9
|
-
/**
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.Body=Body;var _react=_interopRequireDefault(require("react"));var _propTypes=_interopRequireDefault(require("prop-types"));function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj};}/**
|
|
10
2
|
* Body component which will be used in page component
|
|
3
|
+
* @param {object} jsx - page jsx code
|
|
4
|
+
* @param {object} statusCode - document request status code
|
|
11
5
|
* @param {object} initialState - initial state object for redux store
|
|
12
6
|
* @param {object} firstFoldCss - style elements extracted for initial page load
|
|
13
7
|
* @param {object} firstFoldJS - javascript elements extracted for initial page load
|
|
14
|
-
* @param {object} jsx - page jsx code
|
|
15
|
-
* @param {object} statusCode - document request status code
|
|
16
8
|
* @param {object} fetcherData - contains data from executing serverFetcher function
|
|
17
|
-
|
|
18
|
-
function Body(props) {
|
|
19
|
-
const {
|
|
20
|
-
initialState = {},
|
|
21
|
-
statusCode = "",
|
|
22
|
-
firstFoldCss = "",
|
|
23
|
-
firstFoldJS = "",
|
|
24
|
-
jsx = "",
|
|
25
|
-
fetcherData = {}
|
|
26
|
-
} = props;
|
|
27
|
-
return /*#__PURE__*/_react.default.createElement("body", null, firstFoldCss, firstFoldJS, jsx, /*#__PURE__*/_react.default.createElement("script", {
|
|
28
|
-
dangerouslySetInnerHTML: {
|
|
29
|
-
__html: `
|
|
9
|
+
* @param {object} children - contains any child elements defined within the component
|
|
10
|
+
*/function Body(props){const{jsx="",statusCode="",initialState={},firstFoldCss="",firstFoldJS="",fetcherData={},children}=props;return/*#__PURE__*/_react.default.createElement("body",null,firstFoldCss,firstFoldJS,jsx,/*#__PURE__*/_react.default.createElement("script",{/* eslint-disable */dangerouslySetInnerHTML:{__html:`
|
|
30
11
|
window.__INITIAL_STATE__ = ${JSON.stringify(initialState)}
|
|
31
12
|
window.__STATUS_CODE__ = ${statusCode}
|
|
32
13
|
window.__ROUTER_INITIAL_DATA__ = ${JSON.stringify(fetcherData)}
|
|
33
|
-
`
|
|
34
|
-
}
|
|
35
|
-
}), props.children);
|
|
36
|
-
}
|
|
14
|
+
`}}),children);}Body.propTypes={initialState:_propTypes.default.object,firstFoldCss:_propTypes.default.any,firstFoldJS:_propTypes.default.any,jsx:_propTypes.default.any,statusCode:_propTypes.default.string,fetcherData:_propTypes.default.object,children:_propTypes.default.node};
|
|
@@ -1,43 +1,9 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.Head = Head;
|
|
7
|
-
var _react = _interopRequireDefault(require("react"));
|
|
8
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
9
|
-
/**
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.Head=Head;var _react=_interopRequireDefault(require("react"));var _propTypes=_interopRequireDefault(require("prop-types"));function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj};}/**
|
|
10
2
|
* Head component which will be used in page rendering
|
|
3
|
+
* @param {boolean} isBot - checks if request is made by bot
|
|
11
4
|
* @param {string} pageCss - includes all styles for page css
|
|
12
5
|
* @param {object} pageJS - async scripts for loading chunks
|
|
13
|
-
* @param {
|
|
14
|
-
* @param {boolean} isBot - checks if request is made by bot
|
|
6
|
+
* @param {array} metaTags - user defined function which returns meta tags in array
|
|
15
7
|
* @param {string} publicAssetPath - public asset path for assets
|
|
16
|
-
* @param {object}
|
|
17
|
-
*/
|
|
18
|
-
function Head(props) {
|
|
19
|
-
const {
|
|
20
|
-
pageCss,
|
|
21
|
-
pageJS,
|
|
22
|
-
metaTags,
|
|
23
|
-
isBot,
|
|
24
|
-
publicAssetPath,
|
|
25
|
-
fetcherData
|
|
26
|
-
} = props;
|
|
27
|
-
return /*#__PURE__*/_react.default.createElement("head", null, /*#__PURE__*/_react.default.createElement("meta", {
|
|
28
|
-
charSet: "utf-8"
|
|
29
|
-
}), /*#__PURE__*/_react.default.createElement("meta", {
|
|
30
|
-
name: "viewport",
|
|
31
|
-
content: "width=device-width, initial-scale=1"
|
|
32
|
-
}), publicAssetPath && /*#__PURE__*/_react.default.createElement("link", {
|
|
33
|
-
rel: "preconnect",
|
|
34
|
-
href: publicAssetPath
|
|
35
|
-
}), publicAssetPath && /*#__PURE__*/_react.default.createElement("link", {
|
|
36
|
-
rel: "dns-prefetch",
|
|
37
|
-
href: publicAssetPath
|
|
38
|
-
}), metaTags && metaTags, !isBot && pageJS, !isBot && /*#__PURE__*/_react.default.createElement("style", {
|
|
39
|
-
dangerouslySetInnerHTML: {
|
|
40
|
-
__html: pageCss
|
|
41
|
-
}
|
|
42
|
-
}), props.children);
|
|
43
|
-
}
|
|
8
|
+
* @param {object} children - contains any child elements defined within the component
|
|
9
|
+
*/function Head(props){const{pageCss,pageJS,metaTags,isBot,publicAssetPath,children}=props;return/*#__PURE__*/_react.default.createElement("head",null,/*#__PURE__*/_react.default.createElement("meta",{charSet:"utf-8"}),/*#__PURE__*/_react.default.createElement("meta",{name:"viewport",content:"width=device-width, initial-scale=1"}),publicAssetPath&&/*#__PURE__*/_react.default.createElement("link",{rel:"preconnect",href:publicAssetPath}),publicAssetPath&&/*#__PURE__*/_react.default.createElement("link",{rel:"dns-prefetch",href:publicAssetPath}),metaTags&&metaTags,!isBot&&pageJS,!isBot&&pageCss&&/*#__PURE__*/_react.default.createElement("style",{dangerouslySetInnerHTML:{__html:pageCss}}),children);}Head.propTypes={isBot:_propTypes.default.bool,pageJS:_propTypes.default.object,pageCss:_propTypes.default.string,metaTags:_propTypes.default.array,publicAssetPath:_propTypes.default.string,children:_propTypes.default.node};
|
|
@@ -1,27 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
var _Head = require("./Head");
|
|
7
|
-
Object.keys(_Head).forEach(function (key) {
|
|
8
|
-
if (key === "default" || key === "__esModule") return;
|
|
9
|
-
if (key in exports && exports[key] === _Head[key]) return;
|
|
10
|
-
Object.defineProperty(exports, key, {
|
|
11
|
-
enumerable: true,
|
|
12
|
-
get: function () {
|
|
13
|
-
return _Head[key];
|
|
14
|
-
}
|
|
15
|
-
});
|
|
16
|
-
});
|
|
17
|
-
var _Body = require("./Body");
|
|
18
|
-
Object.keys(_Body).forEach(function (key) {
|
|
19
|
-
if (key === "default" || key === "__esModule") return;
|
|
20
|
-
if (key in exports && exports[key] === _Body[key]) return;
|
|
21
|
-
Object.defineProperty(exports, key, {
|
|
22
|
-
enumerable: true,
|
|
23
|
-
get: function () {
|
|
24
|
-
return _Body[key];
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
});
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});var _Head=require("./Head");Object.keys(_Head).forEach(function(key){if(key==="default"||key==="__esModule")return;if(key in exports&&exports[key]===_Head[key])return;Object.defineProperty(exports,key,{enumerable:true,get:function(){return _Head[key];}});});var _Body=require("./Body");Object.keys(_Body).forEach(function(key){if(key==="default"||key==="__esModule")return;if(key in exports&&exports[key]===_Body[key])return;Object.defineProperty(exports,key,{enumerable:true,get:function(){return _Body[key];}});});
|