@bigbinary/neeto-audit-frontend 1.0.7 → 1.0.9

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bigbinary/neeto-audit-frontend",
3
- "version": "1.0.7",
3
+ "version": "1.0.9",
4
4
  "description": "Audits neeto frontend codebase for issues and suggests a fix.",
5
5
  "type": "module",
6
6
  "bin": "./dist/index.js",
package/src/cli.js CHANGED
@@ -1,3 +1,5 @@
1
+ import chalk from "chalk";
2
+
1
3
  import { getCliOptions, runVerifiers } from "./utils";
2
4
  import verifiers from "./verifiers";
3
5
 
@@ -7,4 +9,6 @@ const run = async () => {
7
9
  runVerifiers({ verifiers, autoFix, debug });
8
10
  };
9
11
 
10
- run();
12
+ process.env.SKIP_AUDIT === "true"
13
+ ? console.log(chalk.green("Skipped frontend audit"))
14
+ : run();
@@ -1,3 +1,17 @@
1
1
  import path from "path";
2
2
 
3
3
  export const PACKAGE_JSON_PATH = path.resolve("./package.json");
4
+
5
+ export const STATUSES = {
6
+ PASS: "PASS",
7
+ FAIL: "FAIL",
8
+ SKIPPED: "SKIPPED",
9
+ };
10
+
11
+ export const NANO_TYPE_MAP = {
12
+ nano: "nano",
13
+ frontend: "frontend",
14
+ extension: "extension",
15
+ editor: "frontend",
16
+ molecules: "frontend",
17
+ };
@@ -10,7 +10,7 @@ import { identity, last, split } from "ramda";
10
10
  import { simpleGit } from "simple-git";
11
11
  import util from "util";
12
12
 
13
- import { PACKAGE_JSON_PATH } from "../constants";
13
+ import { NANO_TYPE_MAP, PACKAGE_JSON_PATH } from "../constants";
14
14
 
15
15
  const run = util.promisify(exec);
16
16
 
