@tsparticles/cli 2.0.4 → 2.1.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.
@@ -12,11 +12,11 @@ jobs:
12
12
  runs-on: ubuntu-latest
13
13
  if: ${{ github.event_name != 'pull_request' }}
14
14
  steps:
15
- - uses: actions/checkout@v3
15
+ - uses: actions/checkout@v4
16
16
  name: Checkout [main]
17
17
  with:
18
18
  fetch-depth: 0
19
- - uses: actions/setup-node@v3
19
+ - uses: actions/setup-node@v4
20
20
  with:
21
21
  node-version: "16"
22
22
  - uses: pnpm/action-setup@v2.4.0
@@ -35,7 +35,7 @@ jobs:
35
35
  run: |
36
36
  echo "::set-output name=pnpm_cache_dir::$(pnpm store path)"
37
37
 
38
- - uses: actions/cache@v3
38
+ - uses: actions/cache@v4
39
39
  name: Setup pnpm cache
40
40
  with:
41
41
  path: ${{ steps.pnpm-cache.outputs.pnpm_cache_dir }}
@@ -49,12 +49,12 @@ jobs:
49
49
  runs-on: ubuntu-latest
50
50
  if: ${{ github.event_name == 'pull_request' }}
51
51
  steps:
52
- - uses: actions/checkout@v3
52
+ - uses: actions/checkout@v4
53
53
  with:
54
54
  ref: ${{ github.event.pull_request.head.ref }}
55
55
  repository: ${{ github.event.pull_request.head.repo.full_name }}
56
56
  fetch-depth: 0
57
- - uses: actions/setup-node@v3
57
+ - uses: actions/setup-node@v4
58
58
  with:
59
59
  node-version: "16"
60
60
  - uses: pnpm/action-setup@v2.4.0
@@ -73,7 +73,7 @@ jobs:
73
73
  run: |
74
74
  echo "::set-output name=pnpm_cache_dir::$(pnpm store path)"
75
75
 
76
- - uses: actions/cache@v3
76
+ - uses: actions/cache@v4
77
77
  name: Setup pnpm cache
78
78
  with:
79
79
  path: ${{ steps.pnpm-cache.outputs.pnpm_cache_dir }}
@@ -48,7 +48,7 @@ async function buildDistFiles(basePath) {
48
48
  libObj.peerDependencies = JSON.parse(JSON.stringify(pkgInfo.peerDependencies).replaceAll("workspace:", ""));
49
49
  }
50
50
  const jsonIndent = 2;
51
- fs_extra_1.default.writeFileSync(libPackage, `${JSON.stringify(libObj, undefined, jsonIndent)}\n`, "utf8");
51
+ await fs_extra_1.default.writeFile(libPackage, `${JSON.stringify(libObj, undefined, jsonIndent)}\n`, "utf8");
52
52
  console.log(`package.dist.json updated successfully to version ${pkgInfo.version}`);
