express-fix-any-js 1.3.8 → 1.4.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.
Files changed (25) hide show
  1. package/bin/{v2 → v4}/UpdateJs/common/AlterFile/index.js +15 -10
  2. package/bin/v4/UpdateJs/index.js +56 -0
  3. package/package.json +3 -4
  4. package/bin/v2/EndPointsJs/UpdateJs/common/AlterFile/index.js +0 -51
  5. package/bin/v2/EndPointsJs/UpdateJs/index.js +0 -34
  6. package/bin/v2/EndPointsJs/UpdateJs/validations/validateAppJsPath.js +0 -11
  7. package/bin/v2/EndPointsJs/UpdateJs/validations/validateEndpoint.js +0 -9
  8. package/bin/v2/EndPointsJs/index.js +0 -12
  9. package/bin/v2/UpdateJs/checkLines.json +0 -18
  10. package/bin/v2/UpdateJs/common/AlterFile/buildUpdatedContent.js +0 -19
  11. package/bin/v2/UpdateJs/common/AlterFile/checkDuplicate.js +0 -21
  12. package/bin/v2/UpdateJs/common/AlterFile/findInsertIndex.js +0 -30
  13. package/bin/v2/UpdateJs/common/readFile.js +0 -8
  14. package/bin/v2/UpdateJs/common/writeFile.js +0 -10
  15. package/bin/v2/UpdateJs/index.js +0 -31
  16. package/bin/v2/core/createFolder.js +0 -34
  17. /package/bin/{v2/EndPointsJs → v4}/UpdateJs/checkLines.json +0 -0
  18. /package/bin/{v2/EndPointsJs → v4}/UpdateJs/common/AlterFile/buildUpdatedContent.js +0 -0
  19. /package/bin/{v2/EndPointsJs → v4}/UpdateJs/common/AlterFile/checkDuplicate.js +0 -0
  20. /package/bin/{v2/EndPointsJs → v4}/UpdateJs/common/AlterFile/findInsertIndex.js +0 -0
  21. /package/bin/{v2/EndPointsJs → v4}/UpdateJs/common/readFile.js +0 -0
  22. /package/bin/{v2/EndPointsJs → v4}/UpdateJs/common/writeFile.js +0 -0
  23. /package/bin/{v2 → v4}/core/parseInput.js +0 -0
  24. /package/bin/{v2 → v4}/core/showUsage.js +0 -0
  25. /package/bin/{v2 → v4}/start.js +0 -0
@@ -5,14 +5,6 @@ import writeFile from "../writeFile.js";
5
5
 
6
6
  import buildUpdatedContent from "./buildUpdatedContent.js";
7
7
 
