express-fix-any-js 1.4.2 → 1.7.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/README.md +77 -38
- package/bin/{v4 → v6}/UpdateJs/common/AlterFile/buildUpdatedContent.js +8 -0
- package/bin/v6/UpdateJs/common/AlterFile/checkDuplicate.js +14 -0
- package/bin/{v3 → v6}/UpdateJs/index.js +4 -5
- package/bin/v6/UpdateJs/validateCheckLines.js +31 -0
- package/bin/{v3 → v7}/UpdateJs/common/AlterFile/buildUpdatedContent.js +8 -0
- package/bin/v7/UpdateJs/common/AlterFile/checkDuplicate.js +14 -0
- package/bin/{v3 → v7}/UpdateJs/common/AlterFile/index.js +6 -1
- package/bin/v7/UpdateJs/index.js +30 -0
- package/bin/v7/UpdateJs/validateCheckLines.js +31 -0
- package/bin/{v4 → v7}/start.js +1 -1
- package/index.js +14 -4
- package/package.json +4 -2
- package/bin/v3/UpdateJs/checkLines.json +0 -18
- package/bin/v3/UpdateJs/common/AlterFile/checkDuplicate.js +0 -21
- package/bin/v3/core/createFolder.js +0 -34
- package/bin/v4/UpdateJs/checkLines.json +0 -18
- package/bin/v4/UpdateJs/common/AlterFile/checkDuplicate.js +0 -21
- package/bin/v4/UpdateJs/index.js +0 -56
- /package/bin/{v3 → v6}/UpdateJs/common/AlterFile/findInsertIndex.js +0 -0
- /package/bin/{v4 → v6}/UpdateJs/common/AlterFile/index.js +0 -0
- /package/bin/{v3 → v6}/UpdateJs/common/readFile.js +0 -0
- /package/bin/{v3 → v6}/UpdateJs/common/writeFile.js +0 -0
- /package/bin/{v3 → v6}/core/parseInput.js +0 -0
- /package/bin/{v3 → v6}/core/showUsage.js +0 -0
- /package/bin/{v3 → v6}/start.js +0 -0
- /package/bin/{v4 → v7}/UpdateJs/common/AlterFile/findInsertIndex.js +0 -0
- /package/bin/{v4 → v7}/UpdateJs/common/readFile.js +0 -0
- /package/bin/{v4 → v7}/UpdateJs/common/writeFile.js +0 -0
- /package/bin/{v4 → v7}/core/parseInput.js +0 -0
- /package/bin/{v4 → v7}/core/showUsage.js +0 -0
package/README.md
CHANGED
|
@@ -1,50 +1,91 @@
|
|
|
1
|
-
#
|
|
1
|
+
# express-fix-any-js 🚀
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
started git actions also to https://github.com/keshavsoft/express-fix-endpoints-get-js,
|
|
5
|
-
also started actions
|
|
3
|
+
> **Instantly repair, structure, and align Express.js routing files with automated idempotency & formatting safeguards.**
|
|
6
4
|
|
|
7
|
-
|
|
5
|
+
[](https://www.npmjs.com/package/express-fix-any-js)
|
|
6
|
+
[](LICENSE)
|
|
7
|
+
[](https://github.com/keshavsoft/express-fix-any-js/actions)
|
|
8
8
|
|
|
9
|
-
|
|
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.
|
|
10
14
|
|
|
11
|
-
|
|
12
|
-
* Preventing duplicate routes
|
|
13
|
-
* Preserving route order
|
|
14
|
-
* Maintaining consistent formatting
|
|
15
|
+
This module acts as the foundation layer for the **KeshavSoft API Generation Suite**, dynamically structuring routes generated via CLI or VS Code extensions.
|
|
15
16
|
|
|
16
17
|
---
|
|
17
18
|
|
|
18
|
-
##
|
|
19
|
+
## ✨ Features
|
|
19
20
|
|
|
20
|
-
|
|
21
|
-
|
|
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.
|
|
22
28
|
|
|
23
|
-
|
|
29
|
+
---
|
|
24
30
|
|
|
25
|
-
|
|
31
|
+
## 📁 Repository Integration Map
|
|
26
32
|
|
|
27
|
-
|
|
28
|
-
AlterFunc({ req, res, inTablePath: tablePath })
|
|
29
|
-
);
|
|
33
|
+
`express-fix-any-js` is part of a larger cascading developer ecosystem:
|
|
30
34
|
|
|
31
|
-
|
|
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
|
|
32
48
|
```
|
|
33
49
|
|
|
34
50
|
---
|
|
35
51
|
|
|
36
|
-
##
|
|
52
|
+
## 🚀 Quick Start
|
|
37
53
|
|
|
38
|
-
###
|
|
54
|
+
### Installation
|
|
39
55
|
|
|
40
|
-
|
|
56
|
+
```bash
|
|
57
|
+
npm install express-fix-any-js
|
|
58
|
+
```
|
|
41
59
|
|
|
42
|
-
|
|
43
|
-
* Add one blank line before `export { router };`
|
|
60
|
+
### Programmatic Usage
|
|
44
61
|
|
|
45
|
-
|
|
62
|
+
You can use the core `alterFile` function to modify local routes files safely:
|
|
46
63
|
|
|
47
|
-
```
|
|
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
|
|
48
89
|
const router = express.Router();
|
|
49
90
|
|
|
50
91
|
router.post("/Alter", express.json(), handler);
|
|
@@ -52,28 +93,26 @@ router.post("/Alter", express.json(), handler);
|
|
|
52
93
|
export { router };
|
|
53
94
|
```
|
|
54
95
|
|
|
55
|
-
###
|
|
56
|
-
|
|
57
|
-
New routes are always appended after the last route.
|
|
96
|
+
### 2. Multi-Route Appending
|
|
97
|
+
Subsequent routes are appended directly after the last matching route with no empty line spacing between them:
|
|
58
98
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
```js
|
|
99
|
+
```javascript
|
|
62
100
|
router.post("/Alter", express.json(), handler);
|
|
63
101
|
router.post("/Alter1", express.json(), handler);
|
|
64
102
|
router.post("/Alter2", express.json(), handler);
|
|
65
103
|
```
|
|
66
104
|
|
|
67
|
-
No blank lines are inserted between routes.
|
|
68
|
-
|
|
69
105
|
---
|
|
70
106
|
|
|
71
|
-
##
|
|
107
|
+
## 🛠️ Developer & API Reference
|
|
72
108
|
|
|
73
|
-
|
|
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)
|
|
74
113
|
|
|
75
114
|
---
|
|
76
115
|
|
|
77
|
-
##
|
|
116
|
+
## ⚖️ License
|
|
78
117
|
|
|
79
|
-
|
|
118
|
+
MIT License. Designed with ❤️ by [KeshavSoft](https://github.com/keshavsoft).
|
|
@@ -9,6 +9,14 @@ const startFunc = ({
|
|
|
9
9
|
const isFirstInsert =
|
|
10
10
|
insertInfo.matchedPattern === insertAfter[insertAfter.length - 1];
|
|
11
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
|
+
|
|
12
20
|
return before +
|
|
13
21
|
(isFirstInsert ? "\n" : "") +
|
|
14
22
|
toInsertLine +
|
|
@@ -0,0 +1,14 @@
|
|
|
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,13 +1,12 @@
|
|
|
1
|
-
// v2/AppJs/index.js
|
|
2
|
-
|
|
3
|
-
import checkLines from "./checkLines.json" with {type: "json"};
|
|
4
1
|
import alterFile from "./common/AlterFile/index.js";
|
|
2
|
+
import validateCheckLines from "./validateCheckLines.js";
|
|
5
3
|
|
|
6
4
|
const updateAppJs = ({ inJsFilePath, inCheckLines,
|
|
7
5
|
showLog = false }) => {
|
|
8
6
|
|
|
9
|
-
const localCheckLines = inCheckLines
|
|
10
|
-
|
|
7
|
+
const localCheckLines = inCheckLines;
|
|
8
|
+
|
|
9
|
+
validateCheckLines(localCheckLines);
|
|
11
10
|
|
|
12
11
|
alterFile({
|
|
13
12
|
jsFilePath: inJsFilePath,
|
|
@@ -0,0 +1,31 @@
|
|
|
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;
|
|
@@ -9,6 +9,14 @@ const startFunc = ({
|
|
|
9
9
|
const isFirstInsert =
|
|
10
10
|
insertInfo.matchedPattern === insertAfter[insertAfter.length - 1];
|
|
11
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
|
+
|
|
12
20
|
return before +
|
|
13
21
|
(isFirstInsert ? "\n" : "") +
|
|
14
22
|
toInsertLine +
|
|
@@ -0,0 +1,14 @@
|
|
|
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;
|
|
@@ -37,7 +37,6 @@ const alterFile = ({
|
|
|
37
37
|
return duplicateInfo;
|
|
38
38
|
};
|
|
39
39
|
|
|
40
|
-
// const index = locateInsertPoint({ content, importInsertAfter });
|
|
41
40
|
const insertInfo = locateInsertPoint({
|
|
42
41
|
content,
|
|
43
42
|
insertAfter
|
|
@@ -51,6 +50,12 @@ const alterFile = ({
|
|
|
51
50
|
});
|
|
52
51
|
|
|
53
52
|
writeFile(jsFilePath, updated);
|
|
53
|
+
|
|
54
|
+
return {
|
|
55
|
+
found: false,
|
|
56
|
+
filePath: jsFilePath,
|
|
57
|
+
lineNumber: null
|
|
58
|
+
};
|
|
54
59
|
};
|
|
55
60
|
|
|
56
61
|
export default alterFile;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import alterFile from "./common/AlterFile/index.js";
|
|
2
|
+
import validateCheckLines from "./validateCheckLines.js";
|
|
3
|
+
|
|
4
|
+
const updateAppJs = ({ inJsFilePath, inCheckLines,
|
|
5
|
+
showLog = false }) => {
|
|
6
|
+
|
|
7
|
+
const localCheckLines = inCheckLines;
|
|
8
|
+
|
|
9
|
+
validateCheckLines(localCheckLines);
|
|
10
|
+
|
|
11
|
+
const importResult = alterFile({
|
|
12
|
+
jsFilePath: inJsFilePath,
|
|
13
|
+
toInsertLine: localCheckLines.importLines.toInsertLine,
|
|
14
|
+
duplicationCheck: localCheckLines.importLines.duplicationCheck,
|
|
15
|
+
insertAfter: localCheckLines.importLines.insertAfter,
|
|
16
|
+
showLog
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
const useResult = alterFile({
|
|
20
|
+
jsFilePath: inJsFilePath,
|
|
21
|
+
toInsertLine: localCheckLines.useLines.toInsertLine,
|
|
22
|
+
duplicationCheck: localCheckLines.useLines.duplicationCheck,
|
|
23
|
+
insertAfter: localCheckLines.useLines.insertAfter,
|
|
24
|
+
showLog
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
return { importResult, useResult };
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export default updateAppJs;
|
|
@@ -0,0 +1,31 @@
|
|
|
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;
|
package/bin/{v4 → v7}/start.js
RENAMED
package/index.js
CHANGED
|
@@ -1,11 +1,21 @@
|
|
|
1
1
|
import getLatestVersion from "./bin/core/getLatestVersion.js";
|
|
2
|
+
import startV6 from "./bin/v6/start.js";
|
|
3
|
+
import startV7 from "./bin/v7/start.js";
|
|
2
4
|
|
|
3
|
-
const
|
|
5
|
+
const runners = {
|
|
6
|
+
v6: startV6,
|
|
7
|
+
v7: startV7
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
const load = ({ jsFilePath, inCheckLines, showLog }) => {
|
|
4
11
|
const v = getLatestVersion();
|
|
12
|
+
const runner = runners[v];
|
|
5
13
|
|
|
6
|
-
|
|
14
|
+
if (!runner) {
|
|
15
|
+
throw new Error(`Unsupported version: ${v}`);
|
|
16
|
+
}
|
|
7
17
|
|
|
8
|
-
|
|
18
|
+
return runner({ jsFilePath, inCheckLines, showLog });
|
|
9
19
|
};
|
|
10
20
|
|
|
11
|
-
export default load;
|
|
21
|
+
export default load;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "express-fix-any-js",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.7.2",
|
|
4
4
|
"description": "CLI to build for appjs, the endpoints",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cli",
|
|
@@ -9,7 +9,9 @@
|
|
|
9
9
|
"node",
|
|
10
10
|
"project-generator"
|
|
11
11
|
],
|
|
12
|
-
"dependencies": {
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"express-check-any-for-import": "file:../ks1/express-check-any-for-import"
|
|
14
|
+
},
|
|
13
15
|
"type": "module",
|
|
14
16
|
"exports": {
|
|
15
17
|
".": "./index.js"
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"importLines": {
|
|
3
|
-
"toInsertLine": "import funcFrom${endpoint} from './${endpoint}/controller.js';",
|
|
4
|
-
"duplicationCheck": "from './${endpoint}/controller.js'",
|
|
5
|
-
"insertAfter": [
|
|
6
|
-
"import funcFrom",
|
|
7
|
-
"import express"
|
|
8
|
-
]
|
|
9
|
-
},
|
|
10
|
-
"useLines": {
|
|
11
|
-
"toInsertLine": "router.post('/${endpoint}', express.json(), (req, res) => funcFrom${endpoint}({ req, res, inTablePath: tablePath }));",
|
|
12
|
-
"duplicationCheck": "router.use('/${endpoint}'",
|
|
13
|
-
"insertAfter": [
|
|
14
|
-
"router.",
|
|
15
|
-
"const router = "
|
|
16
|
-
]
|
|
17
|
-
}
|
|
18
|
-
}
|
|
@@ -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,34 +0,0 @@
|
|
|
1
|
-
import fs from "fs";
|
|
2
|
-
|
|
3
|
-
export const createFolder = ({ source, destination, checkBeforeCreate = false, isAnnounce = true }) => {
|
|
4
|
-
if (checkBeforeCreate) {
|
|
5
|
-
return createFolderWithCheck({ source, destination, isAnnounce });
|
|
6
|
-
} else {
|
|
7
|
-
return createOnly({ source, destination });
|
|
8
|
-
};
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
const createOnly = ({ source, destination }) => {
|
|
12
|
-
fs.mkdirSync(destination, { recursive: true });
|
|
13
|
-
|
|
14
|
-
fs.cpSync(source, destination, { recursive: true });
|
|
15
|
-
|
|
16
|
-
return {
|
|
17
|
-
KTF: true
|
|
18
|
-
};
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
const createFolderWithCheck = ({ source, destination, isAnnounce }) => {
|
|
22
|
-
if (fs.existsSync(destination)) {
|
|
23
|
-
if (isAnnounce) console.log("Folder already exists :", destination);
|
|
24
|
-
|
|
25
|
-
return {
|
|
26
|
-
KTF: false,
|
|
27
|
-
KReason: "Folder already exists"
|
|
28
|
-
};
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
if (isAnnounce) console.log("Folder created :", destination);
|
|
32
|
-
|
|
33
|
-
return createOnly({ source, destination });
|
|
34
|
-
};
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"importLines": {
|
|
3
|
-
"toInsertLine": "import funcFrom${endpoint} from './${endpoint}/controller.js';",
|
|
4
|
-
"duplicationCheck": "from './${endpoint}/controller.js'",
|
|
5
|
-
"insertAfter": [
|
|
6
|
-
"import funcFrom",
|
|
7
|
-
"import express"
|
|
8
|
-
]
|
|
9
|
-
},
|
|
10
|
-
"useLines": {
|
|
11
|
-
"toInsertLine": "router.post('/${endpoint}', express.json(), (req, res) => funcFrom${endpoint}({ req, res, inTablePath: tablePath }));",
|
|
12
|
-
"duplicationCheck": "router.use('/${endpoint}'",
|
|
13
|
-
"insertAfter": [
|
|
14
|
-
"router.",
|
|
15
|
-
"const router = "
|
|
16
|
-
]
|
|
17
|
-
}
|
|
18
|
-
}
|
|
@@ -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;
|
package/bin/v4/UpdateJs/index.js
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
// v2/AppJs/index.js
|
|
2
|
-
|
|
3
|
-
import checkLines from "./checkLines.json" with {type: "json"};
|
|
4
|
-
import alterFile from "./common/AlterFile/index.js";
|
|
5
|
-
|
|
6
|
-
const validateCheckLines = (obj) => {
|
|
7
|
-
if (typeof obj !== "object" || obj === null || Array.isArray(obj)) {
|
|
8
|
-
throw new TypeError("inCheckLines must be a valid object.");
|
|
9
|
-
}
|
|
10
|
-
for (const key of ["importLines", "useLines"]) {
|
|
11
|
-
if (!(key in obj)) {
|
|
12
|
-
throw new Error(`inCheckLines must contain "${key}".`);
|
|
13
|
-
}
|
|
14
|
-
const section = obj[key];
|
|
15
|
-
if (typeof section !== "object" || section === null || Array.isArray(section)) {
|
|
16
|
-
throw new TypeError(`inCheckLines.${key} must be an object.`);
|
|
17
|
-
}
|
|
18
|
-
if (typeof section.toInsertLine !== "string") {
|
|
19
|
-
throw new TypeError(`inCheckLines.${key}.toInsertLine must be a string.`);
|
|
20
|
-
}
|
|
21
|
-
if (typeof section.duplicationCheck !== "string") {
|
|
22
|
-
throw new TypeError(`inCheckLines.${key}.duplicationCheck must be a string.`);
|
|
23
|
-
}
|
|
24
|
-
if (!Array.isArray(section.insertAfter)) {
|
|
25
|
-
throw new TypeError(`inCheckLines.${key}.insertAfter must be an array.`);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
const updateAppJs = ({ inJsFilePath, inCheckLines,
|
|
31
|
-
showLog = false }) => {
|
|
32
|
-
|
|
33
|
-
const localCheckLines = (inCheckLines && Object.keys(inCheckLines).length > 0) ? inCheckLines : checkLines;
|
|
34
|
-
|
|
35
|
-
validateCheckLines(localCheckLines);
|
|
36
|
-
|
|
37
|
-
alterFile({
|
|
38
|
-
jsFilePath: inJsFilePath,
|
|
39
|
-
toInsertLine: localCheckLines.importLines.toInsertLine,
|
|
40
|
-
duplicationCheck: localCheckLines.importLines.duplicationCheck,
|
|
41
|
-
insertAfter: localCheckLines.importLines.insertAfter,
|
|
42
|
-
showLog
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
alterFile({
|
|
46
|
-
jsFilePath: inJsFilePath,
|
|
47
|
-
toInsertLine: localCheckLines.useLines.toInsertLine,
|
|
48
|
-
duplicationCheck: localCheckLines.useLines.duplicationCheck,
|
|
49
|
-
insertAfter: localCheckLines.useLines.insertAfter,
|
|
50
|
-
showLog
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
return false;
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
export default updateAppJs;
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
/package/bin/{v3 → v6}/start.js
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|