@tsparticles/cli 1.12.0 → 2.0.0-beta.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-distfiles.js +6 -8
- 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-distfiles.ts +2 -2
- 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
|
@@ -1,9 +1,8 @@
|
|
|
1
|
+
import { getDestinationDir, getRepositoryUrl } from "../../utils/file-utils";
|
|
1
2
|
import prompts, { type PromptObject } from "prompts";
|
|
2
3
|
import { Command } from "commander";
|
|
3
4
|
import { capitalize } from "../../utils/string-utils";
|
|
4
5
|
import { createPresetTemplate } from "./create-preset";
|
|
5
|
-
import { execSync } from "child_process";
|
|
6
|
-
import fs from "fs-extra";
|
|
7
6
|
import path from "path";
|
|
8
7
|
|
|
9
8
|
const presetCommand = new Command("preset");
|
|
@@ -11,27 +10,8 @@ const presetCommand = new Command("preset");
|
|
|
11
10
|
presetCommand.description("Create a new tsParticles preset");
|
|
12
11
|
presetCommand.argument("<destination>", "Destination folder");
|
|
13
12
|
presetCommand.action(async (destination: string) => {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const destPath = path.resolve(path.join(process.cwd(), destination)),
|
|
17
|
-
destExists = await fs.pathExists(destPath);
|
|
18
|
-
|
|
19
|
-
if (destExists) {
|
|
20
|
-
const destContents = await fs.readdir(destPath),
|
|
21
|
-
destContentsNoGit = destContents.filter(t => t !== ".git" && t !== ".gitignore");
|
|
22
|
-
|
|
23
|
-
if (destContentsNoGit.length) {
|
|
24
|
-
throw new Error("Destination folder already exists and is not empty");
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
await fs.ensureDir(destPath);
|
|
29
|
-
|
|
30
|
-
try {
|
|
31
|
-
repoUrl = execSync("git config --get remote.origin.url").toString();
|
|
32
|
-
} catch {
|
|
33
|
-
repoUrl = "";
|
|
34
|
-
}
|
|
13
|
+
const destPath = await getDestinationDir(destination),
|
|
14
|
+
repoUrl = getRepositoryUrl();
|
|
35
15
|
|
|
36
16
|
const initialName = destPath.split(path.sep).pop(),
|
|
37
17
|
questions: PromptObject[] = [
|
|
@@ -59,7 +39,7 @@ presetCommand.action(async (destination: string) => {
|
|
|
59
39
|
|
|
60
40
|
const { name, description, repositoryUrl } = await prompts(questions);
|
|
61
41
|
|
|
62
|
-
createPresetTemplate(name.trim(), description.trim(), repositoryUrl.trim(), destPath);
|
|
42
|
+
await createPresetTemplate(name.trim(), description.trim(), repositoryUrl.trim(), destPath);
|
|
63
43
|
});
|
|
64
44
|
|
|
65
45
|
export { presetCommand };
|
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
} from "../../utils/template-utils";
|
|
11
11
|
import fs from "fs-extra";
|
|
12
12
|
import path from "path";
|
|
13
|
+
import { replaceTokensInFile } from "../../utils/file-utils";
|
|
13
14
|
|
|
14
15
|
/**
|
|
15
16
|
* Updates the index file with the correct function name
|
|
@@ -17,16 +18,22 @@ import path from "path";
|
|
|
17
18
|
* @param name - The name of the project
|
|
18
19
|
*/
|
|
19
20
|
async function updateIndexFile(destPath: string, name: string): Promise<void> {
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
capitalizedName = capitalize(capitalize(name, "-"), " "),
|
|
23
|
-
camelizedName = camelize(capitalizedName),
|
|
24
|
-
indexFunctionRegex = /loadTemplateShape/g,
|
|
25
|
-
replacedFuncText = index.replace(indexFunctionRegex, `load${capitalizedName}Shape`),
|
|
26
|
-
indexNameRegex = /"#template#"/g,
|
|
27
|
-
replacedNameText = replacedFuncText.replace(indexNameRegex, `"${camelizedName}"`);
|
|
21
|
+
const capitalizedName = capitalize(name, "-", " "),
|
|
22
|
+
camelizedName = camelize(capitalizedName);
|
|
28
23
|
|
|
29
|
-
await
|
|
24
|
+
await replaceTokensInFile({
|
|
25
|
+
path: path.resolve(destPath, "src", "index.ts"),
|
|
26
|
+
tokens: [
|
|
27
|
+
{
|
|
28
|
+
from: /loadTemplateShape/g,
|
|
29
|
+
to: `load${capitalizedName}Shape`,
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
from: /"#template#"/g,
|
|
33
|
+
to: `"${camelizedName}"`,
|
|
34
|
+
},
|
|
35
|
+
],
|
|
36
|
+
});
|
|
30
37
|
}
|
|
31
38
|
|
|
32
39
|
/**
|
|
@@ -45,11 +52,11 @@ async function updateShapePackageFile(
|
|
|
45
52
|
const camelizedName = camelize(camelize(name, "-"), " "),
|
|
46
53
|
dashedName = dash(camelizedName);
|
|
47
54
|
|
|
48
|
-
updatePackageFile(
|
|
55
|
+
await updatePackageFile(
|
|
49
56
|
destPath,
|
|
50
|
-
`
|
|
57
|
+
`tsparticles-shape-${dashedName}`,
|
|
51
58
|
description,
|
|
52
|
-
`
|
|
59
|
+
`tsparticles.shape.${camelizedName}.min.js`,
|
|
53
60
|
repoUrl,
|
|
54
61
|
);
|
|
55
62
|
}
|
|
@@ -72,9 +79,9 @@ async function updateShapePackageDistFile(
|
|
|
72
79
|
|
|
73
80
|
await updatePackageDistFile(
|
|
74
81
|
destPath,
|
|
75
|
-
`
|
|
82
|
+
`tsparticles-shape-${dashedName}`,
|
|
76
83
|
description,
|
|
77
|
-
`
|
|
84
|
+
`tsparticles.shape.${camelizedName}.min.js`,
|
|
78
85
|
repoUrl,
|
|
79
86
|
);
|
|
80
87
|
}
|
|
@@ -87,44 +94,46 @@ async function updateShapePackageDistFile(
|
|
|
87
94
|
* @param repoUrl - The repository url
|
|
88
95
|
*/
|
|
89
96
|
async function updateReadmeFile(destPath: string, name: string, description: string, repoUrl: string): Promise<void> {
|
|
90
|
-
const
|
|
91
|
-
readme = await fs.readFile(readmePath, "utf-8"),
|
|
92
|
-
capitalizedName = capitalize(capitalize(name, "-"), " "),
|
|
97
|
+
const capitalizedName = capitalize(name, "-", " "),
|
|
93
98
|
camelizedName = camelize(capitalizedName),
|
|
94
99
|
dashedName = dash(camelizedName),
|
|
95
|
-
readmeDescriptionRegex = /tsParticles Template Shape/g,
|
|
96
|
-
replacedDescriptionText = readme.replace(readmeDescriptionRegex, `tsParticles ${description} Shape`),
|
|
97
|
-
readmePackageNameRegex = /tsparticles-shape-template/g,
|
|
98
|
-
replacedPackageNameText = replacedDescriptionText.replace(
|
|
99
|
-
readmePackageNameRegex,
|
|
100
|
-
`tsparticles-shape-${dashedName}`,
|
|
101
|
-
),
|
|
102
|
-
readmeFileNameRegex = /tsparticles\.shape\.template(\.bundle)?\.min\.js/g,
|
|
103
|
-
replacedFileNameText = replacedPackageNameText.replace(
|
|
104
|
-
readmeFileNameRegex,
|
|
105
|
-
`tsparticles.shape.${camelizedName}$1.min.js`,
|
|
106
|
-
),
|
|
107
|
-
readmeFunctionNameRegex = /loadTemplateShape/g,
|
|
108
|
-
replacedFunctionNameText = replacedFileNameText.replace(readmeFunctionNameRegex, `load${capitalizedName}Shape`),
|
|
109
|
-
readmeMiniDescriptionRegex =
|
|
110
|
-
/\[tsParticles]\(https:\/\/github.com\/matteobruni\/tsparticles\) additional template shape\./g,
|
|
111
|
-
replacedMiniDescriptionText = replacedFunctionNameText.replace(
|
|
112
|
-
readmeMiniDescriptionRegex,
|
|
113
|
-
`[tsParticles](https://github.com/matteobruni/tsparticles) additional ${name} shape.`,
|
|
114
|
-
),
|
|
115
|
-
readmeUsageRegex = /shape\.type: "template"/g,
|
|
116
|
-
replacedUsageText = replacedMiniDescriptionText.replace(readmeUsageRegex, `shape.type: "${camelizedName}`),
|
|
117
|
-
sampleImageRegex =
|
|
118
|
-
/!\[demo]\(https:\/\/raw.githubusercontent.com\/tsparticles\/shape-template\/main\/images\/sample.png\)/g,
|
|
119
100
|
repoPath = repoUrl.includes("github.com")
|
|
120
101
|
? repoUrl.substring(repoUrl.indexOf("github.com/") + 11, repoUrl.indexOf(".git"))
|
|
121
|
-
: "tsparticles/shape-template"
|
|
122
|
-
replacedText = replacedUsageText.replace(
|
|
123
|
-
sampleImageRegex,
|
|
124
|
-
``,
|
|
125
|
-
);
|
|
102
|
+
: "tsparticles/shape-template";
|
|
126
103
|
|
|
127
|
-
await
|
|
104
|
+
await replaceTokensInFile({
|
|
105
|
+
path: path.resolve(destPath, "README.md"),
|
|
106
|
+
tokens: [
|
|
107
|
+
{
|
|
108
|
+
from: /tsParticles Template Shape/g,
|
|
109
|
+
to: `tsParticles ${description} Shape`,
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
from: /tsparticles-shape-template/g,
|
|
113
|
+
to: `tsparticles-shape-${dashedName}`,
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
from: /tsparticles\.shape\.template(\.bundle)?\.min\.js/g,
|
|
117
|
+
to: `tsparticles.shape.${camelizedName}$1.min.js`,
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
from: /loadTemplateShape/g,
|
|
121
|
+
to: `load${capitalizedName}Shape`,
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
from: /\[tsParticles]\(https:\/\/github.com\/matteobruni\/tsparticles\) additional template shape\./g,
|
|
125
|
+
to: `[tsParticles](https://github.com/matteobruni/tsparticles) additional ${name} shape.`,
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
from: /shape\.type: "template"/g,
|
|
129
|
+
to: `shape.type: "${camelizedName}`,
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
from: /!\[demo]\(https:\/\/raw.githubusercontent.com\/tsparticles\/shape-template\/main\/images\/sample.png\)/g,
|
|
133
|
+
to: ``,
|
|
134
|
+
},
|
|
135
|
+
],
|
|
136
|
+
});
|
|
128
137
|
}
|
|
129
138
|
|
|
130
139
|
/**
|
|
@@ -134,12 +143,7 @@ async function updateReadmeFile(destPath: string, name: string, description: str
|
|
|
134
143
|
* @param description - The description of the project
|
|
135
144
|
*/
|
|
136
145
|
async function updateShapeWebpackFile(destPath: string, name: string, description: string): Promise<void> {
|
|
137
|
-
await updateWebpackFile(
|
|
138
|
-
destPath,
|
|
139
|
-
camelize(capitalize(capitalize(name, "-"), " ")),
|
|
140
|
-
description,
|
|
141
|
-
"loadParticlesShape",
|
|
142
|
-
);
|
|
146
|
+
await updateWebpackFile(destPath, camelize(capitalize(name, "-", " ")), description, "loadParticlesShape");
|
|
143
147
|
}
|
|
144
148
|
|
|
145
149
|
/**
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
+
import { getDestinationDir, getRepositoryUrl } from "../../utils/file-utils";
|
|
1
2
|
import prompts, { type PromptObject } from "prompts";
|
|
2
3
|
import { Command } from "commander";
|
|
3
4
|
import { capitalize } from "../../utils/string-utils";
|
|
4
5
|
import { createShapeTemplate } from "./create-shape";
|
|
5
|
-
import { execSync } from "child_process";
|
|
6
|
-
import fs from "fs-extra";
|
|
7
6
|
import path from "path";
|
|
8
7
|
|
|
9
8
|
const shapeCommand = new Command("shape");
|
|
@@ -11,27 +10,8 @@ const shapeCommand = new Command("shape");
|
|
|
11
10
|
shapeCommand.description("Create a new tsParticles shape");
|
|
12
11
|
shapeCommand.argument("<destination>", "Destination folder");
|
|
13
12
|
shapeCommand.action(async (destination: string) => {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const destPath = path.resolve(path.join(process.cwd(), destination)),
|
|
17
|
-
destExists = await fs.pathExists(destPath);
|
|
18
|
-
|
|
19
|
-
if (destExists) {
|
|
20
|
-
const destContents = await fs.readdir(destPath),
|
|
21
|
-
destContentsNoGit = destContents.filter(t => t !== ".git" && t !== ".gitignore");
|
|
22
|
-
|
|
23
|
-
if (destContentsNoGit.length) {
|
|
24
|
-
throw new Error("Destination folder already exists and is not empty");
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
await fs.ensureDir(destPath);
|
|
29
|
-
|
|
30
|
-
try {
|
|
31
|
-
repoUrl = execSync("git config --get remote.origin.url").toString();
|
|
32
|
-
} catch {
|
|
33
|
-
repoUrl = "";
|
|
34
|
-
}
|
|
13
|
+
const destPath = await getDestinationDir(destination),
|
|
14
|
+
repoUrl = getRepositoryUrl();
|
|
35
15
|
|
|
36
16
|
const initialName = destPath.split(path.sep).pop(),
|
|
37
17
|
questions: PromptObject[] = [
|
|
@@ -59,7 +39,7 @@ shapeCommand.action(async (destination: string) => {
|
|
|
59
39
|
|
|
60
40
|
const { name, description, repositoryUrl } = await prompts(questions);
|
|
61
41
|
|
|
62
|
-
createShapeTemplate(name.trim(), description.trim(), repositoryUrl.trim(), destPath);
|
|
42
|
+
await createShapeTemplate(name.trim(), description.trim(), repositoryUrl.trim(), destPath);
|
|
63
43
|
});
|
|
64
44
|
|
|
65
45
|
export { shapeCommand };
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { execSync } from "child_process";
|
|
2
|
+
import fs from "fs-extra";
|
|
3
|
+
import path from "path";
|
|
4
|
+
|
|
5
|
+
export type ReplaceTokensOptions = {
|
|
6
|
+
path: string;
|
|
7
|
+
tokens: ReplaceTokensData[];
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export type ReplaceTokensData = {
|
|
11
|
+
from: string | RegExp;
|
|
12
|
+
to: string;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
*
|
|
17
|
+
* @param options -
|
|
18
|
+
*/
|
|
19
|
+
export async function replaceTokensInFiles(options: ReplaceTokensOptions[]): Promise<void> {
|
|
20
|
+
for (const item of options) {
|
|
21
|
+
const filePath = path.resolve(item.path);
|
|
22
|
+
|
|
23
|
+
let data = await fs.readFile(filePath, "utf-8");
|
|
24
|
+
|
|
25
|
+
for (const token of item.tokens) {
|
|
26
|
+
const regex = new RegExp(token.from, "g");
|
|
27
|
+
|
|
28
|
+
data = data.replace(regex, token.to);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
await fs.writeFile(filePath, data);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
*
|
|
37
|
+
* @param options -
|
|
38
|
+
*/
|
|
39
|
+
export async function replaceTokensInFile(options: ReplaceTokensOptions): Promise<void> {
|
|
40
|
+
await replaceTokensInFiles([options]);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
*
|
|
45
|
+
* @param destination -
|
|
46
|
+
* @returns the destination directory path
|
|
47
|
+
*/
|
|
48
|
+
export async function getDestinationDir(destination: string): Promise<string> {
|
|
49
|
+
const destPath = path.resolve(path.join(process.cwd(), destination)),
|
|
50
|
+
destExists = await fs.pathExists(destPath);
|
|
51
|
+
|
|
52
|
+
if (destExists) {
|
|
53
|
+
const destContents = await fs.readdir(destPath),
|
|
54
|
+
destContentsNoGit = destContents.filter(t => t !== ".git" && t !== ".gitignore");
|
|
55
|
+
|
|
56
|
+
if (destContentsNoGit.length) {
|
|
57
|
+
throw new Error("Destination folder already exists and is not empty");
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
await fs.ensureDir(destPath);
|
|
62
|
+
|
|
63
|
+
return destPath;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* @returns the repository URL
|
|
68
|
+
*/
|
|
69
|
+
export function getRepositoryUrl(): string {
|
|
70
|
+
try {
|
|
71
|
+
return execSync("git config --get remote.origin.url").toString();
|
|
72
|
+
} catch {
|
|
73
|
+
return "";
|
|
74
|
+
}
|
|
75
|
+
}
|
|
@@ -1,23 +1,30 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* This function is used to capitalize a string.
|
|
3
3
|
* @param str - the string to capitalize (e.g. "my-string" -\> "MyString")
|
|
4
|
-
* @param
|
|
4
|
+
* @param splits - the characters used to split the string, if not provided the string will be considered a single word
|
|
5
5
|
* @returns the capitalized string
|
|
6
6
|
*/
|
|
7
|
-
export function capitalize(str: string,
|
|
8
|
-
|
|
7
|
+
export function capitalize(str: string, ...splits: string[]): string {
|
|
8
|
+
let res = str.replace(/./, c => c.toUpperCase());
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
for (const split of splits) {
|
|
11
|
+
res = res
|
|
12
|
+
.split(split)
|
|
13
|
+
.map(w => w.replace(/./, c => c.toUpperCase()))
|
|
14
|
+
.join("");
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return res;
|
|
11
18
|
}
|
|
12
19
|
|
|
13
20
|
/**
|
|
14
21
|
* This function is used to camelcase a string.
|
|
15
22
|
* @param str - the string to camelcase (e.g. "my-string" -\> "myString")
|
|
16
|
-
* @param
|
|
23
|
+
* @param splits - the characters used to split the string, if not provided the string will be considered a single word
|
|
17
24
|
* @returns the camelized string
|
|
18
25
|
*/
|
|
19
|
-
export function camelize(str: string,
|
|
20
|
-
return capitalize(str,
|
|
26
|
+
export function camelize(str: string, ...splits: string[]): string {
|
|
27
|
+
return capitalize(str, ...splits).replace(/./, c => c.toLowerCase());
|
|
21
28
|
}
|
|
22
29
|
|
|
23
30
|
/**
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { execSync } from "child_process";
|
|
2
2
|
import fs from "fs-extra";
|
|
3
3
|
import path from "path";
|
|
4
|
+
import { replaceTokensInFile } from "./file-utils";
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* Updates the package.json file
|
|
@@ -17,22 +18,35 @@ export async function updatePackageFile(
|
|
|
17
18
|
fileName: string,
|
|
18
19
|
repoUrl: string,
|
|
19
20
|
): Promise<void> {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
21
|
+
await replaceTokensInFile({
|
|
22
|
+
path: path.resolve(destPath, "package.json"),
|
|
23
|
+
tokens: [
|
|
24
|
+
{
|
|
25
|
+
from: /"tsParticles empty template"/g,
|
|
26
|
+
to: `"${description}"`,
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
from: /"tsparticles.empty.template.min.js"/g,
|
|
30
|
+
to: `"${fileName}"`,
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
from: /\s{4}"private": true,\r?\n?/g,
|
|
34
|
+
to: "",
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
from: /"@tsparticles\/empty-template"/g,
|
|
38
|
+
to: `"${packageName}"`,
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
from: /"url": "git\+https:\/\/github\.com\/tsparticles\/empty-template\.git"/g,
|
|
42
|
+
to: `"url": "git+${repoUrl}"`,
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
from: /"url": "https:\/\/github\.com\/tsparticles\/empty-template\/issues"/g,
|
|
46
|
+
to: `"url": "${repoUrl.replace(".git", "/issues")}"`,
|
|
47
|
+
},
|
|
48
|
+
],
|
|
49
|
+
});
|
|
36
50
|
}
|
|
37
51
|
|
|
38
52
|
/**
|
|
@@ -50,22 +64,35 @@ export async function updatePackageDistFile(
|
|
|
50
64
|
fileName: string,
|
|
51
65
|
repoUrl: string,
|
|
52
66
|
): Promise<void> {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
67
|
+
await replaceTokensInFile({
|
|
68
|
+
path: path.resolve(destPath, "package.dist.json"),
|
|
69
|
+
tokens: [
|
|
70
|
+
{
|
|
71
|
+
from: /"tsParticles empty template"/g,
|
|
72
|
+
to: `"${description}"`,
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
from: /"tsparticles.empty.template.min.js"/g,
|
|
76
|
+
to: `"${fileName}"`,
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
from: /\s{4}"private": true,\r?\n?/g,
|
|
80
|
+
to: "",
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
from: /"@tsparticles\/empty-template"/g,
|
|
84
|
+
to: `"${packageName}"`,
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
from: /"url": "git\+https:\/\/github\.com\/tsparticles\/empty-template\.git"/g,
|
|
88
|
+
to: `"url": "git+${repoUrl}"`,
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
from: /"url": "https:\/\/github\.com\/tsparticles\/empty-template\/issues"/g,
|
|
92
|
+
to: `"url": "${repoUrl.replace(".git", "/issues")}"`,
|
|
93
|
+
},
|
|
94
|
+
],
|
|
95
|
+
});
|
|
69
96
|
}
|
|
70
97
|
|
|
71
98
|
/**
|
|
@@ -81,16 +108,23 @@ export async function updateWebpackFile(
|
|
|
81
108
|
description: string,
|
|
82
109
|
fnName: string,
|
|
83
110
|
): Promise<void> {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
111
|
+
await replaceTokensInFile({
|
|
112
|
+
path: path.resolve(destPath, "webpack.config.js"),
|
|
113
|
+
tokens: [
|
|
114
|
+
{
|
|
115
|
+
from: /"Empty"/g,
|
|
116
|
+
to: `"${description}"`,
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
from: /"empty"/g,
|
|
120
|
+
to: `"${name}"`,
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
from: /loadParticlesTemplate/g,
|
|
124
|
+
to: fnName,
|
|
125
|
+
},
|
|
126
|
+
],
|
|
127
|
+
});
|
|
94
128
|
}
|
|
95
129
|
|
|
96
130
|
/**
|
|
@@ -98,9 +132,7 @@ export async function updateWebpackFile(
|
|
|
98
132
|
* @param destPath - The path where the project will be created
|
|
99
133
|
*/
|
|
100
134
|
export async function copyEmptyTemplateFiles(destPath: string): Promise<void> {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
await fs.copy(emptyPath, destPath, {
|
|
135
|
+
await fs.copy(path.resolve(__dirname, "..", "..", "files", "empty-project"), destPath, {
|
|
104
136
|
overwrite: true,
|
|
105
137
|
filter: copyFilter,
|
|
106
138
|
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { describe, it } from "mocha";
|
|
2
|
+
import { expect } from "chai";
|
|
3
|
+
import { createPluginTemplate } from "../src/create/plugin/create-plugin";
|
|
4
|
+
import path from "path";
|
|
5
|
+
import fs from "fs-extra";
|
|
6
|
+
|
|
7
|
+
describe("create-plugin", async () => {
|
|
8
|
+
it("should have created the plugin project", async () => {
|
|
9
|
+
const destDir = path.resolve(path.join(__dirname, "tmp-files", "foo-plugin"));
|
|
10
|
+
|
|
11
|
+
await createPluginTemplate("foo", "Foo", "", destDir);
|
|
12
|
+
|
|
13
|
+
const pkgInfo = await fs.readJSON(path.join(destDir, "package.json"));
|
|
14
|
+
|
|
15
|
+
expect(pkgInfo.name).to.be.equal("tsparticles-plugin-foo");
|
|
16
|
+
|
|
17
|
+
await fs.remove(destDir);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it("should have created the plugin project, w/ repo", async () => {
|
|
21
|
+
const destDir = path.resolve(path.join(__dirname, "tmp-files", "bar-plugin"));
|
|
22
|
+
|
|
23
|
+
await createPluginTemplate("bar", "Bar", "https://github.com/matteobruni/tsparticles", destDir);
|
|
24
|
+
|
|
25
|
+
const pkgInfo = await fs.readJSON(path.join(destDir, "package.json"));
|
|
26
|
+
|
|
27
|
+
expect(pkgInfo.name).to.be.equal("tsparticles-plugin-bar");
|
|
28
|
+
|
|
29
|
+
await fs.remove(destDir);
|
|
30
|
+
});
|
|
31
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { describe, it } from "mocha";
|
|
2
|
+
import { expect } from "chai";
|
|
3
|
+
import { createPresetTemplate } from "../src/create/preset/create-preset";
|
|
4
|
+
import path from "path";
|
|
5
|
+
import fs from "fs-extra";
|
|
6
|
+
|
|
7
|
+
describe("create-plugin", async () => {
|
|
8
|
+
it("should have created the preset project", async () => {
|
|
9
|
+
const destDir = path.resolve(path.join(__dirname, "tmp-files", "foo-preset"));
|
|
10
|
+
|
|
11
|
+
await createPresetTemplate("foo", "Foo", "", destDir);
|
|
12
|
+
|
|
13
|
+
const pkgInfo = await fs.readJSON(path.join(destDir, "package.json"));
|
|
14
|
+
|
|
15
|
+
expect(pkgInfo.name).to.be.equal("tsparticles-preset-foo");
|
|
16
|
+
|
|
17
|
+
await fs.remove(destDir);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it("should have created the preset project, w/ repo", async () => {
|
|
21
|
+
const destDir = path.resolve(path.join(__dirname, "tmp-files", "bar-preset"));
|
|
22
|
+
|
|
23
|
+
await createPresetTemplate("bar", "Bar", "https://github.com/matteobruni/tsparticles", destDir);
|
|
24
|
+
|
|
25
|
+
const pkgInfo = await fs.readJSON(path.join(destDir, "package.json"));
|
|
26
|
+
|
|
27
|
+
expect(pkgInfo.name).to.be.equal("tsparticles-preset-bar");
|
|
28
|
+
|
|
29
|
+
await fs.remove(destDir);
|
|
30
|
+
});
|
|
31
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { describe, it } from "mocha";
|
|
2
|
+
import { expect } from "chai";
|
|
3
|
+
import { createShapeTemplate } from "../src/create/shape/create-shape";
|
|
4
|
+
import path from "path";
|
|
5
|
+
import fs from "fs-extra";
|
|
6
|
+
|
|
7
|
+
describe("create-shape", async () => {
|
|
8
|
+
it("should have created the shape project", async () => {
|
|
9
|
+
const destDir = path.resolve(path.join(__dirname, "tmp-files", "foo-shape"));
|
|
10
|
+
|
|
11
|
+
await createShapeTemplate("foo", "Foo", "", destDir);
|
|
12
|
+
|
|
13
|
+
const pkgInfo = await fs.readJSON(path.join(destDir, "package.json"));
|
|
14
|
+
|
|
15
|
+
expect(pkgInfo.name).to.be.equal("tsparticles-shape-foo");
|
|
16
|
+
|
|
17
|
+
await fs.remove(destDir);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it("should have created the shape project, w/ repo", async () => {
|
|
21
|
+
const destDir = path.resolve(path.join(__dirname, "tmp-files", "bar-shape"));
|
|
22
|
+
|
|
23
|
+
await createShapeTemplate("bar", "Bar", "https://github.com/matteobruni/tsparticles", destDir);
|
|
24
|
+
|
|
25
|
+
const pkgInfo = await fs.readJSON(path.join(destDir, "package.json"));
|
|
26
|
+
|
|
27
|
+
expect(pkgInfo.name).to.be.equal("tsparticles-shape-bar");
|
|
28
|
+
|
|
29
|
+
await fs.remove(destDir);
|
|
30
|
+
});
|
|
31
|
+
});
|