@@ -36,10 +36,10 @@ const renderErrors = (errors = [], isAutoFixFlagPresent = false) => {
36
36
  const getResults = async ({ verifiers, debug }) => {
37
37
  let errors = [];
38
38
  const results = verifiers.map(async ([name, verifier]) => {
39
- const { isSuccess = false, error } = await verifier(debug);
39
+ const { isSuccess = false, error, status } = await verifier(debug);
40
40
  !isSuccess && errors.push(error);
41
41
 
42
- return { name, isSuccess };
42
+ return { name, isSuccess, status };
43
43
  });
44
44
 
45
45
  const allResults = await Promise.all(results);
@@ -219,10 +219,10 @@ export const runVerifiers = async ({ verifiers, autoFix, debug }) => {
219
219
  const { results, errors } = await getResults({ verifiers, autoFix, debug });
220
220
  const isErrorPresent = isNotEmpty(errors);
221
221
 
222
- results.map(({ name, isSuccess }) => {
222
+ results.map(({ name, isSuccess, status }) => {
223
223
  const resultText = isSuccess
224
- ? chalk.bgGreen.black("PASS")
225
- : chalk.bgRed.black("FAIL");
224
+ ? chalk.bgGreen.black(status)
225
+ : chalk.bgRed.black(status);
226
226
  console.log(resultText, name);
227
227
  });
228
228
 
@@ -256,7 +256,10 @@ export const getNanoType = async () => {
256
256
 
257
257
  const projectName = projectGitName.split(".git").at(0);
258
258
 
259
- return last(split("-", projectName));
259
+ return {
260
+ type: NANO_TYPE_MAP[last(split("-", projectName))],
261
+ repoName: projectName,
262
+ };
260
263
  };
261
264
 
262
265
  export const getPackageJson = async (debug) => {
@@ -1,6 +1,7 @@
1
1
  import { NVMRC_FILE_PATH, REQUIRED_NODE_VERSION } from "./constants";
2
2
  import { createOrReplaceFile, getFileContent } from "../../utils";
3
3
  import { getSemVer } from "./utils";
4
+ import { STATUSES } from "../../constants";
4
5
 
5
6
  const currentNodeVersion = async (debug) => {
6
7
  const fix = async (debug) => {
@@ -28,10 +29,14 @@ const currentNodeVersion = async (debug) => {
28
29
  patch >= REQUIRED_NODE_VERSION.patch;
29
30
 
30
31
  if (!isSuccess) {
31
- return { error: "There is a mismatch in the node version.", fix };
32
+ return {
33
+ error: "There is a mismatch in the node version.",
34
+ status: STATUSES.FAIL,
35
+ fix,
36
+ };
32
37
  }
33
38
 
34
- return { isSuccess };
39
+ return { isSuccess, status: STATUSES.PASS };
35
40
  };
36
41
 
37
42
  export default currentNodeVersion;
@@ -7,13 +7,18 @@ import {
7
7
  identicalDirectoryFiles,
8
8
  } from "../../utils";
9
9
  import { ESLINT_DESTINATION_DIRECTORY, NANOS_TO_OVERRIDE } from "./constants";
10
+ import { STATUSES } from "../../constants";
10
11
 
11
12
  const eslint = async (debug) => {
12
- const nanoType = await getNanoType();
13
+ const { type, repoName } = await getNanoType();
13
14
 
14
- const eslintCommonSource = NANOS_TO_OVERRIDE.includes(nanoType)
15
- ? nanoType
16
- : "common";
15
+ // neeto-molecules has different ESLint rules disabled. This does not match other frontend packages.
16
+ // So, decided to skip this check instead of adding a different config check just for a single repo.
17
+ if (repoName === "neeto-molecules") {
18
+ return { isSuccess: true, status: STATUSES.SKIPPED };
19
+ }
20
+
21
+ const eslintCommonSource = NANOS_TO_OVERRIDE.includes(type) ? type : "common";
17
22
 
18
23
  const eslintSourceDirectory = path.resolve(
19
24
  `./node_modules/@bigbinary/neeto-audit-frontend/common/eslint/${eslintCommonSource}`
@@ -38,10 +43,14 @@ const eslint = async (debug) => {
38
43
  const isSuccess = eslintFiles.every(identity);
39
44
 
40
45
  if (!isSuccess) {
41
- return { error: "ESLint and its related files are not present.", fix };
46
+ return {
47
+ error: "ESLint and its related files are not present.",
48
+ status: STATUSES.FAIL,
49
+ fix,
50
+ };
42
51
  }
43
52
 
44
- return { isSuccess };
53
+ return { isSuccess, status: STATUSES.PASS };
45
54
  };
46
55
 
47
56
  export default eslint;
@@ -12,11 +12,12 @@ import {
12
12
  HUSKY_SOURCE_DIRECTORY,
13
13
  HUSKY_COMMON_SOURCE_DIRECTORY,
14
14
  } from "./constants";
15
+ import { STATUSES } from "../../constants";
15
16
 
16
17
  const husky = async (debug) => {
17
- const nanoType = await getNanoType();
18
+ const { type } = await getNanoType();
18
19
 
19
- const nanoSourceDirectory = `${HUSKY_SOURCE_DIRECTORY}/${nanoType}`;
20
+ const nanoSourceDirectory = `${HUSKY_SOURCE_DIRECTORY}/${type}`;
20
21
 
21
22
  const fix = async (debug) => {
22
23
  await createOrReplaceDirectoryFiles({
@@ -60,10 +61,14 @@ const husky = async (debug) => {
60
61
  const isSuccess = huskyFiles.every(identity);
61
62
 
62
63
  if (!isSuccess) {
63
- return { error: "Some husky helper files are not present.", fix };
64
+ return {
65
+ error: "Some husky helper files are not present.",
66
+ status: STATUSES.FAIL,
67
+ fix,
68
+ };
64
69
  }
65
70
 
66
- return { isSuccess };
71
+ return { isSuccess, status: STATUSES.PASS };
67
72
  };
68
73
 
69
74
  export default husky;
@@ -7,11 +7,18 @@ import {
7
7
  identicalDirectoryFiles,
8
8
  } from "../../utils";
9
9
  import { PRETTIER_DESTINATION_PATH } from "./constants";
10
+ import { STATUSES } from "../../constants";
10
11
 
11
12
  const prettier = async (debug) => {
12
- const nanoType = await getNanoType();
13
+ const { type, repoName } = await getNanoType();
13
14
 
14
- const prettierCommonSource = nanoType === "extension" ? nanoType : "common";
15
+ // neeto-molecules uses custom tailwind plugins for styles. This does not match other frontend packages.
16
+ // So, decided to skip this check instead of adding a different config check just for a single repo.
17
+ if (repoName === "neeto-molecules") {
18
+ return { isSuccess: true, status: STATUSES.SKIPPED };
19
+ }
20
+
21
+ const prettierCommonSource = type === "extension" ? type : "common";
15
22
 
16
23
  const prettierSourceDirectory = path.resolve(
17
24
  `./node_modules/@bigbinary/neeto-audit-frontend/common/prettier/${prettierCommonSource}`
@@ -38,11 +45,12 @@ const prettier = async (debug) => {
38
45
  if (!isSuccess) {
39
46
  return {
40
47
  error: "There are some discrepancy in the prettier configurations.",
48
+ status: STATUSES.FAIL,
41
49
  fix,
42
50
  };
43
51
  }
44
52
 
45
- return { isSuccess };
53
+ return { isSuccess, status: STATUSES.PASS };
46
54
  };
47
55
 
48
56
  export default prettier;
@@ -2,7 +2,7 @@ import { existsBy, isNotEmpty } from "@bigbinary/neeto-commons-frontend/pure";
2
2
  import { mergeDeepRight, objOf } from "ramda";
3
3
 
4
4
  import recommendedDependencies from "../../../common/recommendedDependencies";
5
- import { PACKAGE_JSON_PATH } from "../../constants";
5
+ import { PACKAGE_JSON_PATH, STATUSES } from "../../constants";
6
6
  import {
7
7
  createOrReplaceFile,
8
8
  execute,
@@ -18,11 +18,11 @@ import {
18
18
  const recommendedPackageVersions = async (debug) => {
19
19
  const packageJson = await getPackageJson(debug);
20
20
 
21
- const nanoType = await getNanoType();
21
+ const { type } = await getNanoType();
22
22
 
23
23
  const recommendedVersions = mergeDeepRight(
24
24
  recommendedDependencies["common"],
25
- recommendedDependencies[nanoType]
25
+ recommendedDependencies[type]
26
26
  );
27
27
 
28
28
  const packagesToUpdate = getOutdatedPackages(
@@ -62,11 +62,12 @@ const recommendedPackageVersions = async (debug) => {
62
62
  if (!isSuccess) {
63
63
  return {
64
64
  error: "The dependency packages are not using the recommended versions.",
65
+ status: STATUSES.FAIL,
65
66
  fix,
66
67
  };
67
68
  }
68
69
 
69
- return { isSuccess };
70
+ return { isSuccess, status: STATUSES.PASS };
70
71
  };
71
72
 
72
73
  export default recommendedPackageVersions;