@foal/cli 5.1.2 → 5.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 (166) hide show
  1. package/lib/cli.d.ts +6 -0
  2. package/lib/cli.js +208 -0
  3. package/lib/commands/connectors/connect-angular/connect-angular-command.service.d.ts +15 -0
  4. package/lib/commands/connectors/connect-angular/connect-angular-command.service.js +66 -0
  5. package/lib/commands/connectors/connect-angular/index.d.ts +1 -0
  6. package/lib/commands/connectors/connect-angular/index.js +5 -0
  7. package/lib/commands/connectors/connect-react/connect-react-command.service.d.ts +15 -0
  8. package/lib/commands/connectors/connect-react/connect-react-command.service.js +47 -0
  9. package/lib/commands/connectors/connect-react/index.d.ts +1 -0
  10. package/lib/commands/connectors/connect-react/index.js +5 -0
  11. package/lib/commands/connectors/connect-vue/connect-vue-command.service.d.ts +15 -0
  12. package/lib/commands/connectors/connect-vue/connect-vue-command.service.js +51 -0
  13. package/lib/commands/connectors/connect-vue/index.d.ts +1 -0
  14. package/lib/commands/connectors/connect-vue/index.js +5 -0
  15. package/lib/commands/connectors/index.d.ts +3 -0
  16. package/lib/commands/connectors/index.js +9 -0
  17. package/lib/commands/create-secret/create-secret-command.service.d.ts +7 -0
  18. package/lib/commands/create-secret/create-secret-command.service.js +16 -0
  19. package/lib/commands/create-secret/index.d.ts +1 -0
  20. package/lib/commands/create-secret/index.js +5 -0
  21. package/lib/commands/generators/create-app/create-app-command.service.d.ts +25 -0
  22. package/lib/commands/generators/create-app/create-app-command.service.js +151 -0
  23. package/lib/commands/generators/create-app/index.d.ts +1 -0
  24. package/lib/commands/generators/create-app/index.js +5 -0
  25. package/lib/commands/generators/create-controller/create-controller-command.service.d.ts +19 -0
  26. package/lib/commands/generators/create-controller/create-controller-command.service.js +53 -0
  27. package/lib/commands/generators/create-controller/index.d.ts +1 -0
  28. package/lib/commands/generators/create-controller/index.js +5 -0
  29. package/lib/commands/generators/create-entity/create-entity-command.service.d.ts +17 -0
  30. package/lib/commands/generators/create-entity/create-entity-command.service.js +42 -0
  31. package/lib/commands/generators/create-entity/index.d.ts +1 -0
  32. package/lib/commands/generators/create-entity/index.js +5 -0
  33. package/lib/commands/generators/create-hook/create-hook-command.service.d.ts +17 -0
  34. package/lib/commands/generators/create-hook/create-hook-command.service.js +40 -0
  35. package/lib/commands/generators/create-hook/index.d.ts +1 -0
  36. package/lib/commands/generators/create-hook/index.js +5 -0
  37. package/lib/commands/generators/create-rest-api/create-rest-api-command.service.d.ts +21 -0
  38. package/lib/commands/generators/create-rest-api/create-rest-api-command.service.js +80 -0
  39. package/lib/commands/generators/create-rest-api/index.d.ts +1 -0
  40. package/lib/commands/generators/create-rest-api/index.js +5 -0
  41. package/lib/commands/generators/create-script/create-script-command.service.d.ts +17 -0
  42. package/lib/commands/generators/create-script/create-script-command.service.js +28 -0
  43. package/lib/commands/generators/create-script/index.d.ts +1 -0
  44. package/lib/commands/generators/create-script/index.js +5 -0
  45. package/lib/commands/generators/create-service/create-service-command.service.d.ts +17 -0
  46. package/lib/commands/generators/create-service/create-service-command.service.js +40 -0
  47. package/lib/commands/generators/create-service/index.d.ts +1 -0
  48. package/lib/commands/generators/create-service/index.js +5 -0
  49. package/lib/commands/generators/index.d.ts +7 -0
  50. package/lib/commands/generators/index.js +17 -0
  51. package/lib/commands/index.d.ts +6 -0
  52. package/lib/commands/index.js +23 -0
  53. package/lib/commands/rmdir/index.d.ts +1 -0
  54. package/lib/commands/rmdir/index.js +5 -0
  55. package/lib/commands/rmdir/rmdir-command.service.d.ts +12 -0
  56. package/lib/commands/rmdir/rmdir-command.service.js +29 -0
  57. package/lib/commands/run-script/index.d.ts +1 -0
  58. package/lib/commands/run-script/index.js +5 -0
  59. package/lib/commands/run-script/run-script-command.service.d.ts +10 -0
  60. package/lib/commands/run-script/run-script-command.service.js +79 -0
  61. package/lib/commands/upgrade/index.d.ts +1 -0
  62. package/lib/commands/upgrade/index.js +5 -0
  63. package/lib/commands/upgrade/upgrade-command.service.d.ts +24 -0
  64. package/lib/commands/upgrade/upgrade-command.service.js +49 -0
  65. package/lib/index.d.ts +1 -6
  66. package/lib/index.js +1 -156
  67. package/lib/services/crypto/crypto.service.d.ts +11 -0
  68. package/lib/services/crypto/crypto.service.js +20 -0
  69. package/lib/services/crypto/index.d.ts +1 -0
  70. package/lib/services/crypto/index.js +5 -0
  71. package/lib/services/file-system/file-system.service.d.ts +24 -0
  72. package/lib/services/file-system/file-system.service.js +89 -0
  73. package/lib/services/file-system/index.d.ts +1 -0
  74. package/lib/services/file-system/index.js +5 -0
  75. package/lib/{generate/file-system.d.ts → services/generator/generator.d.ts} +34 -41
  76. package/lib/{generate/file-system.js → services/generator/generator.js} +82 -112
  77. package/lib/services/generator/index.d.ts +1 -0
  78. package/lib/services/generator/index.js +6 -0
  79. package/lib/services/index.d.ts +5 -0
  80. package/lib/services/index.js +14 -0
  81. package/lib/services/logger/index.d.ts +1 -0
  82. package/lib/services/logger/index.js +5 -0
  83. package/lib/services/logger/logger.service.d.ts +8 -0
  84. package/lib/services/logger/logger.service.js +39 -0
  85. package/lib/services/util/index.d.ts +1 -0
  86. package/lib/services/util/index.js +5 -0
  87. package/lib/services/util/util.service.d.ts +12 -0
  88. package/lib/services/util/util.service.js +33 -0
  89. package/package.json +5 -8
  90. package/templates/file-system/test-template.txt +1 -0
  91. package/lib/create-secret/create-secret.d.ts +0 -7
  92. package/lib/create-secret/create-secret.js +0 -15
  93. package/lib/create-secret/index.d.ts +0 -1
  94. package/lib/create-secret/index.js +0 -5
  95. package/lib/generate/generators/angular/connect-angular.d.ts +0 -1
  96. package/lib/generate/generators/angular/connect-angular.js +0 -52
  97. package/lib/generate/generators/angular/index.d.ts +0 -1
  98. package/lib/generate/generators/angular/index.js +0 -5
  99. package/lib/generate/generators/app/create-app.d.ts +0 -7
  100. package/lib/generate/generators/app/create-app.js +0 -134
  101. package/lib/generate/generators/app/index.d.ts +0 -1
  102. package/lib/generate/generators/app/index.js +0 -5
  103. package/lib/generate/generators/controller/create-controller.d.ts +0 -4
  104. package/lib/generate/generators/controller/create-controller.js +0 -39
  105. package/lib/generate/generators/controller/index.d.ts +0 -1
  106. package/lib/generate/generators/controller/index.js +0 -5
  107. package/lib/generate/generators/entity/create-entity.d.ts +0 -3
  108. package/lib/generate/generators/entity/create-entity.js +0 -28
  109. package/lib/generate/generators/entity/index.d.ts +0 -1
  110. package/lib/generate/generators/entity/index.js +0 -5
  111. package/lib/generate/generators/hook/create-hook.d.ts +0 -3
  112. package/lib/generate/generators/hook/create-hook.js +0 -26
  113. package/lib/generate/generators/hook/index.d.ts +0 -1
  114. package/lib/generate/generators/hook/index.js +0 -5
  115. package/lib/generate/generators/index.d.ts +0 -11
  116. package/lib/generate/generators/index.js +0 -27
  117. package/lib/generate/generators/react/connect-react.d.ts +0 -1
  118. package/lib/generate/generators/react/connect-react.js +0 -33
  119. package/lib/generate/generators/react/index.d.ts +0 -1
  120. package/lib/generate/generators/react/index.js +0 -5
  121. package/lib/generate/generators/rest-api/create-rest-api.d.ts +0 -5
  122. package/lib/generate/generators/rest-api/create-rest-api.js +0 -63
  123. package/lib/generate/generators/rest-api/index.d.ts +0 -1
  124. package/lib/generate/generators/rest-api/index.js +0 -5
  125. package/lib/generate/generators/script/create-script.d.ts +0 -3
  126. package/lib/generate/generators/script/create-script.js +0 -15
  127. package/lib/generate/generators/script/index.d.ts +0 -1
  128. package/lib/generate/generators/script/index.js +0 -5
  129. package/lib/generate/generators/service/create-service.d.ts +0 -3
  130. package/lib/generate/generators/service/create-service.js +0 -26
  131. package/lib/generate/generators/service/index.d.ts +0 -1
  132. package/lib/generate/generators/service/index.js +0 -5
  133. package/lib/generate/generators/upgrade/index.d.ts +0 -1
  134. package/lib/generate/generators/upgrade/index.js +0 -5
  135. package/lib/generate/generators/upgrade/upgrade.d.ts +0 -8
  136. package/lib/generate/generators/upgrade/upgrade.js +0 -34
  137. package/lib/generate/generators/vue/connect-vue.d.ts +0 -1
  138. package/lib/generate/generators/vue/connect-vue.js +0 -37
  139. package/lib/generate/generators/vue/index.d.ts +0 -1
  140. package/lib/generate/generators/vue/index.js +0 -5
  141. package/lib/generate/index.d.ts +0 -1
  142. package/lib/generate/index.js +0 -17
  143. package/lib/rmdir/index.d.ts +0 -1
  144. package/lib/rmdir/index.js +0 -5
  145. package/lib/rmdir/rmdir.util.d.ts +0 -8
  146. package/lib/rmdir/rmdir.util.js +0 -24
  147. package/lib/run/get-command-line-arguments.util.d.ts +0 -1
  148. package/lib/run/get-command-line-arguments.util.js +0 -21
  149. package/lib/run/index.d.ts +0 -1
  150. package/lib/run/index.js +0 -5
  151. package/lib/run/run-script.d.ts +0 -7
  152. package/lib/run/run-script.js +0 -76
  153. /package/lib/{generate → commands/generators}/utils/get-names.d.ts +0 -0
  154. /package/lib/{generate → commands/generators}/utils/get-names.js +0 -0
  155. /package/lib/{generate → commands/generators}/utils/index.d.ts +0 -0
  156. /package/lib/{generate → commands/generators}/utils/index.js +0 -0
  157. /package/lib/{generate → commands/generators}/utils/init-git-repo.d.ts +0 -0
  158. /package/lib/{generate → commands/generators}/utils/init-git-repo.js +0 -0
  159. /package/lib/{generate → commands/generators}/utils/install-dependencies.d.ts +0 -0
  160. /package/lib/{generate → commands/generators}/utils/install-dependencies.js +0 -0
  161. /package/lib/{generate → commands/generators}/utils/logger.d.ts +0 -0
  162. /package/lib/{generate → commands/generators}/utils/logger.js +0 -0
  163. /package/lib/{generate → commands/generators}/utils/mkdir-if-does-not-exist.d.ts +0 -0
  164. /package/lib/{generate → commands/generators}/utils/mkdir-if-does-not-exist.js +0 -0
  165. /package/lib/{generate → commands/generators}/utils/rm-dir-and-files-if-exist.d.ts +0 -0
  166. /package/lib/{generate → commands/generators}/utils/rm-dir-and-files-if-exist.js +0 -0
