@tsparticles/cli 1.2.0 → 1.3.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.
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getDistStats = void 0;
7
+ const fs_extra_1 = __importDefault(require("fs-extra"));
8
+ const path_1 = __importDefault(require("path"));
9
+ /**
10
+ * @param folderPath - the path to the folder to get the stats for
11
+ * @returns the given folder stats;
12
+ */
13
+ async function getFolderStats(folderPath) {
14
+ const stats = {
15
+ totalFiles: 0,
16
+ totalFolders: 0,
17
+ totalSize: 0,
18
+ };
19
+ const dir = await fs_extra_1.default.promises.opendir(folderPath);
20
+ for await (const dirent of dir) {
21
+ if (dirent.isDirectory()) {
22
+ const subDirStats = await getDistStats(path_1.default.join(folderPath, dirent.name));
23
+ stats.totalFolders += subDirStats.totalFolders + 1;
24
+ stats.totalFiles += subDirStats.totalFiles;
25
+ stats.totalSize += subDirStats.totalSize;
26
+ }
27
+ else {
28
+ const fileStats = await fs_extra_1.default.stat(path_1.default.join(folderPath, dirent.name));
29
+ stats.totalFiles++;
30
+ stats.totalSize += fileStats.size;
31
+ }
32
+ }
33
+ return stats;
34
+ }
35
+ /**
36
+ * Gets the stats for the dist folder
37
+ * @param basePath - the base path to the project
38
+ * @returns the stats for the dist folder
39
+ */
40
+ async function getDistStats(basePath) {
41
+ return await getFolderStats(path_1.default.join(basePath, "dist"));
42
+ }
43
+ exports.getDistStats = getDistStats;
@@ -11,6 +11,7 @@ const build_tsc_1 = require("./build-tsc");
11
11
  const build_bundle_1 = require("./build-bundle");
12
12
  const build_clear_1 = require("./build-clear");
13
13
  const fs_extra_1 = __importDefault(require("fs-extra"));
14
+ const build_diststats_1 = require("./build-diststats");
14
15
  const build_eslint_1 = require("./build-eslint");
15
16
  const path_1 = __importDefault(require("path"));
16
17
  const buildCommand = new commander_1.Command("build");
