@tsparticles/cli 1.12.0 → 1.13.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.
- package/.github/workflows/node.js-ci.yml +2 -0
- package/.mocharc.json +11 -0
- package/dist/build/build.js +1 -1
- package/dist/cli.js +2 -2
- package/dist/create/plugin/create-plugin.js +53 -8
- package/dist/create/plugin/plugin.js +3 -18
- package/dist/create/preset/create-preset.js +65 -12
- package/dist/create/preset/preset.js +3 -18
- package/dist/create/shape/create-shape.js +53 -8
- package/dist/create/shape/shape.js +3 -18
- package/dist/utils/file-utils.js +62 -0
- package/dist/utils/string-utils.js +13 -7
- package/dist/utils/template-utils.js +77 -8
- package/files/empty-project/package.json +2 -2
- package/package.json +19 -12
- package/src/build/build.ts +1 -1
- package/src/cli.ts +2 -2
- package/src/create/plugin/create-plugin.ts +57 -55
- package/src/create/plugin/plugin.ts +4 -24
- package/src/create/preset/create-preset.ts +72 -67
- package/src/create/preset/preset.ts +4 -24
- package/src/create/shape/create-shape.ts +57 -53
- package/src/create/shape/shape.ts +4 -24
- package/src/utils/file-utils.ts +75 -0
- package/src/utils/string-utils.ts +14 -7
- package/src/utils/template-utils.ts +77 -45
- package/tests/create-plugin.test.ts +31 -0
- package/tests/create-preset.test.ts +31 -0
- package/tests/create-shape.test.ts +31 -0
- package/tests/file-utils.test.ts +101 -0
- package/tests/string-utils.test.ts +125 -0
- package/tests/tsconfig.json +24 -0
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { describe, it } from "mocha";
|
|
2
|
+
import { expect } from "chai";
|
|
3
|
+
import fs from "fs-extra";
|
|
4
|
+
import path from "path";
|
|
5
|
+
import {
|
|
6
|
+
getDestinationDir,
|
|
7
|
+
getRepositoryUrl,
|
|
8
|
+
replaceTokensInFile,
|
|
9
|
+
replaceTokensInFiles,
|
|
10
|
+
} from "../src/utils/file-utils";
|
|
11
|
+
|
|
12
|
+
describe("file-utils", async () => {
|
|
13
|
+
const baseDir = path.join(__dirname, "tmp-files");
|
|
14
|
+
|
|
15
|
+
await fs.ensureDir(baseDir);
|
|
16
|
+
|
|
17
|
+
describe("replace tokens in files", async () => {
|
|
18
|
+
fs.writeFileSync(path.join(baseDir, "files1.txt"), "test");
|
|
19
|
+
fs.writeFileSync(path.join(baseDir, "files2.txt"), "test");
|
|
20
|
+
|
|
21
|
+
await replaceTokensInFiles([{
|
|
22
|
+
path: path.join(baseDir, "files1.txt"),
|
|
23
|
+
tokens: [{
|
|
24
|
+
from: "test",
|
|
25
|
+
to: "test1",
|
|
26
|
+
}],
|
|
27
|
+
}, {
|
|
28
|
+
path: path.join(baseDir, "files2.txt"),
|
|
29
|
+
tokens: [{
|
|
30
|
+
from: "test",
|
|
31
|
+
to: "test2",
|
|
32
|
+
}],
|
|
33
|
+
}]);
|
|
34
|
+
|
|
35
|
+
it("should replace tokens in files", async () => {
|
|
36
|
+
const data1 = await fs.readFile(path.join(baseDir, "files1.txt"), "utf8"),
|
|
37
|
+
data2 = await fs.readFile(path.join(baseDir, "files2.txt"), "utf8");
|
|
38
|
+
|
|
39
|
+
expect(data1).to.be.equal("test1");
|
|
40
|
+
expect(data2).to.be.equal("test2");
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
describe("replace tokens in file", async () => {
|
|
45
|
+
fs.writeFileSync(path.join(baseDir, "file1.txt"), "test");
|
|
46
|
+
|
|
47
|
+
await replaceTokensInFile({
|
|
48
|
+
path: path.join(baseDir, "file1.txt"),
|
|
49
|
+
tokens: [{
|
|
50
|
+
from: "test",
|
|
51
|
+
to: "test1",
|
|
52
|
+
}],
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it("should replace tokens in files", async () => {
|
|
56
|
+
const data = await fs.readFile(path.join(baseDir, "file1.txt"), "utf8");
|
|
57
|
+
|
|
58
|
+
expect(data).to.be.equal("test1");
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
describe("get destination dir", async () => {
|
|
63
|
+
const destDir = await getDestinationDir(path.join(baseDir, "baz"));
|
|
64
|
+
|
|
65
|
+
it("should return the destination dir", () => {
|
|
66
|
+
expect(destDir).to.be.equal(path.join(baseDir, "baz"));
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it("should return the destination dir", async () => {
|
|
70
|
+
const destDir2 = await getDestinationDir(path.join(baseDir, "baz"));
|
|
71
|
+
|
|
72
|
+
expect(destDir2).to.be.equal(path.join(baseDir, "baz"));
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it("should throw exception", async () => {
|
|
76
|
+
await fs.writeFile(path.join(baseDir, "baz", "tmp.txt"), "");
|
|
77
|
+
|
|
78
|
+
let ex = false;
|
|
79
|
+
|
|
80
|
+
try {
|
|
81
|
+
await getDestinationDir(path.join(baseDir, "baz"));
|
|
82
|
+
|
|
83
|
+
console.log("never");
|
|
84
|
+
} catch {
|
|
85
|
+
ex = true;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
expect(ex).to.be.equal(true);
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
describe("get repository url", () => {
|
|
93
|
+
it("should return the repository url", () => {
|
|
94
|
+
expect(getRepositoryUrl()).to.be.not.equal("");
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
after(async () => {
|
|
99
|
+
await fs.remove(baseDir);
|
|
100
|
+
});
|
|
101
|
+
});
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { describe, it } from "mocha";
|
|
2
|
+
import { expect } from "chai";
|
|
3
|
+
import { camelize, capitalize, dash } from "../src/utils/string-utils";
|
|
4
|
+
|
|
5
|
+
describe("capitalize", () => {
|
|
6
|
+
describe("empty string", () => {
|
|
7
|
+
expect(capitalize("")).to.be.equal("");
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
describe("lowercase string", () => {
|
|
11
|
+
it("should return capitalized string", () => {
|
|
12
|
+
expect(capitalize("test")).to.be.equal("Test");
|
|
13
|
+
});
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
describe("capitalized string", () => {
|
|
17
|
+
it("should return capitalized string", () => {
|
|
18
|
+
expect(capitalize("Test")).to.be.equal("Test");
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
describe("multiple lowercase words string", () => {
|
|
23
|
+
it("should return capitalized string, no split", () => {
|
|
24
|
+
expect(capitalize("test test")).to.be.equal("Test test");
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it("should return capitalized string, split", () => {
|
|
28
|
+
expect(capitalize("test test", " ")).to.be.equal("TestTest");
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it("should return capitalized string, wrong split", () => {
|
|
32
|
+
expect(capitalize("test test", ";")).to.be.equal("Test test");
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
describe("multiple uppercase words string", () => {
|
|
37
|
+
it("should return capitalized string, no split", () => {
|
|
38
|
+
expect(capitalize("Test Test")).to.be.equal("Test Test");
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it("should return capitalized string, split", () => {
|
|
42
|
+
expect(capitalize("Test Test", " ")).to.be.equal("TestTest");
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it("should return capitalized string, wrong split", () => {
|
|
46
|
+
expect(capitalize("Test Test", ";")).to.be.equal("Test Test");
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
describe("camelize", () => {
|
|
52
|
+
describe("empty string", () => {
|
|
53
|
+
expect(camelize("")).to.be.equal("");
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
describe("lowercase string", () => {
|
|
57
|
+
it("should return camelized string", () => {
|
|
58
|
+
expect(camelize("test")).to.be.equal("test");
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
describe("uppercase string", () => {
|
|
63
|
+
it("should return camelized string", () => {
|
|
64
|
+
expect(camelize("Test")).to.be.equal("test");
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
describe("multiple lowercase words string", () => {
|
|
69
|
+
it("should return camelized string, no split", () => {
|
|
70
|
+
expect(camelize("test test")).to.be.equal("test test");
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it("should return camelized string, split", () => {
|
|
74
|
+
expect(camelize("test test", " ")).to.be.equal("testTest");
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it("should return camelized string, wrong split", () => {
|
|
78
|
+
expect(camelize("test test", ";")).to.be.equal("test test");
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
describe("multiple uppercase words string", () => {
|
|
83
|
+
it("should return camelized string, no split", () => {
|
|
84
|
+
expect(camelize("Test Test")).to.be.equal("test Test");
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it("should return camelized string, split", () => {
|
|
88
|
+
expect(camelize("Test Test", " ")).to.be.equal("testTest");
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it("should return camelized string, wrong split", () => {
|
|
92
|
+
expect(camelize("Test Test", ";")).to.be.equal("test Test");
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
describe("dash", () => {
|
|
98
|
+
describe("empty string", () => {
|
|
99
|
+
expect(dash("")).to.be.equal("");
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
describe("lowercase string", () => {
|
|
103
|
+
it("should return dashed string", () => {
|
|
104
|
+
expect(dash("test")).to.be.equal("test");
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
describe("uppercase string", () => {
|
|
109
|
+
it("should return dashed string", () => {
|
|
110
|
+
expect(dash("Test")).to.be.equal("test");
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
describe("capitalized word string", () => {
|
|
115
|
+
it("should return dashed string", () => {
|
|
116
|
+
expect(dash("TestTest")).to.be.equal("test-test");
|
|
117
|
+
});
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
describe("camelized word string", () => {
|
|
121
|
+
it("should return dashed string", () => {
|
|
122
|
+
expect(dash("testTest")).to.be.equal("test-test");
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
});
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2021",
|
|
4
|
+
"module": "commonjs",
|
|
5
|
+
"lib": ["ESNext", "ES2022", "ES2021", "ES2020", "ES2019", "ES2018", "ES2017", "ES2016", "ES2015", "DOM"],
|
|
6
|
+
"types": ["jsdom", "mocha", "chai", "node"],
|
|
7
|
+
"allowJs": true,
|
|
8
|
+
"rootDir": ".",
|
|
9
|
+
"declaration": false,
|
|
10
|
+
"removeComments": true,
|
|
11
|
+
"importHelpers": false,
|
|
12
|
+
"strict": true,
|
|
13
|
+
"noImplicitAny": true,
|
|
14
|
+
"strictNullChecks": true,
|
|
15
|
+
"alwaysStrict": true,
|
|
16
|
+
"noFallthroughCasesInSwitch": true,
|
|
17
|
+
"moduleResolution": "node",
|
|
18
|
+
"allowSyntheticDefaultImports": true,
|
|
19
|
+
"esModuleInterop": true,
|
|
20
|
+
"experimentalDecorators": true,
|
|
21
|
+
"forceConsistentCasingInFileNames": true
|
|
22
|
+
},
|
|
23
|
+
"references": [{ "path": "../src" }],
|
|
24
|
+
}
|