@@ -1,27 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.FileSystem = exports.ClientError = void 0;
3
+ exports.Generator = exports.ClientError = void 0;
4
4
  // std
5
5
  const assert_1 = require("assert");
6
- const fs_1 = require("fs");
7
6
  const path_1 = require("path");
8
- // 3p
9
- const safe_1 = require("colors/safe");
10
- function rmDirAndFiles(path) {
11
- const files = (0, fs_1.readdirSync)(path);
12
- for (const file of files) {
13
- const stats = (0, fs_1.statSync)((0, path_1.join)(path, file));
14
- if (stats.isDirectory()) {
15
- rmDirAndFiles((0, path_1.join)(path, file));
16
- }
17
- else {
18
- (0, fs_1.unlinkSync)((0, path_1.join)(path, file));
19
- }
20
- }
21
- (0, fs_1.rmdirSync)(path);
22
- }
23
7
  /**
24
- * Error thrown by the FileSystem which aims to be pretty
8
+ * Error thrown by the Generator which aims to be pretty
25
9
  * printed without the stacktrace.
26
10
  *
27
11
  * @export
@@ -33,21 +17,27 @@ class ClientError extends Error {
33
17
  }
34
18
  exports.ClientError = ClientError;
35
19
  /**
36
- * This class provides more methods that Node std "fs".
20
+ * This class provides more methods that Node std "generator".
37
21
  * It also allows to create an isolated directory during directory.
38
22
  *
39
23
  * @export
40
- * @class FileSystem
24
+ * @class Generator
41
25
  */
