@tsparticles/cli 3.0.13 → 3.0.15

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 +4 -4
  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 +14 -14
  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,12 +1,12 @@
1
1
  import { camelize, capitalize, dash } from "../../utils/string-utils.js";
2
2
  import {
3
- copyEmptyTemplateFiles,
4
- copyFilter,
5
- runBuild,
6
- runInstall,
7
- updatePackageDistFile,
8
- updatePackageFile,
9
- updateWebpackFile,
3
+ copyEmptyTemplateFiles,
4
+ copyFilter,
5
+ runBuild,
6
+ runInstall,
7
+ updatePackageDistFile,
8
+ updatePackageFile,
9
+ updateWebpackFile,
10
10
  } from "../../utils/template-utils.js";
11
11
  import fs from "fs-extra";
12
12
  import path from "path";
@@ -18,22 +18,22 @@ import { replaceTokensInFile } from "../../utils/file-utils.js";
18
18
  * @param name - The name of the project
19
19
  */
20
20
  async function updateIndexFile(destPath: string, name: string): Promise<void> {
21
- const capitalizedName = capitalize(name, "-", " "),
22
- camelizedName = camelize(capitalizedName);
21
+ const capitalizedName = capitalize(name, "-", " "),
22
+ camelizedName = camelize(capitalizedName);
23
23
 
24
- await replaceTokensInFile({
25
- path: path.join(destPath, "src", "index.ts"),
26
- tokens: [
27
- {
28
- from: /loadTemplatePlugin/g,
29
- to: `load${capitalizedName}Plugin`,
30
- },
31
- {
32
- from: /"#template#"/g,
33
- to: `"${camelizedName}"`,
34
- },
35
- ],
36
- });
24
+ await replaceTokensInFile({
25
+ path: path.join(destPath, "src", "index.ts"),
26
+ tokens: [
27
+ {
28
+ from: /loadTemplatePlugin/g,
29
+ to: `load${capitalizedName}Plugin`,
30
+ },
31
+ {
32
+ from: /"#template#"/g,
33
+ to: `"${camelizedName}"`,
34
+ },
35
+ ],
36
+ });
37
37
  }
38
38
 
39
39
  /**
@@ -44,21 +44,21 @@ async function updateIndexFile(destPath: string, name: string): Promise<void> {
44
44
  * @param repoUrl - The repository url
45
45
  */
46
46
  async function updatePluginPackageFile(
47
- destPath: string,
48
- name: string,
49
- description: string,
50
- repoUrl: string,
47
+ destPath: string,
48
+ name: string,
49
+ description: string,
50
+ repoUrl: string,
51
51
  ): Promise<void> {
52
- const camelizedName = camelize(camelize(name, "-"), " "),
53
- dashedName = dash(camelizedName);
52
+ const camelizedName = camelize(camelize(name, "-"), " "),
53
+ dashedName = dash(camelizedName);
54
54
 
55
- await updatePackageFile(
56
- destPath,
57
- `tsparticles-plugin-${dashedName}`,
58
- description,
59
- `tsparticles.plugin.${camelizedName}.min.js`,
60
- repoUrl,
61
- );
55
+ await updatePackageFile(
56
+ destPath,
57
+ `tsparticles-plugin-${dashedName}`,
58
+ description,
59
+ `tsparticles.plugin.${camelizedName}.min.js`,
60
+ repoUrl,
61
+ );
62
62
  }
63
63
 
64
64
  /**
@@ -69,21 +69,21 @@ async function updatePluginPackageFile(
69
69
  * @param repoUrl - The repository url
70
70
  */
71
71
  async function updatePluginPackageDistFile(
72
- destPath: string,
73
- name: string,
74
- description: string,
75
- repoUrl: string,
72
+ destPath: string,
73
+ name: string,
74
+ description: string,
75
+ repoUrl: string,
76
76
  ): Promise<void> {
77
- const camelizedName = camelize(camelize(name, "-"), " "),
78
- dashedName = dash(camelizedName);
77
+ const camelizedName = camelize(camelize(name, "-"), " "),
78
+ dashedName = dash(camelizedName);
79
79
 
80
- await updatePackageDistFile(
81
- destPath,
82
- `tsparticles-plugin-${dashedName}`,
83
- description,
84
- `tsparticles.plugin.${camelizedName}.min.js`,
85
- repoUrl,
86
- );
80
+ await updatePackageDistFile(
81
+ destPath,
82
+ `tsparticles-plugin-${dashedName}`,
83
+ description,
84
+ `tsparticles.plugin.${camelizedName}.min.js`,
85
+ repoUrl,
86
+ );
87
87
  }
