express-fix-any-js 1.7.2 → 1.7.7

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.
@@ -0,0 +1,27 @@
1
+ const startFunc = ({
2
+ content,
3
+ insertInfo,
4
+ toInsertLine,
5
+ insertAfter
6
+ }) => {
7
+ const before = content.slice(0, insertInfo.index);
8
+
9
+ const isFirstInsert =
10
+ insertInfo.matchedPattern === insertAfter[insertAfter.length - 1];
11
+
12
+ if (Array.isArray(toInsertLine)) {
13
+ return before +
14
+ (isFirstInsert ? "\n" : "") +
15
+ toInsertLine.join("\n") +
16
+ "\n" +
17
+ content.slice(insertInfo.index);
18
+ }
19
+
20
+ return before +
21
+ (isFirstInsert ? "\n" : "") +
22
+ toInsertLine +
23
+ "\n" +
24
+ content.slice(insertInfo.index);
25
+ };
26
+
27
+ export default startFunc;
@@ -0,0 +1,21 @@
1
+ const checkUseDuplicate = ({
2
+ inContent,
3
+ inFilePath,
4
+ inSearchText
5
+ }) => {
6
+ const lines = inContent.split("\n");
7
+
8
+ const lineIndex = lines.findIndex(line =>
9
+ line.includes(inSearchText)
10
+ );
11
+
12
+ return {
13
+ found: lineIndex !== -1,
14
+ filePath: inFilePath,
15
+ lineNumber: lineIndex !== -1
16
+ ? lineIndex + 1
17
+ : null
18
+ };
19
+ };
20
+
21
+ export default checkUseDuplicate;
@@ -0,0 +1,30 @@
1
+ const findInsertIndex = ({
2
+ inContent,
3
+ inPatterns = []
4
+ }) => {
5
+ const lines = inContent.split("\n");
6
+
7
+ let lineNumber = -1;
8
+ let matchedPattern = null;
9
+
10
+ lines.forEach((line, index) => {
11
+ const pattern = inPatterns.find(item => line.includes(item));
12
+
13
+ if (pattern) {
14
+ lineNumber = index;
15
+ matchedPattern = pattern;
16
+ };
17
+ });
18
+
19
+ return {
20
+ index: lineNumber === -1
21
+ ? -1
22
+ : lines
23
+ .slice(0, lineNumber + 1)
24
+ .join("\n")
25
+ .length + 1,
26
+ matchedPattern
27
+ };
28
+ };
29
+
30
+ export default findInsertIndex;
@@ -0,0 +1,61 @@
1
+ import readFile from "../readFile.js";
2
+ import checkDuplicate from "./checkDuplicate.js";
3
+ import findInsertIndex from "./findInsertIndex.js";
4
+ import writeFile from "../writeFile.js";
5
+
6
+ import buildUpdatedContent from "./buildUpdatedContent.js";
7
+
8
+ const locateInsertPoint = ({ content, insertAfter }) => {
9
+ return findInsertIndex({
10
+ inContent: content,
11
+ inPatterns: insertAfter
12
+ });
13
+ };
14
+
15
+ const alterFile = ({
16
+ jsFilePath,
17
+ toInsertLine,
18
+ duplicationCheck,
19
+ insertAfter = [],
20
+ showLog = false
21
+ }) => {
22
+ const content = readFile(jsFilePath);
23
+
24
+ const duplicateInfo = checkDuplicate({
25
+ inContent: content,
26
+ inFilePath: jsFilePath,
27
+ inSearchText: duplicationCheck
28
+ });
29
+
30
+ if (duplicateInfo.found) {
31
+ if (showLog) {
32
+ console.log(
33
+ `Duplicate found at line ${duplicateInfo.lineNumber}`
34
+ );
35
+ }
36
+
37
+ return duplicateInfo;
38
+ };
39
+
40
+ const insertInfo = locateInsertPoint({
41
+ content,
42
+ insertAfter
43
+ });
44
+
45
+ const updated = buildUpdatedContent({
46
+ content,
47
+ insertInfo,
48
+ toInsertLine,
49
+ insertAfter
50
+ });
51
+
52
+ writeFile(jsFilePath, updated);
53
+
54
+ return {
55
+ found: false,
56
+ filePath: jsFilePath,
57
+ lineNumber: null
58
+ };
59
+ };
60
+
61
+ export default alterFile;
@@ -0,0 +1,27 @@
1
+ const startFunc = ({
2
+ content,
3
+ insertInfo,
4
+ toInsertLine,
5
+ insertAfter
6
+ }) => {
7
+ const before = content.slice(0, insertInfo.index);
8
+
9
+ const isFirstInsert =
10
+ insertInfo.matchedPattern === insertAfter[insertAfter.length - 1];
11
+
12
+ if (Array.isArray(toInsertLine)) {
13
+ return before +
14
+ (isFirstInsert ? "\n" : "") +
15
+ toInsertLine.join("\n") +
16
+ "\n" +
17
+ content.slice(insertInfo.index);
18
+ }
19
+
20
+ return before +
21
+ (isFirstInsert ? "\n" : "") +
22
+ toInsertLine +
23
+ "\n" +
24
+ content.slice(insertInfo.index);
25
+ };
26
+
27
+ export default startFunc;
@@ -0,0 +1,14 @@
1
+ import { isImportPresent } from "express-check-any-for-import";
2
+
3
+ const checkUseDuplicate = ({ inContent, inFilePath, inSearchText }) => {
4
+ const cleanText = inSearchText.match(/['"]([^'"]+)['"]/)?.[1] || inSearchText;
5
+ const found = isImportPresent(inContent, cleanText) || inContent.includes(inSearchText);
6
+
7
+ return {
8
+ found,
9
+ filePath: inFilePath,
10
+ lineNumber: found ? inContent.split("\n").findIndex(line => line.includes(cleanText)) + 1 : null
11
+ };
12
+ };
13
+
14
+ export default checkUseDuplicate;
@@ -0,0 +1,30 @@
1
+ const findInsertIndex = ({
2
+ inContent,
3
+ inPatterns = []
4
+ }) => {
5
+ const lines = inContent.split("\n");
6
+
7
+ let lineNumber = -1;
8
+ let matchedPattern = null;
9
+
10
+ lines.forEach((line, index) => {
11
+ const pattern = inPatterns.find(item => line.includes(item));
12
+
13
+ if (pattern) {
14
+ lineNumber = index;
15
+ matchedPattern = pattern;
16
+ };
17
+ });
18
+
19
+ return {
20
+ index: lineNumber === -1
21
+ ? -1
22
+ : lines
23
+ .slice(0, lineNumber + 1)
24
+ .join("\n")
25
+ .length + 1,
26
+ matchedPattern
27
+ };
28
+ };
29
+
30
+ export default findInsertIndex;
@@ -0,0 +1,61 @@
1
+ import readFile from "../readFile.js";
2
+ import checkDuplicate from "./checkDuplicate.js";
3
+ import findInsertIndex from "./findInsertIndex.js";
4
+ import writeFile from "../writeFile.js";
5
+
6
+ import buildUpdatedContent from "./buildUpdatedContent.js";
7
+
8
+ const locateInsertPoint = ({ content, insertAfter }) => {
9
+ return findInsertIndex({
10
+ inContent: content,
11
+ inPatterns: insertAfter
12
+ });
13
+ };
14
+
15
+ const alterFile = ({
16
+ jsFilePath,
17
+ toInsertLine,
18
+ duplicationCheck,
19
+ insertAfter = [],
20
+ showLog = false
21
+ }) => {
22
+ const content = readFile(jsFilePath);
23
+
24
+ const duplicateInfo = checkDuplicate({
25
+ inContent: content,
26
+ inFilePath: jsFilePath,
27
+ inSearchText: duplicationCheck
28
+ });
29
+
30
+ if (duplicateInfo.found) {
31
+ if (showLog) {
32
+ console.log(
33
+ `Duplicate found at line ${duplicateInfo.lineNumber}`
34
+ );
35
+ }
36
+
37
+ return duplicateInfo;
38
+ };
39
+
40
+ const insertInfo = locateInsertPoint({
41
+ content,
42
+ insertAfter
43
+ });
44
+
45
+ const updated = buildUpdatedContent({
46
+ content,
47
+ insertInfo,
48
+ toInsertLine,
49
+ insertAfter
50
+ });
51
+
52
+ writeFile(jsFilePath, updated);
53
+
54
+ return {
55
+ found: false,
56
+ filePath: jsFilePath,
57
+ lineNumber: null
58
+ };
59
+ };
60
+
61
+ export default alterFile;
@@ -1,14 +1,16 @@
1
- import alterFile from "./common/AlterFile/index.js";
1
+ // import alterFile from "./common/AlterFile/index.js";
2
2
  import validateCheckLines from "./validateCheckLines.js";
