express-fix-any-js 1.26.2 → 1.28.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.
Files changed (39) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +88 -88
  3. package/bin/cli.js +11 -11
  4. package/bin/core/getLatestVersion.js +12 -12
  5. package/bin/core/loadRunner.js +8 -8
  6. package/bin/{v25 → v27}/alterFile/forImportLine/index.js +40 -40
  7. package/bin/{v26/hookFolder → v27/alterFile}/forInsertIndex.js +29 -29
  8. package/bin/{v26 → v27}/alterFile/insertLine/addLines.js +15 -15
  9. package/bin/{v25/hookFolder → v27/alterFile}/insertLine/findInsertIndex.js +37 -37
  10. package/bin/{v25/hookFolder → v27/alterFile}/insertLine/index.js +49 -49
  11. package/bin/{v25 → v27}/alterFile/insertLine/writeToFile.js +7 -7
  12. package/bin/{v26 → v27}/alterFile/start.js +44 -44
  13. package/bin/{v25 → v27}/fileNames.json +34 -34
  14. package/bin/{v26 → v27}/hookFolder/forImportLine/index.js +40 -40
  15. package/bin/{v25/alterFile → v27/hookFolder}/forInsertIndex.js +29 -29
  16. package/bin/{v25 → v27}/hookFolder/insertLine/addLines.js +15 -15
  17. package/bin/{v26 → v27}/hookFolder/insertLine/findInsertIndex.js +37 -37
  18. package/bin/{v26/alterFile → v27/hookFolder}/insertLine/index.js +49 -49
  19. package/bin/{v26/alterFile → v27/hookFolder}/insertLine/writeToFile.js +7 -7
  20. package/bin/{v26 → v27}/hookFolder/start.js +27 -27
  21. package/bin/{v25 → v27}/start.js +24 -24
  22. package/bin/{v26 → v28}/alterFile/forImportLine/index.js +40 -40
  23. package/bin/{v25/hookFolder → v28/alterFile}/forInsertIndex.js +29 -29
  24. package/bin/{v25 → v28}/alterFile/insertLine/addLines.js +15 -15
  25. package/bin/{v26 → v28}/alterFile/insertLine/findInsertIndex.js +37 -37
  26. package/bin/{v25 → v28}/alterFile/insertLine/index.js +49 -49
  27. package/bin/{v26/hookFolder → v28/alterFile}/insertLine/writeToFile.js +7 -7
  28. package/bin/{v25 → v28}/alterFile/start.js +44 -40
  29. package/bin/{v25 → v28}/hookFolder/forImportLine/index.js +44 -40
  30. package/bin/{v26/alterFile → v28/hookFolder}/forInsertIndex.js +29 -29
  31. package/bin/{v26 → v28}/hookFolder/insertLine/addLines.js +15 -15
  32. package/bin/{v25/alterFile → v28/hookFolder}/insertLine/findInsertIndex.js +37 -37
  33. package/bin/{v26 → v28}/hookFolder/insertLine/index.js +47 -49
  34. package/bin/{v25 → v28}/hookFolder/insertLine/writeToFile.js +7 -7
  35. package/bin/{v25 → v28}/hookFolder/start.js +27 -24
  36. package/bin/{v26 → v28}/start.js +24 -24
  37. package/index.js +13 -13
  38. package/package.json +37 -37
  39. package/bin/v26/fileNames.json +0 -35
