@tsparticles/cli 3.3.1 → 3.3.3
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/dependabot.yml +7 -0
- package/.planning/codebase/ARCHITECTURE.md +83 -51
- package/.planning/codebase/CONCERNS.md +61 -58
- package/.planning/codebase/CONVENTIONS.md +47 -52
- package/.planning/codebase/INTEGRATIONS.md +26 -17
- package/.planning/codebase/STACK.md +37 -31
- package/.planning/codebase/STRUCTURE.md +87 -53
- package/.planning/codebase/TESTING.md +80 -62
- package/dist/build/build-distfiles.js +14 -13
- package/dist/build/build-diststats.js +8 -7
- package/dist/build/build-prettier.js +16 -15
- package/dist/build/build-tsc.js +4 -3
- package/dist/build/build.js +10 -8
- package/dist/cli.js +3 -3
- package/dist/create/plugin/create-plugin.js +4 -3
- package/dist/create/preset/create-preset.js +4 -3
- package/dist/create/shape/create-shape.js +4 -3
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utils/file-utils.js +8 -7
- package/dist/utils/template-utils.js +4 -3
- package/files/empty-project/package.json +7 -7
- package/files/empty-project/webpack.config.js +11 -11
- package/package.json +9 -11
- package/src/build/build-distfiles.ts +15 -14
- package/src/build/build-diststats.ts +8 -8
- package/src/build/build-prettier.ts +16 -15
- package/src/build/build-tsc.ts +4 -3
- package/src/build/build.ts +10 -10
- package/src/cli.ts +3 -3
- package/src/create/plugin/create-plugin.ts +4 -3
- package/src/create/preset/create-preset.ts +4 -3
- package/src/create/shape/create-shape.ts +4 -3
- package/src/utils/file-utils.ts +8 -7
- package/src/utils/template-utils.ts +4 -3
- package/tests/create-plugin.test.ts +25 -25
- package/tests/create-preset.test.ts +25 -25
- package/tests/create-shape.test.ts +25 -25
- package/tests/file-utils.test.ts +87 -78
- package/tests/tsconfig.json +12 -11
- package/tsconfig.json +52 -53
|
@@ -85,11 +85,11 @@
|
|
|
85
85
|
"devDependencies": {
|
|
86
86
|
"@swc/core": "^1.15.18",
|
|
87
87
|
"@tsparticles/cli": "latest",
|
|
88
|
-
"@tsparticles/depcruise-config": "^3.3.
|
|
89
|
-
"@tsparticles/eslint-config": "^3.3.
|
|
90
|
-
"@tsparticles/prettier-config": "^3.3.
|
|
91
|
-
"@tsparticles/tsconfig": "^3.3.
|
|
92
|
-
"@tsparticles/webpack-plugin": "^3.3.
|
|
88
|
+
"@tsparticles/depcruise-config": "^3.3.1",
|
|
89
|
+
"@tsparticles/eslint-config": "^3.3.1",
|
|
90
|
+
"@tsparticles/prettier-config": "^3.3.1",
|
|
91
|
+
"@tsparticles/tsconfig": "^3.3.1",
|
|
92
|
+
"@tsparticles/webpack-plugin": "^3.3.1",
|
|
93
93
|
"@types/webpack-env": "^1.18.8",
|
|
94
94
|
"browserslist": "^4.28.1",
|
|
95
95
|
"copyfiles": "^2.4.1",
|
|
@@ -98,9 +98,9 @@
|
|
|
98
98
|
"prettier": "^3.8.1",
|
|
99
99
|
"rimraf": "^6.1.3",
|
|
100
100
|
"swc-loader": "^0.2.7",
|
|
101
|
-
"terser-webpack-plugin": "^5.
|
|
101
|
+
"terser-webpack-plugin": "^5.4.0",
|
|
102
102
|
"typescript": "^5.9.3",
|
|
103
|
-
"typescript-eslint": "^8.
|
|
103
|
+
"typescript-eslint": "^8.57.0",
|
|
104
104
|
"webpack": "^5.105.4",
|
|
105
105
|
"webpack-bundle-analyzer": "^5.2.0",
|
|
106
106
|
"webpack-cli": "^6.0.1"
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import {loadParticlesTemplate} from "@tsparticles/webpack-plugin";
|
|
2
|
-
import {fileURLToPath} from "url";
|
|
3
|
-
import
|
|
4
|
-
import path from "path";
|
|
1
|
+
import { loadParticlesTemplate } from "@tsparticles/webpack-plugin";
|
|
2
|
+
import { fileURLToPath } from "node:url";
|
|
3
|
+
import { readFile } from "node:fs/promises";
|
|
4
|
+
import path from "node:path";
|
|
5
5
|
|
|
6
6
|
const __filename = fileURLToPath(import.meta.url),
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
__dirname = path.dirname(__filename),
|
|
8
|
+
rootPkgPath = path.join(__dirname, "package.json"),
|
|
9
|
+
pkg = JSON.parse(await readFile(rootPkgPath, "utf-8"));
|
|
10
10
|
|
|
11
11
|
export default loadParticlesTemplate({
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
moduleName: "empty",
|
|
13
|
+
templateName: "Empty",
|
|
14
|
+
version: pkg.version,
|
|
15
|
+
dir: __dirname,
|
|
16
16
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsparticles/cli",
|
|
3
|
-
"version": "3.3.
|
|
3
|
+
"version": "3.3.3",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -17,18 +17,17 @@
|
|
|
17
17
|
"prettier": "@tsparticles/prettier-config",
|
|
18
18
|
"dependencies": {
|
|
19
19
|
"@swc/core": "^1.15.18",
|
|
20
|
-
"@tsparticles/depcruise-config": "^3.3.
|
|
21
|
-
"@tsparticles/eslint-config": "^3.3.
|
|
22
|
-
"@tsparticles/prettier-config": "^3.3.
|
|
23
|
-
"@tsparticles/tsconfig": "^3.3.
|
|
24
|
-
"@tsparticles/webpack-plugin": "^3.3.
|
|
20
|
+
"@tsparticles/depcruise-config": "^3.3.1",
|
|
21
|
+
"@tsparticles/eslint-config": "^3.3.1",
|
|
22
|
+
"@tsparticles/prettier-config": "^3.3.1",
|
|
23
|
+
"@tsparticles/tsconfig": "^3.3.1",
|
|
24
|
+
"@tsparticles/webpack-plugin": "^3.3.1",
|
|
25
25
|
"commander": "^14.0.3",
|
|
26
26
|
"eslint": "^10.0.3",
|
|
27
27
|
"eslint-config-prettier": "^10.1.8",
|
|
28
28
|
"eslint-plugin-jsdoc": "^62.7.1",
|
|
29
29
|
"eslint-plugin-prettier": "^5.5.5",
|
|
30
30
|
"eslint-plugin-tsdoc": "^0.5.2",
|
|
31
|
-
"fs-extra": "^11.3.4",
|
|
32
31
|
"klaw": "^4.1.0",
|
|
33
32
|
"lookpath": "^1.2.3",
|
|
34
33
|
"dependency-cruiser": "^17.3.8",
|
|
@@ -39,22 +38,21 @@
|
|
|
39
38
|
"rimraf": "^6.1.3",
|
|
40
39
|
"swc-loader": "^0.2.7",
|
|
41
40
|
"typescript": "^5.9.3",
|
|
42
|
-
"typescript-eslint": "^8.
|
|
41
|
+
"typescript-eslint": "^8.57.0",
|
|
43
42
|
"webpack": "^5.105.4"
|
|
44
43
|
},
|
|
45
44
|
"devDependencies": {
|
|
46
45
|
"@tsparticles/cli": "latest",
|
|
47
46
|
"@tsparticles/engine": "^3.9.1",
|
|
48
47
|
"@types/estree": "^1.0.8",
|
|
49
|
-
"@types/fs-extra": "^11.0.4",
|
|
50
48
|
"@types/klaw": "^3.0.7",
|
|
51
|
-
"@types/node": "^25.
|
|
49
|
+
"@types/node": "^25.4.0",
|
|
52
50
|
"@types/prompts": "^2.4.9",
|
|
53
51
|
"@types/webpack-env": "^1.18.8",
|
|
54
52
|
"browserslist": "^4.28.1",
|
|
55
53
|
"copyfiles": "^2.4.1",
|
|
56
54
|
"cross-env": "^10.1.0",
|
|
57
|
-
"terser-webpack-plugin": "^5.
|
|
55
|
+
"terser-webpack-plugin": "^5.4.0",
|
|
58
56
|
"ts-node": "^10.9.2",
|
|
59
57
|
"vitest": "^4.0.18",
|
|
60
58
|
"webpack-bundle-analyzer": "^5.2.0",
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { copyFile, mkdir, readFile, writeFile } from "node:fs/promises";
|
|
2
|
+
import { existsSync } from "node:fs";
|
|
2
3
|
import klaw from "klaw";
|
|
3
4
|
import path from "node:path";
|
|
4
5
|
|
|
@@ -15,7 +16,7 @@ export async function buildDistFiles(basePath: string, silent: boolean): Promise
|
|
|
15
16
|
let res: boolean;
|
|
16
17
|
|
|
17
18
|
try {
|
|
18
|
-
const pkgInfo = JSON.parse((await
|
|
19
|
+
const pkgInfo = JSON.parse((await readFile(path.join(basePath, "package.json"))).toString()) as {
|
|
19
20
|
dependencies?: Record<string, string>;
|
|
20
21
|
peerDependencies?: Record<string, string>;
|
|
21
22
|
publishConfig?: { directory?: string };
|
|
@@ -23,7 +24,7 @@ export async function buildDistFiles(basePath: string, silent: boolean): Promise
|
|
|
23
24
|
},
|
|
24
25
|
libPackage = path.join(basePath, "package.dist.json"),
|
|
25
26
|
distPath = path.join(basePath, pkgInfo.publishConfig?.directory ?? "dist"),
|
|
26
|
-
data = await
|
|
27
|
+
data = await readFile(libPackage),
|
|
27
28
|
text = data.toString(),
|
|
28
29
|
libObj = JSON.parse(text) as Record<string, unknown>;
|
|
29
30
|
|
|
@@ -37,7 +38,7 @@ export async function buildDistFiles(basePath: string, silent: boolean): Promise
|
|
|
37
38
|
|
|
38
39
|
const jsonIndent = 2;
|
|
39
40
|
|
|
40
|
-
await
|
|
41
|
+
await writeFile(libPackage, `${JSON.stringify(libObj, undefined, jsonIndent)}\n`, "utf8");
|
|
41
42
|
|
|
42
43
|
if (!silent) {
|
|
43
44
|
console.log(`package.dist.json updated successfully to version ${pkgInfo.version}`);
|
|
@@ -56,19 +57,19 @@ export async function buildDistFiles(basePath: string, silent: boolean): Promise
|
|
|
56
57
|
const src = path.join(basePath, typeof file === "string" ? file : file.source),
|
|
57
58
|
dest = path.join(distPath, typeof file === "string" ? file : file.destination);
|
|
58
59
|
|
|
59
|
-
await
|
|
60
|
+
await copyFile(src, dest);
|
|
60
61
|
}
|
|
61
62
|
|
|
62
63
|
const scriptsPath = path.join(basePath, "scripts"),
|
|
63
64
|
distScriptsPath = path.join(distPath, "scripts");
|
|
64
65
|
|
|
65
|
-
if ((
|
|
66
|
-
await
|
|
66
|
+
if (existsSync(scriptsPath) && !existsSync(distScriptsPath)) {
|
|
67
|
+
await mkdir(distScriptsPath, { recursive: true });
|
|
67
68
|
|
|
68
69
|
const installPath = path.join(scriptsPath, "install.js");
|
|
69
70
|
|
|
70
|
-
if (
|
|
71
|
-
await
|
|
71
|
+
if (existsSync(installPath)) {
|
|
72
|
+
await copyFile(installPath, path.join(distScriptsPath, "install.js"));
|
|
72
73
|
}
|
|
73
74
|
}
|
|
74
75
|
|
|
@@ -77,9 +78,9 @@ export async function buildDistFiles(basePath: string, silent: boolean): Promise
|
|
|
77
78
|
continue;
|
|
78
79
|
}
|
|
79
80
|
|
|
80
|
-
const contents = await
|
|
81
|
+
const contents = await readFile(file.path, "utf8");
|
|
81
82
|
|
|
82
|
-
await
|
|
83
|
+
await writeFile(file.path, contents.replaceAll("__VERSION__", `"${pkgInfo.version}"`), "utf8");
|
|
83
84
|
}
|
|
84
85
|
|
|
85
86
|
/* for await (const file of klaw(path.join(distPath, "cjs"))) {
|
|
@@ -90,9 +91,9 @@ export async function buildDistFiles(basePath: string, silent: boolean): Promise
|
|
|
90
91
|
await fs.rename(file.path, file.path.replace(/\.js$/, ".mjs"));
|
|
91
92
|
} */
|
|
92
93
|
|
|
93
|
-
await
|
|
94
|
-
await
|
|
95
|
-
await
|
|
94
|
+
await writeFile(path.join(distPath, "cjs", "package.json"), `{ "type": "commonjs" }`);
|
|
95
|
+
await writeFile(path.join(distPath, "esm", "package.json"), `{ "type": "module" }`);
|
|
96
|
+
await writeFile(path.join(distPath, "browser", "package.json"), `{ "type": "module" }`);
|
|
96
97
|
|
|
97
98
|
res = true;
|
|
98
99
|
} catch (e) {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { opendir, readFile, stat } from "node:fs/promises";
|
|
2
|
+
import { existsSync } from "node:fs";
|
|
2
3
|
|
|
3
4
|
export interface IDistStats {
|
|
4
5
|
bundleSize: number;
|
|
@@ -20,11 +21,11 @@ async function getFolderStats(folderPath: string, bundlePath?: string): Promise<
|
|
|
20
21
|
totalSize: 0,
|
|
21
22
|
};
|
|
22
23
|
|
|
23
|
-
if (!(
|
|
24
|
+
if (!existsSync(folderPath)) {
|
|
24
25
|
return stats;
|
|
25
26
|
}
|
|
26
27
|
|
|
27
|
-
const dir = await
|
|
28
|
+
const dir = await opendir(folderPath),
|
|
28
29
|
path = await import("path");
|
|
29
30
|
|
|
30
31
|
for await (const dirent of dir) {
|
|
@@ -37,7 +38,7 @@ async function getFolderStats(folderPath: string, bundlePath?: string): Promise<
|
|
|
37
38
|
stats.totalFiles += subDirStats.totalFiles;
|
|
38
39
|
stats.totalSize += subDirStats.totalSize;
|
|
39
40
|
} else {
|
|
40
|
-
const fileStats = await
|
|
41
|
+
const fileStats = await stat(path.join(folderPath, dirent.name));
|
|
41
42
|
|
|
42
43
|
stats.totalFiles++;
|
|
43
44
|
stats.totalSize += fileStats.size;
|
|
@@ -59,13 +60,12 @@ async function getFolderStats(folderPath: string, bundlePath?: string): Promise<
|
|
|
59
60
|
export async function getDistStats(basePath: string): Promise<IDistStats> {
|
|
60
61
|
const path = await import("path"),
|
|
61
62
|
distFolder = path.join(basePath, "dist"),
|
|
62
|
-
pkgInfo = (
|
|
63
|
-
? (JSON.parse((await
|
|
63
|
+
pkgInfo = existsSync(path.join(distFolder, "package.json"))
|
|
64
|
+
? (JSON.parse((await readFile(path.join(distFolder, "package.json"))).toString()) as {
|
|
64
65
|
jsdelivr?: string;
|
|
65
66
|
})
|
|
66
67
|
: {},
|
|
67
|
-
bundlePath =
|
|
68
|
-
(await fs.exists(distFolder)) && pkgInfo.jsdelivr ? path.join(distFolder, pkgInfo.jsdelivr) : undefined;
|
|
68
|
+
bundlePath = existsSync(distFolder) && pkgInfo.jsdelivr ? path.join(distFolder, pkgInfo.jsdelivr) : undefined;
|
|
69
69
|
|
|
70
70
|
return await getFolderStats(distFolder, bundlePath);
|
|
71
71
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { readFile, writeFile } from "node:fs/promises";
|
|
2
|
+
import { existsSync } from "node:fs";
|
|
2
3
|
import klaw from "klaw";
|
|
3
4
|
import path from "node:path";
|
|
4
5
|
import prettier from "prettier";
|
|
@@ -23,7 +24,7 @@ export async function prettifySrc(basePath: string, srcPath: string, ci: boolean
|
|
|
23
24
|
continue;
|
|
24
25
|
}
|
|
25
26
|
|
|
26
|
-
const contents = await
|
|
27
|
+
const contents = await readFile(file.path, "utf8"),
|
|
27
28
|
options = (await prettier.resolveConfig(basePath)) ?? {};
|
|
28
29
|
|
|
29
30
|
options.printWidth = 120;
|
|
@@ -39,7 +40,7 @@ export async function prettifySrc(basePath: string, srcPath: string, ci: boolean
|
|
|
39
40
|
} else {
|
|
40
41
|
const formatted = await prettier.format(contents, options);
|
|
41
42
|
|
|
42
|
-
await
|
|
43
|
+
await writeFile(file.path, formatted, "utf8");
|
|
43
44
|
}
|
|
44
45
|
}
|
|
45
46
|
|
|
@@ -71,7 +72,7 @@ export async function prettifyPackageJson(basePath: string, ci: boolean, silent:
|
|
|
71
72
|
let res: boolean;
|
|
72
73
|
|
|
73
74
|
try {
|
|
74
|
-
const contents = await
|
|
75
|
+
const contents = await readFile("package.json", "utf8"),
|
|
75
76
|
options = (await prettier.resolveConfig(basePath)) ?? {};
|
|
76
77
|
|
|
77
78
|
options.tabWidth = 2;
|
|
@@ -86,7 +87,7 @@ export async function prettifyPackageJson(basePath: string, ci: boolean, silent:
|
|
|
86
87
|
} else {
|
|
87
88
|
const formatted = await prettier.format(contents, options);
|
|
88
89
|
|
|
89
|
-
await
|
|
90
|
+
await writeFile("package.json", formatted, "utf8");
|
|
90
91
|
}
|
|
91
92
|
|
|
92
93
|
res = true;
|
|
@@ -117,7 +118,7 @@ export async function prettifyPackageDistJson(basePath: string, ci: boolean, sil
|
|
|
117
118
|
let res: boolean;
|
|
118
119
|
|
|
119
120
|
try {
|
|
120
|
-
const contents = await
|
|
121
|
+
const contents = await readFile("package.dist.json", "utf8"),
|
|
121
122
|
options = (await prettier.resolveConfig(basePath)) ?? {};
|
|
122
123
|
|
|
123
124
|
options.tabWidth = 2;
|
|
@@ -132,7 +133,7 @@ export async function prettifyPackageDistJson(basePath: string, ci: boolean, sil
|
|
|
132
133
|
} else {
|
|
133
134
|
const formatted = await prettier.format(contents, options);
|
|
134
135
|
|
|
135
|
-
await
|
|
136
|
+
await writeFile("package.dist.json", formatted, "utf8");
|
|
136
137
|
}
|
|
137
138
|
|
|
138
139
|
res = true;
|
|
@@ -163,7 +164,7 @@ export async function prettifyReadme(basePath: string, ci: boolean, silent: bool
|
|
|
163
164
|
let res: boolean;
|
|
164
165
|
|
|
165
166
|
try {
|
|
166
|
-
const contents = await
|
|
167
|
+
const contents = await readFile("README.md", "utf8"),
|
|
167
168
|
options = (await prettier.resolveConfig(basePath)) ?? {};
|
|
168
169
|
|
|
169
170
|
options.printWidth = 120;
|
|
@@ -177,7 +178,7 @@ export async function prettifyReadme(basePath: string, ci: boolean, silent: bool
|
|
|
177
178
|
} else {
|
|
178
179
|
const formatted = await prettier.format(contents, options);
|
|
179
180
|
|
|
180
|
-
await
|
|
181
|
+
await writeFile("README.md", formatted, "utf8");
|
|
181
182
|
}
|
|
182
183
|
|
|
183
184
|
res =
|
|
@@ -212,7 +213,7 @@ async function prettifyTraductions(basePath: string, ci: boolean, silent: boolea
|
|
|
212
213
|
const folder = "traduction",
|
|
213
214
|
folderPath = path.join(basePath, folder);
|
|
214
215
|
|
|
215
|
-
if (!
|
|
216
|
+
if (!existsSync(folderPath)) {
|
|
216
217
|
res = true;
|
|
217
218
|
}
|
|
218
219
|
|
|
@@ -222,7 +223,7 @@ async function prettifyTraductions(basePath: string, ci: boolean, silent: boolea
|
|
|
222
223
|
continue;
|
|
223
224
|
}
|
|
224
225
|
|
|
225
|
-
const contents = await
|
|
226
|
+
const contents = await readFile(file.path, "utf8"),
|
|
226
227
|
options = (await prettier.resolveConfig(basePath)) ?? {};
|
|
227
228
|
|
|
228
229
|
options.printWidth = 120;
|
|
@@ -236,7 +237,7 @@ async function prettifyTraductions(basePath: string, ci: boolean, silent: boolea
|
|
|
236
237
|
} else {
|
|
237
238
|
const formatted = await prettier.format(contents, options);
|
|
238
239
|
|
|
239
|
-
await
|
|
240
|
+
await writeFile(file.path, formatted, "utf8");
|
|
240
241
|
}
|
|
241
242
|
}
|
|
242
243
|
|
|
@@ -272,7 +273,7 @@ async function prettifyMarkdownTypeDocFiles(basePath: string, ci: boolean, silen
|
|
|
272
273
|
const folder = "markdown",
|
|
273
274
|
folderPath = path.join(basePath, folder);
|
|
274
275
|
|
|
275
|
-
if (!
|
|
276
|
+
if (!existsSync(folderPath)) {
|
|
276
277
|
res = true;
|
|
277
278
|
}
|
|
278
279
|
|
|
@@ -282,7 +283,7 @@ async function prettifyMarkdownTypeDocFiles(basePath: string, ci: boolean, silen
|
|
|
282
283
|
continue;
|
|
283
284
|
}
|
|
284
285
|
|
|
285
|
-
const contents = await
|
|
286
|
+
const contents = await readFile(file.path, "utf8"),
|
|
286
287
|
options = (await prettier.resolveConfig(basePath)) ?? {};
|
|
287
288
|
|
|
288
289
|
options.printWidth = 120;
|
|
@@ -296,7 +297,7 @@ async function prettifyMarkdownTypeDocFiles(basePath: string, ci: boolean, silen
|
|
|
296
297
|
} else {
|
|
297
298
|
const formatted = await prettier.format(contents, options);
|
|
298
299
|
|
|
299
|
-
await
|
|
300
|
+
await writeFile(file.path, formatted, "utf8");
|
|
300
301
|
}
|
|
301
302
|
}
|
|
302
303
|
|
package/src/build/build-tsc.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
|
+
import { readFile } from "node:fs/promises";
|
|
3
4
|
|
|
4
5
|
enum ExitCodes {
|
|
5
6
|
OK = 0,
|
|
@@ -17,8 +18,8 @@ enum ExitCodes {
|
|
|
17
18
|
async function readConfig(basePath: string, file: string): Promise<string | undefined> {
|
|
18
19
|
const tsconfigPath = path.join(basePath, file);
|
|
19
20
|
|
|
20
|
-
if (
|
|
21
|
-
const data = await
|
|
21
|
+
if (existsSync(tsconfigPath)) {
|
|
22
|
+
const data = await readFile(path.join(basePath, file));
|
|
22
23
|
|
|
23
24
|
return data.toString();
|
|
24
25
|
}
|
package/src/build/build.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { Command } from "commander";
|
|
2
|
+
import { existsSync } from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
2
4
|
|
|
3
5
|
const buildCommand = new Command("build");
|
|
4
6
|
|
|
@@ -52,11 +54,9 @@ buildCommand.action(async (argPath: string) => {
|
|
|
52
54
|
await clearDist(basePath, silent);
|
|
53
55
|
}
|
|
54
56
|
|
|
55
|
-
const
|
|
56
|
-
srcPath = path.join(basePath, argPath),
|
|
57
|
-
fs = await import("fs-extra");
|
|
57
|
+
const srcPath = path.join(basePath, argPath);
|
|
58
58
|
|
|
59
|
-
if (!(
|
|
59
|
+
if (!existsSync(srcPath)) {
|
|
60
60
|
throw new Error("Provided path does not exist");
|
|
61
61
|
}
|
|
62
62
|
|
|
@@ -126,12 +126,12 @@ buildCommand.action(async (argPath: string) => {
|
|
|
126
126
|
outputFunc = bundleSizeIncreased ? console.warn : console.info;
|
|
127
127
|
|
|
128
128
|
texts = [
|
|
129
|
-
|
|
130
|
-
?
|
|
131
|
-
:
|
|
132
|
-
|
|
133
|
-
?
|
|
134
|
-
:
|
|
129
|
+
bundleDiffSize
|
|
130
|
+
? `Bundle size ${bundleSizeIncreasedText} from ${oldStats.bundleSize.toString()} to ${newStats.bundleSize.toString()} (${Math.abs(bundleDiffSize).toString()}B)`
|
|
131
|
+
: "Bundle size unchanged",
|
|
132
|
+
diffSize
|
|
133
|
+
? `Size ${diffSizeIncreasedText} from ${oldStats.totalSize.toString()} to ${newStats.totalSize.toString()} (${Math.abs(diffSize).toString()}B)`
|
|
134
|
+
: "Size unchanged",
|
|
135
135
|
`Files count changed from ${oldStats.totalFiles.toString()} to ${newStats.totalFiles.toString()} (${(
|
|
136
136
|
newStats.totalFiles - oldStats.totalFiles
|
|
137
137
|
).toString()})`,
|
package/src/cli.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { buildCommand } from "./build/build.js";
|
|
3
3
|
import { createCommand } from "./create/create.js";
|
|
4
|
-
import { fileURLToPath } from "url";
|
|
5
|
-
import fs from "fs-extra";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
6
5
|
import path from "node:path";
|
|
7
6
|
import { program } from "commander";
|
|
7
|
+
import { readFile } from "node:fs/promises";
|
|
8
8
|
|
|
9
9
|
const __filename = fileURLToPath(import.meta.url),
|
|
10
10
|
__dirname = path.dirname(__filename),
|
|
11
11
|
rootPkgPath = path.join(__dirname, "..", "package.json"),
|
|
12
|
-
pkg = (await
|
|
12
|
+
pkg = JSON.parse(await readFile(rootPkgPath, "utf-8")) as { version: string };
|
|
13
13
|
|
|
14
14
|
program.name("tsparticles-cli");
|
|
15
15
|
program.description("tsParticles CLI");
|
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
updatePackageFile,
|
|
9
9
|
updateWebpackFile,
|
|
10
10
|
} from "../../utils/template-utils.js";
|
|
11
|
-
import
|
|
11
|
+
import { cp } from "node:fs/promises";
|
|
12
12
|
import path from "node:path";
|
|
13
13
|
import { replaceTokensInFile } from "../../utils/file-utils.js";
|
|
14
14
|
|
|
@@ -166,8 +166,9 @@ export async function createPluginTemplate(
|
|
|
166
166
|
|
|
167
167
|
await copyEmptyTemplateFiles(destPath);
|
|
168
168
|
|
|
169
|
-
await
|
|
170
|
-
|
|
169
|
+
await cp(sourcePath, destPath, {
|
|
170
|
+
recursive: true,
|
|
171
|
+
force: true,
|
|
171
172
|
filter: copyFilter,
|
|
172
173
|
});
|
|
173
174
|
|
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
updatePackageFile,
|
|
9
9
|
updateWebpackFile,
|
|
10
10
|
} from "../../utils/template-utils.js";
|
|
11
|
-
import
|
|
11
|
+
import { cp } from "node:fs/promises";
|
|
12
12
|
import path from "node:path";
|
|
13
13
|
import { replaceTokensInFile } from "../../utils/file-utils.js";
|
|
14
14
|
|
|
@@ -184,8 +184,9 @@ export async function createPresetTemplate(
|
|
|
184
184
|
|
|
185
185
|
await copyEmptyTemplateFiles(destPath);
|
|
186
186
|
|
|
187
|
-
await
|
|
188
|
-
|
|
187
|
+
await cp(sourcePath, destPath, {
|
|
188
|
+
recursive: true,
|
|
189
|
+
force: true,
|
|
189
190
|
filter: copyFilter,
|
|
190
191
|
});
|
|
191
192
|
|
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
updatePackageFile,
|
|
9
9
|
updateWebpackFile,
|
|
10
10
|
} from "../../utils/template-utils.js";
|
|
11
|
-
import
|
|
11
|
+
import { cp } from "node:fs/promises";
|
|
12
12
|
import path from "node:path";
|
|
13
13
|
import { replaceTokensInFile } from "../../utils/file-utils.js";
|
|
14
14
|
|
|
@@ -171,8 +171,9 @@ export async function createShapeTemplate(
|
|
|
171
171
|
|
|
172
172
|
await copyEmptyTemplateFiles(destPath);
|
|
173
173
|
|
|
174
|
-
await
|
|
175
|
-
|
|
174
|
+
await cp(sourcePath, destPath, {
|
|
175
|
+
recursive: true,
|
|
176
|
+
force: true,
|
|
176
177
|
filter: copyFilter,
|
|
177
178
|
});
|
|
178
179
|
|
package/src/utils/file-utils.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { mkdir, readFile, readdir, writeFile } from "node:fs/promises";
|
|
1
2
|
import { exec } from "node:child_process";
|
|
2
|
-
import
|
|
3
|
+
import { existsSync } from "node:fs";
|
|
3
4
|
import { lookpath } from "lookpath";
|
|
4
5
|
import path from "node:path";
|
|
5
6
|
|
|
@@ -21,15 +22,15 @@ export async function replaceTokensInFiles(options: ReplaceTokensOptions[]): Pro
|
|
|
21
22
|
for (const item of options) {
|
|
22
23
|
const filePath = item.path;
|
|
23
24
|
|
|
24
|
-
let data = await
|
|
25
|
+
let data = await readFile(filePath, "utf-8");
|
|
25
26
|
|
|
26
27
|
for (const token of item.tokens) {
|
|
27
|
-
const regex = new RegExp(token.from, "g");
|
|
28
|
+
const regex = token.from instanceof RegExp ? token.from : new RegExp(token.from, "g");
|
|
28
29
|
|
|
29
30
|
data = data.replace(regex, token.to);
|
|
30
31
|
}
|
|
31
32
|
|
|
32
|
-
await
|
|
33
|
+
await writeFile(filePath, data);
|
|
33
34
|
}
|
|
34
35
|
}
|
|
35
36
|
|
|
@@ -48,10 +49,10 @@ export async function replaceTokensInFile(options: ReplaceTokensOptions): Promis
|
|
|
48
49
|
*/
|
|
49
50
|
export async function getDestinationDir(destination: string): Promise<string> {
|
|
50
51
|
const destPath = path.join(process.cwd(), destination),
|
|
51
|
-
destExists =
|
|
52
|
+
destExists = existsSync(destPath);
|
|
52
53
|
|
|
53
54
|
if (destExists) {
|
|
54
|
-
const destContents = await
|
|
55
|
+
const destContents = await readdir(destPath),
|
|
55
56
|
destContentsNoGit = destContents.filter(t => t !== ".git" && t !== ".gitignore");
|
|
56
57
|
|
|
57
58
|
if (destContentsNoGit.length) {
|
|
@@ -59,7 +60,7 @@ export async function getDestinationDir(destination: string): Promise<string> {
|
|
|
59
60
|
}
|
|
60
61
|
}
|
|
61
62
|
|
|
62
|
-
await
|
|
63
|
+
await mkdir(destPath, { recursive: true });
|
|
63
64
|
|
|
64
65
|
return destPath;
|
|
65
66
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { cp } from "node:fs/promises";
|
|
1
2
|
import { exec } from "node:child_process";
|
|
2
|
-
import fs from "fs-extra";
|
|
3
3
|
import { lookpath } from "lookpath";
|
|
4
4
|
import path from "node:path";
|
|
5
5
|
import { replaceTokensInFile } from "./file-utils.js";
|
|
@@ -133,8 +133,9 @@ export async function updateWebpackFile(
|
|
|
133
133
|
* @param destPath - The path where the project will be created
|
|
134
134
|
*/
|
|
135
135
|
export async function copyEmptyTemplateFiles(destPath: string): Promise<void> {
|
|
136
|
-
await
|
|
137
|
-
|
|
136
|
+
await cp(path.join(__dirname, "..", "..", "files", "empty-project"), destPath, {
|
|
137
|
+
recursive: true,
|
|
138
|
+
force: true,
|
|
138
139
|
filter: copyFilter,
|
|
139
140
|
});
|
|
140
141
|
}
|
|
@@ -1,40 +1,40 @@
|
|
|
1
1
|
import { describe, it, expect } from "vitest";
|
|
2
2
|
import { createPluginTemplate } from "../src/create/plugin/create-plugin.js";
|
|
3
|
+
import { readFile, rm } from "node:fs/promises";
|
|
3
4
|
import path from "node:path";
|
|
4
|
-
import fs from "fs-extra";
|
|
5
5
|
|
|
6
6
|
describe("create-plugin", () => {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
it("should have created the plugin project", async () => {
|
|
8
|
+
const destDir = path.join(__dirname, "tmp-files", "foo-plugin"),
|
|
9
|
+
pkgPath = path.join(destDir, "package.json");
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
try {
|
|
12
|
+
await createPluginTemplate("foo", "Foo", "", destDir);
|
|
13
|
+
} catch (e) {
|
|
14
|
+
console.error(e);
|
|
15
|
+
}
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
const pkgInfo = JSON.parse(await readFile(pkgPath, "utf-8"));
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
expect(pkgInfo.name).toBe("tsparticles-plugin-foo");
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
await rm(destDir, { recursive: true, force: true });
|
|
22
|
+
});
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
it("should have created the plugin project, w/ repo", async () => {
|
|
25
|
+
const destDir = path.join(__dirname, "tmp-files", "bar-plugin");
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
27
|
+
try {
|
|
28
|
+
await createPluginTemplate("bar", "Bar", "https://github.com/matteobruni/tsparticles", destDir);
|
|
29
|
+
} catch (e) {
|
|
30
|
+
console.error(e);
|
|
31
|
+
}
|
|
32
32
|
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
const pkgPath = path.join(destDir, "package.json"),
|
|
34
|
+
pkgInfo = JSON.parse(await readFile(pkgPath, "utf-8"));
|
|
35
35
|
|
|
36
|
-
|
|
36
|
+
expect(pkgInfo.name).toBe("tsparticles-plugin-bar");
|
|
37
37
|
|
|
38
|
-
|
|
39
|
-
|
|
38
|
+
await rm(destDir, { recursive: true, force: true });
|
|
39
|
+
});
|
|
40
40
|
});
|