88
88
 
89
89
  /**
@@ -94,52 +94,49 @@ async function updatePluginPackageDistFile(
94
94
  * @param repoUrl - The repository url
95
95
  */
96
96
  async function updateReadmeFile(destPath: string, name: string, description: string, repoUrl: string): Promise<void> {
97
- const readmePath = path.join(destPath, "README.md"),
98
- capitalizedName = capitalize(name, "-", " "),
99
- camelizedName = camelize(capitalizedName),
100
- dashedName = dash(camelizedName),
101
- stringSearch = "github.com",
102
- trailingSlashSearch = "github.com/",
103
- repoPath = repoUrl.includes(stringSearch)
104
- ? repoUrl.substring(
105
- repoUrl.indexOf(trailingSlashSearch) + trailingSlashSearch.length,
106
- repoUrl.indexOf(".git"),
107
- )
108
- : "tsparticles/plugin-template";
97
+ const readmePath = path.join(destPath, "README.md"),
98
+ capitalizedName = capitalize(name, "-", " "),
99
+ camelizedName = camelize(capitalizedName),
100
+ dashedName = dash(camelizedName),
101
+ stringSearch = "github.com",
102
+ trailingSlashSearch = "github.com/",
103
+ repoPath = repoUrl.includes(stringSearch)
104
+ ? repoUrl.substring(repoUrl.indexOf(trailingSlashSearch) + trailingSlashSearch.length, repoUrl.indexOf(".git"))
105
+ : "tsparticles/plugin-template";
109
106
 
110
- await replaceTokensInFile({
111
- path: readmePath,
112
- tokens: [
113
- {
114
- from: /tsParticles Template Plugin/g,
115
- to: `tsParticles ${description} Plugin`,
116
- },
117
- {
118
- from: /tsparticles-plugin-template/g,
119
- to: `tsparticles-plugin-${dashedName}`,
120
- },
121
- {
122
- from: /tsparticles\.plugin\.template(\.bundle)?\.min\.js/g,
123
- to: `tsparticles.plugin.${camelizedName}$1.min.js`,
124
- },
125
- {
126
- from: /loadTemplatePlugin/g,
127
- to: `load${capitalizedName}Plugin`,
128
- },
129
- {
130
- from: /\[tsParticles]\(https:\/\/github.com\/matteobruni\/tsparticles\) additional template plugin\./g,
131
- to: `[tsParticles](https://github.com/matteobruni/tsparticles) additional ${name} plugin.`,
132
- },
133
- {
134
- from: /plugin\.type: "template"/g,
135
- to: `plugin.type: "${camelizedName}"`,
136
- },
137
- {
138
- from: /!\[demo]\(https:\/\/raw.githubusercontent.com\/tsparticles\/plugin-template\/main\/images\/sample.png\)/g,
139
- to: `![demo](https://raw.githubusercontent.com/${repoPath}/main/images/sample.png)`,
140
- },
141
- ],
142
- });
107
+ await replaceTokensInFile({
108
+ path: readmePath,
109
+ tokens: [
110
+ {
111
+ from: /tsParticles Template Plugin/g,
112
+ to: `tsParticles ${description} Plugin`,
113
+ },
114
+ {
115
+ from: /tsparticles-plugin-template/g,
116
+ to: `tsparticles-plugin-${dashedName}`,
117
+ },
118
+ {
119
+ from: /tsparticles\.plugin\.template(\.bundle)?\.min\.js/g,
120
+ to: `tsparticles.plugin.${camelizedName}$1.min.js`,
121
+ },
122
+ {
123
+ from: /loadTemplatePlugin/g,
124
+ to: `load${capitalizedName}Plugin`,
125
+ },
126
+ {
127
+ from: /\[tsParticles]\(https:\/\/github.com\/matteobruni\/tsparticles\) additional template plugin\./g,
128
+ to: `[tsParticles](https://github.com/matteobruni/tsparticles) additional ${name} plugin.`,
129
+ },
130
+ {
131
+ from: /plugin\.type: "template"/g,
132
+ to: `plugin.type: "${camelizedName}"`,
133
+ },
134
+ {
135
+ from: /!\[demo]\(https:\/\/raw.githubusercontent.com\/tsparticles\/plugin-template\/main\/images\/sample.png\)/g,
136
+ to: `![demo](https://raw.githubusercontent.com/${repoPath}/main/images/sample.png)`,
137
+ },
138
+ ],
139
+ });
143
140
  }
