@tsparticles/cli 3.0.14 → 3.0.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. package/.github/workflows/node.js-ci.yml +13 -7
  2. package/dist/build/build-bundle.d.ts +5 -0
  3. package/dist/build/build-circular-deps.d.ts +6 -0
  4. package/dist/build/build-clear.d.ts +5 -0
  5. package/dist/build/build-distfiles.d.ts +5 -0
  6. package/dist/build/build-distfiles.js +7 -8
  7. package/dist/build/build-diststats.d.ts +12 -0
  8. package/dist/build/build-eslint.d.ts +5 -0
  9. package/dist/build/build-eslint.js +1 -3
  10. package/dist/build/build-prettier.d.ts +25 -0
  11. package/dist/build/build-prettier.js +4 -4
  12. package/dist/build/build-tsc.d.ts +5 -0
  13. package/dist/build/build.d.ts +3 -0
  14. package/dist/cli.d.ts +2 -0
  15. package/dist/create/create.d.ts +3 -0
  16. package/dist/create/plugin/create-plugin.d.ts +8 -0
  17. package/dist/create/plugin/plugin.d.ts +3 -0
  18. package/dist/create/preset/create-preset.d.ts +8 -0
  19. package/dist/create/preset/preset.d.ts +3 -0
  20. package/dist/create/shape/create-shape.d.ts +8 -0
  21. package/dist/create/shape/shape.d.ts +3 -0
  22. package/dist/tsconfig.tsbuildinfo +1 -0
  23. package/dist/utils/file-utils.d.ts +28 -0
  24. package/dist/utils/string-utils.d.ts +20 -0
  25. package/dist/utils/template-utils.d.ts +47 -0
  26. package/files/create-plugin/src/PluginInstance.ts +4 -2
  27. package/files/create-plugin/src/index.ts +1 -1
  28. package/files/create-plugin/src/plugin.ts +6 -6
  29. package/files/empty-project/.browserslistrc +1 -1
  30. package/files/empty-project/package.dist.json +1 -1
  31. package/files/empty-project/package.json +9 -9
  32. package/files/empty-project/tsconfig.base.json +2 -1
  33. package/package.json +12 -12
  34. package/src/build/build-bundle.ts +34 -34
  35. package/src/build/build-circular-deps.ts +23 -23
  36. package/src/build/build-clear.ts +11 -11
  37. package/src/build/build-distfiles.ts +67 -70
  38. package/src/build/build-diststats.ts +41 -41
  39. package/src/build/build-eslint.ts +26 -28
  40. package/src/build/build-prettier.ts +166 -166
  41. package/src/build/build-tsc.ts +146 -149
  42. package/src/build/build.ts +116 -116
  43. package/src/cli.ts +3 -3
  44. package/src/create/plugin/create-plugin.ts +108 -111
  45. package/src/create/plugin/plugin.ts +31 -31
  46. package/src/create/preset/create-preset.ts +123 -126
  47. package/src/create/preset/preset.ts +31 -31
  48. package/src/create/shape/create-shape.ts +112 -115
  49. package/src/create/shape/shape.ts +31 -31
  50. package/src/tsconfig.json +7 -125
  51. package/src/utils/file-utils.ts +35 -35
  52. package/src/utils/string-utils.ts +13 -13
  53. package/src/utils/template-utils.ts +130 -130
  54. package/tests/create-plugin.test.ts +11 -3
  55. package/tests/create-preset.test.ts +10 -2
  56. package/tests/create-shape.test.ts +10 -2
  57. package/tests/tsconfig.json +3 -15
  58. package/tsconfig.json +53 -20
  59. package/.mocharc.json +0 -11
  60. package/tsconfig.eslint.json +0 -8
@@ -1,13 +1,15 @@
1
- import { type Container, type Engine, type IContainerPlugin } from "@tsparticles/engine";
1
+ import { /*type Container, type Engine,*/ type IContainerPlugin } from "@tsparticles/engine";
2
2
 
