@tsparticles/cli 1.11.0 → 1.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/node.js-ci.yml +2 -0
- package/.mocharc.json +11 -0
- package/dist/build/build.js +1 -1
- package/dist/cli.js +2 -2
- package/dist/create/plugin/create-plugin.js +53 -8
- package/dist/create/plugin/plugin.js +3 -18
- package/dist/create/preset/create-preset.js +65 -12
- package/dist/create/preset/preset.js +3 -18
- package/dist/create/shape/create-shape.js +53 -8
- package/dist/create/shape/shape.js +3 -18
- package/dist/utils/file-utils.js +62 -0
- package/dist/utils/string-utils.js +13 -7
- package/dist/utils/template-utils.js +77 -8
- package/files/create-preset/README.md +3 -3
- package/files/empty-project/package.dist.json +1 -1
- package/files/empty-project/package.json +3 -3
- package/package.json +19 -12
- package/scripts/postversion.js +1 -1
- package/src/build/build.ts +1 -1
- package/src/cli.ts +2 -2
- package/src/create/plugin/create-plugin.ts +58 -56
- package/src/create/plugin/plugin.ts +4 -24
- package/src/create/preset/create-preset.ts +73 -68
- package/src/create/preset/preset.ts +4 -24
- package/src/create/shape/create-shape.ts +58 -54
- package/src/create/shape/shape.ts +4 -24
- package/src/utils/file-utils.ts +75 -0
- package/src/utils/string-utils.ts +14 -7
- package/src/utils/template-utils.ts +77 -45
- package/tests/create-plugin.test.ts +31 -0
- package/tests/create-preset.test.ts +31 -0
- package/tests/create-shape.test.ts +31 -0
- package/tests/file-utils.test.ts +101 -0
- package/tests/string-utils.test.ts +125 -0
- package/tests/tsconfig.json +24 -0
|
@@ -7,6 +7,7 @@ exports.runBuild = exports.runInstall = exports.copyFilter = exports.copyEmptyTe
|
|
|
7
7
|
const child_process_1 = require("child_process");
|
|
8
8
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
9
9
|
const path_1 = __importDefault(require("path"));
|
|
10
|
+
const file_utils_1 = require("./file-utils");
|
|
10
11
|
/**
|
|
11
12
|
* Updates the package.json file
|
|
12
13
|
* @param destPath - The path where the package.json file is located
|
|
@@ -16,8 +17,35 @@ const path_1 = __importDefault(require("path"));
|
|
|
16
17
|
* @param repoUrl - The repository URL
|
|
17
18
|
*/
|
|
18
19
|
async function updatePackageFile(destPath, packageName, description, fileName, repoUrl) {
|
|
19
|
-
|
|
20
|
-
|
|
20
|
+
await (0, file_utils_1.replaceTokensInFile)({
|
|
21
|
+
path: path_1.default.resolve(destPath, "package.json"),
|
|
22
|
+
tokens: [
|
|
23
|
+
{
|
|
24
|
+
from: /"tsParticles empty template"/g,
|
|
25
|
+
to: `"${description}"`,
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
from: /"tsparticles.empty.template.min.js"/g,
|
|
29
|
+
to: `"${fileName}"`,
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
from: /\s{4}"private": true,\r?\n?/g,
|
|
33
|
+
to: "",
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
from: /"@tsparticles\/empty-template"/g,
|
|
37
|
+
to: `"${packageName}"`,
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
from: /"url": "git\+https:\/\/github\.com\/tsparticles\/empty-template\.git"/g,
|
|
41
|
+
to: `"url": "git+${repoUrl}"`,
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
from: /"url": "https:\/\/github\.com\/tsparticles\/empty-template\/issues"/g,
|
|
45
|
+
to: `"url": "${repoUrl.replace(".git", "/issues")}"`,
|
|
46
|
+
},
|
|
47
|
+
],
|
|
48
|
+
});
|
|
21
49
|
}
|
|
22
50
|
exports.updatePackageFile = updatePackageFile;
|
|
23
51
|
/**
|
|
@@ -29,8 +57,35 @@ exports.updatePackageFile = updatePackageFile;
|
|
|
29
57
|
* @param repoUrl - The url of the repository
|
|
30
58
|
*/
|
|
31
59
|
async function updatePackageDistFile(destPath, packageName, description, fileName, repoUrl) {
|
|
32
|
-
|
|
33
|
-
|
|
60
|
+
await (0, file_utils_1.replaceTokensInFile)({
|
|
61
|
+
path: path_1.default.resolve(destPath, "package.dist.json"),
|
|
62
|
+
tokens: [
|
|
63
|
+
{
|
|
64
|
+
from: /"tsParticles empty template"/g,
|
|
65
|
+
to: `"${description}"`,
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
from: /"tsparticles.empty.template.min.js"/g,
|
|
69
|
+
to: `"${fileName}"`,
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
from: /\s{4}"private": true,\r?\n?/g,
|
|
73
|
+
to: "",
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
from: /"@tsparticles\/empty-template"/g,
|
|
77
|
+
to: `"${packageName}"`,
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
from: /"url": "git\+https:\/\/github\.com\/tsparticles\/empty-template\.git"/g,
|
|
81
|
+
to: `"url": "git+${repoUrl}"`,
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
from: /"url": "https:\/\/github\.com\/tsparticles\/empty-template\/issues"/g,
|
|
85
|
+
to: `"url": "${repoUrl.replace(".git", "/issues")}"`,
|
|
86
|
+
},
|
|
87
|
+
],
|
|
88
|
+
});
|
|
34
89
|
}
|
|
35
90
|
exports.updatePackageDistFile = updatePackageDistFile;
|
|
36
91
|
/**
|
|
@@ -41,8 +96,23 @@ exports.updatePackageDistFile = updatePackageDistFile;
|
|
|
41
96
|
* @param fnName - The name of the function to load the template
|
|
42
97
|
*/
|
|
43
98
|
async function updateWebpackFile(destPath, name, description, fnName) {
|
|
44
|
-
|
|
45
|
-
|
|
99
|
+
await (0, file_utils_1.replaceTokensInFile)({
|
|
100
|
+
path: path_1.default.resolve(destPath, "webpack.config.js"),
|
|
101
|
+
tokens: [
|
|
102
|
+
{
|
|
103
|
+
from: /"Empty"/g,
|
|
104
|
+
to: `"${description}"`,
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
from: /"empty"/g,
|
|
108
|
+
to: `"${name}"`,
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
from: /loadParticlesTemplate/g,
|
|
112
|
+
to: fnName,
|
|
113
|
+
},
|
|
114
|
+
],
|
|
115
|
+
});
|
|
46
116
|
}
|
|
47
117
|
exports.updateWebpackFile = updateWebpackFile;
|
|
48
118
|
/**
|
|
@@ -50,8 +120,7 @@ exports.updateWebpackFile = updateWebpackFile;
|
|
|
50
120
|
* @param destPath - The path where the project will be created
|
|
51
121
|
*/
|
|
52
122
|
async function copyEmptyTemplateFiles(destPath) {
|
|
53
|
-
|
|
54
|
-
await fs_extra_1.default.copy(emptyPath, destPath, {
|
|
123
|
+
await fs_extra_1.default.copy(path_1.default.resolve(__dirname, "..", "..", "files", "empty-project"), destPath, {
|
|
55
124
|
overwrite: true,
|
|
56
125
|
filter: copyFilter,
|
|
57
126
|
});
|
|
@@ -21,8 +21,8 @@ Once installed you need one more script to be included in your page (or you can
|
|
|
21
21
|
from [jsDelivr](https://www.jsdelivr.com/package/npm/tsparticles-preset-template):
|
|
22
22
|
|
|
23
23
|
```html
|
|
24
|
-
<script src="https://cdn.jsdelivr.net/npm/tsparticles@
|
|
25
|
-
<script src="https://cdn.jsdelivr.net/npm/tsparticles-preset-template
|
|
24
|
+
<script src="https://cdn.jsdelivr.net/npm/tsparticles-engine@2/tsparticles.engine.min.js"></script>
|
|
25
|
+
<script src="https://cdn.jsdelivr.net/npm/tsparticles-preset-template/tsparticles.preset.template.min.js"></script>
|
|
26
26
|
```
|
|
27
27
|
|
|
28
28
|
This script **MUST** be placed after the `tsParticles` one.
|
|
@@ -32,7 +32,7 @@ This script **MUST** be placed after the `tsParticles` one.
|
|
|
32
32
|
A bundled script can also be used, this will include every needed plugin needed by the preset.
|
|
33
33
|
|
|
34
34
|
```html
|
|
35
|
-
<script src="https://cdn.jsdelivr.net/npm/tsparticles-preset-template
|
|
35
|
+
<script src="https://cdn.jsdelivr.net/npm/tsparticles-preset-template/tsparticles.preset.template.bundle.min.js"></script>
|
|
36
36
|
```
|
|
37
37
|
|
|
38
38
|
### Usage
|
|
@@ -83,7 +83,7 @@
|
|
|
83
83
|
"prettier": "@tsparticles/prettier-config",
|
|
84
84
|
"devDependencies": {
|
|
85
85
|
"@babel/core": "^7.22.9",
|
|
86
|
-
"@tsparticles/cli": "1.
|
|
86
|
+
"@tsparticles/cli": "^1.13.0",
|
|
87
87
|
"@tsparticles/eslint-config": "^1.19.0",
|
|
88
88
|
"@tsparticles/prettier-config": "^1.12.0",
|
|
89
89
|
"@tsparticles/tsconfig": "^1.14.0",
|
|
@@ -95,7 +95,7 @@
|
|
|
95
95
|
"browserslist": "^4.21.10",
|
|
96
96
|
"copyfiles": "^2.4.1",
|
|
97
97
|
"eslint": "^8.46.0",
|
|
98
|
-
"eslint-config-prettier": "^
|
|
98
|
+
"eslint-config-prettier": "^9.0.0",
|
|
99
99
|
"prettier": "^3.0.1",
|
|
100
100
|
"rimraf": "^5.0.1",
|
|
101
101
|
"terser-webpack-plugin": "^5.3.9",
|
|
@@ -105,6 +105,6 @@
|
|
|
105
105
|
"webpack-cli": "^5.1.4"
|
|
106
106
|
},
|
|
107
107
|
"dependencies": {
|
|
108
|
-
"tsparticles-engine": "^2.
|
|
108
|
+
"tsparticles-engine": "^2.12.0"
|
|
109
109
|
}
|
|
110
110
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsparticles/cli",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.13.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"bin": {
|
|
6
6
|
"tsparticles-cli": "dist/cli.js"
|
|
@@ -10,32 +10,38 @@
|
|
|
10
10
|
},
|
|
11
11
|
"prettier": "@tsparticles/prettier-config",
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@tsparticles/eslint-config": "^1.
|
|
13
|
+
"@tsparticles/eslint-config": "^1.20.0",
|
|
14
14
|
"@tsparticles/prettier-config": "^1.12.0",
|
|
15
15
|
"@tsparticles/tsconfig": "^1.14.0",
|
|
16
|
-
"@tsparticles/webpack-plugin": "^1.
|
|
17
|
-
"@typescript-eslint/eslint-plugin": "^6.
|
|
18
|
-
"@typescript-eslint/parser": "^6.
|
|
16
|
+
"@tsparticles/webpack-plugin": "^1.24.0",
|
|
17
|
+
"@typescript-eslint/eslint-plugin": "^6.3.0",
|
|
18
|
+
"@typescript-eslint/parser": "^6.3.0",
|
|
19
19
|
"commander": "^11.0.0",
|
|
20
|
-
"eslint": "^8.
|
|
21
|
-
"eslint-config-prettier": "^
|
|
22
|
-
"eslint-plugin-jsdoc": "^46.4.
|
|
20
|
+
"eslint": "^8.46.0",
|
|
21
|
+
"eslint-config-prettier": "^9.0.0",
|
|
22
|
+
"eslint-plugin-jsdoc": "^46.4.6",
|
|
23
23
|
"eslint-plugin-tsdoc": "^0.2.17",
|
|
24
24
|
"fs-extra": "^11.1.1",
|
|
25
25
|
"klaw": "^4.1.0",
|
|
26
26
|
"path-scurry": "^1.10.1",
|
|
27
|
-
"prettier": "^3.0.
|
|
27
|
+
"prettier": "^3.0.1",
|
|
28
28
|
"prompts": "^2.4.2",
|
|
29
29
|
"rimraf": "^5.0.1",
|
|
30
30
|
"typescript": "^5.1.6",
|
|
31
31
|
"webpack": "^5.88.2"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
|
-
"@types/
|
|
34
|
+
"@types/chai": "^4.3.5",
|
|
35
35
|
"@types/fs-extra": "^11.0.1",
|
|
36
36
|
"@types/klaw": "^3.0.3",
|
|
37
|
-
"@types/
|
|
38
|
-
"@types/
|
|
37
|
+
"@types/mocha": "^10.0.1",
|
|
38
|
+
"@types/node": "^20.4.8",
|
|
39
|
+
"@types/prompts": "^2.4.4",
|
|
40
|
+
"chai": "^4.3.7",
|
|
41
|
+
"cross-env": "^7.0.3",
|
|
42
|
+
"mocha": "^10.2.0",
|
|
43
|
+
"nyc": "^15.1.0",
|
|
44
|
+
"ts-node": "^10.9.1"
|
|
39
45
|
},
|
|
40
46
|
"description": "tsParticles CLI",
|
|
41
47
|
"main": ".eslintrc.js",
|
|
@@ -51,6 +57,7 @@
|
|
|
51
57
|
"compile:ci": "pnpm run build:ts",
|
|
52
58
|
"build:ts": "pnpm run build:ts:cjs",
|
|
53
59
|
"build:ts:cjs": "tsc -p src",
|
|
60
|
+
"test": "cross-env TS_NODE_PROJECT='./tests/tsconfig.json' nyc mocha --timeout 300000",
|
|
54
61
|
"build": "pnpm run clear:dist && pnpm run prettify:src && pnpm run lint && pnpm run compile && pnpm run prettify:readme && chmod +x dist/cli.js && chmod +x dist/build/build.js && chmod +x dist/create/create.js && chmod +x dist/create/preset/preset.js",
|
|
55
62
|
"build:ci": "pnpm run clear:dist && pnpm run prettify:ci:src && pnpm run lint:ci && pnpm run compile && pnpm run prettify:ci:readme",
|
|
56
63
|
"clear:dist": "rimraf ./dist",
|
package/scripts/postversion.js
CHANGED
|
@@ -14,7 +14,7 @@ const emptyProjectPkgPath = path.join(__dirname, "..", "files", "empty-project",
|
|
|
14
14
|
|
|
15
15
|
const obj = JSON.parse(data);
|
|
16
16
|
|
|
17
|
-
obj["devDependencies"]["@tsparticles/cli"] = pkg.version
|
|
17
|
+
obj["devDependencies"]["@tsparticles/cli"] = `^${pkg.version}`;
|
|
18
18
|
|
|
19
19
|
const result = JSON.stringify(obj, undefined, 2);
|
|
20
20
|
|
package/src/build/build.ts
CHANGED
|
@@ -11,7 +11,7 @@ import path from "path";
|
|
|
11
11
|
|
|
12
12
|
const buildCommand = new Command("build");
|
|
13
13
|
|
|
14
|
-
buildCommand.description("Build the library using TypeScript");
|
|
14
|
+
buildCommand.description("Build the tsParticles library using TypeScript");
|
|
15
15
|
buildCommand.option(
|
|
16
16
|
"-a, --all",
|
|
17
17
|
"Do all build steps (default if no flags are specified) (same as -b -c -d -l -p -t)",
|
package/src/cli.ts
CHANGED
|
@@ -4,8 +4,8 @@ import { createCommand } from "./create/create";
|
|
|
4
4
|
import pkgInfo from "../package.json";
|
|
5
5
|
import { program } from "commander";
|
|
6
6
|
|
|
7
|
-
program.name("tsparticles-cli
|
|
8
|
-
program.description("tsParticles
|
|
7
|
+
program.name("tsparticles-cli");
|
|
8
|
+
program.description("tsParticles CLI");
|
|
9
9
|
program.version(pkgInfo.version, "-v, --version", "output the current version");
|
|
10
10
|
program.addCommand(buildCommand);
|
|
11
11
|
program.addCommand(createCommand);
|
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
} from "../../utils/template-utils";
|
|
11
11
|
import fs from "fs-extra";
|
|
12
12
|
import path from "path";
|
|
13
|
+
import { replaceTokensInFile } from "../../utils/file-utils";
|
|
13
14
|
|
|
14
15
|
/**
|
|
15
16
|
* Updates the index file with the correct function name
|
|
@@ -17,16 +18,22 @@ import path from "path";
|
|
|
17
18
|
* @param name - The name of the project
|
|
18
19
|
*/
|
|
19
20
|
async function updateIndexFile(destPath: string, name: string): Promise<void> {
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
capitalizedName = capitalize(capitalize(name, "-"), " "),
|
|
23
|
-
camelizedName = camelize(capitalizedName),
|
|
24
|
-
indexFunctionRegex = /loadTemplatePlugin/g,
|
|
25
|
-
replacedFuncText = index.replace(indexFunctionRegex, `load${capitalizedName}Plugin`),
|
|
26
|
-
indexNameRegex = /"#template#"/g,
|
|
27
|
-
replacedNameText = replacedFuncText.replace(indexNameRegex, `"${camelizedName}"`);
|
|
21
|
+
const capitalizedName = capitalize(name, "-", " "),
|
|
22
|
+
camelizedName = camelize(capitalizedName);
|
|
28
23
|
|
|
29
|
-
await
|
|
24
|
+
await replaceTokensInFile({
|
|
25
|
+
path: path.resolve(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
|
+
});
|
|
30
37
|
}
|
|
31
38
|
|
|
32
39
|
/**
|
|
@@ -45,11 +52,11 @@ async function updatePluginPackageFile(
|
|
|
45
52
|
const camelizedName = camelize(camelize(name, "-"), " "),
|
|
46
53
|
dashedName = dash(camelizedName);
|
|
47
54
|
|
|
48
|
-
updatePackageFile(
|
|
55
|
+
await updatePackageFile(
|
|
49
56
|
destPath,
|
|
50
|
-
`
|
|
57
|
+
`tsparticles-plugin-${dashedName}`,
|
|
51
58
|
description,
|
|
52
|
-
`
|
|
59
|
+
`tsparticles.plugin.${camelizedName}.min.js`,
|
|
53
60
|
repoUrl,
|
|
54
61
|
);
|
|
55
62
|
}
|
|
@@ -70,11 +77,11 @@ async function updatePluginPackageDistFile(
|
|
|
70
77
|
const camelizedName = camelize(camelize(name, "-"), " "),
|
|
71
78
|
dashedName = dash(camelizedName);
|
|
72
79
|
|
|
73
|
-
updatePackageDistFile(
|
|
80
|
+
await updatePackageDistFile(
|
|
74
81
|
destPath,
|
|
75
|
-
`
|
|
82
|
+
`tsparticles-plugin-${dashedName}`,
|
|
76
83
|
description,
|
|
77
|
-
`
|
|
84
|
+
`tsparticles.plugin.${camelizedName}.min.js`,
|
|
78
85
|
repoUrl,
|
|
79
86
|
);
|
|
80
87
|
}
|
|
@@ -88,46 +95,46 @@ async function updatePluginPackageDistFile(
|
|
|
88
95
|
*/
|
|
89
96
|
async function updateReadmeFile(destPath: string, name: string, description: string, repoUrl: string): Promise<void> {
|
|
90
97
|
const readmePath = path.resolve(destPath, "README.md"),
|
|
91
|
-
|
|
92
|
-
capitalizedName = capitalize(capitalize(name, "-"), " "),
|
|
98
|
+
capitalizedName = capitalize(name, "-", " "),
|
|
93
99
|
camelizedName = camelize(capitalizedName),
|
|
94
100
|
dashedName = dash(camelizedName),
|
|
95
|
-
readmeDescriptionRegex = /tsParticles Template Plugin/g,
|
|
96
|
-
replacedDescriptionText = readme.replace(readmeDescriptionRegex, `tsParticles ${description} Plugin`),
|
|
97
|
-
readmePackageNameRegex = /tsparticles-plugin-template/g,
|
|
98
|
-
replacedPackageNameText = replacedDescriptionText.replace(
|
|
99
|
-
readmePackageNameRegex,
|
|
100
|
-
`tsparticles-plugin-${dashedName}`,
|
|
101
|
-
),
|
|
102
|
-
readmeFileNameRegex = /tsparticles\.plugin\.template(\.bundle)?\.min\.js/g,
|
|
103
|
-
replacedFileNameText = replacedPackageNameText.replace(
|
|
104
|
-
readmeFileNameRegex,
|
|
105
|
-
`tsparticles.plugin.${camelizedName}$1.min.js`,
|
|
106
|
-
),
|
|
107
|
-
readmeFunctionNameRegex = /loadTemplatePlugin/g,
|
|
108
|
-
replacedFunctionNameText = replacedFileNameText.replace(
|
|
109
|
-
readmeFunctionNameRegex,
|
|
110
|
-
`load${capitalizedName}Plugin`,
|
|
111
|
-
),
|
|
112
|
-
readmeMiniDescriptionRegex =
|
|
113
|
-
/\[tsParticles]\(https:\/\/github.com\/matteobruni\/tsparticles\) additional template plugin\./g,
|
|
114
|
-
replacedMiniDescriptionText = replacedFunctionNameText.replace(
|
|
115
|
-
readmeMiniDescriptionRegex,
|
|
116
|
-
`[tsParticles](https://github.com/matteobruni/tsparticles) additional ${name} plugin.`,
|
|
117
|
-
),
|
|
118
|
-
readmeUsageRegex = /plugin\.type: "template"/g,
|
|
119
|
-
replacedUsageText = replacedMiniDescriptionText.replace(readmeUsageRegex, `plugin.type: "${camelizedName}`),
|
|
120
|
-
sampleImageRegex =
|
|
121
|
-
/!\[demo]\(https:\/\/raw.githubusercontent.com\/tsparticles\/plugin-template\/main\/images\/sample.png\)/g,
|
|
122
101
|
repoPath = repoUrl.includes("github.com")
|
|
123
102
|
? repoUrl.substring(repoUrl.indexOf("github.com/") + 11, repoUrl.indexOf(".git"))
|
|
124
|
-
: "tsparticles/plugin-template"
|
|
125
|
-
replacedText = replacedUsageText.replace(
|
|
126
|
-
sampleImageRegex,
|
|
127
|
-
``,
|
|
128
|
-
);
|
|
103
|
+
: "tsparticles/plugin-template";
|
|
129
104
|
|
|
130
|
-
await
|
|
105
|
+
await replaceTokensInFile({
|
|
106
|
+
path: readmePath,
|
|
107
|
+
tokens: [
|
|
108
|
+
{
|
|
109
|
+
from: /tsParticles Template Plugin/g,
|
|
110
|
+
to: `tsParticles ${description} Plugin`,
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
from: /tsparticles-plugin-template/g,
|
|
114
|
+
to: `tsparticles-plugin-${dashedName}`,
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
from: /tsparticles\.plugin\.template(\.bundle)?\.min\.js/g,
|
|
118
|
+
to: `tsparticles.plugin.${camelizedName}$1.min.js`,
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
from: /loadTemplatePlugin/g,
|
|
122
|
+
to: `load${capitalizedName}Plugin`,
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
from: /\[tsParticles]\(https:\/\/github.com\/matteobruni\/tsparticles\) additional template plugin\./g,
|
|
126
|
+
to: `[tsParticles](https://github.com/matteobruni/tsparticles) additional ${name} plugin.`,
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
from: /plugin\.type: "template"/g,
|
|
130
|
+
to: `plugin.type: "${camelizedName}"`,
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
from: /!\[demo]\(https:\/\/raw.githubusercontent.com\/tsparticles\/plugin-template\/main\/images\/sample.png\)/g,
|
|
134
|
+
to: ``,
|
|
135
|
+
},
|
|
136
|
+
],
|
|
137
|
+
});
|
|
131
138
|
}
|
|
132
139
|
|
|
133
140
|
/**
|
|
@@ -137,12 +144,7 @@ async function updateReadmeFile(destPath: string, name: string, description: str
|
|
|
137
144
|
* @param description - The description of the project
|
|
138
145
|
*/
|
|
139
146
|
async function updatePluginWebpackFile(destPath: string, name: string, description: string): Promise<void> {
|
|
140
|
-
await updateWebpackFile(
|
|
141
|
-
destPath,
|
|
142
|
-
camelize(capitalize(capitalize(name, "-"), " ")),
|
|
143
|
-
`tsParticles ${description} Plugin`,
|
|
144
|
-
"loadParticlesPlugin",
|
|
145
|
-
);
|
|
147
|
+
await updateWebpackFile(destPath, camelize(capitalize(name, "-", " ")), description, "loadParticlesPlugin");
|
|
146
148
|
}
|
|
147
149
|
|
|
148
150
|
/**
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
+
import { getDestinationDir, getRepositoryUrl } from "../../utils/file-utils";
|
|
1
2
|
import prompts, { type PromptObject } from "prompts";
|
|
2
3
|
import { Command } from "commander";
|
|
3
4
|
import { capitalize } from "../../utils/string-utils";
|
|
4
5
|
import { createPluginTemplate } from "./create-plugin";
|
|
5
|
-
import { execSync } from "child_process";
|
|
6
|
-
import fs from "fs-extra";
|
|
7
6
|
import path from "path";
|
|
8
7
|
|
|
9
8
|
const pluginCommand = new Command("plugin");
|
|
@@ -11,27 +10,8 @@ const pluginCommand = new Command("plugin");
|
|
|
11
10
|
pluginCommand.description("Create a new tsParticles plugin");
|
|
12
11
|
pluginCommand.argument("<destination>", "Destination folder");
|
|
13
12
|
pluginCommand.action(async (destination: string) => {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const destPath = path.resolve(path.join(process.cwd(), destination)),
|
|
17
|
-
destExists = await fs.pathExists(destPath);
|
|
18
|
-
|
|
19
|
-
if (destExists) {
|
|
20
|
-
const destContents = await fs.readdir(destPath),
|
|
21
|
-
destContentsNoGit = destContents.filter(t => t !== ".git" && t !== ".gitignore");
|
|
22
|
-
|
|
23
|
-
if (destContentsNoGit.length) {
|
|
24
|
-
throw new Error("Destination folder already exists and is not empty");
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
await fs.ensureDir(destPath);
|
|
29
|
-
|
|
30
|
-
try {
|
|
31
|
-
repoUrl = execSync("git config --get remote.origin.url").toString();
|
|
32
|
-
} catch {
|
|
33
|
-
repoUrl = "";
|
|
34
|
-
}
|
|
13
|
+
const destPath = await getDestinationDir(destination),
|
|
14
|
+
repoUrl = getRepositoryUrl();
|
|
35
15
|
|
|
36
16
|
const initialName = destPath.split(path.sep).pop(),
|
|
37
17
|
questions: PromptObject[] = [
|
|
@@ -59,7 +39,7 @@ pluginCommand.action(async (destination: string) => {
|
|
|
59
39
|
|
|
60
40
|
const { name, description, repositoryUrl } = await prompts(questions);
|
|
61
41
|
|
|
62
|
-
createPluginTemplate(name.trim(), description.trim(), repositoryUrl.trim(), destPath);
|
|
42
|
+
await createPluginTemplate(name.trim(), description.trim(), repositoryUrl.trim(), destPath);
|
|
63
43
|
});
|
|
64
44
|
|
|
65
45
|
export { pluginCommand };
|