express-fix-any-js 1.11.3 → 1.13.3

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.
Files changed (47) hide show
  1. package/bin/v12/UpdateJs/bothLines/forImportLine/index.js +30 -0
  2. package/bin/v12/UpdateJs/bothLines/forImportLine/insertImportLine.js +55 -0
  3. package/bin/v12/UpdateJs/bothLines/forInsertIndex.js +19 -0
  4. package/bin/v12/UpdateJs/bothLines/forUseLine/index.js +29 -0
  5. package/bin/{v11/UpdateJs/bothLines → v12/UpdateJs/bothLines/forUseLine}/insertUseLine.js +14 -2
  6. package/bin/v12/UpdateJs/bothLines/index.js +11 -0
  7. package/bin/{v11 → v12}/UpdateJs/index.js +1 -1
  8. package/bin/v13/UpdateJs/bothLines/forImportLine/index.js +30 -0
  9. package/bin/v13/UpdateJs/bothLines/forImportLine/insertImportLine.js +55 -0
  10. package/bin/v13/UpdateJs/bothLines/forInsertIndex.js +30 -0
  11. package/bin/v13/UpdateJs/bothLines/forUseLine/index.js +29 -0
  12. package/bin/v13/UpdateJs/bothLines/forUseLine/insertUseLine.js +44 -0
  13. package/bin/v13/UpdateJs/bothLines/index.js +11 -0
  14. package/bin/v13/UpdateJs/index.js +11 -0
  15. package/package.json +2 -2
  16. package/bin/v10/UpdateJs/common/AlterFileForConsume/buildUpdatedContent.js +0 -28
  17. package/bin/v10/UpdateJs/common/AlterFileForConsume/checkDuplicate.js +0 -21
  18. package/bin/v10/UpdateJs/common/AlterFileForConsume/findInsertIndex.js +0 -30
  19. package/bin/v10/UpdateJs/common/AlterFileForConsume/index.js +0 -61
  20. package/bin/v10/UpdateJs/common/AlterFileForImport/buildUpdatedContent copy.js +0 -27
  21. package/bin/v10/UpdateJs/common/AlterFileForImport/buildUpdatedContent.js +0 -41
  22. package/bin/v10/UpdateJs/common/AlterFileForImport/checkDuplicate.js +0 -14
  23. package/bin/v10/UpdateJs/common/AlterFileForImport/findInsertIndex.js +0 -30
  24. package/bin/v10/UpdateJs/common/AlterFileForImport/index.js +0 -61
  25. package/bin/v10/UpdateJs/common/readFile.js +0 -8
  26. package/bin/v10/UpdateJs/common/writeFile.js +0 -10
  27. package/bin/v10/UpdateJs/index.js +0 -33
  28. package/bin/v10/UpdateJs/validateCheckLines.js +0 -31
  29. package/bin/v10/core/parseInput.js +0 -13
  30. package/bin/v10/core/showUsage.js +0 -50
  31. package/bin/v11/UpdateJs/bothLines/insertImportLine.js +0 -27
  32. package/bin/v11/UpdateJs/bothLines/test.js +0 -57
  33. package/bin/v11/UpdateJs/common/AlterFileForConsume/buildUpdatedContent.js +0 -28
  34. package/bin/v11/UpdateJs/common/AlterFileForConsume/checkDuplicate.js +0 -21
  35. package/bin/v11/UpdateJs/common/AlterFileForConsume/findInsertIndex.js +0 -30
  36. package/bin/v11/UpdateJs/common/AlterFileForConsume/index.js +0 -61
  37. package/bin/v11/UpdateJs/common/AlterFileForImport/buildUpdatedContent copy.js +0 -27
  38. package/bin/v11/UpdateJs/common/AlterFileForImport/buildUpdatedContent.js +0 -41
  39. package/bin/v11/UpdateJs/common/AlterFileForImport/checkDuplicate.js +0 -14
  40. package/bin/v11/UpdateJs/common/AlterFileForImport/findInsertIndex.js +0 -30
  41. package/bin/v11/UpdateJs/common/AlterFileForImport/index.js +0 -61
  42. package/bin/v11/UpdateJs/common/readFile.js +0 -8
  43. package/bin/v11/UpdateJs/common/writeFile.js +0 -10
  44. package/bin/v11/UpdateJs/index copy.js +0 -33
  45. package/bin/v11/UpdateJs/validateCheckLines.js +0 -31
  46. /package/bin/{v10 → v12}/start.js +0 -0
  47. /package/bin/{v11 → v13}/start.js +0 -0
