express-fix-any-js 1.15.3 → 1.16.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.
@@ -4,25 +4,31 @@ import defaultFunc from 'pattern-collector-anyjs-story';
4
4
  import insertImportLine from "./insertImportLine.js";
5
5
 
6
6
  const startFunc = ({ inFolderNameToInsert, inFileType, inJsPath }) => {
7
- const folderNameToInsert = inFolderNameToInsert;
8
- const localJsPath = inJsPath;
7
+ try {
9
8
 
10
- const fileContent = fs.readFileSync(localJsPath, 'utf8');
9
+ const folderNameToInsert = inFolderNameToInsert;
10
+ const localJsPath = inJsPath;
11
11
 
12
- const story = defaultFunc({
13
- fileContent,
14
- fileType: inFileType
15
- });
12
+ const fileContent = fs.readFileSync(localJsPath, 'utf8');
16
13
 
17
- insertImportLine({
18
- inStory: story,
19
- fileContent, extractRegex: story?.extractRegex,
20
- filePath: localJsPath, inFolderNameToInsert: folderNameToInsert,
21
- inTemplate1: story.regexForPullLinesStory.importRegex.reverseTemplate,
22
- inTemplate: story.reverseTemplates.importRegex,
23
- inParts: [`${story.variablesConnection}${folderNameToInsert}`, folderNameToInsert]
24
- });
14
+ const story = defaultFunc({
15
+ fileContent,
16
+ fileType: inFileType
17
+ });
25
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
+ });
27
+
28
+ } catch (error) {
29
+ console.log("error : ", error);
30
+
31
+ };
26
32
  };
27
33
 
28
34
  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;
@@ -16,11 +16,12 @@ 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,
23
- inParts: [folderNameToInsert, `${story.variablesConnection}${folderNameToInsert}`]
23
+ inParts: [folderNameToInsert, `${story.variablesConnection}${folderNameToInsert}`],
24
+ fileType: inFileType
24
25
  });
25
26
  };
26
27
 
@@ -1,11 +1,13 @@
1
1
  import fs from 'fs';
2
+ import findInsertIndex from "../findInsertIndex.js";
3
+ import addLines from "../addLines.js";
2
4
 
3
5
  import {
4
6
  findImportLinesFromNpmIndex, findImportLinesIndex,
5
7
  findVariablesDeclareHereLinesIndex
6
8
  } from "../forInsertIndex.js";
7
9
 
8
- const findInsertIndex = ({ inStory }) => {
10
+ const findInsertIndex1 = ({ inStory }) => {
9
11
  const importLines = findImportLinesIndex({ inStory });
10
12
  const importLinesFromNpm = findImportLinesFromNpmIndex({ inStory });
11
13
  const variablesDeclareHereLines = findVariablesDeclareHereLinesIndex({ inStory });
@@ -18,8 +20,9 @@ function build(template, parts) {
18
20
  return template.replace(/\{(\d+)\}/g, (_, i) => parts[i]);
19
21
  };
20
22
 
21
- const startFunc = ({ inStory, fileContent, filePath,
22
- inFolderNameToInsert, lineType = "useLines", inTemplate, inParts }) => {
23
+ const startFunc = ({ inStory, fileContent, filePath, extractRegex,
24
+ inFolderNameToInsert, lineType = "useLines", inTemplate, inParts,
25
+ fileType }) => {
23
26
 
24
27
  const foundUseLinesStory = inStory.linesStory[lineType].find(element => {
25
28
  return element.part1 === inFolderNameToInsert;
@@ -30,12 +33,17 @@ const startFunc = ({ inStory, fileContent, filePath,
30
33
 
31
34
  const lines = fileContent.split(/\r?\n/);
32
35
 
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);
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
+ });
39
47
 
40
48
  fs.writeFileSync(filePath, lines.join(fileContent.includes("\r\n") ? "\r\n" : "\n"));
41
49
  };
@@ -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.15.3",
3
+ "version": "1.16.3",
4
4
  "description": "CLI to build for appjs, the endpoints",
5
5
  "keywords": [
6
6
  "cli",
@@ -10,8 +10,7 @@
10
10
  "project-generator"
11
11
  ],
12
12
  "dependencies": {
13
- "express-check-any-for-import": "^1.4.7",
14
- "pattern-collector-anyjs-story": "^1.19.11"
13
+ "pattern-collector-anyjs-story": "^1.20.4"
15
14
  },
16
15
  "type": "module",
17
16
  "exports": {
@@ -1,30 +0,0 @@
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, extractRegex: story?.extractRegex,
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 });
@@ -1,84 +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 = ({ 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
- };
52
-
53
- return insertIndex;
54
- };
55
-
56
- const startFunc = ({ inStory, fileContent, filePath, extractRegex,
57
- inFolderNameToInsert, lineType = "importLines", inTemplate, inParts }) => {
58
-
59
- const foundUseLinesStory = inStory.linesStory[lineType].find(element => {
60
- return element.part1 === inFolderNameToInsert;
61
- });
62
-
63
- if (!foundUseLinesStory) {
64
- const newLine = build(inTemplate, inParts);
65
-
66
- const lines = fileContent.split(/\r?\n/);
67
-
68
- // findInsertIndex({ inStory });
69
-
70
- // const lastLine = inStory.lines[lineType][inStory.lines[lineType].length - 1];
71
- // const insertAtIndex = lastLine.lineNumber;
72
-
73
- const insertAtIndex = findInsertIndex({
74
- onlyIndexesValues: inStory?.onlyIndexesValues,
75
- extractRegex
76
- });
77
-
78
- lines.splice(insertAtIndex, 0, newLine);
79
-
80
- fs.writeFileSync(filePath, lines.join(fileContent.includes("\r\n") ? "\r\n" : "\n"));
81
- };
82
- };
83
-
84
- 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 });
package/bin/v14/start.js DELETED
@@ -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;
File without changes