mushroom-cli 1.2.0-alpha.9 → 1.2.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 (52) hide show
  1. package/README.md +199 -161
  2. package/dist/check-update.js +6 -0
  3. package/dist/common.js +280 -0
  4. package/dist/config.js +394 -0
  5. package/dist/docs/bootstrap-theme.min.css +6 -0
  6. package/dist/docs/bootstrap.min.css +6 -0
  7. package/dist/docs/bootstrap.min.js +7 -0
  8. package/dist/docs/doc-mt.js +633 -0
  9. package/dist/docs/docs.html +5380 -0
  10. package/{docs → dist/docs}/docs.v2.html +5205 -5065
  11. package/dist/docs/docs.v2.js +2036 -0
  12. package/dist/docs/jquery.min.js +4 -0
  13. package/dist/docs/mt-dom-1.0.js +1398 -0
  14. package/dist/docs/mt.extension.js +199 -0
  15. package/dist/gen/gen-api-docs-v1.js +110 -0
  16. package/dist/gen/gen-api-docs.js +327 -0
  17. package/{gen → dist/gen}/gen-csharp.js +1256 -1399
  18. package/{gen → dist/gen}/gen-db-docs.js +204 -222
  19. package/{gen → dist/gen}/gen-js-driver-tarball.js +81 -101
  20. package/{gen → dist/gen}/gen-js-driver.js +116 -133
  21. package/dist/gen/gen-ts-driver.js +600 -0
  22. package/{gen.js → dist/gen.js} +109 -124
  23. package/{help.js → dist/help.js} +53 -55
  24. package/dist/init/init-json.js +92 -0
  25. package/dist/init/init-netcore.js +30 -0
  26. package/dist/init.js +23 -0
  27. package/dist/master-file/master-file.js +185 -0
  28. package/dist/merge.js +70 -0
  29. package/dist/mr.js +77 -0
  30. package/dist/types.js +1 -0
  31. package/dist/update/tsCode.js +82 -0
  32. package/dist/update.js +20 -0
  33. package/package.json +64 -29
  34. package/check-update.js +0 -9
  35. package/common.js +0 -273
  36. package/config.js +0 -445
  37. package/docs/doc-mt.js +0 -523
  38. package/docs/docs.html +0 -5190
  39. package/docs/docs.v2.js +0 -1558
  40. package/docs/mt-dom-1.0.js +0 -1268
  41. package/docs/mt.extension.js +0 -174
  42. package/gen/gen-api-docs-v1.js +0 -125
  43. package/gen/gen-api-docs.js +0 -298
  44. package/gen/gen-ts-driver.js +0 -471
  45. package/init/init-json.js +0 -106
  46. package/init/init-netcore.js +0 -32
  47. package/init.js +0 -28
  48. package/master-file/master-file.js +0 -234
  49. package/merge.js +0 -84
  50. package/mr.js +0 -82
  51. package/update/tsCode.js +0 -20
  52. package/update.js +0 -24
