catalyst-core-internal 0.0.1-beta.2 → 0.0.1-beta.21
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 +9 -0
- package/.eslintrc +91 -0
- package/.husky/commit-msg +1 -0
- package/.husky/pre-commit +1 -0
- package/README.md +45 -43
- package/babel.config.json +2 -5
- package/bin/catalyst.js +33 -35
- package/caching.js +1 -16
- package/changelog.md +12 -0
- package/commitlint.config.js +11 -0
- package/config.json +1 -1
- package/index.js +1 -16
- package/license +10 -0
- package/logger.js +3 -89
- package/package.json +89 -83
- package/router/ClientRouter.js +2 -18
- package/router/ServerRouter.js +1 -19
- package/router.js +1 -16
- package/scripts/build.js +9 -28
- package/scripts/checkVersion.js +1 -5
- package/scripts/devBuild.js +10 -0
- package/scripts/devServe.js +5 -0
- 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 -29
- package/scripts/start.js +5 -25
- package/scripts/validator.js +1 -130
- 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 -241
- package/server/renderer/index.js +1 -12
- package/server/renderer/render.js +8 -60
- package/server/startServer.js +6 -65
- package/server/utils/userAgentUtil.js +3 -49
- package/server/utils/validator.js +1 -130
- 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 -167
- package/webpack/development.client.babel.js +4 -82
- package/webpack/production.client.babel.js +4 -78
- package/webpack/production.ssr.babel.js +4 -61
- package/webpack/scssParams.js +5 -31
- package/packages/create-framework-app/templates/redux-js/node_modules/@babel/core/lib/config/caching.js +0 -261
- package/packages/create-framework-app/templates/redux-js/node_modules/@remix-run/router/dist/router.js +0 -4327
- package/packages/create-framework-app/templates/redux-js/node_modules/catalyst/router.js +0 -15
- package/packages/create-framework-app/templates/redux-js/node_modules/catalyst/src/router.js +0 -1
- package/packages/create-framework-app/templates/redux-js/node_modules/http-proxy-middleware/dist/router.js +0 -46
- 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/types/caching.d.ts +0 -1
- package/types/config/config.d.ts +0 -19
- package/types/index.d.ts +0 -1
- package/types/logger/index.d.ts +0 -14
- package/types/reducer/index.d.ts +0 -22
- package/types/reducer/loadableConfigReducer.d.ts +0 -9
- package/types/router/ClientRouter.d.ts +0 -5
- package/types/router/ServerRouter.d.ts +0 -7
- package/types/router/index.d.ts +0 -8
- package/types/router.d.ts +0 -1
- package/types/scripts/build.d.ts +0 -1
- package/types/scripts/loadEnvironmentVariables.d.ts +0 -5
- package/types/scripts/loadScriptsBeforeServerStarts.d.ts +0 -1
- package/types/scripts/prepare.d.ts +0 -1
- package/types/scripts/registerAliases.d.ts +0 -1
- package/types/scripts/serve.d.ts +0 -1
- package/types/scripts/start.d.ts +0 -1
- package/types/scripts/validator.d.ts +0 -9
- package/types/scripts/verifyConfig.d.ts +0 -1
- package/types/server/mainIndex.d.ts +0 -1
- package/types/server/mainServer.d.ts +0 -2
- package/types/server/renderer/document/Body.d.ts +0 -11
- package/types/server/renderer/document/Head.d.ts +0 -11
- package/types/server/renderer/document/index.d.ts +0 -2
- package/types/server/renderer/extract.d.ts +0 -18
- package/types/server/renderer/handler.d.ts +0 -6
- package/types/server/renderer/index.d.ts +0 -2
- package/types/server/renderer/render.d.ts +0 -38
- package/types/server/renderer/userAgentUtil.d.ts +0 -1
- package/types/store/index.d.ts +0 -11
- package/types/store/index.dev.d.ts +0 -8
- package/types/store/index.prod.d.ts +0 -8
- package/types/webpack/babel-plugins/remove-client.plugin.d.ts +0 -10
- package/types/webpack/babel-plugins/remove-ssr.plugin.d.ts +0 -10
- package/types/webpack/babel.config.client.d.ts +0 -21
- package/types/webpack/babel.config.d.ts +0 -16
- package/types/webpack/babel.config.ssr.d.ts +0 -21
- package/types/webpack/base.babel.d.ts +0 -184
- package/types/webpack/development.client.babel.d.ts +0 -1
- package/types/webpack/plugins/mime-types.d.ts +0 -78
- package/types/webpack/plugins/route-manifest-plugin.d.ts +0 -1
- package/types/webpack/plugins/upload-assets-plugin.d.ts +0 -1
- package/types/webpack/production.client.babel.d.ts +0 -174
- package/types/webpack/production.ssr.babel.d.ts +0 -2
- package/types/webpack/scssParams.d.ts +0 -2
- 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
|
@@ -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;
|
|
@@ -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;
|
|
@@ -1,181 +0,0 @@
|
|
|
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 */
|