@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.
- package/.github/workflows/node.js-ci.yml +13 -7
- package/dist/build/build-bundle.d.ts +5 -0
- package/dist/build/build-circular-deps.d.ts +6 -0
- package/dist/build/build-clear.d.ts +5 -0
- package/dist/build/build-distfiles.d.ts +5 -0
- package/dist/build/build-distfiles.js +7 -8
- package/dist/build/build-diststats.d.ts +12 -0
- package/dist/build/build-eslint.d.ts +5 -0
- package/dist/build/build-eslint.js +1 -3
- package/dist/build/build-prettier.d.ts +25 -0
- package/dist/build/build-prettier.js +4 -4
- package/dist/build/build-tsc.d.ts +5 -0
- package/dist/build/build.d.ts +3 -0
- package/dist/cli.d.ts +2 -0
- package/dist/create/create.d.ts +3 -0
- package/dist/create/plugin/create-plugin.d.ts +8 -0
- package/dist/create/plugin/plugin.d.ts +3 -0
- package/dist/create/preset/create-preset.d.ts +8 -0
- package/dist/create/preset/preset.d.ts +3 -0
- package/dist/create/shape/create-shape.d.ts +8 -0
- package/dist/create/shape/shape.d.ts +3 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/utils/file-utils.d.ts +28 -0
- package/dist/utils/string-utils.d.ts +20 -0
- package/dist/utils/template-utils.d.ts +47 -0
- package/files/create-plugin/src/PluginInstance.ts +4 -2
- package/files/create-plugin/src/index.ts +1 -1
- package/files/create-plugin/src/plugin.ts +6 -6
- package/files/empty-project/.browserslistrc +1 -1
- package/files/empty-project/package.dist.json +1 -1
- package/files/empty-project/package.json +9 -9
- package/files/empty-project/tsconfig.base.json +2 -1
- package/package.json +14 -14
- package/src/build/build-bundle.ts +34 -34
- package/src/build/build-circular-deps.ts +23 -23
- package/src/build/build-clear.ts +11 -11
- package/src/build/build-distfiles.ts +67 -70
- package/src/build/build-diststats.ts +41 -41
- package/src/build/build-eslint.ts +26 -28
- package/src/build/build-prettier.ts +166 -166
- package/src/build/build-tsc.ts +146 -149
- package/src/build/build.ts +116 -116
- package/src/cli.ts +3 -3
- package/src/create/plugin/create-plugin.ts +108 -111
- package/src/create/plugin/plugin.ts +31 -31
- package/src/create/preset/create-preset.ts +123 -126
- package/src/create/preset/preset.ts +31 -31
- package/src/create/shape/create-shape.ts +112 -115
- package/src/create/shape/shape.ts +31 -31
- package/src/tsconfig.json +7 -125
- package/src/utils/file-utils.ts +35 -35
- package/src/utils/string-utils.ts +13 -13
- package/src/utils/template-utils.ts +130 -130
- package/tests/create-plugin.test.ts +11 -3
- package/tests/create-preset.test.ts +10 -2
- package/tests/create-shape.test.ts +10 -2
- package/tests/tsconfig.json +3 -15
- package/tsconfig.json +53 -20
- package/.mocharc.json +0 -11
- 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
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
-
|
|
22
|
-
|
|
21
|
+
const capitalizedName = capitalize(name, "-", " "),
|
|
22
|
+
camelizedName = camelize(capitalizedName);
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
47
|
+
destPath: string,
|
|
48
|
+
name: string,
|
|
49
|
+
description: string,
|
|
50
|
+
repoUrl: string,
|
|
51
51
|
): Promise<void> {
|
|
52
|
-
|
|
53
|
-
|
|
52
|
+
const camelizedName = camelize(camelize(name, "-"), " "),
|
|
53
|
+
dashedName = dash(camelizedName);
|
|
54
54
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
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
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
72
|
+
destPath: string,
|
|
73
|
+
name: string,
|
|
74
|
+
description: string,
|
|
75
|
+
repoUrl: string,
|
|
76
76
|
): Promise<void> {
|
|
77
|
-
|
|
78
|
-
|
|
77
|
+
const camelizedName = camelize(camelize(name, "-"), " "),
|
|
78
|
+
dashedName = dash(camelizedName);
|
|
79
79
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
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
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
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
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
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: ``,
|
|
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
|
-
|
|
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
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
160
|
+
name: string,
|
|
161
|
+
description: string,
|
|
162
|
+
repoUrl: string,
|
|
163
|
+
destPath: string,
|
|
167
164
|
): Promise<void> {
|
|
168
|
-
|
|
165
|
+
const sourcePath = path.join(__dirname, "..", "..", "..", "files", "create-plugin");
|
|
169
166
|
|
|
170
|
-
|
|
167
|
+
await copyEmptyTemplateFiles(destPath);
|
|
171
168
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
169
|
+
await fs.copy(sourcePath, destPath, {
|
|
170
|
+
overwrite: true,
|
|
171
|
+
filter: copyFilter,
|
|
172
|
+
});
|
|
176
173
|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
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
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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
|
-
|
|
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
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
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
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
66
|
+
destPath: string,
|
|
67
|
+
name: string,
|
|
68
|
+
description: string,
|
|
69
|
+
repoUrl: string,
|
|
70
70
|
): Promise<void> {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
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
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
91
|
+
destPath: string,
|
|
92
|
+
name: string,
|
|
93
|
+
description: string,
|
|
94
|
+
repoUrl: string,
|
|
95
95
|
): Promise<void> {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
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
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
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: ``,
|
|
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
|
-
|
|
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
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
178
|
+
name: string,
|
|
179
|
+
description: string,
|
|
180
|
+
repoUrl: string,
|
|
181
|
+
destPath: string,
|
|
185
182
|
): Promise<void> {
|
|
186
|
-
|
|
183
|
+
const sourcePath = path.join(__dirname, "..", "..", "..", "files", "create-preset");
|
|
187
184
|
|
|
188
|
-
|
|
185
|
+
await copyEmptyTemplateFiles(destPath);
|
|
189
186
|
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
187
|
+
await fs.copy(sourcePath, destPath, {
|
|
188
|
+
overwrite: true,
|
|
189
|
+
filter: copyFilter,
|
|
190
|
+
});
|
|
194
191
|
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
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
|
-
|
|
203
|
-
|
|
199
|
+
await runInstall(destPath);
|
|
200
|
+
await runBuild(destPath);
|
|
204
201
|
}
|