@tsparticles/cli 2.0.0-beta.1 → 2.0.0-beta.11

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 (37) hide show
  1. package/.github/workflows/node.js-ci.yml +4 -4
  2. package/dist/build/build-distfiles.js +6 -5
  3. package/dist/build/build-prettier.js +67 -1
  4. package/dist/build/build.js +4 -2
  5. package/dist/create/plugin/create-plugin.js +2 -2
  6. package/dist/create/plugin/plugin.js +1 -1
  7. package/dist/create/preset/create-preset.js +2 -2
  8. package/dist/create/preset/preset.js +1 -1
  9. package/dist/create/shape/create-shape.js +2 -2
  10. package/dist/create/shape/shape.js +1 -1
  11. package/dist/utils/file-utils.js +12 -5
  12. package/dist/utils/template-utils.js +29 -6
  13. package/files/create-plugin/README.md +2 -2
  14. package/files/create-plugin/src/PluginInstance.ts +1 -1
  15. package/files/create-plugin/src/index.ts +1 -1
  16. package/files/create-preset/README.md +2 -2
  17. package/files/create-preset/src/bundle.ts +1 -1
  18. package/files/create-preset/src/index.ts +1 -1
  19. package/files/create-preset/src/options.ts +1 -1
  20. package/files/create-shape/README.md +2 -2
  21. package/files/create-shape/src/ShapeDrawer.ts +3 -8
  22. package/files/create-shape/src/index.ts +1 -1
  23. package/files/empty-project/package.dist.json +1 -1
  24. package/files/empty-project/package.json +16 -16
  25. package/package.json +23 -21
  26. package/src/build/build-distfiles.ts +2 -2
  27. package/src/build/build-prettier.ts +84 -0
  28. package/src/build/build.ts +5 -3
  29. package/src/create/plugin/create-plugin.ts +2 -2
  30. package/src/create/plugin/plugin.ts +1 -1
  31. package/src/create/preset/create-preset.ts +2 -2
  32. package/src/create/preset/preset.ts +1 -1
  33. package/src/create/shape/create-shape.ts +2 -2
  34. package/src/create/shape/shape.ts +1 -1
  35. package/src/utils/file-utils.ts +16 -5
  36. package/src/utils/template-utils.ts +44 -7
  37. package/tests/file-utils.test.ts +2 -2
@@ -43,8 +43,8 @@ jobs:
43
43
  restore-keys: |
44
44
  ${{ runner.os }}-pnpm-store-
45
45
  - run: pnpm install --no-frozen-lockfile
46
- - run: npx pnpm run build:ci
47
- - run: npx pnpm test
46
+ - run: pnpm run build:ci
47
+ - run: pnpm test
48
48
  pr:
49
49
  runs-on: ubuntu-latest
50
50
  if: ${{ github.event_name == 'pull_request' }}
@@ -81,5 +81,5 @@ jobs:
81
81
  restore-keys: |
82
82
  ${{ runner.os }}-pnpm-store-
83
83
  - run: pnpm install --no-frozen-lockfile
84
- - run: npx pnpm run build:ci
85
- - run: npx pnpm test
84
+ - run: pnpm run build:ci
85
+ - run: pnpm test
@@ -76,12 +76,13 @@ async function buildDistFiles(basePath) {
76
76
  const contents = await fs_extra_1.default.readFile(file.path, "utf8");
77
77
  await fs_extra_1.default.writeFile(file.path, contents.replaceAll("__VERSION__", `"${pkgInfo.version}"`), "utf8");
78
78
  }
