express-fix-any-js 1.4.2 → 1.5.3
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 +79 -79
- package/bin/cli.js +11 -11
- package/bin/core/getLatestVersion.js +12 -12
- package/bin/core/loadRunner.js +8 -8
- package/bin/v4/UpdateJs/checkLines.json +17 -17
- package/bin/v4/UpdateJs/common/AlterFile/buildUpdatedContent.js +18 -18
- package/bin/v4/UpdateJs/common/AlterFile/checkDuplicate.js +20 -20
- package/bin/v4/UpdateJs/common/AlterFile/findInsertIndex.js +29 -29
- package/bin/v4/UpdateJs/common/AlterFile/index.js +54 -54
- package/bin/v4/UpdateJs/common/readFile.js +7 -7
- package/bin/v4/UpdateJs/common/writeFile.js +9 -9
- package/bin/v4/UpdateJs/index.js +55 -55
- package/bin/v4/core/parseInput.js +12 -12
- package/bin/v4/core/showUsage.js +49 -49
- package/bin/v4/start.js +17 -17
- package/bin/{v3 → v5}/UpdateJs/common/AlterFile/buildUpdatedContent.js +26 -18
- package/bin/{v3 → v5}/UpdateJs/common/AlterFile/checkDuplicate.js +20 -20
- package/bin/{v3 → v5}/UpdateJs/common/AlterFile/findInsertIndex.js +29 -29
- package/bin/{v3 → v5}/UpdateJs/common/AlterFile/index.js +54 -55
- package/bin/{v3 → v5}/UpdateJs/common/readFile.js +7 -7
- package/bin/{v3 → v5}/UpdateJs/common/writeFile.js +9 -9
- package/bin/{v3 → v5}/UpdateJs/index.js +29 -30
- package/bin/v5/UpdateJs/validateCheckLines.js +31 -0
- package/bin/{v3 → v5}/core/parseInput.js +12 -12
- package/bin/{v3 → v5}/core/showUsage.js +49 -49
- package/bin/{v3 → v5}/start.js +17 -17
- package/index.js +10 -10
- package/package.json +33 -33
- package/bin/v3/UpdateJs/checkLines.json +0 -18
- package/bin/v3/core/createFolder.js +0 -34
package/bin/v4/UpdateJs/index.js
CHANGED
|
@@ -1,56 +1,56 @@
|
|
|
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
|
-
|
|
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
56
|
export default updateAppJs;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
export default function parseInput({ jsFilePath,
|
|
2
|
-
inCheckLines = {}, showLog }) {
|
|
3
|
-
|
|
4
|
-
const [...args] = process.argv.slice(2);
|
|
5
|
-
|
|
6
|
-
return {
|
|
7
|
-
showLog: args[1] === undefined
|
|
8
|
-
? showLog
|
|
9
|
-
: args[1] === "true",
|
|
10
|
-
inJsFilePath: jsFilePath || process.cwd(),
|
|
11
|
-
inCheckLines
|
|
12
|
-
};
|
|
1
|
+
export default function parseInput({ jsFilePath,
|
|
2
|
+
inCheckLines = {}, showLog }) {
|
|
3
|
+
|
|
4
|
+
const [...args] = process.argv.slice(2);
|
|
5
|
+
|
|
6
|
+
return {
|
|
7
|
+
showLog: args[1] === undefined
|
|
8
|
+
? showLog
|
|
9
|
+
: args[1] === "true",
|
|
10
|
+
inJsFilePath: jsFilePath || process.cwd(),
|
|
11
|
+
inCheckLines
|
|
12
|
+
};
|
|
13
13
|
};
|
package/bin/v4/core/showUsage.js
CHANGED
|
@@ -1,50 +1,50 @@
|
|
|
1
|
-
/*
|
|
2
|
-
KSchema CLI – Entry Flow
|
|
3
|
-
|
|
4
|
-
1. Read user input from terminal (parseInput)
|
|
5
|
-
2. If no command → show usage (first-time user safety)
|
|
6
|
-
3. If help flags → show usage (quick guidance)
|
|
7
|
-
4. Resolve command dynamically (no hardcoding logic)
|
|
8
|
-
5. If command not found → inform + guide back to usage
|
|
9
|
-
6. Execute command with parsed input
|
|
10
|
-
|
|
11
|
-
Goal:
|
|
12
|
-
- Zero confusion for user
|
|
13
|
-
- Single source of truth (showUsage)
|
|
14
|
-
- Easy to extend (just add commands, no core changes)
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
export default function showUsage(version) {
|
|
18
|
-
const g = "\x1b[32m";
|
|
19
|
-
const y = "\x1b[33m";
|
|
20
|
-
const c = "\x1b[36m";
|
|
21
|
-
const gray = "\x1b[90m";
|
|
22
|
-
const r = "\x1b[0m";
|
|
23
|
-
|
|
24
|
-
console.log(`
|
|
25
|
-
${c}🚀 KSchema Api Generator v${version}${r}
|
|
26
|
-
|
|
27
|
-
${y}Usage:${r}
|
|
28
|
-
${g}npx @keshavsoft/kschema-api-gen${r} <command> [options]
|
|
29
|
-
|
|
30
|
-
${y}Commands:${r}
|
|
31
|
-
${g}StartEndPoint${r} Initialize a new folder and files
|
|
32
|
-
${g}AddSubRoute${r} Initialize a new folder and files
|
|
33
|
-
${g}AddTableName${r} Initialize a new folder and files for TableName
|
|
34
|
-
${g}ShowAll${r} Initialize a new folder and files for action
|
|
35
|
-
|
|
36
|
-
${g}CreateApi${r} Creates new end point and hooks to app.js
|
|
37
|
-
${g}InsertApi${r} Creates new InsertApi end point and hooks to app.js
|
|
38
|
-
|
|
39
|
-
${y}Examples:${r}
|
|
40
|
-
${gray}npx @keshavsoft/kschema-api-gen StartEndPoint${r}
|
|
41
|
-
${gray}npx @keshavsoft/kschema-api-gen AddSubRoute${r}
|
|
42
|
-
${gray}npx @keshavsoft/kschema-api-gen AddTableName${r}
|
|
43
|
-
${gray}npx @keshavsoft/kschema-api-gen ShowAll${r}
|
|
44
|
-
${gray}npx @keshavsoft/kschema-api-gen CreateApi Api/V1/journals/ShowAll${r}
|
|
45
|
-
${gray}npx @keshavsoft/kschema-api-gen InsertApi Api/V1/journals/Insert${r}
|
|
46
|
-
|
|
47
|
-
${y}Tip:${r}
|
|
48
|
-
${gray}npm i -g @keshavsoft/kschema-api-gen${r}
|
|
49
|
-
`);
|
|
1
|
+
/*
|
|
2
|
+
KSchema CLI – Entry Flow
|
|
3
|
+
|
|
4
|
+
1. Read user input from terminal (parseInput)
|
|
5
|
+
2. If no command → show usage (first-time user safety)
|
|
6
|
+
3. If help flags → show usage (quick guidance)
|
|
7
|
+
4. Resolve command dynamically (no hardcoding logic)
|
|
8
|
+
5. If command not found → inform + guide back to usage
|
|
9
|
+
6. Execute command with parsed input
|
|
10
|
+
|
|
11
|
+
Goal:
|
|
12
|
+
- Zero confusion for user
|
|
13
|
+
- Single source of truth (showUsage)
|
|
14
|
+
- Easy to extend (just add commands, no core changes)
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
export default function showUsage(version) {
|
|
18
|
+
const g = "\x1b[32m";
|
|
19
|
+
const y = "\x1b[33m";
|
|
20
|
+
const c = "\x1b[36m";
|
|
21
|
+
const gray = "\x1b[90m";
|
|
22
|
+
const r = "\x1b[0m";
|
|
23
|
+
|
|
24
|
+
console.log(`
|
|
25
|
+
${c}🚀 KSchema Api Generator v${version}${r}
|
|
26
|
+
|
|
27
|
+
${y}Usage:${r}
|
|
28
|
+
${g}npx @keshavsoft/kschema-api-gen${r} <command> [options]
|
|
29
|
+
|
|
30
|
+
${y}Commands:${r}
|
|
31
|
+
${g}StartEndPoint${r} Initialize a new folder and files
|
|
32
|
+
${g}AddSubRoute${r} Initialize a new folder and files
|
|
33
|
+
${g}AddTableName${r} Initialize a new folder and files for TableName
|
|
34
|
+
${g}ShowAll${r} Initialize a new folder and files for action
|
|
35
|
+
|
|
36
|
+
${g}CreateApi${r} Creates new end point and hooks to app.js
|
|
37
|
+
${g}InsertApi${r} Creates new InsertApi end point and hooks to app.js
|
|
38
|
+
|
|
39
|
+
${y}Examples:${r}
|
|
40
|
+
${gray}npx @keshavsoft/kschema-api-gen StartEndPoint${r}
|
|
41
|
+
${gray}npx @keshavsoft/kschema-api-gen AddSubRoute${r}
|
|
42
|
+
${gray}npx @keshavsoft/kschema-api-gen AddTableName${r}
|
|
43
|
+
${gray}npx @keshavsoft/kschema-api-gen ShowAll${r}
|
|
44
|
+
${gray}npx @keshavsoft/kschema-api-gen CreateApi Api/V1/journals/ShowAll${r}
|
|
45
|
+
${gray}npx @keshavsoft/kschema-api-gen InsertApi Api/V1/journals/Insert${r}
|
|
46
|
+
|
|
47
|
+
${y}Tip:${r}
|
|
48
|
+
${gray}npm i -g @keshavsoft/kschema-api-gen${r}
|
|
49
|
+
`);
|
|
50
50
|
}
|
package/bin/v4/start.js
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import parseInput from "./core/parseInput.js";
|
|
2
|
-
import showUsage from './core/showUsage.js';
|
|
3
|
-
|
|
4
|
-
import updateJs from "./UpdateJs/index.js";
|
|
5
|
-
|
|
6
|
-
import pkg from '../../package.json' with { type: 'json' };
|
|
7
|
-
|
|
8
|
-
const version = pkg.version;
|
|
9
|
-
|
|
10
|
-
const run = ({ jsFilePath, inCheckLines, showLog }) => {
|
|
11
|
-
const input = parseInput({ jsFilePath, inCheckLines, showLog });
|
|
12
|
-
|
|
13
|
-
if (input.cmd === "--help" || input.cmd === "-h" || input.cmd === "help") return showUsage(version);
|
|
14
|
-
|
|
15
|
-
updateJs(input);
|
|
16
|
-
};
|
|
17
|
-
|
|
1
|
+
import parseInput from "./core/parseInput.js";
|
|
2
|
+
import showUsage from './core/showUsage.js';
|
|
3
|
+
|
|
4
|
+
import updateJs from "./UpdateJs/index.js";
|
|
5
|
+
|
|
6
|
+
import pkg from '../../package.json' with { type: 'json' };
|
|
7
|
+
|
|
8
|
+
const version = pkg.version;
|
|
9
|
+
|
|
10
|
+
const run = ({ jsFilePath, inCheckLines, showLog }) => {
|
|
11
|
+
const input = parseInput({ jsFilePath, inCheckLines, showLog });
|
|
12
|
+
|
|
13
|
+
if (input.cmd === "--help" || input.cmd === "-h" || input.cmd === "help") return showUsage(version);
|
|
14
|
+
|
|
15
|
+
updateJs(input);
|
|
16
|
+
};
|
|
17
|
+
|
|
18
18
|
export default run;
|
|
@@ -1,19 +1,27 @@
|
|
|
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
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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
|
+
|
|
19
27
|
export default startFunc;
|
|
@@ -1,21 +1,21 @@
|
|
|
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
|
-
|
|
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
21
|
export default checkUseDuplicate;
|
|
@@ -1,30 +1,30 @@
|
|
|
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
|
-
|
|
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
30
|
export default findInsertIndex;
|
|
@@ -1,56 +1,55 @@
|
|
|
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
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
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
|
+
|
|
56
55
|
export default alterFile;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import fs from "fs";
|
|
2
|
-
|
|
3
|
-
const readFile = (inAppJsPath) => {
|
|
4
|
-
const localPath = inAppJsPath;
|
|
5
|
-
return fs.readFileSync(localPath, "utf-8");
|
|
6
|
-
};
|
|
7
|
-
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
|
|
3
|
+
const readFile = (inAppJsPath) => {
|
|
4
|
+
const localPath = inAppJsPath;
|
|
5
|
+
return fs.readFileSync(localPath, "utf-8");
|
|
6
|
+
};
|
|
7
|
+
|
|
8
8
|
export default readFile;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import fs from "fs";
|
|
2
|
-
|
|
3
|
-
const writeFile = (inAppJsPath, inContent) => {
|
|
4
|
-
const localPath = inAppJsPath;
|
|
5
|
-
const localContent = inContent;
|
|
6
|
-
|
|
7
|
-
fs.writeFileSync(localPath, localContent);
|
|
8
|
-
};
|
|
9
|
-
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
|
|
3
|
+
const writeFile = (inAppJsPath, inContent) => {
|
|
4
|
+
const localPath = inAppJsPath;
|
|
5
|
+
const localContent = inContent;
|
|
6
|
+
|
|
7
|
+
fs.writeFileSync(localPath, localContent);
|
|
8
|
+
};
|
|
9
|
+
|
|
10
10
|
export default writeFile;
|
|
@@ -1,31 +1,30 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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
|
+
alterFile({
|
|
12
|
+
jsFilePath: inJsFilePath,
|
|
13
|
+
toInsertLine: localCheckLines.importLines.toInsertLine,
|
|
14
|
+
duplicationCheck: localCheckLines.importLines.duplicationCheck,
|
|
15
|
+
insertAfter: localCheckLines.importLines.insertAfter,
|
|
16
|
+
showLog
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
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 false;
|
|
28
|
+
};
|
|
29
|
+
|
|
31
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;
|