@tsparticles/cli 3.0.14 → 3.0.16

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 (60) hide show
  1. package/.github/workflows/node.js-ci.yml +13 -7
  2. package/dist/build/build-bundle.d.ts +5 -0
  3. package/dist/build/build-circular-deps.d.ts +6 -0
  4. package/dist/build/build-clear.d.ts +5 -0
  5. package/dist/build/build-distfiles.d.ts +5 -0
  6. package/dist/build/build-distfiles.js +7 -8
  7. package/dist/build/build-diststats.d.ts +12 -0
  8. package/dist/build/build-eslint.d.ts +5 -0
  9. package/dist/build/build-eslint.js +1 -3
  10. package/dist/build/build-prettier.d.ts +25 -0
  11. package/dist/build/build-prettier.js +5 -5
  12. package/dist/build/build-tsc.d.ts +5 -0
  13. package/dist/build/build.d.ts +3 -0
  14. package/dist/cli.d.ts +2 -0
  15. package/dist/create/create.d.ts +3 -0
  16. package/dist/create/plugin/create-plugin.d.ts +8 -0
  17. package/dist/create/plugin/plugin.d.ts +3 -0
  18. package/dist/create/preset/create-preset.d.ts +8 -0
  19. package/dist/create/preset/preset.d.ts +3 -0
  20. package/dist/create/shape/create-shape.d.ts +8 -0
  21. package/dist/create/shape/shape.d.ts +3 -0
  22. package/dist/tsconfig.tsbuildinfo +1 -0
  23. package/dist/utils/file-utils.d.ts +28 -0
  24. package/dist/utils/string-utils.d.ts +20 -0
  25. package/dist/utils/template-utils.d.ts +47 -0
  26. package/files/create-plugin/src/PluginInstance.ts +4 -2
  27. package/files/create-plugin/src/index.ts +1 -1
  28. package/files/create-plugin/src/plugin.ts +6 -6
  29. package/files/empty-project/.browserslistrc +1 -1
  30. package/files/empty-project/package.dist.json +1 -1
  31. package/files/empty-project/package.json +9 -9
  32. package/files/empty-project/tsconfig.base.json +2 -1
  33. package/package.json +12 -12
  34. package/src/build/build-bundle.ts +34 -34
  35. package/src/build/build-circular-deps.ts +23 -23
  36. package/src/build/build-clear.ts +11 -11
  37. package/src/build/build-distfiles.ts +67 -70
  38. package/src/build/build-diststats.ts +41 -41
  39. package/src/build/build-eslint.ts +26 -28
  40. package/src/build/build-prettier.ts +166 -166
  41. package/src/build/build-tsc.ts +146 -149
  42. package/src/build/build.ts +116 -116
  43. package/src/cli.ts +3 -3
  44. package/src/create/plugin/create-plugin.ts +108 -111
  45. package/src/create/plugin/plugin.ts +31 -31
  46. package/src/create/preset/create-preset.ts +123 -126
  47. package/src/create/preset/preset.ts +31 -31
  48. package/src/create/shape/create-shape.ts +112 -115
  49. package/src/create/shape/shape.ts +31 -31
  50. package/src/tsconfig.json +7 -125
  51. package/src/utils/file-utils.ts +35 -35
  52. package/src/utils/string-utils.ts +13 -13
  53. package/src/utils/template-utils.ts +130 -130
  54. package/tests/create-plugin.test.ts +11 -3
  55. package/tests/create-preset.test.ts +10 -2
  56. package/tests/create-shape.test.ts +10 -2
  57. package/tests/tsconfig.json +3 -15
  58. package/tsconfig.json +53 -20
  59. package/.mocharc.json +0 -11
  60. package/tsconfig.eslint.json +0 -8
@@ -1,10 +1,10 @@
1
1
  import fs from "fs-extra";
2
2
 
3
3
  export interface IDistStats {
4
- bundleSize: number;
5
- totalFiles: number;
6
- totalFolders: number;
7
- totalSize: number;
4
+ bundleSize: number;
5
+ totalFiles: number;
6
+ totalFolders: number;
7
+ totalSize: number;
8
8
  }
9
9
 
10
10
  /**
@@ -13,42 +13,42 @@ export interface IDistStats {
13
13
  * @returns the given folder stats;
14
14
  */