79
- for await (const file of (0, klaw_1.default)(path_1.default.join(distPath, "cjs"))) {
80
- await fs_extra_1.default.rename(file.path, file.path.replace(/\.js$/, ".cjs"));
81
- }
82
- for await (const file of (0, klaw_1.default)(path_1.default.join(distPath, "esm"))) {
83
- await fs_extra_1.default.rename(file.path, file.path.replace(/\.js$/, ".mjs"));
79
+ /*for await (const file of klaw(path.join(distPath, "cjs"))) {
80
+ await fs.rename(file.path, file.path.replace(/\.js$/, ".cjs"));
84
81
  }
82
+
83
+ for await (const file of klaw(path.join(distPath, "esm"))) {
84
+ await fs.rename(file.path, file.path.replace(/\.js$/, ".mjs"));
85
+ }*/
85
86
  await fs_extra_1.default.writeFile(path_1.default.join(distPath, "cjs", "package.json"), `{ "type": "commonjs" }`);
86
87
  await fs_extra_1.default.writeFile(path_1.default.join(distPath, "esm", "package.json"), `{ "type": "module" }`);
87
88
  await fs_extra_1.default.writeFile(path_1.default.join(distPath, "browser", "package.json"), `{ "type": "module" }`);
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.prettifyReadme = exports.prettifySrc = void 0;
6
+ exports.prettifyReadme = exports.prettifyPackageDistJson = exports.prettifyPackageJson = exports.prettifySrc = void 0;
7
7
  const fs_extra_1 = __importDefault(require("fs-extra"));
8
8
  const klaw_1 = __importDefault(require("klaw"));
9
9
  const path_1 = __importDefault(require("path"));
@@ -47,6 +47,72 @@ async function prettifySrc(basePath, srcPath, ci) {
47
47
  return res;
48
48
  }
49
49
  exports.prettifySrc = prettifySrc;
50
+ /**
51
+ * @param basePath -
52
+ * @param ci -
53
+ * @returns true if the prettify package.json process was successful
54
+ */
55
+ async function prettifyPackageJson(basePath, ci) {
56
+ console.log("Prettier - started on package.json");
57
+ let res;
58
+ try {
59
+ const contents = await fs_extra_1.default.readFile("package.json", "utf8"), options = (await prettier_1.default.resolveConfig(basePath)) ?? {};
60
+ options.tabWidth = 2;
61
+ options.printWidth = 120;
62
+ options.endOfLine = "lf";
63
+ options.parser = "json";
64
+ if (ci) {
65
+ if (!(await prettier_1.default.check(contents, options))) {
66
+ throw new Error(`package.json is not formatted correctly`);
67
+ }
68
+ }
69
+ else {
70
+ const formatted = await prettier_1.default.format(contents, options);
71
+ await fs_extra_1.default.writeFile("package.json", formatted, "utf8");
72
+ }
73
+ res = true;
74
+ }
75
+ catch (e) {
76
+ console.error(e);
77
+ res = false;
78
+ }
79
+ console.log("Prettier - done on package.json");
80
+ return res;
81
+ }
82
+ exports.prettifyPackageJson = prettifyPackageJson;
83
+ /**
84
+ * @param basePath -
85
+ * @param _ci -
86
+ * @returns true if the prettify package.dist.json process was successful
87
+ */
88
+ async function prettifyPackageDistJson(basePath, _ci) {
89
+ console.log("Prettier - started on package.dist.json");
90
+ let res;
91
+ try {
92
+ const contents = await fs_extra_1.default.readFile("package.dist.json", "utf8"), options = (await prettier_1.default.resolveConfig(basePath)) ?? {};
93
+ options.tabWidth = 2;
94
+ options.printWidth = 120;
95
+ options.endOfLine = "lf";
96
+ options.parser = "json";
97
+ // TODO: disabled this check until "prettier-plugin-multiline-arrays" package is compatible with Prettier 3.0.0
98
+ /*if (ci) {
99
+ if (!(await prettier.check(contents, options))) {
100
+ throw new Error(`package.dist.json is not formatted correctly`);
101
+ }
102
+ } else {*/
103
+ const formatted = await prettier_1.default.format(contents, options);
104
+ await fs_extra_1.default.writeFile("package.dist.json", formatted, "utf8");
105
+ //}
106
+ res = true;
107
+ }
108
+ catch (e) {
109
+ console.error(e);
110
+ res = false;
111
+ }
112
+ console.log("Prettier - done on package.dist.json");
113
+ return res;
114
+ }
115
+ exports.prettifyPackageDistJson = prettifyPackageDistJson;
50
116
  /**
51
117
  * @param basePath -
52
118
  * @param ci -
@@ -17,7 +17,7 @@ const path_1 = __importDefault(require("path"));
17
17
  const buildCommand = new commander_1.Command("build");
18
18
  exports.buildCommand = buildCommand;
19
19
  buildCommand.description("Build the tsParticles library using TypeScript");
20
- buildCommand.option("-a, --all", "Do all build steps (default if no flags are specified) (same as -b -c -d -l -p -t)", true);
20
+ buildCommand.option("-a, --all", "Do all build steps (default if no flags are specified) (same as -b -c -d -l -p -t)", false);
21
21
  buildCommand.option("-b, --bundle", "Bundle the library using Webpack", false);
22
22
  buildCommand.option("-c, --clean", "Clean the dist folder", false);
23
23
  buildCommand.option("--ci", "Do all build steps for CI, no fixing files, only checking if they are formatted correctly", false);
@@ -27,7 +27,7 @@ buildCommand.option("-p, --prettify", "Prettify the source files", false);
27
27
  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
- 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
+ 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
31
  const basePath = process.cwd(), oldStats = await (0, build_diststats_1.getDistStats)(basePath);
32
32
  if (clean) {
33
33
  await (0, build_clear_1.clearDist)(basePath);
@@ -51,6 +51,8 @@ buildCommand.action(async (argPath) => {
51
51
  }
52
52
  if (canContinue && prettier) {
53
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);
54
56
  }
55
57
  if (canContinue && distfiles) {
56
58
  canContinue = await (0, build_distfiles_1.buildDistFiles)(basePath);
@@ -125,7 +125,7 @@ async function createPluginTemplate(name, description, repoUrl, destPath) {
125
125
  await updatePluginPackageDistFile(destPath, name, description, repoUrl);
126
126
  await updateReadmeFile(destPath, name, description, repoUrl);
127
127
  await updatePluginWebpackFile(destPath, name, description);
128
- (0, template_utils_1.runInstall)(destPath);
129
- (0, template_utils_1.runBuild)(destPath);
128
+ await (0, template_utils_1.runInstall)(destPath);
129
+ await (0, template_utils_1.runBuild)(destPath);
130
130
  }
131
131
  exports.createPluginTemplate = createPluginTemplate;
@@ -15,7 +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 = (0, file_utils_1.getRepositoryUrl)();
18
+ const destPath = await (0, file_utils_1.getDestinationDir)(destination), repoUrl = await (0, file_utils_1.getRepositoryUrl)();
19
19
  const initialName = destPath.split(path_1.default.sep).pop(), questions = [
20
20
  {
21
21
  type: "text",
@@ -143,7 +143,7 @@ async function createPresetTemplate(name, description, repoUrl, destPath) {
143
143
  await updatePresetPackageDistFile(destPath, name, description, repoUrl);
144
144
  await updateReadmeFile(destPath, name, description, repoUrl);
145
145
  await updatePresetWebpackFile(destPath, name, description);
146
- (0, template_utils_1.runInstall)(destPath);
147
- (0, template_utils_1.runBuild)(destPath);
146
+ await (0, template_utils_1.runInstall)(destPath);
147
+ await (0, template_utils_1.runBuild)(destPath);
148
148
  }
149
149
  exports.createPresetTemplate = createPresetTemplate;
@@ -15,7 +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 = (0, file_utils_1.getRepositoryUrl)();
18
+ const destPath = await (0, file_utils_1.getDestinationDir)(destination), repoUrl = await (0, file_utils_1.getRepositoryUrl)();
19
19
  const initialName = destPath.split(path_1.default.sep).pop(), questions = [
20
20
  {
21
21
  type: "text",
@@ -125,7 +125,7 @@ async function createShapeTemplate(name, description, repoUrl, destPath) {
125
125
  await updateShapePackageDistFile(destPath, name, description, repoUrl);
126
126
  await updateReadmeFile(destPath, name, description, repoUrl);
127
127
  await updateShapeWebpackFile(destPath, name, description);
128
- (0, template_utils_1.runInstall)(destPath);
129
- (0, template_utils_1.runBuild)(destPath);
128
+ await (0, template_utils_1.runInstall)(destPath);
129
+ await (0, template_utils_1.runBuild)(destPath);
130
130
  }
131
131
  exports.createShapeTemplate = createShapeTemplate;
@@ -15,7 +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 = (0, file_utils_1.getRepositoryUrl)();
18
+ const destPath = await (0, file_utils_1.getDestinationDir)(destination), repoUrl = await (0, file_utils_1.getRepositoryUrl)();
19
19
  const initialName = destPath.split(path_1.default.sep).pop(), questions = [
20
20
  {
21
21
  type: "text",
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.getRepositoryUrl = exports.getDestinationDir = exports.replaceTokensInFile = exports.replaceTokensInFiles = void 0;
7
7
  const child_process_1 = require("child_process");
8
8
  const fs_extra_1 = __importDefault(require("fs-extra"));
9
+ const lookpath_1 = require("lookpath");
9
10
  const path_1 = __importDefault(require("path"));
10
11
  /**
11
12
  *
@@ -51,12 +52,18 @@ exports.getDestinationDir = getDestinationDir;
51
52
  /**
52
53
  * @returns the repository URL
53
54
  */
54
- function getRepositoryUrl() {
55
- try {
56
- return (0, child_process_1.execSync)("git config --get remote.origin.url").toString();
57
- }
58
- catch {
55
+ async function getRepositoryUrl() {
56
+ if (!(await (0, lookpath_1.lookpath)("git"))) {
59
57
  return "";
60
58
  }
59
+ return new Promise((resolve, reject) => {
60
+ (0, child_process_1.exec)("git config --get remote.origin.url", (error, stdout) => {
61
+ if (error) {
62
+ reject(error);
63
+ return;
64
+ }
65
+ resolve(stdout.toString());
66
+ });
67
+ });
61
68
  }
62
69
  exports.getRepositoryUrl = getRepositoryUrl;
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.runBuild = exports.runInstall = exports.copyFilter = exports.copyEmptyTemplateFiles = exports.updateWebpackFile = exports.updatePackageDistFile = exports.updatePackageFile = void 0;
7
7
  const child_process_1 = require("child_process");
8
8
  const fs_extra_1 = __importDefault(require("fs-extra"));
9
+ const lookpath_1 = require("lookpath");
9
10
  const path_1 = __importDefault(require("path"));
10
11
  const file_utils_1 = require("./file-utils");
11
12
  /**
@@ -139,9 +140,20 @@ exports.copyFilter = copyFilter;
139
140
  * Runs npm install in the given path
140
141
  * @param destPath - The path where the project will be created
141
142
  */
142
- function runInstall(destPath) {
143
- (0, child_process_1.execSync)("npm install", {
144
- cwd: destPath,
143
+ async function runInstall(destPath) {
144
+ if (!(await (0, lookpath_1.lookpath)("npm"))) {
145
+ return;
146
+ }
147
+ return new Promise((resolve, reject) => {
148
+ (0, child_process_1.exec)("npm install", {
149
+ cwd: destPath,
150
+ }, error => {
151
+ if (error) {
152
+ reject(error);
153
+ return;
154
+ }
155
+ resolve();
156
+ });
145
157
  });
146
158
  }
147
159
  exports.runInstall = runInstall;
@@ -149,9 +161,20 @@ exports.runInstall = runInstall;
149
161
  * Runs npm run build in the given path
150
162
  * @param destPath - The path where the project will be build
151
163
  */
152
- function runBuild(destPath) {
153
- (0, child_process_1.execSync)("npm run build", {
154
- cwd: destPath,
164
+ async function runBuild(destPath) {
165
+ if (!(await (0, lookpath_1.lookpath)("npm"))) {
166
+ return;
167
+ }
168
+ return new Promise((resolve, reject) => {
169
+ (0, child_process_1.exec)("npm run build", {
170
+ cwd: destPath,
171
+ }, error => {
172
+ if (error) {
173
+ reject(error);
174
+ return;
175
+ }
176
+ resolve();
177
+ });
155
178
  });
156
179
  }
157
180
  exports.runBuild = runBuild;
@@ -54,7 +54,7 @@ $ yarn add tsparticles-plugin-template
54
54
  Then you need to import it in the app, like this:
55
55
 
56
56
  ```javascript
57
- const { tsParticles } = require("tsparticles-engine");
57
+ const { tsParticles } = require("@tsparticles/engine");
58
58
  const { loadTemplatePlugin } = require("tsparticles-plugin-template");
59
59
 
60
60
  (async () => {
@@ -65,7 +65,7 @@ const { loadTemplatePlugin } = require("tsparticles-plugin-template");
65
65
  or
66
66
 
67
67
  ```javascript
68
- import { tsParticles } from "tsparticles-engine";
68
+ import { tsParticles } from "@tsparticles/engine";
69
69
  import { loadTemplatePlugin } from "tsparticles-plugin-template";
70
70
 
71
71
  (async () => {
@@ -1,4 +1,4 @@
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
  private readonly _container;
@@ -1,4 +1,4 @@
1
- import type { Container, Engine, IPlugin, ISourceOptions, Options } from "tsparticles-engine";
1
+ import type { Container, Engine, IPlugin, ISourceOptions, Options } from "@tsparticles/engine";
2
2
  import { PluginInstance } from "./PluginInstance";
3
3
 
4
4
  /**
@@ -21,7 +21,7 @@ Once installed you need one more script to be included in your page (or you can
21
21
  from [jsDelivr](https://www.jsdelivr.com/package/npm/tsparticles-preset-template):
22
22
 
23
23
  ```html
24
- <script src="https://cdn.jsdelivr.net/npm/tsparticles-engine@2/tsparticles.engine.min.js"></script>
24
+ <script src="https://cdn.jsdelivr.net/npm/@tsparticles/engine@2/tsparticles.engine.min.js"></script>
25
25
  <script src="https://cdn.jsdelivr.net/npm/tsparticles-preset-template/tsparticles.preset.template.min.js"></script>
26
26
  ```
27
27
 
@@ -75,7 +75,7 @@ This sample uses the class component syntax, but you can use hooks as well (if t
75
75
 
76
76
  ```javascript
77
77
  import Particles from "react-particles";
78
- import { Engine } from "tsparticles-engine";
78
+ import { Engine } from "@tsparticles/engine";
79
79
  import { loadTemplatePreset } from "tsparticles-preset-template";
80
80
 
81
81
  export class ParticlesContainer extends React.PureComponent<IProps> {
@@ -1,5 +1,5 @@
1
1
  import { loadTemplatePreset } from ".";
2
- import { tsParticles } from "tsparticles-engine";
2
+ import { tsParticles } from "@tsparticles/engine";
3
3
 
4
4
  loadTemplatePreset(tsParticles);
5
5
 
@@ -1,4 +1,4 @@
1
- import type { Engine } from "tsparticles-engine";
1
+ import type { Engine } from "@tsparticles/engine";
2
2
  import { options } from "./options";
3
3
 
4
4
  /**
@@ -1,4 +1,4 @@
1
- import type { ISourceOptions } from "tsparticles-engine";
1
+ import type { ISourceOptions } from "@tsparticles/engine";
2
2
 
3
3
  // The options used by the preset
4
4
  export const options: ISourceOptions = {
@@ -55,7 +55,7 @@ $ yarn add tsparticles-shape-template
55
55
  Then you need to import it in the app, like this:
56
56
 
57
57
  ```javascript
58
- const { tsParticles } = require("tsparticles-engine");
58
+ const { tsParticles } = require("@tsparticles/engine");
59
59
  const { loadTemplateShape } = require("tsparticles-shape-template");
60
60
 
61
61
  (async () => {
@@ -66,7 +66,7 @@ const { loadTemplateShape } = require("tsparticles-shape-template");
66
66
  or
67
67
 
68
68
  ```javascript
69
- import { tsParticles } from "tsparticles-engine";
69
+ import { tsParticles } from "@tsparticles/engine";
70
70
  import { loadTemplateShape } from "tsparticles-shape-template";
71
71
 
72
72
  (async () => {
@@ -1,15 +1,10 @@
1
- import type { IDelta, IShapeDrawer, Particle } from "tsparticles-engine";
1
+ import type { IShapeDrawData, IShapeDrawer } from "@tsparticles/engine";
2
2
 
3
3
  export class ShapeDrawer implements IShapeDrawer {
4
- draw(_context: CanvasRenderingContext2D,
5
- _particle: Particle,
6
- _radius: number,
7
- _opacity: number,
8
- _delta: IDelta,
9
- _pixelRatio: number): void {
4
+ draw(_data: IShapeDrawData): void {
10
5
  // draw the particle using the context
11
6
  // which is already centered in the particle position
12
- // colors are already handles, just draw the shape
7
+ // colors are already handled, just draw the shape
13
8
  // the bounds are -radius to radius
14
9
  // delta is the frame time difference between the last frame and this one, in ms, use it for animated shapes
15
10
  // pixelRatio is the canvas ratio used by the tsParticles instance, you may need it for density-independent shapes
@@ -1,4 +1,4 @@
1
- import type { Engine } from "tsparticles-engine";
1
+ import type { Engine } from "@tsparticles/engine";
2
2
  import { ShapeDrawer } from "./ShapeDrawer";
3
3
 
4
4
  /**
@@ -72,6 +72,6 @@
72
72
  "module": "index.js",
73
73
  "types": "index.d.ts",
74
74
  "dependencies": {
75
- "tsparticles-engine": "^2.12.0"
75
+ "@tsparticles/engine": "^3.0.0-beta.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.22.9",
86
- "@tsparticles/cli": "^2.0.0-beta.1",
87
- "@tsparticles/eslint-config": "^1.19.0",
88
- "@tsparticles/prettier-config": "^1.12.0",
89
- "@tsparticles/tsconfig": "^1.14.0",
90
- "@tsparticles/webpack-plugin": "^1.23.0",
91
- "@types/webpack-env": "^1.18.1",
92
- "@typescript-eslint/eslint-plugin": "^6.2.1",
93
- "@typescript-eslint/parser": "^6.2.1",
85
+ "@babel/core": "^7.23.0",
86
+ "@tsparticles/cli": "^2.0.0-beta.11",
87
+ "@tsparticles/eslint-config": "^2.0.0-beta.2",
88
+ "@tsparticles/prettier-config": "^2.0.0-beta.2",
89
+ "@tsparticles/tsconfig": "^2.0.0-beta.1",
90
+ "@tsparticles/webpack-plugin": "^2.0.0-beta.2",
91
+ "@types/webpack-env": "^1.18.2",
92
+ "@typescript-eslint/eslint-plugin": "^6.7.4",
93
+ "@typescript-eslint/parser": "^6.7.4",
94
94
  "babel-loader": "^9.1.3",
95
- "browserslist": "^4.21.10",
95
+ "browserslist": "^4.22.1",
96
96
  "copyfiles": "^2.4.1",
97
- "eslint": "^8.46.0",
97
+ "eslint": "^8.51.0",
98
98
  "eslint-config-prettier": "^9.0.0",
99
- "prettier": "^3.0.1",
100
- "rimraf": "^5.0.1",
99
+ "prettier": "^3.0.3",
100
+ "rimraf": "^5.0.5",
101
101
  "terser-webpack-plugin": "^5.3.9",
102
- "typescript": "^5.1.6",
102
+ "typescript": "^5.2.2",
103
103
  "webpack": "^5.88.2",
104
- "webpack-bundle-analyzer": "^4.9.0",
104
+ "webpack-bundle-analyzer": "^4.9.1",
105
105
  "webpack-cli": "^5.1.4"
106
106
  },
107
107
  "dependencies": {
108
- "tsparticles-engine": "^2.12.0"
108
+ "@tsparticles/engine": "^3.0.0-beta.3"
109
109
  }
110
110
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tsparticles/cli",
3
- "version": "2.0.0-beta.1",
3
+ "version": "2.0.0-beta.11",
4
4
  "license": "MIT",
5
5
  "bin": {
6
6
  "tsparticles-cli": "dist/cli.js"
@@ -10,34 +10,36 @@
10
10
  },
11
11
  "prettier": "@tsparticles/prettier-config",
12
12
  "dependencies": {
13
- "@tsparticles/eslint-config": "^1.20.0",
14
- "@tsparticles/prettier-config": "^1.12.0",
15
- "@tsparticles/tsconfig": "^1.14.0",
16
- "@tsparticles/webpack-plugin": "^1.24.0",
17
- "@typescript-eslint/eslint-plugin": "^6.3.0",
18
- "@typescript-eslint/parser": "^6.3.0",
19
- "commander": "^11.0.0",
20
- "eslint": "^8.46.0",
13
+ "@tsparticles/eslint-config": "^2.0.0-beta.3",
14
+ "@tsparticles/prettier-config": "^2.0.0-beta.3",
15
+ "@tsparticles/tsconfig": "^2.0.0-beta.1",
16
+ "@tsparticles/webpack-plugin": "^2.0.0-beta.3",
17
+ "@typescript-eslint/eslint-plugin": "^6.8.0",
18
+ "@typescript-eslint/parser": "^6.8.0",
19
+ "commander": "^11.1.0",
20
+ "eslint": "^8.52.0",
21
21
  "eslint-config-prettier": "^9.0.0",
22
- "eslint-plugin-jsdoc": "^46.4.6",
22
+ "eslint-plugin-jsdoc": "^46.8.2",
23
23
  "eslint-plugin-tsdoc": "^0.2.17",
24
24
  "fs-extra": "^11.1.1",
25
25
  "klaw": "^4.1.0",
26
+ "lookpath": "^1.2.2",
26
27
  "path-scurry": "^1.10.1",
27
- "prettier": "^3.0.1",
28
+ "prettier": "^3.0.3",
29
+ "prettier-plugin-multiline-arrays": "^3.0.0",
28
30
  "prompts": "^2.4.2",
29
- "rimraf": "^5.0.1",
30
- "typescript": "^5.1.6",
31
- "webpack": "^5.88.2"
31
+ "rimraf": "^5.0.5",
32
+ "typescript": "^5.2.2",
33
+ "webpack": "^5.89.0"
32
34
  },
33
35
  "devDependencies": {
34
- "@types/chai": "^4.3.5",
35
- "@types/fs-extra": "^11.0.1",
36
- "@types/klaw": "^3.0.3",
37
- "@types/mocha": "^10.0.1",
38
- "@types/node": "^20.4.8",
39
- "@types/prompts": "^2.4.4",
40
- "chai": "^4.3.7",
36
+ "@types/chai": "^4.3.9",
37
+ "@types/fs-extra": "^11.0.3",
38
+ "@types/klaw": "^3.0.5",
39
+ "@types/mocha": "^10.0.3",
40
+ "@types/node": "^20.8.7",
41
+ "@types/prompts": "^2.4.7",
42
+ "chai": "^4.3.10",
41
43
  "cross-env": "^7.0.3",
42
44
  "mocha": "^10.2.0",
43
45
  "nyc": "^15.1.0",
@@ -71,13 +71,13 @@ export async function buildDistFiles(basePath: string): Promise<boolean> {
71
71
  await fs.writeFile(file.path, contents.replaceAll("__VERSION__", `"${pkgInfo.version}"`), "utf8");
72
72
  }
73
73
 
74
- for await (const file of klaw(path.join(distPath, "cjs"))) {
74
+ /*for await (const file of klaw(path.join(distPath, "cjs"))) {
75
75
  await fs.rename(file.path, file.path.replace(/\.js$/, ".cjs"));
76
76
  }
77
77
 
78
78
  for await (const file of klaw(path.join(distPath, "esm"))) {
79
79
  await fs.rename(file.path, file.path.replace(/\.js$/, ".mjs"));
80
- }
80
+ }*/
81
81
 
82
82
  await fs.writeFile(path.join(distPath, "cjs", "package.json"), `{ "type": "commonjs" }`);
83
83
  await fs.writeFile(path.join(distPath, "esm", "package.json"), `{ "type": "module" }`);
@@ -51,6 +51,90 @@ export async function prettifySrc(basePath: string, srcPath: string, ci: boolean
51
51
  return res;
52
52
  }
53
53
 
54
+ /**
55
+ * @param basePath -
56
+ * @param ci -
57
+ * @returns true if the prettify package.json process was successful
58
+ */
59
+ export async function prettifyPackageJson(basePath: string, ci: boolean): Promise<boolean> {
60
+ console.log("Prettier - started on package.json");
61
+
62
+ let res: boolean;
63
+
64
+ try {
65
+ const contents = await fs.readFile("package.json", "utf8"),
66
+ options = (await prettier.resolveConfig(basePath)) ?? {};
67
+
68
+ options.tabWidth = 2;
69
+ options.printWidth = 120;
70
+ options.endOfLine = "lf";
71
+ options.parser = "json";
72
+
73
+ if (ci) {
74
+ if (!(await prettier.check(contents, options))) {
75
+ throw new Error(`package.json is not formatted correctly`);
76
+ }
77
+ } else {
78
+ const formatted = await prettier.format(contents, options);
79
+
80
+ await fs.writeFile("package.json", formatted, "utf8");
81
+ }
82
+
83
+ res = true;
84
+ } catch (e) {
85
+ console.error(e);
86
+
87
+ res = false;
88
+ }
89
+
90
+ console.log("Prettier - done on package.json");
91
+
92
+ return res;
93
+ }
94
+
95
+ /**
96
+ * @param basePath -
97
+ * @param _ci -
98
+ * @returns true if the prettify package.dist.json process was successful
99
+ */
100
+ export async function prettifyPackageDistJson(basePath: string, _ci: boolean): Promise<boolean> {
101
+ console.log("Prettier - started on package.dist.json");
102
+
103
+ let res: boolean;
104
+
105
+ try {
106
+ const contents = await fs.readFile("package.dist.json", "utf8"),
107
+ options = (await prettier.resolveConfig(basePath)) ?? {};
108
+
109
+ options.tabWidth = 2;
110
+ options.printWidth = 120;
111
+ options.endOfLine = "lf";
112
+ options.parser = "json";
113
+
114
+ // TODO: disabled this check until "prettier-plugin-multiline-arrays" package is compatible with Prettier 3.0.0
115
+
116
+ /*if (ci) {
117
+ if (!(await prettier.check(contents, options))) {
118
+ throw new Error(`package.dist.json is not formatted correctly`);
119
+ }
120
+ } else {*/
121
+ const formatted = await prettier.format(contents, options);
122
+
123
+ await fs.writeFile("package.dist.json", formatted, "utf8");
124
+ //}
125
+
126
+ res = true;
127
+ } catch (e) {
128
+ console.error(e);
129
+
130
+ res = false;
131
+ }
132
+
133
+ console.log("Prettier - done on package.dist.json");
134
+
135
+ return res;
136
+ }
137
+
54
138
  /**
55
139
  * @param basePath -
56
140
  * @param ci -
@@ -1,4 +1,4 @@
1
- import { prettifyReadme, prettifySrc } from "./build-prettier";
1
+ import { prettifyPackageDistJson, prettifyPackageJson, prettifyReadme, prettifySrc } from "./build-prettier";
2
2
  import { Command } from "commander";
3
3
  import { buildDistFiles } from "./build-distfiles";
4
4
  import { buildTS } from "./build-tsc";
@@ -15,7 +15,7 @@ buildCommand.description("Build the tsParticles library using TypeScript");
15
15
  buildCommand.option(
16
16
  "-a, --all",
17
17
  "Do all build steps (default if no flags are specified) (same as -b -c -d -l -p -t)",
18
- true,
18
+ false,
19
19
  );
20
20
  buildCommand.option("-b, --bundle", "Bundle the library using Webpack", false);
21
21
  buildCommand.option("-c, --clean", "Clean the dist folder", false);
@@ -33,7 +33,7 @@ buildCommand.argument("[path]", `Path to the project root folder, default is "sr
33
33
  buildCommand.action(async (argPath: string) => {
34
34
  const opts = buildCommand.opts(),
35
35
  ci = !!opts.ci,
36
- all = !!opts.all,
36
+ all = !!opts.all || (!opts.bundle && !opts.clean && !opts.dist && !opts.lint && !opts.prettify && !opts.tsc),
37
37
  doBundle = all || !!opts.bundle,
38
38
  clean = all || !!opts.clean,
39
39
  distfiles = all || !!opts.dist,
@@ -74,6 +74,8 @@ buildCommand.action(async (argPath: string) => {
74
74
 
75
75
  if (canContinue && prettier) {
76
76
  canContinue = await prettifyReadme(basePath, ci);
77
+ canContinue = await prettifyPackageJson(basePath, ci);
78
+ canContinue = await prettifyPackageDistJson(basePath, ci);
77
79
  }
78
80
 
79
81
  if (canContinue && distfiles) {
@@ -175,6 +175,6 @@ export async function createPluginTemplate(
175
175
  await updateReadmeFile(destPath, name, description, repoUrl);
176
176
  await updatePluginWebpackFile(destPath, name, description);
177
177
 
178
- runInstall(destPath);
179
- runBuild(destPath);
178
+ await runInstall(destPath);
179
+ await runBuild(destPath);
180
180
  }
@@ -11,7 +11,7 @@ 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 = getRepositoryUrl();
14
+ repoUrl = await getRepositoryUrl();
15
15
 
16
16
  const initialName = destPath.split(path.sep).pop(),
17
17
  questions: PromptObject[] = [
@@ -194,6 +194,6 @@ export async function createPresetTemplate(
194
194
  await updateReadmeFile(destPath, name, description, repoUrl);
195
195
  await updatePresetWebpackFile(destPath, name, description);
196
196
 
197
- runInstall(destPath);
198
- runBuild(destPath);
197
+ await runInstall(destPath);
198
+ await runBuild(destPath);
199
199
  }
@@ -11,7 +11,7 @@ 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 = getRepositoryUrl();
14
+ repoUrl = await getRepositoryUrl();
15
15
 
16
16
  const initialName = destPath.split(path.sep).pop(),
17
17
  questions: PromptObject[] = [
@@ -174,6 +174,6 @@ export async function createShapeTemplate(
174
174
  await updateReadmeFile(destPath, name, description, repoUrl);
175
175
  await updateShapeWebpackFile(destPath, name, description);
176
176
 
177
- runInstall(destPath);
178
- runBuild(destPath);
177
+ await runInstall(destPath);
178
+ await runBuild(destPath);
179
179
  }
@@ -11,7 +11,7 @@ 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 = getRepositoryUrl();
14
+ repoUrl = await getRepositoryUrl();
15
15
 
16
16
  const initialName = destPath.split(path.sep).pop(),
17
17
  questions: PromptObject[] = [
@@ -1,5 +1,6 @@
1
- import { execSync } from "child_process";
1
+ import { exec } from "child_process";
2
2
  import fs from "fs-extra";
3
+ import { lookpath } from "lookpath";
3
4
  import path from "path";
4
5
 
5
6
  export type ReplaceTokensOptions = {
@@ -66,10 +67,20 @@ export async function getDestinationDir(destination: string): Promise<string> {
66
67
  /**
67
68
  * @returns the repository URL
68
69
  */
69
- export function getRepositoryUrl(): string {
70
- try {
71
- return execSync("git config --get remote.origin.url").toString();
72
- } catch {
70
+ export async function getRepositoryUrl(): Promise<string> {
71
+ if (!(await lookpath("git"))) {
73
72
  return "";
74
73
  }
74
+
75
+ return new Promise<string>((resolve, reject) => {
76
+ exec("git config --get remote.origin.url", (error, stdout) => {
77
+ if (error) {
78
+ reject(error);
79
+
80
+ return;
81
+ }
82
+
83
+ resolve(stdout.toString());
84
+ });
85
+ });
75
86
  }
@@ -1,5 +1,6 @@
1
- import { execSync } from "child_process";
1
+ import { exec } from "child_process";
2
2
  import fs from "fs-extra";
3
+ import { lookpath } from "lookpath";
3
4
  import path from "path";
4
5
  import { replaceTokensInFile } from "./file-utils";
5
6
 
@@ -151,9 +152,27 @@ export function copyFilter(src: string): boolean {
151
152
  * Runs npm install in the given path
152
153
  * @param destPath - The path where the project will be created
153
154
  */
154
- export function runInstall(destPath: string): void {
155
- execSync("npm install", {
156
- cwd: destPath,
155
+ export async function runInstall(destPath: string): Promise<void> {
156
+ if (!(await lookpath("npm"))) {
157
+ return;
158
+ }
159
+
160
+ return new Promise((resolve, reject) => {
161
+ exec(
162
+ "npm install",
163
+ {
164
+ cwd: destPath,
165
+ },
166
+ error => {
167
+ if (error) {
168
+ reject(error);
169
+
170
+ return;
171
+ }
172
+
173
+ resolve();
174
+ },
175
+ );
157
176
  });
158
177
  }
159
178
 
@@ -161,8 +180,26 @@ export function runInstall(destPath: string): void {
161
180
  * Runs npm run build in the given path
162
181
  * @param destPath - The path where the project will be build
163
182
  */
164
- export function runBuild(destPath: string): void {
165
- execSync("npm run build", {
166
- cwd: destPath,
183
+ export async function runBuild(destPath: string): Promise<void> {
184
+ if (!(await lookpath("npm"))) {
185
+ return;
186
+ }
187
+
188
+ return new Promise((resolve, reject) => {
189
+ exec(
190
+ "npm run build",
191
+ {
192
+ cwd: destPath,
193
+ },
194
+ error => {
195
+ if (error) {
196
+ reject(error);
197
+
198
+ return;
199
+ }
200
+
201
+ resolve();
202
+ },
203
+ );
167
204
  });
168
205
  }
@@ -90,8 +90,8 @@ describe("file-utils", async () => {
90
90
  });
91
91
 
92
92
  describe("get repository url", () => {
93
- it("should return the repository url", () => {
94
- expect(getRepositoryUrl()).to.be.not.equal("");
93
+ it("should return the repository url", async () => {
94
+ expect(await getRepositoryUrl()).to.be.not.equal("");
95
95
  });
96
96
  });
97
97