express-fix-any-js 1.13.3 → 1.15.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.
@@ -16,7 +16,7 @@ const startFunc = ({ inFolderNameToInsert, inFileType, inJsPath }) => {
16
16
 
17
17
  insertImportLine({
18
18
  inStory: story,
19
- fileContent,
19
+ fileContent, extractRegex: story?.extractRegex,
20
20
  filePath: localJsPath, inFolderNameToInsert: folderNameToInsert,
21
21
  inTemplate1: story.regexForPullLinesStory.importRegex.reverseTemplate,
22
22
  inTemplate: story.reverseTemplates.importRegex,
@@ -20,14 +20,40 @@ const findImportLinesIndex = ({ inStory }) => {
20
20
  return lastLine?.lineNumber;
21
21
  };
22
22
 
23
- const findInsertIndex = ({ inStory }) => {
24
- const importLines = findImportLinesIndex({ inStory });
25
- const importLinesFromNpm = findImportLinesFromNpmIndex({ inStory });
23
+ const findInsertIndex = ({ onlyIndexesValues, extractRegex }) => {
24
+ let insertIndex;
25
+
26
+ mainLoop: for (const element of extractRegex?.toInsertIndex?.import) {
27
+ const splitValues = element.split(".");
28
+ const firstValue = splitValues[0];
29
+ const secondValue = splitValues[1];
30
+
31
+ if (splitValues.length > 1) {
32
+ if (firstValue in onlyIndexesValues) {
33
+ if (onlyIndexesValues[firstValue]) {
34
+ if (secondValue in onlyIndexesValues[firstValue]) {
35
+ insertIndex = onlyIndexesValues[firstValue][secondValue];
36
+ break mainLoop;
37
+ };
38
+ };
39
+ };
40
+ } else {
41
+ switch (element) {
42
+ case "first":
43
+ insertIndex = 0;
44
+ break mainLoop;
45
+ break;
46
+
47
+ default:
48
+ break;
49
+ }
50
+ };
51
+ };
26
52
 
27
- return importLines ? importLines : importLinesFromNpm;
53
+ return insertIndex;
28
54
  };
29
55
 
30
- const startFunc = ({ inStory, fileContent, filePath,
56
+ const startFunc = ({ inStory, fileContent, filePath, extractRegex,
31
57
  inFolderNameToInsert, lineType = "importLines", inTemplate, inParts }) => {
32
58
 
33
59
  const foundUseLinesStory = inStory.linesStory[lineType].find(element => {
@@ -44,7 +70,10 @@ const startFunc = ({ inStory, fileContent, filePath,
44
70
  // const lastLine = inStory.lines[lineType][inStory.lines[lineType].length - 1];
45
71
  // const insertAtIndex = lastLine.lineNumber;
46
72
 
47
- const insertAtIndex = findInsertIndex({ inStory });
73
+ const insertAtIndex = findInsertIndex({
74
+ onlyIndexesValues: inStory?.onlyIndexesValues,
75
+ extractRegex
76
+ });
48
77
 
49
78
  lines.splice(insertAtIndex, 0, newLine);
50
79
 
@@ -0,0 +1,16 @@
1
+ const startFunc = ({
2
+ inLines,
3
+ inNewLine,
4
+ inInsertAtIndex,
5
+ inGapBefore = false,
6
+ inGapAfter = false
7
+ }) => {
8
+ let line = inNewLine;
9
+
10
+ if (inGapBefore) line = "\n" + line;
11
+ if (inGapAfter) line = line + "\n";
12
+
13
+ inLines.splice(inInsertAtIndex, 0, line);
14
+ };
15
+
16
+ export default startFunc;
@@ -0,0 +1,75 @@
1
+ const startFunc1 = ({ onlyIndexesValues, extractRegex, presentKey }) => {
2
+ let insertStory = {};
3
+
4
+ mainLoop: for (const element of extractRegex?.toInsertIndex?.import) {
5
+ const splitValues = element.split(".");
6
+ const firstValue = splitValues[0];
7
+ const secondValue = splitValues[1];
8
+
9
+ if (splitValues.length > 1) {
10
+ if (firstValue in onlyIndexesValues) {
11
+ if (onlyIndexesValues[firstValue]) {
12
+ if (secondValue in onlyIndexesValues[firstValue]) {
13
+ insertStory.index = onlyIndexesValues[firstValue][secondValue];
14
+
15
+ if (presentKey in onlyIndexesValues) {
16
+ if (!onlyIndexesValues[presentKey]) {
17
+ insertStory.gapBefore = true;
18
+ };
19
+ };
20
+
21
+ break mainLoop;
22
+ };
23
+ };
24
+ };
25
+ } else {
26
+ switch (element) {
27
+ case "first":
28
+ insertStory.index = 0;
29
+
30
+ break mainLoop;
31
+ break;
32
+
33
+ default:
34
+ break;
35
+ }
36
+ };
37
+ };
38
+
39
+ return insertStory;
40
+ };
41
+
42
+ const startFunc = ({ onlyIndexesValues, extractRegex, presentKey }) => {
43
+ const insertStory = {};
44
+
45
+ // Try each preferred location until one exists.
46
+ for (const preference of extractRegex) {
47
+
48
+ const [group, property] = preference.split(".");
49
+
50
+ // Preference like: importLines.firstLineIndex
51
+ if (property) {
52
+ if (onlyIndexesValues[group]?.[property] !== undefined) {
53
+ insertStory.index = onlyIndexesValues[group][property];
54
+
55
+ if (presentKey in onlyIndexesValues && !onlyIndexesValues[presentKey]) {
56
+ insertStory.gapBefore = true;
57
+ }
58
+
59
+ break;
60
+ }
61
+
62
+ continue;
63
+ }
64
+
65
+ // Special preference like: first
66
+ if (preference === "firstLineIndex") {
67
+ insertStory.index = 0;
68
+ break;
69
+ };
70
+ };
71
+
72
+ return insertStory;
73
+ };
74
+
75
+ export default startFunc;
@@ -16,7 +16,7 @@ const startFunc = ({ inFolderNameToInsert, inFileType, inJsPath }) => {
16
16
 
17
17
  insertImportLine({
18
18
  inStory: story,
19
- fileContent,
19
+ fileContent, extractRegex: story?.extractRegex,
20
20
  filePath: localJsPath, inFolderNameToInsert: folderNameToInsert,
21
21
  inTemplate1: story.regexForPullLinesStory.importRegex.reverseTemplate,
22
22
  inTemplate: story.reverseTemplates.importRegex,
@@ -0,0 +1,54 @@
1
+ import fs from 'fs';
2
+ import findInsertIndex from "../findInsertIndex.js";
3
+ import addLines from "../addLines.js";
4
+
5
+ function build(template, parts) {
6
+ return template.replace(/\{(\d+)\}/g, (_, i) => parts[i]);
7
+ };
8
+
9
+ const addLines1 = ({
10
+ inLines,
11
+ inNewLine,
12
+ inInsertAtIndex,
13
+ inGapBefore = false,
14
+ inGapAfter = false
15
+ }) => {
16
+ let line = inNewLine;
17
+
18
+ if (inGapBefore) line = "\n" + line;
19
+ if (inGapAfter) line = line + "\n";
20
+
21
+ inLines.splice(inInsertAtIndex, 0, line);
22
+ };
23
+
24
+ const startFunc = ({ inStory, fileContent, filePath, extractRegex,
25
+ inFolderNameToInsert, lineType = "importLines", inTemplate, inParts }) => {
26
+
27
+ const foundUseLinesStory = inStory.linesStory[lineType].find(element => {
28
+ return element.part1 === inFolderNameToInsert;
29
+ });
30
+
31
+ if (!foundUseLinesStory) {
32
+ const newLine = build(inTemplate, inParts);
33
+
34
+ const lines = fileContent.split(/\r?\n/);
35
+
36
+ const insertStory = findInsertIndex({
37
+ onlyIndexesValues: inStory?.onlyIndexesValues,
38
+ extractRegex: extractRegex?.toInsertIndex?.import,
39
+ presentKey: lineType
40
+ });
41
+
42
+ addLines({
43
+ inLines: lines, inInsertAtIndex: insertStory?.index,
44
+ inNewLine: newLine, inGapBefore: insertStory?.gapBefore,
45
+ inGapAfter: insertStory?.gapAfter
46
+ });
47
+
48
+ // lines.splice(insertAtIndex, 0, newLine);
49
+
50
+ fs.writeFileSync(filePath, lines.join(fileContent.includes("\r\n") ? "\r\n" : "\n"));
51
+ };
52
+ };
53
+
54
+ export default startFunc;
@@ -16,4 +16,15 @@ const findImportLinesIndex = ({ inStory }) => {
16
16
  return lastLine?.lineNumber;
17
17
  };
18
18
 
19
- export { findImportLinesFromNpmIndex, findImportLinesIndex };
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
+ };
@@ -16,7 +16,7 @@ const startFunc = ({ inFolderNameToInsert, inFileType, inJsPath }) => {
16
16
 
17
17
  insertUseLine({
18
18
  inStory: story,
19
- fileContent,
19
+ fileContent, extractRegex: story?.extractRegex,
20
20
  filePath: localJsPath, inFolderNameToInsert: folderNameToInsert,
21
21
  inTemplate1: story.regexForPullLinesStory.consumptionRegex.reverseTemplate,
22
22
  inTemplate: story.reverseTemplates.consumptionRegex,
@@ -0,0 +1,58 @@
1
+ import fs from 'fs';
2
+ import findInsertIndex from "../findInsertIndex.js";
3
+ import addLines from "../addLines.js";
4
+
5
+ import {
6
+ findImportLinesFromNpmIndex, findImportLinesIndex,
7
+ findVariablesDeclareHereLinesIndex
8
+ } from "../forInsertIndex.js";
9
+
10
+ const findInsertIndex1 = ({ inStory }) => {
11
+ const importLines = findImportLinesIndex({ inStory });
12
+ const importLinesFromNpm = findImportLinesFromNpmIndex({ inStory });
13
+ const variablesDeclareHereLines = findVariablesDeclareHereLinesIndex({ inStory });
14
+
15
+ // findVariablesDeclareHereLinesIndex
16
+ return importLines ? importLines : variablesDeclareHereLines;
17
+ };
18
+
19
+ function build(template, parts) {
20
+ return template.replace(/\{(\d+)\}/g, (_, i) => parts[i]);
21
+ };
22
+
23
+ const startFunc = ({ inStory, fileContent, filePath, extractRegex,
24
+ inFolderNameToInsert, lineType = "useLines", inTemplate, inParts }) => {
25
+
26
+ const foundUseLinesStory = inStory.linesStory[lineType].find(element => {
27
+ return element.part1 === inFolderNameToInsert;
28
+ });
29
+
30
+ if (!foundUseLinesStory) {
31
+ const newLine = build(inTemplate, inParts);
32
+
33
+ const lines = fileContent.split(/\r?\n/);
34
+
35
+ // const lastUseLine = inStory.lines[lineType][inStory.lines[lineType].length - 1];
36
+ // const insertAtIndex = lastUseLine.lineNumber;
37
+
38
+ const insertStory = findInsertIndex({
39
+ onlyIndexesValues: inStory?.onlyIndexesValues,
40
+ extractRegex: extractRegex?.toInsertIndex?.consumption,
41
+ presentKey: lineType
42
+ });
43
+
44
+ addLines({
45
+ inLines: lines, inInsertAtIndex: insertStory?.index,
46
+ inNewLine: newLine, inGapBefore: insertStory?.gapBefore,
47
+ inGapAfter: insertStory?.gapAfter
48
+ });
49
+
50
+ // const insertAtIndex = findInsertIndex({ inStory });
51
+
52
+ // lines.splice(insertAtIndex, 0, newLine);
53
+
54
+ fs.writeFileSync(filePath, lines.join(fileContent.includes("\r\n") ? "\r\n" : "\n"));
55
+ };
56
+ };
57
+
58
+ export default startFunc;
@@ -0,0 +1,18 @@
1
+ import forImportLine from "./forImportLine/index.js";
2
+ import forUseLine from "./forUseLine/index.js";
3
+
4
+ const startFunc = ({ inFolderNameToInsert, inFileType, jsFilePath }) => {
5
+ const fromImportLine = forImportLine({
6
+ inFolderNameToInsert, inFileType,
7
+ inJsPath: jsFilePath
8
+ });
9
+
10
+ const fromUseLine = forUseLine({
11
+ inFolderNameToInsert, inFileType,
12
+ inJsPath: jsFilePath
13
+ });
14
+
15
+ return { fromImportLine, fromUseLine }
16
+ };
17
+
18
+ export default startFunc;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "express-fix-any-js",
3
- "version": "1.13.3",
3
+ "version": "1.15.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.19.6"
14
+ "pattern-collector-anyjs-story": "^1.19.11"
15
15
  },
16
16
  "type": "module",
17
17
  "exports": {
@@ -1,39 +0,0 @@
1
- import fs from 'fs';
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
-
12
- function build(template, parts) {
13
- return template.replace(/\{(\d+)\}/g, (_, i) => parts[i]);
14
- };
15
-
16
- const startFunc = ({ inStory, fileContent, filePath,
17
- inFolderNameToInsert, lineType = "useLines", inTemplate, inParts }) => {
18
-
19
- const foundUseLinesStory = inStory.linesStory[lineType].find(element => {
20
- return element.part1 === inFolderNameToInsert;
21
- });
22
-
23
- if (!foundUseLinesStory) {
24
- const newLine = build(inTemplate, inParts);
25
-
26
- const lines = fileContent.split(/\r?\n/);
27
-
28
- // const lastUseLine = inStory.lines[lineType][inStory.lines[lineType].length - 1];
29
- // const insertAtIndex = lastUseLine.lineNumber;
30
-
31
- const insertAtIndex = findInsertIndex({ inStory });
32
-
33
- lines.splice(insertAtIndex, 0, newLine);
34
-
35
- fs.writeFileSync(filePath, lines.join(fileContent.includes("\r\n") ? "\r\n" : "\n"));
36
- };
37
- };
38
-
39
- export default startFunc;
package/bin/v12/start.js DELETED
@@ -1,8 +0,0 @@
1
- import updateJs from "./UpdateJs/index.js";
2
-
3
- const run = (args) => {
4
-
5
- return updateJs(args);
6
- };
7
-
8
- export default run;
@@ -1,55 +0,0 @@
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;
@@ -1,11 +0,0 @@
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,11 +0,0 @@
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/bin/v13/start.js DELETED
@@ -1,8 +0,0 @@
1
- import updateJs from "./UpdateJs/index.js";
2
-
3
- const run = (args) => {
4
-
5
- return updateJs(args);
6
- };
7
-
8
- export default run;
File without changes
File without changes