@tsparticles/cli 2.1.0 → 2.2.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,34 @@
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.buildCircularDeps = void 0;
7
+ const madge_1 = __importDefault(require("madge"));
8
+ const path_1 = __importDefault(require("path"));
9
+ /**
10
+ *
11
+ * @param basePath -
12
+ * @returns true if no circular dependencies are found, false otherwise
13
+ */
14
+ async function buildCircularDeps(basePath) {
15
+ let res = false;
16
+ try {
17
+ const madgeRes = await (0, madge_1.default)(path_1.default.join(basePath, "src"), {
18
+ fileExtensions: ["ts"],
19
+ detectiveOptions: {
20
+ skipTypeImports: true,
21
+ },
22
+ }), circularDeps = madgeRes.circular();
23
+ if (circularDeps.length) {
24
+ throw new Error(`Circular dependencies found: ${circularDeps.join(", ")}`);
25
+ }
26
+ res = true;
27
+ }
28
+ catch (e) {
29
+ console.error(e);
30
+ }
31
+ console.log("Finished checking circular dependencies.");
32
+ return res;
33
+ }
34
+ exports.buildCircularDeps = buildCircularDeps;
@@ -32,13 +32,14 @@ buildCommand.option("-a, --all", "Do all build steps (default if no flags are sp
32
32
  buildCommand.option("-b, --bundle", "Bundle the library using Webpack", false);
33
33
  buildCommand.option("-c, --clean", "Clean the dist folder", false);
34
34
  buildCommand.option("--ci", "Do all build steps for CI, no fixing files, only checking if they are formatted correctly", false);
35
+ buildCommand.option("-cd, --circular-deps", "Check for circular dependencies", false);
35
36
  buildCommand.option("-d, --dist", "Build the dist files", false);
36
37
  buildCommand.option("-l, --lint", "Lint the source files", false);
37
38
  buildCommand.option("-p, --prettify", "Prettify the source files", false);
38
39
  buildCommand.option("-t, --tsc", "Build the library using TypeScript", false);
39
40
  buildCommand.argument("[path]", `Path to the project root folder, default is "src"`, "src");
40
41
  buildCommand.action(async (argPath) => {
41
- const opts = buildCommand.opts(), ci = !!opts.ci, all = !!opts.all || (!opts.bundle && !opts.clean && !opts.dist && !opts.lint && !opts.prettify && !opts.tsc), doBundle = all || !!opts.bundle, clean = all || !!opts.clean, distfiles = all || !!opts.dist, doLint = all || !!opts.lint, prettier = all || !!opts.prettify, tsc = all || !!opts.tsc;
42
+ const opts = buildCommand.opts(), ci = !!opts.ci, all = !!opts.all || (!opts.bundle && !opts.clean && !opts.dist && !opts.lint && !opts.prettify && !opts.tsc), doBundle = all || !!opts.bundle, circularDeps = all || !!opts.circularDeps, clean = all || !!opts.clean, distfiles = all || !!opts.dist, doLint = all || !!opts.lint, prettier = all || !!opts.prettify, tsc = all || !!opts.tsc;
42
43
  const basePath = process.cwd(), { getDistStats } = await Promise.resolve().then(() => __importStar(require("./build-diststats.js"))), oldStats = await getDistStats(basePath);
43
44
  if (clean) {
44
45
  const { clearDist } = await Promise.resolve().then(() => __importStar(require("./build-clear.js")));
@@ -61,6 +62,10 @@ buildCommand.action(async (argPath) => {
61
62
  const { buildTS } = await Promise.resolve().then(() => __importStar(require("./build-tsc.js")));
62
63
  canContinue = await buildTS(basePath);
63
64
  }
65
+ if (canContinue && circularDeps) {
66
+ const { buildCircularDeps } = await Promise.resolve().then(() => __importStar(require("./build-circular-deps.js")));
67
+ canContinue = await buildCircularDeps(basePath);
68
+ }
64
69
  if (canContinue && doBundle) {
65
70
  const { bundle } = await Promise.resolve().then(() => __importStar(require("./build-bundle.js")));
66
71
  canContinue = await bundle(basePath);
@@ -83,7 +83,7 @@
83
83
  "prettier": "@tsparticles/prettier-config",
84
84
  "devDependencies": {
85
85
  "@babel/core": "^7.23.9",
86
- "@tsparticles/cli": "^2.1.0",
86
+ "@tsparticles/cli": "^2.2.0",
87
87
  "@tsparticles/eslint-config": "^2.1.4",
88
88
  "@tsparticles/prettier-config": "^2.1.0",
89
89
  "@tsparticles/tsconfig": "^2.0.1",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tsparticles/cli",
3
- "version": "2.1.0",
3
+ "version": "2.2.0",
4
4
  "license": "MIT",
5
5
  "bin": {
6
6
  "tsparticles-cli": "dist/cli.js"
@@ -24,6 +24,7 @@
24
24
  "fs-extra": "^11.2.0",
25
25
  "klaw": "^4.1.0",
26
26
  "lookpath": "^1.2.2",
27
+ "madge": "^6.1.0",
27
28
  "path-scurry": "^1.10.1",
28
29
  "prettier": "^3.2.4",
29
30
  "prettier-plugin-multiline-arrays": "^3.0.1",
@@ -36,6 +37,7 @@
36
37
  "@types/chai": "^4.3.11",
37
38
  "@types/fs-extra": "^11.0.4",
38
39
  "@types/klaw": "^3.0.6",
40
+ "@types/madge": "^5.0.3",
39
41
  "@types/mocha": "^10.0.6",
40
42
  "@types/node": "^20.11.13",
41
43
  "@types/prompts": "^2.4.9",
@@ -55,12 +57,13 @@
55
57
  "prettify:readme": "prettier --write ./README.md",
56
58
  "lint": "eslint src --ext .js,.jsx,.ts,.tsx --fix",
57
59
  "lint:ci": "eslint src --ext .js,.jsx,.ts,.tsx",
60
+ "circular-deps": "madge --circular --extensions ts src",
58
61
  "compile": "pnpm run build:ts",
59
62
  "compile:ci": "pnpm run build:ts",
60
63
  "build:ts": "pnpm run build:ts:cjs",
61
64
  "build:ts:cjs": "tsc -p src",
62
65
  "test": "cross-env TS_NODE_PROJECT='./tests/tsconfig.json' nyc mocha --timeout 300000",
63
- "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",
66
+ "build": "pnpm run clear:dist && pnpm run prettify:src && pnpm run lint && pnpm run compile && pnpm run circular-deps && 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",
64
67
  "build:ci": "pnpm run clear:dist && pnpm run prettify:ci:src && pnpm run lint:ci && pnpm run compile && pnpm run prettify:ci:readme",
65
68
  "clear:dist": "rimraf ./dist",
66
69
  "version": "node scripts/postversion.js && git add files/empty-project/package.json"
@@ -0,0 +1,33 @@
1
+ import madge from "madge";
2
+ import path from "path";
3
+
4
+ /**
5
+ *
6
+ * @param basePath -
7
+ * @returns true if no circular dependencies are found, false otherwise
8
+ */
9
+ export async function buildCircularDeps(basePath: string): Promise<boolean> {
10
+ let res = false;
11
+
12
+ try {
13
+ const madgeRes = await madge(path.join(basePath, "src"), {
14
+ fileExtensions: ["ts"],
15
+ detectiveOptions: {
16
+ skipTypeImports: true,
17
+ },
18
+ }),
19
+ circularDeps = madgeRes.circular();
20
+
21
+ if (circularDeps.length) {
22
+ throw new Error(`Circular dependencies found: ${circularDeps.join(", ")}`);
23
+ }
24
+
25
+ res = true;
26
+ } catch (e) {
27
+ console.error(e);
28
+ }
29
+
30
+ console.log("Finished checking circular dependencies.");
31
+
32
+ return res;
33
+ }
@@ -15,6 +15,7 @@ buildCommand.option(
15
15
  "Do all build steps for CI, no fixing files, only checking if they are formatted correctly",
16
16
  false,
17
17
  );
18
+ buildCommand.option("-cd, --circular-deps", "Check for circular dependencies", false);
18
19
  buildCommand.option("-d, --dist", "Build the dist files", false);
19
20
  buildCommand.option("-l, --lint", "Lint the source files", false);
20
21
  buildCommand.option("-p, --prettify", "Prettify the source files", false);
@@ -26,6 +27,7 @@ buildCommand.action(async (argPath: string) => {
26
27
  ci = !!opts.ci,
27
28
  all = !!opts.all || (!opts.bundle && !opts.clean && !opts.dist && !opts.lint && !opts.prettify && !opts.tsc),
28
29
  doBundle = all || !!opts.bundle,
30
+ circularDeps = all || !!opts.circularDeps,
29
31
  clean = all || !!opts.clean,
30
32
  distfiles = all || !!opts.dist,
31
33
  doLint = all || !!opts.lint,
@@ -70,6 +72,12 @@ buildCommand.action(async (argPath: string) => {
70
72
  canContinue = await buildTS(basePath);
71
73
  }
72
74
 
75
+ if (canContinue && circularDeps) {
76
+ const { buildCircularDeps } = await import("./build-circular-deps.js");
77
+
78
+ canContinue = await buildCircularDeps(basePath);
79
+ }
80
+
73
81
  if (canContinue && doBundle) {
74
82
  const { bundle } = await import("./build-bundle.js");
75
83