42
- class FileSystem {
26
+ class Generator {
27
+ fileSystem;
28
+ logger;
43
29
  currentDir = '';
44
30
  testDir = 'test-generators/subdir';
45
31
  logs = true;
32
+ constructor(fileSystem, logger) {
33
+ this.fileSystem = fileSystem;
34
+ this.logger = logger;
35
+ }
46
36
  /**
47
37
  * Do not show create and update logs.
48
38
  *
49
39
  * @returns {this}
50
- * @memberof FileSystem
40
+ * @memberof Generator
51
41
  */
52
42
  hideLogs() {
53
43
  this.logs = false;
@@ -58,7 +48,7 @@ class FileSystem {
58
48
  *
59
49
  * @param {string} path - Relative path of the directory.
60
50
  * @returns {this}
61
- * @memberof FileSystem
51
+ * @memberof Generator
62
52
  */
63
53
  cd(path) {
64
54
  this.currentDir = (0, path_1.join)(this.currentDir, path);
@@ -72,7 +62,7 @@ class FileSystem {
72
62
  * as dependency.
73
63
  *
74
64
  * @returns {this}
75
- * @memberof FileSystem
65
+ * @memberof Generator
76
66
  */
77
67
  cdProjectRootDir() {
78
68
  // "/" on Unix, C:\ on Windows
@@ -83,7 +73,8 @@ class FileSystem {
83
73
  }
84
74
  this.cd('..');
85
75
  }
86
- const content = (0, fs_1.readFileSync)(this.parse('package.json'), 'utf8');
76
+ const packagePath = (0, path_1.join)(this.currentDir, 'package.json');
77
+ const content = this.fileSystem.readFile(packagePath);
87
78
  let pkg;
88
79
  try {
89
80
  pkg = JSON.parse(content);
@@ -101,10 +92,11 @@ class FileSystem {
101
92
  *
102
93
  * @param {string} path - The path relative to the client directory.
103
94
  * @returns {boolean}
104
- * @memberof FileSystem
95
+ * @memberof Generator
105
96
  */
106
97
  exists(path) {
107
- return (0, fs_1.existsSync)(this.parse(path));
98
+ const relativePath = (0, path_1.join)(this.currentDir, path);
99
+ return this.fileSystem.exists(relativePath);
108
100
  }
109
101
  /**
110
102
  * Recursively ensures that a directory exists. If the directory structure does not
@@ -112,16 +104,11 @@ class FileSystem {
112
104
  *
113
105
  * @param {string} path - The path relative to the client directory.
114
106
  * @returns {this}
115
- * @memberof FileSystem
107
+ * @memberof Generator
116
108
  */
117
109
  ensureDir(path) {
118
- const dir = (0, path_1.dirname)(path);
119
- if (dir !== '.') {
120
- this.ensureDir(dir);
121
- }
122
- if (!(0, fs_1.existsSync)(this.parse(path))) {
123
- (0, fs_1.mkdirSync)(this.parse(path));
124
- }
110
+ const relativePath = (0, path_1.join)(this.currentDir, path);
111
+ this.fileSystem.mkdir(relativePath);
125
112
  return this;
126
113
  }
127
114
  /**
@@ -131,7 +118,7 @@ class FileSystem {
131
118
  * @param {boolean} condition - The condition.
132
119
  * @param {string} path - The path relative to the client directory.
133
120
  * @returns {this}
134
- * @memberof FileSystem
121
+ * @memberof Generator
135
122
  */
136
123
  ensureDirOnlyIf(condition, path) {
137
124
  if (condition) {
@@ -144,12 +131,13 @@ class FileSystem {
144
131
  *
145
132
  * @param {string} path - The path relative to the client directory.
146
133
  * @returns {this}
147
- * @memberof FileSystem
134
+ * @memberof Generator
148
135
  */
149
136
  ensureFile(path) {
150
- if (!(0, fs_1.existsSync)(this.parse(path))) {
137
+ const relativePath = (0, path_1.join)(this.currentDir, path);
138
+ if (!this.fileSystem.exists(relativePath)) {
151
139
  this.logCreate(path);
152
- (0, fs_1.writeFileSync)(this.parse(path), '', 'utf8');
140
+ this.fileSystem.writeFile(relativePath, '');
153
141
  }
154
142
  return this;
155
143
  }
@@ -159,15 +147,14 @@ class FileSystem {
159
147
  * @param {string} src - The source path relative to the `templates/` directory.
160
148
  * @param {string} dest - The destination path relative to the client directory.
161
149
  * @returns {this}
162
- * @memberof FileSystem
150
+ * @memberof Generator
163
151
  */
164
- copy(src, dest) {
165
- const templatePath = (0, path_1.join)(__dirname, '../..', 'templates', src);
166
- if (!(0, fs_1.existsSync)(templatePath)) {
152
+ copyTemplate(src, dest) {
153
+ if (!this.fileSystem.existsTemplate(src)) {
167
154
  throw new Error(`The template "${src}" does not exist.`);
168
155
  }
169
156
  this.logCreate(dest);
170
- (0, fs_1.copyFileSync)(templatePath, this.parse(dest));
157
+ this.fileSystem.copyFileFromTemplates(src, (0, path_1.join)(this.currentDir, dest));
171
158
  return this;
172
159
  }
173
160
  /**
@@ -177,11 +164,11 @@ class FileSystem {
177
164
  * @param {string} src - The source path relative to the `templates/` directory.
178
165
  * @param {string} dest - The destination path relative to the client directory.
179
166
  * @returns {this}
180
- * @memberof FileSystem
167
+ * @memberof Generator
181
168
  */
182
- copyOnlyIf(condition, src, dest) {
169
+ copyTemplateOnlyIf(condition, src, dest) {
183
170
  if (condition) {
184
- this.copy(src, dest);
171
+ this.copyTemplate(src, dest);
185
172
  }
186
173
  return this;
187
174
  }
@@ -192,19 +179,18 @@ class FileSystem {
192
179
  * @param {string} dest - The destination path relative to the client directory.
193
180
  * @param {*} locals - The template variables.
194
181
  * @returns {this}
195
- * @memberof FileSystem
182
+ * @memberof Generator
196
183
  */
197
184
  render(src, dest, locals) {
198
- const templatePath = (0, path_1.join)(__dirname, '../..', 'templates', src);
199
- if (!(0, fs_1.existsSync)(templatePath)) {
185
+ if (!this.fileSystem.existsTemplate(src)) {
200
186
  throw new Error(`The template "${src}" does not exist.`);
201
187
  }
202
- let content = (0, fs_1.readFileSync)(templatePath, 'utf8');
188
+ let content = this.fileSystem.readFileFromTemplates(src);
203
189
  for (const key in locals) {
204
190
  content = content.split(`/* ${key} */`).join(locals[key]);
205
191
  }
206
192
  this.logCreate(dest);
207
- (0, fs_1.writeFileSync)(this.parse(dest), content, 'utf8');
193
+ this.fileSystem.writeFile((0, path_1.join)(this.currentDir, dest), content);
208
194
  return this;
209
195
  }
210
196
  /**
@@ -215,7 +201,7 @@ class FileSystem {
215
201
  * @param {string} dest - The destination path relative to the client directory.
216
202
  * @param {*} locals - The template variables.
217
203
  * @returns {this}
218
- * @memberof FileSystem
204
+ * @memberof Generator
219
205
  */
220
206
  renderOnlyIf(condition, src, dest, locals) {
221
207
  if (condition) {
@@ -229,15 +215,16 @@ class FileSystem {
229
215
  * @param {string} path - The path relative to the client directory.
230
216
  * @param {(content: string) => string} callback - The callback that modifies the content.
231
217
  * @returns {this}
232
- * @memberof FileSystem
218
+ * @memberof Generator
233
219
  */
234
220
  modify(path, callback) {
235
- if (!(0, fs_1.existsSync)(this.parse(path))) {
221
+ const relativePath = (0, path_1.join)(this.currentDir, path);
222
+ if (!this.fileSystem.exists(relativePath)) {
236
223
  throw new ClientError(`Impossible to modify "${path}": the file does not exist.`);
237
224
  }
238
- const content = (0, fs_1.readFileSync)(this.parse(path), 'utf8');
225
+ const content = this.fileSystem.readFile(relativePath);
239
226
  this.logUpdate(path);
240
- (0, fs_1.writeFileSync)(this.parse(path), callback(content), 'utf8');
227
+ this.fileSystem.writeFile(relativePath, callback(content));
241
228
  return this;
242
229
  }
243
230
  /**
@@ -247,7 +234,7 @@ class FileSystem {
247
234
  * @param {string} path - The path relative to the client directory.
248
235
  * @param {(content: string) => string} callback - The callback that modifies the content.
249
236
  * @returns {this}
250
- * @memberof FileSystem
237
+ * @memberof Generator
251
238
  */
252
239
  modifyOnlyfIf(condition, path, callback) {
253
240
  if (condition) {
@@ -262,7 +249,7 @@ class FileSystem {
262
249
  * @param {string} specifier - The import specifier.
263
250
  * @param {string} source - The import source.
264
251
  * @returns {this}
265
- * @memberof FileSystem
252
+ * @memberof Generator
266
253
  */
267
254
  addNamedExportIn(path, specifier, source) {
268
255
  this.modify(path, content => `${content}export { ${specifier} } from '${source}';\n`);
@@ -278,7 +265,7 @@ class FileSystem {
278
265
  * @param {string} specifier - The import specifier.
279
266
  * @param {string} source - The import source.
280
267
  * @returns {this}
281
- * @memberof FileSystem
268
+ * @memberof Generator
282
269
  */
283
270
  addOrExtendNamedImportIn(path, specifier, source, options) {
284
271
  const initialLogs = this.logs;
@@ -336,7 +323,7 @@ class FileSystem {
336
323
  * @param {string} propertyName - The property name.
337
324
  * @param {string} element - The item to add to the array.
338
325
  * @returns {this}
339
- * @memberof FileSystem
326
+ * @memberof Generator
340
327
  */
341
328
  addOrExtendClassArrayPropertyIn(path, propertyName, element, options) {
342
329
  const initialLogs = this.logs;
@@ -376,12 +363,13 @@ class FileSystem {
376
363
  *
377
364
  * @param {string} name - The name of the dependency.
378
365
  * @returns {boolean}
379
- * @memberof FileSystem
366
+ * @memberof Generator
380
367
  */
381
368
  projectHasDependency(name) {
382
369
  const initialCurrentDir = this.currentDir;
383
370
  this.cdProjectRootDir();
384
- const pkg = JSON.parse((0, fs_1.readFileSync)(this.parse('package.json'), 'utf8'));
371
+ const packagePath = (0, path_1.join)(this.currentDir, 'package.json');
372
+ const pkg = JSON.parse(this.fileSystem.readFile(packagePath));
385
373
  this.currentDir = initialCurrentDir;
386
374
  return pkg.dependencies.hasOwnProperty(name);
387
375
  }
@@ -393,7 +381,8 @@ class FileSystem {
393
381
  getProjectDependencies() {
394
382
  const initialCurrentDir = this.currentDir;
395
383
  this.cdProjectRootDir();
396
- const pkg = JSON.parse((0, fs_1.readFileSync)(this.parse('package.json'), 'utf8'));
384
+ const packagePath = (0, path_1.join)(this.currentDir, 'package.json');
385
+ const pkg = JSON.parse(this.fileSystem.readFile(packagePath));
397
386
  this.currentDir = initialCurrentDir;
398
387
  return Object.keys(pkg.dependencies)
399
388
  .map(name => ({ name, version: pkg.dependencies[name] }));
@@ -406,9 +395,10 @@ class FileSystem {
406
395
  setOrUpdateProjectDependency(name, version) {
407
396
  const initialCurrentDir = this.currentDir;
408
397
  this.cdProjectRootDir();
409
- const pkg = JSON.parse((0, fs_1.readFileSync)(this.parse('package.json'), 'utf8'));
398
+ const packagePath = (0, path_1.join)(this.currentDir, 'package.json');
399
+ const pkg = JSON.parse(this.fileSystem.readFile(packagePath));
410
400
  pkg.dependencies[name] = version;
411
- (0, fs_1.writeFileSync)(this.parse('package.json'), JSON.stringify(pkg, null, 2));
401
+ this.fileSystem.writeFile(packagePath, JSON.stringify(pkg, null, 2));
412
402
  this.currentDir = initialCurrentDir;
413
403
  return this;
414
404
  }
@@ -431,7 +421,8 @@ class FileSystem {
431
421
  getProjectDevDependencies() {
432
422
  const initialCurrentDir = this.currentDir;
433
423
  this.cdProjectRootDir();
434
- const pkg = JSON.parse((0, fs_1.readFileSync)(this.parse('package.json'), 'utf8'));
424
+ const packagePath = (0, path_1.join)(this.currentDir, 'package.json');
425
+ const pkg = JSON.parse(this.fileSystem.readFile(packagePath));
435
426
  this.currentDir = initialCurrentDir;
436
427
  return Object.keys(pkg.devDependencies)
437
428
  .map(name => ({ name, version: pkg.devDependencies[name] }));
@@ -444,45 +435,26 @@ class FileSystem {
444
435
  setOrUpdateProjectDevDependency(name, version) {
445
436
  const initialCurrentDir = this.currentDir;
446
437
  this.cdProjectRootDir();
447
- const pkg = JSON.parse((0, fs_1.readFileSync)(this.parse('package.json'), 'utf8'));
438
+ const packagePath = (0, path_1.join)(this.currentDir, 'package.json');
439
+ const pkg = JSON.parse(this.fileSystem.readFile(packagePath));
448
440
  pkg.devDependencies[name] = version;
449
- (0, fs_1.writeFileSync)(this.parse('package.json'), JSON.stringify(pkg, null, 2));
441
+ this.fileSystem.writeFile(packagePath, JSON.stringify(pkg, null, 2));
450
442
  this.currentDir = initialCurrentDir;
451
443
  return this;
452
444
  }
453
445
  /************************
454
446
  Testing Methods
455
447
  ************************/
456
- /**
457
- * Creates the test client directory. Sets current directory to none.
458
- *
459
- * @memberof FileSystem
460
- */
461
- setUp() {
462
- const [firstDir] = this.testDir.split('/');
463
- (0, fs_1.mkdirSync)(firstDir);
464
- (0, fs_1.mkdirSync)(this.testDir);
465
- this.currentDir = '';
466
- }
467
- /**
468
- * Empties and removes the test client directory. Sets current directory to none.
469
- *
470
- * @memberof FileSystem
471
- */
472
- tearDown() {
473
- const [firstDir] = this.testDir.split('/');
474
- rmDirAndFiles(firstDir);
475
- this.currentDir = '';
476
- }
477
448
  /**
478
449
  * Throws an error if the file or directory does not exist.
479
450
  *
480
451
  * @param {string} path - The path relative to the client directory.
481
452
  * @returns {this}
482
- * @memberof FileSystem
453
+ * @memberof Generator
483
454
  */
484
455
  assertExists(path) {
485
- if (!(0, fs_1.existsSync)(this.parse(path))) {
456
+ const relativePath = (0, path_1.join)(this.currentDir, path);
457
+ if (!this.fileSystem.exists(relativePath)) {
486
458
  throw new Error(`The file "${path}" does not exist.`);
487
459
  }
488
460
  return this;
@@ -492,10 +464,11 @@ class FileSystem {
492
464
  *
493
465
  * @param {string} path - The path relative to the client directory.
494
466
  * @returns {this}
495
- * @memberof FileSystem
467
+ * @memberof Generator
496
468
  */
497
469
  assertNotExists(path) {
498
- if ((0, fs_1.existsSync)(this.parse(path))) {
470
+ const relativePath = (0, path_1.join)(this.currentDir, path);
471
+ if (this.fileSystem.exists(relativePath)) {
499
472
  throw new Error(`The file "${path}" should not exist.`);
500
473
  }
501
474
  return this;
@@ -504,10 +477,10 @@ class FileSystem {
504
477
  * Throws an error if the directory is not empty.
505
478
  *
506
479
  * @param {string} path - The path relative to the client directory.
507
- * @memberof FileSystem
480
+ * @memberof Generator
508
481
  */
509
482
  assertEmptyDir(path) {
510
- if ((0, fs_1.readdirSync)(this.parse(path)).length > 0) {
483
+ if (!this.fileSystem.isDirectoryEmpty((0, path_1.join)(this.currentDir, path))) {
511
484
  throw new Error(`The directory "${path}" should be empty.`);
512
485
  }
513
486
  }
@@ -518,18 +491,17 @@ class FileSystem {
518
491
  * @param {string} expected - The path relative to the `specs/` directory.
519
492
  * @param {{ binary: boolean }} [{ binary }={ binary: true }] - Specify if the file is binary.
520
493
  * @returns {this}
521
- * @memberof FileSystem
494
+ * @memberof Generator
522
495
  */
523
496
  assertEqual(actual, expected, { binary } = { binary: false }) {
524
- const specPath = (0, path_1.join)(__dirname, '../..', 'specs', expected);
525
- if (!(0, fs_1.existsSync)(specPath)) {
497
+ if (!this.fileSystem.existsSpec(expected)) {
526
498
  throw new Error(`The spec file "${expected}" does not exist.`);
527
499
  }
528
500
  if (binary) {
529
- (0, assert_1.deepStrictEqual)((0, fs_1.readFileSync)(this.parse(actual)), (0, fs_1.readFileSync)(specPath));
501
+ (0, assert_1.deepStrictEqual)(this.fileSystem.readBinaryFile((0, path_1.join)(this.currentDir, actual)), this.fileSystem.readBinaryFileFromSpecs(expected));
530
502
  }
531
503
  else {
532
- (0, assert_1.strictEqual)((0, fs_1.readFileSync)(this.parse(actual), 'utf8'), (0, fs_1.readFileSync)(specPath, 'utf8'));
504
+ (0, assert_1.strictEqual)(this.fileSystem.readFile((0, path_1.join)(this.currentDir, actual)), this.fileSystem.readFileFromSpecs(expected));
533
505
  }
534
506
  return this;
535
507
  }
@@ -539,24 +511,24 @@ class FileSystem {
539
511
  * @param {string} src - The source path relative to the `fixtures/` directory.
540
512
  * @param {string} dest - The destination path relative to the client directory.
541
513
  * @returns {this}
542
- * @memberof FileSystem
514
+ * @memberof Generator
543
515
  */
544
516
  copyFixture(src, dest) {
545
- const fixturePath = (0, path_1.join)(__dirname, '../..', 'fixtures', src);
546
- if (!(0, fs_1.existsSync)(fixturePath)) {
517
+ if (!this.fileSystem.existsFixture(src)) {
547
518
  throw new Error(`The fixture file "${src}" does not exist.`);
548
519
  }
549
- (0, fs_1.copyFileSync)(fixturePath, this.parse(dest));
520
+ this.fileSystem.copyFileFromFixtures(src, (0, path_1.join)(this.currentDir, dest));
550
521
  return this;
551
522
  }
552
523
  /**
553
524
  * Removes a file.
554
525
  *
555
526
  * @param {string} path - The path relative to the client directory.
556
- * @memberof FileSystem
527
+ * @memberof Generator
557
528
  */
558
529
  rmfile(path) {
559
- (0, fs_1.unlinkSync)(this.parse(path));
530
+ const relativePath = (0, path_1.join)(this.currentDir, path);
531
+ this.fileSystem.deleteFile(relativePath);
560
532
  }
561
533
  isTestingEnvironment() {
562
534
  return process.env.P1Z7kEbSUUPMxF8GqPwD8Gx_FOAL_CLI_TEST === 'true';
@@ -569,17 +541,15 @@ class FileSystem {
569
541
  }
570
542
  logCreate(path) {
571
543
  path = (0, path_1.join)(this.currentDir, path);
572
- // && !this.options.noLogs
573
544
  if (!this.isTestingEnvironment() && this.logs) {
574
- console.log(`${(0, safe_1.green)('CREATE')} ${path}`);
545
+ this.logger.info(path, 'create');
575
546
  }
576
547
  }
577
548
  logUpdate(path) {
578
- // && !this.options.noLogs
579
549
  path = (0, path_1.join)(this.currentDir, path);
580
550
  if (!this.isTestingEnvironment() && this.logs) {
581
- console.log(`${(0, safe_1.cyan)('UPDATE')} ${path}`);
551
+ this.logger.info(path, 'update');
582
552
  }
583
553
  }
584
554
  }
585
- exports.FileSystem = FileSystem;
555
+ exports.Generator = Generator;
@@ -0,0 +1 @@
1
+ export { ClientError, Generator } from './generator';
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Generator = exports.ClientError = void 0;
4
+ var generator_1 = require("./generator");
5
+ Object.defineProperty(exports, "ClientError", { enumerable: true, get: function () { return generator_1.ClientError; } });
6
+ Object.defineProperty(exports, "Generator", { enumerable: true, get: function () { return generator_1.Generator; } });
@@ -0,0 +1,5 @@
1
+ export { CryptoService } from './crypto';
2
+ export { FileSystemService } from './file-system';
3
+ export { ClientError, Generator } from './generator';
4
+ export { LoggerService } from './logger';
5
+ export { UtilService } from './util';
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UtilService = exports.LoggerService = exports.Generator = exports.ClientError = exports.FileSystemService = exports.CryptoService = void 0;
4
+ var crypto_1 = require("./crypto");
5
+ Object.defineProperty(exports, "CryptoService", { enumerable: true, get: function () { return crypto_1.CryptoService; } });
6
+ var file_system_1 = require("./file-system");
7
+ Object.defineProperty(exports, "FileSystemService", { enumerable: true, get: function () { return file_system_1.FileSystemService; } });
8
+ var generator_1 = require("./generator");
9
+ Object.defineProperty(exports, "ClientError", { enumerable: true, get: function () { return generator_1.ClientError; } });
10
+ Object.defineProperty(exports, "Generator", { enumerable: true, get: function () { return generator_1.Generator; } });
11
+ var logger_1 = require("./logger");
12
+ Object.defineProperty(exports, "LoggerService", { enumerable: true, get: function () { return logger_1.LoggerService; } });
13
+ var util_1 = require("./util");
14
+ Object.defineProperty(exports, "UtilService", { enumerable: true, get: function () { return util_1.UtilService; } });
@@ -0,0 +1 @@
1
+ export { LoggerService } from './logger.service';
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LoggerService = void 0;
4
+ var logger_service_1 = require("./logger.service");
5
+ Object.defineProperty(exports, "LoggerService", { enumerable: true, get: function () { return logger_service_1.LoggerService; } });
@@ -0,0 +1,8 @@
1
+ type Level = 'info' | 'error';
2
+ export declare class LoggerService {
3
+ private lastBlockType;
4
+ log(level: Level, message: string, type?: 'build' | 'server' | 'create' | 'update' | 'default'): void;
5
+ info(message: string, type?: 'build' | 'server' | 'create' | 'update' | 'default'): void;
6
+ error(message: string, type?: 'build' | 'server' | 'create' | 'update' | 'default'): void;
7
+ }
8
+ export {};
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LoggerService = void 0;
4
+ const safe_1 = require("colors/safe");
5
+ class LoggerService {
6
+ lastBlockType = null;
7
+ log(level, message, type = 'default') {
8
+ if (this.lastBlockType && this.lastBlockType !== type) {
9
+ console.log('');
10
+ }
11
+ this.lastBlockType = type;
12
+ let prefix = null;
13
+ if (type === 'build') {
14
+ prefix = level === 'error' ? (0, safe_1.bgRed)((0, safe_1.white)(' BUILD ')) : (0, safe_1.bgCyan)((0, safe_1.white)(' BUILD '));
15
+ }
16
+ else if (type === 'server') {
17
+ prefix = level === 'error' ? (0, safe_1.bgRed)((0, safe_1.white)(' SERVER ')) : (0, safe_1.bgGreen)((0, safe_1.white)(' SERVER '));
18
+ }
19
+ else if (type === 'create') {
20
+ prefix = level === 'error' ? (0, safe_1.bgRed)((0, safe_1.white)(' CREATE ')) : (0, safe_1.bgGreen)((0, safe_1.white)(' CREATE '));
21
+ }
22
+ else if (type === 'update') {
23
+ prefix = level === 'error' ? (0, safe_1.bgRed)((0, safe_1.white)(' UPDATE ')) : (0, safe_1.bgCyan)((0, safe_1.white)(' UPDATE '));
24
+ }
25
+ const formattedMessage = prefix ? `${prefix} ${message}` : message;
26
+ if (level === 'error') {
27
+ console.error(formattedMessage);
28
+ return;
29
+ }
30
+ console.log(formattedMessage);
31
+ }
32
+ info(message, type = 'default') {
33
+ this.log('info', message, type);
34
+ }
35
+ error(message, type = 'default') {
36
+ this.log('error', message, type);
37
+ }
38
+ }
39
+ exports.LoggerService = LoggerService;
@@ -0,0 +1 @@
1
+ export { UtilService } from './util.service';
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UtilService = void 0;
4
+ var util_service_1 = require("./util.service");
5
+ Object.defineProperty(exports, "UtilService", { enumerable: true, get: function () { return util_service_1.UtilService; } });
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Service for utility functions.
3
+ */
4
+ export declare class UtilService {
5
+ /**
6
+ * Parse command line arguments from argv array.
7
+ *
8
+ * @param {string[]} argv - The command line arguments array (typically process.argv)
9
+ * @returns {Record<string, any>} An object containing the parsed arguments
10
+ */
11
+ getCommandLineArguments(argv: string[]): Record<string, any>;
12
+ }
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UtilService = void 0;
4
+ /**
5
+ * Service for utility functions.
6
+ */
7
+ class UtilService {
8
+ /**
9
+ * Parse command line arguments from argv array.
10
+ *
11
+ * @param {string[]} argv - The command line arguments array (typically process.argv)
12
+ * @returns {Record<string, any>} An object containing the parsed arguments
13
+ */
14
+ getCommandLineArguments(argv) {
15
+ const args = argv.splice(4);
16
+ const result = {};
17
+ args.forEach(keyAndValue => {
18
+ const [key, value] = keyAndValue.split('=');
19
+ if (typeof value === 'undefined') {
20
+ result[key] = true;
21
+ return;
22
+ }
23
+ try {
24
+ result[key] = JSON.parse(value);
25
+ }
26
+ catch (error) {
27
+ result[key] = value;
28
+ }
29
+ });
30
+ return result;
31
+ }
32
+ }
33
+ exports.UtilService = UtilService;
package/package.json CHANGED
@@ -1,16 +1,13 @@
1
1
  {
2
2
  "name": "@foal/cli",
3
- "version": "5.1.2",
3
+ "version": "5.2.0",
4
4
  "description": "CLI tool for FoalTS",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./lib/index.d.ts",
7
7
  "scripts": {
8
8
  "test": "rimraf lib && tsc -p tsconfig.json && mocha --file \"./lib/test.js\" \"./lib/**/*.spec.js\"",
9
- "dev:test:fs": "mocha --file \"./src/test.ts\" --require ts-node/register --watch --extension ts \"./src/generate/file-system.spec.ts\"",
10
- "dev:test:generators": "mocha --file \"./src/test.ts\" --require ts-node/register --watch --extension ts \"./src/generate/generators/**/*.spec.ts\"",
11
- "dev:test:rmdir": "mocha --file \"./src/test.ts\" --require ts-node/register --watch --extension ts \"./src/rmdir/**/*.spec.ts\"",
12
- "dev:test:run": "mocha --file \"./src/test.ts\" --require ts-node/register --watch --extension ts \"./src/run/**/*.spec.ts\"",
13
- "dev:test:create-secret": "mocha --file \"./src/test.ts\" --require ts-node/register --watch --extension ts \"./src/create-secret/**/*.spec.ts\"",
9
+ "dev:test:commands": "mocha --file \"./src/test.ts\" --require ts-node/register --watch --extension ts \"./src/commands/**/*.spec.ts\"",
10
+ "dev:test:services": "mocha --file \"./src/test.ts\" --require ts-node/register --watch --extension ts \"./src/services/**/*.spec.ts\"",
14
11
  "build": "rimraf lib && tsc -p tsconfig-build.json",
15
12
  "prepublish": "npm run build"
16
13
  },
@@ -60,7 +57,7 @@
60
57
  "commander": "~14.0.2"
61
58
  },
62
59
  "devDependencies": {
63
- "@foal/core": "^5.1.2",
60
+ "@foal/core": "^5.2.0",
64
61
  "@types/mocha": "10.0.10",
65
62
  "@types/node": "24.10.0",
66
63
  "mocha": "~11.7.5",
@@ -68,5 +65,5 @@
68
65
  "ts-node": "~10.9.2",
69
66
  "typescript": "~5.5.4"
70
67
  },
71
- "gitHead": "85593e34027d7f0639c164222f0902aaf80475b5"
68
+ "gitHead": "f48cf4f28f4472b39aae33893578605f23d64e39"
72
69
  }
@@ -0,0 +1 @@
1
+ This is a template to test the FileSystem service.