@tsparticles/cli 3.0.8 → 3.0.10
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.
- package/dist/build/build-distfiles.js +1 -1
- package/dist/build/build-diststats.js +2 -4
- package/dist/build/build-eslint.js +3 -3
- package/dist/cli.js +1 -1
- package/dist/create/plugin/create-plugin.js +3 -3
- package/dist/create/preset/create-preset.js +4 -4
- package/dist/create/shape/create-shape.js +8 -3
- package/dist/utils/file-utils.js +2 -2
- package/dist/utils/template-utils.js +4 -4
- package/eslint.config.js +1 -1
- package/files/create-shape/src/ShapeDrawer.ts +2 -0
- package/files/create-shape/src/index.ts +1 -1
- package/files/empty-project/package.json +1 -1
- package/package.json +1 -1
- package/src/build/build-distfiles.ts +1 -1
- package/src/build/build-diststats.ts +4 -4
- package/src/build/build-eslint.ts +3 -3
- package/src/cli.ts +1 -1
- package/src/create/plugin/create-plugin.ts +3 -4
- package/src/create/preset/create-preset.ts +4 -4
- package/src/create/shape/create-shape.ts +9 -3
- package/src/utils/file-utils.ts +2 -2
- package/src/utils/template-utils.ts +4 -4
- package/tests/create-plugin.test.ts +7 -5
- package/tests/create-preset.test.ts +7 -5
- package/tests/create-shape.test.ts +7 -5
- package/tests/file-utils.test.ts +7 -7
- package/tests/string-utils.test.ts +10 -4
- package/vitest.config.ts +1 -1
|
@@ -9,7 +9,7 @@ export async function buildDistFiles(basePath) {
|
|
|
9
9
|
console.log("Build - started on dist files");
|
|
10
10
|
let res;
|
|
11
11
|
try {
|
|
12
|
-
const pkgInfo = (await
|
|
12
|
+
const pkgInfo = JSON.parse((await fs.readFile(path.join(basePath, "package.json"))).toString()), libPackage = path.join(basePath, "package.dist.json"), distPath = path.join(basePath, pkgInfo.publishConfig?.directory ?? "dist");
|
|
13
13
|
const data = await fs.readFile(libPackage), text = data.toString(), libObj = JSON.parse(text);
|
|
14
14
|
libObj.version = pkgInfo.version;
|
|
15
15
|
if (pkgInfo.dependencies) {
|
|
@@ -41,9 +41,7 @@ async function getFolderStats(folderPath, bundlePath) {
|
|
|
41
41
|
*/
|
|
42
42
|
export async function getDistStats(basePath) {
|
|
43
43
|
const path = await import("path"), distFolder = path.join(basePath, "dist"), pkgInfo = (await fs.exists(path.join(distFolder, "package.json")))
|
|
44
|
-
? (await
|
|
45
|
-
: {}, bundlePath = (await fs.exists(distFolder)) && pkgInfo.jsdelivr
|
|
46
|
-
? path.resolve(path.join(distFolder, pkgInfo.jsdelivr))
|
|
47
|
-
: undefined;
|
|
44
|
+
? JSON.parse((await fs.readFile(path.join(distFolder, "package.json"))).toString())
|
|
45
|
+
: {}, bundlePath = (await fs.exists(distFolder)) && pkgInfo.jsdelivr ? path.join(distFolder, pkgInfo.jsdelivr) : undefined;
|
|
48
46
|
return await getFolderStats(distFolder, bundlePath);
|
|
49
47
|
}
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import { ESLint } from "eslint";
|
|
2
|
-
import { defineConfig } from "eslint/config";
|
|
3
|
-
import tsParticlesESLintConfig from "@tsparticles/eslint-config";
|
|
4
2
|
/**
|
|
5
3
|
* @param ci -
|
|
6
4
|
* @returns true if the linting was successful
|
|
@@ -9,7 +7,9 @@ export async function lint(ci) {
|
|
|
9
7
|
console.log("ESLint - started on src");
|
|
10
8
|
let res;
|
|
11
9
|
try {
|
|
12
|
-
const eslint = new ESLint({
|
|
10
|
+
const eslint = new ESLint({
|
|
11
|
+
fix: !ci,
|
|
12
|
+
});
|
|
13
13
|
const results = await eslint.lintFiles(["src"]), errors = ESLint.getErrorResults(results);
|
|
14
14
|
await ESLint.outputFixes(results);
|
|
15
15
|
const formatter = await eslint.loadFormatter("stylish"), resultText = formatter.format(results), minimumLength = 0;
|
package/dist/cli.js
CHANGED
|
@@ -5,7 +5,7 @@ import { fileURLToPath } from "url";
|
|
|
5
5
|
import fs from "fs-extra";
|
|
6
6
|
import path from "path";
|
|
7
7
|
import { program } from "commander";
|
|
8
|
-
const __filename = fileURLToPath(import.meta.url), __dirname = path.dirname(__filename), rootPkgPath = path.join(__dirname, "package.json"), pkg = (await fs.readJson(rootPkgPath));
|
|
8
|
+
const __filename = fileURLToPath(import.meta.url), __dirname = path.dirname(__filename), rootPkgPath = path.join(__dirname, "..", "package.json"), pkg = (await fs.readJson(rootPkgPath));
|
|
9
9
|
program.name("tsparticles-cli");
|
|
10
10
|
program.description("tsParticles CLI");
|
|
11
11
|
program.version(pkg.version, "-v, --version", "output the current version");
|
|
@@ -11,7 +11,7 @@ import { replaceTokensInFile } from "../../utils/file-utils.js";
|
|
|
11
11
|
async function updateIndexFile(destPath, name) {
|
|
12
12
|
const capitalizedName = capitalize(name, "-", " "), camelizedName = camelize(capitalizedName);
|
|
13
13
|
await replaceTokensInFile({
|
|
14
|
-
path: path.
|
|
14
|
+
path: path.join(destPath, "src", "index.ts"),
|
|
15
15
|
tokens: [
|
|
16
16
|
{
|
|
17
17
|
from: /loadTemplatePlugin/g,
|
|
@@ -54,7 +54,7 @@ async function updatePluginPackageDistFile(destPath, name, description, repoUrl)
|
|
|
54
54
|
* @param repoUrl - The repository url
|
|
55
55
|
*/
|
|
56
56
|
async function updateReadmeFile(destPath, name, description, repoUrl) {
|
|
57
|
-
const readmePath = path.
|
|
57
|
+
const readmePath = path.join(destPath, "README.md"), capitalizedName = capitalize(name, "-", " "), camelizedName = camelize(capitalizedName), dashedName = dash(camelizedName), stringSearch = "github.com", trailingSlashSearch = "github.com/", repoPath = repoUrl.includes(stringSearch)
|
|
58
58
|
? repoUrl.substring(repoUrl.indexOf(trailingSlashSearch) + trailingSlashSearch.length, repoUrl.indexOf(".git"))
|
|
59
59
|
: "tsparticles/plugin-template";
|
|
60
60
|
await replaceTokensInFile({
|
|
@@ -108,7 +108,7 @@ async function updatePluginWebpackFile(destPath, name, description) {
|
|
|
108
108
|
* @param destPath - The path where the project is located
|
|
109
109
|
*/
|
|
110
110
|
export async function createPluginTemplate(name, description, repoUrl, destPath) {
|
|
111
|
-
const sourcePath = path.
|
|
111
|
+
const sourcePath = path.join(__dirname, "..", "..", "..", "files", "create-plugin");
|
|
112
112
|
await copyEmptyTemplateFiles(destPath);
|
|
113
113
|
await fs.copy(sourcePath, destPath, {
|
|
114
114
|
overwrite: true,
|
|
@@ -11,7 +11,7 @@ import { replaceTokensInFile } from "../../utils/file-utils.js";
|
|
|
11
11
|
async function updateBundleFile(destPath, name) {
|
|
12
12
|
const capitalizedName = capitalize(name, "-", " ");
|
|
13
13
|
await replaceTokensInFile({
|
|
14
|
-
path: path.
|
|
14
|
+
path: path.join(destPath, "src", "bundle.ts"),
|
|
15
15
|
tokens: [
|
|
16
16
|
{
|
|
17
17
|
from: /loadTemplatePreset/g,
|
|
@@ -28,7 +28,7 @@ async function updateBundleFile(destPath, name) {
|
|
|
28
28
|
async function updateIndexFile(destPath, name) {
|
|
29
29
|
const capitalizedName = capitalize(name, "-", " "), camelizedName = camelize(capitalizedName);
|
|
30
30
|
await replaceTokensInFile({
|
|
31
|
-
path: path.
|
|
31
|
+
path: path.join(destPath, "src", "index.ts"),
|
|
32
32
|
tokens: [
|
|
33
33
|
{
|
|
34
34
|
from: /loadTemplatePreset/g,
|
|
@@ -75,7 +75,7 @@ async function updateReadmeFile(destPath, name, description, repoUrl) {
|
|
|
75
75
|
? repoUrl.substring(repoUrl.indexOf(trailingSlashSearch) + trailingSlashSearch.length, repoUrl.indexOf(".git"))
|
|
76
76
|
: "tsparticles/preset-template";
|
|
77
77
|
await replaceTokensInFile({
|
|
78
|
-
path: path.
|
|
78
|
+
path: path.join(destPath, "README.md"),
|
|
79
79
|
tokens: [
|
|
80
80
|
{
|
|
81
81
|
from: /tsParticles Template Preset/g,
|
|
@@ -125,7 +125,7 @@ async function updatePresetWebpackFile(destPath, name, description) {
|
|
|
125
125
|
* @param destPath - The path where the project is located
|
|
126
126
|
*/
|
|
127
127
|
export async function createPresetTemplate(name, description, repoUrl, destPath) {
|
|
128
|
-
const sourcePath = path.
|
|
128
|
+
const sourcePath = path.join(__dirname, "..", "..", "..", "files", "create-preset");
|
|
129
129
|
await copyEmptyTemplateFiles(destPath);
|
|
130
130
|
await fs.copy(sourcePath, destPath, {
|
|
131
131
|
overwrite: true,
|
|
@@ -11,12 +11,17 @@ import { replaceTokensInFile } from "../../utils/file-utils.js";
|
|
|
11
11
|
async function updateIndexFile(destPath, name) {
|
|
12
12
|
const capitalizedName = capitalize(name, "-", " "), camelizedName = camelize(capitalizedName);
|
|
13
13
|
await replaceTokensInFile({
|
|
14
|
-
path: path.
|
|
14
|
+
path: path.join(destPath, "src", "index.ts"),
|
|
15
15
|
tokens: [
|
|
16
16
|
{
|
|
17
17
|
from: /loadTemplateShape/g,
|
|
18
18
|
to: `load${capitalizedName}Shape`,
|
|
19
19
|
},
|
|
20
|
+
],
|
|
21
|
+
});
|
|
22
|
+
await replaceTokensInFile({
|
|
23
|
+
path: path.join(destPath, "src", "ShapeDrawer.ts"),
|
|
24
|
+
tokens: [
|
|
20
25
|
{
|
|
21
26
|
from: /"#template#"/g,
|
|
22
27
|
to: `"${camelizedName}"`,
|
|
@@ -58,7 +63,7 @@ async function updateReadmeFile(destPath, name, description, repoUrl) {
|
|
|
58
63
|
? repoUrl.substring(repoUrl.indexOf(trailingSlashSearch) + trailingSlashSearch.length, repoUrl.indexOf(".git"))
|
|
59
64
|
: "tsparticles/shape-template";
|
|
60
65
|
await replaceTokensInFile({
|
|
61
|
-
path: path.
|
|
66
|
+
path: path.join(destPath, "README.md"),
|
|
62
67
|
tokens: [
|
|
63
68
|
{
|
|
64
69
|
from: /tsParticles Template Shape/g,
|
|
@@ -108,7 +113,7 @@ async function updateShapeWebpackFile(destPath, name, description) {
|
|
|
108
113
|
* @param destPath - The path where the project is located
|
|
109
114
|
*/
|
|
110
115
|
export async function createShapeTemplate(name, description, repoUrl, destPath) {
|
|
111
|
-
const sourcePath = path.
|
|
116
|
+
const sourcePath = path.join(__dirname, "..", "..", "..", "files", "create-shape");
|
|
112
117
|
await copyEmptyTemplateFiles(destPath);
|
|
113
118
|
await fs.copy(sourcePath, destPath, {
|
|
114
119
|
overwrite: true,
|
package/dist/utils/file-utils.js
CHANGED
|
@@ -8,7 +8,7 @@ import path from "path";
|
|
|
8
8
|
*/
|
|
9
9
|
export async function replaceTokensInFiles(options) {
|
|
10
10
|
for (const item of options) {
|
|
11
|
-
const filePath =
|
|
11
|
+
const filePath = item.path;
|
|
12
12
|
let data = await fs.readFile(filePath, "utf-8");
|
|
13
13
|
for (const token of item.tokens) {
|
|
14
14
|
const regex = new RegExp(token.from, "g");
|
|
@@ -30,7 +30,7 @@ export async function replaceTokensInFile(options) {
|
|
|
30
30
|
* @returns the destination directory path
|
|
31
31
|
*/
|
|
32
32
|
export async function getDestinationDir(destination) {
|
|
33
|
-
const destPath = path.
|
|
33
|
+
const destPath = path.join(process.cwd(), destination), destExists = await fs.pathExists(destPath);
|
|
34
34
|
if (destExists) {
|
|
35
35
|
const destContents = await fs.readdir(destPath), destContentsNoGit = destContents.filter(t => t !== ".git" && t !== ".gitignore");
|
|
36
36
|
if (destContentsNoGit.length) {
|
|
@@ -13,7 +13,7 @@ import { replaceTokensInFile } from "./file-utils.js";
|
|
|
13
13
|
*/
|
|
14
14
|
export async function updatePackageFile(destPath, packageName, description, fileName, repoUrl) {
|
|
15
15
|
await replaceTokensInFile({
|
|
16
|
-
path: path.
|
|
16
|
+
path: path.join(destPath, "package.json"),
|
|
17
17
|
tokens: [
|
|
18
18
|
{
|
|
19
19
|
from: /"tsParticles empty template"/g,
|
|
@@ -52,7 +52,7 @@ export async function updatePackageFile(destPath, packageName, description, file
|
|
|
52
52
|
*/
|
|
53
53
|
export async function updatePackageDistFile(destPath, packageName, description, fileName, repoUrl) {
|
|
54
54
|
await replaceTokensInFile({
|
|
55
|
-
path: path.
|
|
55
|
+
path: path.join(destPath, "package.dist.json"),
|
|
56
56
|
tokens: [
|
|
57
57
|
{
|
|
58
58
|
from: /"tsParticles empty template"/g,
|
|
@@ -90,7 +90,7 @@ export async function updatePackageDistFile(destPath, packageName, description,
|
|
|
90
90
|
*/
|
|
91
91
|
export async function updateWebpackFile(destPath, name, description, fnName) {
|
|
92
92
|
await replaceTokensInFile({
|
|
93
|
-
path: path.
|
|
93
|
+
path: path.join(destPath, "webpack.config.js"),
|
|
94
94
|
tokens: [
|
|
95
95
|
{
|
|
96
96
|
from: /"Empty"/g,
|
|
@@ -112,7 +112,7 @@ export async function updateWebpackFile(destPath, name, description, fnName) {
|
|
|
112
112
|
* @param destPath - The path where the project will be created
|
|
113
113
|
*/
|
|
114
114
|
export async function copyEmptyTemplateFiles(destPath) {
|
|
115
|
-
await fs.copy(path.
|
|
115
|
+
await fs.copy(path.join(__dirname, "..", "..", "files", "empty-project"), destPath, {
|
|
116
116
|
overwrite: true,
|
|
117
117
|
filter: copyFilter,
|
|
118
118
|
});
|
package/eslint.config.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { IShapeDrawData, IShapeDrawer } from "@tsparticles/engine";
|
|
2
2
|
|
|
3
3
|
export class ShapeDrawer implements IShapeDrawer {
|
|
4
|
+
readonly validTypes = ["#template#"] as const;
|
|
5
|
+
|
|
4
6
|
draw(_data: IShapeDrawData): void {
|
|
5
7
|
// draw the particle using the context
|
|
6
8
|
// which is already centered in the particle position
|
|
@@ -6,5 +6,5 @@ import type { Engine } from "@tsparticles/engine";
|
|
|
6
6
|
export async function loadTemplateShape(engine: Engine): Promise<void> {
|
|
7
7
|
const { ShapeDrawer } = await import("./ShapeDrawer.js");
|
|
8
8
|
|
|
9
|
-
await engine.addShape(
|
|
9
|
+
await engine.addShape(new ShapeDrawer());
|
|
10
10
|
}
|
|
@@ -84,7 +84,7 @@
|
|
|
84
84
|
"prettier": "@tsparticles/prettier-config",
|
|
85
85
|
"devDependencies": {
|
|
86
86
|
"@babel/core": "^7.28.3",
|
|
87
|
-
"@tsparticles/cli": "^3.0.
|
|
87
|
+
"@tsparticles/cli": "^3.0.10",
|
|
88
88
|
"@tsparticles/eslint-config": "^3.0.5",
|
|
89
89
|
"@tsparticles/prettier-config": "^3.0.1",
|
|
90
90
|
"@tsparticles/tsconfig": "^3.0.5",
|
package/package.json
CHANGED
|
@@ -12,7 +12,7 @@ export async function buildDistFiles(basePath: string): Promise<boolean> {
|
|
|
12
12
|
let res: boolean;
|
|
13
13
|
|
|
14
14
|
try {
|
|
15
|
-
const pkgInfo = (await
|
|
15
|
+
const pkgInfo = JSON.parse((await fs.readFile(path.join(basePath, "package.json"))).toString()) as {
|
|
16
16
|
dependencies?: Record<string, string>;
|
|
17
17
|
peerDependencies?: Record<string, string>;
|
|
18
18
|
publishConfig?: { directory?: string };
|
|
@@ -60,12 +60,12 @@ export async function getDistStats(basePath: string): Promise<IDistStats> {
|
|
|
60
60
|
const path = await import("path"),
|
|
61
61
|
distFolder = path.join(basePath, "dist"),
|
|
62
62
|
pkgInfo = (await fs.exists(path.join(distFolder, "package.json")))
|
|
63
|
-
? ((await
|
|
63
|
+
? (JSON.parse((await fs.readFile(path.join(distFolder, "package.json"))).toString()) as {
|
|
64
|
+
jsdelivr?: string;
|
|
65
|
+
})
|
|
64
66
|
: {},
|
|
65
67
|
bundlePath =
|
|
66
|
-
(await fs.exists(distFolder)) && pkgInfo.jsdelivr
|
|
67
|
-
? path.resolve(path.join(distFolder, pkgInfo.jsdelivr))
|
|
68
|
-
: undefined;
|
|
68
|
+
(await fs.exists(distFolder)) && pkgInfo.jsdelivr ? path.join(distFolder, pkgInfo.jsdelivr) : undefined;
|
|
69
69
|
|
|
70
70
|
return await getFolderStats(distFolder, bundlePath);
|
|
71
71
|
}
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import { ESLint } from "eslint";
|
|
2
|
-
import { defineConfig } from "eslint/config";
|
|
3
|
-
import tsParticlesESLintConfig from "@tsparticles/eslint-config";
|
|
4
2
|
|
|
5
3
|
/**
|
|
6
4
|
* @param ci -
|
|
@@ -12,7 +10,9 @@ export async function lint(ci: boolean): Promise<boolean> {
|
|
|
12
10
|
let res: boolean;
|
|
13
11
|
|
|
14
12
|
try {
|
|
15
|
-
const eslint = new ESLint({
|
|
13
|
+
const eslint = new ESLint({
|
|
14
|
+
fix: !ci,
|
|
15
|
+
});
|
|
16
16
|
|
|
17
17
|
const results = await eslint.lintFiles(["src"]),
|
|
18
18
|
errors = ESLint.getErrorResults(results);
|
package/src/cli.ts
CHANGED
|
@@ -8,7 +8,7 @@ import { program } from "commander";
|
|
|
8
8
|
|
|
9
9
|
const __filename = fileURLToPath(import.meta.url),
|
|
10
10
|
__dirname = path.dirname(__filename),
|
|
11
|
-
rootPkgPath = path.join(__dirname, "package.json"),
|
|
11
|
+
rootPkgPath = path.join(__dirname, "..", "package.json"),
|
|
12
12
|
pkg = (await fs.readJson(rootPkgPath)) as { version: string };
|
|
13
13
|
|
|
14
14
|
program.name("tsparticles-cli");
|
|
@@ -22,7 +22,7 @@ async function updateIndexFile(destPath: string, name: string): Promise<void> {
|
|
|
22
22
|
camelizedName = camelize(capitalizedName);
|
|
23
23
|
|
|
24
24
|
await replaceTokensInFile({
|
|
25
|
-
path: path.
|
|
25
|
+
path: path.join(destPath, "src", "index.ts"),
|
|
26
26
|
tokens: [
|
|
27
27
|
{
|
|
28
28
|
from: /loadTemplatePlugin/g,
|
|
@@ -94,7 +94,7 @@ async function updatePluginPackageDistFile(
|
|
|
94
94
|
* @param repoUrl - The repository url
|
|
95
95
|
*/
|
|
96
96
|
async function updateReadmeFile(destPath: string, name: string, description: string, repoUrl: string): Promise<void> {
|
|
97
|
-
const readmePath = path.
|
|
97
|
+
const readmePath = path.join(destPath, "README.md"),
|
|
98
98
|
capitalizedName = capitalize(name, "-", " "),
|
|
99
99
|
camelizedName = camelize(capitalizedName),
|
|
100
100
|
dashedName = dash(camelizedName),
|
|
@@ -165,7 +165,7 @@ export async function createPluginTemplate(
|
|
|
165
165
|
repoUrl: string,
|
|
166
166
|
destPath: string,
|
|
167
167
|
): Promise<void> {
|
|
168
|
-
const sourcePath = path.
|
|
168
|
+
const sourcePath = path.join(__dirname, "..", "..", "..", "files", "create-plugin");
|
|
169
169
|
|
|
170
170
|
await copyEmptyTemplateFiles(destPath);
|
|
171
171
|
|
|
@@ -179,7 +179,6 @@ export async function createPluginTemplate(
|
|
|
179
179
|
await updatePluginPackageDistFile(destPath, name, description, repoUrl);
|
|
180
180
|
await updateReadmeFile(destPath, name, description, repoUrl);
|
|
181
181
|
await updatePluginWebpackFile(destPath, name, description);
|
|
182
|
-
|
|
183
182
|
await runInstall(destPath);
|
|
184
183
|
await runBuild(destPath);
|
|
185
184
|
}
|
|
@@ -21,7 +21,7 @@ async function updateBundleFile(destPath: string, name: string): Promise<void> {
|
|
|
21
21
|
const capitalizedName = capitalize(name, "-", " ");
|
|
22
22
|
|
|
23
23
|
await replaceTokensInFile({
|
|
24
|
-
path: path.
|
|
24
|
+
path: path.join(destPath, "src", "bundle.ts"),
|
|
25
25
|
tokens: [
|
|
26
26
|
{
|
|
27
27
|
from: /loadTemplatePreset/g,
|
|
@@ -41,7 +41,7 @@ async function updateIndexFile(destPath: string, name: string): Promise<void> {
|
|
|
41
41
|
camelizedName = camelize(capitalizedName);
|
|
42
42
|
|
|
43
43
|
await replaceTokensInFile({
|
|
44
|
-
path: path.
|
|
44
|
+
path: path.join(destPath, "src", "index.ts"),
|
|
45
45
|
tokens: [
|
|
46
46
|
{
|
|
47
47
|
from: /loadTemplatePreset/g,
|
|
@@ -126,7 +126,7 @@ async function updateReadmeFile(destPath: string, name: string, description: str
|
|
|
126
126
|
: "tsparticles/preset-template";
|
|
127
127
|
|
|
128
128
|
await replaceTokensInFile({
|
|
129
|
-
path: path.
|
|
129
|
+
path: path.join(destPath, "README.md"),
|
|
130
130
|
tokens: [
|
|
131
131
|
{
|
|
132
132
|
from: /tsParticles Template Preset/g,
|
|
@@ -183,7 +183,7 @@ export async function createPresetTemplate(
|
|
|
183
183
|
repoUrl: string,
|
|
184
184
|
destPath: string,
|
|
185
185
|
): Promise<void> {
|
|
186
|
-
const sourcePath = path.
|
|
186
|
+
const sourcePath = path.join(__dirname, "..", "..", "..", "files", "create-preset");
|
|
187
187
|
|
|
188
188
|
await copyEmptyTemplateFiles(destPath);
|
|
189
189
|
|
|
@@ -22,12 +22,18 @@ async function updateIndexFile(destPath: string, name: string): Promise<void> {
|
|
|
22
22
|
camelizedName = camelize(capitalizedName);
|
|
23
23
|
|
|
24
24
|
await replaceTokensInFile({
|
|
25
|
-
path: path.
|
|
25
|
+
path: path.join(destPath, "src", "index.ts"),
|
|
26
26
|
tokens: [
|
|
27
27
|
{
|
|
28
28
|
from: /loadTemplateShape/g,
|
|
29
29
|
to: `load${capitalizedName}Shape`,
|
|
30
30
|
},
|
|
31
|
+
],
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
await replaceTokensInFile({
|
|
35
|
+
path: path.join(destPath, "src", "ShapeDrawer.ts"),
|
|
36
|
+
tokens: [
|
|
31
37
|
{
|
|
32
38
|
from: /"#template#"/g,
|
|
33
39
|
to: `"${camelizedName}"`,
|
|
@@ -107,7 +113,7 @@ async function updateReadmeFile(destPath: string, name: string, description: str
|
|
|
107
113
|
: "tsparticles/shape-template";
|
|
108
114
|
|
|
109
115
|
await replaceTokensInFile({
|
|
110
|
-
path: path.
|
|
116
|
+
path: path.join(destPath, "README.md"),
|
|
111
117
|
tokens: [
|
|
112
118
|
{
|
|
113
119
|
from: /tsParticles Template Shape/g,
|
|
@@ -164,7 +170,7 @@ export async function createShapeTemplate(
|
|
|
164
170
|
repoUrl: string,
|
|
165
171
|
destPath: string,
|
|
166
172
|
): Promise<void> {
|
|
167
|
-
const sourcePath = path.
|
|
173
|
+
const sourcePath = path.join(__dirname, "..", "..", "..", "files", "create-shape");
|
|
168
174
|
|
|
169
175
|
await copyEmptyTemplateFiles(destPath);
|
|
170
176
|
|
package/src/utils/file-utils.ts
CHANGED
|
@@ -19,7 +19,7 @@ export interface ReplaceTokensData {
|
|
|
19
19
|
*/
|
|
20
20
|
export async function replaceTokensInFiles(options: ReplaceTokensOptions[]): Promise<void> {
|
|
21
21
|
for (const item of options) {
|
|
22
|
-
const filePath =
|
|
22
|
+
const filePath = item.path;
|
|
23
23
|
|
|
24
24
|
let data = await fs.readFile(filePath, "utf-8");
|
|
25
25
|
|
|
@@ -47,7 +47,7 @@ export async function replaceTokensInFile(options: ReplaceTokensOptions): Promis
|
|
|
47
47
|
* @returns the destination directory path
|
|
48
48
|
*/
|
|
49
49
|
export async function getDestinationDir(destination: string): Promise<string> {
|
|
50
|
-
const destPath = path.
|
|
50
|
+
const destPath = path.join(process.cwd(), destination),
|
|
51
51
|
destExists = await fs.pathExists(destPath);
|
|
52
52
|
|
|
53
53
|
if (destExists) {
|
|
@@ -20,7 +20,7 @@ export async function updatePackageFile(
|
|
|
20
20
|
repoUrl: string,
|
|
21
21
|
): Promise<void> {
|
|
22
22
|
await replaceTokensInFile({
|
|
23
|
-
path: path.
|
|
23
|
+
path: path.join(destPath, "package.json"),
|
|
24
24
|
tokens: [
|
|
25
25
|
{
|
|
26
26
|
from: /"tsParticles empty template"/g,
|
|
@@ -66,7 +66,7 @@ export async function updatePackageDistFile(
|
|
|
66
66
|
repoUrl: string,
|
|
67
67
|
): Promise<void> {
|
|
68
68
|
await replaceTokensInFile({
|
|
69
|
-
path: path.
|
|
69
|
+
path: path.join(destPath, "package.dist.json"),
|
|
70
70
|
tokens: [
|
|
71
71
|
{
|
|
72
72
|
from: /"tsParticles empty template"/g,
|
|
@@ -110,7 +110,7 @@ export async function updateWebpackFile(
|
|
|
110
110
|
fnName: string,
|
|
111
111
|
): Promise<void> {
|
|
112
112
|
await replaceTokensInFile({
|
|
113
|
-
path: path.
|
|
113
|
+
path: path.join(destPath, "webpack.config.js"),
|
|
114
114
|
tokens: [
|
|
115
115
|
{
|
|
116
116
|
from: /"Empty"/g,
|
|
@@ -133,7 +133,7 @@ export async function updateWebpackFile(
|
|
|
133
133
|
* @param destPath - The path where the project will be created
|
|
134
134
|
*/
|
|
135
135
|
export async function copyEmptyTemplateFiles(destPath: string): Promise<void> {
|
|
136
|
-
await fs.copy(path.
|
|
136
|
+
await fs.copy(path.join(__dirname, "..", "..", "files", "empty-project"), destPath, {
|
|
137
137
|
overwrite: true,
|
|
138
138
|
filter: copyFilter,
|
|
139
139
|
});
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import { describe, it, expect } from "vitest";
|
|
2
|
-
import { createPluginTemplate } from "../src/create/plugin/create-plugin";
|
|
2
|
+
import { createPluginTemplate } from "../src/create/plugin/create-plugin.js";
|
|
3
3
|
import path from "path";
|
|
4
4
|
import fs from "fs-extra";
|
|
5
5
|
|
|
6
6
|
describe("create-plugin", () => {
|
|
7
7
|
it("should have created the plugin project", async () => {
|
|
8
|
-
const destDir = path.
|
|
8
|
+
const destDir = path.join(__dirname, "tmp-files", "foo-plugin"),
|
|
9
|
+
pkgPath = path.join(destDir, "package.json");
|
|
9
10
|
|
|
10
11
|
await createPluginTemplate("foo", "Foo", "", destDir);
|
|
11
12
|
|
|
12
|
-
const pkgInfo = await fs.readJSON(
|
|
13
|
+
const pkgInfo = await fs.readJSON(pkgPath);
|
|
13
14
|
|
|
14
15
|
expect(pkgInfo.name).toBe("tsparticles-plugin-foo");
|
|
15
16
|
|
|
@@ -17,11 +18,12 @@ describe("create-plugin", () => {
|
|
|
17
18
|
});
|
|
18
19
|
|
|
19
20
|
it("should have created the plugin project, w/ repo", async () => {
|
|
20
|
-
const destDir = path.
|
|
21
|
+
const destDir = path.join(__dirname,"tmp-files", "bar-plugin");
|
|
21
22
|
|
|
22
23
|
await createPluginTemplate("bar", "Bar", "https://github.com/matteobruni/tsparticles", destDir);
|
|
23
24
|
|
|
24
|
-
const
|
|
25
|
+
const pkgPath = path.join(destDir, "package.json"),
|
|
26
|
+
pkgInfo = await fs.readJSON(pkgPath);
|
|
25
27
|
|
|
26
28
|
expect(pkgInfo.name).toBe("tsparticles-plugin-bar");
|
|
27
29
|
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import { describe, it, expect } from "vitest";
|
|
2
|
-
import { createPresetTemplate } from "../src/create/preset/create-preset";
|
|
2
|
+
import { createPresetTemplate } from "../src/create/preset/create-preset.js";
|
|
3
3
|
import path from "path";
|
|
4
4
|
import fs from "fs-extra";
|
|
5
5
|
|
|
6
6
|
describe("create-preset", () => {
|
|
7
7
|
it("should have created the preset project", async () => {
|
|
8
|
-
const destDir = path.
|
|
8
|
+
const destDir = path.join(__dirname, "tmp-files", "foo-preset");
|
|
9
9
|
|
|
10
10
|
await createPresetTemplate("foo", "Foo", "", destDir);
|
|
11
11
|
|
|
12
|
-
const
|
|
12
|
+
const pkgPath = path.join(destDir, "package.json"),
|
|
13
|
+
pkgInfo = await fs.readJSON(pkgPath);
|
|
13
14
|
|
|
14
15
|
expect(pkgInfo.name).toBe("tsparticles-preset-foo");
|
|
15
16
|
|
|
@@ -17,11 +18,12 @@ describe("create-preset", () => {
|
|
|
17
18
|
});
|
|
18
19
|
|
|
19
20
|
it("should have created the preset project, w/ repo", async () => {
|
|
20
|
-
const destDir = path.
|
|
21
|
+
const destDir = path.join(__dirname, "tmp-files", "bar-preset");
|
|
21
22
|
|
|
22
23
|
await createPresetTemplate("bar", "Bar", "https://github.com/matteobruni/tsparticles", destDir);
|
|
23
24
|
|
|
24
|
-
const
|
|
25
|
+
const pkgPath = path.join(destDir, "package.json"),
|
|
26
|
+
pkgInfo = await fs.readJSON(pkgPath);
|
|
25
27
|
|
|
26
28
|
expect(pkgInfo.name).toBe("tsparticles-preset-bar");
|
|
27
29
|
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import { describe, it, expect } from "vitest";
|
|
2
|
-
import { createShapeTemplate } from "../src/create/shape/create-shape";
|
|
2
|
+
import { createShapeTemplate } from "../src/create/shape/create-shape.js";
|
|
3
3
|
import path from "path";
|
|
4
4
|
import fs from "fs-extra";
|
|
5
5
|
|
|
6
6
|
describe("create-shape", () => {
|
|
7
7
|
it("should have created the shape project", async () => {
|
|
8
|
-
const destDir = path.
|
|
8
|
+
const destDir = path.join(__dirname, "tmp-files", "foo-shape");
|
|
9
9
|
|
|
10
10
|
await createShapeTemplate("foo", "Foo", "", destDir);
|
|
11
11
|
|
|
12
|
-
const
|
|
12
|
+
const pkgPath = path.join(destDir, "package.json"),
|
|
13
|
+
pkgInfo = await fs.readJSON(pkgPath);
|
|
13
14
|
|
|
14
15
|
expect(pkgInfo.name).toBe("tsparticles-shape-foo");
|
|
15
16
|
|
|
@@ -17,11 +18,12 @@ describe("create-shape", () => {
|
|
|
17
18
|
});
|
|
18
19
|
|
|
19
20
|
it("should have created the shape project, w/ repo", async () => {
|
|
20
|
-
const destDir = path.
|
|
21
|
+
const destDir = path.join(__dirname, "tmp-files", "bar-shape");
|
|
21
22
|
|
|
22
23
|
await createShapeTemplate("bar", "Bar", "https://github.com/matteobruni/tsparticles", destDir);
|
|
23
24
|
|
|
24
|
-
const
|
|
25
|
+
const pkgPath = path.join(destDir, "package.json"),
|
|
26
|
+
pkgInfo = await fs.readJSON(pkgPath);
|
|
25
27
|
|
|
26
28
|
expect(pkgInfo.name).toBe("tsparticles-shape-bar");
|
|
27
29
|
|
package/tests/file-utils.test.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { describe, it, expect
|
|
1
|
+
import {afterAll, describe, it, expect} from "vitest";
|
|
2
2
|
import fs from "fs-extra";
|
|
3
3
|
import path from "path";
|
|
4
4
|
import {
|
|
@@ -6,10 +6,10 @@ import {
|
|
|
6
6
|
getRepositoryUrl,
|
|
7
7
|
replaceTokensInFile,
|
|
8
8
|
replaceTokensInFiles,
|
|
9
|
-
} from "../src/utils/file-utils";
|
|
9
|
+
} from "../src/utils/file-utils.js";
|
|
10
10
|
|
|
11
11
|
describe("file-utils", async () => {
|
|
12
|
-
const baseDir = path.
|
|
12
|
+
const baseDir = path.resolve("tmp-files");
|
|
13
13
|
|
|
14
14
|
await fs.ensureDir(baseDir);
|
|
15
15
|
|
|
@@ -59,14 +59,14 @@ describe("file-utils", async () => {
|
|
|
59
59
|
});
|
|
60
60
|
|
|
61
61
|
describe("get destination dir", async () => {
|
|
62
|
-
const destDir = await getDestinationDir(path.join(
|
|
62
|
+
const destDir = await getDestinationDir(path.join("tmp-files", "baz"));
|
|
63
63
|
|
|
64
64
|
it("should return the destination dir", () => {
|
|
65
65
|
expect(destDir).toBe(path.join(baseDir, "baz"));
|
|
66
66
|
});
|
|
67
67
|
|
|
68
68
|
it("should return the destination dir", async () => {
|
|
69
|
-
const destDir2 = await getDestinationDir(path.join(
|
|
69
|
+
const destDir2 = await getDestinationDir(path.join("tmp-files", "baz"));
|
|
70
70
|
|
|
71
71
|
expect(destDir2).toBe(path.join(baseDir, "baz"));
|
|
72
72
|
});
|
|
@@ -77,7 +77,7 @@ describe("file-utils", async () => {
|
|
|
77
77
|
let ex = false;
|
|
78
78
|
|
|
79
79
|
try {
|
|
80
|
-
await getDestinationDir(path.join(
|
|
80
|
+
await getDestinationDir(path.join("tmp-files", "baz"));
|
|
81
81
|
|
|
82
82
|
console.log("never");
|
|
83
83
|
} catch {
|
|
@@ -94,7 +94,7 @@ describe("file-utils", async () => {
|
|
|
94
94
|
});
|
|
95
95
|
});
|
|
96
96
|
|
|
97
|
-
|
|
97
|
+
afterAll(async () => {
|
|
98
98
|
await fs.remove(baseDir);
|
|
99
99
|
});
|
|
100
100
|
});
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { describe, it, expect } from "vitest";
|
|
2
|
-
import { camelize, capitalize, dash } from "../src/utils/string-utils";
|
|
2
|
+
import { camelize, capitalize, dash } from "../src/utils/string-utils.js";
|
|
3
3
|
|
|
4
4
|
describe("capitalize", () => {
|
|
5
5
|
describe("empty string", () => {
|
|
6
|
-
|
|
6
|
+
it("should successfully compare empty strings", () => {
|
|
7
|
+
expect(capitalize("")).toBe("");
|
|
8
|
+
});
|
|
7
9
|
});
|
|
8
10
|
|
|
9
11
|
describe("lowercase string", () => {
|
|
@@ -49,7 +51,9 @@ describe("capitalize", () => {
|
|
|
49
51
|
|
|
50
52
|
describe("camelize", () => {
|
|
51
53
|
describe("empty string", () => {
|
|
52
|
-
|
|
54
|
+
it("should successfully compare empty strings", () => {
|
|
55
|
+
expect(camelize("")).toBe("");
|
|
56
|
+
});
|
|
53
57
|
});
|
|
54
58
|
|
|
55
59
|
describe("lowercase string", () => {
|
|
@@ -95,7 +99,9 @@ describe("camelize", () => {
|
|
|
95
99
|
|
|
96
100
|
describe("dash", () => {
|
|
97
101
|
describe("empty string", () => {
|
|
98
|
-
|
|
102
|
+
it("should successfully compare empty strings", () => {
|
|
103
|
+
expect(dash("")).toBe("");
|
|
104
|
+
});
|
|
99
105
|
});
|
|
100
106
|
|
|
101
107
|
describe("lowercase string", () => {
|