144
141
 
145
142
  /**
@@ -149,7 +146,7 @@ async function updateReadmeFile(destPath: string, name: string, description: str
149
146
  * @param description - The description of the project
150
147
  */
151
148
  async function updatePluginWebpackFile(destPath: string, name: string, description: string): Promise<void> {
152
- await updateWebpackFile(destPath, camelize(capitalize(name, "-", " ")), description, "loadParticlesPlugin");
149
+ await updateWebpackFile(destPath, camelize(capitalize(name, "-", " ")), description, "loadParticlesPlugin");
153
150
  }
154
151
 
155
152
  /**
@@ -160,25 +157,25 @@ async function updatePluginWebpackFile(destPath: string, name: string, descripti
160
157
  * @param destPath - The path where the project is located
161
158
  */
162
159
  export async function createPluginTemplate(
163
- name: string,
164
- description: string,
165
- repoUrl: string,
166
- destPath: string,
160
+ name: string,
161
+ description: string,
162
+ repoUrl: string,
163
+ destPath: string,
167
164
  ): Promise<void> {
168
- const sourcePath = path.join(__dirname, "..", "..", "..", "files", "create-plugin");
165
+ const sourcePath = path.join(__dirname, "..", "..", "..", "files", "create-plugin");
169
166
 
170
- await copyEmptyTemplateFiles(destPath);
167
+ await copyEmptyTemplateFiles(destPath);
171
168
 
172
- await fs.copy(sourcePath, destPath, {
173
- overwrite: true,
174
- filter: copyFilter,
175
- });
169
+ await fs.copy(sourcePath, destPath, {
170
+ overwrite: true,
171
+ filter: copyFilter,
172
+ });
176
173
 
177
- await updateIndexFile(destPath, name);
178
- await updatePluginPackageFile(destPath, name, description, repoUrl);
179
- await updatePluginPackageDistFile(destPath, name, description, repoUrl);
180
- await updateReadmeFile(destPath, name, description, repoUrl);
181
- await updatePluginWebpackFile(destPath, name, description);
182
- await runInstall(destPath);
183
- await runBuild(destPath);
174
+ await updateIndexFile(destPath, name);
175
+ await updatePluginPackageFile(destPath, name, description, repoUrl);
176
+ await updatePluginPackageDistFile(destPath, name, description, repoUrl);
177
+ await updateReadmeFile(destPath, name, description, repoUrl);
178
+ await updatePluginWebpackFile(destPath, name, description);
179
+ await runInstall(destPath);
180
+ await runBuild(destPath);
184
181
  }
@@ -10,38 +10,38 @@ const pluginCommand = new Command("plugin");
10
10
  pluginCommand.description("Create a new tsParticles plugin");
11
11
  pluginCommand.argument("<destination>", "Destination folder");
12
12
  pluginCommand.action(async (destination: string) => {
13
- const destPath = await getDestinationDir(destination),
14
- repoUrl = await getRepositoryUrl(),
15
- initialName = destPath.split(path.sep).pop(),
16
- questions: PromptObject[] = [
17
- {
18
- type: "text",
19
- name: "name",
20
- message: "What is the name of the plugin?",
21
- validate: (value: string) => (value ? true : "The name can't be empty"),
22
- initial: initialName,
23
- },
24
- {
25
- type: "text",
26
- name: "description",
27
- message: "What is the description of the plugin?",
28
- validate: (value: string) => (value ? true : "The description can't be empty"),
29
- initial: capitalize(initialName ?? ""),
30
- },
31
- {
32
- type: "text",
33
- name: "repositoryUrl",
34
- message: "What is the repository URL? (optional)",
35
- initial: repoUrl.trim(),
36
- },
37
- ],
38
- { name, description, repositoryUrl } = (await prompts(questions)) as {
39
- description: string;
40
- name: string;
41
- repositoryUrl: string;
42
- };
13
+ const destPath = await getDestinationDir(destination),
14
+ repoUrl = await getRepositoryUrl(),
15
+ initialName = destPath.split(path.sep).pop(),
16
+ questions: PromptObject[] = [
17
+ {
18
+ type: "text",
19
+ name: "name",
20
+ message: "What is the name of the plugin?",
21
+ validate: (value: string) => (value ? true : "The name can't be empty"),
22
+ initial: initialName,
23
+ },
24
+ {
25
+ type: "text",
26
+ name: "description",
27
+ message: "What is the description of the plugin?",
28
+ validate: (value: string) => (value ? true : "The description can't be empty"),
29
+ initial: capitalize(initialName ?? ""),
30
+ },
31
+ {
32
+ type: "text",
33
+ name: "repositoryUrl",
34
+ message: "What is the repository URL? (optional)",
35
+ initial: repoUrl.trim(),
36
+ },
37
+ ],
38
+ { name, description, repositoryUrl } = (await prompts(questions)) as {
39
+ description: string;
40
+ name: string;
41
+ repositoryUrl: string;
42
+ };
43
43
 
44
- await createPluginTemplate(name.trim(), description.trim(), repositoryUrl.trim(), destPath);
44
+ await createPluginTemplate(name.trim(), description.trim(), repositoryUrl.trim(), destPath);
45
45
  });
