rapida-partner 1.0.0

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 (107) hide show
  1. package/README.md +85 -0
  2. package/index.ts +13 -0
  3. package/package.json +27 -0
  4. package/rapidaObject.json +3024 -0
  5. package/src/constants/options/agendaStatus.ts +3 -0
  6. package/src/constants/options/citiesFromBrazil.ts +27852 -0
  7. package/src/constants/options/countriesFromEarth.ts +1761 -0
  8. package/src/constants/options/currencies.ts +142 -0
  9. package/src/constants/options/eventJobs.ts +94 -0
  10. package/src/constants/options/events.ts +22 -0
  11. package/src/constants/options/hours.ts +26 -0
  12. package/src/constants/options/languages.ts +34 -0
  13. package/src/constants/options/statesFromBrazil.ts +29 -0
  14. package/src/controllers/ts_project_to_json_project.ts +17 -0
  15. package/src/controllers/validate-project-json-schema.ts +11 -0
  16. package/src/examples/components/forms/character.form.ts +92 -0
  17. package/src/examples/components/forms/company.form.ts +648 -0
  18. package/src/examples/components/forms/movie.form.ts +205 -0
  19. package/src/examples/components/forms/movieGenre.form.ts +43 -0
  20. package/src/examples/components/forms/person.form.ts +474 -0
  21. package/src/examples/components/lists/character.list.ts +47 -0
  22. package/src/examples/components/lists/company.list.ts +49 -0
  23. package/src/examples/components/lists/movie.list.ts +60 -0
  24. package/src/examples/components/lists/movieGenre.list.ts +51 -0
  25. package/src/examples/components/lists/person.list.ts +50 -0
  26. package/src/examples/modules/character.ts +13 -0
  27. package/src/examples/modules/company.ts +13 -0
  28. package/src/examples/modules/movie.ts +17 -0
  29. package/src/examples/modules/person.ts +13 -0
  30. package/src/examples/projects/movieBackoffice.ts +110 -0
  31. package/src/interfaces/backend-framework-structure.interface.ts +44 -0
  32. package/src/interfaces/data-card.interface.ts +102 -0
  33. package/src/interfaces/data-chart.interface.ts +84 -0
  34. package/src/interfaces/data-detail.interface.ts +123 -0
  35. package/src/interfaces/data-grid.interface.ts +48 -0
  36. package/src/interfaces/data-table.interface.ts +84 -0
  37. package/src/interfaces/form-array.interface.ts +14 -0
  38. package/src/interfaces/form-autocomplete.interface.ts +79 -0
  39. package/src/interfaces/form-button.interface.ts +34 -0
  40. package/src/interfaces/form-condition.interface.ts +26 -0
  41. package/src/interfaces/form-datepicker.interface.ts +18 -0
  42. package/src/interfaces/form-fieldset.interface.ts +13 -0
  43. package/src/interfaces/form-file.interface.ts +57 -0
  44. package/src/interfaces/form-input.interface.ts +69 -0
  45. package/src/interfaces/form-numeric.interface.ts +22 -0
  46. package/src/interfaces/form-pattern.interface.ts +16 -0
  47. package/src/interfaces/form-radiogroup.interface.ts +21 -0
  48. package/src/interfaces/form-select.interface.ts +60 -0
  49. package/src/interfaces/form-switch.interface.ts +15 -0
  50. package/src/interfaces/form-tab.interface.ts +17 -0
  51. package/src/interfaces/form.interface.ts +73 -0
  52. package/src/interfaces/frontend-framework-structure.interface.ts +39 -0
  53. package/src/interfaces/layout-dashboard.interface.ts +52 -0
  54. package/src/interfaces/layout-panel.interface.ts +45 -0
  55. package/src/interfaces/list.interface.ts +50 -0
  56. package/src/interfaces/project-backend.interface.ts +48 -0
  57. package/src/interfaces/project-style.interface.ts +129 -0
  58. package/src/interfaces/project.interface.ts +79 -0
  59. package/src/interfaces/yaml-template-skeleton.interface.ts +35 -0
  60. package/src/schemas/backend-framework-structure.schema.json +194 -0
  61. package/src/schemas/backend.ref.json +77 -0
  62. package/src/schemas/bdd-and-e2e-narratives.ref.json +57 -0
  63. package/src/schemas/bdd-and-e2e.json +36 -0
  64. package/src/schemas/business-plan.ref.json +25 -0
  65. package/src/schemas/business-rules.ref.json +34 -0
  66. package/src/schemas/component-one-of.ref.json +15 -0
  67. package/src/schemas/dashboard.ref.json +111 -0
  68. package/src/schemas/data-card.ref.json +245 -0
  69. package/src/schemas/data-chart.ref.json +168 -0
  70. package/src/schemas/data-detail.ref.json +297 -0
  71. package/src/schemas/data-grid.ref.json +101 -0
  72. package/src/schemas/data-table.ref.json +181 -0
  73. package/src/schemas/external-application.ref.json +97 -0
  74. package/src/schemas/form-array.ref.json +35 -0
  75. package/src/schemas/form-autocomplete-options-api.ref.json +53 -0
  76. package/src/schemas/form-autocomplete.ref.json +204 -0
  77. package/src/schemas/form-button.ref.json +88 -0
  78. package/src/schemas/form-common-api-request.ref.json +29 -0
  79. package/src/schemas/form-common-filters-from-other-form-fields.ref.json +22 -0
  80. package/src/schemas/form-common-form-fields-filled-by-api-response.ref.json +28 -0
  81. package/src/schemas/form-condition.ref.json +70 -0
  82. package/src/schemas/form-datepicker.ref.json +50 -0
  83. package/src/schemas/form-fieldset.ref.json +28 -0
  84. package/src/schemas/form-file.ref.json +115 -0
  85. package/src/schemas/form-input.ref.json +105 -0
  86. package/src/schemas/form-numeric.ref.json +60 -0
  87. package/src/schemas/form-one-of.ref.json +22 -0
  88. package/src/schemas/form-pattern.ref.json +42 -0
  89. package/src/schemas/form-radiogroup.ref.json +64 -0
  90. package/src/schemas/form-select.ref.json +123 -0
  91. package/src/schemas/form-switch.ref.json +39 -0
  92. package/src/schemas/form-tab.ref.json +50 -0
  93. package/src/schemas/form.ref.json +107 -0
  94. package/src/schemas/frontend-framework-structure.schema.json +178 -0
  95. package/src/schemas/frontend.ref.json +30 -0
  96. package/src/schemas/list.ref.json +196 -0
  97. package/src/schemas/module.ref.json +39 -0
  98. package/src/schemas/panel.ref.json +127 -0
  99. package/src/schemas/project.schema.json +39 -0
  100. package/src/schemas/todo.ref.json +10 -0
  101. package/src/utils/email.ts +56 -0
  102. package/src/utils/env.ts +9 -0
  103. package/src/utils/file.ts +139 -0
  104. package/src/utils/json.ts +100 -0
  105. package/src/utils/path.ts +51 -0
  106. package/src/utils/rapida-project.ts +17 -0
  107. package/tsconfig.json +27 -0