3
3
  export class PluginInstance implements IContainerPlugin {
4
+ /*
4
5
  private readonly _container;
5
6
  private readonly _engine;
6
7
 
7
8
  constructor(container: Container, engine: Engine) {
8
- this._container = container;
9
+ /*this._container = container;
9
10
  this._engine = engine;
10
11
  }
12
+ */
11
13
 
12
14
  async init(): Promise<void> {
13
15
  // add your plugin initialization here, replace the empty promise
@@ -6,5 +6,5 @@ import type { Engine } from "@tsparticles/engine";
6
6
  export async function loadTemplatePlugin(engine: Engine): Promise<void> {
7
7
  const { Plugin } = await import("./plugin.js");
8
8
 
9
- await engine.addPlugin(new Plugin(engine));
9
+ await engine.addPlugin(new Plugin(/*engine*/));
10
10
  }
@@ -1,4 +1,4 @@
1
- import { type Container, type Engine, type IPlugin, type ISourceOptions, type Options } from "@tsparticles/engine";
1
+ import { /*type Container, type Engine,*/ type IPlugin, type ISourceOptions, type Options } from "@tsparticles/engine";
2
2
  import type { PluginInstance } from "./PluginInstance.js";
3
3
 
4
4
  /**
@@ -6,18 +6,18 @@ import type { PluginInstance } from "./PluginInstance.js";
6
6
  export class Plugin implements IPlugin {
7
7
  readonly id;
8
8
 
9
- private readonly _engine;
9
+ //private readonly _engine;
10
10
 
11
- constructor(engine: Engine) {
11
+ constructor(/*engine: Engine*/) {
12
12
  this.id = "#template#";
13
13
 
14
- this._engine = engine;
14
+ //this._engine = engine;
15
15
  }
16
16
 
17
- async getPlugin(container: Container): Promise<PluginInstance> {
17
+ async getPlugin(/*container: Container*/): Promise<PluginInstance> {
18
18
  const { PluginInstance } = await import("./PluginInstance.js");
19
19
 
20
- return new PluginInstance(container, this._engine);
20
+ return new PluginInstance(/*container, this._engine*/);
21
21
  }
22
22
 
23
23
  loadOptions(_options: Options, _source?: ISourceOptions): void {
@@ -1,2 +1,2 @@
1
- since 2019
1
+ since 2021
2
2
  not dead
@@ -73,6 +73,6 @@
73
73
  "module": "index.js",
74
74
  "types": "index.d.ts",
75
75
  "dependencies": {
76
- "@tsparticles/engine": "^3.3.0"
76
+ "@tsparticles/engine": "^3.9.1"
77
77
  }
78
78
  }
@@ -83,25 +83,25 @@
83
83
  "types": "dist/types/index.d.ts",
84
84
  "prettier": "@tsparticles/prettier-config",
85
85
  "devDependencies": {
86
- "@babel/core": "^7.28.5",
87
- "@tsparticles/cli": "^3.0.14",
88
- "@tsparticles/eslint-config": "^3.0.6",
89
- "@tsparticles/prettier-config": "^3.0.6",
90
- "@tsparticles/tsconfig": "^3.0.6",
91
- "@tsparticles/webpack-plugin": "^3.0.6",
86
+ "@babel/core": "^7.28.6",
87
+ "@tsparticles/cli": "^3.0.15",
88
+ "@tsparticles/eslint-config": "^3.0.11",
89
+ "@tsparticles/prettier-config": "^3.0.11",
90
+ "@tsparticles/tsconfig": "^3.0.9",
91
+ "@tsparticles/webpack-plugin": "^3.0.11",
92
92
  "@types/webpack-env": "^1.18.8",
93
93
  "babel-loader": "^10.0.0",
94
94
  "browserslist": "^4.28.1",
95
95
  "copyfiles": "^2.4.1",
96
96
  "eslint": "^9.39.2",
97
97
  "eslint-config-prettier": "^10.1.8",
98
- "prettier": "^3.7.4",
98
+ "prettier": "^3.8.1",
99
99
  "rimraf": "^6.1.2",
100
100
  "terser-webpack-plugin": "^5.3.16",
101
101
  "typescript": "^5.9.3",
102
- "typescript-eslint": "^8.50.0",
102
+ "typescript-eslint": "^8.53.1",
103
103
  "webpack": "^5.104.1",
104
- "webpack-bundle-analyzer": "^5.1.0",
104
+ "webpack-bundle-analyzer": "^5.2.0",
105
105
  "webpack-cli": "^6.0.1"
106
106
  },
107
107
  "dependencies": {
@@ -1,7 +1,8 @@
1
1
  {
2
2
  "extends": "@tsparticles/tsconfig/tsconfig.base.json",
3
3
  "compilerOptions": {
4
- "rootDir": "./src"
4
+ "rootDir": "./src",
5
+ "strictNullChecks": true
5
6
  },
6
7
  "include": [
7
8
  "./src"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tsparticles/cli",
3
- "version": "3.0.14",
3
+ "version": "3.0.15",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "bin": {
@@ -11,31 +11,31 @@
11
11
  },
12
12
  "prettier": "@tsparticles/prettier-config",
13
13
  "dependencies": {
14
- "@tsparticles/eslint-config": "^3.0.9",
15
- "@tsparticles/prettier-config": "^3.0.7",
14
+ "@tsparticles/eslint-config": "^3.0.11",
15
+ "@tsparticles/prettier-config": "^3.0.11",
16
16
  "@tsparticles/tsconfig": "^3.0.9",
17
- "@tsparticles/webpack-plugin": "^3.0.9",
17
+ "@tsparticles/webpack-plugin": "^3.0.11",
18
18
  "commander": "^14.0.2",
19
19
  "eslint": "^9.39.2",
20
20
  "eslint-config-prettier": "^10.1.8",
21
- "eslint-plugin-jsdoc": "^61.5.0",
22
- "eslint-plugin-prettier": "^5.5.4",
21
+ "eslint-plugin-jsdoc": "^62.3.0",
22
+ "eslint-plugin-prettier": "^5.5.5",
23
23
  "eslint-plugin-tsdoc": "^0.5.0",
24
24
  "fs-extra": "^11.3.3",
25
25
  "klaw": "^4.1.0",
26
26
  "lookpath": "^1.2.3",
27
27
  "madge": "^8.0.0",
28
28
  "path-scurry": "^2.0.1",
29
- "prettier": "^3.7.4",
29
+ "prettier": "^3.8.1",
30
30
  "prettier-plugin-multiline-arrays": "^4.1.3",
31
31
  "prompts": "^2.4.2",
32
32
  "rimraf": "^6.1.2",
33
33
  "typescript": "^5.9.3",
34
- "typescript-eslint": "^8.51.0",
34
+ "typescript-eslint": "^8.53.1",
35
35
  "webpack": "^5.104.1"
36
36
  },
37
37
  "devDependencies": {
38
- "@babel/core": "^7.28.5",
38
+ "@babel/core": "^7.28.6",
39
39
  "@tsparticles/cli": "^3.0.14",
40
40
  "@tsparticles/engine": "^3.9.1",
41
41
  "@types/eslint": "^9.6.1",
@@ -43,7 +43,7 @@
43
43
  "@types/fs-extra": "^11.0.4",
44
44
  "@types/klaw": "^3.0.7",
45
45
  "@types/madge": "^5.0.3",
46
- "@types/node": "^25.0.3",
46
+ "@types/node": "^25.0.10",
47
47
  "@types/prompts": "^2.4.9",
48
48
  "@types/webpack-env": "^1.18.8",
49
49
  "babel-loader": "^10.0.0",
@@ -52,8 +52,8 @@
52
52
  "cross-env": "^10.1.0",
53
53
  "terser-webpack-plugin": "^5.3.16",
54
54
  "ts-node": "^10.9.2",
55
- "vitest": "^4.0.16",
56
- "webpack-bundle-analyzer": "^5.1.0",
55
+ "vitest": "^4.0.17",
56
+ "webpack-bundle-analyzer": "^5.2.0",
57
57
  "webpack-cli": "^6.0.1"
58
58
  },
59
59
  "description": "tsParticles CLI",
@@ -6,55 +6,55 @@ import webpack from "webpack";
6
6
  * @returns true if the bundle was created
7
7
  */
8
8
  export async function bundle(basePath: string): Promise<boolean> {
9
- console.log("Bundling started");
9
+ console.log("Bundling started");
10
10
 
11
- let res = false;
11
+ let res = false;
12
12
 
13
- try {
14
- const options = (await import(path.join(basePath, "webpack.config.js"))) as { default: webpack.Configuration };
13
+ try {
14
+ const options = (await import(path.join(basePath, "webpack.config.js"))) as { default: webpack.Configuration };
15
15
 
16
- res = await new Promise<boolean>((resolve, reject) => {
17
- webpack(options.default, (err, stats) => {
18
- if (err) {
19
- console.error(err.stack ?? err);
16
+ res = await new Promise<boolean>((resolve, reject) => {
17
+ webpack(options.default, (err, stats) => {
18
+ if (err) {
19
+ console.error(err.stack ?? err);
20
20
 
21
- reject(err);
21
+ reject(err);
22
22
 
23
- return;
24
- }
23
+ return;
24
+ }
25
25
 
26
- if (!stats) {
27
- const err = new Error("No stats returned from webpack");
26
+ if (!stats) {
27
+ const err = new Error("No stats returned from webpack");
28
28
 
29
- console.error(err);
29
+ console.error(err);
30
30
 
31
- reject(err);
31
+ reject(err);
32
32
 
33
- return;
34
- }
33
+ return;
34
+ }
35
35
 
36
- const info = stats.toJson();
36
+ const info = stats.toJson();
37
37
 
38
- if (stats.hasErrors()) {
39
- console.error(info.errors);
38
+ if (stats.hasErrors()) {
39
+ console.error(info.errors);
40
40
 
41
- reject(new Error(info.errors?.map(error => error.message).join("\n")));
42
- }
41
+ reject(new Error(info.errors?.map(error => error.message).join("\n")));
42
+ }
43
43
 
44
- if (stats.hasWarnings()) {
45
- console.warn(info.warnings);
46
- }
44
+ if (stats.hasWarnings()) {
45
+ console.warn(info.warnings);
46
+ }
47
47
 
48
- resolve(true);
49
- });
50
- });
51
- } catch (e) {
52
- console.error(e);
48
+ resolve(true);
49
+ });
50
+ });
51
+ } catch (e) {
52
+ console.error(e);
53
53
 
54
- res = false;
55
- }
54
+ res = false;
55
+ }
56
56
 
57
- console.log("Bundling done");
57
+ console.log("Bundling done");
58
58
 
59
- return res;
59
+ return res;
60
60
  }
@@ -7,33 +7,33 @@ import path from "path";
7
7
  * @returns true if no circular dependencies are found, false otherwise
8
8
  */
9
9
  export async function buildCircularDeps(basePath: string): Promise<boolean> {
10
- let res = false;
10
+ let res = false;
11
11
 
12
- try {
13
- const madgeRes = await madge(path.join(basePath, "src"), {
14
- fileExtensions: ["ts"],
15
- detectiveOptions: {
16
- ts: {
17
- skipTypeImports: true,
18
- },
19
- },
20
- }),
21
- circularDeps = madgeRes.circular();
12
+ try {
13
+ const madgeRes = await madge(path.join(basePath, "src"), {
14
+ fileExtensions: ["ts"],
15
+ detectiveOptions: {
16
+ ts: {
17
+ skipTypeImports: true,
18
+ },
19
+ },
20
+ }),
21
+ circularDeps = madgeRes.circular();
22
22
 
23
- if (circularDeps.length) {
24
- console.error("Circular dependencies found!");
23
+ if (circularDeps.length) {
24
+ console.error("Circular dependencies found!");
25
25
 
26
- for (const dep of circularDeps) {
27
- console.error(dep.join(" > "));
28
- }
29
- } else {
30
- res = true;
31
- }
32
- } catch (e) {
33
- console.error(e);
26
+ for (const dep of circularDeps) {
27
+ console.error(dep.join(" > "));
28
+ }
29
+ } else {
30
+ res = true;
34
31
  }
32
+ } catch (e) {
33
+ console.error(e);
34
+ }
35
35
 
36
- console.log("Finished checking circular dependencies.");
36
+ console.log("Finished checking circular dependencies.");
37
37
 
38
- return res;
38
+ return res;
39
39
  }
@@ -6,21 +6,21 @@ import { rimraf } from "rimraf";
6
6
  * @returns true if the dist folder was cleared
7
7
  */
8
8
  export async function clearDist(basePath: string): Promise<boolean> {
9
- console.log("Clearing dist folder");
9
+ console.log("Clearing dist folder");
10
10
 
11
- let res = false;
11
+ let res = false;
12
12
 
13
- try {
14
- await rimraf(path.join(basePath, "dist"));
13
+ try {
14
+ await rimraf(path.join(basePath, "dist"));
15
15
 
16
- res = true;
17
- } catch (e) {
18
- console.error(e);
16
+ res = true;
17
+ } catch (e) {
18
+ console.error(e);
19
19
 
20
- res = false;
21
- }
20
+ res = false;
21
+ }
22
22
 
23
- console.log("Clearing dist folder done");
23
+ console.log("Clearing dist folder done");
24
24
 
25
- return res;
25
+ return res;
26
26
  }
@@ -7,80 +7,77 @@ import path from "path";
7
7
  * @returns true if the dist files process was successful
8
8
  */
9
9
  export async function buildDistFiles(basePath: string): Promise<boolean> {
10
- console.log("Build - started on dist files");
11
-
12
- let res: boolean;
13
-
14
- try {
15
- const pkgInfo = JSON.parse((await fs.readFile(path.join(basePath, "package.json"))).toString()) as {
16
- dependencies?: Record<string, string>;
17
- peerDependencies?: Record<string, string>;
18
- publishConfig?: { directory?: string };
19
- version: string;
20
- },
21
- libPackage = path.join(basePath, "package.dist.json"),
22
- distPath = path.join(basePath, pkgInfo.publishConfig?.directory ?? "dist");
23
-
24
- const data = await fs.readFile(libPackage),
25
- text = data.toString(),
26
- libObj = JSON.parse(text) as Record<string, unknown>;
27
-
28
- libObj["version"] = pkgInfo.version;
29
-
30
- if (pkgInfo.dependencies) {
31
- libObj["dependencies"] = JSON.parse(JSON.stringify(pkgInfo.dependencies).replaceAll("workspace:", ""));
32
- } else if (pkgInfo.peerDependencies) {
33
- libObj["peerDependencies"] = JSON.parse(
34
- JSON.stringify(pkgInfo.peerDependencies).replaceAll("workspace:", ""),
35
- );
36
- }
10
+ console.log("Build - started on dist files");
11
+
12
+ let res: boolean;
13
+
14
+ try {
15
+ const pkgInfo = JSON.parse((await fs.readFile(path.join(basePath, "package.json"))).toString()) as {
16
+ dependencies?: Record<string, string>;
17
+ peerDependencies?: Record<string, string>;
18
+ publishConfig?: { directory?: string };
19
+ version: string;
20
+ },
21
+ libPackage = path.join(basePath, "package.dist.json"),
22
+ distPath = path.join(basePath, pkgInfo.publishConfig?.directory ?? "dist"),
23
+ data = await fs.readFile(libPackage),
24
+ text = data.toString(),
25
+ libObj = JSON.parse(text) as Record<string, unknown>;
26
+
27
+ libObj["version"] = pkgInfo.version;
28
+
29
+ if (pkgInfo.dependencies) {
30
+ libObj["dependencies"] = JSON.parse(JSON.stringify(pkgInfo.dependencies).replaceAll("workspace:", ""));
31
+ } else if (pkgInfo.peerDependencies) {
32
+ libObj["peerDependencies"] = JSON.parse(JSON.stringify(pkgInfo.peerDependencies).replaceAll("workspace:", ""));
33
+ }
37
34
 
38
- const jsonIndent = 2;
35
+ const jsonIndent = 2;
39
36
 
40
- await fs.writeFile(libPackage, `${JSON.stringify(libObj, undefined, jsonIndent)}\n`, "utf8");
37
+ await fs.writeFile(libPackage, `${JSON.stringify(libObj, undefined, jsonIndent)}\n`, "utf8");
41
38
 
42
- console.log(`package.dist.json updated successfully to version ${pkgInfo.version}`);
39
+ console.log(`package.dist.json updated successfully to version ${pkgInfo.version}`);
43
40
 
44
- const rootFilesToCopy = [
45
- "LICENSE",
46
- "README.md",
47
- {
48
- source: "package.dist.json",
49
- destination: "package.json",
50
- },
51
- ];
41
+ const rootFilesToCopy = [
42
+ "LICENSE",
43
+ "README.md",
44
+ {
45
+ source: "package.dist.json",
46
+ destination: "package.json",
47
+ },
48
+ ];
52
49
 
53
- for (const file of rootFilesToCopy) {
54
- const src = path.join(basePath, typeof file === "string" ? file : file.source),
55
- dest = path.join(distPath, typeof file === "string" ? file : file.destination);
50
+ for (const file of rootFilesToCopy) {
51
+ const src = path.join(basePath, typeof file === "string" ? file : file.source),
52
+ dest = path.join(distPath, typeof file === "string" ? file : file.destination);
56
53
 
57
- await fs.copyFile(src, dest);
58
- }
54
+ await fs.copyFile(src, dest);
55
+ }
59
56
 
60
- const scriptsPath = path.join(basePath, "scripts"),
61
- distScriptsPath = path.join(distPath, "scripts");
57
+ const scriptsPath = path.join(basePath, "scripts"),
58
+ distScriptsPath = path.join(distPath, "scripts");
62
59
 
63
- if ((await fs.exists(scriptsPath)) && !(await fs.exists(distScriptsPath))) {
64
- await fs.mkdir(distScriptsPath);
60
+ if ((await fs.exists(scriptsPath)) && !(await fs.exists(distScriptsPath))) {
61
+ await fs.mkdir(distScriptsPath);
65
62
 
66
- const installPath = path.join(scriptsPath, "install.js");
63
+ const installPath = path.join(scriptsPath, "install.js");
67
64
 
68
- if (await fs.exists(installPath)) {
69
- await fs.copyFile(installPath, path.join(distScriptsPath, "install.js"));
70
- }
71
- }
65
+ if (await fs.exists(installPath)) {
66
+ await fs.copyFile(installPath, path.join(distScriptsPath, "install.js"));
67
+ }
68
+ }
72
69
 
73
- for await (const file of klaw(distPath)) {
74
- if (file.stats.isDirectory()) {
75
- continue;
76
- }
70
+ for await (const file of klaw(distPath)) {
71
+ if (file.stats.isDirectory()) {
72
+ continue;
73
+ }
77
74
 
78
- const contents = await fs.readFile(file.path, "utf8");
75
+ const contents = await fs.readFile(file.path, "utf8");
79
76
 
80
- await fs.writeFile(file.path, contents.replaceAll("__VERSION__", `"${pkgInfo.version}"`), "utf8");
81
- }
77
+ await fs.writeFile(file.path, contents.replaceAll("__VERSION__", `"${pkgInfo.version}"`), "utf8");
78
+ }
82
79
 
83
- /* for await (const file of klaw(path.join(distPath, "cjs"))) {
80
+ /* for await (const file of klaw(path.join(distPath, "cjs"))) {
84
81
  await fs.rename(file.path, file.path.replace(/\.js$/, ".cjs"));
85
82
  }
86
83
 
@@ -88,18 +85,18 @@ export async function buildDistFiles(basePath: string): Promise<boolean> {
88
85
  await fs.rename(file.path, file.path.replace(/\.js$/, ".mjs"));
89
86
  } */
90
87
 
91
- await fs.writeFile(path.join(distPath, "cjs", "package.json"), `{ "type": "commonjs" }`);
92
- await fs.writeFile(path.join(distPath, "esm", "package.json"), `{ "type": "module" }`);
93
- await fs.writeFile(path.join(distPath, "browser", "package.json"), `{ "type": "module" }`);
88
+ await fs.writeFile(path.join(distPath, "cjs", "package.json"), `{ "type": "commonjs" }`);
89
+ await fs.writeFile(path.join(distPath, "esm", "package.json"), `{ "type": "module" }`);
90
+ await fs.writeFile(path.join(distPath, "browser", "package.json"), `{ "type": "module" }`);
94
91
 
95
- res = true;
96
- } catch (e) {
97
- console.error(e);
92
+ res = true;
93
+ } catch (e) {
94
+ console.error(e);
98
95
 
99
- res = false;
100
- }
96
+ res = false;
97
+ }
101
98
 
102
- console.log("Build - done on dist files");
99
+ console.log("Build - done on dist files");
103
100
 
104
- return res;
101
+ return res;
105
102
  }
@@ -1,10 +1,10 @@
1
1
  import fs from "fs-extra";
2
2
 
3
3
  export interface IDistStats {
4
- bundleSize: number;
5
- totalFiles: number;
6
- totalFolders: number;
7
- totalSize: number;
4
+ bundleSize: number;
5
+ totalFiles: number;
6
+ totalFolders: number;
7
+ totalSize: number;
8
8
  }
9
9
 
10
10
  /**
@@ -13,42 +13,42 @@ export interface IDistStats {
13
13
  * @returns the given folder stats;
14
14
  */
15
15
  async function getFolderStats(folderPath: string, bundlePath?: string): Promise<IDistStats> {
16
- const stats: IDistStats = {
17
- bundleSize: 0,
18
- totalFiles: 0,
19
- totalFolders: 0,
20
- totalSize: 0,
21
- };
16
+ const stats: IDistStats = {
17
+ bundleSize: 0,
18
+ totalFiles: 0,
19
+ totalFolders: 0,
20
+ totalSize: 0,
21
+ };
22
22
 
23
- if (!(await fs.pathExists(folderPath))) {
24
- return stats;
25
- }
23
+ if (!(await fs.pathExists(folderPath))) {
24
+ return stats;
25
+ }
26
26
 
27
- const dir = await fs.promises.opendir(folderPath),
28
- path = await import("path");
27
+ const dir = await fs.promises.opendir(folderPath),
28
+ path = await import("path");
29
29
 
30
- for await (const dirent of dir) {
31
- const increment = 1;
30
+ for await (const dirent of dir) {
31
+ const increment = 1;
32
32
 
33
- if (dirent.isDirectory()) {
34
- const subDirStats = await getFolderStats(path.join(folderPath, dirent.name), bundlePath);
33
+ if (dirent.isDirectory()) {
34
+ const subDirStats = await getFolderStats(path.join(folderPath, dirent.name), bundlePath);
35
35
 
36
- stats.totalFolders += subDirStats.totalFolders + increment;
37
- stats.totalFiles += subDirStats.totalFiles;
38
- stats.totalSize += subDirStats.totalSize;
39
- } else {
40
- const fileStats = await fs.stat(path.join(folderPath, dirent.name));
36
+ stats.totalFolders += subDirStats.totalFolders + increment;
37
+ stats.totalFiles += subDirStats.totalFiles;
38
+ stats.totalSize += subDirStats.totalSize;
39
+ } else {
40
+ const fileStats = await fs.stat(path.join(folderPath, dirent.name));
41
41
 
42
- stats.totalFiles++;
43
- stats.totalSize += fileStats.size;
42
+ stats.totalFiles++;
43
+ stats.totalSize += fileStats.size;
44
44
 
45
- if (bundlePath && path.join(folderPath, dirent.name) === bundlePath) {
46
- stats.bundleSize += fileStats.size;
47
- }
48
- }
45
+ if (bundlePath && path.join(folderPath, dirent.name) === bundlePath) {
46
+ stats.bundleSize += fileStats.size;
47
+ }
49
48
  }
49
+ }
50
50
 
51
- return stats;
51
+ return stats;
52
52
  }
53
53
 
54
54
  /**
@@ -57,15 +57,15 @@ async function getFolderStats(folderPath: string, bundlePath?: string): Promise<
57
57
  * @returns the stats for the dist folder
58
58
  */
59
59
  export async function getDistStats(basePath: string): Promise<IDistStats> {
60
- const path = await import("path"),
61
- distFolder = path.join(basePath, "dist"),
62
- pkgInfo = (await fs.exists(path.join(distFolder, "package.json")))
63
- ? (JSON.parse((await fs.readFile(path.join(distFolder, "package.json"))).toString()) as {
64
- jsdelivr?: string;
65
- })
66
- : {},
67
- bundlePath =
68
- (await fs.exists(distFolder)) && pkgInfo.jsdelivr ? path.join(distFolder, pkgInfo.jsdelivr) : undefined;
60
+ const path = await import("path"),
61
+ distFolder = path.join(basePath, "dist"),
62
+ pkgInfo = (await fs.exists(path.join(distFolder, "package.json")))
63
+ ? (JSON.parse((await fs.readFile(path.join(distFolder, "package.json"))).toString()) as {
64
+ jsdelivr?: string;
65
+ })
66
+ : {},
67
+ bundlePath =
68
+ (await fs.exists(distFolder)) && pkgInfo.jsdelivr ? path.join(distFolder, pkgInfo.jsdelivr) : undefined;
69
69
 
70
- return await getFolderStats(distFolder, bundlePath);
70
+ return await getFolderStats(distFolder, bundlePath);
71
71
  }