@elliemae/pui-cli 6.16.0 → 7.0.0-alpha.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.
- package/dist/cjs/cli-commands/build.js +72 -0
- package/dist/cjs/cli-commands/codemod.js +51 -0
- package/dist/cjs/cli-commands/gendoc.js +52 -0
- package/dist/cjs/cli-commands/lint.js +86 -0
- package/dist/cjs/cli-commands/pack.js +88 -0
- package/dist/cjs/cli-commands/start.js +61 -0
- package/dist/cjs/cli-commands/storybook.js +63 -0
- package/dist/cjs/cli-commands/test.js +86 -0
- package/dist/cjs/cli-commands/tsc.js +103 -0
- package/dist/cjs/cli-commands/utils.js +137 -0
- package/dist/cjs/cli-commands/version.js +71 -0
- package/dist/cjs/cli-commands/vitest.js +84 -0
- package/dist/cjs/cli.js +47 -0
- package/dist/cjs/docgen/jsdoc.conf.json +17 -0
- package/{lib/dummy.ts → dist/cjs/dummy.js} +0 -0
- package/dist/cjs/index.js +41 -0
- package/dist/cjs/lint/lint-staged.config.js +42 -0
- package/dist/cjs/monorepo/delete-merged-tags.js +57 -0
- package/dist/cjs/monorepo/set-registry-version.js +43 -0
- package/dist/cjs/monorepo/set-workspace-version.js +44 -0
- package/dist/cjs/monorepo/utils.js +34 -0
- package/dist/cjs/package.json +4 -0
- package/dist/cjs/pui-config/index.js +40 -0
- package/dist/cjs/scripts/helpers/checkmark.js +32 -0
- package/dist/cjs/scripts/helpers/get-npm-config.js +27 -0
- package/dist/cjs/scripts/helpers/progress.js +35 -0
- package/dist/cjs/scripts/helpers/xmark.js +31 -0
- package/dist/cjs/scripts/npmcheckversion.js +8 -0
- package/dist/cjs/scripts/update-notifier.js +33 -0
- package/dist/cjs/server/csp.js +88 -0
- package/dist/cjs/server/index.js +29 -0
- package/dist/cjs/server/logger.js +50 -0
- package/dist/cjs/server/middlewares/addProdMiddlewares.js +44 -0
- package/dist/cjs/server/middlewares/index.js +57 -0
- package/dist/cjs/server/util/index.js +68 -0
- package/dist/cjs/testing/setup-react-env.js +18 -0
- package/dist/cjs/testing/setup-tests.js +63 -0
- package/dist/cjs/testing/vitest.config.js +39 -0
- package/{lib/testing/vitest.setup.ts → dist/cjs/testing/vitest.setup.js} +0 -0
- package/dist/cjs/transpile/esbuild.js +138 -0
- package/dist/cjs/transpile/react-shim.js +26 -0
- package/{lib → dist/cjs}/typescript/app.tsconfig.json +0 -0
- package/{lib → dist/cjs}/typescript/library.tsconfig.json +0 -0
- package/dist/cjs/typescript/tsc-files/index.js +68 -0
- package/dist/cjs/typescript/tsc-files/utils.js +31 -0
- package/dist/cjs/typescript/util.js +28 -0
- package/dist/cjs/webpack/helpers.js +216 -0
- package/dist/cjs/webpack/webpack.base.babel.js +262 -0
- package/dist/cjs/webpack/webpack.dev.babel.js +136 -0
- package/dist/cjs/webpack/webpack.lib.base.babel.js +217 -0
- package/dist/cjs/webpack/webpack.lib.dev.babel.js +67 -0
- package/dist/cjs/webpack/webpack.lib.prod.babel.js +92 -0
- package/dist/cjs/webpack/webpack.prod.babel.js +139 -0
- package/dist/esm/cli-commands/build.js +56 -0
- package/dist/esm/cli-commands/codemod.js +29 -0
- package/dist/esm/cli-commands/gendoc.js +29 -0
- package/dist/esm/cli-commands/lint.js +64 -0
- package/dist/esm/cli-commands/pack.js +65 -0
- package/dist/esm/cli-commands/start.js +38 -0
- package/dist/esm/cli-commands/storybook.js +41 -0
- package/dist/esm/cli-commands/test.js +64 -0
- package/dist/esm/cli-commands/tsc.js +83 -0
- package/dist/esm/cli-commands/utils.js +120 -0
- package/dist/esm/cli-commands/version.js +49 -0
- package/dist/esm/cli-commands/vitest.js +61 -0
- package/dist/esm/cli.js +31 -0
- package/dist/esm/docgen/jsdoc.conf.json +17 -0
- package/dist/esm/dummy.js +0 -0
- package/dist/esm/index.js +22 -0
- package/dist/esm/lint/lint-staged.config.js +19 -0
- package/dist/esm/monorepo/delete-merged-tags.js +38 -0
- package/dist/esm/monorepo/set-registry-version.js +21 -0
- package/dist/esm/monorepo/set-workspace-version.js +22 -0
- package/dist/esm/monorepo/utils.js +12 -0
- package/dist/esm/package.json +4 -0
- package/dist/esm/pui-config/index.js +18 -0
- package/dist/esm/scripts/helpers/checkmark.js +10 -0
- package/dist/esm/scripts/helpers/get-npm-config.js +5 -0
- package/dist/esm/scripts/helpers/progress.js +13 -0
- package/dist/esm/scripts/helpers/xmark.js +9 -0
- package/dist/esm/scripts/npmcheckversion.js +8 -0
- package/dist/esm/scripts/update-notifier.js +11 -0
- package/dist/esm/server/csp.js +66 -0
- package/dist/esm/server/index.js +17 -0
- package/dist/esm/server/logger.js +28 -0
- package/dist/esm/server/middlewares/addProdMiddlewares.js +22 -0
- package/dist/esm/server/middlewares/index.js +35 -0
- package/{lib → dist/esm}/server/util/index.js +18 -19
- package/dist/esm/testing/setup-react-env.js +3 -0
- package/dist/esm/testing/setup-tests.js +48 -0
- package/dist/esm/testing/vitest.config.js +17 -0
- package/dist/esm/testing/vitest.setup.js +0 -0
- package/dist/esm/transpile/esbuild.js +117 -0
- package/dist/esm/transpile/react-shim.js +4 -0
- package/dist/esm/typescript/app.tsconfig.json +23 -0
- package/dist/esm/typescript/library.tsconfig.json +23 -0
- package/dist/esm/typescript/tsc-files/index.js +55 -0
- package/{lib → dist/esm}/typescript/tsc-files/utils.js +3 -7
- package/dist/esm/typescript/util.js +6 -0
- package/dist/esm/webpack/helpers.js +196 -0
- package/dist/esm/webpack/webpack.base.babel.js +248 -0
- package/dist/esm/webpack/webpack.dev.babel.js +118 -0
- package/dist/esm/webpack/webpack.lib.base.babel.js +208 -0
- package/dist/esm/webpack/webpack.lib.dev.babel.js +45 -0
- package/dist/esm/webpack/webpack.lib.prod.babel.js +70 -0
- package/dist/esm/webpack/webpack.prod.babel.js +122 -0
- package/dist/types/babel/babel.config.d.cts +59 -0
- package/dist/types/cli-commands/build.d.ts +14 -0
- package/dist/types/cli-commands/codemod.d.ts +6 -0
- package/dist/types/cli-commands/gendoc.d.ts +6 -0
- package/dist/types/cli-commands/lint.d.ts +29 -0
- package/dist/types/cli-commands/pack.d.ts +26 -0
- package/dist/types/cli-commands/start.d.ts +13 -0
- package/dist/types/cli-commands/storybook.d.ts +19 -0
- package/dist/types/cli-commands/test.d.ts +35 -0
- package/dist/types/cli-commands/tsc.d.ts +20 -0
- package/dist/types/cli-commands/utils.d.ts +14 -0
- package/dist/types/cli-commands/version.d.ts +30 -0
- package/dist/types/cli-commands/vitest.d.ts +35 -0
- package/dist/types/cli.d.ts +2 -0
- package/dist/types/dummy.d.ts +0 -0
- package/dist/types/index.d.ts +10 -0
- package/dist/types/lint/commitlint.config.d.cts +4 -0
- package/dist/types/lint/eslint/common.d.cts +124 -0
- package/dist/types/lint/eslint/non-react.d.cts +88 -0
- package/dist/types/lint/eslint/react.d.cts +118 -0
- package/dist/types/lint/eslint/typescript/common.d.cts +37 -0
- package/dist/types/lint/eslint/typescript/non-react.d.cts +87 -0
- package/dist/types/lint/eslint/typescript/react.d.cts +118 -0
- package/dist/types/lint/lint-staged.config.d.ts +5 -0
- package/dist/types/lint/prettier.config.d.cts +8 -0
- package/dist/types/lint/stylelint.config.d.cts +10 -0
- package/dist/types/monorepo/delete-merged-tags.d.ts +1 -0
- package/dist/types/monorepo/set-registry-version.d.ts +1 -0
- package/dist/types/monorepo/set-workspace-version.d.ts +1 -0
- package/dist/types/monorepo/utils.d.ts +1 -0
- package/dist/types/pui-config/index.d.ts +1 -0
- package/dist/types/release/release.config.d.cts +9 -0
- package/dist/types/scripts/helpers/checkmark.d.ts +7 -0
- package/dist/types/scripts/helpers/get-npm-config.d.ts +2 -0
- package/dist/types/scripts/helpers/progress.d.ts +7 -0
- package/dist/types/scripts/helpers/xmark.d.ts +6 -0
- package/dist/types/scripts/npmcheckversion.d.ts +1 -0
- package/dist/types/scripts/update-notifier.d.ts +2 -0
- package/dist/types/server/csp.d.ts +10 -0
- package/dist/types/server/index.d.ts +1 -0
- package/dist/types/server/logger.d.ts +4 -0
- package/dist/types/server/middlewares/addProdMiddlewares.d.ts +1 -0
- package/dist/types/server/middlewares/index.d.ts +2 -0
- package/dist/types/server/util/index.d.ts +4 -0
- package/dist/types/testing/jest.config.d.cts +39 -0
- package/dist/types/testing/jest.node.config.d.cts +39 -0
- package/dist/types/testing/mocks/axios.d.cts +14 -0
- package/dist/types/testing/mocks/cssModule.d.cts +2 -0
- package/dist/types/testing/mocks/html.d.cts +2 -0
- package/dist/types/testing/mocks/image.d.cts +2 -0
- package/dist/types/testing/mocks/matchMedia.d.cts +2 -0
- package/dist/types/testing/mocks/pui-app-loader.d.cts +1 -0
- package/dist/types/testing/mocks/pui-diagnostics.d.cts +28 -0
- package/dist/types/testing/mocks/pui-user-monitoring.d.cts +3 -0
- package/dist/types/testing/mocks/retry-axios.d.cts +3 -0
- package/dist/types/testing/mocks/svg.d.cts +3 -0
- package/dist/types/testing/mocks/webpack-hmr.d.cts +1 -0
- package/dist/types/testing/resolver.d.cts +2 -0
- package/dist/types/testing/setup-react-env.d.ts +1 -0
- package/dist/types/testing/setup-tests.d.ts +1 -0
- package/dist/types/testing/vitest.config.d.ts +2 -0
- package/dist/types/testing/vitest.setup.d.ts +0 -0
- package/dist/types/transpile/esbuild.d.ts +13 -0
- package/dist/types/transpile/react-shim.d.ts +2 -0
- package/dist/types/transpile/swcrc.config.d.cts +1 -0
- package/dist/types/typescript/tsc-files/index.d.ts +1 -0
- package/dist/types/typescript/tsc-files/utils.d.ts +3 -0
- package/dist/types/typescript/util.d.ts +1 -0
- package/dist/types/utils.d.cts +3 -0
- package/dist/types/webpack/helpers.d.ts +28 -0
- package/dist/types/webpack/webpack.base.babel.d.ts +90 -0
- package/dist/types/webpack/webpack.dev.babel.d.ts +1 -0
- package/dist/types/webpack/webpack.lib.base.babel.d.ts +107 -0
- package/dist/types/webpack/webpack.lib.dev.babel.d.ts +91 -0
- package/dist/types/webpack/webpack.lib.prod.babel.d.ts +91 -0
- package/dist/types/webpack/webpack.prod.babel.d.ts +2 -0
- package/dist/types/webpack/webpack.storybook.d.cts +4 -0
- package/package.json +63 -52
- package/lib/babel/babel.config.js +0 -101
- package/lib/cli-commands/build.js +0 -56
- package/lib/cli-commands/codemod.js +0 -31
- package/lib/cli-commands/gendoc.js +0 -36
- package/lib/cli-commands/lint.js +0 -75
- package/lib/cli-commands/pack.js +0 -67
- package/lib/cli-commands/start.js +0 -44
- package/lib/cli-commands/storybook.js +0 -53
- package/lib/cli-commands/test.js +0 -63
- package/lib/cli-commands/tsc.js +0 -103
- package/lib/cli-commands/utils.js +0 -89
- package/lib/cli-commands/version.js +0 -53
- package/lib/cli-commands/vitest.js +0 -66
- package/lib/cli.js +0 -33
- package/lib/docgen/jsdoc.config.js +0 -17
- package/lib/index.js +0 -25
- package/lib/lint/commitlint.config.js +0 -1
- package/lib/lint/eslint/common.js +0 -160
- package/lib/lint/eslint/non-react.js +0 -14
- package/lib/lint/eslint/react.js +0 -26
- package/lib/lint/eslint/typescript/common.js +0 -43
- package/lib/lint/eslint/typescript/non-react.js +0 -12
- package/lib/lint/eslint/typescript/react.js +0 -19
- package/lib/lint/lint-staged.config.js +0 -16
- package/lib/lint/prettier.config.js +0 -8
- package/lib/lint/stylelint.config.js +0 -19
- package/lib/monorepo/delete-merged-tags.js +0 -48
- package/lib/monorepo/set-registry-version.js +0 -22
- package/lib/monorepo/set-workspace-version.js +0 -29
- package/lib/monorepo/utils.js +0 -15
- package/lib/pui-config/index.js +0 -18
- package/lib/release/release.config.js +0 -31
- package/lib/scripts/helpers/checkmark.js +0 -15
- package/lib/scripts/helpers/get-npm-config.js +0 -3
- package/lib/scripts/helpers/progress.js +0 -19
- package/lib/scripts/helpers/xmark.js +0 -13
- package/lib/scripts/npmcheckversion.js +0 -8
- package/lib/scripts/update-notifier.js +0 -7
- package/lib/server/argv.js +0 -1
- package/lib/server/csp.js +0 -74
- package/lib/server/index.js +0 -69
- package/lib/server/logger.js +0 -42
- package/lib/server/middlewares/addDevMiddlewares.js +0 -39
- package/lib/server/middlewares/addProdMiddlewares.js +0 -31
- package/lib/server/middlewares/frontendMiddleware.js +0 -16
- package/lib/server/port.js +0 -6
- package/lib/testing/jest.config.js +0 -100
- package/lib/testing/jest.node.config.js +0 -8
- package/lib/testing/mocks/axios.js +0 -15
- package/lib/testing/mocks/cssModule.js +0 -1
- package/lib/testing/mocks/html.js +0 -1
- package/lib/testing/mocks/image.js +0 -1
- package/lib/testing/mocks/matchMedia.js +0 -24
- package/lib/testing/mocks/pui-app-loader.js +0 -1
- package/lib/testing/mocks/pui-diagnostics.js +0 -28
- package/lib/testing/mocks/pui-user-monitoring.js +0 -3
- package/lib/testing/mocks/retry-axios.js +0 -3
- package/lib/testing/mocks/svg.js +0 -5
- package/lib/testing/mocks/webpack-hmr.js +0 -1
- package/lib/testing/resolver.js +0 -47
- package/lib/testing/setup-react-env.js +0 -3
- package/lib/testing/setup-tests.js +0 -58
- package/lib/testing/vitest.config.ts +0 -16
- package/lib/transpile/.swcrc +0 -11
- package/lib/transpile/esbuild.js +0 -116
- package/lib/transpile/react-shim.js +0 -2
- package/lib/transpile/swcrc.config.js +0 -13
- package/lib/typescript/tsc-files/index.js +0 -66
- package/lib/typescript/util.js +0 -5
- package/lib/webpack/helpers.js +0 -255
- package/lib/webpack/webpack.base.babel.js +0 -239
- package/lib/webpack/webpack.dev.babel.js +0 -122
- package/lib/webpack/webpack.lib.base.babel.js +0 -205
- package/lib/webpack/webpack.lib.dev.babel.js +0 -49
- package/lib/webpack/webpack.lib.prod.babel.js +0 -77
- package/lib/webpack/webpack.prod.babel.js +0 -164
- package/lib/webpack/webpack.storybook.js +0 -91
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __spreadValues = (a, b) => {
|
|
9
|
+
for (var prop in b || (b = {}))
|
|
10
|
+
if (__hasOwnProp.call(b, prop))
|
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
|
12
|
+
if (__getOwnPropSymbols)
|
|
13
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
}
|
|
17
|
+
return a;
|
|
18
|
+
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
+
import path from "node:path";
|
|
21
|
+
import yargs from "yargs";
|
|
22
|
+
import { spawnSync } from "child_process";
|
|
23
|
+
import fs from "fs";
|
|
24
|
+
import { logInfo, logError } from "./utils.js";
|
|
25
|
+
const randomChars = () => Math.random().toString(36).slice(2);
|
|
26
|
+
const resolveFromRoot = (...paths) => path.join(process.cwd(), ...paths);
|
|
27
|
+
const validateTypescript = async () => {
|
|
28
|
+
const args = process.argv.slice(2);
|
|
29
|
+
const argsProjectIndex = args.findIndex((arg) => ["-p", "--project"].includes(arg));
|
|
30
|
+
const argsProjectValue = argsProjectIndex !== -1 ? args[argsProjectIndex + 1] : void 0;
|
|
31
|
+
const files = args.filter((file) => /\.(ts|tsx)$/.test(file));
|
|
32
|
+
if (files.length === 0) {
|
|
33
|
+
process.exit(0);
|
|
34
|
+
}
|
|
35
|
+
const remainingArgsToForward = args.slice().filter((arg) => !files.includes(arg));
|
|
36
|
+
if (argsProjectIndex !== -1) {
|
|
37
|
+
remainingArgsToForward.splice(argsProjectIndex, 2);
|
|
38
|
+
}
|
|
39
|
+
const tsconfigPath = argsProjectValue || resolveFromRoot("tsconfig.json");
|
|
40
|
+
const tsconfigContent = fs.readFileSync(tsconfigPath).toString();
|
|
41
|
+
let tsconfig = {};
|
|
42
|
+
eval(`tsconfig = ${tsconfigContent}`);
|
|
43
|
+
const tmpTsconfigPath = resolveFromRoot(`tsconfig.${randomChars()}.json`);
|
|
44
|
+
const tmpTsconfig = __spreadProps(__spreadValues({}, tsconfig), {
|
|
45
|
+
compilerOptions: __spreadProps(__spreadValues({}, tsconfig.compilerOptions), {
|
|
46
|
+
skipLibCheck: true
|
|
47
|
+
}),
|
|
48
|
+
files,
|
|
49
|
+
include: ["shared/typings"]
|
|
50
|
+
});
|
|
51
|
+
fs.writeFileSync(tmpTsconfigPath, JSON.stringify(tmpTsconfig, null, 2));
|
|
52
|
+
const { status } = spawnSync("tsc", ["-p", tmpTsconfigPath, ...remainingArgsToForward], { stdio: "inherit" });
|
|
53
|
+
fs.unlinkSync(tmpTsconfigPath);
|
|
54
|
+
process.exit(status);
|
|
55
|
+
};
|
|
56
|
+
const tscCmd = {
|
|
57
|
+
handler: async (argv) => {
|
|
58
|
+
try {
|
|
59
|
+
await validateTypescript(argv.p);
|
|
60
|
+
logInfo("Typescript validation started");
|
|
61
|
+
} catch (err) {
|
|
62
|
+
logError("Typescript validation failed", err);
|
|
63
|
+
yargs().exit(-1, err);
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
command: "tsc [options]",
|
|
67
|
+
describe: "validate typescript code",
|
|
68
|
+
builder: {
|
|
69
|
+
project: {
|
|
70
|
+
alias: "p",
|
|
71
|
+
type: "boolean",
|
|
72
|
+
default: false
|
|
73
|
+
},
|
|
74
|
+
docs: {
|
|
75
|
+
type: "boolean",
|
|
76
|
+
default: false
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
export {
|
|
81
|
+
tscCmd,
|
|
82
|
+
validateTypescript
|
|
83
|
+
};
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { readFile, writeFile, mkdir, readdir, copyFile } from "fs/promises";
|
|
3
|
+
import { execaCommand } from "execa";
|
|
4
|
+
import chalk from "chalk";
|
|
5
|
+
import {
|
|
6
|
+
getPaths,
|
|
7
|
+
isAppLoaderEnabled,
|
|
8
|
+
getAppVersion,
|
|
9
|
+
LATEST_VERSION
|
|
10
|
+
} from "../webpack/helpers.js";
|
|
11
|
+
const browsersMapping = {
|
|
12
|
+
and_chr: "Chrome for Android",
|
|
13
|
+
chrome: "Google Chrome",
|
|
14
|
+
edge: "Microsoft Edge",
|
|
15
|
+
firefox: "Mozilla Firefox",
|
|
16
|
+
ios_saf: "iOS Safari",
|
|
17
|
+
safari: "Safari",
|
|
18
|
+
samsung: "Samsung Internet"
|
|
19
|
+
};
|
|
20
|
+
const exec = async (command, options = { stdio: "inherit" }) => execaCommand(command, options);
|
|
21
|
+
const logInfo = console.log;
|
|
22
|
+
const logSuccess = (...args) => console.log(chalk.green(...args));
|
|
23
|
+
const logError = console.error;
|
|
24
|
+
const readPackageLock = async () => {
|
|
25
|
+
try {
|
|
26
|
+
const appPkgLockFile = path.join(process.cwd(), "package-lock.json");
|
|
27
|
+
const pkgLockJSON = await readFile(appPkgLockFile, "utf8");
|
|
28
|
+
const { dependencies } = JSON.parse(pkgLockJSON);
|
|
29
|
+
return (moduleName) => dependencies[moduleName]?.version || "";
|
|
30
|
+
} catch (err) {
|
|
31
|
+
console.warn("Package lock file not found");
|
|
32
|
+
return () => "";
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
const getSupportedBrowsers = async () => {
|
|
36
|
+
const { stdout } = await exec("npx --no-install browserslist", {
|
|
37
|
+
stdout: "pipe"
|
|
38
|
+
});
|
|
39
|
+
const browserVersions = stdout && stdout.split("\n") || [];
|
|
40
|
+
return browserVersions.reduce((acc, nameVersion) => {
|
|
41
|
+
const [name, version] = nameVersion.split(" ");
|
|
42
|
+
const versionRange = version.split("-");
|
|
43
|
+
acc[browsersMapping[name]] = versionRange && versionRange[0] || version;
|
|
44
|
+
return acc;
|
|
45
|
+
}, {});
|
|
46
|
+
};
|
|
47
|
+
const getModulesInfo = async () => {
|
|
48
|
+
try {
|
|
49
|
+
const getModuleVersion = await readPackageLock();
|
|
50
|
+
return {
|
|
51
|
+
react: getModuleVersion("react"),
|
|
52
|
+
"react-dom": getModuleVersion("react-dom"),
|
|
53
|
+
"app-react-dependencies": getModuleVersion("@elliemae/app-react-dependencies"),
|
|
54
|
+
"app-sdk": getModuleVersion("@elliemae/pui-app-sdk"),
|
|
55
|
+
cli: getModuleVersion("@elliemae/pui-cli"),
|
|
56
|
+
dimsum: getModuleVersion("@elliemae/ds-system")
|
|
57
|
+
};
|
|
58
|
+
} catch (err) {
|
|
59
|
+
console.warn(err);
|
|
60
|
+
return {};
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
const writeAppInfo = async () => {
|
|
64
|
+
const appInfo = {
|
|
65
|
+
timestamp: new Date().toISOString(),
|
|
66
|
+
modules: await getModulesInfo(),
|
|
67
|
+
browserSupport: await getSupportedBrowsers(),
|
|
68
|
+
screenReaderSupport: [
|
|
69
|
+
"JAWS with Chrome",
|
|
70
|
+
"NVDA with Chrome",
|
|
71
|
+
"VoiceOver with Safari",
|
|
72
|
+
"iOS VoiceOver",
|
|
73
|
+
"Android Talkback"
|
|
74
|
+
]
|
|
75
|
+
};
|
|
76
|
+
const infoJSON = JSON.stringify(appInfo, null, 2);
|
|
77
|
+
const { buildPath: versionedPath } = getPaths();
|
|
78
|
+
[
|
|
79
|
+
path.join(versionedPath, "info.json"),
|
|
80
|
+
path.join(process.cwd(), "build", "public", "info.json")
|
|
81
|
+
].forEach(async (infoPath) => writeFile(infoPath, infoJSON));
|
|
82
|
+
};
|
|
83
|
+
const copyDir = async (src, dest) => {
|
|
84
|
+
const entries = await readdir(src, {
|
|
85
|
+
withFileTypes: true
|
|
86
|
+
});
|
|
87
|
+
await mkdir(dest);
|
|
88
|
+
return Promise.all(entries.map((entry) => {
|
|
89
|
+
const srcPath = path.join(src, entry.name);
|
|
90
|
+
const destPath = path.join(dest, entry.name);
|
|
91
|
+
if (entry.isDirectory()) {
|
|
92
|
+
return copyDir(srcPath, destPath);
|
|
93
|
+
}
|
|
94
|
+
return copyFile(srcPath, destPath);
|
|
95
|
+
}));
|
|
96
|
+
};
|
|
97
|
+
const updateManifestWithVersionInfo = async (dest) => {
|
|
98
|
+
const manifestFile = path.join(dest, "manifest.json");
|
|
99
|
+
let manifestData = await readFile(manifestFile, "utf8");
|
|
100
|
+
manifestData = manifestData.replace(/latest\//g, `${getAppVersion()}/`);
|
|
101
|
+
await writeFile(manifestFile, manifestData);
|
|
102
|
+
};
|
|
103
|
+
const copyBuildAssetsToVersionedFolder = async () => {
|
|
104
|
+
const appVersion = getAppVersion();
|
|
105
|
+
const isVersionedApp = isAppLoaderEnabled() && appVersion !== LATEST_VERSION;
|
|
106
|
+
if (!isVersionedApp)
|
|
107
|
+
return;
|
|
108
|
+
const src = path.resolve(process.cwd(), "build/public/latest");
|
|
109
|
+
const dest = path.resolve(process.cwd(), `build/public/${appVersion}`);
|
|
110
|
+
await copyDir(src, dest);
|
|
111
|
+
await updateManifestWithVersionInfo(dest);
|
|
112
|
+
};
|
|
113
|
+
export {
|
|
114
|
+
copyBuildAssetsToVersionedFolder,
|
|
115
|
+
exec,
|
|
116
|
+
logError,
|
|
117
|
+
logInfo,
|
|
118
|
+
logSuccess,
|
|
119
|
+
writeAppInfo
|
|
120
|
+
};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import yargs from "yargs";
|
|
2
|
+
import { exec, logError } from "./utils.js";
|
|
3
|
+
import { setWorkspaceVersion } from "../monorepo/set-workspace-version.js";
|
|
4
|
+
import { setRegistryVersion } from "../monorepo/set-registry-version.js";
|
|
5
|
+
import { deleteMergedTags } from "../monorepo/delete-merged-tags.js";
|
|
6
|
+
const version = async (lernaOptions = "") => {
|
|
7
|
+
await exec(`cross-env NODE_ENV=production lerna version --conventional-commits --exact --create-release github --force-publish --yes ${lernaOptions}`);
|
|
8
|
+
};
|
|
9
|
+
const versionCmd = {
|
|
10
|
+
handler: async (argv) => {
|
|
11
|
+
try {
|
|
12
|
+
if (argv.deleteTags) {
|
|
13
|
+
await deleteMergedTags();
|
|
14
|
+
} else if (argv.useRegistry) {
|
|
15
|
+
await setRegistryVersion();
|
|
16
|
+
} else if (argv.useWorkspace) {
|
|
17
|
+
await setWorkspaceVersion();
|
|
18
|
+
} else {
|
|
19
|
+
await version(argv.lernaOptions);
|
|
20
|
+
}
|
|
21
|
+
} catch (err) {
|
|
22
|
+
logError("Monorepo versioning failed", err);
|
|
23
|
+
yargs().exit(-1, err);
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
command: "version [options]",
|
|
27
|
+
describe: "version monorepo",
|
|
28
|
+
builder: {
|
|
29
|
+
deleteTags: {
|
|
30
|
+
type: "boolean",
|
|
31
|
+
default: false
|
|
32
|
+
},
|
|
33
|
+
useRegistry: {
|
|
34
|
+
type: "boolean",
|
|
35
|
+
default: false
|
|
36
|
+
},
|
|
37
|
+
useWorkspace: {
|
|
38
|
+
type: "boolean",
|
|
39
|
+
default: false
|
|
40
|
+
},
|
|
41
|
+
lernaOptions: {
|
|
42
|
+
type: "string",
|
|
43
|
+
default: false
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
export {
|
|
48
|
+
versionCmd
|
|
49
|
+
};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import yargs from "yargs";
|
|
2
|
+
import { exec, logError, logSuccess } from "./utils.js";
|
|
3
|
+
const { CI = false } = process.env;
|
|
4
|
+
const configPath = new URL("../testing/vitest.config.ts", import.meta.url);
|
|
5
|
+
const test = async (commandOptions) => {
|
|
6
|
+
await exec(`cross-env FORCE_COLOR=true vitest --config ${configPath} ${commandOptions}`);
|
|
7
|
+
};
|
|
8
|
+
const vitestCmd = {
|
|
9
|
+
handler: async (argv) => {
|
|
10
|
+
let commandOptions = "--coverage";
|
|
11
|
+
if (argv.fix)
|
|
12
|
+
commandOptions = "-u";
|
|
13
|
+
else if (argv.watch)
|
|
14
|
+
commandOptions = "--watch";
|
|
15
|
+
if (argv.p)
|
|
16
|
+
commandOptions += " --passWithNoTests";
|
|
17
|
+
if (argv.r)
|
|
18
|
+
commandOptions += " --related";
|
|
19
|
+
if (argv.s)
|
|
20
|
+
commandOptions += " --silent";
|
|
21
|
+
try {
|
|
22
|
+
if (CI) {
|
|
23
|
+
await exec("rimraf ./reports");
|
|
24
|
+
}
|
|
25
|
+
await test(commandOptions);
|
|
26
|
+
logSuccess("Unit test execution completed");
|
|
27
|
+
} catch (err) {
|
|
28
|
+
logError("Unit test execution failed", err);
|
|
29
|
+
yargs().exit(-1, err);
|
|
30
|
+
return -1;
|
|
31
|
+
}
|
|
32
|
+
return 0;
|
|
33
|
+
},
|
|
34
|
+
command: "vitest [options]",
|
|
35
|
+
describe: "unit tests application code using vitest",
|
|
36
|
+
builder: {
|
|
37
|
+
fix: {
|
|
38
|
+
alias: "f",
|
|
39
|
+
type: "boolean"
|
|
40
|
+
},
|
|
41
|
+
watch: {
|
|
42
|
+
alias: "w",
|
|
43
|
+
type: "boolean"
|
|
44
|
+
},
|
|
45
|
+
passWithNoTests: {
|
|
46
|
+
alias: "p",
|
|
47
|
+
type: "boolean"
|
|
48
|
+
},
|
|
49
|
+
related: {
|
|
50
|
+
alias: "r",
|
|
51
|
+
type: "boolean"
|
|
52
|
+
},
|
|
53
|
+
silent: {
|
|
54
|
+
alias: "s",
|
|
55
|
+
type: "boolean"
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
export {
|
|
60
|
+
vitestCmd
|
|
61
|
+
};
|
package/dist/esm/cli.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
import yargs from "yargs";
|
|
5
|
+
import { hideBin } from "yargs/helpers";
|
|
6
|
+
import { config as envConfig } from "dotenv";
|
|
7
|
+
import notifyUpdates from "./scripts/update-notifier.js";
|
|
8
|
+
import { buildCmd } from "./cli-commands/build.js";
|
|
9
|
+
import { packCmd } from "./cli-commands/pack.js";
|
|
10
|
+
import { startCmd } from "./cli-commands/start.js";
|
|
11
|
+
import { testCmd } from "./cli-commands/test.js";
|
|
12
|
+
import { lintCmd } from "./cli-commands/lint.js";
|
|
13
|
+
import { gendocCmd } from "./cli-commands/gendoc.js";
|
|
14
|
+
import { codemodCmd } from "./cli-commands/codemod.js";
|
|
15
|
+
import { storybookCmd } from "./cli-commands/storybook.js";
|
|
16
|
+
import { vitestCmd } from "./cli-commands/vitest.js";
|
|
17
|
+
import { versionCmd } from "./cli-commands/version.js";
|
|
18
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
19
|
+
envConfig();
|
|
20
|
+
process.env.PATH += path.delimiter + path.join(__dirname, "..", "node_modules", ".bin");
|
|
21
|
+
yargs(hideBin(process.argv)).command(buildCmd).help().argv;
|
|
22
|
+
yargs(hideBin(process.argv)).command(packCmd).help().argv;
|
|
23
|
+
yargs(hideBin(process.argv)).command(startCmd).help().argv;
|
|
24
|
+
yargs(hideBin(process.argv)).command(testCmd).help().argv;
|
|
25
|
+
yargs(hideBin(process.argv)).command(lintCmd).help().argv;
|
|
26
|
+
yargs(hideBin(process.argv)).command(gendocCmd).help().argv;
|
|
27
|
+
yargs(hideBin(process.argv)).command(codemodCmd).help().argv;
|
|
28
|
+
yargs(hideBin(process.argv)).command(storybookCmd).help().argv;
|
|
29
|
+
yargs(hideBin(process.argv)).command(vitestCmd).help().argv;
|
|
30
|
+
yargs(hideBin(process.argv)).command(versionCmd).help().argv;
|
|
31
|
+
notifyUpdates();
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"plugins": ["plugins/markdown"],
|
|
3
|
+
"opts": {
|
|
4
|
+
"template": "node_modules/docdash"
|
|
5
|
+
},
|
|
6
|
+
"docdash": {
|
|
7
|
+
"sort": true,
|
|
8
|
+
"search": true,
|
|
9
|
+
"collapse": true,
|
|
10
|
+
"wrap": true
|
|
11
|
+
},
|
|
12
|
+
"templates": {
|
|
13
|
+
"default": {
|
|
14
|
+
"includeDate": false
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { babelConfig } from "./babel/babel.config.cjs";
|
|
2
|
+
import { esConfig } from "./lint/eslint/non-react.cjs";
|
|
3
|
+
import { esReactConfig } from "./lint/eslint/react.cjs";
|
|
4
|
+
import { stylelintConfig } from "./lint/stylelint.config.cjs";
|
|
5
|
+
import { prettierConfig } from "./lint/prettier.config.cjs";
|
|
6
|
+
import { commitlintConfig } from "./lint/commitlint.config.cjs";
|
|
7
|
+
import { jestConfig } from "./testing/jest.config.cjs";
|
|
8
|
+
import { jestNodeConfig } from "./testing/jest.node.config.cjs";
|
|
9
|
+
import { lintStagedConfig } from "./lint/lint-staged.config.js";
|
|
10
|
+
import { loadRoutes } from "./server/util/index.js";
|
|
11
|
+
export {
|
|
12
|
+
babelConfig,
|
|
13
|
+
commitlintConfig,
|
|
14
|
+
esConfig as eslintBaseConfig,
|
|
15
|
+
esReactConfig as eslintConfig,
|
|
16
|
+
jestConfig,
|
|
17
|
+
jestNodeConfig,
|
|
18
|
+
lintStagedConfig,
|
|
19
|
+
loadRoutes,
|
|
20
|
+
prettierConfig,
|
|
21
|
+
stylelintConfig
|
|
22
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { fileURLToPath } from "node:url";
|
|
3
|
+
import fs from "node:fs";
|
|
4
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
5
|
+
const npmClient = fs.existsSync(path.join(process.cwd(), "pnpm-lock.yaml")) ? "pnpm" : "npm";
|
|
6
|
+
const lintStagedConfig = {
|
|
7
|
+
"*.{js,ts,jsx,tsx,md,mdx,html,css,json}": ["prettier --write"],
|
|
8
|
+
"*.{ts,tsx}": [
|
|
9
|
+
`node ${path.resolve(__dirname, "../typescript/tsc-files/index.js")} --noEmit --emitDeclarationOnly false`
|
|
10
|
+
],
|
|
11
|
+
"*.{js,ts,jsx,tsx}": [
|
|
12
|
+
`${npmClient} run lint:fix`,
|
|
13
|
+
`${npmClient} run test:staged`,
|
|
14
|
+
`${npmClient} run gendoc`
|
|
15
|
+
]
|
|
16
|
+
};
|
|
17
|
+
export {
|
|
18
|
+
lintStagedConfig
|
|
19
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { execSync } from "child_process";
|
|
2
|
+
const cwd = process.cwd();
|
|
3
|
+
const execaOptions = { cwd, stdio: "inherit" };
|
|
4
|
+
const semVerRegEx = /^v?(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/;
|
|
5
|
+
const isSemVersion = (tagName) => semVerRegEx.test(tagName);
|
|
6
|
+
const branchName = (process.env.BRANCH_NAME || "master").toLowerCase();
|
|
7
|
+
const branchTags = {
|
|
8
|
+
master: /^v?(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$/,
|
|
9
|
+
next: /^v.*-next\.(0|[1-9]\d*)/,
|
|
10
|
+
alpha: /^v.*-alpha\.(0|[1-9]\d*)/,
|
|
11
|
+
beta: /^v.*-beta\.(0|[1-9]\d*)/
|
|
12
|
+
};
|
|
13
|
+
const deleteTags = (cmd, filter) => {
|
|
14
|
+
const result = execSync(cmd, { cwd });
|
|
15
|
+
if (!result)
|
|
16
|
+
return;
|
|
17
|
+
const tags = result.toString().split("\n").join(" ");
|
|
18
|
+
execSync(`git tag -d ${filter ? filter(tags) : tags}`, { cwd });
|
|
19
|
+
};
|
|
20
|
+
const tagsFromOtherBranches = (tags = []) => {
|
|
21
|
+
const regex = branchTags[branchName] || branchTags.master;
|
|
22
|
+
return tags.split(" ").filter((tagName) => isSemVersion(tagName) && !regex.test(tagName)).join(" ");
|
|
23
|
+
};
|
|
24
|
+
const deleteMergedTags = () => {
|
|
25
|
+
try {
|
|
26
|
+
if (branchName) {
|
|
27
|
+
deleteTags(`git tag -l --no-merged ${branchName}`);
|
|
28
|
+
deleteTags(`git tag -l --merged ${branchName}`, tagsFromOtherBranches);
|
|
29
|
+
console.log("Last two tags: ");
|
|
30
|
+
execSync("git tag --sort=-creatordate | head -n 2", execaOptions);
|
|
31
|
+
}
|
|
32
|
+
} catch (error) {
|
|
33
|
+
console.error(error);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
export {
|
|
37
|
+
deleteMergedTags
|
|
38
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { readFile, writeFile } from "node:fs/promises";
|
|
2
|
+
import fg from "fast-glob";
|
|
3
|
+
import normalizePath from "normalize-path";
|
|
4
|
+
import { findMonoRepoRoot } from "./utils.js";
|
|
5
|
+
const monorepoRoot = normalizePath(findMonoRepoRoot() || "");
|
|
6
|
+
const setRegistryVersion = async () => {
|
|
7
|
+
const files = await fg([
|
|
8
|
+
`${monorepoRoot}/libs/*/package.json`,
|
|
9
|
+
`${monorepoRoot}/apps/*/package.json`,
|
|
10
|
+
`${monorepoRoot}/package.json`
|
|
11
|
+
]);
|
|
12
|
+
Promise.all(files.map(async (file) => {
|
|
13
|
+
let pkgJSONData = await readFile(file, "utf8");
|
|
14
|
+
const pkgVersion = JSON.parse(pkgJSONData).version;
|
|
15
|
+
pkgJSONData = pkgJSONData.replace(/workspace:\*/g, pkgVersion);
|
|
16
|
+
await writeFile(file, pkgJSONData);
|
|
17
|
+
}));
|
|
18
|
+
};
|
|
19
|
+
export {
|
|
20
|
+
setRegistryVersion
|
|
21
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { readFile, writeFile } from "node:fs/promises";
|
|
2
|
+
import fg from "fast-glob";
|
|
3
|
+
import normalizePath from "normalize-path";
|
|
4
|
+
import { findMonoRepoRoot } from "./utils.js";
|
|
5
|
+
const monorepoRoot = normalizePath(findMonoRepoRoot() || "");
|
|
6
|
+
const setWorkspaceVersion = async () => {
|
|
7
|
+
const files = await fg([
|
|
8
|
+
`${monorepoRoot}/libs/*/package.json`,
|
|
9
|
+
`${monorepoRoot}/apps/*/package.json`,
|
|
10
|
+
`${monorepoRoot}/package.json`
|
|
11
|
+
]);
|
|
12
|
+
Promise.all(files.map(async (file) => {
|
|
13
|
+
let pkgJSONData = await readFile(file, "utf8");
|
|
14
|
+
const pkgVersion = JSON.parse(pkgJSONData).version;
|
|
15
|
+
pkgJSONData = pkgJSONData.replace(new RegExp(pkgVersion, "g"), "workspace:*");
|
|
16
|
+
pkgJSONData = pkgJSONData.replace(/"version": "workspace:\*"/g, `"version": "${pkgVersion}"`);
|
|
17
|
+
await writeFile(file, pkgJSONData);
|
|
18
|
+
}));
|
|
19
|
+
};
|
|
20
|
+
export {
|
|
21
|
+
setWorkspaceVersion
|
|
22
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { findUpSync } from "find-up";
|
|
3
|
+
const WORKSPACE_DIR_ENV_VAR = "NPM_CONFIG_WORKSPACE_DIR";
|
|
4
|
+
const WORKSPACE_MANIFEST_FILENAME = "pnpm-workspace.yaml";
|
|
5
|
+
const findMonoRepoRoot = (cwd = process.cwd()) => {
|
|
6
|
+
const workspaceManifestDirEnvVar = process.env[WORKSPACE_DIR_ENV_VAR] ?? process.env[WORKSPACE_DIR_ENV_VAR.toLowerCase()];
|
|
7
|
+
const workspaceManifestLocation = workspaceManifestDirEnvVar ? path.join(workspaceManifestDirEnvVar, "pnpm-workspace.yaml") : findUpSync([WORKSPACE_MANIFEST_FILENAME, "pnpm-workspace.yml"], { cwd });
|
|
8
|
+
return workspaceManifestLocation && path.dirname(workspaceManifestLocation);
|
|
9
|
+
};
|
|
10
|
+
export {
|
|
11
|
+
findMonoRepoRoot
|
|
12
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import { merge } from "lodash";
|
|
4
|
+
const baseConfig = {
|
|
5
|
+
esBuild: {
|
|
6
|
+
target: "es2020"
|
|
7
|
+
}
|
|
8
|
+
};
|
|
9
|
+
const getPUIConfig = () => {
|
|
10
|
+
const configPath = path.resolve(process.cwd(), "./pui.config.js");
|
|
11
|
+
if (!fs.existsSync(configPath))
|
|
12
|
+
return baseConfig;
|
|
13
|
+
const config = JSON.parse(fs.readFileSync(configPath, "utf8"));
|
|
14
|
+
return merge(baseConfig, config);
|
|
15
|
+
};
|
|
16
|
+
export {
|
|
17
|
+
getPUIConfig
|
|
18
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import readline from "readline";
|
|
2
|
+
function progress_default(message, amountOfDots = 3) {
|
|
3
|
+
let i = 0;
|
|
4
|
+
return setInterval(() => {
|
|
5
|
+
readline.cursorTo(process.stdout, 0);
|
|
6
|
+
i = (i + 1) % (amountOfDots + 1);
|
|
7
|
+
const dots = new Array(i + 1).join(".");
|
|
8
|
+
process.stdout.write(message + dots);
|
|
9
|
+
}, 500);
|
|
10
|
+
}
|
|
11
|
+
export {
|
|
12
|
+
progress_default as default
|
|
13
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import updateNotifier from "update-notifier";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import fs from "node:fs/promises";
|
|
4
|
+
var update_notifier_default = async () => {
|
|
5
|
+
const pkgFile = await fs.readFile(path.join(process.cwd(), "./package.json"));
|
|
6
|
+
const pkg = JSON.parse(pkgFile);
|
|
7
|
+
updateNotifier({ pkg }).notify();
|
|
8
|
+
};
|
|
9
|
+
export {
|
|
10
|
+
update_notifier_default as default
|
|
11
|
+
};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import cspPolicy from "helmet-csp";
|
|
4
|
+
import crypto from "crypto";
|
|
5
|
+
const sources = [
|
|
6
|
+
"'self'",
|
|
7
|
+
"http://localhost:*",
|
|
8
|
+
"*.elliemae.io",
|
|
9
|
+
"*.elliemae.com",
|
|
10
|
+
"*.elliservices.com",
|
|
11
|
+
"*.ellielabs.com",
|
|
12
|
+
"http://pdx-col.eum-appdynamics.com",
|
|
13
|
+
"https://pdx-col.eum-appdynamics.com/",
|
|
14
|
+
"https://www.google-analytics.com",
|
|
15
|
+
"https://www.googletagmanager.com"
|
|
16
|
+
];
|
|
17
|
+
const sendFileWithCSPNonce = ({
|
|
18
|
+
buildPath,
|
|
19
|
+
page = "index.html",
|
|
20
|
+
nonceRegex = /__CSP_NONCE__/g,
|
|
21
|
+
res,
|
|
22
|
+
fileSystem = fs
|
|
23
|
+
}) => {
|
|
24
|
+
fileSystem.readFile(path.resolve(buildPath, page), "utf8", (err, html) => {
|
|
25
|
+
if (err) {
|
|
26
|
+
res.sendStatus(404);
|
|
27
|
+
} else {
|
|
28
|
+
res.set("Content-Type", "text/html");
|
|
29
|
+
res.send(html.replace(nonceRegex, (res.locals || {}).cspNonce));
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
};
|
|
33
|
+
const getScriptSrc = () => {
|
|
34
|
+
const scriptSrc = sources.concat([
|
|
35
|
+
(req, res) => `'nonce-${res.locals.cspNonce}'`
|
|
36
|
+
]);
|
|
37
|
+
return true ? scriptSrc.concat(["'unsafe-eval'"]) : scriptSrc;
|
|
38
|
+
};
|
|
39
|
+
const csp = (app) => {
|
|
40
|
+
app.use((req, res, next) => {
|
|
41
|
+
res.locals.cspNonce = crypto.randomBytes(16).toString("hex");
|
|
42
|
+
next();
|
|
43
|
+
});
|
|
44
|
+
app.use(cspPolicy({
|
|
45
|
+
directives: {
|
|
46
|
+
defaultSrc: ["'self'"],
|
|
47
|
+
baseUri: ["'self'"],
|
|
48
|
+
blockAllMixedContent: [],
|
|
49
|
+
connectSrc: sources,
|
|
50
|
+
fontSrc: sources.concat(["data:"]),
|
|
51
|
+
frameAncestors: sources,
|
|
52
|
+
imgSrc: sources.concat(["data:"]),
|
|
53
|
+
objectSrc: ["'none'"],
|
|
54
|
+
scriptSrc: getScriptSrc(),
|
|
55
|
+
scriptSrcAttr: ["'none'"],
|
|
56
|
+
styleSrc: sources.concat(["'unsafe-inline'"]),
|
|
57
|
+
upgradeInsecureRequests: [],
|
|
58
|
+
reportUri: "/v1/csp"
|
|
59
|
+
},
|
|
60
|
+
reportOnly: true
|
|
61
|
+
}));
|
|
62
|
+
};
|
|
63
|
+
export {
|
|
64
|
+
csp,
|
|
65
|
+
sendFileWithCSPNonce
|
|
66
|
+
};
|