@@ -0,0 +1,196 @@
1
+ {
2
+ "$id": "list.ref.json",
3
+ "$schema": "http://json-schema.org/draft-07/schema#",
4
+ "type": "object",
5
+ "properties": {
6
+ "componentType": {
7
+ "const": "list"
8
+ },
9
+ "id": {
10
+ "type": "string",
11
+ "description": "Named according to component file name (<id>.<componentType>.ts)"
12
+ },
13
+ "title": {
14
+ "type": "string"
15
+ },
16
+ "guards": {
17
+ "type": "array",
18
+ "items": {
19
+ "type": "string"
20
+ }
21
+ },
22
+ "dataSource": {
23
+ "$ref": "form-common-api-request.ref.json"
24
+ },
25
+ "userStory": {
26
+ "type": "string"
27
+ },
28
+ "businessRules": {
29
+ "$ref": "business-rules.ref.json"
30
+ },
31
+ "properties": {
32
+ "type": "array",
33
+ "items": {
34
+ "type": "object",
35
+ "properties": {
36
+ "property": {
37
+ "type": "string",
38
+ "description": "Property name in the response object. e.g.: 'email'"
39
+ },
40
+ "label": {
41
+ "type": "string",
42
+ "description": "Label to property. e.g.: 'E-mail'"
43
+ },
44
+ "type": {
45
+ "type": "string",
46
+ "enum": [
47
+ "title",
48
+ "subtitle",
49
+ "description",
50
+ "video",
51
+ "image",
52
+ "images",
53
+ "icon"
54
+ ]
55
+ },
56
+ "isHtml": {
57
+ "type": "boolean"
58
+ },
59
+ "isLink": {
60
+ "type": "boolean"
61
+ },
62
+ "isTimestamp": {
63
+ "type": "boolean"
64
+ },
65
+ "callToAction": {
66
+ "type": "object",
67
+ "properties": {
68
+ "link": {
69
+ "type": "string",
70
+ "description": "e.g.: '/user'"
71
+ },
72
+ "usePropertyAsQuery": {
73
+ "type": "boolean",
74
+ "description": "if true then '/user/<email>'"
75
+ }
76
+ },
77
+ "required": ["link"]
78
+ }
79
+ },
80
+ "required": ["property"]
81
+ }
82
+ },
83
+ "cardAsALink": {
84
+ "type": "object",
85
+ "properties": {
86
+ "link": {
87
+ "type": "string",
88
+ "description": "e.g.: '/user'"
89
+ },
90
+ "propertiesAsQueryParam": {
91
+ "type": "array",
92
+ "items": {
93
+ "type": "string"
94
+ },
95
+ "description": "if, for example, ['_id', 'email'], then '/user?_id=value&email=value'"
96
+ },
97
+ "propertiesAsPathParam": {
98
+ "type": "array",
99
+ "items": {
100
+ "type": "string"
101
+ },
102
+ "description": "if, for example, ['_id', 'email'], then '/user/<_id>/<email>'"
103
+ }
104
+ },
105
+ "required": ["link"]
106
+ },
107
+ "callsToActionMenu": {
108
+ "type": "array",
109
+ "items": {
110
+ "type": "object",
111
+ "properties": {
112
+ "icon": {
113
+ "type": "string",
114
+ "description": "Material icons e.g: 'pencil'"
115
+ },
116
+ "label": {
117
+ "type": "string",
118
+ "description": "e.g: 'Editar'"
119
+ },
120
+ "action": {
121
+ "type": "object",
122
+ "properties": {
123
+ "link": {
124
+ "type": "object",
125
+ "properties": {
126
+ "endpoint": {
127
+ "type": "string",
128
+ "description": "e.g.: '/user'"
129
+ },
130
+ "propertiesAsQueryParam": {
131
+ "type": "array",
132
+ "items": {
133
+ "type": "string"
134
+ },
135
+ "description": "if, for example, ['_id', 'email'], then '/user?_id=value&email=value'"
136
+ },
137
+ "propertiesAsPathParam": {
138
+ "type": "array",
139
+ "items": {
140
+ "type": "string"
141
+ },
142
+ "description": "if, for example, ['_id', 'email'], then '/user/<_id>/<email>'"
143
+ }
144
+ },
145
+ "required": ["endpoint"]
146
+ },
147
+ "request": {
148
+ "type": "object",
149
+ "properties": {
150
+ "endpoint": {
151
+ "type": "string",
152
+ "description": "e.g.: '/user'"
153
+ },
154
+ "propertiesAsQueryParam": {
155
+ "type": "array",
156
+ "items": {
157
+ "type": "string"
158
+ },
159
+ "description": "if, for example, ['_id', 'email'], then '/user?_id=value&email=value'"
160
+ },
161
+ "propertiesAsPathParam": {
162
+ "type": "array",
163
+ "items": {
164
+ "type": "string"
165
+ },
166
+ "description": "if, for example, ['_id', 'email'], then '/user/<_id>/<email>'"
167
+ },
168
+ "verb": {
169
+ "type": "string",
170
+ "enum": ["get", "post", "put", "delete"]
171
+ },
172
+ "dialog": {
173
+ "type": "object",
174
+ "properties": {
175
+ "title": {
176
+ "type": "string"
177
+ },
178
+ "message": {
179
+ "type": "string"
180
+ }
181
+ },
182
+ "required": ["title", "message"]
183
+ }
184
+ },
185
+ "required": ["endpoint", "verb"]
186
+ }
187
+ },
188
+ "required": ["link"]
189
+ }
190
+ },
191
+ "required": ["icon", "label", "action"]
192
+ }
193
+ }
194
+ },
195
+ "required": ["componentType", "id", "title", "dataSource", "properties"]
196
+ }
@@ -0,0 +1,39 @@
1
+ {
2
+ "$id": "module.ref.json",
3
+ "$schema": "http://json-schema.org/draft-07/schema#",
4
+ "type": "array",
5
+ "items": {
6
+ "type": "object",
7
+ "properties": {
8
+ "id": { "type": "string" },
9
+ "title": { "type": "string" },
10
+ "icon": { "type": "string" },
11
+ "components": {
12
+ "type": "array",
13
+ "items": {
14
+ "oneOf": [
15
+ { "$ref": "form.ref.json" },
16
+ { "$ref": "list.ref.json" },
17
+ { "$ref": "data-table.ref.json" },
18
+ { "$ref": "data-card.ref.json" },
19
+ { "$ref": "data-grid.ref.json" },
20
+ { "$ref": "data-detail.ref.json" },
21
+ { "$ref": "data-chart.ref.json" },
22
+ { "$ref": "dashboard.ref.json" },
23
+ { "$ref": "panel.ref.json" }
24
+ ]
25
+ }
26
+ },
27
+ "businessRules": {
28
+ "$ref": "business-rules.ref.json"
29
+ },
30
+ "todo": {
31
+ "type": "array",
32
+ "items": {
33
+ "$ref": "todo.ref.json"
34
+ }
35
+ }
36
+ },
37
+ "required": ["id", "title", "icon", "components"]
38
+ }
39
+ }
@@ -0,0 +1,127 @@
1
+ {
2
+ "$id": "panel.ref.json",
3
+ "$schema": "http://json-schema.org/draft-07/schema#",
4
+ "type": "object",
5
+ "properties": {
6
+ "componentType": { "const": "panel" },
7
+ "id": { "type": "string" },
8
+ "title": { "type": "string" },
9
+ "subtitle": { "type": "string" },
10
+ "icon": { "type": "string" },
11
+ "collapsible": { "type": "boolean" },
12
+ "collapsed": { "type": "boolean" },
13
+ "userStory": { "type": "string" },
14
+ "headerActions": {
15
+ "type": "array",
16
+ "items": {
17
+ "type": "object",
18
+ "properties": {
19
+ "icon": { "type": "string" },
20
+ "label": { "type": "string" },
21
+ "action": {
22
+ "type": "object",
23
+ "properties": {
24
+ "type": {
25
+ "type": "string",
26
+ "enum": ["link", "request", "event"]
27
+ },
28
+ "link": {
29
+ "type": "object",
30
+ "properties": {
31
+ "route": { "type": "string" }
32
+ },
33
+ "required": ["route"]
34
+ },
35
+ "request": {
36
+ "type": "object",
37
+ "properties": {
38
+ "endpoint": { "type": "string" },
39
+ "method": {
40
+ "type": "string",
41
+ "enum": ["GET", "POST", "PUT", "DELETE"]
42
+ }
43
+ },
44
+ "required": ["endpoint", "method"]
45
+ },
46
+ "event": {
47
+ "type": "object",
48
+ "properties": {
49
+ "name": { "type": "string" },
50
+ "data": {}
51
+ },
52
+ "required": ["name"]
53
+ }
54
+ },
55
+ "required": ["type"]
56
+ }
57
+ },
58
+ "required": ["action"]
59
+ }
60
+ },
61
+ "content": {
62
+ "type": "object",
63
+ "properties": {
64
+ "type": {
65
+ "type": "string",
66
+ "enum": ["component", "html", "markdown"]
67
+ },
68
+ "component": {
69
+ "type": "object",
70
+ "properties": {
71
+ "type": {
72
+ "type": "string",
73
+ "enum": ["dataTable", "dataGrid", "dataCard", "dataChart", "form"]
74
+ },
75
+ "config": {}
76
+ },
77
+ "required": ["type", "config"]
78
+ },
79
+ "html": { "type": "string" },
80
+ "markdown": { "type": "string" }
81
+ },
82
+ "required": ["type"],
83
+ "allOf": [
84
+ {
85
+ "if": {
86
+ "properties": { "type": { "const": "component" } }
87
+ },
88
+ "then": {
89
+ "required": ["component"]
90
+ }
91
+ },
92
+ {
93
+ "if": {
94
+ "properties": { "type": { "const": "html" } }
95
+ },
96
+ "then": {
97
+ "required": ["html"]
98
+ }
99
+ },
100
+ {
101
+ "if": {
102
+ "properties": { "type": { "const": "markdown" } }
103
+ },
104
+ "then": {
105
+ "required": ["markdown"]
106
+ }
107
+ }
108
+ ]
109
+ },
110
+ "styling": {
111
+ "type": "object",
112
+ "properties": {
113
+ "variant": {
114
+ "type": "string",
115
+ "enum": ["default", "outlined", "elevated", "flat"]
116
+ },
117
+ "padding": {
118
+ "type": "string",
119
+ "enum": ["none", "small", "medium", "large"]
120
+ },
121
+ "maxHeight": { "type": "string" },
122
+ "scrollable": { "type": "boolean" }
123
+ }
124
+ }
125
+ },
126
+ "required": ["componentType", "id", "content"]
127
+ }
@@ -0,0 +1,39 @@
1
+ {
2
+ "$id": "project.schema.json",
3
+ "$schema": "http://json-schema.org/draft-07/schema#",
4
+ "type": "object",
5
+ "properties": {
6
+ "id": {
7
+ "type": "string"
8
+ },
9
+ "title": {
10
+ "type": "string"
11
+ },
12
+ "description": {
13
+ "type": "string"
14
+ },
15
+ "flow": {
16
+ "type": "string",
17
+ "enum": ["autentikigo", "invito", "permeson", "komerco", "labotablo", "reto"]
18
+ },
19
+ "businessPlan": {
20
+ "$ref": "business-plan.ref.json"
21
+ },
22
+ "businessRules": {
23
+ "$ref": "business-rules.ref.json"
24
+ },
25
+ "frontend": {
26
+ "$ref": "frontend.ref.json"
27
+ },
28
+ "backend": {
29
+ "$ref": "backend.ref.json"
30
+ },
31
+ "externalApplications": {
32
+ "$ref": "external-application.ref.json"
33
+ },
34
+ "modules": {
35
+ "$ref": "module.ref.json"
36
+ }
37
+ },
38
+ "required": ["id", "title", "description"]
39
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "$id": "todo.ref.json",
3
+ "$schema": "http://json-schema.org/draft-07/schema#",
4
+ "type": "object",
5
+ "properties": {
6
+ "title": { "type": "string" },
7
+ "description": { "type": "string" }
8
+ },
9
+ "required": ["title", "description"]
10
+ }
@@ -0,0 +1,56 @@
1
+ import nodemailer from 'nodemailer';
2
+ import dotenv from 'dotenv';
3
+
4
+ dotenv.config();
5
+
6
+ interface IEmail {
7
+ mailer: "smtp";
8
+ host?: string;
9
+ service?: string;
10
+ port: number;
11
+ username: string;
12
+ password: string;
13
+ encryption: "tls";
14
+ from: string;
15
+ to: string;
16
+ subject: string;
17
+ content: {
18
+ type: "text" | "html";
19
+ content: string;
20
+ }
21
+ }
22
+
23
+ const sendEmailWithNodemailer = (email: IEmail) => {
24
+ const transporter = nodemailer.createTransport({
25
+ service: email.service,
26
+ auth: {
27
+ user: email.username,
28
+ pass: email.password,
29
+ },
30
+ port: email.port,
31
+ secure: email.port === 465, // true for 465, false for other ports
32
+ });
33
+
34
+ const mailOptions = {
35
+ from: email.from,
36
+ to: email.to,
37
+ subject: email.subject,
38
+ ...(email.content.type === "text" && { text: email.content.content }),
39
+ ...(email.content.type === "html" && { html: email.content.content }),
40
+ };
41
+
42
+ transporter.sendMail(mailOptions, (error, info) => {
43
+ if (error) {
44
+ return console.error(error);
45
+ }
46
+ console.info('Email enviado: ' + (info as nodemailer.SentMessageInfo).response);
47
+ });
48
+ };
49
+
50
+ export {
51
+ sendEmailWithNodemailer
52
+ }
53
+
54
+ export type {
55
+ IEmail
56
+ }
@@ -0,0 +1,9 @@
1
+ import dotenv from 'dotenv';
2
+ dotenv.config();
3
+
4
+ const rootPath = process.env.ROOT_PATH;
5
+ const terminalPassword = process.env.TERMINAL_PASSWORD;
6
+ const trelloApiKey = process.env.TRELLO_API_KEY;
7
+ const trelloToken = process.env.TRELLO_TOKEN;
8
+
9
+ export { rootPath, terminalPassword, trelloApiKey, trelloToken };
@@ -0,0 +1,139 @@
1
+ import chp from "child_process";
2
+ import fs from "fs";
3
+
4
+ /**
5
+ * Writes the content of a string to a file, overwriting the file if it already exists.
6
+ *
7
+ * @param {string} stringToFile - The string content to be written to the file.
8
+ * @param {string} filePath - The path of the file to be written.
9
+ */
10
+ export const writeFile = (stringToFile: string, filePath: string) => {
11
+ try {
12
+ fs.rmSync(filePath);
13
+ fs.writeFileSync(filePath, stringToFile);
14
+ } catch (error) {
15
+ fs.writeFileSync(filePath, stringToFile);
16
+ }
17
+ };
18
+
19
+ /**
20
+ * Downloads a file from the specified URL to the provided folder path.
21
+ *
22
+ * @param {string} url - The URL of the file to be downloaded.
23
+ * @param {string} folderPath - The destination folder path where the downloaded file will be saved.
24
+ * @returns {*} - The result of the download operation.
25
+ */
26
+ export const download = (url: string, folderPath: string) => {
27
+ try {
28
+ const result = chp.execSync(`wget ${url}`, { cwd: folderPath });
29
+ return result;
30
+ } catch (error) {
31
+ console.error(error);
32
+ }
33
+ };
34
+
35
+ /**
36
+ * Modifies the contents of a specified file by adding a string at a specified place.
37
+ *
38
+ * @param {string} stringToAdd - The string to be added to the file.
39
+ * @param {string} filePath - The path to the file that is to be modified.
40
+ * @param {string} placeToAddString - A substring after which `stringToAdd` will be added.
41
+ * The function inserts `stringToAdd` immediately after the first occurrence of this substring.
42
+ * @returns {void}
43
+ *
44
+ * This function reads the content of the file located at `filePath`. If the file does not already contain `stringToAdd`,
45
+ * it will insert `stringToAdd` immediately after the first occurrence of `placeToAddString`. If `stringToAdd` already exists
46
+ * in the file, the function logs a message indicating this and does not modify the file.
47
+ *
48
+ * @example
49
+ * // To add a new import statement in a JavaScript file
50
+ * addStringToFile("import newModule from 'new-module';\n", './path/to/file.js', "// Import statements\n");
51
+ */
52
+ export const addStringToFile = (stringToAdd: string, filePath: string, placeToAddString: string) => {
53
+ try {
54
+ const fileContent = fs.readFileSync(filePath).toString();
55
+ const fileContentToCompare = fileContent.replace(/[\r\n\s]+/g, ' ').trim();
56
+ const stringToAddToCompare = stringToAdd.replace(/[\r\n\s]+/g, ' ').trim();
57
+
58
+ if (!fileContentToCompare.includes(stringToAddToCompare)) {
59
+ console.info(`Adding code to ${filePath}.`);
60
+ const fileChanged = fileContent.replace(placeToAddString, `${placeToAddString}${stringToAdd}`);
61
+ writeFile(fileChanged, filePath);
62
+ } else {
63
+ console.info(`Code that would be added already exists in ${filePath}`);
64
+ }
65
+ } catch (error) {
66
+ console.error(error);
67
+ }
68
+ };
69
+
70
+ export const addStringToFileForced = (stringToAdd: string, filePath: string, placeToAddString: string) => {
71
+ try {
72
+ const fileContent = fs.readFileSync(filePath).toString();
73
+
74
+ console.info(`Adding code to ${filePath}.`);
75
+ const fileChanged = fileContent.replace(placeToAddString, `${placeToAddString}${stringToAdd}`);
76
+ writeFile(fileChanged, filePath);
77
+ } catch (error) {
78
+ console.error(error);
79
+ }
80
+ };
81
+
82
+ /**
83
+ * Reads a file from the specified file path, checks if the specified string to be changed exists in the file,
84
+ * and replaces it with the new string if it exists. If the string to be changed does not exist in the file,
85
+ * it logs a message indicating that the change was not made.
86
+ *
87
+ * @param {string} stringToChange - The string to replace the existing string with.
88
+ * @param {string} filePath - The path to the file to be modified.
89
+ * @param {string} stringToBeChanged - The string to be replaced.
90
+ */
91
+ export const replaceStringInFile = (stringToChange: string, filePath: string, stringToBeChanged: string) => {
92
+ try {
93
+ const fileContent = fs.readFileSync(filePath).toString();
94
+ const fileContentToCompare = fileContent.replace(/[\r\n\s]+/g, ' ').trim();
95
+ const stringToChangeToCompare = stringToChange.replace(/[\r\n\s]+/g, ' ').trim();
96
+
97
+ if (!fileContentToCompare.includes(stringToChangeToCompare)) {
98
+ console.info(`Changing code in ${filePath}.`);
99
+ const fileChanged = fileContent.replace(stringToBeChanged.replace(/[\r\n\s]+/g, ' ').trim(), `${stringToChange}`);
100
+
101
+ writeFile(fileChanged, filePath);
102
+ } else {
103
+ console.info(`Code that would be changed already exists in ${filePath}`);
104
+ }
105
+ } catch (error) {
106
+ console.error(error);
107
+ }
108
+ };
109
+
110
+ export const replaceStringInFileForced = (stringToChange: string, filePath: string, stringToBeChanged: string) => {
111
+ try {
112
+ const fileContent = fs.readFileSync(filePath).toString();
113
+ const fileContentToCompare = fileContent.replace(/[\r\n\s]+/g, ' ').trim();
114
+ const stringToChangeToCompare = stringToChange.replace(/[\r\n\s]+/g, ' ').trim();
115
+
116
+ if (!fileContentToCompare.includes(stringToChangeToCompare) || stringToChange === "") {
117
+ console.info(`Changing code in ${filePath}.`);
118
+ const fileChanged = fileContent.replace(stringToBeChanged.replace(/[\r\n\s]+/g, ' ').trim(), `${stringToChange}`);
119
+ writeFile(fileChanged, filePath);
120
+ } else {
121
+ console.info(`Code that would be changed already exists in ${filePath}`);
122
+ }
123
+ } catch (error) {
124
+ console.error(error);
125
+ }
126
+ };
127
+
128
+ export const removeStringInFile = (stringToBeRemoved: string, filePath: string) => {
129
+ try {
130
+ const fileContent = fs.readFileSync(filePath).toString();
131
+
132
+ console.info(`Removing code from ${filePath}.`);
133
+ const fileChanged = fileContent.replace(stringToBeRemoved, "");
134
+ writeFile(fileChanged, filePath);
135
+
136
+ } catch (error) {
137
+ console.error(error);
138
+ }
139
+ };