@tsparticles/cli 2.0.2 → 2.0.3

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.
@@ -47,7 +47,8 @@ async function buildDistFiles(basePath) {
47
47
  else if (pkgInfo.peerDependencies) {
48
48
  libObj.peerDependencies = JSON.parse(JSON.stringify(pkgInfo.peerDependencies).replaceAll("workspace:", ""));
49
49
  }
50
- fs_extra_1.default.writeFileSync(libPackage, `${JSON.stringify(libObj, undefined, 2)}\n`, "utf8");
50
+ const jsonIndent = 2;
51
+ fs_extra_1.default.writeFileSync(libPackage, `${JSON.stringify(libObj, undefined, jsonIndent)}\n`, "utf8");
51
52
  console.log(`package.dist.json updated successfully to version ${pkgInfo.version}`);
52
53
  const rootFilesToCopy = [
53
54
  "LICENSE",
@@ -46,9 +46,10 @@ async function getFolderStats(folderPath, bundlePath) {
46
46
  }
47
47
  const dir = await fs_extra_1.default.promises.opendir(folderPath);
48
48
  for await (const dirent of dir) {
49
+ const increment = 1;
49
50
  if (dirent.isDirectory()) {
50
51
  const subDirStats = await getFolderStats(path_1.default.join(folderPath, dirent.name), bundlePath);
51
- stats.totalFolders += subDirStats.totalFolders + 1;
52
+ stats.totalFolders += subDirStats.totalFolders + increment;
52
53
  stats.totalFiles += subDirStats.totalFiles;
53
54
  stats.totalSize += subDirStats.totalSize;
54
55
  }
@@ -19,8 +19,8 @@ async function lint(ci) {
19
19
  });
20
20
  const results = await eslint.lintFiles(["src"]), errors = eslint_1.ESLint.getErrorResults(results);
21
21
  await eslint_1.ESLint.outputFixes(results);
22
- const formatter = await eslint.loadFormatter("stylish"), resultText = formatter.format(results);
23
- if (errors.length > 0) {
22
+ const formatter = await eslint.loadFormatter("stylish"), resultText = formatter.format(results), minimumLength = 0;
23
+ if (errors.length > minimumLength) {
24
24
  const messages = errors.map(t => t.messages.map(m => `${t.filePath} (${m.line},${m.column}): ${m.message}`).join("\n"));
25
25
  throw new Error(messages.join("\n"));
26
26
  }
@@ -94,31 +94,31 @@ async function compile(basePath, type) {
94
94
  break;
95
95
  }
96
96
  if (!data && !options) {
97
- return 2;
97
+ return 2 /* ExitCodes.NoDataOrOptions */;
98
98
  }
99
99
  if (!options && data) {
100
100
  options = JSON.parse(data);
101
101
  }
102
102
  if (!options) {
103
- return 3;
103
+ return 3 /* ExitCodes.NoOptions */;
104
104
  }
105
105
  const parsed = typescript_1.default.parseJsonConfigFileContent(options, typescript_1.default.sys, basePath);
106
106
  if (!parsed) {
107
- return 4;
107
+ return 4 /* ExitCodes.ParseError */;
108
108
  }
109
109
  const program = typescript_1.default.createProgram(parsed.fileNames, parsed.options), emitResult = program.emit(), allDiagnostics = typescript_1.default.getPreEmitDiagnostics(program).concat(emitResult.diagnostics);
110
110
  let failed = false;
111
111
  allDiagnostics.forEach(diagnostic => {
112
112
  failed = failed || diagnostic.category === typescript_1.default.DiagnosticCategory.Error;
113
113
  if (diagnostic.file) {
114
- const { line, character } = typescript_1.default.getLineAndCharacterOfPosition(diagnostic.file, diagnostic.start ?? 0), message = typescript_1.default.flattenDiagnosticMessageText(diagnostic.messageText, "\n");
115
- console.log(`${diagnostic.file.fileName} (${line + 1},${character + 1}): ${message}`);
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;
115
+ console.log(`${diagnostic.file.fileName} (${line + increment},${character + increment}): ${message}`);
116
116
  }
117
117
  else {
118
118
  console.log(typescript_1.default.flattenDiagnosticMessageText(diagnostic.messageText, "\n"));
119
119
  }
120
120
  });
121
- const exitCode = emitResult.emitSkipped || failed ? 1 : 0;
121
+ const exitCode = emitResult.emitSkipped || failed ? 1 /* ExitCodes.EmitErrors */ : 0 /* ExitCodes.OK */;
122
122
  console.log(`TSC for ${type} done with exit code: '${exitCode}'.`);
123
123
  return exitCode;
124
124
  }
@@ -60,13 +60,13 @@ buildCommand.action(async (argPath) => {
60
60
  if (!canContinue) {
61
61
  throw new Error("Build failed");
62
62
  }
63
- 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 = [
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 = [
64
64
  !bundleDiffSize
65
65
  ? "Bundle size unchanged"
66
66
  : `Bundle size ${bundleSizeIncreased ? "increased" : "decreased"} from ${oldStats.bundleSize} to ${newStats.bundleSize} (${Math.abs(bundleDiffSize)}B)`,
67
67
  !diffSize
68
68
  ? "Size unchanged"
69
- : `Size ${diffSize > 0 ? "increased" : "decreased"} from ${oldStats.totalSize} to ${newStats.totalSize} (${Math.abs(diffSize)}B)`,
69
+ : `Size ${diffSize > minSize ? "increased" : "decreased"} from ${oldStats.totalSize} to ${newStats.totalSize} (${Math.abs(diffSize)}B)`,
70
70
  `Files count changed from ${oldStats.totalFiles} to ${newStats.totalFiles} (${newStats.totalFiles - oldStats.totalFiles})`,
71
71
  `Folders count changed from ${oldStats.totalFolders} to ${newStats.totalFolders} (${newStats.totalFolders - oldStats.totalFolders})`,
72
72
  ];
@@ -60,8 +60,8 @@ async function updatePluginPackageDistFile(destPath, name, description, repoUrl)
60
60
  * @param repoUrl - The repository url
61
61
  */
62
62
  async function updateReadmeFile(destPath, name, description, repoUrl) {
63
- const readmePath = path_1.default.resolve(destPath, "README.md"), capitalizedName = (0, string_utils_1.capitalize)(name, "-", " "), camelizedName = (0, string_utils_1.camelize)(capitalizedName), dashedName = (0, string_utils_1.dash)(camelizedName), repoPath = repoUrl.includes("github.com")
64
- ? repoUrl.substring(repoUrl.indexOf("github.com/") + 11, repoUrl.indexOf(".git"))
63
+ const readmePath = path_1.default.resolve(destPath, "README.md"), capitalizedName = (0, string_utils_1.capitalize)(name, "-", " "), camelizedName = (0, string_utils_1.camelize)(capitalizedName), dashedName = (0, string_utils_1.dash)(camelizedName), stringSearch = "github.com", trailingSlashSearch = "github.com/", repoPath = repoUrl.includes(stringSearch)
64
+ ? repoUrl.substring(repoUrl.indexOf(trailingSlashSearch) + trailingSlashSearch.length, repoUrl.indexOf(".git"))
65
65
  : "tsparticles/plugin-template";
66
66
  await (0, file_utils_1.replaceTokensInFile)({
67
67
  path: readmePath,
@@ -77,8 +77,8 @@ async function updatePresetPackageDistFile(destPath, name, description, repoUrl)
77
77
  * @param repoUrl - The repository url
78
78
  */
79
79
  async function updateReadmeFile(destPath, name, description, repoUrl) {
80
- const capitalizedName = (0, string_utils_1.capitalize)(name, "-", " "), camelizedName = (0, string_utils_1.camelize)(capitalizedName), dashedName = (0, string_utils_1.dash)(camelizedName), repoPath = repoUrl.includes("github.com")
81
- ? repoUrl.substring(repoUrl.indexOf("github.com/") + 11, repoUrl.indexOf(".git"))
80
+ const capitalizedName = (0, string_utils_1.capitalize)(name, "-", " "), camelizedName = (0, string_utils_1.camelize)(capitalizedName), dashedName = (0, string_utils_1.dash)(camelizedName), stringSearch = "github.com", trailingSlashSearch = "github.com/", repoPath = repoUrl.includes(stringSearch)
81
+ ? repoUrl.substring(repoUrl.indexOf(trailingSlashSearch) + trailingSlashSearch.length, repoUrl.indexOf(".git"))
82
82
  : "tsparticles/preset-template";
83
83
  await (0, file_utils_1.replaceTokensInFile)({
84
84
  path: path_1.default.resolve(destPath, "README.md"),
@@ -60,8 +60,8 @@ async function updateShapePackageDistFile(destPath, name, description, repoUrl)
60
60
  * @param repoUrl - The repository url
61
61
  */
62
62
  async function updateReadmeFile(destPath, name, description, repoUrl) {
63
- const capitalizedName = (0, string_utils_1.capitalize)(name, "-", " "), camelizedName = (0, string_utils_1.camelize)(capitalizedName), dashedName = (0, string_utils_1.dash)(camelizedName), repoPath = repoUrl.includes("github.com")
64
- ? repoUrl.substring(repoUrl.indexOf("github.com/") + 11, repoUrl.indexOf(".git"))
63
+ const capitalizedName = (0, string_utils_1.capitalize)(name, "-", " "), camelizedName = (0, string_utils_1.camelize)(capitalizedName), dashedName = (0, string_utils_1.dash)(camelizedName), stringSearch = "github.com", trailingSlashSearch = "github.com/", repoPath = repoUrl.includes(stringSearch)
64
+ ? repoUrl.substring(repoUrl.indexOf(trailingSlashSearch) + trailingSlashSearch.length, repoUrl.indexOf(".git"))
65
65
  : "tsparticles/shape-template";
66
66
  await (0, file_utils_1.replaceTokensInFile)({
67
67
  path: path_1.default.resolve(destPath, "README.md"),
@@ -34,7 +34,7 @@ exports.camelize = camelize;
34
34
  * @returns the dashed string
35
35
  */
36
36
  function dash(str) {
37
- const dashed = str.replace(/([A-Z])/g, g => `-${g[0].toLowerCase()}`);
38
- return dashed.startsWith("-") ? dashed.substring(1) : dashed;
37
+ const index = 0, dashed = str.replace(/([A-Z])/g, g => `-${g[index].toLowerCase()}`), startPos = 1;
38
+ return dashed.startsWith("-") ? dashed.substring(startPos) : dashed;
39
39
  }
40
40
  exports.dash = dash;
@@ -83,7 +83,7 @@
83
83
  "prettier": "@tsparticles/prettier-config",
84
84
  "devDependencies": {
85
85
  "@babel/core": "^7.23.6",
86
- "@tsparticles/cli": "^2.0.2",
86
+ "@tsparticles/cli": "^2.0.3",
87
87
  "@tsparticles/eslint-config": "^2.0.2",
88
88
  "@tsparticles/prettier-config": "^2.0.1",
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.0.2",
3
+ "version": "2.0.3",
4
4
  "license": "MIT",
5
5
  "bin": {
6
6
  "tsparticles-cli": "dist/cli.js"
@@ -10,10 +10,10 @@
10
10
  },
11
11
  "prettier": "@tsparticles/prettier-config",
12
12
  "dependencies": {
13
- "@tsparticles/eslint-config": "^2.0.2",
13
+ "@tsparticles/eslint-config": "^2.0.3",
14
14
  "@tsparticles/prettier-config": "^2.0.1",
15
15
  "@tsparticles/tsconfig": "^2.0.1",
16
- "@tsparticles/webpack-plugin": "^2.0.2",
16
+ "@tsparticles/webpack-plugin": "^2.0.3",
17
17
  "@typescript-eslint/eslint-plugin": "^6.14.0",
18
18
  "@typescript-eslint/parser": "^6.14.0",
19
19
  "commander": "^11.1.0",
@@ -33,7 +33,9 @@ export async function buildDistFiles(basePath: string): Promise<boolean> {
33
33
  libObj.peerDependencies = JSON.parse(JSON.stringify(pkgInfo.peerDependencies).replaceAll("workspace:", ""));
34
34
  }
35
35
 
36
- fs.writeFileSync(libPackage, `${JSON.stringify(libObj, undefined, 2)}\n`, "utf8");
36
+ const jsonIndent = 2;
37
+
38
+ fs.writeFileSync(libPackage, `${JSON.stringify(libObj, undefined, jsonIndent)}\n`, "utf8");
37
39
 
38
40
  console.log(`package.dist.json updated successfully to version ${pkgInfo.version}`);
39
41
 
@@ -28,10 +28,12 @@ async function getFolderStats(folderPath: string, bundlePath?: string): Promise<
28
28
  const dir = await fs.promises.opendir(folderPath);
29
29
 
30
30
  for await (const dirent of dir) {
31
+ const increment = 1;
32
+
31
33
  if (dirent.isDirectory()) {
32
34
  const subDirStats = await getFolderStats(path.join(folderPath, dirent.name), bundlePath);
33
35
 
34
- stats.totalFolders += subDirStats.totalFolders + 1;
36
+ stats.totalFolders += subDirStats.totalFolders + increment;
35
37
  stats.totalFiles += subDirStats.totalFiles;
36
38
  stats.totalSize += subDirStats.totalSize;
37
39
  } else {
@@ -24,9 +24,10 @@ export async function lint(ci: boolean): Promise<boolean> {
24
24
  await ESLint.outputFixes(results);
25
25
 
26
26
  const formatter = await eslint.loadFormatter("stylish"),
27
- resultText = formatter.format(results);
27
+ resultText = formatter.format(results),
28
+ minimumLength = 0;
28
29
 
29
- if (errors.length > 0) {
30
+ if (errors.length > minimumLength) {
30
31
  const messages = errors.map(t =>
31
32
  t.messages.map(m => `${t.filePath} (${m.line},${m.column}): ${m.message}`).join("\n"),
32
33
  );
@@ -2,6 +2,14 @@ import fs from "fs-extra";
2
2
  import path from "path";
3
3
  import ts from "typescript";
4
4
 
5
+ const enum ExitCodes {
6
+ OK,
7
+ EmitErrors,
8
+ NoDataOrOptions,
9
+ NoOptions,
10
+ ParseError,
11
+ }
12
+
5
13
  /**
6
14
  * @param basePath -
7
15
  * @param file -
@@ -104,7 +112,7 @@ async function compile(basePath: string, type: "browser" | "cjs" | "esm" | "type
104
112
  }
105
113
 
106
114
  if (!data && !options) {
107
- return 2;
115
+ return ExitCodes.NoDataOrOptions;
108
116
  }
109
117
 
110
118
  if (!options && data) {
@@ -112,13 +120,13 @@ async function compile(basePath: string, type: "browser" | "cjs" | "esm" | "type
112
120
  }
113
121
 
114
122
  if (!options) {
115
- return 3;
123
+ return ExitCodes.NoOptions;
116
124
  }
117
125
 
118
126
  const parsed = ts.parseJsonConfigFileContent(options, ts.sys, basePath);
119
127
 
120
128
  if (!parsed) {
121
- return 4;
129
+ return ExitCodes.ParseError;
122
130
  }
123
131
 
124
132
  const program = ts.createProgram(parsed.fileNames, parsed.options),
@@ -131,16 +139,21 @@ async function compile(basePath: string, type: "browser" | "cjs" | "esm" | "type
131
139
  failed = failed || diagnostic.category === ts.DiagnosticCategory.Error;
132
140
 
133
141
  if (diagnostic.file) {
134
- const { line, character } = ts.getLineAndCharacterOfPosition(diagnostic.file, diagnostic.start ?? 0),
135
- message = ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n");
136
-
137
- console.log(`${diagnostic.file.fileName} (${line + 1},${character + 1}): ${message}`);
142
+ const startingPos = 0,
143
+ { line, character } = ts.getLineAndCharacterOfPosition(
144
+ diagnostic.file,
145
+ diagnostic.start ?? startingPos,
146
+ ),
147
+ message = ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n"),
148
+ increment = 1;
149
+
150
+ console.log(`${diagnostic.file.fileName} (${line + increment},${character + increment}): ${message}`);
138
151
  } else {
139
152
  console.log(ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n"));
140
153
  }
141
154
  });
142
155
 
143
- const exitCode = emitResult.emitSkipped || failed ? 1 : 0;
156
+ const exitCode = emitResult.emitSkipped || failed ? ExitCodes.EmitErrors : ExitCodes.OK;
144
157
 
145
158
  console.log(`TSC for ${type} done with exit code: '${exitCode}'.`);
146
159
 
@@ -89,7 +89,8 @@ buildCommand.action(async (argPath: string) => {
89
89
  const newStats = await getDistStats(basePath),
90
90
  diffSize = newStats.totalSize - oldStats.totalSize,
91
91
  bundleDiffSize = newStats.bundleSize - oldStats.bundleSize,
92
- bundleSizeIncreased = bundleDiffSize > 0,
92
+ minSize = 0,
93
+ bundleSizeIncreased = bundleDiffSize > minSize,
93
94
  outputFunc = bundleSizeIncreased ? console.warn : console.info,
94
95
  texts = [
95
96
  !bundleDiffSize
@@ -99,7 +100,7 @@ buildCommand.action(async (argPath: string) => {
99
100
  } (${Math.abs(bundleDiffSize)}B)`,
100
101
  !diffSize
101
102
  ? "Size unchanged"
102
- : `Size ${diffSize > 0 ? "increased" : "decreased"} from ${oldStats.totalSize} to ${
103
+ : `Size ${diffSize > minSize ? "increased" : "decreased"} from ${oldStats.totalSize} to ${
103
104
  newStats.totalSize
104
105
  } (${Math.abs(diffSize)}B)`,
105
106
  `Files count changed from ${oldStats.totalFiles} to ${newStats.totalFiles} (${
@@ -98,8 +98,13 @@ async function updateReadmeFile(destPath: string, name: string, description: str
98
98
  capitalizedName = capitalize(name, "-", " "),
99
99
  camelizedName = camelize(capitalizedName),
100
100
  dashedName = dash(camelizedName),
101
- repoPath = repoUrl.includes("github.com")
102
- ? repoUrl.substring(repoUrl.indexOf("github.com/") + 11, repoUrl.indexOf(".git"))
101
+ stringSearch = "github.com",
102
+ trailingSlashSearch = "github.com/",
103
+ repoPath = repoUrl.includes(stringSearch)
104
+ ? repoUrl.substring(
105
+ repoUrl.indexOf(trailingSlashSearch) + trailingSlashSearch.length,
106
+ repoUrl.indexOf(".git"),
107
+ )
103
108
  : "tsparticles/plugin-template";
104
109
 
105
110
  await replaceTokensInFile({
@@ -116,8 +116,13 @@ async function updateReadmeFile(destPath: string, name: string, description: str
116
116
  const capitalizedName = capitalize(name, "-", " "),
117
117
  camelizedName = camelize(capitalizedName),
118
118
  dashedName = dash(camelizedName),
119
- repoPath = repoUrl.includes("github.com")
120
- ? repoUrl.substring(repoUrl.indexOf("github.com/") + 11, repoUrl.indexOf(".git"))
119
+ stringSearch = "github.com",
120
+ trailingSlashSearch = "github.com/",
121
+ repoPath = repoUrl.includes(stringSearch)
122
+ ? repoUrl.substring(
123
+ repoUrl.indexOf(trailingSlashSearch) + trailingSlashSearch.length,
124
+ repoUrl.indexOf(".git"),
125
+ )
121
126
  : "tsparticles/preset-template";
122
127
 
123
128
  await replaceTokensInFile({
@@ -97,8 +97,13 @@ async function updateReadmeFile(destPath: string, name: string, description: str
97
97
  const capitalizedName = capitalize(name, "-", " "),
98
98
  camelizedName = camelize(capitalizedName),
99
99
  dashedName = dash(camelizedName),
100
- repoPath = repoUrl.includes("github.com")
101
- ? repoUrl.substring(repoUrl.indexOf("github.com/") + 11, repoUrl.indexOf(".git"))
100
+ stringSearch = "github.com",
101
+ trailingSlashSearch = "github.com/",
102
+ repoPath = repoUrl.includes(stringSearch)
103
+ ? repoUrl.substring(
104
+ repoUrl.indexOf(trailingSlashSearch) + trailingSlashSearch.length,
105
+ repoUrl.indexOf(".git"),
106
+ )
102
107
  : "tsparticles/shape-template";
103
108
 
104
109
  await replaceTokensInFile({
@@ -33,7 +33,9 @@ export function camelize(str: string, ...splits: string[]): string {
33
33
  * @returns the dashed string
34
34
  */
35
35
  export function dash(str: string): string {
36
- const dashed = str.replace(/([A-Z])/g, g => `-${g[0].toLowerCase()}`);
36
+ const index = 0,
37
+ dashed = str.replace(/([A-Z])/g, g => `-${g[index].toLowerCase()}`),
38
+ startPos = 1;
37
39
 
38
- return dashed.startsWith("-") ? dashed.substring(1) : dashed;
40
+ return dashed.startsWith("-") ? dashed.substring(startPos) : dashed;
39
41
  }