@@ -0,0 +1,30 @@
1
+ import fs from "fs";
2
+
3
+ import defaultFunc from 'pattern-collector-anyjs-story';
4
+ import insertImportLine from "./insertImportLine.js";
5
+
6
+ const startFunc = ({ inFolderNameToInsert, inFileType, inJsPath }) => {
7
+ const folderNameToInsert = inFolderNameToInsert;
8
+ const localJsPath = inJsPath;
9
+
10
+ const fileContent = fs.readFileSync(localJsPath, 'utf8');
11
+
12
+ const story = defaultFunc({
13
+ fileContent,
14
+ fileType: inFileType
15
+ });
16
+
17
+ insertImportLine({
18
+ inStory: story,
19
+ fileContent,
20
+ filePath: localJsPath, inFolderNameToInsert: folderNameToInsert,
21
+ inTemplate1: story.regexForPullLinesStory.importRegex.reverseTemplate,
22
+ inTemplate: story.reverseTemplates.importRegex,
23
+ inParts: [`${story.variablesConnection}${folderNameToInsert}`, folderNameToInsert]
24
+ });
25
+
26
+ };
27
+
28
+ export default startFunc;
29
+
30
+ // startFunc({ folderNameToInsert, fileType });
@@ -0,0 +1,55 @@
1
+ import fs from 'fs';
2
+
3
+ function build(template, parts) {
4
+ return template.replace(/\{(\d+)\}/g, (_, i) => parts[i]);
5
+ };
6
+
7
+ const findImportLinesFromNpmIndex = ({ inStory }) => {
8
+ const importLinesFromNpm = inStory?.linesStory?.importLinesFromNpm;
9
+
10
+ const lastLine = importLinesFromNpm[importLinesFromNpm.length - 1];
11
+
12
+ return lastLine?.lineNumber;
13
+ };
14
+
15
+ const findImportLinesIndex = ({ inStory }) => {
16
+ const importLines = inStory?.linesStory?.importLines;
17
+
18
+ const lastLine = importLines[importLines.length - 1];
19
+
20
+ return lastLine?.lineNumber;
21
+ };
22
+
23
+ const findInsertIndex = ({ inStory }) => {
24
+ const importLines = findImportLinesIndex({ inStory });
25
+ const importLinesFromNpm = findImportLinesFromNpmIndex({ inStory });
26
+
27
+ return importLines ? importLines : importLinesFromNpm;
28
+ };
29
+
30
+ const startFunc = ({ inStory, fileContent, filePath,
31
+ inFolderNameToInsert, lineType = "importLines", inTemplate, inParts }) => {
32
+
33
+ const foundUseLinesStory = inStory.linesStory[lineType].find(element => {
34
+ return element.part1 === inFolderNameToInsert;
35
+ });
36
+
37
+ if (!foundUseLinesStory) {
38
+ const newLine = build(inTemplate, inParts);
39
+
40
+ const lines = fileContent.split(/\r?\n/);
41
+
42
+ // findInsertIndex({ inStory });
43
+
44
+ // const lastLine = inStory.lines[lineType][inStory.lines[lineType].length - 1];
45
+ // const insertAtIndex = lastLine.lineNumber;
46
+
47
+ const insertAtIndex = findInsertIndex({ inStory });
48
+
49
+ lines.splice(insertAtIndex, 0, newLine);
50
+
51
+ fs.writeFileSync(filePath, lines.join(fileContent.includes("\r\n") ? "\r\n" : "\n"));
52
+ };
53
+ };
54
+
55
+ export default startFunc;
@@ -0,0 +1,19 @@
1
+ import fs from 'fs';
2
+
3
+ const findImportLinesFromNpmIndex = ({ inStory }) => {
4
+ const importLinesFromNpm = inStory?.linesStory?.importLinesFromNpm;
5
+
6
+ const lastLine = importLinesFromNpm[importLinesFromNpm.length - 1];
7
+
8
+ return lastLine?.lineNumber;
9
+ };
10
+
11
+ const findImportLinesIndex = ({ inStory }) => {
12
+ const importLines = inStory?.linesStory?.importLines;
13
+
14
+ const lastLine = importLines[importLines.length - 1];
15
+
16
+ return lastLine?.lineNumber;
17
+ };
18
+
19
+ export { findImportLinesFromNpmIndex, findImportLinesIndex };
@@ -0,0 +1,29 @@
1
+ import fs from 'fs';
2
+
3
+ import defaultFunc from 'pattern-collector-anyjs-story';
4
+ import insertUseLine from "./insertUseLine.js";
5
+
6
+ const startFunc = ({ inFolderNameToInsert, inFileType, inJsPath }) => {
7
+ const folderNameToInsert = inFolderNameToInsert;
8
+ const localJsPath = inJsPath;
9
+
10
+ const fileContent = fs.readFileSync(localJsPath, 'utf8');
11
+
12
+ const story = defaultFunc({
13
+ fileContent,
14
+ fileType: inFileType
15
+ });
16
+
17
+ insertUseLine({
18
+ inStory: story,
19
+ fileContent,
20
+ filePath: localJsPath, inFolderNameToInsert: folderNameToInsert,
21
+ inTemplate1: story.regexForPullLinesStory.consumptionRegex.reverseTemplate,
22
+ inTemplate: story.reverseTemplates.consumptionRegex,
23
+ inParts: [folderNameToInsert, `${story.variablesConnection}${folderNameToInsert}`]
24
+ });
25
+ };
26
+
27
+ export default startFunc;
28
+
29
+ // startFunc({ folderNameToInsert, fileType });
@@ -1,5 +1,14 @@
1
1
  import fs from 'fs';
