@tsparticles/cli-command-create 4.0.0-beta.12 → 4.0.0-beta.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.
package/src/create.ts CHANGED
@@ -1,14 +1,26 @@
1
1
  import { Command } from "commander";
2
- import { pluginCommand } from "./plugin/plugin.js";
3
- import { presetCommand } from "./preset/preset.js";
4
- import { shapeCommand } from "./shape/shape.js";
2
+ import { bundleCreateCommand } from "@tsparticles/cli-command-create-bundle";
3
+ import { effectCreateCommand } from "@tsparticles/cli-command-create-effect";
4
+ import { interactionCreateCommand } from "@tsparticles/cli-command-create-interaction";
5
+ import { paletteCreateCommand } from "@tsparticles/cli-command-create-palette";
6
+ import { pathCreateCommand } from "@tsparticles/cli-command-create-path";
7
+ import { pluginCreateCommand } from "@tsparticles/cli-command-create-plugin";
8
+ import { presetCreateCommand } from "@tsparticles/cli-command-create-preset";
9
+ import { shapeCreateCommand } from "@tsparticles/cli-command-create-shape";
10
+ import { updaterCreateCommand } from "@tsparticles/cli-command-create-updater";
5
11
 
6
12
  const createCommand = new Command("create");
7
13
 
8
14
  createCommand.description("Create a new tsParticles project");
9
15
 
10
- createCommand.addCommand(pluginCommand);
11
- createCommand.addCommand(presetCommand);
12
- createCommand.addCommand(shapeCommand);
16
+ createCommand.addCommand(bundleCreateCommand);
17
+ createCommand.addCommand(effectCreateCommand);
18
+ createCommand.addCommand(interactionCreateCommand);
19
+ createCommand.addCommand(paletteCreateCommand);
20
+ createCommand.addCommand(pathCreateCommand);
21
+ createCommand.addCommand(pluginCreateCommand);
22
+ createCommand.addCommand(presetCreateCommand);
23
+ createCommand.addCommand(shapeCreateCommand);
24
+ createCommand.addCommand(updaterCreateCommand);
13
25
 
14
26
  export { createCommand };