46
46
 
47
47
  export { pluginCommand };
@@ -1,12 +1,12 @@
1
1
  import { camelize, capitalize, dash } from "../../utils/string-utils.js";
2
2
  import {
3
- copyEmptyTemplateFiles,
4
- copyFilter,
5
- runBuild,
6
- runInstall,
7
- updatePackageDistFile,
8
- updatePackageFile,
9
- updateWebpackFile,
3
+ copyEmptyTemplateFiles,
4
+ copyFilter,
5
+ runBuild,
6
+ runInstall,
7
+ updatePackageDistFile,
8
+ updatePackageFile,
9
+ updateWebpackFile,
10
10
  } from "../../utils/template-utils.js";
11
11
  import fs from "fs-extra";
12
12
  import path from "path";
@@ -18,17 +18,17 @@ import { replaceTokensInFile } from "../../utils/file-utils.js";
18
18
  * @param name - The name of the project
19
19
  */
20
20
  async function updateBundleFile(destPath: string, name: string): Promise<void> {
21
- const capitalizedName = capitalize(name, "-", " ");
22
-
23
- await replaceTokensInFile({
24
- path: path.join(destPath, "src", "bundle.ts"),
25
- tokens: [
26
- {
27
- from: /loadTemplatePreset/g,
28
- to: `load${capitalizedName}Preset`,
29
- },
30
- ],
31
- });
21
+ const capitalizedName = capitalize(name, "-", " ");
22
+
23
+ await replaceTokensInFile({
24
+ path: path.join(destPath, "src", "bundle.ts"),
25
+ tokens: [
26
+ {
27
+ from: /loadTemplatePreset/g,
28
+ to: `load${capitalizedName}Preset`,
29
+ },
30
+ ],
31
+ });
32
32
  }
33
33
 
34
34
  /**
@@ -37,22 +37,22 @@ async function updateBundleFile(destPath: string, name: string): Promise<void> {
37
37
  * @param name - The name of the project
38
38
  */
39
39
  async function updateIndexFile(destPath: string, name: string): Promise<void> {
40
- const capitalizedName = capitalize(name, "-", " "),
41
- camelizedName = camelize(capitalizedName);
42
-
43
- await replaceTokensInFile({
44
- path: path.join(destPath, "src", "index.ts"),
45
- tokens: [
46
- {
47
- from: /loadTemplatePreset/g,
48
- to: `load${capitalizedName}Preset`,
49
- },
50
- {
51
- from: /"#template#"/g,
52
- to: `"${camelizedName}"`,
53
- },
54
- ],
55
- });
40
+ const capitalizedName = capitalize(name, "-", " "),
41
+ camelizedName = camelize(capitalizedName);
42
+
43
+ await replaceTokensInFile({
44
+ path: path.join(destPath, "src", "index.ts"),
45
+ tokens: [
46
+ {
47
+ from: /loadTemplatePreset/g,
48
+ to: `load${capitalizedName}Preset`,
49
+ },
50
+ {
51
+ from: /"#template#"/g,
52
+ to: `"${camelizedName}"`,
53
+ },
54
+ ],
55
+ });
56
56
  }
57
57
 
58
58
  /**
@@ -63,21 +63,21 @@ async function updateIndexFile(destPath: string, name: string): Promise<void> {
63
63
  * @param repoUrl - The repository url
64
64
  */
