express-fix-any-js 1.11.4 → 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 (34) 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/{v10 → v12}/start.js +0 -0
  34. /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.4",
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;
@@ -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,8 +0,0 @@
1
- import fs from "fs";
2
-
3
- const readFile = (inAppJsPath) => {
4
- const localPath = inAppJsPath;
5
- return fs.readFileSync(localPath, "utf-8");
6
- };
7
-
8
- export default readFile;
@@ -1,10 +0,0 @@
1
- import fs from "fs";
2
-
3
- const writeFile = (inAppJsPath, inContent) => {
4
- const localPath = inAppJsPath;
5
- const localContent = inContent;
6
-
7
- fs.writeFileSync(localPath, localContent);
8
- };
9
-
10
- export default writeFile;
@@ -1,33 +0,0 @@
1
- import validateCheckLines from "./validateCheckLines.js";
2
- import alterFileForImport from "./common/AlterFileForImport/index.js";
3
- import alterFileForConsume from "./common/AlterFileForConsume/index.js";
4
-
5
- const updateAppJs = ({ inJsFilePath, inCheckLines,
6
- showLog = false }) => {
7
-
8
- const localCheckLines = inCheckLines;
9
-
10
- validateCheckLines(localCheckLines);
11
-
12
- const importResult = alterFileForImport({
13
- jsFilePath: inJsFilePath,
14
- toInsertLine: localCheckLines.importLines.toInsertLine,
15
- duplicationCheck: localCheckLines.importLines.duplicationCheck,
16
- insertAfter: localCheckLines.importLines.insertAfter,
17
- showLog
18
- });
19
-
20
- // const useResult = alterFileForConsume({
21
- // jsFilePath: inJsFilePath,
22
- // toInsertLine: localCheckLines.useLines.toInsertLine,
23
- // duplicationCheck: localCheckLines.useLines.duplicationCheck,
24
- // insertAfter: localCheckLines.useLines.insertAfter,
25
- // showLog
26
- // });
27
-
28
- // return { importResult, useResult };
29
-
30
- return { importResult };
31
- };
32
-
33
- export default updateAppJs;
@@ -1,31 +0,0 @@
1
- const startFunc = (obj) => {
2
- if (typeof obj !== "object" || obj === null || Array.isArray(obj)) {
3
- throw new TypeError("inCheckLines must be a valid object.");
4
- }
5
- for (const key of ["importLines", "useLines"]) {
6
- if (!(key in obj)) {
7
- throw new Error(`inCheckLines must contain "${key}".`);
8
- }
9
- const section = obj[key];
10
- if (typeof section !== "object" || section === null || Array.isArray(section)) {
11
- throw new TypeError(`inCheckLines.${key} must be an object.`);
12
- }
13
- if (key === "importLines") {
14
- if (typeof section.toInsertLine !== "string" && !Array.isArray(section.toInsertLine)) {
15
- throw new TypeError(`inCheckLines.importLines.toInsertLine must be a string or an array.`);
16
- }
17
- } else {
18
- if (typeof section.toInsertLine !== "string") {
19
- throw new TypeError(`inCheckLines.${key}.toInsertLine must be a string.`);
20
- }
21
- }
22
- if (typeof section.duplicationCheck !== "string") {
23
- throw new TypeError(`inCheckLines.${key}.duplicationCheck must be a string.`);
24
- }
25
- if (!Array.isArray(section.insertAfter)) {
26
- throw new TypeError(`inCheckLines.${key}.insertAfter must be an array.`);
27
- }
28
- }
29
- };
30
-
31
- export default startFunc;
@@ -1,13 +0,0 @@
1
- export default function parseInput({ jsFilePath,
2
- inCheckLines = {}, showLog }) {
3
-
4
- const [...args] = process.argv.slice(2);
5
-
6
- return {
7
- showLog: args[1] === undefined
8
- ? showLog
9
- : args[1] === "true",
10
- inJsFilePath: jsFilePath || process.cwd(),
11
- inCheckLines
12
- };
13
- };
@@ -1,50 +0,0 @@
1
- /*
2
- KSchema CLI – Entry Flow
3
-
4
- 1. Read user input from terminal (parseInput)
5
- 2. If no command → show usage (first-time user safety)
6
- 3. If help flags → show usage (quick guidance)
7
- 4. Resolve command dynamically (no hardcoding logic)
8
- 5. If command not found → inform + guide back to usage
9
- 6. Execute command with parsed input
10
-
11
- Goal:
12
- - Zero confusion for user
13
- - Single source of truth (showUsage)
14
- - Easy to extend (just add commands, no core changes)
15
- */
16
-
17
- export default function showUsage(version) {
18
- const g = "\x1b[32m";
19
- const y = "\x1b[33m";
20
- const c = "\x1b[36m";
21
- const gray = "\x1b[90m";
22
- const r = "\x1b[0m";
23
-
24
- console.log(`
25
- ${c}🚀 KSchema Api Generator v${version}${r}
26
-
27
- ${y}Usage:${r}
28
- ${g}npx @keshavsoft/kschema-api-gen${r} <command> [options]
29
-
30
- ${y}Commands:${r}
31
- ${g}StartEndPoint${r} Initialize a new folder and files
32
- ${g}AddSubRoute${r} Initialize a new folder and files
33
- ${g}AddTableName${r} Initialize a new folder and files for TableName
34
- ${g}ShowAll${r} Initialize a new folder and files for action
35
-
36
- ${g}CreateApi${r} Creates new end point and hooks to app.js
37
- ${g}InsertApi${r} Creates new InsertApi end point and hooks to app.js
38
-
39
- ${y}Examples:${r}
40
- ${gray}npx @keshavsoft/kschema-api-gen StartEndPoint${r}
41
- ${gray}npx @keshavsoft/kschema-api-gen AddSubRoute${r}
42
- ${gray}npx @keshavsoft/kschema-api-gen AddTableName${r}
43
- ${gray}npx @keshavsoft/kschema-api-gen ShowAll${r}
44
- ${gray}npx @keshavsoft/kschema-api-gen CreateApi Api/V1/journals/ShowAll${r}
45
- ${gray}npx @keshavsoft/kschema-api-gen InsertApi Api/V1/journals/Insert${r}
46
-
47
- ${y}Tip:${r}
48
- ${gray}npm i -g @keshavsoft/kschema-api-gen${r}
49
- `);
50
- }
@@ -1,27 +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 startFunc = ({ inStory, fileContent, filePath,
8
- inFolderNameToInsert, lineType = "importLines", inTemplate, inParts }) => {
9
-
10
- const foundUseLinesStory = inStory.linesStory[lineType].find(element => {
11
- return element.part1 === inFolderNameToInsert;
12
- });
13
-
14
- if (!foundUseLinesStory) {
15
- const newLine = build(inTemplate, inParts);
16
-
17
- const lines = fileContent.split(/\r?\n/);
18
-
19
- const lastLine = inStory.lines[lineType][inStory.lines[lineType].length - 1];
20
- const insertAtIndex = lastLine.lineNumber;
21
- lines.splice(insertAtIndex, 0, newLine);
22
-
23
- fs.writeFileSync(filePath, lines.join(fileContent.includes("\r\n") ? "\r\n" : "\n"));
24
- };
25
- };
26
-
27
- export default startFunc;
@@ -1,57 +0,0 @@
1
- import fs from 'fs';
2
-
3
- import defaultFunc from 'pattern-collector-anyjs-story';
4
- import insertUseLine from "./insertUseLine.js";
5
- import insertImportLine from "./insertImportLine.js";
6
-
7
- const step1 = ({ inFolderNameToInsert, inFileType, inJsPath }) => {
8
- const folderNameToInsert = inFolderNameToInsert;
9
- const localJsPath = inJsPath;
10
-
11
- const fileContent = fs.readFileSync(localJsPath, 'utf8');
12
-
13
- const story = defaultFunc({
14
- fileContent,
15
- fileType: inFileType
16
- });
17
-
18
- insertImportLine({
19
- inStory: story,
20
- fileContent,
21
- filePath: localJsPath, inFolderNameToInsert: folderNameToInsert,
22
- inTemplate1: story.regexForPullLinesStory.importRegex.reverseTemplate,
23
- inTemplate: story.reverseTemplates.importRegex,
24
- inParts: [`${story.variablesConnection}${folderNameToInsert}`, folderNameToInsert]
25
- });
26
-
27
- };
28
-
29
- const step2 = ({ inFolderNameToInsert, inFileType, inJsPath }) => {
30
- const folderNameToInsert = inFolderNameToInsert;
31
- const localJsPath = inJsPath;
32
-
33
- const fileContent = fs.readFileSync(localJsPath, 'utf8');
34
-
35
- const story = defaultFunc({
36
- fileContent,
37
- fileType: inFileType
38
- });
39
-
40
- insertUseLine({
41
- inStory: story,
42
- fileContent,
43
- filePath: localJsPath, inFolderNameToInsert: folderNameToInsert,
44
- inTemplate1: story.regexForPullLinesStory.consumptionRegex.reverseTemplate,
45
- inTemplate: story.reverseTemplates.consumptionRegex,
46
- inParts: [folderNameToInsert, `${story.variablesConnection}${folderNameToInsert}`]
47
- });
48
- };
49
-
50
- const startFunc = ({ inFolderNameToInsert, inFileType, inJsPath }) => {
51
- step1({ inFolderNameToInsert, inFileType, inJsPath })
52
- step2({ inFolderNameToInsert, inFileType, inJsPath })
53
- };
54
-
55
- export default startFunc;
56
-
57
- // startFunc({ folderNameToInsert, fileType });
File without changes
File without changes