@@ -1 +0,0 @@
1
- [{"/Users/matteo/Projects/GitHub/tsparticles/tsparticles/cli/commands/create/src/create.ts":"1","/Users/matteo/Projects/GitHub/tsparticles/tsparticles/cli/commands/create/src/plugin/create-plugin.ts":"2","/Users/matteo/Projects/GitHub/tsparticles/tsparticles/cli/commands/create/src/plugin/plugin.ts":"3","/Users/matteo/Projects/GitHub/tsparticles/tsparticles/cli/commands/create/src/preset/create-preset.ts":"4","/Users/matteo/Projects/GitHub/tsparticles/tsparticles/cli/commands/create/src/preset/preset.ts":"5","/Users/matteo/Projects/GitHub/tsparticles/tsparticles/cli/commands/create/src/shape/create-shape.ts":"6","/Users/matteo/Projects/GitHub/tsparticles/tsparticles/cli/commands/create/src/shape/shape.ts":"7"},{"size":450,"mtime":1777824895211,"results":"8","hashOfConfig":"9"},{"size":5871,"mtime":1777824895211,"results":"10","hashOfConfig":"9"},{"size":1625,"mtime":1777824895211,"results":"11","hashOfConfig":"9"},{"size":6342,"mtime":1777992492247,"results":"12","hashOfConfig":"9"},{"size":1625,"mtime":1777824895211,"results":"13","hashOfConfig":"9"},{"size":5838,"mtime":1777824895211,"results":"14","hashOfConfig":"9"},{"size":1613,"mtime":1777824895212,"results":"15","hashOfConfig":"9"},{"filePath":"16","messages":"17","suppressedMessages":"18","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"jp9a30",{"filePath":"19","messages":"20","suppressedMessages":"21","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"22","messages":"23","suppressedMessages":"24","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"25","messages":"26","suppressedMessages":"27","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"28","messages":"29","suppressedMessages":"30","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"31","messages":"32","suppressedMessages":"33","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"34","messages":"35","suppressedMessages":"36","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"/Users/matteo/Projects/GitHub/tsparticles/tsparticles/cli/commands/create/src/create.ts",[],[],"/Users/matteo/Projects/GitHub/tsparticles/tsparticles/cli/commands/create/src/plugin/create-plugin.ts",[],[],"/Users/matteo/Projects/GitHub/tsparticles/tsparticles/cli/commands/create/src/plugin/plugin.ts",[],[],"/Users/matteo/Projects/GitHub/tsparticles/tsparticles/cli/commands/create/src/preset/create-preset.ts",[],[],"/Users/matteo/Projects/GitHub/tsparticles/tsparticles/cli/commands/create/src/preset/preset.ts",[],[],"/Users/matteo/Projects/GitHub/tsparticles/tsparticles/cli/commands/create/src/shape/create-shape.ts",[],[],"/Users/matteo/Projects/GitHub/tsparticles/tsparticles/cli/commands/create/src/shape/shape.ts",[],[]]
@@ -1,8 +0,0 @@
1
- /**
2
- * Creates the plugin project
3
- * @param name - The name of the project
4
- * @param description - The description of the project
5
- * @param repoUrl - The repository url
6
- * @param destPath - The path where the project is located
7
- */
8
- export declare function createPluginTemplate(name: string, description: string, repoUrl: string, destPath: string): Promise<void>;
@@ -1,136 +0,0 @@
1
- import { camelize, capitalize, copyEmptyTemplateFiles, copyFilter, dash, replaceTokensInFile, runBuild, runInstall, updatePackageDistFile, updatePackageFile, updateWebpackFile, } from "@tsparticles/cli-create-utils";
2
- import { cp } from "node:fs/promises";
3
- import path from "node:path";
4
- /**
5
- * Updates the index file with the correct function name
6
- * @param destPath - The path where the project is located
7
- * @param name - The name of the project
8
- */
9
- async function updateIndexFile(destPath, name) {
10
- const capitalizedName = capitalize(name, "-", " "), camelizedName = camelize(capitalizedName);
11
- await replaceTokensInFile({
12
- path: path.join(destPath, "src", "index.ts"),
13
- tokens: [
14
- {
15
- from: /loadTemplatePlugin/g,
16
- to: `load${capitalizedName}Plugin`,
17
- },
18
- {
19
- from: /"#template#"/g,
20
- to: `"${camelizedName}"`,
21
- },
22
- ],
23
- });
24
- await replaceTokensInFile({
25
- path: path.join(destPath, "src", "index.lazy.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
- }
38
- /**
39
- * Updates the plugin package file
40
- * @param destPath - The path where the project is located
41
- * @param name - The name of the project
42
- * @param description - The description of the project
43
- * @param repoUrl - The repository url
44
- */
45
- async function updatePluginPackageFile(destPath, name, description, repoUrl) {
46
- const camelizedName = camelize(camelize(name, "-"), " "), dashedName = dash(camelizedName);
47
- await updatePackageFile(destPath, `tsparticles-plugin-${dashedName}`, description, `tsparticles.plugin.${camelizedName}.min.js`, repoUrl);
48
- }
49
- /**
50
- * Updates the plugin package dist file
51
- * @param destPath - The path where the project is located
52
- * @param name - The name of the project
53
- * @param description - The description of the project
54
- * @param repoUrl - The repository url
55
- */
56
- async function updatePluginPackageDistFile(destPath, name, description, repoUrl) {
57
- const camelizedName = camelize(camelize(name, "-"), " "), dashedName = dash(camelizedName);
58
- await updatePackageDistFile(destPath, `tsparticles-plugin-${dashedName}`, description, `tsparticles.plugin.${camelizedName}.min.js`, repoUrl);
59
- }
60
- /**
61
- * Updates the plugin readme file
62
- * @param destPath - The path where the project is located
63
- * @param name - The name of the project
64
- * @param description - The description of the project
65
- * @param repoUrl - The repository url
66
- */
67
- async function updateReadmeFile(destPath, name, description, repoUrl) {
68
- const readmePath = path.join(destPath, "README.md"), capitalizedName = capitalize(name, "-", " "), camelizedName = camelize(capitalizedName), dashedName = dash(camelizedName), stringSearch = "github.com", trailingSlashSearch = "github.com/", repoPath = repoUrl.includes(stringSearch)
69
- ? repoUrl.substring(repoUrl.indexOf(trailingSlashSearch) + trailingSlashSearch.length, repoUrl.indexOf(".git"))
70
- : "tsparticles/plugin-template";
71
- await replaceTokensInFile({
72
- path: readmePath,
73
- tokens: [
74
- {
75
- from: /tsParticles Template Plugin/g,
76
- to: `tsParticles ${description} Plugin`,
77
- },
78
- {
79
- from: /tsparticles-plugin-template/g,
80
- to: `tsparticles-plugin-${dashedName}`,
81
- },
82
- {
83
- from: /tsparticles\.plugin\.template(\.bundle)?\.min\.js/g,
84
- to: `tsparticles.plugin.${camelizedName}$1.min.js`,
85
- },
86
- {
87
- from: /loadTemplatePlugin/g,
88
- to: `load${capitalizedName}Plugin`,
89
- },
90
- {
91
- from: /\[tsParticles]\(https:\/\/github.com\/matteobruni\/tsparticles\) additional template plugin\./g,
92
- to: `[tsParticles](https://github.com/matteobruni/tsparticles) additional ${name} plugin.`,
93
- },
94
- {
95
- from: /plugin\.type: "template"/g,
96
- to: `plugin.type: "${camelizedName}"`,
97
- },
98
- {
99
- from: /!\[demo]\(https:\/\/raw.githubusercontent.com\/tsparticles\/plugin-template\/main\/images\/sample.png\)/g,
100
- to: `![demo](https://raw.githubusercontent.com/${repoPath}/main/images/sample.png)`,
101
- },
102
- ],
103
- });
104
- }
105
- /**
106
- * Updates the plugin webpack file
107
- * @param destPath - The path where the project is located
108
- * @param name - The name of the project
109
- * @param description - The description of the project
110
- */
111
- async function updatePluginWebpackFile(destPath, name, description) {
112
- await updateWebpackFile(destPath, camelize(capitalize(name, "-", " ")), description, "loadParticlesPlugin");
113
- }
114
- /**
115
- * Creates the plugin project
116
- * @param name - The name of the project
117
- * @param description - The description of the project
118
- * @param repoUrl - The repository url
119
- * @param destPath - The path where the project is located
120
- */
121
- export async function createPluginTemplate(name, description, repoUrl, destPath) {
122
- const sourcePath = path.join(__dirname, "..", "..", "files", "create-plugin");
123
- await copyEmptyTemplateFiles(destPath);
124
- await cp(sourcePath, destPath, {
125
- recursive: true,
126
- force: true,
127
- filter: copyFilter,
128
- });
129
- await updateIndexFile(destPath, name);
130
- await updatePluginPackageFile(destPath, name, description, repoUrl);
131
- await updatePluginPackageDistFile(destPath, name, description, repoUrl);
132
- await updateReadmeFile(destPath, name, description, repoUrl);
133
- await updatePluginWebpackFile(destPath, name, description);
134
- await runInstall(destPath);
135
- await runBuild(destPath);
136
- }
@@ -1,3 +0,0 @@
1
- import { Command } from "commander";
2
- declare const pluginCommand: Command;
3
- export { pluginCommand };
@@ -1,34 +0,0 @@
1
- import { capitalize, getDestinationDir, getRepositoryUrl } from "@tsparticles/cli-create-utils";
2
- import prompts from "prompts";
3
- import { Command } from "commander";
4
- import { createPluginTemplate } from "./create-plugin.js";
5
- import path from "node:path";
6
- const pluginCommand = new Command("plugin");
7
- pluginCommand.description("Create a new tsParticles plugin");
8
- pluginCommand.argument("<destination>", "Destination folder");
9
- pluginCommand.action(async (destination) => {
10
- const destPath = await getDestinationDir(destination), repoUrl = await getRepositoryUrl(), initialName = destPath.split(path.sep).pop(), questions = [
11
- {
12
- type: "text",
13
- name: "name",
14
- message: "What is the name of the plugin?",
15
- validate: (value) => (value ? true : "The name can't be empty"),
16
- initial: initialName,
17
- },
18
- {
19
- type: "text",
20
- name: "description",
21
- message: "What is the description of the plugin?",
22
- validate: (value) => (value ? true : "The description can't be empty"),
23
- initial: capitalize(initialName ?? ""),
24
- },
25
- {
26
- type: "text",
27
- name: "repositoryUrl",
28
- message: "What is the repository URL? (optional)",
29
- initial: repoUrl.trim(),
30
- },
31
- ], { name, description, repositoryUrl } = (await prompts(questions));
32
- await createPluginTemplate(name.trim(), description.trim(), repositoryUrl.trim(), destPath);
33
- });
34
- export { pluginCommand };
@@ -1,8 +0,0 @@
1
- /**
2
- * Creates the preset project
3
- * @param name - The name of the project
4
- * @param description - The description of the project
5
- * @param repoUrl - The repository url
6
- * @param destPath - The path where the project is located
7
- */
8
- export declare function createPresetTemplate(name: string, description: string, repoUrl: string, destPath: string): Promise<void>;
@@ -1,154 +0,0 @@
1
- import { camelize, capitalize, copyEmptyTemplateFiles, copyFilter, dash, replaceTokensInFile, runBuild, runInstall, updatePackageDistFile, updatePackageFile, updateWebpackFile, } from "@tsparticles/cli-create-utils";
2
- import { cp } from "node:fs/promises";
3
- import path from "node:path";
4
- /**
5
- * Updates the bundle file with the correct function name
6
- * @param destPath - The path where the project is located
7
- * @param name - The name of the project
8
- */
9
- async function updateBundleFile(destPath, name) {
10
- const capitalizedName = capitalize(name, "-", " ");
11
- await replaceTokensInFile({
12
- path: path.join(destPath, "src", "bundle.ts"),
13
- tokens: [
14
- {
15
- from: /loadTemplatePreset/g,
16
- to: `load${capitalizedName}Preset`,
17
- },
18
- ],
19
- });
20
- }
21
- /**
22
- * Updates the index file with the correct function name
23
- * @param destPath - The path where the project is located
24
- * @param name - The name of the project
25
- */
26
- async function updateIndexFile(destPath, name) {
27
- const capitalizedName = capitalize(name, "-", " "), camelizedName = camelize(capitalizedName);
28
- await replaceTokensInFile({
29
- path: path.join(destPath, "src", "index.ts"),
30
- tokens: [
31
- {
32
- from: /loadTemplatePreset/g,
33
- to: `load${capitalizedName}Preset`,
34
- },
35
- {
36
- from: /"#template#"/g,
37
- to: `"${camelizedName}"`,
38
- },
39
- ],
40
- });
41
- await replaceTokensInFile({
42
- path: path.join(destPath, "src", "index.lazy.ts"),
43
- tokens: [
44
- {
45
- from: /loadTemplatePreset/g,
46
- to: `load${capitalizedName}Preset`,
47
- },
48
- {
49
- from: /"#template#"/g,
50
- to: `"${camelizedName}"`,
51
- },
52
- ],
53
- });
54
- }
55
- /**
56
- * Updates the preset package file
57
- * @param destPath - The path where the project is located
58
- * @param name - The name of the project
59
- * @param description - The description of the project
60
- * @param repoUrl - The repository url
61
- */
62
- async function updatePresetPackageFile(destPath, name, description, repoUrl) {
63
- const camelizedName = camelize(name, "-", " "), dashedName = dash(camelizedName);
64
- await updatePackageFile(destPath, `tsparticles-preset-${dashedName}`, description, `tsparticles.preset.${camelizedName}.min.js`, repoUrl);
65
- }
66
- /**
67
- * Updates the preset package dist file
68
- * @param destPath - The path where the project is located
69
- * @param name - The name of the project
70
- * @param description - The description of the project
71
- * @param repoUrl - The repository url
72
- */
73
- async function updatePresetPackageDistFile(destPath, name, description, repoUrl) {
74
- const camelizedName = camelize(name, "-", " "), dashedName = dash(camelizedName);
75
- await updatePackageDistFile(destPath, `tsparticles-preset-${dashedName}`, description, `tsparticles.preset.${camelizedName}.min.js`, repoUrl);
76
- }
77
- /**
78
- * Updates the preset readme file
79
- * @param destPath - The path where the project is located
80
- * @param name - The name of the project
81
- * @param description - The description of the project
82
- * @param repoUrl - The repository url
83
- */
84
- async function updateReadmeFile(destPath, name, description, repoUrl) {
85
- const capitalizedName = capitalize(name, "-", " "), camelizedName = camelize(capitalizedName), dashedName = dash(camelizedName), stringSearch = "github.com", trailingSlashSearch = "github.com/", repoPath = repoUrl.includes(stringSearch)
86
- ? repoUrl.substring(repoUrl.indexOf(trailingSlashSearch) + trailingSlashSearch.length, repoUrl.indexOf(".git"))
87
- : "tsparticles/preset-template";
88
- await replaceTokensInFile({
89
- path: path.join(destPath, "README.md"),
90
- tokens: [
91
- {
92
- from: /tsParticles Template Preset/g,
93
- to: `tsParticles ${description} Preset`,
94
- },
95
- {
96
- from: /tsparticles-preset-template/g,
97
- to: `tsparticles-preset-${dashedName}`,
98
- },
99
- {
100
- from: /tsparticles\.preset\.template(\.bundle)?\.min\.js/g,
101
- to: `tsparticles.preset.${camelizedName}$1.min.js`,
102
- },
103
- {
104
- from: /loadTemplatePreset/g,
105
- to: `load${capitalizedName}Preset`,
106
- },
107
- {
108
- from: /\[tsParticles]\(https:\/\/github.com\/matteobruni\/tsparticles\) preset template\./g,
109
- to: `[tsParticles](https://github.com/matteobruni/tsparticles) preset ${name}.`,
110
- },
111
- {
112
- from: /preset: "template"/g,
113
- to: `preset: "${camelizedName}`,
114
- },
115
- {
116
- from: /!\[demo]\(https:\/\/raw.githubusercontent.com\/tsparticles\/preset-template\/main\/images\/sample.png\)/g,
117
- to: `![demo](https://raw.githubusercontent.com/${repoPath}/main/images/sample.png)`,
118
- },
119
- ],
120
- });
121
- }
122
- /**
123
- * Updates the preset webpack file
124
- * @param destPath - The path where the project is located
125
- * @param name - The name of the project
126
- * @param description - The description of the project
127
- */
128
- async function updatePresetWebpackFile(destPath, name, description) {
129
- await updateWebpackFile(destPath, camelize(capitalize(name, "-", " ")), description, "loadParticlesPreset");
130
- }
131
- /**
132
- * Creates the preset project
133
- * @param name - The name of the project
134
- * @param description - The description of the project
135
- * @param repoUrl - The repository url
136
- * @param destPath - The path where the project is located
137
- */
138
- export async function createPresetTemplate(name, description, repoUrl, destPath) {
139
- const sourcePath = path.join(__dirname, "..", "..", "files", "create-preset");
140
- await copyEmptyTemplateFiles(destPath);
141
- await cp(sourcePath, destPath, {
142
- recursive: true,
143
- force: true,
144
- filter: copyFilter,
145
- });
146
- await updateBundleFile(destPath, name);
147
- await updateIndexFile(destPath, name);
148
- await updatePresetPackageFile(destPath, name, description, repoUrl);
149
- await updatePresetPackageDistFile(destPath, name, description, repoUrl);
150
- await updateReadmeFile(destPath, name, description, repoUrl);
151
- await updatePresetWebpackFile(destPath, name, description);
152
- await runInstall(destPath);
153
- await runBuild(destPath);
154
- }
@@ -1,3 +0,0 @@
1
- import { Command } from "commander";
2
- declare const presetCommand: Command;
3
- export { presetCommand };
@@ -1,34 +0,0 @@
1
- import { capitalize, getDestinationDir, getRepositoryUrl } from "@tsparticles/cli-create-utils";
2
- import prompts from "prompts";
3
- import { Command } from "commander";
4
- import { createPresetTemplate } from "./create-preset.js";
5
- import path from "node:path";
6
- const presetCommand = new Command("preset");
7
- presetCommand.description("Create a new tsParticles preset");
8
- presetCommand.argument("<destination>", "Destination folder");
9
- presetCommand.action(async (destination) => {
10
- const destPath = await getDestinationDir(destination), repoUrl = await getRepositoryUrl(), initialName = destPath.split(path.sep).pop(), questions = [
11
- {
12
- type: "text",
13
- name: "name",
14
- message: "What is the name of the preset?",
15
- validate: (value) => (value ? true : "The name can't be empty"),
16
- initial: initialName,
17
- },
18
- {
19
- type: "text",
20
- name: "description",
21
- message: "What is the description of the preset?",
22
- validate: (value) => (value ? true : "The description can't be empty"),
23
- initial: capitalize(initialName ?? ""),
24
- },
25
- {
26
- type: "text",
27
- name: "repositoryUrl",
28
- message: "What is the repository URL? (optional)",
29
- initial: repoUrl.trim(),
30
- },
31
- ], { name, description, repositoryUrl } = (await prompts(questions));
32
- await createPresetTemplate(name.trim(), description.trim(), repositoryUrl.trim(), destPath);
33
- });
34
- export { presetCommand };
@@ -1,8 +0,0 @@
1
- /**
2
- * Creates the shape project
3
- * @param name - The name of the project
4
- * @param description - The description of the project
5
- * @param repoUrl - The repository url
6
- * @param destPath - The path where the project is located
7
- */
8
- export declare function createShapeTemplate(name: string, description: string, repoUrl: string, destPath: string): Promise<void>;
@@ -1,137 +0,0 @@
1
- import { camelize, capitalize, copyEmptyTemplateFiles, copyFilter, dash, replaceTokensInFile, runBuild, runInstall, updatePackageDistFile, updatePackageFile, updateWebpackFile, } from "@tsparticles/cli-create-utils";
2
- import { cp } from "node:fs/promises";
3
- import path from "node:path";
4
- /**
5
- * Updates the index file with the correct function name
6
- * @param destPath - The path where the project is located
7
- * @param name - The name of the project
8
- */
9
- async function updateIndexFile(destPath, name) {
10
- const capitalizedName = capitalize(name, "-", " "), camelizedName = camelize(capitalizedName);
11
- await replaceTokensInFile({
12
- path: path.join(destPath, "src", "index.ts"),
13
- tokens: [
14
- {
15
- from: /loadTemplateShape/g,
16
- to: `load${capitalizedName}Shape`,
17
- },
18
- ],
19
- });
20
- await replaceTokensInFile({
21
- path: path.join(destPath, "src", "index.lazy.ts"),
22
- tokens: [
23
- {
24
- from: /loadTemplateShape/g,
25
- to: `load${capitalizedName}Shape`,
26
- },
27
- ],
28
- });
29
- await replaceTokensInFile({
30
- path: path.join(destPath, "src", "ShapeDrawer.ts"),
31
- tokens: [
32
- {
33
- from: /"#template#"/g,
34
- to: `"${camelizedName}"`,
35
- },
36
- ],
37
- });
38
- }
39
- /**
40
- * Updates the shape package file
41
- * @param destPath - The path where the project is located
42
- * @param name - The name of the project
43
- * @param description - The description of the project
44
- * @param repoUrl - The repository url
45
- */
46
- async function updateShapePackageFile(destPath, name, description, repoUrl) {
47
- const camelizedName = camelize(camelize(name, "-"), " "), dashedName = dash(camelizedName);
48
- await updatePackageFile(destPath, `tsparticles-shape-${dashedName}`, description, `tsparticles.shape.${camelizedName}.min.js`, repoUrl);
49
- }
50
- /**
51
- * Updates the shape package dist file
52
- * @param destPath - The path where the project is located
53
- * @param name - The name of the project
54
- * @param description - The description of the project
55
- * @param repoUrl - The repository url
56
- */
57
- async function updateShapePackageDistFile(destPath, name, description, repoUrl) {
58
- const camelizedName = camelize(camelize(name, "-"), " "), dashedName = dash(camelizedName);
59
- await updatePackageDistFile(destPath, `tsparticles-shape-${dashedName}`, description, `tsparticles.shape.${camelizedName}.min.js`, repoUrl);
60
- }
61
- /**
62
- * Updates the shape readme file
63
- * @param destPath - The path where the project is located
64
- * @param name - The name of the project
65
- * @param description - The description of the project
66
- * @param repoUrl - The repository url
67
- */
68
- async function updateReadmeFile(destPath, name, description, repoUrl) {
69
- const capitalizedName = capitalize(name, "-", " "), camelizedName = camelize(capitalizedName), dashedName = dash(camelizedName), stringSearch = "github.com", trailingSlashSearch = "github.com/", repoPath = repoUrl.includes(stringSearch)
70
- ? repoUrl.substring(repoUrl.indexOf(trailingSlashSearch) + trailingSlashSearch.length, repoUrl.indexOf(".git"))
71
- : "tsparticles/shape-template";
72
- await replaceTokensInFile({
73
- path: path.join(destPath, "README.md"),
74
- tokens: [
75
- {
76
- from: /tsParticles Template Shape/g,
77
- to: `tsParticles ${description} Shape`,
78
- },
79
- {
80
- from: /tsparticles-shape-template/g,
81
- to: `tsparticles-shape-${dashedName}`,
82
- },
83
- {
84
- from: /tsparticles\.shape\.template(\.bundle)?\.min\.js/g,
85
- to: `tsparticles.shape.${camelizedName}$1.min.js`,
86
- },
87
- {
88
- from: /loadTemplateShape/g,
89
- to: `load${capitalizedName}Shape`,
90
- },
91
- {
92
- from: /\[tsParticles]\(https:\/\/github.com\/matteobruni\/tsparticles\) additional template shape\./g,
93
- to: `[tsParticles](https://github.com/matteobruni/tsparticles) additional ${name} shape.`,
94
- },
95
- {
96
- from: /shape\.type: "template"/g,
97
- to: `shape.type: "${camelizedName}`,
98
- },
99
- {
100
- from: /!\[demo]\(https:\/\/raw.githubusercontent.com\/tsparticles\/shape-template\/main\/images\/sample.png\)/g,
101
- to: `![demo](https://raw.githubusercontent.com/${repoPath}/main/images/sample.png)`,
102
- },
103
- ],
104
- });
105
- }
106
- /**
107
- * Updates the shape webpack file
108
- * @param destPath - The path where the project is located
109
- * @param name - The name of the project
110
- * @param description - The description of the project
111
- */
112
- async function updateShapeWebpackFile(destPath, name, description) {
113
- await updateWebpackFile(destPath, camelize(capitalize(name, "-", " ")), description, "loadParticlesShape");
114
- }
115
- /**
116
- * Creates the shape project
117
- * @param name - The name of the project
118
- * @param description - The description of the project
119
- * @param repoUrl - The repository url
120
- * @param destPath - The path where the project is located
121
- */
122
- export async function createShapeTemplate(name, description, repoUrl, destPath) {
123
- const sourcePath = path.join(__dirname, "..", "..", "files", "create-shape");
124
- await copyEmptyTemplateFiles(destPath);
125
- await cp(sourcePath, destPath, {
126
- recursive: true,
127
- force: true,
128
- filter: copyFilter,
129
- });
130
- await updateIndexFile(destPath, name);
131
- await updateShapePackageFile(destPath, name, description, repoUrl);
132
- await updateShapePackageDistFile(destPath, name, description, repoUrl);
133
- await updateReadmeFile(destPath, name, description, repoUrl);
134
- await updateShapeWebpackFile(destPath, name, description);
135
- await runInstall(destPath);
136
- await runBuild(destPath);
137
- }
@@ -1,3 +0,0 @@
1
- import { Command } from "commander";
2
- declare const shapeCommand: Command;
3
- export { shapeCommand };
@@ -1,34 +0,0 @@
1
- import { capitalize, getDestinationDir, getRepositoryUrl } from "@tsparticles/cli-create-utils";
2
- import prompts from "prompts";
3
- import { Command } from "commander";
4
- import { createShapeTemplate } from "./create-shape.js";
5
- import path from "node:path";
6
- const shapeCommand = new Command("shape");
7
- shapeCommand.description("Create a new tsParticles shape");
8
- shapeCommand.argument("<destination>", "Destination folder");
9
- shapeCommand.action(async (destination) => {
10
- const destPath = await getDestinationDir(destination), repoUrl = await getRepositoryUrl(), initialName = destPath.split(path.sep).pop(), questions = [
11
- {
12
- type: "text",
13
- name: "name",
14
- message: "What is the name of the shape?",
15
- validate: (value) => (value ? true : "The name can't be empty"),
16
- initial: initialName,
17
- },
18
- {
19
- type: "text",
20
- name: "description",
21
- message: "What is the description of the shape?",
22
- validate: (value) => (value ? true : "The description can't be empty"),
23
- initial: capitalize(initialName ?? ""),
24
- },
25
- {
26
- type: "text",
27
- name: "repositoryUrl",
28
- message: "What is the repository URL? (optional)",
29
- initial: repoUrl.trim(),
30
- },
31
- ], { name, description, repositoryUrl } = (await prompts(questions));
32
- await createShapeTemplate(name.trim(), description.trim(), repositoryUrl.trim(), destPath);
33
- });
34
- export { shapeCommand };