express-fix-any-js-from-base 1.2.5
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 -0
- package/README.md +70 -0
- package/bin/cli.js +12 -0
- package/bin/core/getLatestVersion.js +13 -0
- package/bin/core/loadRunner.js +9 -0
- package/bin/v1/UpdateJs/common/AlterFileForImport/checkDuplicate.js +14 -0
- package/bin/v1/UpdateJs/common/AlterFileForImport/findInsertIndex/defaultAfter/index.js +23 -0
- package/bin/v1/UpdateJs/common/AlterFileForImport/findInsertIndex/defaultAfter/modulat.js +21 -0
- package/bin/v1/UpdateJs/common/AlterFileForImport/findInsertIndex/defaultAfter/story.js +8 -0
- package/bin/v1/UpdateJs/common/AlterFileForImport/findInsertIndex/defaultBefore/index.js +23 -0
- package/bin/v1/UpdateJs/common/AlterFileForImport/findInsertIndex/defaultBefore/modulat.js +24 -0
- package/bin/v1/UpdateJs/common/AlterFileForImport/findInsertIndex/defaultBefore/story.js +8 -0
- package/bin/v1/UpdateJs/common/AlterFileForImport/findInsertIndex/index.js +16 -0
- package/bin/v1/UpdateJs/common/AlterFileForImport/index.js +80 -0
- package/bin/v1/UpdateJs/common/AlterFileForImport/showLogs/atEnd.js +10 -0
- package/bin/v1/UpdateJs/common/AlterFileForImport/showLogs/atStart.js +13 -0
- package/bin/v1/UpdateJs/common/AlterFileForImport/toInsertLineStory.js +17 -0
- package/bin/v1/UpdateJs/common/readFile.js +8 -0
- package/bin/v1/UpdateJs/common/writeFile.js +25 -0
- package/bin/v1/UpdateJs/index.js +9 -0
- package/bin/v1/start.js +7 -0
- package/bin/v2/UpdateJs/common/AlterFileForImport/checkDuplicate.js +14 -0
- package/bin/v2/UpdateJs/common/AlterFileForImport/findInsertIndex/defaultAfter/index.js +23 -0
- package/bin/v2/UpdateJs/common/AlterFileForImport/findInsertIndex/defaultAfter/modulat.js +21 -0
- package/bin/v2/UpdateJs/common/AlterFileForImport/findInsertIndex/defaultAfter/story.js +8 -0
- package/bin/v2/UpdateJs/common/AlterFileForImport/findInsertIndex/defaultBefore/index.js +30 -0
- package/bin/v2/UpdateJs/common/AlterFileForImport/findInsertIndex/defaultBefore/modulat.js +53 -0
- package/bin/v2/UpdateJs/common/AlterFileForImport/findInsertIndex/defaultBefore/story.js +8 -0
- package/bin/v2/UpdateJs/common/AlterFileForImport/findInsertIndex/index.js +19 -0
- package/bin/v2/UpdateJs/common/AlterFileForImport/index.js +82 -0
- package/bin/v2/UpdateJs/common/AlterFileForImport/showLogs/atEnd.js +10 -0
- package/bin/v2/UpdateJs/common/AlterFileForImport/showLogs/atStart.js +12 -0
- package/bin/v2/UpdateJs/common/AlterFileForImport/toInsertLineStory.js +17 -0
- package/bin/v2/UpdateJs/common/readFile.js +8 -0
- package/bin/v2/UpdateJs/common/writeFile.js +29 -0
- package/bin/v2/UpdateJs/index.js +9 -0
- package/bin/v2/start.js +7 -0
- package/index.js +14 -0
- package/package.json +37 -0
package/LICENSE
ADDED
|
@@ -0,0 +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.
|
package/README.md
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# express-fix-any-js-from-for-import 🚀
|
|
2
|
+
|
|
3
|
+
> **Idempotent & Clean Route Imports Builder. Intelligently scans, injects, and aligns routing import statements at the top of Javascript files.**
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/express-fix-any-js-from-for-import)
|
|
6
|
+
[](LICENSE)
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
## 📖 The Story of the 3 Repositories
|
|
11
|
+
|
|
12
|
+
This package handles the top-level **imports** layer in our modular route-fixing ecosystem. It is designed to work in alignment with two other packages:
|
|
13
|
+
|
|
14
|
+
```mermaid
|
|
15
|
+
graph TD
|
|
16
|
+
story["express-fix-any-js-from-story<br/><b>(High-Level CLI Orchestrator)</b>"]
|
|
17
|
+
forimport["express-fix-any-js-from-for-import<br/><b>(Route Imports Fixer)</b>"]
|
|
18
|
+
consumption["express-fix-any-js-from-for-consumption<br/><b>(Route Consumption Fixer)</b>"]
|
|
19
|
+
|
|
20
|
+
story -->|Requires| forimport
|
|
21
|
+
story -->|Requires| consumption
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
1. **[express-fix-any-js-from-for-import](https://github.com/keshavsoft/express-fix-any-js-from-for-import)** *(This Repository)*: Focuses strictly on inspecting, formatting, and injecting route/router **import statements** cleanly at the top of Javascript files without duplication.
|
|
25
|
+
2. **[express-fix-any-js-from-for-consumption](https://github.com/keshavsoft/express-fix-any-js-from-for-consumption)**: Focuses strictly on inspecting, formatting, and injecting route/router **consumption lines** (`router.use(...)` or `router.post(...)`) in the body of the routes initialization block.
|
|
26
|
+
3. **[express-fix-any-js-from-story](https://github.com/keshavsoft/express-fix-any-js-from-story)**: The master orchestrator. It receives generation specifications (stories) and coordinates both the **import fixer** and the **consumption fixer** to safely build and update full routing definitions.
|
|
27
|
+
|
|
28
|
+
---
|
|
29
|
+
|
|
30
|
+
## ✨ Features
|
|
31
|
+
|
|
32
|
+
* **🔒 Strict Idempotency**: Prevents adding duplicate imports regardless of repeated builders runs.
|
|
33
|
+
* **📐 Layout Spacing**: Inserts imports cleanly at the top relative to existing ES imports or CommonJS requires.
|
|
34
|
+
* **⚡ Cascade Dependency**: Automatically triggers dependents notification builds downstream upon successful publishing.
|
|
35
|
+
|
|
36
|
+
---
|
|
37
|
+
|
|
38
|
+
## 🚀 Quick Start
|
|
39
|
+
|
|
40
|
+
### Installation
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
npm install express-fix-any-js-from-for-import
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### Programmatic Usage
|
|
47
|
+
|
|
48
|
+
```javascript
|
|
49
|
+
import alterFileImports from 'express-fix-any-js-from-for-import';
|
|
50
|
+
|
|
51
|
+
alterFileImports({
|
|
52
|
+
jsFilePath: './routes/end-points.js',
|
|
53
|
+
toInsertLine: "import GetRoutes from './routes/GetRoutes.js';",
|
|
54
|
+
duplicationCheck: "import GetRoutes"
|
|
55
|
+
});
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
---
|
|
59
|
+
|
|
60
|
+
## 🛠[]() Developer Technical Guides
|
|
61
|
+
|
|
62
|
+
For more details on the orchestration system:
|
|
63
|
+
* [Developer Docs Home](./docs/index.html)
|
|
64
|
+
* [Orchestration CLI documentation](https://github.com/keshavsoft/express-fix-any-js-from-story)
|
|
65
|
+
|
|
66
|
+
---
|
|
67
|
+
|
|
68
|
+
## ⚖️ License
|
|
69
|
+
|
|
70
|
+
MIT License. Designed with ❤️ by [KeshavSoft](https://github.com/keshavsoft).
|
package/bin/cli.js
ADDED
|
@@ -0,0 +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
|
+
|
|
12
|
+
run({}).then();
|
|
@@ -0,0 +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);
|
|
13
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
const checkUseDuplicate = ({ inSearchText, inFileContentAsStory }) => {
|
|
2
|
+
|
|
3
|
+
const found = inFileContentAsStory.find(element => {
|
|
4
|
+
return element.folderName === inSearchText;
|
|
5
|
+
});
|
|
6
|
+
|
|
7
|
+
return {
|
|
8
|
+
inserted: false,
|
|
9
|
+
found,
|
|
10
|
+
lineNumber: found ? found.lineNumber : null
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export default checkUseDuplicate;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import getFromStory from "./story.js";
|
|
2
|
+
import getFromSummary from "./modulat.js";
|
|
3
|
+
|
|
4
|
+
const findInsertIndex = ({ toInsertIndex,
|
|
5
|
+
inAllLinesStory, inSummary
|
|
6
|
+
}) => {
|
|
7
|
+
|
|
8
|
+
const storyIndex = getFromStory(inAllLinesStory);
|
|
9
|
+
|
|
10
|
+
if (storyIndex !== null) {
|
|
11
|
+
toInsertIndex = storyIndex;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const summaryIndex = getFromSummary(inSummary);
|
|
15
|
+
|
|
16
|
+
if (summaryIndex !== null) {
|
|
17
|
+
toInsertIndex = summaryIndex;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
return toInsertIndex;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export default findInsertIndex;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
const getFromSummary = (inSummary) => {
|
|
2
|
+
let index = null;
|
|
3
|
+
|
|
4
|
+
if (inSummary?.exportSummary) {
|
|
5
|
+
const minLine = inSummary?.exportSummary?.maxLineNumber;
|
|
6
|
+
if (minLine !== Infinity && minLine !== -Infinity) {
|
|
7
|
+
index = minLine + 1;
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
if (inSummary?.consumeSummary) {
|
|
12
|
+
const minLine = inSummary?.consumeSummary?.maxLineNumber;
|
|
13
|
+
if (minLine !== Infinity && minLine !== -Infinity) {
|
|
14
|
+
index = minLine + 1;
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
return index;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export default getFromSummary;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import getFromStory from "./story.js";
|
|
2
|
+
import getFromSummary from "./modulat.js";
|
|
3
|
+
|
|
4
|
+
const findInsertIndex = ({ toInsertIndex,
|
|
5
|
+
inAllLinesStory, inSummary, inKeyInSummary
|
|
6
|
+
}) => {
|
|
7
|
+
|
|
8
|
+
const storyIndex = getFromStory(inAllLinesStory);
|
|
9
|
+
|
|
10
|
+
if (storyIndex !== null) {
|
|
11
|
+
toInsertIndex = storyIndex;
|
|
12
|
+
};
|
|
13
|
+
// console.log("aaaaaaaa-- : ", inKeyInSummary);
|
|
14
|
+
const summaryIndex = getFromSummary({ inSummary, inKeyInSummary });
|
|
15
|
+
|
|
16
|
+
if (summaryIndex !== null) {
|
|
17
|
+
toInsertIndex = summaryIndex;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
return toInsertIndex;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export default findInsertIndex;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
const startFunc = ({ inSummary, inKeyInSummary }) => {
|
|
2
|
+
let index = null;
|
|
3
|
+
let emptyBefore = false;
|
|
4
|
+
|
|
5
|
+
if (inSummary.importSummary?.lineCount === 0) {
|
|
6
|
+
|
|
7
|
+
if (inSummary.importFromNpmSummary?.lineCount === 0) {
|
|
8
|
+
index = 1;
|
|
9
|
+
} else {
|
|
10
|
+
emptyBefore = true;
|
|
11
|
+
index = inSummary.importFromNpmSummary?.maxLineNumber + 1;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
} else {
|
|
15
|
+
index = inSummary.importSummary?.minLineNumber;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
return {
|
|
19
|
+
emptyBefore,
|
|
20
|
+
index
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export default startFunc;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import defaultAfter from "./defaultAfter/index.js";
|
|
2
|
+
import defaultBefore from "./defaultBefore/index.js";
|
|
3
|
+
|
|
4
|
+
const startFunc = ({
|
|
5
|
+
inAllLinesStory, rulesJson, inSummary, inKeyInSummary,
|
|
6
|
+
}) => {
|
|
7
|
+
let toInsertIndex = 3;
|
|
8
|
+
|
|
9
|
+
if (rulesJson.toInsertRule === "defaultAfter") toInsertIndex = defaultAfter({ toInsertIndex, inAllLinesStory, inSummary });
|
|
10
|
+
|
|
11
|
+
if (rulesJson.toInsertRule === "defaultBefore") toInsertIndex = defaultBefore({ toInsertIndex, inAllLinesStory, inSummary, inKeyInSummary });
|
|
12
|
+
// console.log("aaaaaaaa--------- : ", toInsertIndex);
|
|
13
|
+
return toInsertIndex;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export default startFunc;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import getStory from "pattern-collector-anyjs";
|
|
2
|
+
|
|
3
|
+
import readFile from "../readFile.js";
|
|
4
|
+
import checkDuplicate from "./checkDuplicate.js";
|
|
5
|
+
import findInsertIndex from "./findInsertIndex/index.js";
|
|
6
|
+
import writeFile from "../writeFile.js";
|
|
7
|
+
import getLineStory from "./toInsertLineStory.js";
|
|
8
|
+
import atStart from "./showLogs/atStart.js";
|
|
9
|
+
import atEnd from "./showLogs/atEnd.js";
|
|
10
|
+
|
|
11
|
+
import packageJson from '../../../../../package.json' with {type: 'json'};
|
|
12
|
+
|
|
13
|
+
const alterFile = ({
|
|
14
|
+
jsFilePath, rulesJson, extractRegex, inParseRegex,
|
|
15
|
+
toCheckLinesName, inKeyInSummary,
|
|
16
|
+
showLog = false, showLogStep1, showLogStep2, showLogStep3
|
|
17
|
+
}) => {
|
|
18
|
+
|
|
19
|
+
atStart({ jsFilePath, rulesJson, packageJson, showLog, parseRegex: inParseRegex, searchRegex: extractRegex });
|
|
20
|
+
|
|
21
|
+
const toInsertLine = rulesJson.toInsertLine;
|
|
22
|
+
|
|
23
|
+
const content = readFile(jsFilePath);
|
|
24
|
+
|
|
25
|
+
const lineStory = getLineStory({
|
|
26
|
+
toInsertLine, parseRegex: inParseRegex, showLog
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
if (showLog?.withValues) console.log(`${packageJson.name}-lineStory : `, lineStory);
|
|
30
|
+
|
|
31
|
+
const fromPatternCollector = getStory({
|
|
32
|
+
fileContent: content,
|
|
33
|
+
extractRegex,
|
|
34
|
+
showLog: showLogStep1,
|
|
35
|
+
showLogStep1: showLogStep2, showLogStep2: showLogStep3
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
// console.log(`-fromPatternCollector : `, fromPatternCollector.importLines);
|
|
39
|
+
|
|
40
|
+
if (showLog?.withValues) console.log(`${packageJson.name}------------ : `, fromPatternCollector);
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
const duplicateInfo = checkDuplicate({
|
|
44
|
+
inSearchText: lineStory.raka,
|
|
45
|
+
inFileContentAsStory: fromPatternCollector[toCheckLinesName]
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
if (duplicateInfo.found) {
|
|
49
|
+
if (showLog) {
|
|
50
|
+
console.log(
|
|
51
|
+
`Duplicate found at line ${duplicateInfo.lineNumber}`
|
|
52
|
+
);
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
return duplicateInfo;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
const toInsertIndex = findInsertIndex({
|
|
59
|
+
inAllLinesStory: fromPatternCollector.allLinesStory,
|
|
60
|
+
inSummary: fromPatternCollector?.summary,
|
|
61
|
+
rulesJson, inKeyInSummary
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
writeFile({
|
|
65
|
+
inJsFilePath: jsFilePath,
|
|
66
|
+
inInsertLineIndex: toInsertIndex.index,
|
|
67
|
+
toInsertLine, emptyBefore: toInsertIndex.emptyBefore
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
atEnd({ duplicateInfo, packageJson, showLog });
|
|
71
|
+
|
|
72
|
+
return {
|
|
73
|
+
inserted: true,
|
|
74
|
+
found: false,
|
|
75
|
+
filePath: jsFilePath,
|
|
76
|
+
lineNumber: null
|
|
77
|
+
};
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
export default alterFile;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
const startFunc = ({
|
|
2
|
+
duplicateInfo, packageJson, showLog
|
|
3
|
+
}) => {
|
|
4
|
+
|
|
5
|
+
if (showLog?.keysOnly) console.log(`${packageJson.name}-end`);
|
|
6
|
+
if (showLog?.withValues) console.log(`${packageJson.name}-outputs : `, duplicateInfo);
|
|
7
|
+
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export default startFunc;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
const startFunc = ({
|
|
2
|
+
jsFilePath, rulesJson, packageJson, showLog, parseRegex, searchRegex
|
|
3
|
+
}) => {
|
|
4
|
+
|
|
5
|
+
if (showLog?.keysOnly) console.log(`${packageJson.name}-start`);
|
|
6
|
+
|
|
7
|
+
if (showLog?.withValues) console.log(`${packageJson.name}-inputs-jsFilePath : `, jsFilePath);
|
|
8
|
+
if (showLog?.withValues) console.log(`${packageJson.name}-inputs-rulesJson : `, JSON.stringify(rulesJson));
|
|
9
|
+
if (showLog?.withValues) console.log(`${packageJson.name}-inputs-parseRegex : `, JSON.stringify(parseRegex));
|
|
10
|
+
if (showLog?.withValues) console.log(`${packageJson.name}-inputs-searchRegex : `, JSON.stringify(searchRegex));
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export default startFunc;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import baseRegex from "pattern-collector-base-regex";
|
|
2
|
+
|
|
3
|
+
const startFunc = ({ toInsertLine, parseRegex, showLog = false }) => {
|
|
4
|
+
|
|
5
|
+
if (showLog) console.log("toInsertLineStory-inputs : ", parseRegex, toInsertLine);
|
|
6
|
+
|
|
7
|
+
const fromPatternCollector = baseRegex({
|
|
8
|
+
matchLine: toInsertLine,
|
|
9
|
+
parseRegex, showLog
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
if (showLog) console.log("toInsertLineStory-outputs : ", fromPatternCollector);
|
|
13
|
+
|
|
14
|
+
return fromPatternCollector;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export default startFunc;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import readFile from "./readFile.js";
|
|
3
|
+
|
|
4
|
+
const writeFile = ({ inJsFilePath, inInsertLineIndex, toInsertLine,
|
|
5
|
+
emptyBefore = false, emptyAfter = false
|
|
6
|
+
}) => {
|
|
7
|
+
try {
|
|
8
|
+
if (emptyBefore) {
|
|
9
|
+
toInsertLine = "\n".concat(toInsertLine);
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const content = readFile(inJsFilePath);
|
|
13
|
+
|
|
14
|
+
const lines = content.split("\n");
|
|
15
|
+
|
|
16
|
+
const updatedLines = lines.toSpliced(inInsertLineIndex - 1, 0, toInsertLine);
|
|
17
|
+
|
|
18
|
+
fs.writeFileSync(inJsFilePath, updatedLines.join("\n"));
|
|
19
|
+
|
|
20
|
+
} catch (error) {
|
|
21
|
+
return error;
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export default writeFile;
|
package/bin/v1/start.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
const checkUseDuplicate = ({ inSearchText, inFileContentAsStory }) => {
|
|
2
|
+
|
|
3
|
+
const found = inFileContentAsStory.find(element => {
|
|
4
|
+
return element.folderName === inSearchText;
|
|
5
|
+
});
|
|
6
|
+
|
|
7
|
+
return {
|
|
8
|
+
inserted: false,
|
|
9
|
+
found,
|
|
10
|
+
lineNumber: found ? found.lineNumber : null
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export default checkUseDuplicate;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import getFromStory from "./story.js";
|
|
2
|
+
import getFromSummary from "./modulat.js";
|
|
3
|
+
|
|
4
|
+
const findInsertIndex = ({ toInsertIndex,
|
|
5
|
+
inAllLinesStory, inSummary
|
|
6
|
+
}) => {
|
|
7
|
+
|
|
8
|
+
const storyIndex = getFromStory(inAllLinesStory);
|
|
9
|
+
|
|
10
|
+
if (storyIndex !== null) {
|
|
11
|
+
toInsertIndex = storyIndex;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const summaryIndex = getFromSummary(inSummary);
|
|
15
|
+
|
|
16
|
+
if (summaryIndex !== null) {
|
|
17
|
+
toInsertIndex = summaryIndex;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
return toInsertIndex;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export default findInsertIndex;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
const getFromSummary = (inSummary) => {
|
|
2
|
+
let index = null;
|
|
3
|
+
|
|
4
|
+
if (inSummary?.exportSummary) {
|
|
5
|
+
const minLine = inSummary?.exportSummary?.maxLineNumber;
|
|
6
|
+
if (minLine !== Infinity && minLine !== -Infinity) {
|
|
7
|
+
index = minLine + 1;
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
if (inSummary?.consumeSummary) {
|
|
12
|
+
const minLine = inSummary?.consumeSummary?.maxLineNumber;
|
|
13
|
+
if (minLine !== Infinity && minLine !== -Infinity) {
|
|
14
|
+
index = minLine + 1;
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
return index;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export default getFromSummary;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import getFromStory from "./story.js";
|
|
2
|
+
import getFromSummary from "./modulat.js";
|
|
3
|
+
|
|
4
|
+
const findInsertIndex = ({ toInsertIndex,
|
|
5
|
+
inAllLinesStory, inSummary, rulesJson
|
|
6
|
+
}) => {
|
|
7
|
+
|
|
8
|
+
const storyIndex = getFromStory(inAllLinesStory);
|
|
9
|
+
|
|
10
|
+
if (storyIndex !== null) {
|
|
11
|
+
toInsertIndex = storyIndex;
|
|
12
|
+
};
|
|
13
|
+
// console.log("aaaaaaaa-- : ", inKeyInSummary);
|
|
14
|
+
const summaryIndex = getFromSummary({
|
|
15
|
+
inSummary,
|
|
16
|
+
inToCheckKey: rulesJson?.toCheckKey,
|
|
17
|
+
inToCheckEmptyKey: rulesJson?.toCheckEmptyKey,
|
|
18
|
+
inConsiderTop: rulesJson?.considerTop,
|
|
19
|
+
inConsiderBottom: rulesJson?.considerBottom,
|
|
20
|
+
inToCheckEmpty2Key: rulesJson?.toCheckEmpty2Key
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
if (summaryIndex !== null) {
|
|
24
|
+
toInsertIndex = summaryIndex;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
return toInsertIndex;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export default findInsertIndex;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
const startFunc = ({ inSummary, inToCheckKey, inToCheckEmptyKey,
|
|
2
|
+
inConsiderTop, inConsiderBottom, inToCheckEmpty2Key
|
|
3
|
+
}) => {
|
|
4
|
+
|
|
5
|
+
let index = null;
|
|
6
|
+
let emptyBefore = false;
|
|
7
|
+
let emptyAfter = false;
|
|
8
|
+
|
|
9
|
+
const toCheckKey = inToCheckKey;
|
|
10
|
+
const toCheckEmptyKey = inToCheckEmptyKey;
|
|
11
|
+
const toCheckEmpty2Key = inToCheckEmpty2Key;
|
|
12
|
+
|
|
13
|
+
const considerTop = inConsiderTop;
|
|
14
|
+
const considerBottom = inConsiderBottom;
|
|
15
|
+
|
|
16
|
+
if (inSummary[toCheckKey]?.lineCount === 0) {
|
|
17
|
+
|
|
18
|
+
if (considerTop) {
|
|
19
|
+
if (inSummary.importFromNpmSummary?.lineCount === 0) {
|
|
20
|
+
index = 1;
|
|
21
|
+
} else {
|
|
22
|
+
emptyBefore = true;
|
|
23
|
+
index = inSummary.importFromNpmSummary?.maxLineNumber + 1;
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
if (considerBottom) {
|
|
28
|
+
if (inSummary[toCheckEmptyKey]?.lineCount === 0) {
|
|
29
|
+
if (inSummary[toCheckEmpty2Key]?.lineCount === 0) {
|
|
30
|
+
// index = inSummary[toCheckEmptyKey]?.minLineNumber;
|
|
31
|
+
index = 1;
|
|
32
|
+
} else {
|
|
33
|
+
emptyBefore = true;
|
|
34
|
+
index = inSummary[toCheckEmpty2Key]?.maxLineNumber + 1;
|
|
35
|
+
};
|
|
36
|
+
} else {
|
|
37
|
+
emptyAfter = true;
|
|
38
|
+
index = inSummary[toCheckEmptyKey]?.minLineNumber;
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
} else {
|
|
43
|
+
index = inSummary[toCheckKey]?.minLineNumber;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
return {
|
|
47
|
+
emptyBefore,
|
|
48
|
+
emptyAfter,
|
|
49
|
+
index
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export default startFunc;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import defaultAfter from "./defaultAfter/index.js";
|
|
2
|
+
import defaultBefore from "./defaultBefore/index.js";
|
|
3
|
+
|
|
4
|
+
const startFunc = ({
|
|
5
|
+
inAllLinesStory, rulesJson, inSummary
|
|
6
|
+
}) => {
|
|
7
|
+
let toInsertIndex = 3;
|
|
8
|
+
|
|
9
|
+
if (rulesJson.toInsertRule === "defaultAfter") toInsertIndex = defaultAfter({ toInsertIndex, inAllLinesStory, inSummary });
|
|
10
|
+
|
|
11
|
+
if (rulesJson.toInsertRule === "defaultBefore") toInsertIndex = defaultBefore({
|
|
12
|
+
toInsertIndex,
|
|
13
|
+
inAllLinesStory, inSummary, rulesJson
|
|
14
|
+
});
|
|
15
|
+
// console.log("aaaaaaaa--------- : ", toInsertIndex);
|
|
16
|
+
return toInsertIndex;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export default startFunc;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import getStory from "pattern-collector-anyjs";
|
|
2
|
+
|
|
3
|
+
import readFile from "../readFile.js";
|
|
4
|
+
import checkDuplicate from "./checkDuplicate.js";
|
|
5
|
+
import findInsertIndex from "./findInsertIndex/index.js";
|
|
6
|
+
import writeFile from "../writeFile.js";
|
|
7
|
+
import getLineStory from "./toInsertLineStory.js";
|
|
8
|
+
import atStart from "./showLogs/atStart.js";
|
|
9
|
+
import atEnd from "./showLogs/atEnd.js";
|
|
10
|
+
|
|
11
|
+
import packageJson from '../../../../../package.json' with {type: 'json'};
|
|
12
|
+
|
|
13
|
+
const alterFile = ({
|
|
14
|
+
jsFilePath, rulesJson, extractRegex,
|
|
15
|
+
showLog = false, showLogStep1, showLogStep2, showLogStep3
|
|
16
|
+
}) => {
|
|
17
|
+
|
|
18
|
+
atStart({ jsFilePath, rulesJson, packageJson, showLog, searchRegex: extractRegex });
|
|
19
|
+
|
|
20
|
+
const toInsertLine = rulesJson.toInsertLine;
|
|
21
|
+
|
|
22
|
+
const content = readFile(jsFilePath);
|
|
23
|
+
|
|
24
|
+
// "keyNeeded": "importRegex.parseRegex"
|
|
25
|
+
|
|
26
|
+
const lineStory = getLineStory({
|
|
27
|
+
toInsertLine, parseRegex: extractRegex[rulesJson?.regexNeeded],
|
|
28
|
+
showLog
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
if (showLog?.withValues) console.log(`${packageJson.name}-lineStory : `, lineStory);
|
|
32
|
+
|
|
33
|
+
const fromPatternCollector = getStory({
|
|
34
|
+
fileContent: content,
|
|
35
|
+
extractRegex,
|
|
36
|
+
showLog: showLogStep1,
|
|
37
|
+
showLogStep1: showLogStep2, showLogStep2: showLogStep3
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
// console.log(`-fromPatternCollector : `, fromPatternCollector.importLines);
|
|
41
|
+
|
|
42
|
+
if (showLog?.withValues) console.log(`${packageJson.name}------------ : `, fromPatternCollector);
|
|
43
|
+
|
|
44
|
+
const duplicateInfo = checkDuplicate({
|
|
45
|
+
inSearchText: lineStory.raka,
|
|
46
|
+
inFileContentAsStory: fromPatternCollector[rulesJson?.toCheckLinesName]
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
if (duplicateInfo.found) {
|
|
50
|
+
if (showLog) {
|
|
51
|
+
console.log(
|
|
52
|
+
`Duplicate found at line ${duplicateInfo.lineNumber}`
|
|
53
|
+
);
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
return duplicateInfo;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
const toInsertIndex = findInsertIndex({
|
|
60
|
+
inAllLinesStory: fromPatternCollector.allLinesStory,
|
|
61
|
+
inSummary: fromPatternCollector?.summary,
|
|
62
|
+
rulesJson: rulesJson?.aboutInsertIndex
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
writeFile({
|
|
66
|
+
inJsFilePath: jsFilePath,
|
|
67
|
+
inInsertLineIndex: toInsertIndex.index,
|
|
68
|
+
toInsertLine, emptyBefore: toInsertIndex.emptyBefore,
|
|
69
|
+
emptyAfter: toInsertIndex.emptyAfter
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
atEnd({ duplicateInfo, packageJson, showLog });
|
|
73
|
+
|
|
74
|
+
return {
|
|
75
|
+
inserted: true,
|
|
76
|
+
found: false,
|
|
77
|
+
filePath: jsFilePath,
|
|
78
|
+
lineNumber: null
|
|
79
|
+
};
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
export default alterFile;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
const startFunc = ({
|
|
2
|
+
duplicateInfo, packageJson, showLog
|
|
3
|
+
}) => {
|
|
4
|
+
|
|
5
|
+
if (showLog?.keysOnly) console.log(`${packageJson.name}-end`);
|
|
6
|
+
if (showLog?.withValues) console.log(`${packageJson.name}-outputs : `, duplicateInfo);
|
|
7
|
+
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export default startFunc;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
const startFunc = ({
|
|
2
|
+
jsFilePath, rulesJson, packageJson, showLog, searchRegex
|
|
3
|
+
}) => {
|
|
4
|
+
|
|
5
|
+
if (showLog?.keysOnly) console.log(`${packageJson.name}-start`);
|
|
6
|
+
|
|
7
|
+
if (showLog?.withValues) console.log(`${packageJson.name}-inputs-jsFilePath : `, jsFilePath);
|
|
8
|
+
if (showLog?.withValues) console.log(`${packageJson.name}-inputs-rulesJson : `, JSON.stringify(rulesJson));
|
|
9
|
+
if (showLog?.withValues) console.log(`${packageJson.name}-inputs-searchRegex : `, JSON.stringify(searchRegex));
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export default startFunc;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import baseRegex from "pattern-collector-base-regex";
|
|
2
|
+
|
|
3
|
+
const startFunc = ({ toInsertLine, parseRegex, showLog = false }) => {
|
|
4
|
+
|
|
5
|
+
if (showLog) console.log("toInsertLineStory-inputs : ", parseRegex, toInsertLine);
|
|
6
|
+
|
|
7
|
+
const fromPatternCollector = baseRegex({
|
|
8
|
+
matchLine: toInsertLine,
|
|
9
|
+
parseRegex, showLog
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
if (showLog) console.log("toInsertLineStory-outputs : ", fromPatternCollector);
|
|
13
|
+
|
|
14
|
+
return fromPatternCollector;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export default startFunc;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import readFile from "./readFile.js";
|
|
3
|
+
|
|
4
|
+
const writeFile = ({ inJsFilePath, inInsertLineIndex, toInsertLine,
|
|
5
|
+
emptyBefore = false, emptyAfter = false
|
|
6
|
+
}) => {
|
|
7
|
+
try {
|
|
8
|
+
if (emptyBefore) {
|
|
9
|
+
toInsertLine = "\n".concat(toInsertLine);
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
if (emptyAfter) {
|
|
13
|
+
toInsertLine = toInsertLine.concat("\n");
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const content = readFile(inJsFilePath);
|
|
17
|
+
|
|
18
|
+
const lines = content.split("\n");
|
|
19
|
+
|
|
20
|
+
const updatedLines = lines.toSpliced(inInsertLineIndex - 1, 0, toInsertLine);
|
|
21
|
+
|
|
22
|
+
fs.writeFileSync(inJsFilePath, updatedLines.join("\n"));
|
|
23
|
+
|
|
24
|
+
} catch (error) {
|
|
25
|
+
return error;
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export default writeFile;
|
package/bin/v2/start.js
ADDED
package/index.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { createRequire } from "module";
|
|
2
|
+
import getLatestVersion from "./bin/core/getLatestVersion.js";
|
|
3
|
+
|
|
4
|
+
const require = createRequire(import.meta.url);
|
|
5
|
+
|
|
6
|
+
const load = (options) => {
|
|
7
|
+
const v = getLatestVersion();
|
|
8
|
+
|
|
9
|
+
const mod = require(`./bin/${v}/start.js`);
|
|
10
|
+
|
|
11
|
+
return mod.default(options);
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export default load;
|
package/package.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "express-fix-any-js-from-base",
|
|
3
|
+
"version": "1.2.5",
|
|
4
|
+
"description": "CLI to build for appjs, the endpoints",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"cli",
|
|
7
|
+
"scaffold",
|
|
8
|
+
"templates",
|
|
9
|
+
"node",
|
|
10
|
+
"project-generator"
|
|
11
|
+
],
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"pattern-collector-anyjs": "^1.8.2",
|
|
14
|
+
"pattern-collector-base-regex": "^1.3.2"
|
|
15
|
+
},
|
|
16
|
+
"type": "module",
|
|
17
|
+
"exports": {
|
|
18
|
+
".": "./index.js"
|
|
19
|
+
},
|
|
20
|
+
"bin": {
|
|
21
|
+
"express-fix-any-js-from-base": "./bin/cli.js"
|
|
22
|
+
},
|
|
23
|
+
"files": [
|
|
24
|
+
"bin/",
|
|
25
|
+
"index.js",
|
|
26
|
+
"README.md",
|
|
27
|
+
"LICENSE"
|
|
28
|
+
],
|
|
29
|
+
"homepage": "https://cli.keshavsoft.com",
|
|
30
|
+
"repository": {
|
|
31
|
+
"type": "git",
|
|
32
|
+
"url": "https://github.com/keshavsoft/express-fix-any-js-from-base"
|
|
33
|
+
},
|
|
34
|
+
"bugs": {
|
|
35
|
+
"url": "https://github.com/keshavsoft/express-fix-any-js-from-base/issues"
|
|
36
|
+
}
|
|
37
|
+
}
|