express-fix-any-js 1.16.3 → 1.17.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.
@@ -42,6 +42,10 @@ const startFunc1 = ({ onlyIndexesValues, extractRegex, presentKey }) => {
42
42
  const startFunc = ({ onlyIndexesValues, extractRegex, presentKey }) => {
43
43
  const insertStory = {};
44
44
 
45
+ if (!extractRegex) {
46
+ return insertStory;
47
+ };
48
+
45
49
  // Try each preferred location until one exists.
46
50
  for (const preference of extractRegex) {
47
51
 
@@ -22,7 +22,8 @@ const startFunc = ({ inFolderNameToInsert, inFileType, inJsPath }) => {
22
22
  filePath: localJsPath, inFolderNameToInsert: folderNameToInsert,
23
23
  inTemplate1: story.regexForPullLinesStory.importRegex.reverseTemplate,
24
24
  inTemplate: story.reverseTemplates.importRegex,
25
- inParts: [`${story.variablesConnection}${folderNameToInsert}`, folderNameToInsert]
25
+ inParts: [`${story.variablesConnection}${folderNameToInsert}`, folderNameToInsert],
26
+ fileType: inFileType
26
27
  });
27
28
 
28
29
  } catch (error) {
@@ -6,23 +6,9 @@ function build(template, parts) {
6
6
  return template.replace(/\{(\d+)\}/g, (_, i) => parts[i]);
7
7
  };
8
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
9
  const startFunc = ({ inStory, fileContent, filePath, extractRegex,
25
- inFolderNameToInsert, lineType = "importLines", inTemplate, inParts }) => {
10
+ inFolderNameToInsert, lineType = "importLines", inTemplate,
11
+ inParts, fileType }) => {
26
12
 
27
13
  const foundUseLinesStory = inStory.linesStory[lineType].find(element => {
28
14
  return element.part1 === inFolderNameToInsert;
@@ -35,7 +21,7 @@ const startFunc = ({ inStory, fileContent, filePath, extractRegex,
35
21
 
36
22
  const insertStory = findInsertIndex({
37
23
  onlyIndexesValues: inStory?.onlyIndexesValues,
38
- extractRegex: extractRegex?.toInsertIndex?.import,
24
+ extractRegex: extractRegex?.toInsertIndex?.[fileType]?.import,
39
25
  presentKey: lineType
40
26
  });
41
27
 
@@ -20,7 +20,8 @@ const startFunc = ({ inFolderNameToInsert, inFileType, inJsPath }) => {
20
20
  filePath: localJsPath, inFolderNameToInsert: folderNameToInsert,
21
21
  inTemplate1: story.regexForPullLinesStory.consumptionRegex.reverseTemplate,
22
22
  inTemplate: story.reverseTemplates.consumptionRegex,
23
- inParts: [folderNameToInsert, `${story.variablesConnection}${folderNameToInsert}`]
23
+ inParts: [folderNameToInsert, `${story.variablesConnection}${folderNameToInsert}`],
24
+ fileType: inFileType
24
25
  });
25
26
  };
26
27
 
@@ -21,7 +21,8 @@ function build(template, parts) {
21
21
  };
22
22
 
23
23
  const startFunc = ({ inStory, fileContent, filePath, extractRegex,
24
- inFolderNameToInsert, lineType = "useLines", inTemplate, inParts }) => {
24
+ inFolderNameToInsert, lineType = "useLines", inTemplate, inParts,
25
+ fileType }) => {
25
26
 
26
27
  const foundUseLinesStory = inStory.linesStory[lineType].find(element => {
27
28
  return element.part1 === inFolderNameToInsert;
@@ -32,12 +33,9 @@ const startFunc = ({ inStory, fileContent, filePath, extractRegex,
32
33
 
33
34
  const lines = fileContent.split(/\r?\n/);
34
35
 
35
- // const lastUseLine = inStory.lines[lineType][inStory.lines[lineType].length - 1];
36
- // const insertAtIndex = lastUseLine.lineNumber;
37
-
38
36
  const insertStory = findInsertIndex({
39
37
  onlyIndexesValues: inStory?.onlyIndexesValues,
40
- extractRegex: extractRegex?.toInsertIndex?.consumption,
38
+ extractRegex: extractRegex?.toInsertIndex?.[fileType]?.consumption,
41
39
  presentKey: lineType
42
40
  });
43
41
 
@@ -47,10 +45,6 @@ const startFunc = ({ inStory, fileContent, filePath, extractRegex,
47
45
  inGapAfter: insertStory?.gapAfter
48
46
  });
49
47
 
50
- // const insertAtIndex = findInsertIndex({ inStory });
51
-
52
- // lines.splice(insertAtIndex, 0, newLine);
53
-
54
48
  fs.writeFileSync(filePath, lines.join(fileContent.includes("\r\n") ? "\r\n" : "\n"));
55
49
  };
56
50
  };
@@ -0,0 +1,44 @@
1
+ import fs from "fs";
2
+
3
+ import path from "path";
4
+
5
+ import forImportLine from "./forImportLine/index.js";
6
+ import forUseLine from "./forUseLine/index.js";
7
+
8
+ const alterEndPointsJs = ({ filePath, inTableName }) => {
9
+ try {
10
+ let content = fs.readFileSync(filePath, 'utf8');
11
+
12
+ content = content.replaceAll("<TABLE_NAME>", inTableName);
13
+
14
+ fs.writeFileSync(filePath, content, "utf8");
15
+
16
+ // writeFile(filePath, content);
17
+ } catch (e) {
18
+ handleError(e);
19
+ };
20
+ };
21
+
22
+ const startFunc = ({ inTableName, inFileType, jsFilePath,
23
+ inTargetPath
24
+ }) => {
25
+ let fromInternal;
26
+
27
+ switch (inFileType) {
28
+ case "fromEndPointsJs":
29
+
30
+ fromInternal = alterEndPointsJs({
31
+ filePath: path.join(inTargetPath, "end-points.js"),
32
+ inTableName
33
+ });
34
+
35
+ break;
36
+
37
+ default:
38
+ break;
39
+ };
40
+
41
+ return fromInternal;
42
+ };
43
+
44
+ export default startFunc;
@@ -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,79 @@
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
+ if (!extractRegex) {
46
+ return insertStory;
47
+ };
48
+
49
+ // Try each preferred location until one exists.
50
+ for (const preference of extractRegex) {
51
+
52
+ const [group, property] = preference.split(".");
53
+
54
+ // Preference like: importLines.firstLineIndex
55
+ if (property) {
56
+ if (onlyIndexesValues[group]?.[property] !== undefined) {
57
+ insertStory.index = onlyIndexesValues[group][property];
58
+
59
+ if (presentKey in onlyIndexesValues && !onlyIndexesValues[presentKey]) {
60
+ insertStory.gapBefore = true;
61
+ }
62
+
63
+ break;
64
+ }
65
+
66
+ continue;
67
+ }
68
+
69
+ // Special preference like: first
70
+ if (preference === "firstLineIndex") {
71
+ insertStory.index = 0;
72
+ break;
73
+ };
74
+ };
75
+
76
+ return insertStory;
77
+ };
78
+
79
+ export default startFunc;
@@ -0,0 +1,37 @@
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
+ try {
8
+
9
+ const folderNameToInsert = inFolderNameToInsert;
10
+ const localJsPath = inJsPath;
11
+
12
+ const fileContent = fs.readFileSync(localJsPath, 'utf8');
13
+
14
+ const story = defaultFunc({
15
+ fileContent,
16
+ fileType: inFileType
17
+ });
18
+
19
+ insertImportLine({
20
+ inStory: story,
21
+ fileContent, extractRegex: story?.extractRegex,
22
+ filePath: localJsPath, inFolderNameToInsert: folderNameToInsert,
23
+ inTemplate1: story.regexForPullLinesStory.importRegex.reverseTemplate,
24
+ inTemplate: story.reverseTemplates.importRegex,
25
+ inParts: [`${story.variablesConnection}${folderNameToInsert}`, folderNameToInsert],
26
+ fileType: inFileType
27
+ });
28
+
29
+ } catch (error) {
30
+ console.log("error : ", error);
31
+
32
+ };
33
+ };
34
+
35
+ export default startFunc;
36
+
37
+ // startFunc({ folderNameToInsert, fileType });
@@ -0,0 +1,40 @@
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 startFunc = ({ inStory, fileContent, filePath, extractRegex,
10
+ inFolderNameToInsert, lineType = "importLines", inTemplate,
11
+ inParts, fileType }) => {
12
+
13
+ const foundUseLinesStory = inStory.linesStory[lineType].find(element => {
14
+ return element.part1 === inFolderNameToInsert;
15
+ });
16
+
17
+ if (!foundUseLinesStory) {
18
+ const newLine = build(inTemplate, inParts);
19
+
20
+ const lines = fileContent.split(/\r?\n/);
21
+
22
+ const insertStory = findInsertIndex({
23
+ onlyIndexesValues: inStory?.onlyIndexesValues,
24
+ extractRegex: extractRegex?.toInsertIndex?.[fileType]?.import,
25
+ presentKey: lineType
26
+ });
27
+
28
+ addLines({
29
+ inLines: lines, inInsertAtIndex: insertStory?.index,
30
+ inNewLine: newLine, inGapBefore: insertStory?.gapBefore,
31
+ inGapAfter: insertStory?.gapAfter
32
+ });
33
+
34
+ // lines.splice(insertAtIndex, 0, newLine);
35
+
36
+ fs.writeFileSync(filePath, lines.join(fileContent.includes("\r\n") ? "\r\n" : "\n"));
37
+ };
38
+ };
39
+
40
+ 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,30 @@
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, extractRegex: story?.extractRegex,
20
+ filePath: localJsPath, inFolderNameToInsert: folderNameToInsert,
21
+ inTemplate1: story.regexForPullLinesStory.consumptionRegex.reverseTemplate,
22
+ inTemplate: story.reverseTemplates.consumptionRegex,
23
+ inParts: [folderNameToInsert, `${story.variablesConnection}${folderNameToInsert}`],
24
+ fileType: inFileType
25
+ });
26
+ };
27
+
28
+ export default startFunc;
29
+
30
+ // startFunc({ folderNameToInsert, fileType });
@@ -0,0 +1,52 @@
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
+ fileType }) => {
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?.[fileType]?.consumption,
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
+ fs.writeFileSync(filePath, lines.join(fileContent.includes("\r\n") ? "\r\n" : "\n"));
49
+ };
50
+ };
51
+
52
+ export default startFunc;
@@ -0,0 +1,34 @@
1
+ import hookFolder from "./hookFolder/start.js";
2
+ import addTableName from "./addTableName/start.js";
3
+
4
+ const startFunc = ({ inFolderNameToInsert, inFileType, jsFilePath,
5
+ inAlterType, inTargetPath, inTableName
6
+ }) => {
7
+ let fromInternal;
8
+
9
+ switch (inAlterType) {
10
+ case "hookFolder":
11
+
12
+ fromInternal = hookFolder({
13
+ inFolderNameToInsert, inFileType, jsFilePath,
14
+ inTargetPath
15
+ });
16
+
17
+ break;
18
+
19
+ case "addTableName":
20
+
21
+ fromInternal = addTableName({
22
+ inTableName, inFileType, jsFilePath,
23
+ inTargetPath
24
+ });
25
+
26
+ break;
27
+ default:
28
+ break;
29
+ };
30
+
31
+ return fromInternal;
32
+ };
33
+
34
+ export default startFunc;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "express-fix-any-js",
3
- "version": "1.16.3",
3
+ "version": "1.17.2",
4
4
  "description": "CLI to build for appjs, the endpoints",
5
5
  "keywords": [
6
6
  "cli",
File without changes
File without changes
File without changes