@elliemae/pui-cli 7.0.0-beta.1 → 7.0.0-beta.4
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/lib/cli-commands/utils.js +9 -1
- package/lib/server/csp.js +2 -2
- package/lib/server/index.js +8 -40
- package/lib/server/middlewares/addProdMiddlewares.js +9 -10
- package/lib/server/middlewares/index.js +37 -0
- package/lib/server/util/index.js +10 -5
- package/lib/testing/jest.config.js +4 -2
- package/lib/webpack/helpers.js +1 -4
- package/lib/webpack/webpack.prod.babel.js +2 -0
- package/package.json +7 -7
- package/lib/server/argv.js +0 -1
- package/lib/server/middlewares/frontendMiddleware.js +0 -16
- package/lib/server/port.js +0 -6
|
@@ -117,11 +117,19 @@ const copyDir = async (src, dest) => {
|
|
|
117
117
|
);
|
|
118
118
|
};
|
|
119
119
|
|
|
120
|
+
const updateManifestWithVersionInfo = async (dest) => {
|
|
121
|
+
const manifestFile = path.join(dest, 'manifest.json');
|
|
122
|
+
let manifestData = await readFile(manifestFile, 'utf8');
|
|
123
|
+
manifestData = manifestData.replace(/latest\//g, `${getAppVersion()}/`);
|
|
124
|
+
await writeFile(manifestFile, manifestData);
|
|
125
|
+
};
|
|
126
|
+
|
|
120
127
|
exports.copyBuildAssetsToVersionedFolder = async () => {
|
|
121
128
|
const appVersion = getAppVersion();
|
|
122
129
|
const isVersionedApp = isAppLoaderEnabled() && appVersion !== LATEST_VERSION;
|
|
123
130
|
if (!isVersionedApp) return;
|
|
124
131
|
const src = path.resolve(process.cwd(), 'build/public/latest');
|
|
125
132
|
const dest = path.resolve(process.cwd(), `build/public/${appVersion}`);
|
|
126
|
-
copyDir(src, dest);
|
|
133
|
+
await copyDir(src, dest);
|
|
134
|
+
await updateManifestWithVersionInfo(dest);
|
|
127
135
|
};
|
package/lib/server/csp.js
CHANGED
|
@@ -17,13 +17,13 @@ const sources = [
|
|
|
17
17
|
];
|
|
18
18
|
|
|
19
19
|
const sendFileWithCSPNonce = ({
|
|
20
|
-
|
|
20
|
+
buildPath,
|
|
21
21
|
page = 'index.html',
|
|
22
22
|
nonceRegex = /__CSP_NONCE__/g,
|
|
23
23
|
res,
|
|
24
24
|
fileSystem = fs,
|
|
25
25
|
}) => {
|
|
26
|
-
fileSystem.readFile(path.resolve(
|
|
26
|
+
fileSystem.readFile(path.resolve(buildPath, page), 'utf8', (err, html) => {
|
|
27
27
|
if (err) {
|
|
28
28
|
res.sendStatus(404);
|
|
29
29
|
} else {
|
package/lib/server/index.js
CHANGED
|
@@ -1,26 +1,11 @@
|
|
|
1
1
|
/* eslint consistent-return:0 import/order:0 */
|
|
2
|
-
|
|
3
2
|
const express = require('express');
|
|
4
|
-
const cors = require('cors');
|
|
5
|
-
const { resolve } = require('path');
|
|
6
|
-
const expressPinoLogger = require('express-pino-logger');
|
|
7
|
-
const { csp } = require('./csp');
|
|
8
3
|
const logger = require('./logger');
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const {
|
|
14
|
-
|
|
15
|
-
const pino = expressPinoLogger({
|
|
16
|
-
transport: {
|
|
17
|
-
target: 'pino-pretty',
|
|
18
|
-
options: {
|
|
19
|
-
colorize: true,
|
|
20
|
-
},
|
|
21
|
-
},
|
|
22
|
-
});
|
|
23
|
-
pino.logger.level = 'warn';
|
|
4
|
+
const {
|
|
5
|
+
setupDefaultMiddlewares,
|
|
6
|
+
setupAdditionalMiddlewars,
|
|
7
|
+
} = require('./middlewares');
|
|
8
|
+
const { loadRoutes, port, host } = require('./util');
|
|
24
9
|
|
|
25
10
|
// const corsOptions = {
|
|
26
11
|
// origin: '*',
|
|
@@ -37,33 +22,16 @@ pino.logger.level = 'warn';
|
|
|
37
22
|
// maxAge: 3600,
|
|
38
23
|
// };
|
|
39
24
|
const app = express();
|
|
40
|
-
app
|
|
41
|
-
app.use(cors());
|
|
42
|
-
app.options('*', cors());
|
|
43
|
-
csp(app);
|
|
44
|
-
app.use(express.urlencoded({ extended: false }));
|
|
45
|
-
app.use(express.text({ type: 'text/plain' }));
|
|
46
|
-
app.use(express.json({ type: 'application/json' }));
|
|
47
|
-
app.use(express.json({ type: 'application/csp-report' }));
|
|
48
|
-
|
|
25
|
+
setupDefaultMiddlewares(app);
|
|
49
26
|
// load all custom routes from the application
|
|
50
27
|
loadRoutes(app);
|
|
51
|
-
|
|
52
28
|
// In production we need to pass these values in instead of relying on webpack
|
|
53
|
-
|
|
54
|
-
outputPath: resolve(process.cwd(), 'build/public'),
|
|
55
|
-
publicPath: getAssetPath(),
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
// get the intended host and port number, use localhost and port 3000 if not provided
|
|
59
|
-
const customHost = argv.host || process.env.HOST;
|
|
60
|
-
const host = customHost || null; // Let http.Server use its default IPv6/4 host
|
|
61
|
-
const prettyHost = customHost || 'localhost';
|
|
29
|
+
setupAdditionalMiddlewars(app);
|
|
62
30
|
|
|
63
31
|
// Start your app.
|
|
64
32
|
app.listen(port, host, async (err) => {
|
|
65
33
|
if (err) {
|
|
66
34
|
return logger.error(err.message);
|
|
67
35
|
}
|
|
68
|
-
logger.appStarted(port,
|
|
36
|
+
logger.appStarted(port, host || 'localhost');
|
|
69
37
|
});
|
|
@@ -1,25 +1,24 @@
|
|
|
1
|
-
const path = require('path');
|
|
2
1
|
const compression = require('compression');
|
|
3
2
|
const expressStaticGzip = require('express-static-gzip');
|
|
4
3
|
const { sendFileWithCSPNonce } = require('../csp');
|
|
4
|
+
const { getPaths } = require('../../webpack/helpers');
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
const publicPath = options.publicPath || '/';
|
|
8
|
-
const outputPath =
|
|
9
|
-
options.outputPath || path.resolve(process.cwd(), 'build/public');
|
|
6
|
+
const paths = getPaths();
|
|
10
7
|
|
|
8
|
+
module.exports = function addProdMiddlewares(app, options = {}) {
|
|
9
|
+
const { buildPath = paths.buildPath, basePath = paths.basePath } = options;
|
|
11
10
|
// compression middleware compresses your server responses which makes them
|
|
12
11
|
// smaller (applies also to assets). You can read more about that technique
|
|
13
12
|
// and other good practices on official Express.js docs http://mxs.is/googmy
|
|
14
13
|
app.use(compression());
|
|
15
14
|
|
|
16
|
-
app.get(
|
|
17
|
-
sendFileWithCSPNonce({
|
|
15
|
+
app.get(basePath, (req, res) => {
|
|
16
|
+
sendFileWithCSPNonce({ buildPath, res });
|
|
18
17
|
});
|
|
19
18
|
|
|
20
19
|
app.use(
|
|
21
|
-
|
|
22
|
-
expressStaticGzip(
|
|
20
|
+
basePath,
|
|
21
|
+
expressStaticGzip(buildPath, {
|
|
23
22
|
index: false,
|
|
24
23
|
enableBrotli: true,
|
|
25
24
|
orderPreference: ['br'],
|
|
@@ -27,5 +26,5 @@ module.exports = function addProdMiddlewares(app, options) {
|
|
|
27
26
|
);
|
|
28
27
|
app.use(expressStaticGzip('cdn'));
|
|
29
28
|
|
|
30
|
-
app.get('*', (req, res) => sendFileWithCSPNonce({
|
|
29
|
+
app.get('*', (req, res) => sendFileWithCSPNonce({ buildPath, res }));
|
|
31
30
|
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
const express = require('express');
|
|
2
|
+
const cors = require('cors');
|
|
3
|
+
const expressPinoLogger = require('express-pino-logger');
|
|
4
|
+
const { csp } = require('../csp');
|
|
5
|
+
const addProdMiddlewares = require('./addProdMiddlewares');
|
|
6
|
+
const addDevMiddlewares = require('./addDevMiddlewares');
|
|
7
|
+
const webpackConfig = require('../../webpack/webpack.dev.babel');
|
|
8
|
+
|
|
9
|
+
exports.setupDefaultMiddlewares = (app) => {
|
|
10
|
+
const pino = expressPinoLogger({
|
|
11
|
+
transport: {
|
|
12
|
+
target: 'pino-pretty',
|
|
13
|
+
options: {
|
|
14
|
+
colorize: true,
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
});
|
|
18
|
+
pino.logger.level = 'warn';
|
|
19
|
+
app.use(pino);
|
|
20
|
+
app.use(cors());
|
|
21
|
+
app.options('*', cors());
|
|
22
|
+
csp(app);
|
|
23
|
+
app.use(express.urlencoded({ extended: false }));
|
|
24
|
+
app.use(express.text({ type: 'text/plain' }));
|
|
25
|
+
app.use(express.json({ type: 'application/json' }));
|
|
26
|
+
app.use(express.json({ type: 'application/csp-report' }));
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
exports.setupAdditionalMiddlewars = (app, options) => {
|
|
30
|
+
const isProd = process.env.NODE_ENV === 'production';
|
|
31
|
+
if (isProd) {
|
|
32
|
+
addProdMiddlewares(app, options);
|
|
33
|
+
} else {
|
|
34
|
+
addDevMiddlewares(app, webpackConfig);
|
|
35
|
+
}
|
|
36
|
+
return app;
|
|
37
|
+
};
|
package/lib/server/util/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const fs = require('fs');
|
|
2
2
|
const path = require('path');
|
|
3
|
+
const argv = require('minimist')(process.argv.slice(2));
|
|
3
4
|
|
|
4
5
|
const getCWD = () => process.cwd();
|
|
5
6
|
|
|
@@ -25,7 +26,7 @@ const getFilesMatching = (filePattern) => {
|
|
|
25
26
|
const getServerRouteFiles = getFilesMatching(allJS);
|
|
26
27
|
const getServiceEndpoints = getFilesMatching(serviceEndpoints);
|
|
27
28
|
|
|
28
|
-
|
|
29
|
+
exports.loadRoutes = (app) => {
|
|
29
30
|
const routeFiles = getServerRouteFiles(path.join(getCWD(), 'server/routes'));
|
|
30
31
|
routeFiles.push(...getServiceEndpoints(path.join(getCWD(), 'app')));
|
|
31
32
|
routeFiles.push(...getServiceEndpoints(path.join(getCWD(), 'lib')));
|
|
@@ -41,7 +42,11 @@ const loadRoutes = (app) => {
|
|
|
41
42
|
});
|
|
42
43
|
};
|
|
43
44
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
45
|
+
exports.port = parseInt(
|
|
46
|
+
argv.port || process.env.port || process.env.PORT || '3000',
|
|
47
|
+
10,
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
exports.host = argv.host || process.env.HOST;
|
|
51
|
+
|
|
52
|
+
exports.getCWD = getCWD;
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
const path = require('path');
|
|
2
2
|
const normalizePath = require('normalize-path');
|
|
3
|
-
const { getAppConfig,
|
|
3
|
+
const { getAppConfig, getPaths } = require('../webpack/helpers');
|
|
4
4
|
const swcrcConfig = require('../transpile/swcrc.config.js');
|
|
5
5
|
const { findMonoRepoRoot } = require('../monorepo/utils');
|
|
6
6
|
|
|
7
|
+
const { basePath } = getPaths();
|
|
8
|
+
|
|
7
9
|
let isReactModule = true;
|
|
8
10
|
try {
|
|
9
11
|
/* eslint-disable global-require, import/no-unresolved */
|
|
@@ -89,7 +91,7 @@ const jestConfig = {
|
|
|
89
91
|
APP_CONFIG: getAppConfig(),
|
|
90
92
|
__webpack_public_path__: '/',
|
|
91
93
|
},
|
|
92
|
-
testURL: `http://localhost:3111${
|
|
94
|
+
testURL: `http://localhost:3111${basePath}`,
|
|
93
95
|
testEnvironment: 'jsdom',
|
|
94
96
|
};
|
|
95
97
|
|
package/lib/webpack/helpers.js
CHANGED
|
@@ -150,8 +150,6 @@ const getENCWLoaderFileName = () => {
|
|
|
150
150
|
)[0];
|
|
151
151
|
};
|
|
152
152
|
|
|
153
|
-
const getAssetPath = () => (process.env.ASSET_PATH || '/').replace(/\/?$/, '/');
|
|
154
|
-
|
|
155
153
|
const getAppVersion = () => {
|
|
156
154
|
if (!process.env.APP_VERSION) return LATEST_VERSION;
|
|
157
155
|
const match = process.env.APP_VERSION.match(/^v?(\d+\.\d+)\..*$/);
|
|
@@ -166,7 +164,7 @@ const getPaths = (latestVersion = true) => {
|
|
|
166
164
|
return {
|
|
167
165
|
appVersion: version,
|
|
168
166
|
buildPath: path.resolve(process.cwd(), `build/public/`),
|
|
169
|
-
|
|
167
|
+
basePath: (process.env.BASE_PATH || '/').replace(/\/?$/, '/'),
|
|
170
168
|
publicPath,
|
|
171
169
|
userMonScriptPath: `latest/js/${getUserMonitoringFileName()}`,
|
|
172
170
|
appLoaderScriptPath: `latest/js/${getAppLoaderFileName()}`,
|
|
@@ -231,7 +229,6 @@ exports.excludeNodeModulesExcept = excludeNodeModulesExcept;
|
|
|
231
229
|
exports.getLibraryName = getLibraryName;
|
|
232
230
|
exports.getAppConfig = getAppConfig;
|
|
233
231
|
exports.mapToFolder = mapToFolder;
|
|
234
|
-
exports.getAssetPath = getAssetPath;
|
|
235
232
|
exports.isApp = isApp;
|
|
236
233
|
exports.getAlias = getAlias;
|
|
237
234
|
exports.getAppVersion = getAppVersion;
|
|
@@ -91,12 +91,14 @@ const {
|
|
|
91
91
|
appLoaderScriptPath,
|
|
92
92
|
diagnosticsScriptPath,
|
|
93
93
|
encwLoaderScriptPath,
|
|
94
|
+
basePath,
|
|
94
95
|
} = getPaths();
|
|
95
96
|
const htmlWebpackPlugin = new HtmlWebpackPlugin({
|
|
96
97
|
inject: !isAppLoaderEnabled(),
|
|
97
98
|
template: !isAppLoaderEnabled()
|
|
98
99
|
? 'app/index.html'
|
|
99
100
|
: 'app/index-app-loader.html',
|
|
101
|
+
base: basePath,
|
|
100
102
|
minify: {
|
|
101
103
|
removeComments: true,
|
|
102
104
|
collapseWhitespace: true,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elliemae/pui-cli",
|
|
3
|
-
"version": "7.0.0-beta.
|
|
3
|
+
"version": "7.0.0-beta.4",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "ICE MT UI Platform CLI",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
50
|
"@babel/cli": "~7.17.6",
|
|
51
|
-
"@babel/core": "~7.17.
|
|
51
|
+
"@babel/core": "~7.17.8",
|
|
52
52
|
"@babel/eslint-parser": "~7.17.0",
|
|
53
53
|
"@babel/node": "~7.16.8",
|
|
54
54
|
"@babel/plugin-proposal-class-properties": "~7.16.7",
|
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
"@babel/preset-env": "~7.16.11",
|
|
63
63
|
"@babel/preset-react": "~7.16.7",
|
|
64
64
|
"@babel/preset-typescript": "~7.16.7",
|
|
65
|
-
"@babel/runtime": "~7.17.
|
|
65
|
+
"@babel/runtime": "~7.17.8",
|
|
66
66
|
"@commitlint/cli": "~16.2.3",
|
|
67
67
|
"@commitlint/config-conventional": "~16.2.1",
|
|
68
68
|
"@elliemae/browserslist-config-elliemae-latest-browsers": "~1.3.0",
|
|
@@ -87,7 +87,7 @@
|
|
|
87
87
|
"@stylelint/postcss-css-in-js": "~0.37.2",
|
|
88
88
|
"@svgr/webpack": "~6.2.1",
|
|
89
89
|
"@swc/cli": "~0.1.55",
|
|
90
|
-
"@swc/core": "~1.2.
|
|
90
|
+
"@swc/core": "~1.2.159",
|
|
91
91
|
"@swc/jest": "~0.2.20",
|
|
92
92
|
"@testing-library/jest-dom": "~5.16.2",
|
|
93
93
|
"@testing-library/react": "~12.1.4",
|
|
@@ -147,7 +147,7 @@
|
|
|
147
147
|
"eslint-plugin-eslint-comments": "~3.2.0",
|
|
148
148
|
"eslint-plugin-import": "~2.25.4",
|
|
149
149
|
"eslint-plugin-jest": "~26.1.1",
|
|
150
|
-
"eslint-plugin-jsdoc": "~38.0.
|
|
150
|
+
"eslint-plugin-jsdoc": "~38.0.6",
|
|
151
151
|
"eslint-plugin-jsx-a11y": "~6.5.1",
|
|
152
152
|
"eslint-plugin-mdx": "~1.16.0",
|
|
153
153
|
"eslint-plugin-prettier": "~4.0.0",
|
|
@@ -156,7 +156,7 @@
|
|
|
156
156
|
"eslint-plugin-redux-saga": "~1.3.2",
|
|
157
157
|
"eslint-plugin-storybook": "~0.5.7",
|
|
158
158
|
"eslint-plugin-testing-library": "~5.1.0",
|
|
159
|
-
"eslint-plugin-wdio": "~7.
|
|
159
|
+
"eslint-plugin-wdio": "~7.18.1",
|
|
160
160
|
"execa": "~5.1.1",
|
|
161
161
|
"express": "~4.17.3",
|
|
162
162
|
"express-pino-logger": "~7.0.0",
|
|
@@ -233,7 +233,7 @@
|
|
|
233
233
|
"url-loader": "~4.1.1",
|
|
234
234
|
"uuid": "~8.3.2",
|
|
235
235
|
"vite": "~2.8.6",
|
|
236
|
-
"vitest": "~0.7.
|
|
236
|
+
"vitest": "~0.7.6",
|
|
237
237
|
"webpack": "~5.70.0",
|
|
238
238
|
"webpack-bundle-analyzer": "~4.5.0",
|
|
239
239
|
"webpack-cli": "~4.9.2",
|
package/lib/server/argv.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
module.exports = require('minimist')(process.argv.slice(2));
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/* eslint-disable global-require */
|
|
2
|
-
|
|
3
|
-
module.exports = (app, options) => {
|
|
4
|
-
const isProd = process.env.NODE_ENV === 'production';
|
|
5
|
-
|
|
6
|
-
if (isProd) {
|
|
7
|
-
const addProdMiddlewares = require('./addProdMiddlewares');
|
|
8
|
-
addProdMiddlewares(app, options);
|
|
9
|
-
} else {
|
|
10
|
-
const webpackConfig = require('../../webpack/webpack.dev.babel');
|
|
11
|
-
const addDevMiddlewares = require('./addDevMiddlewares');
|
|
12
|
-
addDevMiddlewares(app, webpackConfig);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
return app;
|
|
16
|
-
};
|