65
65
  async function updatePresetPackageFile(
66
- destPath: string,
67
- name: string,
68
- description: string,
69
- repoUrl: string,
66
+ destPath: string,
67
+ name: string,
68
+ description: string,
69
+ repoUrl: string,
70
70
  ): Promise<void> {
71
- const camelizedName = camelize(name, "-", " "),
72
- dashedName = dash(camelizedName);
73
-
74
- await updatePackageFile(
75
- destPath,
76
- `tsparticles-preset-${dashedName}`,
77
- description,
78
- `tsparticles.preset.${camelizedName}.min.js`,
79
- repoUrl,
80
- );
71
+ const camelizedName = camelize(name, "-", " "),
72
+ dashedName = dash(camelizedName);
73
+
74
+ await updatePackageFile(
75
+ destPath,
76
+ `tsparticles-preset-${dashedName}`,
77
+ description,
78
+ `tsparticles.preset.${camelizedName}.min.js`,
79
+ repoUrl,
80
+ );
81
81
  }
82
82
 
83
83
  /**
@@ -88,21 +88,21 @@ async function updatePresetPackageFile(
88
88
  * @param repoUrl - The repository url
89
89
  */
90
90
  async function updatePresetPackageDistFile(
91
- destPath: string,
92
- name: string,
93
- description: string,
94
- repoUrl: string,
91
+ destPath: string,
92
+ name: string,
93
+ description: string,
94
+ repoUrl: string,
95
95
  ): Promise<void> {
96
- const camelizedName = camelize(name, "-", " "),
97
- dashedName = dash(camelizedName);
98
-
99
- await updatePackageDistFile(
100
- destPath,
101
- `tsparticles-preset-${dashedName}`,
102
- description,
103
- `tsparticles.preset.${camelizedName}.min.js`,
104
- repoUrl,
105
- );
96
+ const camelizedName = camelize(name, "-", " "),
97
+ dashedName = dash(camelizedName);
98
+
99
+ await updatePackageDistFile(
100
+ destPath,
101
+ `tsparticles-preset-${dashedName}`,
102
+ description,
103
+ `tsparticles.preset.${camelizedName}.min.js`,
104
+ repoUrl,
105
+ );
106
106
  }
107
107
 
108
108
  /**
@@ -113,51 +113,48 @@ async function updatePresetPackageDistFile(
113
113
  * @param repoUrl - The repository url
114
114
  */
115
115
  async function updateReadmeFile(destPath: string, name: string, description: string, repoUrl: string): Promise<void> {
116
- const capitalizedName = capitalize(name, "-", " "),
117
- camelizedName = camelize(capitalizedName),
118
- dashedName = dash(camelizedName),
119
- stringSearch = "github.com",
120
- trailingSlashSearch = "github.com/",
121
- repoPath = repoUrl.includes(stringSearch)
122
- ? repoUrl.substring(
123
- repoUrl.indexOf(trailingSlashSearch) + trailingSlashSearch.length,
124
- repoUrl.indexOf(".git"),
125
- )
126
- : "tsparticles/preset-template";
127
-
128
- await replaceTokensInFile({
129
- path: path.join(destPath, "README.md"),
130
- tokens: [
131
- {
132
- from: /tsParticles Template Preset/g,
133
- to: `tsParticles ${description} Preset`,
134
- },
135
- {
136
- from: /tsparticles-preset-template/g,
137
- to: `tsparticles-preset-${dashedName}`,
138
- },
139
- {
140
- from: /tsparticles\.preset\.template(\.bundle)?\.min\.js/g,
141
- to: `tsparticles.preset.${camelizedName}$1.min.js`,
142
- },
143
- {
144
- from: /loadTemplatePreset/g,
145
- to: `load${capitalizedName}Preset`,
146
- },
147
- {
148
- from: /\[tsParticles]\(https:\/\/github.com\/matteobruni\/tsparticles\) preset template\./g,
149
- to: `[tsParticles](https://github.com/matteobruni/tsparticles) preset ${name}.`,
150
- },
151
- {
152
- from: /preset: "template"/g,
153
- to: `preset: "${camelizedName}`,
154
- },
155
- {
156
- from: /!\[demo]\(https:\/\/raw.githubusercontent.com\/tsparticles\/preset-template\/main\/images\/sample.png\)/g,
157
- to: `![demo](https://raw.githubusercontent.com/${repoPath}/main/images/sample.png)`,
158
- },
159
- ],
160
- });
116
+ const capitalizedName = capitalize(name, "-", " "),
117
+ camelizedName = camelize(capitalizedName),
118
+ dashedName = dash(camelizedName),
119
+ stringSearch = "github.com",
120
+ trailingSlashSearch = "github.com/",
121
+ repoPath = repoUrl.includes(stringSearch)
122
+ ? repoUrl.substring(repoUrl.indexOf(trailingSlashSearch) + trailingSlashSearch.length, repoUrl.indexOf(".git"))
123
+ : "tsparticles/preset-template";
124
+
125
+ await replaceTokensInFile({
126
+ path: path.join(destPath, "README.md"),
127
+ tokens: [
128
+ {
129
+ from: /tsParticles Template Preset/g,
130
+ to: `tsParticles ${description} Preset`,
131
+ },
132
+ {
133
+ from: /tsparticles-preset-template/g,
134
+ to: `tsparticles-preset-${dashedName}`,
135
+ },
136
+ {
137
+ from: /tsparticles\.preset\.template(\.bundle)?\.min\.js/g,
138
+ to: `tsparticles.preset.${camelizedName}$1.min.js`,
139
+ },
140
+ {
141
+ from: /loadTemplatePreset/g,
142
+ to: `load${capitalizedName}Preset`,
143
+ },
144
+ {
145
+ from: /\[tsParticles]\(https:\/\/github.com\/matteobruni\/tsparticles\) preset template\./g,
146
+ to: `[tsParticles](https://github.com/matteobruni/tsparticles) preset ${name}.`,
147
+ },
148
+ {
149
+ from: /preset: "template"/g,
150
+ to: `preset: "${camelizedName}`,
151
+ },
152
+ {
153
+ from: /!\[demo]\(https:\/\/raw.githubusercontent.com\/tsparticles\/preset-template\/main\/images\/sample.png\)/g,
154
+ to: `![demo](https://raw.githubusercontent.com/${repoPath}/main/images/sample.png)`,
155
+ },
156
+ ],
157
+ });
161
158
  }