15
15
  async function getFolderStats(folderPath: string, bundlePath?: string): Promise<IDistStats> {
16
- const stats: IDistStats = {
17
- bundleSize: 0,
18
- totalFiles: 0,
19
- totalFolders: 0,
20
- totalSize: 0,
21
- };
16
+ const stats: IDistStats = {
17
+ bundleSize: 0,
18
+ totalFiles: 0,
19
+ totalFolders: 0,
20
+ totalSize: 0,
21
+ };
22
22
 
23
- if (!(await fs.pathExists(folderPath))) {
24
- return stats;
25
- }
23
+ if (!(await fs.pathExists(folderPath))) {
24
+ return stats;
25
+ }
26
26
 
27
- const dir = await fs.promises.opendir(folderPath),
28
- path = await import("path");
27
+ const dir = await fs.promises.opendir(folderPath),
28
+ path = await import("path");
29
29
 
30
- for await (const dirent of dir) {
31
- const increment = 1;
30
+ for await (const dirent of dir) {
31
+ const increment = 1;
32
32
 
33
- if (dirent.isDirectory()) {
34
- const subDirStats = await getFolderStats(path.join(folderPath, dirent.name), bundlePath);
33
+ if (dirent.isDirectory()) {
34
+ const subDirStats = await getFolderStats(path.join(folderPath, dirent.name), bundlePath);
35
35
 
36
- stats.totalFolders += subDirStats.totalFolders + increment;
37
- stats.totalFiles += subDirStats.totalFiles;
38
- stats.totalSize += subDirStats.totalSize;
39
- } else {
40
- const fileStats = await fs.stat(path.join(folderPath, dirent.name));
36
+ stats.totalFolders += subDirStats.totalFolders + increment;
37
+ stats.totalFiles += subDirStats.totalFiles;
38
+ stats.totalSize += subDirStats.totalSize;
39
+ } else {
40
+ const fileStats = await fs.stat(path.join(folderPath, dirent.name));
41
41
 
42
- stats.totalFiles++;
43
- stats.totalSize += fileStats.size;
42
+ stats.totalFiles++;
43
+ stats.totalSize += fileStats.size;
44
44
 
45
- if (bundlePath && path.join(folderPath, dirent.name) === bundlePath) {
46
- stats.bundleSize += fileStats.size;
47
- }
48
- }
45
+ if (bundlePath && path.join(folderPath, dirent.name) === bundlePath) {
46
+ stats.bundleSize += fileStats.size;
47
+ }
49
48
  }
49
+ }
50
50
 
51
- return stats;
51
+ return stats;
52
52
  }
53
53
 
54
54
  /**
@@ -57,15 +57,15 @@ async function getFolderStats(folderPath: string, bundlePath?: string): Promise<
57
57
  * @returns the stats for the dist folder
58
58
  */
59
59
  export async function getDistStats(basePath: string): Promise<IDistStats> {
60
- const path = await import("path"),
61
- distFolder = path.join(basePath, "dist"),
62
- pkgInfo = (await fs.exists(path.join(distFolder, "package.json")))
63
- ? (JSON.parse((await fs.readFile(path.join(distFolder, "package.json"))).toString()) as {
64
- jsdelivr?: string;
65
- })
66
- : {},
67
- bundlePath =
68
- (await fs.exists(distFolder)) && pkgInfo.jsdelivr ? path.join(distFolder, pkgInfo.jsdelivr) : undefined;
60
+ const path = await import("path"),
61
+ distFolder = path.join(basePath, "dist"),
62
+ pkgInfo = (await fs.exists(path.join(distFolder, "package.json")))
63
+ ? (JSON.parse((await fs.readFile(path.join(distFolder, "package.json"))).toString()) as {
64
+ jsdelivr?: string;
65
+ })
66
+ : {},
67
+ bundlePath =
68
+ (await fs.exists(distFolder)) && pkgInfo.jsdelivr ? path.join(distFolder, pkgInfo.jsdelivr) : undefined;
69
69
 
70
- return await getFolderStats(distFolder, bundlePath);
70
+ return await getFolderStats(distFolder, bundlePath);
71
71
  }
@@ -5,44 +5,42 @@ import { ESLint } from "eslint";
5
5
  * @returns true if the linting was successful
6
6
  */
7
7
  export async function lint(ci: boolean): Promise<boolean> {
8
- console.log("ESLint - started on src");
8
+ console.log("ESLint - started on src");
9
9
 
10
- let res: boolean;
10
+ let res: boolean;
11
11
 
12
- try {
13
- const eslint = new ESLint({
14
- fix: !ci,
15
- });
12
+ try {
13
+ const eslint = new ESLint({
14
+ fix: !ci,
15
+ });
16
16
 
17
- const results = await eslint.lintFiles(["src"]),
18
- errors = ESLint.getErrorResults(results);
17
+ const results = await eslint.lintFiles(["src"]),
18
+ errors = ESLint.getErrorResults(results);
19
19
 
20
- await ESLint.outputFixes(results);
20
+ await ESLint.outputFixes(results);
21
21
 
22
- const formatter = await eslint.loadFormatter("stylish"),
23
- resultText = formatter.format(results),
24
- minimumLength = 0;
22
+ const formatter = await eslint.loadFormatter("stylish"),
23
+ resultText = formatter.format(results),
24
+ minimumLength = 0;
25
25
 
26
- if (errors.length > minimumLength) {
27
- const messages = errors.map(t =>
28
- t.messages
29
- .map(m => `${t.filePath} (${m.line.toString()},${m.column.toString()}): ${m.message}`)
30
- .join("\n"),
31
- );
26
+ if (errors.length > minimumLength) {
27
+ const messages = errors.map(t =>
28
+ t.messages.map(m => `${t.filePath} (${m.line.toString()},${m.column.toString()}): ${m.message}`).join("\n"),
29
+ );
32
30
 
33
- throw new Error(messages.join("\n"));
34
- }
31
+ throw new Error(messages.join("\n"));
32
+ }
35
33
 
36
- console.log(resultText);
34
+ console.log(resultText);
37
35
 
38
- res = true;
39
- } catch (e) {
40
- console.error(e);
36
+ res = true;
37
+ } catch (e) {
38
+ console.error(e);
41
39
 
42
- res = false;
43
- }
40
+ res = false;
41
+ }
44
42
 
45
- console.log("ESLint - done on src");
43
+ console.log("ESLint - done on src");
46
44
 
47
- return res;
45
+ return res;
48
46
  }
@@ -10,46 +10,46 @@ import prettier from "prettier";
10
10
  * @returns true if the prettify src process was successful
11
11
  */
12
12
  export async function prettifySrc(basePath: string, srcPath: string, ci: boolean): Promise<boolean> {
13
- console.log("Prettier - started on src");
13
+ console.log("Prettier - started on src");
14
14
 
15
- let res: boolean;
15
+ let res: boolean;
16
16
 
17
- try {
18
- for await (const file of klaw(srcPath)) {
19
- if (file.stats.isDirectory()) {
20
- continue;
21
- }
22
-
23
- const contents = await fs.readFile(file.path, "utf8"),
24
- options = (await prettier.resolveConfig(basePath)) ?? {};
17
+ try {
18
+ for await (const file of klaw(srcPath)) {
19
+ if (file.stats.isDirectory()) {
20
+ continue;
21
+ }
25
22
 
26
- options.printWidth = 120;
27
- options.endOfLine = "lf";
28
- options.parser = "typescript";
29
- options.tabWidth = 4;
30
- options.arrowParens = "avoid" as const;
23
+ const contents = await fs.readFile(file.path, "utf8"),
24
+ options = (await prettier.resolveConfig(basePath)) ?? {};
31
25
 
32
- if (ci) {
33
- if (!(await prettier.check(contents, options))) {
34
- throw new Error(`${file.path} is not formatted correctly`);
35
- }
36
- } else {
37
- const formatted = await prettier.format(contents, options);
26
+ options.printWidth = 120;
27
+ options.endOfLine = "lf";
28
+ options.parser = "typescript";
29
+ options.tabWidth = 2;
30
+ options.arrowParens = "avoid" as const;
38
31
 
39
- await fs.writeFile(file.path, formatted, "utf8");
40
- }
32
+ if (ci) {
33
+ if (!(await prettier.check(contents, options))) {
34
+ throw new Error(`${file.path} is not formatted correctly`);
41
35
  }
36
+ } else {
37
+ const formatted = await prettier.format(contents, options);
42
38
 
43
- res = true;
44
- } catch (e) {
45
- console.error(e);
46
-
47
- res = false;
39
+ await fs.writeFile(file.path, formatted, "utf8");
40
+ }
48
41
  }
49
42
 
50
- console.log("Prettier - done on src");
43
+ res = true;
44
+ } catch (e) {
45
+ console.error(e);
46
+
47
+ res = false;
48
+ }
49
+
50
+ console.log("Prettier - done on src");
51
51
 
52
- return res;
52
+ return res;
53
53
  }
54
54
 
55
55
  /**
@@ -58,39 +58,39 @@ export async function prettifySrc(basePath: string, srcPath: string, ci: boolean
58
58
  * @returns true if the prettify package.json process was successful
59
59
  */
60
60
  export async function prettifyPackageJson(basePath: string, ci: boolean): Promise<boolean> {
61
- console.log("Prettier - started on package.json");
61
+ console.log("Prettier - started on package.json");
62
62
 
63
- let res: boolean;
63
+ let res: boolean;
64
64
 
65
- try {
66
- const contents = await fs.readFile("package.json", "utf8"),
67
- options = (await prettier.resolveConfig(basePath)) ?? {};
65
+ try {
66
+ const contents = await fs.readFile("package.json", "utf8"),
67
+ options = (await prettier.resolveConfig(basePath)) ?? {};
68
68
 
69
- options.tabWidth = 2;
70
- options.printWidth = 120;
71
- options.endOfLine = "lf";
72
- options.parser = "json";
69
+ options.tabWidth = 2;
70
+ options.printWidth = 120;
71
+ options.endOfLine = "lf";
72
+ options.parser = "json";
73
73
 
74
- if (ci) {
75
- if (!(await prettier.check(contents, options))) {
76
- throw new Error(`package.json is not formatted correctly`);
77
- }
78
- } else {
79
- const formatted = await prettier.format(contents, options);
74
+ if (ci) {
75
+ if (!(await prettier.check(contents, options))) {
76
+ throw new Error(`package.json is not formatted correctly`);
77
+ }
78
+ } else {
79
+ const formatted = await prettier.format(contents, options);
80
80
 
81
- await fs.writeFile("package.json", formatted, "utf8");
82
- }
81
+ await fs.writeFile("package.json", formatted, "utf8");
82
+ }
83
83
 
84
- res = true;
85
- } catch (e) {
86
- console.error(e);
84
+ res = true;
85
+ } catch (e) {
86
+ console.error(e);
87
87
 
88
- res = false;
89
- }
88
+ res = false;
89
+ }
90
90
 
91
- console.log("Prettier - done on package.json");
91
+ console.log("Prettier - done on package.json");
92
92
 
93
- return res;
93
+ return res;
94
94
  }
95
95
 
96
96
  /**
@@ -99,41 +99,41 @@ export async function prettifyPackageJson(basePath: string, ci: boolean): Promis
99
99
  * @returns true if the prettify package.dist.json process was successful
100
100
  */
101
101
  export async function prettifyPackageDistJson(basePath: string, _ci: boolean): Promise<boolean> {
102
- console.log("Prettier - started on package.dist.json");
102
+ console.log("Prettier - started on package.dist.json");
103
103
 
104
- let res: boolean;
104
+ let res: boolean;
105
105
 
106
- try {
107
- const contents = await fs.readFile("package.dist.json", "utf8"),
108
- options = (await prettier.resolveConfig(basePath)) ?? {};
106
+ try {
107
+ const contents = await fs.readFile("package.dist.json", "utf8"),
108
+ options = (await prettier.resolveConfig(basePath)) ?? {};
109
109
 
110
- options.tabWidth = 2;
111
- options.printWidth = 120;
112
- options.endOfLine = "lf";
113
- options.parser = "json";
110
+ options.tabWidth = 2;
111
+ options.printWidth = 120;
112
+ options.endOfLine = "lf";
113
+ options.parser = "json";
114
114
 
115
- // TODO: disabled this check until "prettier-plugin-multiline-arrays" package is compatible with Prettier 3.0.0
115
+ // TODO: disabled this check until "prettier-plugin-multiline-arrays" package is compatible with Prettier 3.0.0
116
116
 
117
- /* if (ci) {
117
+ /* if (ci) {
118
118
  if (!(await prettier.check(contents, options))) {
119
119
  throw new Error(`package.dist.json is not formatted correctly`);
120
120
  }
121
121
  } else { */
122
- const formatted = await prettier.format(contents, options);
122
+ const formatted = await prettier.format(contents, options);
123
123
 
124
- await fs.writeFile("package.dist.json", formatted, "utf8");
125
- // }
124
+ await fs.writeFile("package.dist.json", formatted, "utf8");
125
+ // }
126
126
 
127
- res = true;
128
- } catch (e) {
129
- console.error(e);
127
+ res = true;
128
+ } catch (e) {
129
+ console.error(e);
130
130
 
131
- res = false;
132
- }
131
+ res = false;
132
+ }
133
133
 
134
- console.log("Prettier - done on package.dist.json");
134
+ console.log("Prettier - done on package.dist.json");
135
135
 
136
- return res;
136
+ return res;
137
137
  }
138
138
 
139
139
  /**
@@ -142,38 +142,38 @@ export async function prettifyPackageDistJson(basePath: string, _ci: boolean): P
142
142
  * @returns true if the prettify readme process was successful
143
143
  */
144
144
  export async function prettifyReadme(basePath: string, ci: boolean): Promise<boolean> {
145
- console.log("Prettier - started on README.md");
145
+ console.log("Prettier - started on README.md");
146
146
 
147
- let res: boolean;
147
+ let res: boolean;
148
148
 
149
- try {
150
- const contents = await fs.readFile("README.md", "utf8"),
151
- options = (await prettier.resolveConfig(basePath)) ?? {};
149
+ try {
150
+ const contents = await fs.readFile("README.md", "utf8"),
151
+ options = (await prettier.resolveConfig(basePath)) ?? {};
152
152
 
153
- options.printWidth = 120;
154
- options.endOfLine = "lf";
155
- options.parser = "markdown";
153
+ options.printWidth = 120;
154
+ options.endOfLine = "lf";
155
+ options.parser = "markdown";
156
156
 
157
- if (ci) {
158
- if (!(await prettier.check(contents, options))) {
159
- throw new Error(`README.md is not formatted correctly`);
160
- }
161
- } else {
162
- const formatted = await prettier.format(contents, options);
157
+ if (ci) {
158
+ if (!(await prettier.check(contents, options))) {
159
+ throw new Error(`README.md is not formatted correctly`);
160
+ }
161
+ } else {
162
+ const formatted = await prettier.format(contents, options);
163
163
 
164
- await fs.writeFile("README.md", formatted, "utf8");
165
- }
164
+ await fs.writeFile("README.md", formatted, "utf8");
165
+ }
166
166
 
167
- res = (await prettifyTraductions(basePath, ci)) && (await prettifyMarkdownTypeDocFiles(basePath, ci));
168
- } catch (e) {
169
- console.error(e);
167
+ res = (await prettifyTraductions(basePath, ci)) && (await prettifyMarkdownTypeDocFiles(basePath, ci));
168
+ } catch (e) {
169
+ console.error(e);
170
170
 
171
- res = false;
172
- }
171
+ res = false;
172
+ }
173
173
 
174
- console.log("Prettier - done on README.md");
174
+ console.log("Prettier - done on README.md");
175
175
 
176
- return res;
176
+ return res;
177
177
  }
178
178
 
179
179
  /**
@@ -182,53 +182,53 @@ export async function prettifyReadme(basePath: string, ci: boolean): Promise<boo
182
182
  * @returns true if the prettify traductions process was successful
183
183
  */
184
184
  async function prettifyTraductions(basePath: string, ci: boolean): Promise<boolean> {
185
- console.log("Prettier - started on traductions");
185
+ console.log("Prettier - started on traductions");
186
186
 
187
- let res = false;
187
+ let res = false;
188
188
 
189
- try {
190
- const folder = "traduction",
191
- folderPath = path.join(basePath, folder);
189
+ try {
190
+ const folder = "traduction",
191
+ folderPath = path.join(basePath, folder);
192
192
 
193
- if (!fs.existsSync(folderPath)) {
194
- res = true;
195
- }
196
-
197
- if (!res) {
198
- for await (const file of klaw(folderPath)) {
199
- if (file.stats.isDirectory()) {
200
- continue;
201
- }
193
+ if (!fs.existsSync(folderPath)) {
194
+ res = true;
195
+ }
202
196
 
203
- const contents = await fs.readFile(file.path, "utf8"),
204
- options = (await prettier.resolveConfig(basePath)) ?? {};
197
+ if (!res) {
198
+ for await (const file of klaw(folderPath)) {
199
+ if (file.stats.isDirectory()) {
200
+ continue;
201
+ }
205
202
 
206
- options.printWidth = 120;
207
- options.endOfLine = "lf";
208
- options.parser = "markdown";
203
+ const contents = await fs.readFile(file.path, "utf8"),
204
+ options = (await prettier.resolveConfig(basePath)) ?? {};
209
205
 
210
- if (ci) {
211
- if (!(await prettier.check(contents, options))) {
212
- throw new Error(`${file.path} is not formatted correctly`);
213
- }
214
- } else {
215
- const formatted = await prettier.format(contents, options);
206
+ options.printWidth = 120;
207
+ options.endOfLine = "lf";
208
+ options.parser = "markdown";
216
209
 
217
- await fs.writeFile(file.path, formatted, "utf8");
218
- }
219
- }
210
+ if (ci) {
211
+ if (!(await prettier.check(contents, options))) {
212
+ throw new Error(`${file.path} is not formatted correctly`);
213
+ }
214
+ } else {
215
+ const formatted = await prettier.format(contents, options);
220
216
 
221
- res = true;
217
+ await fs.writeFile(file.path, formatted, "utf8");
222
218
  }
223
- } catch (e) {
224
- console.error(e);
219
+ }
225
220
 
226
- res = false;
221
+ res = true;
227
222
  }
223
+ } catch (e) {
224
+ console.error(e);
225
+
226
+ res = false;
227
+ }
228
228
 
229
- console.log("Prettier - done on traductions");
229
+ console.log("Prettier - done on traductions");
230
230
 
231
- return res;
231
+ return res;
232
232
  }
233
233
 
234
234
  /**
@@ -237,51 +237,51 @@ async function prettifyTraductions(basePath: string, ci: boolean): Promise<boole
237
237
  * @returns true if the prettify markdown typedoc files process was successful
238
238
  */
239
239
  async function prettifyMarkdownTypeDocFiles(basePath: string, ci: boolean): Promise<boolean> {
240
- console.log("Prettier - started on markdown");
240
+ console.log("Prettier - started on markdown");
241
241
 
242
- let res = false;
242
+ let res = false;
243
243
 
244
- try {
245
- const folder = "markdown",
246
- folderPath = path.join(basePath, folder);
247
-
248
- if (!fs.existsSync(folderPath)) {
249
- res = true;
250
- }
244
+ try {
245
+ const folder = "markdown",
246
+ folderPath = path.join(basePath, folder);
251
247
 
252
- if (!res) {
253
- for await (const file of klaw(folderPath)) {
254
- if (file.stats.isDirectory()) {
255
- continue;
256
- }
248
+ if (!fs.existsSync(folderPath)) {
249
+ res = true;
250
+ }
257
251
 
258
- const contents = await fs.readFile(file.path, "utf8"),
259
- options = (await prettier.resolveConfig(basePath)) ?? {};
252
+ if (!res) {
253
+ for await (const file of klaw(folderPath)) {
254
+ if (file.stats.isDirectory()) {
255
+ continue;
256
+ }
260
257
 
261
- options.printWidth = 120;
262
- options.endOfLine = "lf";
263
- options.parser = "markdown";
258
+ const contents = await fs.readFile(file.path, "utf8"),
259
+ options = (await prettier.resolveConfig(basePath)) ?? {};
264
260
 
265
- if (ci) {
266
- if (!(await prettier.check(contents, options))) {
267
- throw new Error(`${file.path} is not formatted correctly`);
268
- }
269
- } else {
270
- const formatted = await prettier.format(contents, options);
261
+ options.printWidth = 120;
262
+ options.endOfLine = "lf";
263
+ options.parser = "markdown";
271
264
 
272
- await fs.writeFile(file.path, formatted, "utf8");
273
- }
274
- }
265
+ if (ci) {
266
+ if (!(await prettier.check(contents, options))) {
267
+ throw new Error(`${file.path} is not formatted correctly`);
268
+ }
269
+ } else {
270
+ const formatted = await prettier.format(contents, options);
275
271
 
276
- res = true;
272
+ await fs.writeFile(file.path, formatted, "utf8");
277
273
  }
278
- } catch (e) {
279
- console.error(e);
274
+ }
280
275
 
281
- res = false;
276
+ res = true;
282
277
  }
278
+ } catch (e) {
279
+ console.error(e);
280
+
281
+ res = false;
282
+ }
283
283
 
284
- console.log("Prettier - done on markdown");
284
+ console.log("Prettier - done on markdown");
285
285
 
286
- return res;
286
+ return res;
287
287
  }