@@ -28,6 +29,7 @@ buildCommand.argument("[path]", `Path to the project root folder, default is "sr
28
29
  buildCommand.action(async (argPath) => {
29
30
  const opts = buildCommand.opts(), ci = !!opts.ci, all = !!opts.all, doBundle = all || !!opts.bundle, clean = all || !!opts.clean, distfiles = all || !!opts.dist, doLint = all || !!opts.lint, prettier = all || !!opts.prettify, tsc = all || !!opts.tsc;
30
31
  const basePath = process.cwd();
32
+ const oldStats = await (0, build_diststats_1.getDistStats)(path_1.default.join(basePath, "dist"));
31
33
  if (clean) {
32
34
  await (0, build_clear_1.clearDist)(basePath);
33
35
  }
@@ -57,4 +59,13 @@ buildCommand.action(async (argPath) => {
57
59
  if (!canContinue) {
58
60
  throw new Error("Build failed");
59
61
  }
62
+ const newStats = await (0, build_diststats_1.getDistStats)(path_1.default.join(basePath, "dist")), diffSize = newStats.totalSize - oldStats.totalSize, texts = [
63
+ `Size changed from ${oldStats.totalSize} to ${newStats.totalSize} (${diffSize}B)`,
64
+ `Files count changed from ${oldStats.totalFiles} to ${newStats.totalFiles} (${newStats.totalFiles - oldStats.totalFiles})`,
65
+ `Folders count changed from ${oldStats.totalFolders} to ${newStats.totalFolders} (${newStats.totalFolders - oldStats.totalFolders})`,
66
+ ], sizeIncreased = diffSize > 0, outputFunc = sizeIncreased ? console.warn : console.info;
67
+ console.log("Build finished successfully!");
68
+ for (const text of texts) {
69
+ outputFunc(text);
70
+ }
60
71
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tsparticles/cli",
3
- "version": "1.2.0",
3
+ "version": "1.3.0",
4
4
  "license": "MIT",
5
5
  "bin": {
6
6
  "tsparticles-cli": "dist/cli.js"
@@ -19,7 +19,7 @@
19
19
  "commander": "^10.0.1",
20
20
  "eslint": "^8.38.0",
21
21
  "eslint-config-prettier": "^8.8.0",
22
- "eslint-plugin-jsdoc": "^43.0.0",
22
+ "eslint-plugin-jsdoc": "^44.0.0",
23
23
  "eslint-plugin-tsdoc": "^0.2.17",
24
24
  "fs-extra": "^11.1.1",
25
25
  "klaw": "^4.1.0",
@@ -0,0 +1,48 @@
1
+ import fs from "fs-extra";
2
+ import path from "path";
3
+
4
+ export interface IDistStats {
5
+ totalFiles: number;
6
+ totalFolders: number;
7
+ totalSize: number;
8
+ }
9
+
10
+ /**
11
+ * @param folderPath - the path to the folder to get the stats for
12
+ * @returns the given folder stats;
13
+ */
14
+ async function getFolderStats(folderPath: string): Promise<IDistStats> {
15
+ const stats: IDistStats = {
16
+ totalFiles: 0,
17
+ totalFolders: 0,
18
+ totalSize: 0,
19
+ };
20
+
21
+ const dir = await fs.promises.opendir(folderPath);
22
+
23
+ for await (const dirent of dir) {
24
+ if (dirent.isDirectory()) {
25
+ const subDirStats = await getDistStats(path.join(folderPath, dirent.name));
26
+
27
+ stats.totalFolders += subDirStats.totalFolders + 1;
28
+ stats.totalFiles += subDirStats.totalFiles;
29
+ stats.totalSize += subDirStats.totalSize;
30
+ } else {
31
+ const fileStats = await fs.stat(path.join(folderPath, dirent.name));
32
+
33
+ stats.totalFiles++;
34
+ stats.totalSize += fileStats.size;
35
+ }
36
+ }
37
+
38
+ return stats;
39
+ }
40
+
41
+ /**
42
+ * Gets the stats for the dist folder
43
+ * @param basePath - the base path to the project
44
+ * @returns the stats for the dist folder
45
+ */
46
+ export async function getDistStats(basePath: string): Promise<IDistStats> {
47
+ return await getFolderStats(path.join(basePath, "dist"));
48
+ }
@@ -5,6 +5,7 @@ import { buildTS } from "./build-tsc";
5
5
  import { bundle } from "./build-bundle";
6
6
  import { clearDist } from "./build-clear";
7
7
  import fs from "fs-extra";
8
+ import { getDistStats } from "./build-diststats";
8
9
  import { lint } from "./build-eslint";
9
10
  import path from "path";
10
11
 
@@ -42,6 +43,8 @@ buildCommand.action(async (argPath: string) => {
42
43
 
43
44
  const basePath = process.cwd();
44
45
 
46
+ const oldStats = await getDistStats(path.join(basePath, "dist"));
47
+
45
48
  if (clean) {
46
49
  await clearDist(basePath);
47
50
  }
@@ -81,6 +84,26 @@ buildCommand.action(async (argPath: string) => {
81
84
  if (!canContinue) {
82
85
  throw new Error("Build failed");
83
86
  }
87
+
88
+ const newStats = await getDistStats(path.join(basePath, "dist")),
89
+ diffSize = newStats.totalSize - oldStats.totalSize,
90
+ texts = [
91
+ `Size changed from ${oldStats.totalSize} to ${newStats.totalSize} (${diffSize}B)`,
92
+ `Files count changed from ${oldStats.totalFiles} to ${newStats.totalFiles} (${
93
+ newStats.totalFiles - oldStats.totalFiles
94
+ })`,
95
+ `Folders count changed from ${oldStats.totalFolders} to ${newStats.totalFolders} (${
96
+ newStats.totalFolders - oldStats.totalFolders
97
+ })`,
98
+ ],
99
+ sizeIncreased = diffSize > 0,
100
+ outputFunc = sizeIncreased ? console.warn : console.info;
101
+
102
+ console.log("Build finished successfully!");
103
+
104
+ for (const text of texts) {
105
+ outputFunc(text);
106
+ }
84
107
  });
85
108
 
86
109
  export { buildCommand };