2
2
 
3
+ import { findImportLinesFromNpmIndex, findImportLinesIndex } from "../forInsertIndex.js";
4
+
5
+ const findInsertIndex = ({ inStory }) => {
6
+ const importLines = findImportLinesIndex({ inStory });
7
+ const importLinesFromNpm = findImportLinesFromNpmIndex({ inStory });
8
+
9
+ return importLines ? importLines : importLinesFromNpm;
10
+ };
11
+
3
12
  function build(template, parts) {
4
13
  return template.replace(/\{(\d+)\}/g, (_, i) => parts[i]);
5
14
  };
@@ -16,8 +25,11 @@ const startFunc = ({ inStory, fileContent, filePath,
16
25
 
17
26
  const lines = fileContent.split(/\r?\n/);
18
27
 
19
- const lastUseLine = inStory.lines[lineType][inStory.lines[lineType].length - 1];
20
- const insertAtIndex = lastUseLine.lineNumber;
28
+ // const lastUseLine = inStory.lines[lineType][inStory.lines[lineType].length - 1];
29
+ // const insertAtIndex = lastUseLine.lineNumber;
30
+
31
+ const insertAtIndex = findInsertIndex({ inStory });
32
+
21
33
  lines.splice(insertAtIndex, 0, newLine);
22
34
 
23
35
  fs.writeFileSync(filePath, lines.join(fileContent.includes("\r\n") ? "\r\n" : "\n"));
@@ -0,0 +1,11 @@
1
+ import forImportLine from "./forImportLine/index.js";
2
+ import forUseLine from "./forUseLine/index.js";
3
+
4
+ const startFunc = ({ inFolderNameToInsert, inFileType, inJsPath }) => {
5
+ forImportLine({ inFolderNameToInsert, inFileType, inJsPath })
6
+ forUseLine({ inFolderNameToInsert, inFileType, inJsPath })
7
+ };
8
+
9
+ export default startFunc;
10
+
11
+ // startFunc({ folderNameToInsert, fileType });
@@ -1,4 +1,4 @@
1
- import bothLines from './bothLines/test.js';
1
+ import bothLines from './bothLines/index.js';
2
2
 
3
3
  const startFunc = ({ inFolderNameToInsert, inFileType, jsFilePath }) => {
4
4
 
@@ -0,0 +1,30 @@
1
+ import fs from "fs";
2
+
3
+ import defaultFunc from 'pattern-collector-anyjs-story';
4
+ import insertImportLine from "./insertImportLine.js";
5
+
6
+ const startFunc = ({ inFolderNameToInsert, inFileType, inJsPath }) => {
7
+ const folderNameToInsert = inFolderNameToInsert;
8
+ const localJsPath = inJsPath;
9
+
10
+ const fileContent = fs.readFileSync(localJsPath, 'utf8');
11
+
12
+ const story = defaultFunc({
13
+ fileContent,
14
+ fileType: inFileType
15
+ });
16
+
17
+ insertImportLine({
18
+ inStory: story,
19
+ fileContent,
20
+ filePath: localJsPath, inFolderNameToInsert: folderNameToInsert,
21
+ inTemplate1: story.regexForPullLinesStory.importRegex.reverseTemplate,
22
+ inTemplate: story.reverseTemplates.importRegex,
23
+ inParts: [`${story.variablesConnection}${folderNameToInsert}`, folderNameToInsert]
24
+ });
25
+
26
+ };
27
+
28
+ export default startFunc;
29
+
30
+ // startFunc({ folderNameToInsert, fileType });
@@ -0,0 +1,55 @@
1
+ import fs from 'fs';
2
+
3
+ function build(template, parts) {
4
+ return template.replace(/\{(\d+)\}/g, (_, i) => parts[i]);
5
+ };
6
+
7
+ const findImportLinesFromNpmIndex = ({ inStory }) => {
8
+ const importLinesFromNpm = inStory?.linesStory?.importLinesFromNpm;
9
+
10
+ const lastLine = importLinesFromNpm[importLinesFromNpm.length - 1];
11
+
12
+ return lastLine?.lineNumber;
13
+ };
14
+
15
+ const findImportLinesIndex = ({ inStory }) => {
16
+ const importLines = inStory?.linesStory?.importLines;
17
+
18
+ const lastLine = importLines[importLines.length - 1];
19
+
20
+ return lastLine?.lineNumber;
21
+ };
22
+
23
+ const findInsertIndex = ({ inStory }) => {
24
+ const importLines = findImportLinesIndex({ inStory });
25
+ const importLinesFromNpm = findImportLinesFromNpmIndex({ inStory });
26
+
27
+ return importLines ? importLines : importLinesFromNpm;
28
+ };
29
+
30
+ const startFunc = ({ inStory, fileContent, filePath,
31
+ inFolderNameToInsert, lineType = "importLines", inTemplate, inParts }) => {
32
+
33
+ const foundUseLinesStory = inStory.linesStory[lineType].find(element => {
34
+ return element.part1 === inFolderNameToInsert;
35
+ });
36
+
37
+ if (!foundUseLinesStory) {
38
+ const newLine = build(inTemplate, inParts);
39
+
40
+ const lines = fileContent.split(/\r?\n/);
41
+
42
+ // findInsertIndex({ inStory });
43
+
44
+ // const lastLine = inStory.lines[lineType][inStory.lines[lineType].length - 1];
45
+ // const insertAtIndex = lastLine.lineNumber;
46
+
47
+ const insertAtIndex = findInsertIndex({ inStory });
48
+
49
+ lines.splice(insertAtIndex, 0, newLine);
50
+
51
+ fs.writeFileSync(filePath, lines.join(fileContent.includes("\r\n") ? "\r\n" : "\n"));
52
+ };
53
+ };
54
+
55
+ export default startFunc;
@@ -0,0 +1,30 @@
1
+ import fs from 'fs';
2
+
3
+ const findImportLinesFromNpmIndex = ({ inStory }) => {
4
+ const importLinesFromNpm = inStory?.linesStory?.importLinesFromNpm;
5
+
6
+ const lastLine = importLinesFromNpm[importLinesFromNpm.length - 1];
7
+
8
+ return lastLine?.lineNumber;
9
+ };
10
+
11
+ const findImportLinesIndex = ({ inStory }) => {
12
+ const importLines = inStory?.linesStory?.importLines;
13
+
14
+ const lastLine = importLines[importLines.length - 1];
15
+
16
+ return lastLine?.lineNumber;
17
+ };
18
+
19
+ const findVariablesDeclareHereLinesIndex = ({ inStory }) => {
20
+ const variablesDeclareHereLines = inStory?.lines?.variablesDeclareHereLines;
21
+
22
+ const lastLine = variablesDeclareHereLines[variablesDeclareHereLines.length - 1];
23
+
24
+ return lastLine?.lineNumber;
25
+ };
26
+
27
+ export {
28
+ findImportLinesFromNpmIndex, findImportLinesIndex,
29
+ findVariablesDeclareHereLinesIndex
30
+ };
@@ -0,0 +1,29 @@
1
+ import fs from 'fs';
2
+
3
+ import defaultFunc from 'pattern-collector-anyjs-story';
4
+ import insertUseLine from "./insertUseLine.js";
5
+
6
+ const startFunc = ({ inFolderNameToInsert, inFileType, inJsPath }) => {
7
+ const folderNameToInsert = inFolderNameToInsert;
8
+ const localJsPath = inJsPath;
9
+
10
+ const fileContent = fs.readFileSync(localJsPath, 'utf8');
11
+
12
+ const story = defaultFunc({
13
+ fileContent,
14
+ fileType: inFileType
15
+ });
16
+
17
+ insertUseLine({
18
+ inStory: story,
19
+ fileContent,
20
+ filePath: localJsPath, inFolderNameToInsert: folderNameToInsert,
21
+ inTemplate1: story.regexForPullLinesStory.consumptionRegex.reverseTemplate,
22
+ inTemplate: story.reverseTemplates.consumptionRegex,
23
+ inParts: [folderNameToInsert, `${story.variablesConnection}${folderNameToInsert}`]
24
+ });
25
+ };
26
+
27
+ export default startFunc;
28
+
29
+ // startFunc({ folderNameToInsert, fileType });
@@ -0,0 +1,44 @@
1
+ import fs from 'fs';
2
+
3
+ import {
4
+ findImportLinesFromNpmIndex, findImportLinesIndex,
5
+ findVariablesDeclareHereLinesIndex
6
+ } from "../forInsertIndex.js";
7
+
8
+ const findInsertIndex = ({ inStory }) => {
9
+ const importLines = findImportLinesIndex({ inStory });
10
+ const importLinesFromNpm = findImportLinesFromNpmIndex({ inStory });
11
+ const variablesDeclareHereLines = findVariablesDeclareHereLinesIndex({ inStory });
12
+
13
+ // findVariablesDeclareHereLinesIndex
14
+ return importLines ? importLines : variablesDeclareHereLines;
15
+ };
16
+
17
+ function build(template, parts) {
18
+ return template.replace(/\{(\d+)\}/g, (_, i) => parts[i]);
19
+ };
20
+
21
+ const startFunc = ({ inStory, fileContent, filePath,
22
+ inFolderNameToInsert, lineType = "useLines", inTemplate, inParts }) => {
23
+
24
+ const foundUseLinesStory = inStory.linesStory[lineType].find(element => {
25
+ return element.part1 === inFolderNameToInsert;
26
+ });
27
+
28
+ if (!foundUseLinesStory) {
29
+ const newLine = build(inTemplate, inParts);
30
+
31
+ const lines = fileContent.split(/\r?\n/);
32
+
33
+ // const lastUseLine = inStory.lines[lineType][inStory.lines[lineType].length - 1];
34
+ // const insertAtIndex = lastUseLine.lineNumber;
35
+
36
+ const insertAtIndex = findInsertIndex({ inStory });
37
+
38
+ lines.splice(insertAtIndex, 0, newLine);
39
+
40
+ fs.writeFileSync(filePath, lines.join(fileContent.includes("\r\n") ? "\r\n" : "\n"));
41
+ };
42
+ };
43
+
44
+ export default startFunc;
@@ -0,0 +1,11 @@
1
+ import forImportLine from "./forImportLine/index.js";
2
+ import forUseLine from "./forUseLine/index.js";
3
+
4
+ const startFunc = ({ inFolderNameToInsert, inFileType, inJsPath }) => {
5
+ forImportLine({ inFolderNameToInsert, inFileType, inJsPath })
6
+ forUseLine({ inFolderNameToInsert, inFileType, inJsPath })
7
+ };
8
+
9
+ export default startFunc;
10
+
11
+ // startFunc({ folderNameToInsert, fileType });
@@ -0,0 +1,11 @@
1
+ import bothLines from './bothLines/index.js';
2
+
3
+ const startFunc = ({ inFolderNameToInsert, inFileType, jsFilePath }) => {
4
+
5
+ return bothLines({
6
+ inFolderNameToInsert, inFileType,
7
+ inJsPath: jsFilePath
8
+ });
9
+ };
10
+
11
+ export default startFunc;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "express-fix-any-js",
3
- "version": "1.11.3",
3
+ "version": "1.13.3",
4
4
  "description": "CLI to build for appjs, the endpoints",
5
5
  "keywords": [
6
6
  "cli",
@@ -11,7 +11,7 @@
11
11
  ],
12
12
  "dependencies": {
13
13
  "express-check-any-for-import": "^1.4.7",
14
- "pattern-collector-anyjs-story": "^1.18.1"
14
+ "pattern-collector-anyjs-story": "^1.19.6"
15
15
  },
16
16
  "type": "module",
17
17
  "exports": {
@@ -1,28 +0,0 @@
1
- const startFunc = ({
2
- content,
3
- insertInfo,
4
- toInsertLine,
5
- insertAfter
6
- }) => {
7
- const index = insertInfo.index === -1 ? content.length : insertInfo.index;
8
- const before = content.slice(0, index);
9
-
10
- const isFirstInsert =
11
- insertInfo.matchedPattern === insertAfter[insertAfter.length - 1];
12
-
13
- if (Array.isArray(toInsertLine)) {
14
- return before +
15
- (isFirstInsert ? "\n" : "") +
16
- toInsertLine.join("\n") +
17
- "\n" +
18
- content.slice(index);
19
- }
20
-
21
- return before +
22
- (isFirstInsert ? "\n" : "") +
23
- toInsertLine +
24
- "\n" +
25
- content.slice(index);
26
- };
27
-
28
- export default startFunc;
@@ -1,21 +0,0 @@
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;
@@ -1,30 +0,0 @@
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;
@@ -1,61 +0,0 @@
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,27 +0,0 @@
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;
@@ -1,41 +0,0 @@
1
- const startFunc = ({
2
- content,
3
- insertInfo,
4
- toInsertLine,
5
- insertAfter
6
- }) => {
7
-
8
- // let before;
9
-
10
- // if (insertInfo.index === -1) {
11
- // before = 0;
12
-
13
- // } else {
14
-
15
- // before = content.slice(0, insertInfo.index);
16
-
17
- // };
18
- // const before = content.slice(0, insertInfo.index);
19
-
20
- const index = insertInfo.index === -1 ? 0 : insertInfo.index;
21
- const before = content.slice(0, index);
22
-
23
- const isFirstInsert =
24
- insertInfo.matchedPattern === insertAfter[insertAfter.length - 1];
25
-
26
- if (Array.isArray(toInsertLine)) {
27
- return before +
28
- (isFirstInsert ? "\n" : "") +
29
- toInsertLine.join("\n") +
30
- "\n" +
31
- content.slice(index);
32
- }
33
-
34
- return before +
35
- (isFirstInsert ? "\n" : "") +
36
- toInsertLine +
37
- "\n" +
38
- content.slice(index);
39
- };
40
-
41
- export default startFunc;
@@ -1,14 +0,0 @@
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;
@@ -1,30 +0,0 @@
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;