162
159
 
163
160
  /**
@@ -167,7 +164,7 @@ async function updateReadmeFile(destPath: string, name: string, description: str
167
164
  * @param description - The description of the project
168
165
  */
169
166
  async function updatePresetWebpackFile(destPath: string, name: string, description: string): Promise<void> {
170
- await updateWebpackFile(destPath, camelize(capitalize(name, "-", " ")), description, "loadParticlesPreset");
167
+ await updateWebpackFile(destPath, camelize(capitalize(name, "-", " ")), description, "loadParticlesPreset");
171
168
  }
172
169
 
173
170
  /**
@@ -178,27 +175,27 @@ async function updatePresetWebpackFile(destPath: string, name: string, descripti
178
175
  * @param destPath - The path where the project is located
179
176
  */
180
177
  export async function createPresetTemplate(
181
- name: string,
182
- description: string,
183
- repoUrl: string,
184
- destPath: string,
178
+ name: string,
179
+ description: string,
180
+ repoUrl: string,
181
+ destPath: string,
185
182
  ): Promise<void> {
186
- const sourcePath = path.join(__dirname, "..", "..", "..", "files", "create-preset");
183
+ const sourcePath = path.join(__dirname, "..", "..", "..", "files", "create-preset");
187
184
 
188
- await copyEmptyTemplateFiles(destPath);
185
+ await copyEmptyTemplateFiles(destPath);
189
186
 
190
- await fs.copy(sourcePath, destPath, {
191
- overwrite: true,
192
- filter: copyFilter,
193
- });
187
+ await fs.copy(sourcePath, destPath, {
188
+ overwrite: true,
189
+ filter: copyFilter,
190
+ });
194
191
 
195
- await updateBundleFile(destPath, name);
196
- await updateIndexFile(destPath, name);
197
- await updatePresetPackageFile(destPath, name, description, repoUrl);
198
- await updatePresetPackageDistFile(destPath, name, description, repoUrl);
199
- await updateReadmeFile(destPath, name, description, repoUrl);
200
- await updatePresetWebpackFile(destPath, name, description);
192
+ await updateBundleFile(destPath, name);
193
+ await updateIndexFile(destPath, name);
194
+ await updatePresetPackageFile(destPath, name, description, repoUrl);
195
+ await updatePresetPackageDistFile(destPath, name, description, repoUrl);
196
+ await updateReadmeFile(destPath, name, description, repoUrl);
197
+ await updatePresetWebpackFile(destPath, name, description);
201
198
 
202
- await runInstall(destPath);
203
- await runBuild(destPath);
199
+ await runInstall(destPath);
200
+ await runBuild(destPath);
204
201
  }