express-fix-any-js 1.16.4 → 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.
- package/LICENSE +21 -21
- package/README.md +118 -118
- package/bin/cli.js +11 -11
- package/bin/core/getLatestVersion.js +12 -12
- package/bin/core/loadRunner.js +8 -8
- package/bin/v16/addLines.js +15 -15
- package/bin/v16/findInsertIndex.js +78 -78
- package/bin/v16/forImportLine/index.js +36 -36
- package/bin/v16/forImportLine/insertImportLine.js +39 -39
- package/bin/v16/forInsertIndex.js +29 -29
- package/bin/v16/forUseLine/index.js +29 -29
- package/bin/v16/forUseLine/insertUseLine.js +51 -51
- package/bin/v16/start.js +17 -17
- package/bin/{v15 → v17/addTableName}/addLines.js +15 -15
- package/bin/{v15 → v17/addTableName}/findInsertIndex.js +78 -74
- package/bin/{v15 → v17/addTableName}/forImportLine/index.js +36 -35
- package/bin/{v15 → v17/addTableName}/forImportLine/insertImportLine.js +39 -53
- package/bin/{v15 → v17/addTableName}/forInsertIndex.js +29 -29
- package/bin/{v15 → v17/addTableName}/forUseLine/index.js +29 -28
- package/bin/{v15 → v17/addTableName}/forUseLine/insertUseLine.js +51 -57
- package/bin/v17/addTableName/start.js +44 -0
- package/bin/v17/hookFolder/addLines.js +16 -0
- package/bin/v17/hookFolder/findInsertIndex.js +79 -0
- package/bin/v17/hookFolder/forImportLine/index.js +37 -0
- package/bin/v17/hookFolder/forImportLine/insertImportLine.js +40 -0
- package/bin/v17/hookFolder/forInsertIndex.js +30 -0
- package/bin/v17/hookFolder/forUseLine/index.js +30 -0
- package/bin/v17/hookFolder/forUseLine/insertUseLine.js +52 -0
- package/bin/{v15 → v17/hookFolder}/start.js +17 -17
- package/bin/v17/start.js +34 -0
- package/index.js +13 -13
- package/package.json +35 -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,118 +1,118 @@
|
|
|
1
|
-
# express-fix-any-js 🚀
|
|
2
|
-
|
|
3
|
-
> **Instantly repair, structure, and align Express.js routing files with automated idempotency & formatting safeguards.**
|
|
4
|
-
|
|
5
|
-
[](https://www.npmjs.com/package/express-fix-any-js)
|
|
6
|
-
[](LICENSE)
|
|
7
|
-
[](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 JS AST and file modifier utility. It automatically injects missing Express.js route declarations, import statements, and export configurations into your JavaScript files while ensuring complete protection against code duplication.
|
|
14
|
-
|
|
15
|
-
This module acts as the foundation layer for the **KeshavSoft API Generation Suite**, dynamically structuring routes generated via CLI or VS Code extensions.
|
|
16
|
-
|
|
17
|
-
---
|
|
18
|
-
|
|
19
|
-
## ✨ Features
|
|
20
|
-
|
|
21
|
-
* **🔒 Duplicate Prevention (Idempotency)**: Checks files before altering them. If a route or pattern already exists, it skips execution silently to avoid code corruption.
|
|
22
|
-
* **📐 Strict Route Formatting**:
|
|
23
|
-
* Inserts clean line spaces after `express.Router()` initialization.
|
|
24
|
-
* Maintains zero-line spacing between consecutive route definitions.
|
|
25
|
-
* Appends spacing cleanly before the `export` keyword.
|
|
26
|
-
* **⚡ Multiple File Versions (V1 - V6)**: Supports legacy configuration modifications alongside cutting-edge AST-based insertions.
|
|
27
|
-
* **🛠️ Developer-First Diagnostics**: Provides clear inline logging of file updates and duplicate line match warnings.
|
|
28
|
-
|
|
29
|
-
---
|
|
30
|
-
|
|
31
|
-
## 📁 Repository Integration Map
|
|
32
|
-
|
|
33
|
-
`express-fix-any-js` is part of a larger cascading developer ecosystem:
|
|
34
|
-
|
|
35
|
-
```mermaid
|
|
36
|
-
graph TD
|
|
37
|
-
ext["vs-code-ext-express-api-gen-get-actions<br/><i>VS Code Extension</i>"]
|
|
38
|
-
|
|
39
|
-
gen["kschema-fs-api-gen-get-actions<br/><i>API Generator Actions</i>"]
|
|
40
|
-
|
|
41
|
-
endpoints["express-fix-endpoints-get-js<br/><i>Endpoint Logic Builder</i>"]
|
|
42
|
-
|
|
43
|
-
anyjs["express-fix-any-js<br/><i>This Core Utility</i>"]
|
|
44
|
-
|
|
45
|
-
ext -->|delegates to| gen
|
|
46
|
-
gen -->|invokes| endpoints
|
|
47
|
-
endpoints -->|relies on| anyjs
|
|
48
|
-
```
|
|
49
|
-
|
|
50
|
-
---
|
|
51
|
-
|
|
52
|
-
## 🚀 Quick Start
|
|
53
|
-
|
|
54
|
-
### Installation
|
|
55
|
-
|
|
56
|
-
```bash
|
|
57
|
-
npm install express-fix-any-js
|
|
58
|
-
```
|
|
59
|
-
|
|
60
|
-
### Programmatic Usage
|
|
61
|
-
|
|
62
|
-
You can use the core `alterFile` function to modify local routes files safely:
|
|
63
|
-
|
|
64
|
-
```javascript
|
|
65
|
-
import alterFile from 'express-fix-any-js/bin/v6/UpdateJs/common/AlterFile/index.js';
|
|
66
|
-
|
|
67
|
-
alterFile({
|
|
68
|
-
jsFilePath: './routes/end-points.js',
|
|
69
|
-
toInsertLine: 'router.post("/Create", express.json(), CreateFunc);',
|
|
70
|
-
duplicationCheck: 'router.post("/Create"',
|
|
71
|
-
insertAfter: [
|
|
72
|
-
'const router = express.Router();',
|
|
73
|
-
'router.post("/Alter"' // Inserts immediately after this line if found, otherwise after Router init
|
|
74
|
-
],
|
|
75
|
-
showLog: true
|
|
76
|
-
});
|
|
77
|
-
```
|
|
78
|
-
|
|
79
|
-
---
|
|
80
|
-
|
|
81
|
-
## 📜 Structuring Rules
|
|
82
|
-
|
|
83
|
-
The utility operates under strict structural rules to preserve route aesthetics:
|
|
84
|
-
|
|
85
|
-
### 1. First Route Placement
|
|
86
|
-
When the first route is inserted into an empty routing structure, the file is formatted with breathing space:
|
|
87
|
-
|
|
88
|
-
```javascript
|
|
89
|
-
const router = express.Router();
|
|
90
|
-
|
|
91
|
-
router.post("/Alter", express.json(), handler);
|
|
92
|
-
|
|
93
|
-
export { router };
|
|
94
|
-
```
|
|
95
|
-
|
|
96
|
-
### 2. Multi-Route Appending
|
|
97
|
-
Subsequent routes are appended directly after the last matching route with no empty line spacing between them:
|
|
98
|
-
|
|
99
|
-
```javascript
|
|
100
|
-
router.post("/Alter", express.json(), handler);
|
|
101
|
-
router.post("/Alter1", express.json(), handler);
|
|
102
|
-
router.post("/Alter2", express.json(), handler);
|
|
103
|
-
```
|
|
104
|
-
|
|
105
|
-
---
|
|
106
|
-
|
|
107
|
-
## 🛠️ Developer & API Reference
|
|
108
|
-
|
|
109
|
-
For detailed developer notes, architectural mappings, and code analyses:
|
|
110
|
-
* [Developer Docs Home](./docs/index.html)
|
|
111
|
-
* [Code Style & Readability Analysis](./docs/code_style_and_readability.md)
|
|
112
|
-
* [AlterFile Workflow Analysis](./docs/alter_file_analysis.md)
|
|
113
|
-
|
|
114
|
-
---
|
|
115
|
-
|
|
116
|
-
## ⚖️ License
|
|
117
|
-
|
|
118
|
-
MIT License. Designed with ❤️ by [KeshavSoft](https://github.com/keshavsoft).
|
|
1
|
+
# express-fix-any-js 🚀
|
|
2
|
+
|
|
3
|
+
> **Instantly repair, structure, and align Express.js routing files with automated idempotency & formatting safeguards.**
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/express-fix-any-js)
|
|
6
|
+
[](LICENSE)
|
|
7
|
+
[](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 JS AST and file modifier utility. It automatically injects missing Express.js route declarations, import statements, and export configurations into your JavaScript files while ensuring complete protection against code duplication.
|
|
14
|
+
|
|
15
|
+
This module acts as the foundation layer for the **KeshavSoft API Generation Suite**, dynamically structuring routes generated via CLI or VS Code extensions.
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
## ✨ Features
|
|
20
|
+
|
|
21
|
+
* **🔒 Duplicate Prevention (Idempotency)**: Checks files before altering them. If a route or pattern already exists, it skips execution silently to avoid code corruption.
|
|
22
|
+
* **📐 Strict Route Formatting**:
|
|
23
|
+
* Inserts clean line spaces after `express.Router()` initialization.
|
|
24
|
+
* Maintains zero-line spacing between consecutive route definitions.
|
|
25
|
+
* Appends spacing cleanly before the `export` keyword.
|
|
26
|
+
* **⚡ Multiple File Versions (V1 - V6)**: Supports legacy configuration modifications alongside cutting-edge AST-based insertions.
|
|
27
|
+
* **🛠️ Developer-First Diagnostics**: Provides clear inline logging of file updates and duplicate line match warnings.
|
|
28
|
+
|
|
29
|
+
---
|
|
30
|
+
|
|
31
|
+
## 📁 Repository Integration Map
|
|
32
|
+
|
|
33
|
+
`express-fix-any-js` is part of a larger cascading developer ecosystem:
|
|
34
|
+
|
|
35
|
+
```mermaid
|
|
36
|
+
graph TD
|
|
37
|
+
ext["vs-code-ext-express-api-gen-get-actions<br/><i>VS Code Extension</i>"]
|
|
38
|
+
|
|
39
|
+
gen["kschema-fs-api-gen-get-actions<br/><i>API Generator Actions</i>"]
|
|
40
|
+
|
|
41
|
+
endpoints["express-fix-endpoints-get-js<br/><i>Endpoint Logic Builder</i>"]
|
|
42
|
+
|
|
43
|
+
anyjs["express-fix-any-js<br/><i>This Core Utility</i>"]
|
|
44
|
+
|
|
45
|
+
ext -->|delegates to| gen
|
|
46
|
+
gen -->|invokes| endpoints
|
|
47
|
+
endpoints -->|relies on| anyjs
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
---
|
|
51
|
+
|
|
52
|
+
## 🚀 Quick Start
|
|
53
|
+
|
|
54
|
+
### Installation
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
npm install express-fix-any-js
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### Programmatic Usage
|
|
61
|
+
|
|
62
|
+
You can use the core `alterFile` function to modify local routes files safely:
|
|
63
|
+
|
|
64
|
+
```javascript
|
|
65
|
+
import alterFile from 'express-fix-any-js/bin/v6/UpdateJs/common/AlterFile/index.js';
|
|
66
|
+
|
|
67
|
+
alterFile({
|
|
68
|
+
jsFilePath: './routes/end-points.js',
|
|
69
|
+
toInsertLine: 'router.post("/Create", express.json(), CreateFunc);',
|
|
70
|
+
duplicationCheck: 'router.post("/Create"',
|
|
71
|
+
insertAfter: [
|
|
72
|
+
'const router = express.Router();',
|
|
73
|
+
'router.post("/Alter"' // Inserts immediately after this line if found, otherwise after Router init
|
|
74
|
+
],
|
|
75
|
+
showLog: true
|
|
76
|
+
});
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
---
|
|
80
|
+
|
|
81
|
+
## 📜 Structuring Rules
|
|
82
|
+
|
|
83
|
+
The utility operates under strict structural rules to preserve route aesthetics:
|
|
84
|
+
|
|
85
|
+
### 1. First Route Placement
|
|
86
|
+
When the first route is inserted into an empty routing structure, the file is formatted with breathing space:
|
|
87
|
+
|
|
88
|
+
```javascript
|
|
89
|
+
const router = express.Router();
|
|
90
|
+
|
|
91
|
+
router.post("/Alter", express.json(), handler);
|
|
92
|
+
|
|
93
|
+
export { router };
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
### 2. Multi-Route Appending
|
|
97
|
+
Subsequent routes are appended directly after the last matching route with no empty line spacing between them:
|
|
98
|
+
|
|
99
|
+
```javascript
|
|
100
|
+
router.post("/Alter", express.json(), handler);
|
|
101
|
+
router.post("/Alter1", express.json(), handler);
|
|
102
|
+
router.post("/Alter2", express.json(), handler);
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
---
|
|
106
|
+
|
|
107
|
+
## 🛠️ Developer & API Reference
|
|
108
|
+
|
|
109
|
+
For detailed developer notes, architectural mappings, and code analyses:
|
|
110
|
+
* [Developer Docs Home](./docs/index.html)
|
|
111
|
+
* [Code Style & Readability Analysis](./docs/code_style_and_readability.md)
|
|
112
|
+
* [AlterFile Workflow Analysis](./docs/alter_file_analysis.md)
|
|
113
|
+
|
|
114
|
+
---
|
|
115
|
+
|
|
116
|
+
## ⚖️ License
|
|
117
|
+
|
|
118
|
+
MIT License. Designed with ❤️ by [KeshavSoft](https://github.com/keshavsoft).
|
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
|
};
|
package/bin/core/loadRunner.js
CHANGED
|
@@ -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
|
};
|
package/bin/v16/addLines.js
CHANGED
|
@@ -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,79 +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
|
-
|
|
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
79
|
export default startFunc;
|
|
@@ -1,37 +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
|
-
|
|
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
37
|
// startFunc({ folderNameToInsert, fileType });
|