3
+ import alterFileForImport from "./common/AlterFileForImport/index.js";
4
+ import alterFileForConsume from "./common/AlterFileForConsume/index.js";
3
5
 
4
6
  const updateAppJs = ({ inJsFilePath, inCheckLines,
5
7
  showLog = false }) => {
6
8
 
7
9
  const localCheckLines = inCheckLines;
8
-
10
+
9
11
  validateCheckLines(localCheckLines);
10
12
 
11
- const importResult = alterFile({
13
+ const importResult = alterFileForImport({
12
14
  jsFilePath: inJsFilePath,
13
15
  toInsertLine: localCheckLines.importLines.toInsertLine,
14
16
  duplicationCheck: localCheckLines.importLines.duplicationCheck,
@@ -16,7 +18,7 @@ const updateAppJs = ({ inJsFilePath, inCheckLines,
16
18
  showLog
17
19
  });
18
20
 
19
- const useResult = alterFile({
21
+ const useResult = alterFileForConsume({
20
22
  jsFilePath: inJsFilePath,
21
23
  toInsertLine: localCheckLines.useLines.toInsertLine,
22
24
  duplicationCheck: localCheckLines.useLines.duplicationCheck,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "express-fix-any-js",
3
- "version": "1.7.2",
3
+ "version": "1.7.7",
4
4
  "description": "CLI to build for appjs, the endpoints",
5
5
  "keywords": [
6
6
  "cli",
@@ -10,7 +10,7 @@
10
10
  "project-generator"
11
11
  ],
12
12
  "dependencies": {
13
- "express-check-any-for-import": "file:../ks1/express-check-any-for-import"
13
+ "express-check-any-for-import": "^1.4.6"
14
14
  },
15
15
  "type": "module",
16
16
  "exports": {
@@ -33,4 +33,4 @@
33
33
  "bugs": {
34
34
  "url": "https://github.com/keshavsoft/express-fix-any-js/issues"
35
35
  }
36
- }
36
+ }