53
53
  const rootFilesToCopy = [
54
54
  "LICENSE",
@@ -60,14 +60,14 @@ async function buildDistFiles(basePath) {
60
60
  ];
61
61
  for (const file of rootFilesToCopy) {
62
62
  const src = path_1.default.join(basePath, typeof file === "string" ? file : file.source), dest = path_1.default.join(distPath, typeof file === "string" ? file : file.destination);
63
- fs_extra_1.default.copyFileSync(src, dest);
63
+ await fs_extra_1.default.copyFile(src, dest);
64
64
  }
65
65
  const scriptsPath = path_1.default.join(basePath, "scripts"), distScriptsPath = path_1.default.join(distPath, "scripts");
66
- if (fs_extra_1.default.existsSync(scriptsPath) && !fs_extra_1.default.existsSync(distScriptsPath)) {
67
- fs_extra_1.default.mkdirSync(distScriptsPath);
66
+ if ((await fs_extra_1.default.exists(scriptsPath)) && !(await fs_extra_1.default.exists(distScriptsPath))) {
67
+ await fs_extra_1.default.mkdir(distScriptsPath);
68
68
  const installPath = path_1.default.join(scriptsPath, "install.js");
69
- if (fs_extra_1.default.existsSync(installPath)) {
70
- fs_extra_1.default.copyFileSync(installPath, path_1.default.join(distScriptsPath, "install.js"));
69
+ if (await fs_extra_1.default.exists(installPath)) {
70
+ await fs_extra_1.default.copyFile(installPath, path_1.default.join(distScriptsPath, "install.js"));
71
71
  }
72
72
  }
73
73
  for await (const file of (0, klaw_1.default)(distPath)) {
@@ -28,7 +28,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
29
  exports.getDistStats = void 0;
30
30
  const fs_extra_1 = __importDefault(require("fs-extra"));
31
- const path_1 = __importDefault(require("path"));
32
31
  /**
33
32
  * @param folderPath - the path to the folder to get the stats for
34
33
  * @param bundlePath - the bundle path to get the bundle size for
@@ -44,20 +43,20 @@ async function getFolderStats(folderPath, bundlePath) {
44
43
  if (!(await fs_extra_1.default.pathExists(folderPath))) {
45
44
  return stats;
46
45
  }
47
- const dir = await fs_extra_1.default.promises.opendir(folderPath);
46
+ const dir = await fs_extra_1.default.promises.opendir(folderPath), path = await Promise.resolve().then(() => __importStar(require("path")));
48
47
  for await (const dirent of dir) {
49
48
  const increment = 1;
50
49
  if (dirent.isDirectory()) {
51
- const subDirStats = await getFolderStats(path_1.default.join(folderPath, dirent.name), bundlePath);
50
+ const subDirStats = await getFolderStats(path.join(folderPath, dirent.name), bundlePath);
52
51
  stats.totalFolders += subDirStats.totalFolders + increment;
53
52
  stats.totalFiles += subDirStats.totalFiles;
54
53
  stats.totalSize += subDirStats.totalSize;
55
54
  }
56
55
  else {
57
- const fileStats = await fs_extra_1.default.stat(path_1.default.join(folderPath, dirent.name));
56
+ const fileStats = await fs_extra_1.default.stat(path.join(folderPath, dirent.name));
58
57
  stats.totalFiles++;
59
58
  stats.totalSize += fileStats.size;
60
- if (bundlePath && path_1.default.join(folderPath, dirent.name) === bundlePath) {
59
+ if (bundlePath && path.join(folderPath, dirent.name) === bundlePath) {
61
60
  stats.bundleSize += fileStats.size;
62
61
  }
63
62
  }
@@ -70,10 +69,10 @@ async function getFolderStats(folderPath, bundlePath) {
70
69
  * @returns the stats for the dist folder
71
70
  */
72
71
  async function getDistStats(basePath) {
73
- const distFolder = path_1.default.join(basePath, "dist"), pkgInfo = (await fs_extra_1.default.exists(path_1.default.join(distFolder, "package.json")))
74
- ? (await Promise.resolve(`${path_1.default.join(distFolder, "package.json")}`).then(s => __importStar(require(s))))
72
+ const path = await Promise.resolve().then(() => __importStar(require("path"))), distFolder = path.join(basePath, "dist"), pkgInfo = (await fs_extra_1.default.exists(path.join(distFolder, "package.json")))
73
+ ? (await Promise.resolve(`${path.join(distFolder, "package.json")}`).then(s => __importStar(require(s))))
75
74
  : {}, bundlePath = (await fs_extra_1.default.exists(distFolder)) && pkgInfo.jsdelivr
76
- ? path_1.default.resolve(path_1.default.join(distFolder, pkgInfo.jsdelivr))
75
+ ? path.resolve(path.join(distFolder, pkgInfo.jsdelivr))
77
76
  : undefined;
78
77
  return await getFolderStats(distFolder, bundlePath);
79
78
  }
@@ -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
  };
@@ -6,7 +29,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
29
  exports.buildTS = void 0;
7
30
  const fs_extra_1 = __importDefault(require("fs-extra"));
8
31
  const path_1 = __importDefault(require("path"));
9
- const typescript_1 = __importDefault(require("typescript"));
10
32
  /**
11
33
  * @param basePath -
12
34
  * @param file -
@@ -102,20 +124,20 @@ async function compile(basePath, type) {
102
124
  if (!options) {
103
125
  return 3 /* ExitCodes.NoOptions */;
104
126
  }
105
- const parsed = typescript_1.default.parseJsonConfigFileContent(options, typescript_1.default.sys, basePath);
127
+ const ts = await Promise.resolve().then(() => __importStar(require("typescript"))), parsed = ts.parseJsonConfigFileContent(options, ts.sys, basePath);
106
128
  if (!parsed) {
107
129
  return 4 /* ExitCodes.ParseError */;
108
130
  }
109
- const program = typescript_1.default.createProgram(parsed.fileNames, parsed.options), emitResult = program.emit(), allDiagnostics = typescript_1.default.getPreEmitDiagnostics(program).concat(emitResult.diagnostics);
131
+ const program = ts.createProgram(parsed.fileNames, parsed.options), emitResult = program.emit(), allDiagnostics = ts.getPreEmitDiagnostics(program).concat(emitResult.diagnostics);
110
132
  let failed = false;
111
133
  allDiagnostics.forEach(diagnostic => {
112
- failed = failed || diagnostic.category === typescript_1.default.DiagnosticCategory.Error;
134
+ failed = failed || diagnostic.category === ts.DiagnosticCategory.Error;
113
135
  if (diagnostic.file) {
114
- const startingPos = 0, { line, character } = typescript_1.default.getLineAndCharacterOfPosition(diagnostic.file, diagnostic.start ?? startingPos), message = typescript_1.default.flattenDiagnosticMessageText(diagnostic.messageText, "\n"), increment = 1;
136
+ const startingPos = 0, { line, character } = ts.getLineAndCharacterOfPosition(diagnostic.file, diagnostic.start ?? startingPos), message = ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n"), increment = 1;
115
137
  console.log(`${diagnostic.file.fileName} (${line + increment},${character + increment}): ${message}`);
116
138
  }
117
139
  else {
118
- console.log(typescript_1.default.flattenDiagnosticMessageText(diagnostic.messageText, "\n"));
140
+ console.log(ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n"));
119
141
  }
120
142
  });
121
143
  const exitCode = emitResult.emitSkipped || failed ? 1 /* ExitCodes.EmitErrors */ : 0 /* ExitCodes.OK */;
@@ -1,19 +1,30 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
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;
4
24
  };
5
25
  Object.defineProperty(exports, "__esModule", { value: true });
6
26
  exports.buildCommand = void 0;
7
- const build_prettier_1 = require("./build-prettier");
8
27
  const commander_1 = require("commander");
9
- const build_distfiles_1 = require("./build-distfiles");
10
- const build_tsc_1 = require("./build-tsc");
11
- const build_bundle_1 = require("./build-bundle");
12
- const build_clear_1 = require("./build-clear");
13
- const fs_extra_1 = __importDefault(require("fs-extra"));
14
- const build_diststats_1 = require("./build-diststats");
15
- const build_eslint_1 = require("./build-eslint");
16
- const path_1 = __importDefault(require("path"));
17
28
  const buildCommand = new commander_1.Command("build");
18
29
  exports.buildCommand = buildCommand;
19
30
  buildCommand.description("Build the tsParticles library using TypeScript");
@@ -28,39 +39,46 @@ buildCommand.option("-t, --tsc", "Build the library using TypeScript", false);
28
39
  buildCommand.argument("[path]", `Path to the project root folder, default is "src"`, "src");
29
40
  buildCommand.action(async (argPath) => {
30
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;
31
- const basePath = process.cwd(), oldStats = await (0, build_diststats_1.getDistStats)(basePath);
42
+ const basePath = process.cwd(), { getDistStats } = await Promise.resolve().then(() => __importStar(require("./build-diststats.js"))), oldStats = await getDistStats(basePath);
32
43
  if (clean) {
33
- await (0, build_clear_1.clearDist)(basePath);
44
+ const { clearDist } = await Promise.resolve().then(() => __importStar(require("./build-clear.js")));
45
+ await clearDist(basePath);
34
46
  }
35
- const srcPath = path_1.default.join(basePath, argPath);
36
- if (!(await fs_extra_1.default.pathExists(srcPath))) {
47
+ const path = await Promise.resolve().then(() => __importStar(require("path"))), srcPath = path.join(basePath, argPath), fs = await Promise.resolve().then(() => __importStar(require("fs-extra")));
48
+ if (!(await fs.pathExists(srcPath))) {
37
49
  throw new Error("Provided path does not exist");
38
50
  }
39
51
  let canContinue = true;
40
52
  if (canContinue && prettier) {
41
- canContinue = await (0, build_prettier_1.prettifySrc)(basePath, srcPath, ci);
53
+ const { prettifySrc } = await Promise.resolve().then(() => __importStar(require("./build-prettier.js")));
54
+ canContinue = await prettifySrc(basePath, srcPath, ci);
42
55
  }
43
56
  if (canContinue && doLint) {
44
- canContinue = await (0, build_eslint_1.lint)(ci);
57
+ const { lint } = await Promise.resolve().then(() => __importStar(require("./build-eslint.js")));
58
+ canContinue = await lint(ci);
45
59
  }
46
60
  if (canContinue && tsc) {
47
- canContinue = await (0, build_tsc_1.buildTS)(basePath);
61
+ const { buildTS } = await Promise.resolve().then(() => __importStar(require("./build-tsc.js")));
62
+ canContinue = await buildTS(basePath);
48
63
  }
49
64
  if (canContinue && doBundle) {
50
- canContinue = await (0, build_bundle_1.bundle)(basePath);
65
+ const { bundle } = await Promise.resolve().then(() => __importStar(require("./build-bundle.js")));
66
+ canContinue = await bundle(basePath);
51
67
  }
52
68
  if (canContinue && prettier) {
53
- canContinue = await (0, build_prettier_1.prettifyReadme)(basePath, ci);
54
- canContinue = await (0, build_prettier_1.prettifyPackageJson)(basePath, ci);
55
- canContinue = await (0, build_prettier_1.prettifyPackageDistJson)(basePath, ci);
69
+ const { prettifyReadme, prettifyPackageJson, prettifyPackageDistJson } = await Promise.resolve().then(() => __importStar(require("./build-prettier")));
70
+ canContinue = await prettifyReadme(basePath, ci);
71
+ canContinue = await prettifyPackageJson(basePath, ci);
72
+ canContinue = await prettifyPackageDistJson(basePath, ci);
56
73
  }
57
74
  if (canContinue && distfiles) {
58
- canContinue = await (0, build_distfiles_1.buildDistFiles)(basePath);
75
+ const { buildDistFiles } = await Promise.resolve().then(() => __importStar(require("./build-distfiles.js")));
76
+ canContinue = await buildDistFiles(basePath);
59
77
  }
60
78
  if (!canContinue) {
61
79
  throw new Error("Build failed");
62
80
  }
63
- const newStats = await (0, build_diststats_1.getDistStats)(basePath), diffSize = newStats.totalSize - oldStats.totalSize, bundleDiffSize = newStats.bundleSize - oldStats.bundleSize, minSize = 0, bundleSizeIncreased = bundleDiffSize > minSize, outputFunc = bundleSizeIncreased ? console.warn : console.info, texts = [
81
+ const newStats = await getDistStats(basePath), diffSize = newStats.totalSize - oldStats.totalSize, bundleDiffSize = newStats.bundleSize - oldStats.bundleSize, minSize = 0, bundleSizeIncreased = bundleDiffSize > minSize, outputFunc = bundleSizeIncreased ? console.warn : console.info, texts = [
64
82
  !bundleDiffSize
65
83
  ? "Bundle size unchanged"
66
84
  : `Bundle size ${bundleSizeIncreased ? "increased" : "decreased"} from ${oldStats.bundleSize} to ${newStats.bundleSize} (${Math.abs(bundleDiffSize)}B)`,
@@ -15,8 +15,7 @@ exports.pluginCommand = pluginCommand;
15
15
  pluginCommand.description("Create a new tsParticles plugin");
16
16
  pluginCommand.argument("<destination>", "Destination folder");
17
17
  pluginCommand.action(async (destination) => {
18
- const destPath = await (0, file_utils_1.getDestinationDir)(destination), repoUrl = await (0, file_utils_1.getRepositoryUrl)();
19
- const initialName = destPath.split(path_1.default.sep).pop(), questions = [
18
+ const destPath = await (0, file_utils_1.getDestinationDir)(destination), repoUrl = await (0, file_utils_1.getRepositoryUrl)(), initialName = destPath.split(path_1.default.sep).pop(), questions = [
20
19
  {
21
20
  type: "text",
22
21
  name: "name",
@@ -37,7 +36,6 @@ pluginCommand.action(async (destination) => {
37
36
  message: "What is the repository URL? (optional)",
38
37
  initial: repoUrl.trim(),
39
38
  },
40
- ];
41
- const { name, description, repositoryUrl } = (await (0, prompts_1.default)(questions));
39
+ ], { name, description, repositoryUrl } = (await (0, prompts_1.default)(questions));
42
40
  await (0, create_plugin_1.createPluginTemplate)(name.trim(), description.trim(), repositoryUrl.trim(), destPath);
43
41
  });
@@ -15,8 +15,7 @@ exports.presetCommand = presetCommand;
15
15
  presetCommand.description("Create a new tsParticles preset");
16
16
  presetCommand.argument("<destination>", "Destination folder");
17
17
  presetCommand.action(async (destination) => {
18
- const destPath = await (0, file_utils_1.getDestinationDir)(destination), repoUrl = await (0, file_utils_1.getRepositoryUrl)();
19
- const initialName = destPath.split(path_1.default.sep).pop(), questions = [
18
+ const destPath = await (0, file_utils_1.getDestinationDir)(destination), repoUrl = await (0, file_utils_1.getRepositoryUrl)(), initialName = destPath.split(path_1.default.sep).pop(), questions = [
20
19
  {
21
20
  type: "text",
22
21
  name: "name",
@@ -37,7 +36,6 @@ presetCommand.action(async (destination) => {
37
36
  message: "What is the repository URL? (optional)",
38
37
  initial: repoUrl.trim(),
39
38
  },
40
- ];
41
- const { name, description, repositoryUrl } = (await (0, prompts_1.default)(questions));
39
+ ], { name, description, repositoryUrl } = (await (0, prompts_1.default)(questions));
42
40
  await (0, create_preset_1.createPresetTemplate)(name.trim(), description.trim(), repositoryUrl.trim(), destPath);
43
41
  });
@@ -15,8 +15,7 @@ exports.shapeCommand = shapeCommand;
15
15
  shapeCommand.description("Create a new tsParticles shape");
16
16
  shapeCommand.argument("<destination>", "Destination folder");
17
17
  shapeCommand.action(async (destination) => {
18
- const destPath = await (0, file_utils_1.getDestinationDir)(destination), repoUrl = await (0, file_utils_1.getRepositoryUrl)();
19
- const initialName = destPath.split(path_1.default.sep).pop(), questions = [
18
+ const destPath = await (0, file_utils_1.getDestinationDir)(destination), repoUrl = await (0, file_utils_1.getRepositoryUrl)(), initialName = destPath.split(path_1.default.sep).pop(), questions = [
20
19
  {
21
20
  type: "text",
22
21
  name: "name",
@@ -37,7 +36,6 @@ shapeCommand.action(async (destination) => {
37
36
  message: "What is the repository URL? (optional)",
38
37
  initial: repoUrl.trim(),
39
38
  },
40
- ];
41
- const { name, description, repositoryUrl } = (await (0, prompts_1.default)(questions));
39
+ ], { name, description, repositoryUrl } = (await (0, prompts_1.default)(questions));
42
40
  await (0, create_shape_1.createShapeTemplate)(name.trim(), description.trim(), repositoryUrl.trim(), destPath);
43
41
  });
@@ -10,6 +10,7 @@ export class PluginInstance implements IContainerPlugin {
10
10
  }
11
11
 
12
12
  async init(): Promise<void> {
13
- // add your plugin initialization here
13
+ // add your plugin initialization here, replace the empty promise
14
+ return await Promise.resolve();
14
15
  }
15
16
  }
@@ -1,39 +1,10 @@
1
- import type { Container, Engine, IPlugin, ISourceOptions, Options } from "@tsparticles/engine";
2
- import { PluginInstance } from "./PluginInstance";
3
-
4
- /**
5
- */
6
- class Plugin implements IPlugin {
7
- readonly id;
8
-
9
- private readonly _engine;
10
-
11
- constructor(engine: Engine) {
12
- this.id = "#template#";
13
-
14
- this._engine = engine;
15
- }
16
-
17
- getPlugin(container: Container): PluginInstance {
18
- return new PluginInstance(container, this._engine);
19
- }
20
-
21
- loadOptions(_options: Options, _source?: ISourceOptions): void {
22
- if (!this.needsPlugin()) {
23
- return;
24
- }
25
-
26
- // Load your options here
27
- }
28
-
29
- needsPlugin(_options?: ISourceOptions): boolean {
30
- return true; // add your condition here
31
- }
32
- }
1
+ import type { Engine } from "@tsparticles/engine";
33
2
 
34
3
  /**
35
4
  * @param engine - The engine instance
36
5
  */
37
6
  export async function loadTemplatePlugin(engine: Engine): Promise<void> {
7
+ const { Plugin } = await import("./plugin.js");
8
+
38
9
  await engine.addPlugin(new Plugin(engine));
39
10
  }
@@ -0,0 +1,36 @@
1
+ import { type Container, type Engine, type IPlugin, type ISourceOptions, type Options } from "@tsparticles/engine";
2
+ import type { PluginInstance } from "./PluginInstance.js";
3
+
4
+ /**
5
+ */
6
+ export class Plugin implements IPlugin {
7
+ readonly id;
8
+
9
+ private readonly _engine;
10
+
11
+ constructor(engine: Engine) {
12
+ this.id = "#template#";
13
+
14
+ this._engine = engine;
15
+ }
16
+
17
+ async getPlugin(container: Container): Promise<PluginInstance> {
18
+ const { PluginInstance } = await import("./PluginInstance.js");
19
+
20
+ return new PluginInstance(container, this._engine);
21
+ }
22
+
23
+ loadOptions(_options: Options, _source?: ISourceOptions): void {
24
+ if (!this.needsPlugin()) {
25
+ // ignore plugin options when not needed
26
+
27
+ return;
28
+ }
29
+
30
+ // Load your options here
31
+ }
32
+
33
+ needsPlugin(_options?: ISourceOptions): boolean {
34
+ return true; // add your condition here, replace true with condition if needed
35
+ }
36
+ }
@@ -1,6 +1,6 @@
1
- import { loadTemplatePreset } from ".";
1
+ import { loadTemplatePreset } from "./index.js";
2
2
  import { tsParticles } from "@tsparticles/engine";
3
3
 
4
- loadTemplatePreset(tsParticles);
4
+ void loadTemplatePreset(tsParticles);
5
5
 
6
6
  export { loadTemplatePreset, tsParticles };
@@ -1,13 +1,14 @@
1
1
  import type { Engine } from "@tsparticles/engine";
2
- import { options } from "./options";
3
2
 
4
3
  /**
5
4
  *
6
5
  * @param engine - the engine instance to load the preset into
7
6
  */
8
- export function loadTemplatePreset(engine: Engine): void {
7
+ export async function loadTemplatePreset(engine: Engine): Promise<void> {
8
+ const { options } = await import("./options");
9
+
9
10
  // TODO: additional modules must be loaded here
10
11
 
11
12
  // Adds the preset to the engine, with the given options
12
- engine.addPreset("#template#", options);
13
+ await engine.addPreset("#template#", options);
13
14
  }
@@ -1,7 +1,7 @@
1
1
  import type { IShapeDrawData, IShapeDrawer } from "@tsparticles/engine";
2
2
 
3
3
  export class ShapeDrawer implements IShapeDrawer {
4
- draw(_data: IShapeDrawData): void {
4
+ async draw(_data: IShapeDrawData): Promise<void> {
5
5
  // draw the particle using the context
6
6
  // which is already centered in the particle position
7
7
  // colors are already handled, just draw the shape
@@ -10,5 +10,8 @@ export class ShapeDrawer implements IShapeDrawer {
10
10
  // pixelRatio is the canvas ratio used by the tsParticles instance, you may need it for density-independent shapes
11
11
  // the parameters have an underscore prefix because they're not used in this example
12
12
  // the underscore prefix can be removed for used parameters, the unused ones can be removed too
13
+
14
+ // remove this if there's already an await call
15
+ await Promise.resolve();
13
16
  }
14
17
  }
@@ -1,9 +1,10 @@
1
1
  import type { Engine } from "@tsparticles/engine";
2
- import { ShapeDrawer } from "./ShapeDrawer";
3
2
 
4
3
  /**
5
4
  * @param engine - the engine instance to load the shape into
6
5
  */
7
6
  export async function loadTemplateShape(engine: Engine): Promise<void> {
7
+ const { ShapeDrawer } = await import("./ShapeDrawer");
8
+
8
9
  await engine.addShape("#template#", new ShapeDrawer());
9
10
  }
@@ -72,6 +72,6 @@
72
72
  "module": "index.js",
73
73
  "types": "index.d.ts",
74
74
  "dependencies": {
75
- "@tsparticles/engine": "^3.0.2"
75
+ "@tsparticles/engine": "^3.0.3"
76
76
  }
77
77
  }
@@ -82,29 +82,29 @@
82
82
  "types": "dist/types/index.d.ts",
83
83
  "prettier": "@tsparticles/prettier-config",
84
84
  "devDependencies": {
85
- "@babel/core": "^7.23.6",
86
- "@tsparticles/cli": "^2.0.4",
87
- "@tsparticles/eslint-config": "^2.0.2",
88
- "@tsparticles/prettier-config": "^2.0.1",
85
+ "@babel/core": "^7.23.9",
86
+ "@tsparticles/cli": "^2.1.0",
87
+ "@tsparticles/eslint-config": "^2.1.4",
88
+ "@tsparticles/prettier-config": "^2.1.0",
89
89
  "@tsparticles/tsconfig": "^2.0.1",
90
- "@tsparticles/webpack-plugin": "^2.0.2",
90
+ "@tsparticles/webpack-plugin": "^2.1.4",
91
91
  "@types/webpack-env": "^1.18.4",
92
- "@typescript-eslint/eslint-plugin": "^6.14.0",
93
- "@typescript-eslint/parser": "^6.14.0",
92
+ "@typescript-eslint/eslint-plugin": "^6.20.0",
93
+ "@typescript-eslint/parser": "^6.20.0",
94
94
  "babel-loader": "^9.1.3",
95
- "browserslist": "^4.22.1",
95
+ "browserslist": "^4.22.3",
96
96
  "copyfiles": "^2.4.1",
97
- "eslint": "^8.55.0",
97
+ "eslint": "^8.56.0",
98
98
  "eslint-config-prettier": "^9.1.0",
99
- "prettier": "^3.1.1",
99
+ "prettier": "^3.2.4",
100
100
  "rimraf": "^5.0.5",
101
- "terser-webpack-plugin": "^5.3.9",
101
+ "terser-webpack-plugin": "^5.3.10",
102
102
  "typescript": "^5.3.3",
103
- "webpack": "^5.89.0",
104
- "webpack-bundle-analyzer": "^4.10.0",
103
+ "webpack": "^5.90.0",
104
+ "webpack-bundle-analyzer": "^4.10.1",
105
105
  "webpack-cli": "^5.1.4"
106
106
  },
107
107
  "dependencies": {
108
- "@tsparticles/engine": "^3.0.2"
108
+ "@tsparticles/engine": "^3.2.0"
109
109
  }
110
110
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tsparticles/cli",
3
- "version": "2.0.4",
3
+ "version": "2.1.0",
4
4
  "license": "MIT",
5
5
  "bin": {
6
6
  "tsparticles-cli": "dist/cli.js"
@@ -10,36 +10,36 @@
10
10
  },
11
11
  "prettier": "@tsparticles/prettier-config",
12
12
  "dependencies": {
13
- "@tsparticles/eslint-config": "^2.0.4",
14
- "@tsparticles/prettier-config": "^2.0.1",
13
+ "@tsparticles/eslint-config": "^2.1.4",
14
+ "@tsparticles/prettier-config": "^2.1.0",
15
15
  "@tsparticles/tsconfig": "^2.0.1",
16
- "@tsparticles/webpack-plugin": "^2.0.4",
17
- "@typescript-eslint/eslint-plugin": "^6.14.0",
18
- "@typescript-eslint/parser": "^6.14.0",
16
+ "@tsparticles/webpack-plugin": "^2.1.4",
17
+ "@typescript-eslint/eslint-plugin": "^6.20.0",
18
+ "@typescript-eslint/parser": "^6.20.0",
19
19
  "commander": "^11.1.0",
20
- "eslint": "^8.55.0",
20
+ "eslint": "^8.56.0",
21
21
  "eslint-config-prettier": "^9.1.0",
22
- "eslint-plugin-jsdoc": "^46.9.0",
22
+ "eslint-plugin-jsdoc": "^48.0.4",
23
23
  "eslint-plugin-tsdoc": "^0.2.17",
24
24
  "fs-extra": "^11.2.0",
25
25
  "klaw": "^4.1.0",
26
26
  "lookpath": "^1.2.2",
27
27
  "path-scurry": "^1.10.1",
28
- "prettier": "^3.1.1",
28
+ "prettier": "^3.2.4",
29
29
  "prettier-plugin-multiline-arrays": "^3.0.1",
30
30
  "prompts": "^2.4.2",
31
31
  "rimraf": "^5.0.5",
32
32
  "typescript": "^5.3.3",
33
- "webpack": "^5.89.0"
33
+ "webpack": "^5.90.0"
34
34
  },
35
35
  "devDependencies": {
36
36
  "@types/chai": "^4.3.11",
37
37
  "@types/fs-extra": "^11.0.4",
38
38
  "@types/klaw": "^3.0.6",
39
39
  "@types/mocha": "^10.0.6",
40
- "@types/node": "^20.10.4",
40
+ "@types/node": "^20.11.13",
41
41
  "@types/prompts": "^2.4.9",
42
- "chai": "^4.3.10",
42
+ "chai": "^4.4.0",
43
43
  "cross-env": "^7.0.3",
44
44
  "mocha": "^10.2.0",
45
45
  "nyc": "^15.1.0",
@@ -35,7 +35,7 @@ export async function buildDistFiles(basePath: string): Promise<boolean> {
35
35
 
36
36
  const jsonIndent = 2;
37
37
 
38
- fs.writeFileSync(libPackage, `${JSON.stringify(libObj, undefined, jsonIndent)}\n`, "utf8");
38
+ await fs.writeFile(libPackage, `${JSON.stringify(libObj, undefined, jsonIndent)}\n`, "utf8");
39
39
 
40
40
  console.log(`package.dist.json updated successfully to version ${pkgInfo.version}`);
41
41
 
@@ -52,19 +52,19 @@ export async function buildDistFiles(basePath: string): Promise<boolean> {
52
52
  const src = path.join(basePath, typeof file === "string" ? file : file.source),
53
53
  dest = path.join(distPath, typeof file === "string" ? file : file.destination);
54
54
 
55
- fs.copyFileSync(src, dest);
55
+ await fs.copyFile(src, dest);
56
56
  }
57
57
 
58
58
  const scriptsPath = path.join(basePath, "scripts"),
59
59
  distScriptsPath = path.join(distPath, "scripts");
60
60
 
61
- if (fs.existsSync(scriptsPath) && !fs.existsSync(distScriptsPath)) {
62
- fs.mkdirSync(distScriptsPath);
61
+ if ((await fs.exists(scriptsPath)) && !(await fs.exists(distScriptsPath))) {
62
+ await fs.mkdir(distScriptsPath);
63
63
 
64
64
  const installPath = path.join(scriptsPath, "install.js");
65
65
 
66
- if (fs.existsSync(installPath)) {
67
- fs.copyFileSync(installPath, path.join(distScriptsPath, "install.js"));
66
+ if (await fs.exists(installPath)) {
67
+ await fs.copyFile(installPath, path.join(distScriptsPath, "install.js"));
68
68
  }
69
69
  }
70
70
 
@@ -1,5 +1,4 @@
1
1
  import fs from "fs-extra";
2
- import path from "path";
3
2
 
4
3
  export interface IDistStats {
5
4
  bundleSize: number;
@@ -25,7 +24,8 @@ async function getFolderStats(folderPath: string, bundlePath?: string): Promise<
25
24
  return stats;
26
25
  }
27
26
 
28
- const dir = await fs.promises.opendir(folderPath);
27
+ const dir = await fs.promises.opendir(folderPath),
28
+ path = await import("path");
29
29
 
30
30
  for await (const dirent of dir) {
31
31
  const increment = 1;
@@ -57,7 +57,8 @@ 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 distFolder = path.join(basePath, "dist"),
60
+ const path = await import("path"),
61
+ distFolder = path.join(basePath, "dist"),
61
62
  pkgInfo = (await fs.exists(path.join(distFolder, "package.json")))
62
63
  ? ((await import(path.join(distFolder, "package.json"))) as { jsdelivr?: string })
63
64
  : {},
@@ -1,6 +1,5 @@
1
1
  import fs from "fs-extra";
2
2
  import path from "path";
3
- import ts from "typescript";
4
3
 
5
4
  const enum ExitCodes {
6
5
  OK = 0,
@@ -123,7 +122,8 @@ async function compile(basePath: string, type: "browser" | "cjs" | "esm" | "type
123
122
  return ExitCodes.NoOptions;
124
123
  }
125
124
 
126
- const parsed = ts.parseJsonConfigFileContent(options, ts.sys, basePath);
125
+ const ts = await import("typescript"),
126
+ parsed = ts.parseJsonConfigFileContent(options, ts.sys, basePath);
127
127
 
128
128
  if (!parsed) {
129
129
  return ExitCodes.ParseError;
@@ -1,13 +1,4 @@
1
- import { prettifyPackageDistJson, prettifyPackageJson, prettifyReadme, prettifySrc } from "./build-prettier";
2
1
  import { Command } from "commander";
3
- import { buildDistFiles } from "./build-distfiles";
4
- import { buildTS } from "./build-tsc";
5
- import { bundle } from "./build-bundle";
6
- import { clearDist } from "./build-clear";
7
- import fs from "fs-extra";
8
- import { getDistStats } from "./build-diststats";
9
- import { lint } from "./build-eslint";
10
- import path from "path";
11
2
 
12
3
  const buildCommand = new Command("build");
13
4
 
@@ -42,13 +33,18 @@ buildCommand.action(async (argPath: string) => {
42
33
  tsc = all || !!opts.tsc;
43
34
 
44
35
  const basePath = process.cwd(),
36
+ { getDistStats } = await import("./build-diststats.js"),
45
37
  oldStats = await getDistStats(basePath);
46
38
 
47
39
  if (clean) {
40
+ const { clearDist } = await import("./build-clear.js");
41
+
48
42
  await clearDist(basePath);
49
43
  }
50
44
 
51
- const srcPath = path.join(basePath, argPath);
45
+ const path = await import("path"),
46
+ srcPath = path.join(basePath, argPath),
47
+ fs = await import("fs-extra");
52
48
 
53
49
  if (!(await fs.pathExists(srcPath))) {
54
50
  throw new Error("Provided path does not exist");
@@ -57,28 +53,40 @@ buildCommand.action(async (argPath: string) => {
57
53
  let canContinue = true;
58
54
 
59
55
  if (canContinue && prettier) {
56
+ const { prettifySrc } = await import("./build-prettier.js");
57
+
60
58
  canContinue = await prettifySrc(basePath, srcPath, ci);
61
59
  }
62
60
 
63
61
  if (canContinue && doLint) {
62
+ const { lint } = await import("./build-eslint.js");
63
+
64
64
  canContinue = await lint(ci);
65
65
  }
66
66
 
67
67
  if (canContinue && tsc) {
68
+ const { buildTS } = await import("./build-tsc.js");
69
+
68
70
  canContinue = await buildTS(basePath);
69
71
  }
70
72
 
71
73
  if (canContinue && doBundle) {
74
+ const { bundle } = await import("./build-bundle.js");
75
+
72
76
  canContinue = await bundle(basePath);
73
77
  }
74
78
 
75
79
  if (canContinue && prettier) {
80
+ const { prettifyReadme, prettifyPackageJson, prettifyPackageDistJson } = await import("./build-prettier");
81
+
76
82
  canContinue = await prettifyReadme(basePath, ci);
77
83
  canContinue = await prettifyPackageJson(basePath, ci);
78
84
  canContinue = await prettifyPackageDistJson(basePath, ci);
79
85
  }
80
86
 
81
87
  if (canContinue && distfiles) {
88
+ const { buildDistFiles } = await import("./build-distfiles.js");
89
+
82
90
  canContinue = await buildDistFiles(basePath);
83
91
  }
84
92
 
@@ -11,9 +11,8 @@ pluginCommand.description("Create a new tsParticles plugin");
11
11
  pluginCommand.argument("<destination>", "Destination folder");
12
12
  pluginCommand.action(async (destination: string) => {
13
13
  const destPath = await getDestinationDir(destination),
14
- repoUrl = await getRepositoryUrl();
15
-
16
- const initialName = destPath.split(path.sep).pop(),
14
+ repoUrl = await getRepositoryUrl(),
15
+ initialName = destPath.split(path.sep).pop(),
17
16
  questions: PromptObject[] = [
18
17
  {
19
18
  type: "text",
@@ -35,13 +34,12 @@ pluginCommand.action(async (destination: string) => {
35
34
  message: "What is the repository URL? (optional)",
36
35
  initial: repoUrl.trim(),
37
36
  },
38
- ];
39
-
40
- const { name, description, repositoryUrl } = (await prompts(questions)) as {
41
- description: string;
42
- name: string;
43
- repositoryUrl: string;
44
- };
37
+ ],
38
+ { name, description, repositoryUrl } = (await prompts(questions)) as {
39
+ description: string;
40
+ name: string;
41
+ repositoryUrl: string;
42
+ };
45
43
 
46
44
  await createPluginTemplate(name.trim(), description.trim(), repositoryUrl.trim(), destPath);
47
45
  });
@@ -11,9 +11,8 @@ presetCommand.description("Create a new tsParticles preset");
11
11
  presetCommand.argument("<destination>", "Destination folder");
12
12
  presetCommand.action(async (destination: string) => {
13
13
  const destPath = await getDestinationDir(destination),
14
- repoUrl = await getRepositoryUrl();
15
-
16
- const initialName = destPath.split(path.sep).pop(),
14
+ repoUrl = await getRepositoryUrl(),
15
+ initialName = destPath.split(path.sep).pop(),
17
16
  questions: PromptObject[] = [
18
17
  {
19
18
  type: "text",
@@ -35,13 +34,12 @@ presetCommand.action(async (destination: string) => {
35
34
  message: "What is the repository URL? (optional)",
36
35
  initial: repoUrl.trim(),
37
36
  },
38
- ];
39
-
40
- const { name, description, repositoryUrl } = (await prompts(questions)) as {
41
- description: string;
42
- name: string;
43
- repositoryUrl: string;
44
- };
37
+ ],
38
+ { name, description, repositoryUrl } = (await prompts(questions)) as {
39
+ description: string;
40
+ name: string;
41
+ repositoryUrl: string;
42
+ };
45
43
 
46
44
  await createPresetTemplate(name.trim(), description.trim(), repositoryUrl.trim(), destPath);
47
45
  });
@@ -11,9 +11,8 @@ shapeCommand.description("Create a new tsParticles shape");
11
11
  shapeCommand.argument("<destination>", "Destination folder");
12
12
  shapeCommand.action(async (destination: string) => {
13
13
  const destPath = await getDestinationDir(destination),
14
- repoUrl = await getRepositoryUrl();
15
-
16
- const initialName = destPath.split(path.sep).pop(),
14
+ repoUrl = await getRepositoryUrl(),
15
+ initialName = destPath.split(path.sep).pop(),
17
16
  questions: PromptObject[] = [
18
17
  {
19
18
  type: "text",
@@ -35,13 +34,12 @@ shapeCommand.action(async (destination: string) => {
35
34
  message: "What is the repository URL? (optional)",
36
35
  initial: repoUrl.trim(),
37
36
  },
38
- ];
39
-
40
- const { name, description, repositoryUrl } = (await prompts(questions)) as {
41
- description: string;
42
- name: string;
43
- repositoryUrl: string;
44
- };
37
+ ],
38
+ { name, description, repositoryUrl } = (await prompts(questions)) as {
39
+ description: string;
40
+ name: string;
41
+ repositoryUrl: string;
42
+ };
45
43
 
46
44
  await createShapeTemplate(name.trim(), description.trim(), repositoryUrl.trim(), destPath);
47
45
  });
package/src/tsconfig.json CHANGED
@@ -85,7 +85,7 @@
85
85
  /* Ensure that casing is correct in imports. */
86
86
 
87
87
  /* Type Checking */
88
- "strict": true
88
+ "strict": true,
89
89
  /* Enable all strict type-checking options. */
90
90
  // "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */
91
91
  // "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */
@@ -111,5 +111,5 @@
111
111
  // "skipLibCheck": true
112
112
  /* Skip type checking all .d.ts files. */
113
113
  },
114
- "references": [{ "path": "../" }]
114
+ "references": [{ "path": "../" }],
115
115
  }
@@ -4,7 +4,7 @@ import { createPresetTemplate } from "../src/create/preset/create-preset";
4
4
  import path from "path";
5
5
  import fs from "fs-extra";
6
6
 
7
- describe("create-plugin", async () => {
7
+ describe("create-preset", async () => {
8
8
  it("should have created the preset project", async () => {
9
9
  const destDir = path.resolve(path.join(__dirname, "tmp-files", "foo-preset"));
10
10