package/README.md CHANGED
@@ -1,161 +1,199 @@
1
- # Mushroom CLI
2
-
3
- ## Init
4
-
5
- Init a mushroom json file
6
-
7
- npx mushroom-cli init json ./api/SampleProject.json [silent]
8
-
9
- Init a DotNet Core project which pre-install Mushroom Server
10
-
11
- npx mushroom-cli init netcore [projectName]
12
-
13
- ## Configure
14
-
15
- Add the mushroom json file into mushroom-config.json
16
-
17
- npx mushroom-cli config add ./api/yourProjectName.json
18
-
19
- Config gen docs api
20
-
21
- npx mushroom-cli config gen projectName docs ./wwwroot/docs.html [alias aliasName] [features file,auth,mail,driver] [roles Admin,User-Contributor]
22
-
23
- Config gen database docs
24
-
25
- npx mushroom-cli config gen projectName db-docs ./wwwroot/db-docs.html [alias aliasName] [features file,auth,mail]
26
-
27
- Config gen javascript driver
28
-
29
- npx mushroom-cli config gen projectName js-driver ./src/api/mushroom.api.js [alias aliasName] [roles Admin,User-Contributor] [tarball tarballName]
30
-
31
- Config gen typescript driver
32
-
33
- npx mushroom-cli config gen projectName ts-driver ./src/api/mushroom.api.ts [alias aliasName] [roles Admin,User-Contributor]
34
-
35
- Config gen entities for Mushroom project in CSharp and using MongoDb
36
-
37
- npx mushroom-cli config gen projectName c#-mongo ./API/Generated.cs [alias aliasName]
38
-
39
- Config gen entities for CSharp project which calls Mushroom API
40
-
41
- npx mushroom-cli config gen projectName c#-driver ./API/Generated.cs [roles Admin,User-Contributor] [alias aliasName] [access-modifier public] [features file,auth,mail]
42
-
43
- ## Genarate
44
-
45
- Generate docs api (html format)
46
-
47
- npx mushroom-cli gen projectName[@aliasName] docs [v1] [tmp]
48
-
49
- Generate database docs (html format)
50
-
51
- npx mushroom-cli gen projectName[@aliasName] db-docs [tmp]
52
-
53
- Generate npm package (tarball file)
54
-
55
- npx mushroom-cli gen projectName[@aliasName] js-driver-tarball
56
-
57
- Generate javascript driver
58
-
59
- npx mushroom-cli gen projectName[@aliasName] js-driver
60
-
61
- Generate typescript driver
62
-
63
- npx mushroom-cli gen projectName[@aliasName] ts-driver
64
-
65
- Generate entities for Mushroom project in CSharp and using MongoDb
66
-
67
- npx mushroom-cli gen projectName[@aliasName] c#-mongo
68
-
69
- Generate entities for CSharp project which calls Mushroom API
70
-
71
- npx mushroom-cli gen projectName[@aliasName] c#-driver
72
-
73
- ## Merge
74
-
75
- npx mushroom-cli merge output-path.json
76
-
77
- ## Update
78
-
79
- Update ts code
80
-
81
- npx mushroom-cli update ts-code [file-path.ts] [remote-ts-code-url]
82
-
83
- ## Other
84
-
85
- Disable checking for update:
86
-
87
- npx mushroom-cli parameters --no-check-update
88
-
89
- ## Version
90
-
91
- ### 1.2.0-alpha.9
92
-
93
- Improvement:
94
-
95
- * gen-docs
96
- * v1.2: minify, fix bug (some fields are not excluded)
97
-
98
- ### 1.2.0-alpha.8
99
-
100
- Improvement:
101
-
102
- * gen-docs
103
- * v1.2: deal with very big api docs
104
- * v1: prerender all docs html (need more RAM, less performance)
105
-
106
- ### 1.2.0-alpha.7
107
-
108
- New features:
109
-
110
- * init netcore: Support some new set-functions: `ToLowerCase`, `ToUpperCase`, `Trim`, `Replace`
111
-
112
- Changes:
113
-
114
- * init netcore: Operating fail if unknown command or set-function found
115
-
116
- ### 1.2.0-alpha.6
117
-
118
- New features:
119
-
120
- * gen-ts-driver: Support offline mode
121
-
122
- Changes:
123
-
124
- * gen-api-docs: Improve generating api-docs
125
- * gen-csharp: Generate resource classes with `partial`
126
-
127
- ### 1.2.0-alpha.5
128
-
129
- New features:
130
-
131
- * Improve documentation generation: view, custom action.
132
-
133
- ### 1.2.0-alpha.4
134
-
135
- Fixed bugs:
136
-
137
- * Generate api docs: doesn't exclude fields of object in an array
138
-
139
- ### 1.2.0-alpha.3
140
-
141
- Fixed bugs:
142
-
143
- * Generate wrong required field for view parameter
144
-
145
- ### 1.2.0-alpha.2
146
-
147
- New features:
148
-
149
- * Support merge command
150
-
151
- ### 1.2.0-alpha.1
152
-
153
- New features:
154
-
155
- * Support type for View result
156
-
157
- ### 1.1.0
158
-
159
- Support MushroomServer 0.2.25.4 or later
160
-
161
- Support mushroomjs 1.1.0 or later
1
+ # Mushroom CLI
2
+
3
+ ## Init
4
+
5
+ Init a mushroom json file
6
+
7
+ ```bash
8
+ npx mushroom-cli init json ./api/SampleProject.json [silent]
9
+ ```
10
+
11
+ Init a DotNet Core project which pre-install Mushroom Server
12
+
13
+ ```bash
14
+ npx mushroom-cli init netcore [projectName]
15
+ ```
16
+
17
+ ## Configure
18
+
19
+ Add the mushroom json file into mushroom-config.json
20
+
21
+ ```bash
22
+ npx mushroom-cli config add ./api/yourProjectName.json
23
+ ```
24
+
25
+ Config gen docs api
26
+
27
+ ```bash
28
+ npx mushroom-cli config gen projectName docs ./wwwroot/docs.html [alias aliasName] [features file,auth,mail,driver] [roles Admin,User-Contributor]
29
+ ```
30
+
31
+ Config gen database docs
32
+
33
+ ```bash
34
+ npx mushroom-cli config gen projectName "db-docs" ./wwwroot/db-docs.html [alias aliasName] [features file,auth,mail]
35
+ ```
36
+
37
+ Config gen javascript driver
38
+
39
+ ```bash
40
+ npx mushroom-cli config gen projectName "js-driver" ./src/api/mushroom.api.js [alias aliasName] [roles Admin,User-Contributor] [tarball tarballName]
41
+ ```
42
+
43
+ Config gen typescript driver
44
+
45
+ ```bash
46
+ npx mushroom-cli config gen projectName "ts-driver" ./src/api/mushroom.api.ts [alias aliasName] [roles Admin,User-Contributor]
47
+ ```
48
+
49
+ Config gen entities for Mushroom project in CSharp and using MongoDb
50
+
51
+ ```bash
52
+ npx mushroom-cli config gen projectName "c#-mongo" ./API/Generated.cs [alias aliasName]
53
+ ```
54
+
55
+ Config gen entities for CSharp project which calls Mushroom API
56
+
57
+ ```bash
58
+ npx mushroom-cli config gen projectName "c#-driver" ./API/Generated.cs [roles Admin,User-Contributor] [alias aliasName] [access-modifier public] [features file,auth,mail]
59
+ ```
60
+
61
+ ## Genarate
62
+
63
+ Generate docs api (html format)
64
+
65
+ ```bash
66
+ npx mushroom-cli gen projectName[@aliasName] docs [v1] [tmp]
67
+ ```
68
+
69
+ Generate database docs (html format)
70
+
71
+ ```bash
72
+ npx mushroom-cli gen projectName[@aliasName] "db-docs" [tmp]
73
+ ```
74
+
75
+ Generate npm package (tarball file)
76
+
77
+ ```bash
78
+ npx mushroom-cli gen projectName[@aliasName] "js-driver-tarball"
79
+ ```
80
+
81
+ Generate javascript driver
82
+
83
+ ```bash
84
+ npx mushroom-cli gen projectName[@aliasName] "js-driver"
85
+ ```
86
+
87
+ Generate typescript driver
88
+
89
+ ```bash
90
+ npx mushroom-cli gen projectName[@aliasName] "ts-driver"
91
+ ```
92
+
93
+ Generate entities for Mushroom project in CSharp and using MongoDb
94
+
95
+ ```bash
96
+ npx mushroom-cli gen projectName[@aliasName] "c#-mongo"
97
+ ```
98
+
99
+ Generate entities for CSharp project which calls Mushroom API
100
+
101
+ ```bash
102
+ npx mushroom-cli gen projectName[@aliasName] "c#-driver"
103
+ ```
104
+
105
+ ## Merge
106
+
107
+ ```bash
108
+ npx mushroom-cli merge output-path.json
109
+ ```
110
+
111
+ ## Update
112
+
113
+ Update ts code (configuration was stored in mushroom-config.json file)
114
+
115
+ ```bash
116
+ npx mushroom-cli update "ts-code"
117
+ ```
118
+
119
+ Update ts code (simple call)
120
+
121
+ ```bash
122
+ npx mushroom-cli update "ts-code" file-path.ts remote-ts-code-url
123
+ ```
124
+
125
+ ## Other
126
+
127
+ Disable checking for update:
128
+
129
+ ```bash
130
+ npx mushroom-cli parameters --no-check-update
131
+ ```
132
+
133
+ ## Version
134
+
135
+ ### 1.2.0
136
+
137
+ New features:
138
+
139
+ - Support merge command
140
+ - Support type for View result
141
+ - gen-ts-driver: Support offline mode
142
+ - init netcore: Support some new set-functions: `ToLowerCase`, `ToUpperCase`, `Trim`, `Replace`, `New-RandomNumber`, `New-RandomString`
143
+ - gen-docs: New gen docs engine v1.2 - deal with very big api docs
144
+ - support minify
145
+ - allow user to add and change API root url
146
+ - add `JavascriptParamModel`, `JavascriptRequestBodyModel`, `JavascriptResultModel` tab in code snippets of custom methods
147
+ - add docs for `inline` mode of download file and zip file(s), `allowSmallerSize` for thumb
148
+ - support links for Roles and Code Snippets
149
+ - add docs for response body of custom methods
150
+ - allow collapse object fields
151
+ - add validation of fields in custom methods and parameters in views
152
+
153
+ Improvement/Changes:
154
+
155
+ - init netcore
156
+ - Operating fail if unknown command or set-function found
157
+ - gen c#-mongo
158
+ - support System.Text.Json on resources
159
+ - generate resource classes with `partial`
160
+ - gen c#-driver
161
+ - Generate resource classes with `partial`
162
+ - gen ts-driver
163
+ - export type for object fields
164
+ - generate type for custom methods of action
165
+ - generate description for fields, entities
166
+ - generate type for getCountAsync declaration
167
+ - gen docs
168
+ - add default-value information of fields
169
+ - Improve documentation generation: view, custom action.
170
+ - filter role list
171
+ - format cURL to easy to copy and paste to Postman
172
+ - lighten font on MacOS
173
+ - donot use css and js files of bootstrap and jquery in CDN, copy file locally to enable to view offline
174
+ - curl of custom method is missing header X-HTTP-Method-Override
175
+ - Correct generate query string and request body at HTTP and cURL tabs in code snippets of custom methods
176
+ - Correct generate param and body at Javascript tab in code snippets of custom methods
177
+ - Correct generate JavascriptModel in code snippets
178
+ - improve copy function
179
+ - display the description of entities
180
+
181
+ Fixed bugs:
182
+
183
+ - gen docs
184
+ - Generate wrong required field for view parameter
185
+ - doesn't exclude fields of object in an array
186
+ - gen-ts
187
+ - add null value for nullable field type
188
+
189
+ ### 1.1.1
190
+
191
+ Improvement:
192
+
193
+ - `mushroom-cli update tsCode` can read the configuration in mushroom-config.json file
194
+
195
+ ### 1.1.0
196
+
197
+ Support MushroomServer 0.2.25.4 or later
198
+
199
+ Support mushroomjs 1.1.0 or later
@@ -0,0 +1,6 @@
1
+ import fetch from 'node-fetch';
2
+ export default async function checkUpdate() {
3
+ const res = await fetch('https://registry.npmjs.org/mushroom-cli/');
4
+ const data = await res.json();
5
+ return data;
6
+ }
package/dist/common.js ADDED
@@ -0,0 +1,280 @@
1
+ import fs from 'fs';
2
+ import path from 'path';
3
+ import { fileURLToPath } from 'url';
4
+ import readlineSync from 'readline-sync';
5
+ const __filename = fileURLToPath(import.meta.url);
6
+ const __dirname = path.dirname(__filename);
7
+ export function getPackageVersion() {
8
+ try {
9
+ const content = fs.readFileSync(path.join(__dirname, '../package.json')).toString();
10
+ const pkg = JSON.parse(content);
11
+ return pkg.version;
12
+ }
13
+ catch {
14
+ return '<!unable to get package version>';
15
+ }
16
+ }
17
+ export function ensureFolder(path, isFolder) {
18
+ const index = path.lastIndexOf('/');
19
+ if (!isFolder && index <= 0) {
20
+ return;
21
+ }
22
+ if (!isFolder)
23
+ path = path.substring(0, index);
24
+ if (path === '.' || path === '..')
25
+ return;
26
+ if (!fs.existsSync(path)) {
27
+ fs.mkdirSync(path, { recursive: true, mode: 0o755 });
28
+ }
29
+ }
30
+ export function getRootUrl(projectApiConfiguration) {
31
+ return projectApiConfiguration.codeHint && projectApiConfiguration.codeHint.rootUrl
32
+ ? projectApiConfiguration.codeHint.rootUrl
33
+ : projectApiConfiguration.rootUrl;
34
+ }
35
+ export function getEntities(projectApiConfiguration, roles, getAll) {
36
+ if (!projectApiConfiguration || !projectApiConfiguration.entities || !Array.isArray(projectApiConfiguration.entities))
37
+ return {};
38
+ const entities = {};
39
+ projectApiConfiguration.entities.forEach((entity) => {
40
+ if (entity.disabled)
41
+ return;
42
+ if (getAll) {
43
+ entities[entity.name] = entity;
44
+ entity.storageName = entity.storageName ? entity.storageName : entity.name;
45
+ if (!roles || !roles.length)
46
+ roles = ['*'];
47
+ return;
48
+ }
49
+ for (const actionName in entity.actions) {
50
+ entity.actions[actionName].forEach((action) => {
51
+ var _a;
52
+ if (!action.grant || !action.enabled || (action.codeHint && action.codeHint.disabled))
53
+ return;
54
+ const allow = roles?.includes('*') || action.grant === '*';
55
+ if (!allow) {
56
+ action.grant = action.grant
57
+ .split('|')
58
+ .map((roleGroup) => {
59
+ if (!roleGroup)
60
+ return null;
61
+ const ok = roleGroup.split('+').every((grantedRole) => roles?.includes(grantedRole));
62
+ return ok ? roleGroup : null;
63
+ })
64
+ .filter((roleGroup) => roleGroup)
65
+ .join('|');
66
+ if (!action.grant)
67
+ return;
68
+ }
69
+ if (!(entity.name in entities)) {
70
+ entities[entity.name] = {
71
+ name: entity.name,
72
+ description: entity.description,
73
+ storageName: entity.storageName ? entity.storageName : entity.name,
74
+ fields: entity.fields,
75
+ views: {},
76
+ };
77
+ }
78
+ const actions = ((_a = entities[entity.name]).actions ?? (_a.actions = {}));
79
+ actions[actionName] ?? (actions[actionName] = []);
80
+ actions[actionName].push(action);
81
+ });
82
+ }
83
+ for (const viewName in entity.views) {
84
+ entity.views[viewName].forEach((view) => {
85
+ var _a;
86
+ if (!view.grant || !view.enabled)
87
+ return;
88
+ const allow = roles?.indexOf('*') !== -1 || view.grant === '*';
89
+ if (!allow) {
90
+ view.grant = view.grant
91
+ .split('|')
92
+ .map((roleGroup) => {
93
+ if (!roleGroup)
94
+ return null;
95
+ const ok = roleGroup.split('+').every((grantedRole) => roles?.includes(grantedRole));
96
+ return ok ? roleGroup : null;
97
+ })
98
+ .filter((roleGroup) => roleGroup)
99
+ .join('|');
100
+ if (!view.grant)
101
+ return;
102
+ }
103
+ if (!(entity.name in entities)) {
104
+ entities[entity.name] = {
105
+ name: entity.name,
106
+ description: entity.description,
107
+ storageName: entity.storageName ? entity.storageName : entity.name,
108
+ fields: entity.fields,
109
+ actions: {},
110
+ views: {},
111
+ };
112
+ }
113
+ const views = ((_a = entities[entity.name]).views ?? (_a.views = {}));
114
+ views[viewName] ?? (views[viewName] = []);
115
+ views[viewName].push(view);
116
+ });
117
+ }
118
+ if (entity.name in entities) {
119
+ entities[entity.name].features = entity.features;
120
+ }
121
+ });
122
+ return entities;
123
+ }
124
+ export function filterRoles(roleList, allowRoleList) {
125
+ const roles = !allowRoleList || allowRoleList.includes('*')
126
+ ? [...roleList]
127
+ : roleList.filter((role) => allowRoleList.includes(role.name));
128
+ roles.push({
129
+ name: '[Mọi người dùng]',
130
+ description: 'Tất cả người dùng (kể cả chưa đăng nhập)',
131
+ });
132
+ return roles;
133
+ }
134
+ export function processTemplate(basePath, templatePath) {
135
+ const templateJsonContent = fs.readFileSync(path.join(basePath, templatePath)).toString();
136
+ const template = JSON.parse(templateJsonContent);
137
+ if (template && typeof template !== 'object') {
138
+ throw new TypeError(`Invalid template file ${templatePath}`);
139
+ }
140
+ const commands = template.steps;
141
+ if (!Array.isArray(commands)) {
142
+ throw new TypeError(`Invalid template file ${templatePath}`);
143
+ }
144
+ const variables = {};
145
+ commands.forEach((command) => processCommand(command, basePath, variables));
146
+ return variables;
147
+ }
148
+ function processCommand(command, basePath, variables) {
149
+ const commandName = command.command;
150
+ switch (commandName) {
151
+ case 'input':
152
+ processInputCommand(command, variables);
153
+ return;
154
+ case 'set':
155
+ processSetCommand(command, variables);
156
+ return;
157
+ case 'rename':
158
+ processRenameCommand(command, basePath, variables);
159
+ return;
160
+ case 'delete':
161
+ processDeleteCommand(command, basePath, variables);
162
+ return;
163
+ case 'replace':
164
+ processReplaceCommand(command, basePath, variables);
165
+ return;
166
+ default:
167
+ throw new Error(`Unknown command: ${commandName}`);
168
+ }
169
+ }
170
+ function processInputCommand(command, variables) {
171
+ const value = readlineSync.question(command.message ?? '');
172
+ if (command.validation) {
173
+ if (command.validation.required) {
174
+ if (value === '')
175
+ throw new TypeError(`${command.variable} is required`);
176
+ }
177
+ if (command.validation.pattern) {
178
+ if (!new RegExp(command.validation.pattern).test(value))
179
+ throw new Error(`${value} is not valid`);
180
+ }
181
+ }
182
+ variables[command.variable] = value;
183
+ }
184
+ function processSetCommand(command, variables) {
185
+ switch (command['function']) {
186
+ case 'New-GUID':
187
+ processSetNewGuidCommand(command.variable, variables);
188
+ break;
189
+ case 'New-RandomNumber':
190
+ processSetNewRandomNumberCommand(command.variable, variables, command.min, command.max);
191
+ break;
192
+ case 'New-RandomString':
193
+ processSetNewRandomStringCommand(command.variable, variables, command.length, command.characterPool);
194
+ break;
195
+ case 'ToLowerCase':
196
+ toLowerCommand(command.variable, variables, command.input);
197
+ break;
198
+ case 'ToUpperCase':
199
+ toUpperCaseCommand(command.variable, variables, command.input);
200
+ break;
201
+ case 'Trim':
202
+ trimCommand(command.variable, variables, command.input);
203
+ break;
204
+ case 'Replace':
205
+ replaceCommand(command.variable, variables, command.input, command.replacement, command.pattern, command.mode);
206
+ break;
207
+ default:
208
+ throw new Error(`Unknown set-command: ${command['function']}`);
209
+ }
210
+ }
211
+ function processSetNewGuidCommand(variable, variables) {
212
+ variables[variable] = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'
213
+ .replace(/[xy]/g, (c) => {
214
+ const r = (Math.random() * 16) | 0;
215
+ const v = c == 'x' ? r : (r & 0x3) | 0x8;
216
+ return v.toString(16);
217
+ })
218
+ .toUpperCase();
219
+ }
220
+ function processSetNewRandomNumberCommand(variable, variables, min = 0, max = (1 << 30) * 4) {
221
+ variables[variable] = Math.floor(min + Math.random() * (max - min)).toString();
222
+ }
223
+ function processSetNewRandomStringCommand(variable, variables, length, characterPool = '1234567890qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM') {
224
+ let result = '';
225
+ for (let i = 0; i < length; i++) {
226
+ result += characterPool.charAt(Math.floor(Math.random() * characterPool.length));
227
+ }
228
+ variables[variable] = result;
229
+ }
230
+ function toLowerCommand(variable, variables, input) {
231
+ variables[variable] = variables[input].toLowerCase();
232
+ }
233
+ function toUpperCaseCommand(variable, variables, input) {
234
+ variables[variable] = variables[input].toUpperCase();
235
+ }
236
+ function trimCommand(variable, variables, input) {
237
+ variables[variable] = variables[input].trim();
238
+ }
239
+ function replaceCommand(variable, variables, input, replacement, pattern, mode) {
240
+ const regex = new RegExp(pattern, mode);
241
+ variables[variable] = variables[input].replace(regex, replacement);
242
+ }
243
+ function processRenameCommand(command, basePath, variables) {
244
+ const input = replaceVariables(command.input, variables);
245
+ const output = replaceVariables(command.output, variables);
246
+ fs.renameSync(path.join(basePath, input), path.join(basePath, output));
247
+ }
248
+ function processDeleteCommand(command, basePath, variables) {
249
+ const input = replaceVariables(command.input, variables);
250
+ const deletedPath = path.join(basePath, input);
251
+ if (fs.lstatSync(deletedPath).isDirectory()) {
252
+ fs.rmSync(deletedPath, { recursive: true, force: true });
253
+ }
254
+ else {
255
+ fs.rmSync(deletedPath, { force: true });
256
+ }
257
+ }
258
+ function processReplaceCommand(command, basePath, variables) {
259
+ const files = command.input;
260
+ const pattern = new RegExp(command.pattern ?? '', 'g');
261
+ const replacement = replaceVariables(command.replacement ?? '', variables);
262
+ files.forEach((file) => {
263
+ const filePath = replaceVariables(file, variables);
264
+ let content = fs.readFileSync(path.join(basePath, filePath)).toString();
265
+ content = content.replace(pattern, () => replacement);
266
+ fs.writeFileSync(path.join(basePath, filePath), content);
267
+ });
268
+ }
269
+ function replaceVariables(str, variables) {
270
+ return str.replace(/\$\{(\w+)\}/g, (_, varName) => variables[varName] ?? '');
271
+ }
272
+ export function logInfo(message, ...parameters) {
273
+ console.log(message, ...parameters);
274
+ }
275
+ export function logWarning(message, ...parameters) {
276
+ console.warn(message, ...parameters);
277
+ }
278
+ export function logError(message, ...parameters) {
279
+ console.error(message, ...parameters);
280
+ }