@tsparticles/cli 1.11.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/create-preset/README.md +3 -3
- package/files/empty-project/package.dist.json +1 -1
- package/files/empty-project/package.json +3 -3
- package/package.json +19 -12
- package/scripts/postversion.js +1 -1
- package/src/build/build.ts +1 -1
- package/src/cli.ts +2 -2
- package/src/create/plugin/create-plugin.ts +58 -56
- package/src/create/plugin/plugin.ts +4 -24
- package/src/create/preset/create-preset.ts +73 -68
- package/src/create/preset/preset.ts +4 -24
- package/src/create/shape/create-shape.ts +58 -54
- 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
|
@@ -44,6 +44,7 @@ jobs:
|
|
|
44
44
|
${{ runner.os }}-pnpm-store-
|
|
45
45
|
- run: pnpm install --no-frozen-lockfile
|
|
46
46
|
- run: npx pnpm run build:ci
|
|
47
|
+
- run: npx pnpm test
|
|
47
48
|
pr:
|
|
48
49
|
runs-on: ubuntu-latest
|
|
49
50
|
if: ${{ github.event_name == 'pull_request' }}
|
|
@@ -81,3 +82,4 @@ jobs:
|
|
|
81
82
|
${{ runner.os }}-pnpm-store-
|
|
82
83
|
- run: pnpm install --no-frozen-lockfile
|
|
83
84
|
- run: npx pnpm run build:ci
|
|
85
|
+
- run: npx pnpm test
|
package/.mocharc.json
ADDED
package/dist/build/build.js
CHANGED
|
@@ -16,7 +16,7 @@ const build_eslint_1 = require("./build-eslint");
|
|
|
16
16
|
const path_1 = __importDefault(require("path"));
|
|
17
17
|
const buildCommand = new commander_1.Command("build");
|
|
18
18
|
exports.buildCommand = buildCommand;
|
|
19
|
-
buildCommand.description("Build the library using TypeScript");
|
|
19
|
+
buildCommand.description("Build the tsParticles library using TypeScript");
|
|
20
20
|
buildCommand.option("-a, --all", "Do all build steps (default if no flags are specified) (same as -b -c -d -l -p -t)", true);
|
|
21
21
|
buildCommand.option("-b, --bundle", "Bundle the library using Webpack", false);
|
|
22
22
|
buildCommand.option("-c, --clean", "Clean the dist folder", false);
|
package/dist/cli.js
CHANGED
|
@@ -8,8 +8,8 @@ const build_1 = require("./build/build");
|
|
|
8
8
|
const create_1 = require("./create/create");
|
|
9
9
|
const package_json_1 = __importDefault(require("../package.json"));
|
|
10
10
|
const commander_1 = require("commander");
|
|
11
|
-
commander_1.program.name("tsparticles-cli
|
|
12
|
-
commander_1.program.description("tsParticles
|
|
11
|
+
commander_1.program.name("tsparticles-cli");
|
|
12
|
+
commander_1.program.description("tsParticles CLI");
|
|
13
13
|
commander_1.program.version(package_json_1.default.version, "-v, --version", "output the current version");
|
|
14
14
|
commander_1.program.addCommand(build_1.buildCommand);
|
|
15
15
|
commander_1.program.addCommand(create_1.createCommand);
|
|
@@ -8,14 +8,27 @@ const string_utils_1 = require("../../utils/string-utils");
|
|
|
8
8
|
const template_utils_1 = require("../../utils/template-utils");
|
|
9
9
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
10
10
|
const path_1 = __importDefault(require("path"));
|
|
11
|
+
const file_utils_1 = require("../../utils/file-utils");
|
|
11
12
|
/**
|
|
12
13
|
* Updates the index file with the correct function name
|
|
13
14
|
* @param destPath - The path where the project is located
|
|
14
15
|
* @param name - The name of the project
|
|
15
16
|
*/
|
|
16
17
|
async function updateIndexFile(destPath, name) {
|
|
17
|
-
const
|
|
18
|
-
await
|
|
18
|
+
const capitalizedName = (0, string_utils_1.capitalize)(name, "-", " "), camelizedName = (0, string_utils_1.camelize)(capitalizedName);
|
|
19
|
+
await (0, file_utils_1.replaceTokensInFile)({
|
|
20
|
+
path: path_1.default.resolve(destPath, "src", "index.ts"),
|
|
21
|
+
tokens: [
|
|
22
|
+
{
|
|
23
|
+
from: /loadTemplatePlugin/g,
|
|
24
|
+
to: `load${capitalizedName}Plugin`,
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
from: /"#template#"/g,
|
|
28
|
+
to: `"${camelizedName}"`,
|
|
29
|
+
},
|
|
30
|
+
],
|
|
31
|
+
});
|
|
19
32
|
}
|
|
20
33
|
/**
|
|
21
34
|
* Updates the plugin package file
|
|
@@ -26,7 +39,7 @@ async function updateIndexFile(destPath, name) {
|
|
|
26
39
|
*/
|
|
27
40
|
async function updatePluginPackageFile(destPath, name, description, repoUrl) {
|
|
28
41
|
const camelizedName = (0, string_utils_1.camelize)((0, string_utils_1.camelize)(name, "-"), " "), dashedName = (0, string_utils_1.dash)(camelizedName);
|
|
29
|
-
(0, template_utils_1.updatePackageFile)(destPath, `
|
|
42
|
+
await (0, template_utils_1.updatePackageFile)(destPath, `tsparticles-plugin-${dashedName}`, description, `tsparticles.plugin.${camelizedName}.min.js`, repoUrl);
|
|
30
43
|
}
|
|
31
44
|
/**
|
|
32
45
|
* Updates the plugin package dist file
|
|
@@ -37,7 +50,7 @@ async function updatePluginPackageFile(destPath, name, description, repoUrl) {
|
|
|
37
50
|
*/
|
|
38
51
|
async function updatePluginPackageDistFile(destPath, name, description, repoUrl) {
|
|
39
52
|
const camelizedName = (0, string_utils_1.camelize)((0, string_utils_1.camelize)(name, "-"), " "), dashedName = (0, string_utils_1.dash)(camelizedName);
|
|
40
|
-
(0, template_utils_1.updatePackageDistFile)(destPath, `
|
|
53
|
+
await (0, template_utils_1.updatePackageDistFile)(destPath, `tsparticles-plugin-${dashedName}`, description, `tsparticles.plugin.${camelizedName}.min.js`, repoUrl);
|
|
41
54
|
}
|
|
42
55
|
/**
|
|
43
56
|
* Updates the plugin readme file
|
|
@@ -47,10 +60,42 @@ async function updatePluginPackageDistFile(destPath, name, description, repoUrl)
|
|
|
47
60
|
* @param repoUrl - The repository url
|
|
48
61
|
*/
|
|
49
62
|
async function updateReadmeFile(destPath, name, description, repoUrl) {
|
|
50
|
-
const readmePath = path_1.default.resolve(destPath, "README.md"),
|
|
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")
|
|
51
64
|
? repoUrl.substring(repoUrl.indexOf("github.com/") + 11, repoUrl.indexOf(".git"))
|
|
52
|
-
: "tsparticles/plugin-template"
|
|
53
|
-
await
|
|
65
|
+
: "tsparticles/plugin-template";
|
|
66
|
+
await (0, file_utils_1.replaceTokensInFile)({
|
|
67
|
+
path: readmePath,
|
|
68
|
+
tokens: [
|
|
69
|
+
{
|
|
70
|
+
from: /tsParticles Template Plugin/g,
|
|
71
|
+
to: `tsParticles ${description} Plugin`,
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
from: /tsparticles-plugin-template/g,
|
|
75
|
+
to: `tsparticles-plugin-${dashedName}`,
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
from: /tsparticles\.plugin\.template(\.bundle)?\.min\.js/g,
|
|
79
|
+
to: `tsparticles.plugin.${camelizedName}$1.min.js`,
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
from: /loadTemplatePlugin/g,
|
|
83
|
+
to: `load${capitalizedName}Plugin`,
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
from: /\[tsParticles]\(https:\/\/github.com\/matteobruni\/tsparticles\) additional template plugin\./g,
|
|
87
|
+
to: `[tsParticles](https://github.com/matteobruni/tsparticles) additional ${name} plugin.`,
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
from: /plugin\.type: "template"/g,
|
|
91
|
+
to: `plugin.type: "${camelizedName}"`,
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
from: /!\[demo]\(https:\/\/raw.githubusercontent.com\/tsparticles\/plugin-template\/main\/images\/sample.png\)/g,
|
|
95
|
+
to: ``,
|
|
96
|
+
},
|
|
97
|
+
],
|
|
98
|
+
});
|
|
54
99
|
}
|
|
55
100
|
/**
|
|
56
101
|
* Updates the plugin webpack file
|
|
@@ -59,7 +104,7 @@ async function updateReadmeFile(destPath, name, description, repoUrl) {
|
|
|
59
104
|
* @param description - The description of the project
|
|
60
105
|
*/
|
|
61
106
|
async function updatePluginWebpackFile(destPath, name, description) {
|
|
62
|
-
await (0, template_utils_1.updateWebpackFile)(destPath, (0, string_utils_1.camelize)((0, string_utils_1.capitalize)(
|
|
107
|
+
await (0, template_utils_1.updateWebpackFile)(destPath, (0, string_utils_1.camelize)((0, string_utils_1.capitalize)(name, "-", " ")), description, "loadParticlesPlugin");
|
|
63
108
|
}
|
|
64
109
|
/**
|
|
65
110
|
* Creates the plugin project
|
|
@@ -4,33 +4,18 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.pluginCommand = void 0;
|
|
7
|
+
const file_utils_1 = require("../../utils/file-utils");
|
|
7
8
|
const prompts_1 = __importDefault(require("prompts"));
|
|
8
9
|
const commander_1 = require("commander");
|
|
9
10
|
const string_utils_1 = require("../../utils/string-utils");
|
|
10
11
|
const create_plugin_1 = require("./create-plugin");
|
|
11
|
-
const child_process_1 = require("child_process");
|
|
12
|
-
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
13
12
|
const path_1 = __importDefault(require("path"));
|
|
14
13
|
const pluginCommand = new commander_1.Command("plugin");
|
|
15
14
|
exports.pluginCommand = pluginCommand;
|
|
16
15
|
pluginCommand.description("Create a new tsParticles plugin");
|
|
17
16
|
pluginCommand.argument("<destination>", "Destination folder");
|
|
18
17
|
pluginCommand.action(async (destination) => {
|
|
19
|
-
|
|
20
|
-
const destPath = path_1.default.resolve(path_1.default.join(process.cwd(), destination)), destExists = await fs_extra_1.default.pathExists(destPath);
|
|
21
|
-
if (destExists) {
|
|
22
|
-
const destContents = await fs_extra_1.default.readdir(destPath), destContentsNoGit = destContents.filter(t => t !== ".git" && t !== ".gitignore");
|
|
23
|
-
if (destContentsNoGit.length) {
|
|
24
|
-
throw new Error("Destination folder already exists and is not empty");
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
await fs_extra_1.default.ensureDir(destPath);
|
|
28
|
-
try {
|
|
29
|
-
repoUrl = (0, child_process_1.execSync)("git config --get remote.origin.url").toString();
|
|
30
|
-
}
|
|
31
|
-
catch {
|
|
32
|
-
repoUrl = "";
|
|
33
|
-
}
|
|
18
|
+
const destPath = await (0, file_utils_1.getDestinationDir)(destination), repoUrl = (0, file_utils_1.getRepositoryUrl)();
|
|
34
19
|
const initialName = destPath.split(path_1.default.sep).pop(), questions = [
|
|
35
20
|
{
|
|
36
21
|
type: "text",
|
|
@@ -54,5 +39,5 @@ pluginCommand.action(async (destination) => {
|
|
|
54
39
|
},
|
|
55
40
|
];
|
|
56
41
|
const { name, description, repositoryUrl } = await (0, prompts_1.default)(questions);
|
|
57
|
-
(0, create_plugin_1.createPluginTemplate)(name.trim(), description.trim(), repositoryUrl.trim(), destPath);
|
|
42
|
+
await (0, create_plugin_1.createPluginTemplate)(name.trim(), description.trim(), repositoryUrl.trim(), destPath);
|
|
58
43
|
});
|
|
@@ -8,14 +8,23 @@ const string_utils_1 = require("../../utils/string-utils");
|
|
|
8
8
|
const template_utils_1 = require("../../utils/template-utils");
|
|
9
9
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
10
10
|
const path_1 = __importDefault(require("path"));
|
|
11
|
+
const file_utils_1 = require("../../utils/file-utils");
|
|
11
12
|
/**
|
|
12
13
|
* Updates the bundle file with the correct function name
|
|
13
14
|
* @param destPath - The path where the project is located
|
|
14
15
|
* @param name - The name of the project
|
|
15
16
|
*/
|
|
16
17
|
async function updateBundleFile(destPath, name) {
|
|
17
|
-
const
|
|
18
|
-
await
|
|
18
|
+
const capitalizedName = (0, string_utils_1.capitalize)(name, "-", " ");
|
|
19
|
+
await (0, file_utils_1.replaceTokensInFile)({
|
|
20
|
+
path: path_1.default.resolve(destPath, "src", "bundle.ts"),
|
|
21
|
+
tokens: [
|
|
22
|
+
{
|
|
23
|
+
from: /loadTemplatePreset/g,
|
|
24
|
+
to: `load${capitalizedName}Preset`,
|
|
25
|
+
},
|
|
26
|
+
],
|
|
27
|
+
});
|
|
19
28
|
}
|
|
20
29
|
/**
|
|
21
30
|
* Updates the index file with the correct function name
|
|
@@ -23,8 +32,20 @@ async function updateBundleFile(destPath, name) {
|
|
|
23
32
|
* @param name - The name of the project
|
|
24
33
|
*/
|
|
25
34
|
async function updateIndexFile(destPath, name) {
|
|
26
|
-
const
|
|
27
|
-
await
|
|
35
|
+
const capitalizedName = (0, string_utils_1.capitalize)(name, "-", " "), camelizedName = (0, string_utils_1.camelize)(capitalizedName);
|
|
36
|
+
await (0, file_utils_1.replaceTokensInFile)({
|
|
37
|
+
path: path_1.default.resolve(destPath, "src", "index.ts"),
|
|
38
|
+
tokens: [
|
|
39
|
+
{
|
|
40
|
+
from: /loadTemplatePreset/g,
|
|
41
|
+
to: `load${capitalizedName}Preset`,
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
from: /"#template#"/g,
|
|
45
|
+
to: `"${camelizedName}"`,
|
|
46
|
+
},
|
|
47
|
+
],
|
|
48
|
+
});
|
|
28
49
|
}
|
|
29
50
|
/**
|
|
30
51
|
* Updates the preset package file
|
|
@@ -34,8 +55,8 @@ async function updateIndexFile(destPath, name) {
|
|
|
34
55
|
* @param repoUrl - The repository url
|
|
35
56
|
*/
|
|
36
57
|
async function updatePresetPackageFile(destPath, name, description, repoUrl) {
|
|
37
|
-
const camelizedName = (0, string_utils_1.camelize)(
|
|
38
|
-
(0, template_utils_1.updatePackageFile)(destPath, `
|
|
58
|
+
const camelizedName = (0, string_utils_1.camelize)(name, "-", " "), dashedName = (0, string_utils_1.dash)(camelizedName);
|
|
59
|
+
await (0, template_utils_1.updatePackageFile)(destPath, `tsparticles-preset-${dashedName}`, description, `tsparticles.preset.${camelizedName}.min.js`, repoUrl);
|
|
39
60
|
}
|
|
40
61
|
/**
|
|
41
62
|
* Updates the preset package dist file
|
|
@@ -45,8 +66,8 @@ async function updatePresetPackageFile(destPath, name, description, repoUrl) {
|
|
|
45
66
|
* @param repoUrl - The repository url
|
|
46
67
|
*/
|
|
47
68
|
async function updatePresetPackageDistFile(destPath, name, description, repoUrl) {
|
|
48
|
-
const camelizedName = (0, string_utils_1.camelize)(
|
|
49
|
-
(0, template_utils_1.updatePackageDistFile)(destPath, `
|
|
69
|
+
const camelizedName = (0, string_utils_1.camelize)(name, "-", " "), dashedName = (0, string_utils_1.dash)(camelizedName);
|
|
70
|
+
await (0, template_utils_1.updatePackageDistFile)(destPath, `tsparticles-preset-${dashedName}`, description, `tsparticles.preset.${camelizedName}.min.js`, repoUrl);
|
|
50
71
|
}
|
|
51
72
|
/**
|
|
52
73
|
* Updates the preset readme file
|
|
@@ -56,10 +77,42 @@ async function updatePresetPackageDistFile(destPath, name, description, repoUrl)
|
|
|
56
77
|
* @param repoUrl - The repository url
|
|
57
78
|
*/
|
|
58
79
|
async function updateReadmeFile(destPath, name, description, repoUrl) {
|
|
59
|
-
const
|
|
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")
|
|
60
81
|
? repoUrl.substring(repoUrl.indexOf("github.com/") + 11, repoUrl.indexOf(".git"))
|
|
61
|
-
: "tsparticles/preset-template"
|
|
62
|
-
await
|
|
82
|
+
: "tsparticles/preset-template";
|
|
83
|
+
await (0, file_utils_1.replaceTokensInFile)({
|
|
84
|
+
path: path_1.default.resolve(destPath, "README.md"),
|
|
85
|
+
tokens: [
|
|
86
|
+
{
|
|
87
|
+
from: /tsParticles Template Preset/g,
|
|
88
|
+
to: `tsParticles ${description} Preset`,
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
from: /tsparticles-preset-template/g,
|
|
92
|
+
to: `tsparticles-preset-${dashedName}`,
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
from: /tsparticles\.preset\.template(\.bundle)?\.min\.js/g,
|
|
96
|
+
to: `tsparticles.preset.${camelizedName}$1.min.js`,
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
from: /loadTemplatePreset/g,
|
|
100
|
+
to: `load${capitalizedName}Preset`,
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
from: /\[tsParticles]\(https:\/\/github.com\/matteobruni\/tsparticles\) preset template\./g,
|
|
104
|
+
to: `[tsParticles](https://github.com/matteobruni/tsparticles) preset ${name}.`,
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
from: /preset: "template"/g,
|
|
108
|
+
to: `preset: "${camelizedName}`,
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
from: /!\[demo]\(https:\/\/raw.githubusercontent.com\/tsparticles\/preset-template\/main\/images\/sample.png\)/g,
|
|
112
|
+
to: ``,
|
|
113
|
+
},
|
|
114
|
+
],
|
|
115
|
+
});
|
|
63
116
|
}
|
|
64
117
|
/**
|
|
65
118
|
* Updates the preset webpack file
|
|
@@ -68,7 +121,7 @@ async function updateReadmeFile(destPath, name, description, repoUrl) {
|
|
|
68
121
|
* @param description - The description of the project
|
|
69
122
|
*/
|
|
70
123
|
async function updatePresetWebpackFile(destPath, name, description) {
|
|
71
|
-
await (0, template_utils_1.updateWebpackFile)(destPath, (0, string_utils_1.camelize)((0, string_utils_1.capitalize)(
|
|
124
|
+
await (0, template_utils_1.updateWebpackFile)(destPath, (0, string_utils_1.camelize)((0, string_utils_1.capitalize)(name, "-", " ")), description, "loadParticlesPreset");
|
|
72
125
|
}
|
|
73
126
|
/**
|
|
74
127
|
* Creates the preset project
|
|
@@ -4,33 +4,18 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.presetCommand = void 0;
|
|
7
|
+
const file_utils_1 = require("../../utils/file-utils");
|
|
7
8
|
const prompts_1 = __importDefault(require("prompts"));
|
|
8
9
|
const commander_1 = require("commander");
|
|
9
10
|
const string_utils_1 = require("../../utils/string-utils");
|
|
10
11
|
const create_preset_1 = require("./create-preset");
|
|
11
|
-
const child_process_1 = require("child_process");
|
|
12
|
-
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
13
12
|
const path_1 = __importDefault(require("path"));
|
|
14
13
|
const presetCommand = new commander_1.Command("preset");
|
|
15
14
|
exports.presetCommand = presetCommand;
|
|
16
15
|
presetCommand.description("Create a new tsParticles preset");
|
|
17
16
|
presetCommand.argument("<destination>", "Destination folder");
|
|
18
17
|
presetCommand.action(async (destination) => {
|
|
19
|
-
|
|
20
|
-
const destPath = path_1.default.resolve(path_1.default.join(process.cwd(), destination)), destExists = await fs_extra_1.default.pathExists(destPath);
|
|
21
|
-
if (destExists) {
|
|
22
|
-
const destContents = await fs_extra_1.default.readdir(destPath), destContentsNoGit = destContents.filter(t => t !== ".git" && t !== ".gitignore");
|
|
23
|
-
if (destContentsNoGit.length) {
|
|
24
|
-
throw new Error("Destination folder already exists and is not empty");
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
await fs_extra_1.default.ensureDir(destPath);
|
|
28
|
-
try {
|
|
29
|
-
repoUrl = (0, child_process_1.execSync)("git config --get remote.origin.url").toString();
|
|
30
|
-
}
|
|
31
|
-
catch {
|
|
32
|
-
repoUrl = "";
|
|
33
|
-
}
|
|
18
|
+
const destPath = await (0, file_utils_1.getDestinationDir)(destination), repoUrl = (0, file_utils_1.getRepositoryUrl)();
|
|
34
19
|
const initialName = destPath.split(path_1.default.sep).pop(), questions = [
|
|
35
20
|
{
|
|
36
21
|
type: "text",
|
|
@@ -54,5 +39,5 @@ presetCommand.action(async (destination) => {
|
|
|
54
39
|
},
|
|
55
40
|
];
|
|
56
41
|
const { name, description, repositoryUrl } = await (0, prompts_1.default)(questions);
|
|
57
|
-
(0, create_preset_1.createPresetTemplate)(name.trim(), description.trim(), repositoryUrl.trim(), destPath);
|
|
42
|
+
await (0, create_preset_1.createPresetTemplate)(name.trim(), description.trim(), repositoryUrl.trim(), destPath);
|
|
58
43
|
});
|
|
@@ -8,14 +8,27 @@ const string_utils_1 = require("../../utils/string-utils");
|
|
|
8
8
|
const template_utils_1 = require("../../utils/template-utils");
|
|
9
9
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
10
10
|
const path_1 = __importDefault(require("path"));
|
|
11
|
+
const file_utils_1 = require("../../utils/file-utils");
|
|
11
12
|
/**
|
|
12
13
|
* Updates the index file with the correct function name
|
|
13
14
|
* @param destPath - The path where the project is located
|
|
14
15
|
* @param name - The name of the project
|
|
15
16
|
*/
|
|
16
17
|
async function updateIndexFile(destPath, name) {
|
|
17
|
-
const
|
|
18
|
-
await
|
|
18
|
+
const capitalizedName = (0, string_utils_1.capitalize)(name, "-", " "), camelizedName = (0, string_utils_1.camelize)(capitalizedName);
|
|
19
|
+
await (0, file_utils_1.replaceTokensInFile)({
|
|
20
|
+
path: path_1.default.resolve(destPath, "src", "index.ts"),
|
|
21
|
+
tokens: [
|
|
22
|
+
{
|
|
23
|
+
from: /loadTemplateShape/g,
|
|
24
|
+
to: `load${capitalizedName}Shape`,
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
from: /"#template#"/g,
|
|
28
|
+
to: `"${camelizedName}"`,
|
|
29
|
+
},
|
|
30
|
+
],
|
|
31
|
+
});
|
|
19
32
|
}
|
|
20
33
|
/**
|
|
21
34
|
* Updates the shape package file
|
|
@@ -26,7 +39,7 @@ async function updateIndexFile(destPath, name) {
|
|
|
26
39
|
*/
|
|
27
40
|
async function updateShapePackageFile(destPath, name, description, repoUrl) {
|
|
28
41
|
const camelizedName = (0, string_utils_1.camelize)((0, string_utils_1.camelize)(name, "-"), " "), dashedName = (0, string_utils_1.dash)(camelizedName);
|
|
29
|
-
(0, template_utils_1.updatePackageFile)(destPath, `
|
|
42
|
+
await (0, template_utils_1.updatePackageFile)(destPath, `tsparticles-shape-${dashedName}`, description, `tsparticles.shape.${camelizedName}.min.js`, repoUrl);
|
|
30
43
|
}
|
|
31
44
|
/**
|
|
32
45
|
* Updates the shape package dist file
|
|
@@ -37,7 +50,7 @@ async function updateShapePackageFile(destPath, name, description, repoUrl) {
|
|
|
37
50
|
*/
|
|
38
51
|
async function updateShapePackageDistFile(destPath, name, description, repoUrl) {
|
|
39
52
|
const camelizedName = (0, string_utils_1.camelize)((0, string_utils_1.camelize)(name, "-"), " "), dashedName = (0, string_utils_1.dash)(camelizedName);
|
|
40
|
-
(0, template_utils_1.updatePackageDistFile)(destPath, `
|
|
53
|
+
await (0, template_utils_1.updatePackageDistFile)(destPath, `tsparticles-shape-${dashedName}`, description, `tsparticles.shape.${camelizedName}.min.js`, repoUrl);
|
|
41
54
|
}
|
|
42
55
|
/**
|
|
43
56
|
* Updates the shape readme file
|
|
@@ -47,10 +60,42 @@ async function updateShapePackageDistFile(destPath, name, description, repoUrl)
|
|
|
47
60
|
* @param repoUrl - The repository url
|
|
48
61
|
*/
|
|
49
62
|
async function updateReadmeFile(destPath, name, description, repoUrl) {
|
|
50
|
-
const
|
|
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")
|
|
51
64
|
? repoUrl.substring(repoUrl.indexOf("github.com/") + 11, repoUrl.indexOf(".git"))
|
|
52
|
-
: "tsparticles/shape-template"
|
|
53
|
-
await
|
|
65
|
+
: "tsparticles/shape-template";
|
|
66
|
+
await (0, file_utils_1.replaceTokensInFile)({
|
|
67
|
+
path: path_1.default.resolve(destPath, "README.md"),
|
|
68
|
+
tokens: [
|
|
69
|
+
{
|
|
70
|
+
from: /tsParticles Template Shape/g,
|
|
71
|
+
to: `tsParticles ${description} Shape`,
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
from: /tsparticles-shape-template/g,
|
|
75
|
+
to: `tsparticles-shape-${dashedName}`,
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
from: /tsparticles\.shape\.template(\.bundle)?\.min\.js/g,
|
|
79
|
+
to: `tsparticles.shape.${camelizedName}$1.min.js`,
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
from: /loadTemplateShape/g,
|
|
83
|
+
to: `load${capitalizedName}Shape`,
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
from: /\[tsParticles]\(https:\/\/github.com\/matteobruni\/tsparticles\) additional template shape\./g,
|
|
87
|
+
to: `[tsParticles](https://github.com/matteobruni/tsparticles) additional ${name} shape.`,
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
from: /shape\.type: "template"/g,
|
|
91
|
+
to: `shape.type: "${camelizedName}`,
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
from: /!\[demo]\(https:\/\/raw.githubusercontent.com\/tsparticles\/shape-template\/main\/images\/sample.png\)/g,
|
|
95
|
+
to: ``,
|
|
96
|
+
},
|
|
97
|
+
],
|
|
98
|
+
});
|
|
54
99
|
}
|
|
55
100
|
/**
|
|
56
101
|
* Updates the shape webpack file
|
|
@@ -59,7 +104,7 @@ async function updateReadmeFile(destPath, name, description, repoUrl) {
|
|
|
59
104
|
* @param description - The description of the project
|
|
60
105
|
*/
|
|
61
106
|
async function updateShapeWebpackFile(destPath, name, description) {
|
|
62
|
-
await (0, template_utils_1.updateWebpackFile)(destPath, (0, string_utils_1.camelize)((0, string_utils_1.capitalize)(
|
|
107
|
+
await (0, template_utils_1.updateWebpackFile)(destPath, (0, string_utils_1.camelize)((0, string_utils_1.capitalize)(name, "-", " ")), description, "loadParticlesShape");
|
|
63
108
|
}
|
|
64
109
|
/**
|
|
65
110
|
* Creates the shape project
|
|
@@ -4,33 +4,18 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.shapeCommand = void 0;
|
|
7
|
+
const file_utils_1 = require("../../utils/file-utils");
|
|
7
8
|
const prompts_1 = __importDefault(require("prompts"));
|
|
8
9
|
const commander_1 = require("commander");
|
|
9
10
|
const string_utils_1 = require("../../utils/string-utils");
|
|
10
11
|
const create_shape_1 = require("./create-shape");
|
|
11
|
-
const child_process_1 = require("child_process");
|
|
12
|
-
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
13
12
|
const path_1 = __importDefault(require("path"));
|
|
14
13
|
const shapeCommand = new commander_1.Command("shape");
|
|
15
14
|
exports.shapeCommand = shapeCommand;
|
|
16
15
|
shapeCommand.description("Create a new tsParticles shape");
|
|
17
16
|
shapeCommand.argument("<destination>", "Destination folder");
|
|
18
17
|
shapeCommand.action(async (destination) => {
|
|
19
|
-
|
|
20
|
-
const destPath = path_1.default.resolve(path_1.default.join(process.cwd(), destination)), destExists = await fs_extra_1.default.pathExists(destPath);
|
|
21
|
-
if (destExists) {
|
|
22
|
-
const destContents = await fs_extra_1.default.readdir(destPath), destContentsNoGit = destContents.filter(t => t !== ".git" && t !== ".gitignore");
|
|
23
|
-
if (destContentsNoGit.length) {
|
|
24
|
-
throw new Error("Destination folder already exists and is not empty");
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
await fs_extra_1.default.ensureDir(destPath);
|
|
28
|
-
try {
|
|
29
|
-
repoUrl = (0, child_process_1.execSync)("git config --get remote.origin.url").toString();
|
|
30
|
-
}
|
|
31
|
-
catch {
|
|
32
|
-
repoUrl = "";
|
|
33
|
-
}
|
|
18
|
+
const destPath = await (0, file_utils_1.getDestinationDir)(destination), repoUrl = (0, file_utils_1.getRepositoryUrl)();
|
|
34
19
|
const initialName = destPath.split(path_1.default.sep).pop(), questions = [
|
|
35
20
|
{
|
|
36
21
|
type: "text",
|
|
@@ -54,5 +39,5 @@ shapeCommand.action(async (destination) => {
|
|
|
54
39
|
},
|
|
55
40
|
];
|
|
56
41
|
const { name, description, repositoryUrl } = await (0, prompts_1.default)(questions);
|
|
57
|
-
(0, create_shape_1.createShapeTemplate)(name.trim(), description.trim(), repositoryUrl.trim(), destPath);
|
|
42
|
+
await (0, create_shape_1.createShapeTemplate)(name.trim(), description.trim(), repositoryUrl.trim(), destPath);
|
|
58
43
|
});
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getRepositoryUrl = exports.getDestinationDir = exports.replaceTokensInFile = exports.replaceTokensInFiles = void 0;
|
|
7
|
+
const child_process_1 = require("child_process");
|
|
8
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
9
|
+
const path_1 = __importDefault(require("path"));
|
|
10
|
+
/**
|
|
11
|
+
*
|
|
12
|
+
* @param options -
|
|
13
|
+
*/
|
|
14
|
+
async function replaceTokensInFiles(options) {
|
|
15
|
+
for (const item of options) {
|
|
16
|
+
const filePath = path_1.default.resolve(item.path);
|
|
17
|
+
let data = await fs_extra_1.default.readFile(filePath, "utf-8");
|
|
18
|
+
for (const token of item.tokens) {
|
|
19
|
+
const regex = new RegExp(token.from, "g");
|
|
20
|
+
data = data.replace(regex, token.to);
|
|
21
|
+
}
|
|
22
|
+
await fs_extra_1.default.writeFile(filePath, data);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
exports.replaceTokensInFiles = replaceTokensInFiles;
|
|
26
|
+
/**
|
|
27
|
+
*
|
|
28
|
+
* @param options -
|
|
29
|
+
*/
|
|
30
|
+
async function replaceTokensInFile(options) {
|
|
31
|
+
await replaceTokensInFiles([options]);
|
|
32
|
+
}
|
|
33
|
+
exports.replaceTokensInFile = replaceTokensInFile;
|
|
34
|
+
/**
|
|
35
|
+
*
|
|
36
|
+
* @param destination -
|
|
37
|
+
* @returns the destination directory path
|
|
38
|
+
*/
|
|
39
|
+
async function getDestinationDir(destination) {
|
|
40
|
+
const destPath = path_1.default.resolve(path_1.default.join(process.cwd(), destination)), destExists = await fs_extra_1.default.pathExists(destPath);
|
|
41
|
+
if (destExists) {
|
|
42
|
+
const destContents = await fs_extra_1.default.readdir(destPath), destContentsNoGit = destContents.filter(t => t !== ".git" && t !== ".gitignore");
|
|
43
|
+
if (destContentsNoGit.length) {
|
|
44
|
+
throw new Error("Destination folder already exists and is not empty");
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
await fs_extra_1.default.ensureDir(destPath);
|
|
48
|
+
return destPath;
|
|
49
|
+
}
|
|
50
|
+
exports.getDestinationDir = getDestinationDir;
|
|
51
|
+
/**
|
|
52
|
+
* @returns the repository URL
|
|
53
|
+
*/
|
|
54
|
+
function getRepositoryUrl() {
|
|
55
|
+
try {
|
|
56
|
+
return (0, child_process_1.execSync)("git config --get remote.origin.url").toString();
|
|
57
|
+
}
|
|
58
|
+
catch {
|
|
59
|
+
return "";
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
exports.getRepositoryUrl = getRepositoryUrl;
|
|
@@ -4,22 +4,28 @@ exports.dash = exports.camelize = exports.capitalize = void 0;
|
|
|
4
4
|
/**
|
|
5
5
|
* This function is used to capitalize a string.
|
|
6
6
|
* @param str - the string to capitalize (e.g. "my-string" -\> "MyString")
|
|
7
|
-
* @param
|
|
7
|
+
* @param splits - the characters used to split the string, if not provided the string will be considered a single word
|
|
8
8
|
* @returns the capitalized string
|
|
9
9
|
*/
|
|
10
|
-
function capitalize(str,
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
function capitalize(str, ...splits) {
|
|
11
|
+
let res = str.replace(/./, c => c.toUpperCase());
|
|
12
|
+
for (const split of splits) {
|
|
13
|
+
res = res
|
|
14
|
+
.split(split)
|
|
15
|
+
.map(w => w.replace(/./, c => c.toUpperCase()))
|
|
16
|
+
.join("");
|
|
17
|
+
}
|
|
18
|
+
return res;
|
|
13
19
|
}
|
|
14
20
|
exports.capitalize = capitalize;
|
|
15
21
|
/**
|
|
16
22
|
* This function is used to camelcase a string.
|
|
17
23
|
* @param str - the string to camelcase (e.g. "my-string" -\> "myString")
|
|
18
|
-
* @param
|
|
24
|
+
* @param splits - the characters used to split the string, if not provided the string will be considered a single word
|
|
19
25
|
* @returns the camelized string
|
|
20
26
|
*/
|
|
21
|
-
function camelize(str,
|
|
22
|
-
return capitalize(str,
|
|
27
|
+
function camelize(str, ...splits) {
|
|
28
|
+
return capitalize(str, ...splits).replace(/./, c => c.toLowerCase());
|
|
23
29
|
}
|
|
24
30
|
exports.camelize = camelize;
|
|
25
31
|
/**
|