8
- const validateDuplicate = ({ content, jsFilePath, duplicationCheck }) => {
9
- return checkDuplicate({
10
- inContent: content,
11
- inFilePath: jsFilePath,
12
- inSearchText: duplicationCheck
13
- });
14
- };
15
-
16
8
  const locateInsertPoint = ({ content, insertAfter }) => {
17
9
  return findInsertIndex({
18
10
  inContent: content,
@@ -29,9 +21,22 @@ const alterFile = ({
29
21
  }) => {
30
22
  const content = readFile(jsFilePath);
31
23
 
32
- const duplicateInfo = validateDuplicate({ content, jsFilePath, duplicationCheck });
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
+ };
33
39
 
34
- // const index = locateInsertPoint({ content, importInsertAfter });
35
40
  const insertInfo = locateInsertPoint({
36
41
  content,
37
42
  insertAfter
@@ -0,0 +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
+
56
+ export default updateAppJs;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "express-fix-any-js",
3
- "version": "1.3.8",
3
+ "version": "1.4.2",
4
4
  "description": "CLI to build for appjs, the endpoints",
5
5
  "keywords": [
6
6
  "cli",
@@ -9,8 +9,7 @@
9
9
  "node",
10
10
  "project-generator"
11
11
  ],
12
- "dependencies": {
13
- },
12
+ "dependencies": {},
14
13
  "type": "module",
15
14
  "exports": {
16
15
  ".": "./index.js"
@@ -32,4 +31,4 @@
32
31
  "bugs": {
33
32
  "url": "https://github.com/keshavsoft/express-fix-any-js/issues"
34
33
  }
35
- }
34
+ }
@@ -1,51 +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
- import validateAppJsPath from "../../validations/validateAppJsPath.js";
6
-
7
- import buildUpdatedContent from "./buildUpdatedContent.js";
8
-
9
- const validateDuplicate = ({ content, jsFilePath, duplicationCheck }) => {
10
- return checkDuplicate({
11
- inContent: content,
12
- inFilePath: jsFilePath,
13
- inSearchText: duplicationCheck
14
- });
15
- };
16
-
17
- const locateInsertPoint = ({ content, insertAfter }) => {
18
- return findInsertIndex({
19
- inContent: content,
20
- inPatterns: insertAfter
21
- });
22
- };
23
-
24
- const alterFile = ({
25
- jsFilePath,
26
- toInsertLine,
27
- duplicationCheck,
28
- insertAfter = [],
29
- showLog = false
30
- }) => {
31
- const content = readFile(jsFilePath);
32
-
33
- const duplicateInfo = validateDuplicate({ content, jsFilePath, duplicationCheck });
34
-
35
- // const index = locateInsertPoint({ content, importInsertAfter });
36
- const insertInfo = locateInsertPoint({
37
- content,
38
- insertAfter
39
- });
40
-
41
- const updated = buildUpdatedContent({
42
- content,
43
- insertInfo,
44
- toInsertLine,
45
- insertAfter
46
- });
47
-
48
- writeFile(jsFilePath, updated);
49
- };
50
-
51
- export default alterFile;
@@ -1,34 +0,0 @@
1
- // v2/AppJs/index.js
2
-
3
- import checkLines from "./checkLines.json" with {type: "json"};
4
- import validateEndpoint from "./validations/validateEndpoint.js";
5
- import alterFile from "./common/AlterFile/index.js";
6
-
7
- const updateAppJs = ({ inJsFilePath, actionName, inCheckLines,
8
- showLog = false }) => {
9
-
10
- validateEndpoint({ endpoint: actionName });
11
-
12
- const localCheckLines = inCheckLines || checkLines;
13
- // console.log("bbbbbbbbbbbb : ", localCheckLines);
14
-
15
- alterFile({
16
- jsFilePath: inJsFilePath,
17
- toInsertLine: localCheckLines.importLines.toInsertLine,
18
- duplicationCheck: localCheckLines.importLines.duplicationCheck,
19
- insertAfter: localCheckLines.importLines.insertAfter,
20
- showLog
21
- });
22
-
23
- alterFile({
24
- jsFilePath: inJsFilePath,
25
- toInsertLine: localCheckLines.useLines.toInsertLine,
26
- duplicationCheck: localCheckLines.useLines.duplicationCheck,
27
- insertAfter: localCheckLines.useLines.insertAfter,
28
- showLog
29
- });
30
-
31
- return false;
32
- };
33
-
34
- export default updateAppJs;
@@ -1,11 +0,0 @@
1
- // v2/AppJs/validations/validateAppJsPath.js
2
-
3
- import fs from "fs";
4
-
5
- const validateAppJsPath = ({ jsFilePath }) => {
6
- if (!fs.existsSync(jsFilePath)) {
7
- throw new Error(`${jsFilePath} file not found`);
8
- };
9
- };
10
-
11
- export default validateAppJsPath;
@@ -1,9 +0,0 @@
1
- // v2/AppJs/validations/validateEndpoint.js
2
-
3
- const validateEndpoint = ({ endpoint }) => {
4
- if (!endpoint || endpoint.trim() === "") {
5
- throw new Error("endpoint should not be empty");
6
- };
7
- };
8
-
9
- export default validateEndpoint;
@@ -1,12 +0,0 @@
1
- import updateJs from "./UpdateJs/index.js";
2
-
3
- export default ({ actionName, inJsFilePath, inCheckLines, showLog }) => {
4
- const fromUpdate = updateJs({
5
- inJsFilePath,
6
- actionName,
7
- inCheckLines,
8
- showLog
9
- });
10
-
11
- return true;
12
- };
@@ -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,19 +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
- return before +
13
- (isFirstInsert ? "\n" : "") +
14
- toInsertLine +
15
- "\n" +
16
- content.slice(insertInfo.index);
17
- };
18
-
19
- 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,8 +0,0 @@
1
- import fs from "fs";
2
-
3
- const readFile = (inAppJsPath) => {
4
- const localPath = inAppJsPath;
5
- return fs.readFileSync(localPath, "utf-8");
6
- };
7
-
8
- export default readFile;
@@ -1,10 +0,0 @@
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
- export default writeFile;
@@ -1,31 +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 updateAppJs = ({ inJsFilePath, inCheckLines,
7
- showLog = false }) => {
8
-
9
- const localCheckLines = inCheckLines || checkLines;
10
- // console.log("bbbbbbbbbbbb : ", localCheckLines);
11
-
12
- alterFile({
13
- jsFilePath: inJsFilePath,
14
- toInsertLine: localCheckLines.importLines.toInsertLine,
15
- duplicationCheck: localCheckLines.importLines.duplicationCheck,
16
- insertAfter: localCheckLines.importLines.insertAfter,
17
- showLog
18
- });
19
-
20
- alterFile({
21
- jsFilePath: inJsFilePath,
22
- toInsertLine: localCheckLines.useLines.toInsertLine,
23
- duplicationCheck: localCheckLines.useLines.duplicationCheck,
24
- insertAfter: localCheckLines.useLines.insertAfter,
25
- showLog
26
- });
27
-
28
- return false;
29
- };
30
-
31
- export default updateAppJs;
@@ -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
- };
File without changes
File without changes
File without changes