express-fix-any-js 1.11.2 → 1.11.4
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/package.json +1 -1
- package/bin/v11/UpdateJs/common/AlterFileForConsume/buildUpdatedContent.js +0 -28
- package/bin/v11/UpdateJs/common/AlterFileForConsume/checkDuplicate.js +0 -21
- package/bin/v11/UpdateJs/common/AlterFileForConsume/findInsertIndex.js +0 -30
- package/bin/v11/UpdateJs/common/AlterFileForConsume/index.js +0 -61
- package/bin/v11/UpdateJs/common/AlterFileForImport/buildUpdatedContent copy.js +0 -27
- package/bin/v11/UpdateJs/common/AlterFileForImport/buildUpdatedContent.js +0 -41
- package/bin/v11/UpdateJs/common/AlterFileForImport/checkDuplicate.js +0 -14
- package/bin/v11/UpdateJs/common/AlterFileForImport/findInsertIndex.js +0 -30
- package/bin/v11/UpdateJs/common/AlterFileForImport/index.js +0 -61
- package/bin/v11/UpdateJs/common/readFile.js +0 -8
- package/bin/v11/UpdateJs/common/writeFile.js +0 -10
- package/bin/v11/UpdateJs/index copy.js +0 -33
- package/bin/v11/UpdateJs/validateCheckLines.js +0 -31
package/package.json
CHANGED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
const startFunc = ({
|
|
2
|
-
content,
|
|
3
|
-
insertInfo,
|
|
4
|
-
toInsertLine,
|
|
5
|
-
insertAfter
|
|
6
|
-
}) => {
|
|
7
|
-
const index = insertInfo.index === -1 ? content.length : insertInfo.index;
|
|
8
|
-
const before = content.slice(0, index);
|
|
9
|
-
|
|
10
|
-
const isFirstInsert =
|
|
11
|
-
insertInfo.matchedPattern === insertAfter[insertAfter.length - 1];
|
|
12
|
-
|
|
13
|
-
if (Array.isArray(toInsertLine)) {
|
|
14
|
-
return before +
|
|
15
|
-
(isFirstInsert ? "\n" : "") +
|
|
16
|
-
toInsertLine.join("\n") +
|
|
17
|
-
"\n" +
|
|
18
|
-
content.slice(index);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
return before +
|
|
22
|
-
(isFirstInsert ? "\n" : "") +
|
|
23
|
-
toInsertLine +
|
|
24
|
-
"\n" +
|
|
25
|
-
content.slice(index);
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
export default startFunc;
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
const checkUseDuplicate = ({
|
|
2
|
-
inContent,
|
|
3
|
-
inFilePath,
|
|
4
|
-
inSearchText
|
|
5
|
-
}) => {
|
|
6
|
-
const lines = inContent.split("\n");
|
|
7
|
-
|
|
8
|
-
const lineIndex = lines.findIndex(line =>
|
|
9
|
-
line.includes(inSearchText)
|
|
10
|
-
);
|
|
11
|
-
|
|
12
|
-
return {
|
|
13
|
-
found: lineIndex !== -1,
|
|
14
|
-
filePath: inFilePath,
|
|
15
|
-
lineNumber: lineIndex !== -1
|
|
16
|
-
? lineIndex + 1
|
|
17
|
-
: null
|
|
18
|
-
};
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
export default checkUseDuplicate;
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
const findInsertIndex = ({
|
|
2
|
-
inContent,
|
|
3
|
-
inPatterns = []
|
|
4
|
-
}) => {
|
|
5
|
-
const lines = inContent.split("\n");
|
|
6
|
-
|
|
7
|
-
let lineNumber = -1;
|
|
8
|
-
let matchedPattern = null;
|
|
9
|
-
|
|
10
|
-
lines.forEach((line, index) => {
|
|
11
|
-
const pattern = inPatterns.find(item => line.includes(item));
|
|
12
|
-
|
|
13
|
-
if (pattern) {
|
|
14
|
-
lineNumber = index;
|
|
15
|
-
matchedPattern = pattern;
|
|
16
|
-
};
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
return {
|
|
20
|
-
index: lineNumber === -1
|
|
21
|
-
? -1
|
|
22
|
-
: lines
|
|
23
|
-
.slice(0, lineNumber + 1)
|
|
24
|
-
.join("\n")
|
|
25
|
-
.length + 1,
|
|
26
|
-
matchedPattern
|
|
27
|
-
};
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
export default findInsertIndex;
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import readFile from "../readFile.js";
|
|
2
|
-
import checkDuplicate from "./checkDuplicate.js";
|
|
3
|
-
import findInsertIndex from "./findInsertIndex.js";
|
|
4
|
-
import writeFile from "../writeFile.js";
|
|
5
|
-
|
|
6
|
-
import buildUpdatedContent from "./buildUpdatedContent.js";
|
|
7
|
-
|
|
8
|
-
const locateInsertPoint = ({ content, insertAfter }) => {
|
|
9
|
-
return findInsertIndex({
|
|
10
|
-
inContent: content,
|
|
11
|
-
inPatterns: insertAfter
|
|
12
|
-
});
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
const alterFile = ({
|
|
16
|
-
jsFilePath,
|
|
17
|
-
toInsertLine,
|
|
18
|
-
duplicationCheck,
|
|
19
|
-
insertAfter = [],
|
|
20
|
-
showLog = false
|
|
21
|
-
}) => {
|
|
22
|
-
const content = readFile(jsFilePath);
|
|
23
|
-
|
|
24
|
-
const duplicateInfo = checkDuplicate({
|
|
25
|
-
inContent: content,
|
|
26
|
-
inFilePath: jsFilePath,
|
|
27
|
-
inSearchText: duplicationCheck
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
if (duplicateInfo.found) {
|
|
31
|
-
if (showLog) {
|
|
32
|
-
console.log(
|
|
33
|
-
`Duplicate found at line ${duplicateInfo.lineNumber}`
|
|
34
|
-
);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
return duplicateInfo;
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
const insertInfo = locateInsertPoint({
|
|
41
|
-
content,
|
|
42
|
-
insertAfter
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
const updated = buildUpdatedContent({
|
|
46
|
-
content,
|
|
47
|
-
insertInfo,
|
|
48
|
-
toInsertLine,
|
|
49
|
-
insertAfter
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
writeFile(jsFilePath, updated);
|
|
53
|
-
|
|
54
|
-
return {
|
|
55
|
-
found: false,
|
|
56
|
-
filePath: jsFilePath,
|
|
57
|
-
lineNumber: null
|
|
58
|
-
};
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
export default alterFile;
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
const startFunc = ({
|
|
2
|
-
content,
|
|
3
|
-
insertInfo,
|
|
4
|
-
toInsertLine,
|
|
5
|
-
insertAfter
|
|
6
|
-
}) => {
|
|
7
|
-
const before = content.slice(0, insertInfo.index);
|
|
8
|
-
|
|
9
|
-
const isFirstInsert =
|
|
10
|
-
insertInfo.matchedPattern === insertAfter[insertAfter.length - 1];
|
|
11
|
-
|
|
12
|
-
if (Array.isArray(toInsertLine)) {
|
|
13
|
-
return before +
|
|
14
|
-
(isFirstInsert ? "\n" : "") +
|
|
15
|
-
toInsertLine.join("\n") +
|
|
16
|
-
"\n" +
|
|
17
|
-
content.slice(insertInfo.index);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
return before +
|
|
21
|
-
(isFirstInsert ? "\n" : "") +
|
|
22
|
-
toInsertLine +
|
|
23
|
-
"\n" +
|
|
24
|
-
content.slice(insertInfo.index);
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
export default startFunc;
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
const startFunc = ({
|
|
2
|
-
content,
|
|
3
|
-
insertInfo,
|
|
4
|
-
toInsertLine,
|
|
5
|
-
insertAfter
|
|
6
|
-
}) => {
|
|
7
|
-
|
|
8
|
-
// let before;
|
|
9
|
-
|
|
10
|
-
// if (insertInfo.index === -1) {
|
|
11
|
-
// before = 0;
|
|
12
|
-
|
|
13
|
-
// } else {
|
|
14
|
-
|
|
15
|
-
// before = content.slice(0, insertInfo.index);
|
|
16
|
-
|
|
17
|
-
// };
|
|
18
|
-
// const before = content.slice(0, insertInfo.index);
|
|
19
|
-
|
|
20
|
-
const index = insertInfo.index === -1 ? 0 : insertInfo.index;
|
|
21
|
-
const before = content.slice(0, index);
|
|
22
|
-
|
|
23
|
-
const isFirstInsert =
|
|
24
|
-
insertInfo.matchedPattern === insertAfter[insertAfter.length - 1];
|
|
25
|
-
|
|
26
|
-
if (Array.isArray(toInsertLine)) {
|
|
27
|
-
return before +
|
|
28
|
-
(isFirstInsert ? "\n" : "") +
|
|
29
|
-
toInsertLine.join("\n") +
|
|
30
|
-
"\n" +
|
|
31
|
-
content.slice(index);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
return before +
|
|
35
|
-
(isFirstInsert ? "\n" : "") +
|
|
36
|
-
toInsertLine +
|
|
37
|
-
"\n" +
|
|
38
|
-
content.slice(index);
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
export default startFunc;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { isImportPresent } from "express-check-any-for-import";
|
|
2
|
-
|
|
3
|
-
const checkUseDuplicate = ({ inContent, inFilePath, inSearchText }) => {
|
|
4
|
-
const cleanText = inSearchText.match(/['"]([^'"]+)['"]/)?.[1] || inSearchText;
|
|
5
|
-
const found = isImportPresent(inContent, cleanText) || inContent.includes(inSearchText);
|
|
6
|
-
|
|
7
|
-
return {
|
|
8
|
-
found,
|
|
9
|
-
filePath: inFilePath,
|
|
10
|
-
lineNumber: found ? inContent.split("\n").findIndex(line => line.includes(cleanText)) + 1 : null
|
|
11
|
-
};
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
export default checkUseDuplicate;
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
const findInsertIndex = ({
|
|
2
|
-
inContent,
|
|
3
|
-
inPatterns = []
|
|
4
|
-
}) => {
|
|
5
|
-
const lines = inContent.split("\n");
|
|
6
|
-
|
|
7
|
-
let lineNumber = -1;
|
|
8
|
-
let matchedPattern = null;
|
|
9
|
-
|
|
10
|
-
lines.forEach((line, index) => {
|
|
11
|
-
const pattern = inPatterns.find(item => line.includes(item));
|
|
12
|
-
|
|
13
|
-
if (pattern) {
|
|
14
|
-
lineNumber = index;
|
|
15
|
-
matchedPattern = pattern;
|
|
16
|
-
};
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
return {
|
|
20
|
-
index: lineNumber === -1
|
|
21
|
-
? -1
|
|
22
|
-
: lines
|
|
23
|
-
.slice(0, lineNumber + 1)
|
|
24
|
-
.join("\n")
|
|
25
|
-
.length + 1,
|
|
26
|
-
matchedPattern
|
|
27
|
-
};
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
export default findInsertIndex;
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import readFile from "../readFile.js";
|
|
2
|
-
import checkDuplicate from "./checkDuplicate.js";
|
|
3
|
-
import findInsertIndex from "./findInsertIndex.js";
|
|
4
|
-
import writeFile from "../writeFile.js";
|
|
5
|
-
|
|
6
|
-
import buildUpdatedContent from "./buildUpdatedContent.js";
|
|
7
|
-
|
|
8
|
-
const locateInsertPoint = ({ content, insertAfter }) => {
|
|
9
|
-
return findInsertIndex({
|
|
10
|
-
inContent: content,
|
|
11
|
-
inPatterns: insertAfter
|
|
12
|
-
});
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
const alterFile = ({
|
|
16
|
-
jsFilePath,
|
|
17
|
-
toInsertLine,
|
|
18
|
-
duplicationCheck,
|
|
19
|
-
insertAfter = [],
|
|
20
|
-
showLog = false
|
|
21
|
-
}) => {
|
|
22
|
-
const content = readFile(jsFilePath);
|
|
23
|
-
|
|
24
|
-
const duplicateInfo = checkDuplicate({
|
|
25
|
-
inContent: content,
|
|
26
|
-
inFilePath: jsFilePath,
|
|
27
|
-
inSearchText: duplicationCheck
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
if (duplicateInfo.found) {
|
|
31
|
-
if (showLog) {
|
|
32
|
-
console.log(
|
|
33
|
-
`Duplicate found at line ${duplicateInfo.lineNumber}`
|
|
34
|
-
);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
return duplicateInfo;
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
const insertInfo = locateInsertPoint({
|
|
41
|
-
content,
|
|
42
|
-
insertAfter
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
const updated = buildUpdatedContent({
|
|
46
|
-
content,
|
|
47
|
-
insertInfo,
|
|
48
|
-
toInsertLine,
|
|
49
|
-
insertAfter
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
writeFile(jsFilePath, updated);
|
|
53
|
-
|
|
54
|
-
return {
|
|
55
|
-
found: false,
|
|
56
|
-
filePath: jsFilePath,
|
|
57
|
-
lineNumber: null
|
|
58
|
-
};
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
export default alterFile;
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import validateCheckLines from "./validateCheckLines.js";
|
|
2
|
-
import alterFileForImport from "./common/AlterFileForImport/index.js";
|
|
3
|
-
import alterFileForConsume from "./common/AlterFileForConsume/index.js";
|
|
4
|
-
|
|
5
|
-
const updateAppJs = ({ inJsFilePath, inCheckLines,
|
|
6
|
-
showLog = false }) => {
|
|
7
|
-
|
|
8
|
-
const localCheckLines = inCheckLines;
|
|
9
|
-
|
|
10
|
-
validateCheckLines(localCheckLines);
|
|
11
|
-
|
|
12
|
-
const importResult = alterFileForImport({
|
|
13
|
-
jsFilePath: inJsFilePath,
|
|
14
|
-
toInsertLine: localCheckLines.importLines.toInsertLine,
|
|
15
|
-
duplicationCheck: localCheckLines.importLines.duplicationCheck,
|
|
16
|
-
insertAfter: localCheckLines.importLines.insertAfter,
|
|
17
|
-
showLog
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
// const useResult = alterFileForConsume({
|
|
21
|
-
// jsFilePath: inJsFilePath,
|
|
22
|
-
// toInsertLine: localCheckLines.useLines.toInsertLine,
|
|
23
|
-
// duplicationCheck: localCheckLines.useLines.duplicationCheck,
|
|
24
|
-
// insertAfter: localCheckLines.useLines.insertAfter,
|
|
25
|
-
// showLog
|
|
26
|
-
// });
|
|
27
|
-
|
|
28
|
-
// return { importResult, useResult };
|
|
29
|
-
|
|
30
|
-
return { importResult };
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
export default updateAppJs;
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
const startFunc = (obj) => {
|
|
2
|
-
if (typeof obj !== "object" || obj === null || Array.isArray(obj)) {
|
|
3
|
-
throw new TypeError("inCheckLines must be a valid object.");
|
|
4
|
-
}
|
|
5
|
-
for (const key of ["importLines", "useLines"]) {
|
|
6
|
-
if (!(key in obj)) {
|
|
7
|
-
throw new Error(`inCheckLines must contain "${key}".`);
|
|
8
|
-
}
|
|
9
|
-
const section = obj[key];
|
|
10
|
-
if (typeof section !== "object" || section === null || Array.isArray(section)) {
|
|
11
|
-
throw new TypeError(`inCheckLines.${key} must be an object.`);
|
|
12
|
-
}
|
|
13
|
-
if (key === "importLines") {
|
|
14
|
-
if (typeof section.toInsertLine !== "string" && !Array.isArray(section.toInsertLine)) {
|
|
15
|
-
throw new TypeError(`inCheckLines.importLines.toInsertLine must be a string or an array.`);
|
|
16
|
-
}
|
|
17
|
-
} else {
|
|
18
|
-
if (typeof section.toInsertLine !== "string") {
|
|
19
|
-
throw new TypeError(`inCheckLines.${key}.toInsertLine must be a string.`);
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
if (typeof section.duplicationCheck !== "string") {
|
|
23
|
-
throw new TypeError(`inCheckLines.${key}.duplicationCheck must be a string.`);
|
|
24
|
-
}
|
|
25
|
-
if (!Array.isArray(section.insertAfter)) {
|
|
26
|
-
throw new TypeError(`inCheckLines.${key}.insertAfter must be an array.`);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
export default startFunc;
|