@elliemae/pui-cli 7.0.0-beta.1 → 7.0.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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
  };
@@ -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 argv = require('./argv');
10
- const port = require('./port');
11
- const setup = require('./middlewares/frontendMiddleware');
12
- const { loadRoutes } = require('./util');
13
- const { getAssetPath } = require('../webpack/helpers');
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.use(pino);
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
- setup(app, {
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, prettyHost);
36
+ logger.appStarted(port, host || 'localhost');
69
37
  });
@@ -1,25 +1,26 @@
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
- module.exports = function addProdMiddlewares(app, options) {
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(
9
+ app,
10
+ { buildPath = paths.buildPath, mountPath = paths.mountPath },
11
+ ) {
11
12
  // compression middleware compresses your server responses which makes them
12
13
  // smaller (applies also to assets). You can read more about that technique
13
14
  // and other good practices on official Express.js docs http://mxs.is/googmy
14
15
  app.use(compression());
15
16
 
16
- app.get(publicPath, (req, res) => {
17
- sendFileWithCSPNonce({ outputPath, res });
17
+ app.get(mountPath, (req, res) => {
18
+ sendFileWithCSPNonce({ buildPath, res });
18
19
  });
19
20
 
20
21
  app.use(
21
- publicPath,
22
- expressStaticGzip(outputPath, {
22
+ mountPath,
23
+ expressStaticGzip(buildPath, {
23
24
  index: false,
24
25
  enableBrotli: true,
25
26
  orderPreference: ['br'],
@@ -27,5 +28,5 @@ module.exports = function addProdMiddlewares(app, options) {
27
28
  );
28
29
  app.use(expressStaticGzip('cdn'));
29
30
 
30
- app.get('*', (req, res) => sendFileWithCSPNonce({ outputPath, res }));
31
+ app.get('*', (req, res) => sendFileWithCSPNonce({ buildPath, res }));
31
32
  };
@@ -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
+ };
@@ -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
- const loadRoutes = (app) => {
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
- module.exports = {
45
- getCWD,
46
- loadRoutes,
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, getAssetPath } = require('../webpack/helpers');
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 { mountPath } = 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${getAssetPath()}`,
94
+ testURL: `http://localhost:3111${mountPath}`,
93
95
  testEnvironment: 'jsdom',
94
96
  };
95
97
 
@@ -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
- // base path for all assets
167
+ mountPath: (process.env.MOUNT_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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elliemae/pui-cli",
3
- "version": "7.0.0-beta.1",
3
+ "version": "7.0.0-beta.2",
4
4
  "private": false,
5
5
  "description": "ICE MT UI Platform CLI",
6
6
  "sideEffects": false,
@@ -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
- };
@@ -1,6 +0,0 @@
1
- const argv = require('./argv');
2
-
3
- module.exports = parseInt(
4
- argv.port || process.env.port || process.env.PORT || '3000',
5
- 10,
6
- );