@tsparticles/cli 1.3.3 → 1.4.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.
|
@@ -1,4 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
27
|
};
|
|
@@ -8,10 +31,12 @@ const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
|
8
31
|
const path_1 = __importDefault(require("path"));
|
|
9
32
|
/**
|
|
10
33
|
* @param folderPath - the path to the folder to get the stats for
|
|
34
|
+
* @param bundlePath - the bundle path to get the bundle size for
|
|
11
35
|
* @returns the given folder stats;
|
|
12
36
|
*/
|
|
13
|
-
async function getFolderStats(folderPath) {
|
|
37
|
+
async function getFolderStats(folderPath, bundlePath) {
|
|
14
38
|
const stats = {
|
|
39
|
+
bundleSize: 0,
|
|
15
40
|
totalFiles: 0,
|
|
16
41
|
totalFolders: 0,
|
|
17
42
|
totalSize: 0,
|
|
@@ -22,7 +47,7 @@ async function getFolderStats(folderPath) {
|
|
|
22
47
|
const dir = await fs_extra_1.default.promises.opendir(folderPath);
|
|
23
48
|
for await (const dirent of dir) {
|
|
24
49
|
if (dirent.isDirectory()) {
|
|
25
|
-
const subDirStats = await getFolderStats(path_1.default.join(folderPath, dirent.name));
|
|
50
|
+
const subDirStats = await getFolderStats(path_1.default.join(folderPath, dirent.name), bundlePath);
|
|
26
51
|
stats.totalFolders += subDirStats.totalFolders + 1;
|
|
27
52
|
stats.totalFiles += subDirStats.totalFiles;
|
|
28
53
|
stats.totalSize += subDirStats.totalSize;
|
|
@@ -31,6 +56,9 @@ async function getFolderStats(folderPath) {
|
|
|
31
56
|
const fileStats = await fs_extra_1.default.stat(path_1.default.join(folderPath, dirent.name));
|
|
32
57
|
stats.totalFiles++;
|
|
33
58
|
stats.totalSize += fileStats.size;
|
|
59
|
+
if (bundlePath && path_1.default.join(folderPath, dirent.name) === bundlePath) {
|
|
60
|
+
stats.bundleSize += fileStats.size;
|
|
61
|
+
}
|
|
34
62
|
}
|
|
35
63
|
}
|
|
36
64
|
return stats;
|
|
@@ -41,6 +69,9 @@ async function getFolderStats(folderPath) {
|
|
|
41
69
|
* @returns the stats for the dist folder
|
|
42
70
|
*/
|
|
43
71
|
async function getDistStats(basePath) {
|
|
44
|
-
|
|
72
|
+
const distFolder = path_1.default.join(basePath, "dist"), pkgInfo = (await fs_extra_1.default.exists(distFolder)) ? await Promise.resolve(`${path_1.default.join(distFolder, "package.json")}`).then(s => __importStar(require(s))) : {}, bundlePath = (await fs_extra_1.default.exists(distFolder)) && pkgInfo.jsdelivr
|
|
73
|
+
? path_1.default.resolve(path_1.default.join(distFolder, pkgInfo.jsdelivr))
|
|
74
|
+
: undefined;
|
|
75
|
+
return await getFolderStats(distFolder, bundlePath);
|
|
45
76
|
}
|
|
46
77
|
exports.getDistStats = getDistStats;
|
package/dist/build/build.js
CHANGED
|
@@ -28,8 +28,7 @@ buildCommand.option("-t, --tsc", "Build the library using TypeScript", false);
|
|
|
28
28
|
buildCommand.argument("[path]", `Path to the project root folder, default is "src"`, "src");
|
|
29
29
|
buildCommand.action(async (argPath) => {
|
|
30
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;
|
|
31
|
-
const basePath = process.cwd();
|
|
32
|
-
const oldStats = await (0, build_diststats_1.getDistStats)(basePath);
|
|
31
|
+
const basePath = process.cwd(), oldStats = await (0, build_diststats_1.getDistStats)(basePath);
|
|
33
32
|
if (clean) {
|
|
34
33
|
await (0, build_clear_1.clearDist)(basePath);
|
|
35
34
|
}
|
|
@@ -59,11 +58,16 @@ buildCommand.action(async (argPath) => {
|
|
|
59
58
|
if (!canContinue) {
|
|
60
59
|
throw new Error("Build failed");
|
|
61
60
|
}
|
|
62
|
-
const newStats = await (0, build_diststats_1.getDistStats)(basePath), diffSize = newStats.totalSize - oldStats.totalSize, texts = [
|
|
63
|
-
|
|
61
|
+
const newStats = await (0, build_diststats_1.getDistStats)(basePath), diffSize = newStats.totalSize - oldStats.totalSize, bundleDiffSize = newStats.bundleSize - oldStats.bundleSize, bundleSizeIncreased = bundleDiffSize > 0, outputFunc = bundleSizeIncreased ? console.warn : console.info, texts = [
|
|
62
|
+
!bundleDiffSize
|
|
63
|
+
? "Bundle size unchanged"
|
|
64
|
+
: `Bundle size ${bundleSizeIncreased ? "increased" : "decreased"} from ${oldStats.bundleSize} to ${newStats.bundleSize} (${Math.abs(bundleDiffSize)}B)`,
|
|
65
|
+
!diffSize
|
|
66
|
+
? "Size unchanged"
|
|
67
|
+
: `Size ${diffSize > 0 ? "increased" : "decreased"} from ${oldStats.totalSize} to ${newStats.totalSize} (${Math.abs(diffSize)}B)`,
|
|
64
68
|
`Files count changed from ${oldStats.totalFiles} to ${newStats.totalFiles} (${newStats.totalFiles - oldStats.totalFiles})`,
|
|
65
69
|
`Folders count changed from ${oldStats.totalFolders} to ${newStats.totalFolders} (${newStats.totalFolders - oldStats.totalFolders})`,
|
|
66
|
-
]
|
|
70
|
+
];
|
|
67
71
|
console.log("Build finished successfully!");
|
|
68
72
|
for (const text of texts) {
|
|
69
73
|
outputFunc(text);
|
|
@@ -83,7 +83,7 @@
|
|
|
83
83
|
"prettier": "@tsparticles/prettier-config",
|
|
84
84
|
"devDependencies": {
|
|
85
85
|
"@babel/core": "^7.21.4",
|
|
86
|
-
"@tsparticles/cli": "^1.
|
|
86
|
+
"@tsparticles/cli": "^1.3.3",
|
|
87
87
|
"@tsparticles/eslint-config": "^1.11.0",
|
|
88
88
|
"@tsparticles/prettier-config": "^1.9.0",
|
|
89
89
|
"@tsparticles/tsconfig": "^1.12.0",
|
package/package.json
CHANGED
|
@@ -2,6 +2,7 @@ import fs from "fs-extra";
|
|
|
2
2
|
import path from "path";
|
|
3
3
|
|
|
4
4
|
export interface IDistStats {
|
|
5
|
+
bundleSize: number;
|
|
5
6
|
totalFiles: number;
|
|
6
7
|
totalFolders: number;
|
|
7
8
|
totalSize: number;
|
|
@@ -9,10 +10,12 @@ export interface IDistStats {
|
|
|
9
10
|
|
|
10
11
|
/**
|
|
11
12
|
* @param folderPath - the path to the folder to get the stats for
|
|
13
|
+
* @param bundlePath - the bundle path to get the bundle size for
|
|
12
14
|
* @returns the given folder stats;
|
|
13
15
|
*/
|
|
14
|
-
async function getFolderStats(folderPath: string): Promise<IDistStats> {
|
|
16
|
+
async function getFolderStats(folderPath: string, bundlePath?: string): Promise<IDistStats> {
|
|
15
17
|
const stats: IDistStats = {
|
|
18
|
+
bundleSize: 0,
|
|
16
19
|
totalFiles: 0,
|
|
17
20
|
totalFolders: 0,
|
|
18
21
|
totalSize: 0,
|
|
@@ -26,7 +29,7 @@ async function getFolderStats(folderPath: string): Promise<IDistStats> {
|
|
|
26
29
|
|
|
27
30
|
for await (const dirent of dir) {
|
|
28
31
|
if (dirent.isDirectory()) {
|
|
29
|
-
const subDirStats = await getFolderStats(path.join(folderPath, dirent.name));
|
|
32
|
+
const subDirStats = await getFolderStats(path.join(folderPath, dirent.name), bundlePath);
|
|
30
33
|
|
|
31
34
|
stats.totalFolders += subDirStats.totalFolders + 1;
|
|
32
35
|
stats.totalFiles += subDirStats.totalFiles;
|
|
@@ -36,6 +39,10 @@ async function getFolderStats(folderPath: string): Promise<IDistStats> {
|
|
|
36
39
|
|
|
37
40
|
stats.totalFiles++;
|
|
38
41
|
stats.totalSize += fileStats.size;
|
|
42
|
+
|
|
43
|
+
if (bundlePath && path.join(folderPath, dirent.name) === bundlePath) {
|
|
44
|
+
stats.bundleSize += fileStats.size;
|
|
45
|
+
}
|
|
39
46
|
}
|
|
40
47
|
}
|
|
41
48
|
|
|
@@ -48,5 +55,12 @@ async function getFolderStats(folderPath: string): Promise<IDistStats> {
|
|
|
48
55
|
* @returns the stats for the dist folder
|
|
49
56
|
*/
|
|
50
57
|
export async function getDistStats(basePath: string): Promise<IDistStats> {
|
|
51
|
-
|
|
58
|
+
const distFolder = path.join(basePath, "dist"),
|
|
59
|
+
pkgInfo = (await fs.exists(distFolder)) ? await import(path.join(distFolder, "package.json")) : {},
|
|
60
|
+
bundlePath =
|
|
61
|
+
(await fs.exists(distFolder)) && pkgInfo.jsdelivr
|
|
62
|
+
? path.resolve(path.join(distFolder, pkgInfo.jsdelivr))
|
|
63
|
+
: undefined;
|
|
64
|
+
|
|
65
|
+
return await getFolderStats(distFolder, bundlePath);
|
|
52
66
|
}
|
package/src/build/build.ts
CHANGED
|
@@ -41,9 +41,8 @@ buildCommand.action(async (argPath: string) => {
|
|
|
41
41
|
prettier = all || !!opts.prettify,
|
|
42
42
|
tsc = all || !!opts.tsc;
|
|
43
43
|
|
|
44
|
-
const basePath = process.cwd()
|
|
45
|
-
|
|
46
|
-
const oldStats = await getDistStats(basePath);
|
|
44
|
+
const basePath = process.cwd(),
|
|
45
|
+
oldStats = await getDistStats(basePath);
|
|
47
46
|
|
|
48
47
|
if (clean) {
|
|
49
48
|
await clearDist(basePath);
|
|
@@ -87,17 +86,27 @@ buildCommand.action(async (argPath: string) => {
|
|
|
87
86
|
|
|
88
87
|
const newStats = await getDistStats(basePath),
|
|
89
88
|
diffSize = newStats.totalSize - oldStats.totalSize,
|
|
89
|
+
bundleDiffSize = newStats.bundleSize - oldStats.bundleSize,
|
|
90
|
+
bundleSizeIncreased = bundleDiffSize > 0,
|
|
91
|
+
outputFunc = bundleSizeIncreased ? console.warn : console.info,
|
|
90
92
|
texts = [
|
|
91
|
-
|
|
93
|
+
!bundleDiffSize
|
|
94
|
+
? "Bundle size unchanged"
|
|
95
|
+
: `Bundle size ${bundleSizeIncreased ? "increased" : "decreased"} from ${oldStats.bundleSize} to ${
|
|
96
|
+
newStats.bundleSize
|
|
97
|
+
} (${Math.abs(bundleDiffSize)}B)`,
|
|
98
|
+
!diffSize
|
|
99
|
+
? "Size unchanged"
|
|
100
|
+
: `Size ${diffSize > 0 ? "increased" : "decreased"} from ${oldStats.totalSize} to ${
|
|
101
|
+
newStats.totalSize
|
|
102
|
+
} (${Math.abs(diffSize)}B)`,
|
|
92
103
|
`Files count changed from ${oldStats.totalFiles} to ${newStats.totalFiles} (${
|
|
93
104
|
newStats.totalFiles - oldStats.totalFiles
|
|
94
105
|
})`,
|
|
95
106
|
`Folders count changed from ${oldStats.totalFolders} to ${newStats.totalFolders} (${
|
|
96
107
|
newStats.totalFolders - oldStats.totalFolders
|
|
97
108
|
})`,
|
|
98
|
-
]
|
|
99
|
-
sizeIncreased = diffSize > 0,
|
|
100
|
-
outputFunc = sizeIncreased ? console.warn : console.info;
|
|
109
|
+
];
|
|
101
110
|
|
|
102
111
|
console.log("Build finished successfully!");
|
|
103
112
|
|