package/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2026 KeshavSoft
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to do so, subject to the
10
- following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2026 KeshavSoft
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to do so, subject to the
10
+ following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,88 +1,88 @@
1
- # express-fix-any-js 🚀
2
-
3
- **Instantly repair, structure, and align Express.js routing files with automated idempotency and strict formatting safeguards.**
4
-
5
- [![npm version](https://img.shields.io/npm/v/express-fix-any-js.svg?style=flat-square&color=38bdf8)](https://www.npmjs.com/package/express-fix-any-js)
6
- [![license](https://img.shields.io/npm/l/express-fix-any-js.svg?style=flat-square&color=34d399)](LICENSE)
7
- [![GitHub workflows](https://img.shields.io/github/actions/workflow/status/keshavsoft/express-fix-any-js/npm-publish.yml?style=flat-square&label=workflows)](https://github.com/keshavsoft/express-fix-any-js/actions)
8
-
9
- ---
10
-
11
- ## 📖 Overview
12
-
13
- `express-fix-any-js` is a lightweight, high-performance AST and file-modifier utility. It dynamically injects missing Express.js route declarations, import statements, and export configurations into your JavaScript files while ensuring complete protection against code duplication.
14
-
15
- It acts as the foundational engine for the **KeshavSoft API Generation Suite**, seamlessly structuring routes generated via CLI tools or VS Code extensions.
16
-
17
- ---
18
-
19
- ## ✨ Features
20
-
21
- * 🔒 **Idempotent Injection:** Checks files before altering; skips execution silently if a duplicate pattern or route already exists.
22
- * 📐 **Strict Aesthetics:** Enforces zero-line spacing between consecutive routes while maintaining ideal breathing space after router initializations.
23
- * ⚡ **Versatile Versioning:** Supports legacy structure modifications alongside cutting-edge AST-based insertions (V1 to V6).
24
- * 🛠️ **Developer Diagnostics:** Emits clean, explicit inline logging for file updates and duplicate line match warnings.
25
-
26
- ---
27
-
28
- ## 🚀 Quick Start
29
-
30
- ### Installation
31
-
32
- ```bash
33
- npm install express-fix-any-js
34
- ```
35
-
36
- ### Programmatic Usage
37
-
38
- Safely append or insert local routes using the core `alterFile` API:
39
-
40
- ```javascript
41
- import alterFile from 'express-fix-any-js/bin/v6/UpdateJs/common/AlterFile/index.js';
42
-
43
- alterFile({
44
- jsFilePath: './routes/end-points.js',
45
- toInsertLine: 'router.post("/Create", express.json(), CreateFunc);',
46
- duplicationCheck: 'router.post("/Create"',
47
- insertAfter: [
48
- 'const router = express.Router();',
49
- 'router.post("/Alter"' // Inserts here if found, otherwise falls back to router initialization
50
- ],
51
- showLog: true
52
- });
53
- ```
54
-
55
- ---
56
-
57
- ## 📐 Formatting Standards
58
-
59
- The utility ensures your routing logic remains pristine by applying strict formatting:
60
-
61
- ### 1. First Route Base Layout
62
- ```javascript
63
- const router = express.Router();
64
-
65
- router.post("/Alter", express.json(), handler); // Injected with clean top margin
66
-
67
- export { router };
68
- ```
69
-
70
- ### 2. Multi-Route Append Strategy
71
- ```javascript
72
- router.post("/Alter", express.json(), handler);
73
- router.post("/Alter1", express.json(), handler); // Appended flush below previous route
74
- router.post("/Alter2", express.json(), handler);
75
- ```
76
-
77
- ---
78
-
79
- ## 🌐 Documentation & Guides
80
-
81
- Explore the [Official Documentation Portal](https://keshavsoft.github.io/express-fix-any-js/) for interactive guides and deeper architectural workflows:
82
-
83
- * 📄 **App.js Route Generation** – Automates app-level router registration.
84
- * 📄 **Version Route Generation** – Easily sets up `/v1` or `/v2` routing scopes.
85
- * 📄 **Table Route Generation** – Generates structured relational endpoints like `/doctors`.
86
- * 📄 **Endpoint Generation** – Scaffolds foundational GET, POST, PUT, and DELETE methods.
87
-
88
- Developed with ❤ by [KeshavSoft](https://github.com/keshavsoft). Distributed under the **MIT License**.
1
+ # express-fix-any-js 🚀
2
+
3
+ **Instantly repair, structure, and align Express.js routing files with automated idempotency and strict formatting safeguards.**
4
+
5
+ [![npm version](https://img.shields.io/npm/v/express-fix-any-js.svg?style=flat-square&color=38bdf8)](https://www.npmjs.com/package/express-fix-any-js)
6
+ [![license](https://img.shields.io/npm/l/express-fix-any-js.svg?style=flat-square&color=34d399)](LICENSE)
7
+ [![GitHub workflows](https://img.shields.io/github/actions/workflow/status/keshavsoft/express-fix-any-js/npm-publish.yml?style=flat-square&label=workflows)](https://github.com/keshavsoft/express-fix-any-js/actions)
8
+
9
+ ---
10
+
11
+ ## 📖 Overview
12
+
13
+ `express-fix-any-js` is a lightweight, high-performance AST and file-modifier utility. It dynamically injects missing Express.js route declarations, import statements, and export configurations into your JavaScript files while ensuring complete protection against code duplication.
14
+
15
+ It acts as the foundational engine for the **KeshavSoft API Generation Suite**, seamlessly structuring routes generated via CLI tools or VS Code extensions.
16
+
17
+ ---
18
+
19
+ ## ✨ Features
20
+
21
+ * 🔒 **Idempotent Injection:** Checks files before altering; skips execution silently if a duplicate pattern or route already exists.
22
+ * 📐 **Strict Aesthetics:** Enforces zero-line spacing between consecutive routes while maintaining ideal breathing space after router initializations.
23
+ * ⚡ **Versatile Versioning:** Supports legacy structure modifications alongside cutting-edge AST-based insertions (V1 to V6).
24
+ * 🛠️ **Developer Diagnostics:** Emits clean, explicit inline logging for file updates and duplicate line match warnings.
25
+
26
+ ---
27
+
28
+ ## 🚀 Quick Start
29
+
30
+ ### Installation
31
+
32
+ ```bash
33
+ npm install express-fix-any-js
34
+ ```
35
+
36
+ ### Programmatic Usage
37
+
38
+ Safely append or insert local routes using the core `alterFile` API:
39
+
40
+ ```javascript
41
+ import alterFile from 'express-fix-any-js/bin/v6/UpdateJs/common/AlterFile/index.js';
42
+
43
+ alterFile({
44
+ jsFilePath: './routes/end-points.js',
45
+ toInsertLine: 'router.post("/Create", express.json(), CreateFunc);',
46
+ duplicationCheck: 'router.post("/Create"',
47
+ insertAfter: [
48
+ 'const router = express.Router();',
49
+ 'router.post("/Alter"' // Inserts here if found, otherwise falls back to router initialization
50
+ ],
51
+ showLog: true
52
+ });
53
+ ```
54
+
55
+ ---
56
+
57
+ ## 📐 Formatting Standards
58
+
59
+ The utility ensures your routing logic remains pristine by applying strict formatting:
60
+
61
+ ### 1. First Route Base Layout
62
+ ```javascript
63
+ const router = express.Router();
64
+
65
+ router.post("/Alter", express.json(), handler); // Injected with clean top margin
66
+
67
+ export { router };
68
+ ```
69
+
70
+ ### 2. Multi-Route Append Strategy
71
+ ```javascript
72
+ router.post("/Alter", express.json(), handler);
73
+ router.post("/Alter1", express.json(), handler); // Appended flush below previous route
74
+ router.post("/Alter2", express.json(), handler);
75
+ ```
76
+
77
+ ---
78
+
79
+ ## 🌐 Documentation & Guides
80
+
81
+ Explore the [Official Documentation Portal](https://keshavsoft.github.io/express-fix-any-js/) for interactive guides and deeper architectural workflows:
82
+
83
+ * 📄 **App.js Route Generation** – Automates app-level router registration.
84
+ * 📄 **Version Route Generation** – Easily sets up `/v1` or `/v2` routing scopes.
85
+ * 📄 **Table Route Generation** – Generates structured relational endpoints like `/doctors`.
86
+ * 📄 **Endpoint Generation** – Scaffolds foundational GET, POST, PUT, and DELETE methods.
87
+
88
+ Developed with ❤ by [KeshavSoft](https://github.com/keshavsoft). Distributed under the **MIT License**.
package/bin/cli.js CHANGED
@@ -1,12 +1,12 @@
1
- #!/usr/bin/env node
2
-
3
- import getLatestVersion from "./core/getLatestVersion.js";
4
- import loadRunner from "./core/loadRunner.js";
5
-
6
- const run = async ({ }) => {
7
- const version = getLatestVersion();
8
- const runner = await loadRunner(version);
9
- await runner({});
10
- };
11
-
1
+ #!/usr/bin/env node
2
+
3
+ import getLatestVersion from "./core/getLatestVersion.js";
4
+ import loadRunner from "./core/loadRunner.js";
5
+
6
+ const run = async ({ }) => {
7
+ const version = getLatestVersion();
8
+ const runner = await loadRunner(version);
9
+ await runner({});
10
+ };
11
+
12
12
  run({}).then();
@@ -1,13 +1,13 @@
1
- import fs from "fs";
2
- import path from "path";
3
- import { fileURLToPath } from "url";
4
-
5
- const __dirname = path.dirname(fileURLToPath(import.meta.url));
6
-
7
- export default function getLatestVersion() {
8
- const versions = fs.readdirSync(path.join(__dirname, ".."))
9
- .filter(n => /^v\d+$/.test(n))
10
- .sort((a, b) => parseInt(a.slice(1)) - parseInt(b.slice(1)));
11
-
12
- return versions.at(-1);
1
+ import fs from "fs";
2
+ import path from "path";
3
+ import { fileURLToPath } from "url";
4
+
5
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
6
+
7
+ export default function getLatestVersion() {
8
+ const versions = fs.readdirSync(path.join(__dirname, ".."))
9
+ .filter(n => /^v\d+$/.test(n))
10
+ .sort((a, b) => parseInt(a.slice(1)) - parseInt(b.slice(1)));
11
+
12
+ return versions.at(-1);
13
13
  };
@@ -1,9 +1,9 @@
1
- export default async function loadRunner(version) {
2
- const mod = await import(`../${version}/start.js`);
3
-
4
- if (typeof mod.default !== "function") {
5
- throw new Error(`Invalid start.js in ${version}`);
6
- }
7
-
8
- return mod.default;
1
+ export default async function loadRunner(version) {
2
+ const mod = await import(`../${version}/start.js`);
3
+
4
+ if (typeof mod.default !== "function") {
5
+ throw new Error(`Invalid start.js in ${version}`);
6
+ }
7
+
8
+ return mod.default;
9
9
  };
@@ -1,41 +1,41 @@
1
- import fs from "fs";
2
- import path from "path";
3
-
4
- import defaultFunc from 'pattern-collector-anyjs-story';
5
- import insertLine from "../insertLine/index.js";
6
-
7
- import fileNamesJson from '../../fileNames.json' with {type: 'json'};
8
-
9
- const startFunc = ({ inParts, inFileType, inTargetPath,
10
- presentKey, regexKey, templateKey
11
- }) => {
12
-
13
- try {
14
- const localJsPath = path.join(inTargetPath, fileNamesJson[inFileType]);
15
-
16
- const fileContent = fs.readFileSync(localJsPath, 'utf8');
17
-
18
- const story = defaultFunc({ fileContent, fileType: inFileType });
19
-
20
- const fromInsertLine = insertLine({
21
- presentKey,
22
- linesStory: story.linesStory,
23
- onlyIndexesValues: story?.onlyIndexesValues,
24
- fileContent,
25
- importRegex: story?.extractRegex?.toInsertIndex?.[inFileType]?.[regexKey],
26
- filePath: localJsPath,
27
- inTemplate: story?.reverseTemplates?.[templateKey],
28
- inParts
29
- });
30
-
31
- return fromInsertLine;
32
-
33
- } catch (error) {
34
- console.log("error : ", error);
35
-
36
- };
37
- };
38
-
39
- export default startFunc;
40
-
1
+ import fs from "fs";
2
+ import path from "path";
3
+
4
+ import defaultFunc from 'pattern-collector-anyjs-story';
5
+ import insertLine from "../insertLine/index.js";
6
+
7
+ import fileNamesJson from '../../fileNames.json' with {type: 'json'};
8
+
9
+ const startFunc = ({ inParts, inFileType, inTargetPath,
10
+ presentKey, regexKey, templateKey
11
+ }) => {
12
+
13
+ try {
14
+ const localJsPath = path.join(inTargetPath, fileNamesJson[inFileType]);
15
+
16
+ const fileContent = fs.readFileSync(localJsPath, 'utf8');
17
+
18
+ const story = defaultFunc({ fileContent, fileType: inFileType });
19
+
20
+ const fromInsertLine = insertLine({
21
+ presentKey,
22
+ linesStory: story.linesStory,
23
+ onlyIndexesValues: story?.onlyIndexesValues,
24
+ fileContent,
25
+ importRegex: story?.extractRegex?.toInsertIndex?.[inFileType]?.[regexKey],
26
+ filePath: localJsPath,
27
+ inTemplate: story?.reverseTemplates?.[templateKey],
28
+ inParts
29
+ });
30
+
31
+ return fromInsertLine;
32
+
33
+ } catch (error) {
34
+ console.log("error : ", error);
35
+
36
+ };
37
+ };
38
+
39
+ export default startFunc;
40
+
41
41
  // startFunc({ folderNameToInsert, fileType });
@@ -1,30 +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
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
30
  };
@@ -1,16 +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
-
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
16
  export default startFunc;
@@ -1,38 +1,38 @@
1
- const startFunc = ({ onlyIndexesValues, importRegex, presentKey }) => {
2
- const insertStory = {};
3
-
4
- if (!importRegex) {
5
- return insertStory;
6
- };
7
-
8
- // Try each preferred location until one exists.
9
- for (const preference of importRegex) {
10
-
11
- const [group, property] = preference.split(".");
12
-
13
- // Preference like: importLines.firstLineIndex
14
- if (property) {
15
- if (onlyIndexesValues[group]?.[property] !== undefined) {
16
- insertStory.index = onlyIndexesValues[group][property];
17
-
18
- if (presentKey in onlyIndexesValues && !onlyIndexesValues[presentKey]) {
19
- insertStory.gapBefore = true;
20
- }
21
-
22
- break;
23
- }
24
-
25
- continue;
26
- }
27
-
28
- // Special preference like: first
29
- if (preference === "firstLineIndex") {
30
- insertStory.index = 0;
31
- break;
32
- };
33
- };
34
-
35
- return insertStory;
36
- };
37
-
1
+ const startFunc = ({ onlyIndexesValues, importRegex, presentKey }) => {
2
+ const insertStory = {};
3
+
4
+ if (!importRegex) {
5
+ return insertStory;
6
+ };
7
+
8
+ // Try each preferred location until one exists.
9
+ for (const preference of importRegex) {
10
+
11
+ const [group, property] = preference.split(".");
12
+
13
+ // Preference like: importLines.firstLineIndex
14
+ if (property) {
15
+ if (onlyIndexesValues[group]?.[property] !== undefined) {
16
+ insertStory.index = onlyIndexesValues[group][property];
17
+
18
+ if (presentKey in onlyIndexesValues && !onlyIndexesValues[presentKey]) {
19
+ insertStory.gapBefore = true;
20
+ }
21
+
22
+ break;
23
+ }
24
+
25
+ continue;
26
+ }
27
+
28
+ // Special preference like: first
29
+ if (preference === "firstLineIndex") {
30
+ insertStory.index = 0;
31
+ break;
32
+ };
33
+ };
34
+
35
+ return insertStory;
36
+ };
37
+
38
38
  export default startFunc;
@@ -1,50 +1,50 @@
1
- import findInsertIndex from "./findInsertIndex.js";
2
- import addLines from "./addLines.js";
3
- import writeToFile from "./writeToFile.js";
4
-
5
- function build(template, parts) {
6
- return template.replace(/\{(\d+)\}/g, (_, i) => parts[i]);
7
- };
8
-
9
- const startFunc = ({ linesStory, fileContent, filePath, importRegex, onlyIndexesValues,
10
- presentKey, inTemplate, inParts }) => {
11
-
12
- const foundUseLinesStory = linesStory[presentKey].find(element => {
13
- return element.part2 === inParts[1];
14
- });
15
-
16
- if (foundUseLinesStory) {
17
- return {
18
- KTF: false,
19
- KReason: foundUseLinesStory
20
- };
21
- };
22
-
23
- const newLine = build(inTemplate, inParts);
24
-
25
- const lines = fileContent.split(/\r?\n/);
26
-
27
- const insertStory = findInsertIndex({
28
- onlyIndexesValues,
29
- importRegex,
30
- presentKey
31
- });
32
-
33
- addLines({
34
- inLines: lines, inInsertAtIndex: insertStory?.index,
35
- inNewLine: newLine, inGapBefore: insertStory?.gapBefore,
36
- inGapAfter: insertStory?.gapAfter
37
- });
38
-
39
- // lines.splice(insertAtIndex, 0, newLine);
40
-
41
- writeToFile({ fileContent, filePath, lines });
42
-
43
- return {
44
- newLine, inParts
45
- };
46
- // fs.writeFileSync(filePath, lines.join(fileContent.includes("\r\n") ? "\r\n" : "\n"));
47
-
48
- };
49
-
1
+ import findInsertIndex from "./findInsertIndex.js";
2
+ import addLines from "./addLines.js";
3
+ import writeToFile from "./writeToFile.js";
4
+
5
+ function build(template, parts) {
6
+ return template.replace(/\{(\d+)\}/g, (_, i) => parts[i]);
7
+ };
8
+
9
+ const startFunc = ({ linesStory, fileContent, filePath, importRegex, onlyIndexesValues,
10
+ presentKey, inTemplate, inParts }) => {
11
+
12
+ const foundUseLinesStory = linesStory[presentKey].find(element => {
13
+ return element.part2 === inParts[1];
14
+ });
15
+
16
+ if (foundUseLinesStory) {
17
+ return {
18
+ KTF: false,
19
+ KReason: foundUseLinesStory
20
+ };
21
+ };
22
+
23
+ const newLine = build(inTemplate, inParts);
24
+
25
+ const lines = fileContent.split(/\r?\n/);
26
+
27
+ const insertStory = findInsertIndex({
28
+ onlyIndexesValues,
29
+ importRegex,
30
+ presentKey
31
+ });
32
+
33
+ addLines({
34
+ inLines: lines, inInsertAtIndex: insertStory?.index,
35
+ inNewLine: newLine, inGapBefore: insertStory?.gapBefore,
36
+ inGapAfter: insertStory?.gapAfter
37
+ });
38
+
39
+ // lines.splice(insertAtIndex, 0, newLine);
40
+
41
+ writeToFile({ fileContent, filePath, lines });
42
+
43
+ return {
44
+ newLine, inParts
45
+ };
46
+ // fs.writeFileSync(filePath, lines.join(fileContent.includes("\r\n") ? "\r\n" : "\n"));
47
+
48
+ };
49
+
50
50
  export default startFunc;
@@ -1,8 +1,8 @@
1
- import fs from 'fs';
2
-
3
- const startFunc = ({ fileContent, filePath, lines }) => {
4
-
5
- fs.writeFileSync(filePath, lines.join(fileContent.includes("\r\n") ? "\r\n" : "\n"));
6
- };
7
-
1
+ import fs from 'fs';
2
+
3
+ const startFunc = ({ fileContent, filePath, lines }) => {
4
+
5
+ fs.writeFileSync(filePath, lines.join(fileContent.includes("\r\n") ? "\r\n" : "\n"));
6
+ };
7
+
8
8
  export default startFunc;