@tsparticles/cli 3.0.1 → 3.0.2
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 +8 -8
- package/dist/build/build-bundle.js +5 -44
- package/dist/build/build-circular-deps.js +4 -10
- package/dist/build/build-clear.js +4 -10
- package/dist/build/build-distfiles.js +21 -60
- package/dist/build/build-diststats.js +8 -47
- package/dist/build/build-eslint.js +7 -13
- package/dist/build/build-prettier.js +38 -47
- package/dist/build/build-tsc.js +7 -46
- package/dist/build/build.js +13 -49
- package/dist/cli.js +10 -15
- package/dist/create/create.js +9 -12
- package/dist/create/plugin/create-plugin.js +22 -28
- package/dist/create/plugin/plugin.js +12 -18
- package/dist/create/preset/create-preset.js +26 -32
- package/dist/create/preset/preset.js +12 -18
- package/dist/create/shape/create-shape.js +23 -29
- package/dist/create/shape/shape.js +12 -18
- package/dist/utils/file-utils.js +16 -25
- package/dist/utils/string-utils.js +3 -8
- package/dist/utils/template-utils.js +23 -35
- package/eslint.config.js +0 -1
- package/files/empty-project/eslint.config.js +6 -0
- package/files/empty-project/package.dist.json +1 -0
- package/files/empty-project/package.json +2 -1
- package/files/empty-project/webpack.config.js +10 -3
- package/package.json +3 -7
- package/pnpm-workspace.yaml +1 -0
- package/src/tsconfig.json +1 -1
- package/tests/create-plugin.test.ts +4 -5
- package/tests/create-preset.test.ts +4 -5
- package/tests/create-shape.test.ts +4 -5
- package/tests/file-utils.test.ts +8 -9
- package/tests/string-utils.test.ts +24 -25
- package/tests/tsconfig.json +2 -1
- package/vitest.config.ts +11 -0
- package/files/empty-project/.eslintignore +0 -2
- package/files/empty-project/.eslintrc.js +0 -5
package/dist/build/build-tsc.js
CHANGED
|
@@ -1,44 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
-
};
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.buildTS = buildTS;
|
|
40
|
-
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
41
|
-
const path_1 = __importDefault(require("path"));
|
|
1
|
+
import fs from "fs-extra";
|
|
2
|
+
import path from "path";
|
|
42
3
|
var ExitCodes;
|
|
43
4
|
(function (ExitCodes) {
|
|
44
5
|
ExitCodes[ExitCodes["OK"] = 0] = "OK";
|
|
@@ -53,9 +14,9 @@ var ExitCodes;
|
|
|
53
14
|
* @returns the file content or undefined if the file doesn't exist
|
|
54
15
|
*/
|
|
55
16
|
async function readConfig(basePath, file) {
|
|
56
|
-
const tsconfigPath =
|
|
57
|
-
if (await
|
|
58
|
-
const data = await
|
|
17
|
+
const tsconfigPath = path.join(basePath, file);
|
|
18
|
+
if (await fs.pathExists(tsconfigPath)) {
|
|
19
|
+
const data = await fs.readFile(path.join(basePath, file));
|
|
59
20
|
return data.toString();
|
|
60
21
|
}
|
|
61
22
|
}
|
|
@@ -142,7 +103,7 @@ async function compile(basePath, type) {
|
|
|
142
103
|
if (!options) {
|
|
143
104
|
return ExitCodes.NoOptions;
|
|
144
105
|
}
|
|
145
|
-
const ts = await
|
|
106
|
+
const ts = await import("typescript"), parsed = ts.parseJsonConfigFileContent(options, ts.sys, basePath);
|
|
146
107
|
if (parsed.errors.length) {
|
|
147
108
|
return ExitCodes.ParseError;
|
|
148
109
|
}
|
|
@@ -166,7 +127,7 @@ async function compile(basePath, type) {
|
|
|
166
127
|
* @param basePath -
|
|
167
128
|
* @returns true if the build was successful
|
|
168
129
|
*/
|
|
169
|
-
async function buildTS(basePath) {
|
|
130
|
+
export async function buildTS(basePath) {
|
|
170
131
|
console.log("Building TS files");
|
|
171
132
|
let res = true;
|
|
172
133
|
const types = ["browser", "cjs", "esm", "types", "umd"];
|
package/dist/build/build.js
CHANGED
|
@@ -1,42 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.buildCommand = void 0;
|
|
37
|
-
const commander_1 = require("commander");
|
|
38
|
-
const buildCommand = new commander_1.Command("build");
|
|
39
|
-
exports.buildCommand = buildCommand;
|
|
1
|
+
import { Command } from "commander";
|
|
2
|
+
const buildCommand = new Command("build");
|
|
40
3
|
buildCommand.description("Build the tsParticles library using TypeScript");
|
|
41
4
|
buildCommand.option("-a, --all", "Do all build steps (default if no flags are specified) (same as -b -c -d -l -p -t)", false);
|
|
42
5
|
buildCommand.option("-b, --bundle", "Bundle the library using Webpack", false);
|
|
@@ -50,45 +13,45 @@ buildCommand.option("-t, --tsc", "Build the library using TypeScript", false);
|
|
|
50
13
|
buildCommand.argument("[path]", `Path to the project root folder, default is "src"`, "src");
|
|
51
14
|
buildCommand.action(async (argPath) => {
|
|
52
15
|
const opts = buildCommand.opts(), ci = !!opts.ci, all = !!opts.all || (!opts.bundle && !opts.clean && !opts.dist && !opts.lint && !opts.prettify && !opts.tsc), doBundle = all || !!opts.bundle, circularDeps = all || !!opts.circularDeps, clean = all || !!opts.clean, distfiles = all || !!opts.dist, doLint = all || !!opts.lint, prettier = all || !!opts.prettify, tsc = all || !!opts.tsc;
|
|
53
|
-
const basePath = process.cwd(), { getDistStats } = await
|
|
16
|
+
const basePath = process.cwd(), { getDistStats } = await import("./build-diststats.js"), oldStats = await getDistStats(basePath);
|
|
54
17
|
if (clean) {
|
|
55
|
-
const { clearDist } = await
|
|
18
|
+
const { clearDist } = await import("./build-clear.js");
|
|
56
19
|
await clearDist(basePath);
|
|
57
20
|
}
|
|
58
|
-
const path = await
|
|
21
|
+
const path = await import("path"), srcPath = path.join(basePath, argPath), fs = await import("fs-extra");
|
|
59
22
|
if (!(await fs.pathExists(srcPath))) {
|
|
60
23
|
throw new Error("Provided path does not exist");
|
|
61
24
|
}
|
|
62
25
|
let canContinue = true;
|
|
63
26
|
if (prettier) {
|
|
64
|
-
const { prettifySrc } = await
|
|
27
|
+
const { prettifySrc } = await import("./build-prettier.js");
|
|
65
28
|
canContinue = await prettifySrc(basePath, srcPath, ci);
|
|
66
29
|
}
|
|
67
30
|
if (canContinue && doLint) {
|
|
68
|
-
const { lint } = await
|
|
31
|
+
const { lint } = await import("./build-eslint.js");
|
|
69
32
|
canContinue = await lint(ci);
|
|
70
33
|
}
|
|
71
34
|
if (canContinue && tsc) {
|
|
72
|
-
const { buildTS } = await
|
|
35
|
+
const { buildTS } = await import("./build-tsc.js");
|
|
73
36
|
canContinue = await buildTS(basePath);
|
|
74
37
|
}
|
|
75
38
|
if (canContinue && circularDeps) {
|
|
76
|
-
const { buildCircularDeps } = await
|
|
39
|
+
const { buildCircularDeps } = await import("./build-circular-deps.js");
|
|
77
40
|
canContinue = await buildCircularDeps(basePath);
|
|
78
41
|
}
|
|
79
42
|
if (canContinue && doBundle) {
|
|
80
|
-
const { bundle } = await
|
|
43
|
+
const { bundle } = await import("./build-bundle.js");
|
|
81
44
|
canContinue = await bundle(basePath);
|
|
82
45
|
}
|
|
83
46
|
if (canContinue && prettier) {
|
|
84
|
-
const { prettifyReadme, prettifyPackageJson, prettifyPackageDistJson } = await
|
|
47
|
+
const { prettifyReadme, prettifyPackageJson, prettifyPackageDistJson } = await import("./build-prettier.js");
|
|
85
48
|
canContinue =
|
|
86
49
|
(await prettifyReadme(basePath, ci)) &&
|
|
87
50
|
(await prettifyPackageJson(basePath, ci)) &&
|
|
88
51
|
(await prettifyPackageDistJson(basePath, ci));
|
|
89
52
|
}
|
|
90
53
|
if (canContinue && distfiles) {
|
|
91
|
-
const { buildDistFiles } = await
|
|
54
|
+
const { buildDistFiles } = await import("./build-distfiles.js");
|
|
92
55
|
canContinue = await buildDistFiles(basePath);
|
|
93
56
|
}
|
|
94
57
|
if (!canContinue) {
|
|
@@ -109,3 +72,4 @@ buildCommand.action(async (argPath) => {
|
|
|
109
72
|
outputFunc(text);
|
|
110
73
|
}
|
|
111
74
|
});
|
|
75
|
+
export { buildCommand };
|
package/dist/cli.js
CHANGED
|
@@ -1,16 +1,11 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
};
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
commander_1.program.description("tsParticles CLI");
|
|
13
|
-
commander_1.program.version(package_json_1.default.version, "-v, --version", "output the current version");
|
|
14
|
-
commander_1.program.addCommand(build_1.buildCommand);
|
|
15
|
-
commander_1.program.addCommand(create_1.createCommand);
|
|
16
|
-
commander_1.program.parse(process.argv);
|
|
2
|
+
import { buildCommand } from "./build/build";
|
|
3
|
+
import { createCommand } from "./create/create";
|
|
4
|
+
import pkgInfo from "../package.json";
|
|
5
|
+
import { program } from "commander";
|
|
6
|
+
program.name("tsparticles-cli");
|
|
7
|
+
program.description("tsParticles CLI");
|
|
8
|
+
program.version(pkgInfo.version, "-v, --version", "output the current version");
|
|
9
|
+
program.addCommand(buildCommand);
|
|
10
|
+
program.addCommand(createCommand);
|
|
11
|
+
program.parse(process.argv);
|
package/dist/create/create.js
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
const preset_1 = require("./preset/preset");
|
|
7
|
-
const shape_1 = require("./shape/shape");
|
|
8
|
-
const createCommand = new commander_1.Command("create");
|
|
9
|
-
exports.createCommand = createCommand;
|
|
1
|
+
import { Command } from "commander";
|
|
2
|
+
import { pluginCommand } from "./plugin/plugin";
|
|
3
|
+
import { presetCommand } from "./preset/preset";
|
|
4
|
+
import { shapeCommand } from "./shape/shape";
|
|
5
|
+
const createCommand = new Command("create");
|
|
10
6
|
createCommand.description("Create a new tsParticles project");
|
|
11
|
-
createCommand.addCommand(
|
|
12
|
-
createCommand.addCommand(
|
|
13
|
-
createCommand.addCommand(
|
|
7
|
+
createCommand.addCommand(pluginCommand);
|
|
8
|
+
createCommand.addCommand(presetCommand);
|
|
9
|
+
createCommand.addCommand(shapeCommand);
|
|
10
|
+
export { createCommand };
|
|
@@ -1,23 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
exports.createPluginTemplate = createPluginTemplate;
|
|
7
|
-
const string_utils_1 = require("../../utils/string-utils");
|
|
8
|
-
const template_utils_1 = require("../../utils/template-utils");
|
|
9
|
-
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
10
|
-
const path_1 = __importDefault(require("path"));
|
|
11
|
-
const file_utils_1 = require("../../utils/file-utils");
|
|
1
|
+
import { camelize, capitalize, dash } from "../../utils/string-utils";
|
|
2
|
+
import { copyEmptyTemplateFiles, copyFilter, runBuild, runInstall, updatePackageDistFile, updatePackageFile, updateWebpackFile, } from "../../utils/template-utils";
|
|
3
|
+
import fs from "fs-extra";
|
|
4
|
+
import path from "path";
|
|
5
|
+
import { replaceTokensInFile } from "../../utils/file-utils";
|
|
12
6
|
/**
|
|
13
7
|
* Updates the index file with the correct function name
|
|
14
8
|
* @param destPath - The path where the project is located
|
|
15
9
|
* @param name - The name of the project
|
|
16
10
|
*/
|
|
17
11
|
async function updateIndexFile(destPath, name) {
|
|
18
|
-
const capitalizedName =
|
|
19
|
-
await
|
|
20
|
-
path:
|
|
12
|
+
const capitalizedName = capitalize(name, "-", " "), camelizedName = camelize(capitalizedName);
|
|
13
|
+
await replaceTokensInFile({
|
|
14
|
+
path: path.resolve(destPath, "src", "index.ts"),
|
|
21
15
|
tokens: [
|
|
22
16
|
{
|
|
23
17
|
from: /loadTemplatePlugin/g,
|
|
@@ -38,8 +32,8 @@ async function updateIndexFile(destPath, name) {
|
|
|
38
32
|
* @param repoUrl - The repository url
|
|
39
33
|
*/
|
|
40
34
|
async function updatePluginPackageFile(destPath, name, description, repoUrl) {
|
|
41
|
-
const camelizedName =
|
|
42
|
-
await
|
|
35
|
+
const camelizedName = camelize(camelize(name, "-"), " "), dashedName = dash(camelizedName);
|
|
36
|
+
await updatePackageFile(destPath, `tsparticles-plugin-${dashedName}`, description, `tsparticles.plugin.${camelizedName}.min.js`, repoUrl);
|
|
43
37
|
}
|
|
44
38
|
/**
|
|
45
39
|
* Updates the plugin package dist file
|
|
@@ -49,8 +43,8 @@ async function updatePluginPackageFile(destPath, name, description, repoUrl) {
|
|
|
49
43
|
* @param repoUrl - The repository url
|
|
50
44
|
*/
|
|
51
45
|
async function updatePluginPackageDistFile(destPath, name, description, repoUrl) {
|
|
52
|
-
const camelizedName =
|
|
53
|
-
await
|
|
46
|
+
const camelizedName = camelize(camelize(name, "-"), " "), dashedName = dash(camelizedName);
|
|
47
|
+
await updatePackageDistFile(destPath, `tsparticles-plugin-${dashedName}`, description, `tsparticles.plugin.${camelizedName}.min.js`, repoUrl);
|
|
54
48
|
}
|
|
55
49
|
/**
|
|
56
50
|
* Updates the plugin readme file
|
|
@@ -60,10 +54,10 @@ async function updatePluginPackageDistFile(destPath, name, description, repoUrl)
|
|
|
60
54
|
* @param repoUrl - The repository url
|
|
61
55
|
*/
|
|
62
56
|
async function updateReadmeFile(destPath, name, description, repoUrl) {
|
|
63
|
-
const readmePath =
|
|
57
|
+
const readmePath = path.resolve(destPath, "README.md"), capitalizedName = capitalize(name, "-", " "), camelizedName = camelize(capitalizedName), dashedName = dash(camelizedName), stringSearch = "github.com", trailingSlashSearch = "github.com/", repoPath = repoUrl.includes(stringSearch)
|
|
64
58
|
? repoUrl.substring(repoUrl.indexOf(trailingSlashSearch) + trailingSlashSearch.length, repoUrl.indexOf(".git"))
|
|
65
59
|
: "tsparticles/plugin-template";
|
|
66
|
-
await
|
|
60
|
+
await replaceTokensInFile({
|
|
67
61
|
path: readmePath,
|
|
68
62
|
tokens: [
|
|
69
63
|
{
|
|
@@ -104,7 +98,7 @@ async function updateReadmeFile(destPath, name, description, repoUrl) {
|
|
|
104
98
|
* @param description - The description of the project
|
|
105
99
|
*/
|
|
106
100
|
async function updatePluginWebpackFile(destPath, name, description) {
|
|
107
|
-
await
|
|
101
|
+
await updateWebpackFile(destPath, camelize(capitalize(name, "-", " ")), description, "loadParticlesPlugin");
|
|
108
102
|
}
|
|
109
103
|
/**
|
|
110
104
|
* Creates the plugin project
|
|
@@ -113,18 +107,18 @@ async function updatePluginWebpackFile(destPath, name, description) {
|
|
|
113
107
|
* @param repoUrl - The repository url
|
|
114
108
|
* @param destPath - The path where the project is located
|
|
115
109
|
*/
|
|
116
|
-
async function createPluginTemplate(name, description, repoUrl, destPath) {
|
|
117
|
-
const sourcePath =
|
|
118
|
-
await
|
|
119
|
-
await
|
|
110
|
+
export async function createPluginTemplate(name, description, repoUrl, destPath) {
|
|
111
|
+
const sourcePath = path.resolve(__dirname, "..", "..", "..", "files", "create-plugin");
|
|
112
|
+
await copyEmptyTemplateFiles(destPath);
|
|
113
|
+
await fs.copy(sourcePath, destPath, {
|
|
120
114
|
overwrite: true,
|
|
121
|
-
filter:
|
|
115
|
+
filter: copyFilter,
|
|
122
116
|
});
|
|
123
117
|
await updateIndexFile(destPath, name);
|
|
124
118
|
await updatePluginPackageFile(destPath, name, description, repoUrl);
|
|
125
119
|
await updatePluginPackageDistFile(destPath, name, description, repoUrl);
|
|
126
120
|
await updateReadmeFile(destPath, name, description, repoUrl);
|
|
127
121
|
await updatePluginWebpackFile(destPath, name, description);
|
|
128
|
-
await
|
|
129
|
-
await
|
|
122
|
+
await runInstall(destPath);
|
|
123
|
+
await runBuild(destPath);
|
|
130
124
|
}
|
|
@@ -1,21 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
const prompts_1 = __importDefault(require("prompts"));
|
|
9
|
-
const commander_1 = require("commander");
|
|
10
|
-
const string_utils_1 = require("../../utils/string-utils");
|
|
11
|
-
const create_plugin_1 = require("./create-plugin");
|
|
12
|
-
const path_1 = __importDefault(require("path"));
|
|
13
|
-
const pluginCommand = new commander_1.Command("plugin");
|
|
14
|
-
exports.pluginCommand = pluginCommand;
|
|
1
|
+
import { getDestinationDir, getRepositoryUrl } from "../../utils/file-utils";
|
|
2
|
+
import prompts from "prompts";
|
|
3
|
+
import { Command } from "commander";
|
|
4
|
+
import { capitalize } from "../../utils/string-utils";
|
|
5
|
+
import { createPluginTemplate } from "./create-plugin";
|
|
6
|
+
import path from "path";
|
|
7
|
+
const pluginCommand = new Command("plugin");
|
|
15
8
|
pluginCommand.description("Create a new tsParticles plugin");
|
|
16
9
|
pluginCommand.argument("<destination>", "Destination folder");
|
|
17
10
|
pluginCommand.action(async (destination) => {
|
|
18
|
-
const destPath = await
|
|
11
|
+
const destPath = await getDestinationDir(destination), repoUrl = await getRepositoryUrl(), initialName = destPath.split(path.sep).pop(), questions = [
|
|
19
12
|
{
|
|
20
13
|
type: "text",
|
|
21
14
|
name: "name",
|
|
@@ -28,7 +21,7 @@ pluginCommand.action(async (destination) => {
|
|
|
28
21
|
name: "description",
|
|
29
22
|
message: "What is the description of the plugin?",
|
|
30
23
|
validate: (value) => (value ? true : "The description can't be empty"),
|
|
31
|
-
initial:
|
|
24
|
+
initial: capitalize(initialName ?? ""),
|
|
32
25
|
},
|
|
33
26
|
{
|
|
34
27
|
type: "text",
|
|
@@ -36,6 +29,7 @@ pluginCommand.action(async (destination) => {
|
|
|
36
29
|
message: "What is the repository URL? (optional)",
|
|
37
30
|
initial: repoUrl.trim(),
|
|
38
31
|
},
|
|
39
|
-
], { name, description, repositoryUrl } = (await (
|
|
40
|
-
await
|
|
32
|
+
], { name, description, repositoryUrl } = (await prompts(questions));
|
|
33
|
+
await createPluginTemplate(name.trim(), description.trim(), repositoryUrl.trim(), destPath);
|
|
41
34
|
});
|
|
35
|
+
export { pluginCommand };
|
|
@@ -1,23 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
exports.createPresetTemplate = createPresetTemplate;
|
|
7
|
-
const string_utils_1 = require("../../utils/string-utils");
|
|
8
|
-
const template_utils_1 = require("../../utils/template-utils");
|
|
9
|
-
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
10
|
-
const path_1 = __importDefault(require("path"));
|
|
11
|
-
const file_utils_1 = require("../../utils/file-utils");
|
|
1
|
+
import { camelize, capitalize, dash } from "../../utils/string-utils";
|
|
2
|
+
import { copyEmptyTemplateFiles, copyFilter, runBuild, runInstall, updatePackageDistFile, updatePackageFile, updateWebpackFile, } from "../../utils/template-utils";
|
|
3
|
+
import fs from "fs-extra";
|
|
4
|
+
import path from "path";
|
|
5
|
+
import { replaceTokensInFile } from "../../utils/file-utils";
|
|
12
6
|
/**
|
|
13
7
|
* Updates the bundle file with the correct function name
|
|
14
8
|
* @param destPath - The path where the project is located
|
|
15
9
|
* @param name - The name of the project
|
|
16
10
|
*/
|
|
17
11
|
async function updateBundleFile(destPath, name) {
|
|
18
|
-
const capitalizedName =
|
|
19
|
-
await
|
|
20
|
-
path:
|
|
12
|
+
const capitalizedName = capitalize(name, "-", " ");
|
|
13
|
+
await replaceTokensInFile({
|
|
14
|
+
path: path.resolve(destPath, "src", "bundle.ts"),
|
|
21
15
|
tokens: [
|
|
22
16
|
{
|
|
23
17
|
from: /loadTemplatePreset/g,
|
|
@@ -32,9 +26,9 @@ async function updateBundleFile(destPath, name) {
|
|
|
32
26
|
* @param name - The name of the project
|
|
33
27
|
*/
|
|
34
28
|
async function updateIndexFile(destPath, name) {
|
|
35
|
-
const capitalizedName =
|
|
36
|
-
await
|
|
37
|
-
path:
|
|
29
|
+
const capitalizedName = capitalize(name, "-", " "), camelizedName = camelize(capitalizedName);
|
|
30
|
+
await replaceTokensInFile({
|
|
31
|
+
path: path.resolve(destPath, "src", "index.ts"),
|
|
38
32
|
tokens: [
|
|
39
33
|
{
|
|
40
34
|
from: /loadTemplatePreset/g,
|
|
@@ -55,8 +49,8 @@ async function updateIndexFile(destPath, name) {
|
|
|
55
49
|
* @param repoUrl - The repository url
|
|
56
50
|
*/
|
|
57
51
|
async function updatePresetPackageFile(destPath, name, description, repoUrl) {
|
|
58
|
-
const camelizedName =
|
|
59
|
-
await
|
|
52
|
+
const camelizedName = camelize(name, "-", " "), dashedName = dash(camelizedName);
|
|
53
|
+
await updatePackageFile(destPath, `tsparticles-preset-${dashedName}`, description, `tsparticles.preset.${camelizedName}.min.js`, repoUrl);
|
|
60
54
|
}
|
|
61
55
|
/**
|
|
62
56
|
* Updates the preset package dist file
|
|
@@ -66,8 +60,8 @@ async function updatePresetPackageFile(destPath, name, description, repoUrl) {
|
|
|
66
60
|
* @param repoUrl - The repository url
|
|
67
61
|
*/
|
|
68
62
|
async function updatePresetPackageDistFile(destPath, name, description, repoUrl) {
|
|
69
|
-
const camelizedName =
|
|
70
|
-
await
|
|
63
|
+
const camelizedName = camelize(name, "-", " "), dashedName = dash(camelizedName);
|
|
64
|
+
await updatePackageDistFile(destPath, `tsparticles-preset-${dashedName}`, description, `tsparticles.preset.${camelizedName}.min.js`, repoUrl);
|
|
71
65
|
}
|
|
72
66
|
/**
|
|
73
67
|
* Updates the preset readme file
|
|
@@ -77,11 +71,11 @@ async function updatePresetPackageDistFile(destPath, name, description, repoUrl)
|
|
|
77
71
|
* @param repoUrl - The repository url
|
|
78
72
|
*/
|
|
79
73
|
async function updateReadmeFile(destPath, name, description, repoUrl) {
|
|
80
|
-
const capitalizedName =
|
|
74
|
+
const capitalizedName = capitalize(name, "-", " "), camelizedName = camelize(capitalizedName), dashedName = dash(camelizedName), stringSearch = "github.com", trailingSlashSearch = "github.com/", repoPath = repoUrl.includes(stringSearch)
|
|
81
75
|
? repoUrl.substring(repoUrl.indexOf(trailingSlashSearch) + trailingSlashSearch.length, repoUrl.indexOf(".git"))
|
|
82
76
|
: "tsparticles/preset-template";
|
|
83
|
-
await
|
|
84
|
-
path:
|
|
77
|
+
await replaceTokensInFile({
|
|
78
|
+
path: path.resolve(destPath, "README.md"),
|
|
85
79
|
tokens: [
|
|
86
80
|
{
|
|
87
81
|
from: /tsParticles Template Preset/g,
|
|
@@ -121,7 +115,7 @@ async function updateReadmeFile(destPath, name, description, repoUrl) {
|
|
|
121
115
|
* @param description - The description of the project
|
|
122
116
|
*/
|
|
123
117
|
async function updatePresetWebpackFile(destPath, name, description) {
|
|
124
|
-
await
|
|
118
|
+
await updateWebpackFile(destPath, camelize(capitalize(name, "-", " ")), description, "loadParticlesPreset");
|
|
125
119
|
}
|
|
126
120
|
/**
|
|
127
121
|
* Creates the preset project
|
|
@@ -130,12 +124,12 @@ async function updatePresetWebpackFile(destPath, name, description) {
|
|
|
130
124
|
* @param repoUrl - The repository url
|
|
131
125
|
* @param destPath - The path where the project is located
|
|
132
126
|
*/
|
|
133
|
-
async function createPresetTemplate(name, description, repoUrl, destPath) {
|
|
134
|
-
const sourcePath =
|
|
135
|
-
await
|
|
136
|
-
await
|
|
127
|
+
export async function createPresetTemplate(name, description, repoUrl, destPath) {
|
|
128
|
+
const sourcePath = path.resolve(__dirname, "..", "..", "..", "files", "create-preset");
|
|
129
|
+
await copyEmptyTemplateFiles(destPath);
|
|
130
|
+
await fs.copy(sourcePath, destPath, {
|
|
137
131
|
overwrite: true,
|
|
138
|
-
filter:
|
|
132
|
+
filter: copyFilter,
|
|
139
133
|
});
|
|
140
134
|
await updateBundleFile(destPath, name);
|
|
141
135
|
await updateIndexFile(destPath, name);
|
|
@@ -143,6 +137,6 @@ async function createPresetTemplate(name, description, repoUrl, destPath) {
|
|
|
143
137
|
await updatePresetPackageDistFile(destPath, name, description, repoUrl);
|
|
144
138
|
await updateReadmeFile(destPath, name, description, repoUrl);
|
|
145
139
|
await updatePresetWebpackFile(destPath, name, description);
|
|
146
|
-
await
|
|
147
|
-
await
|
|
140
|
+
await runInstall(destPath);
|
|
141
|
+
await runBuild(destPath);
|
|
148
142
|
}
|
|
@@ -1,21 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
const prompts_1 = __importDefault(require("prompts"));
|
|
9
|
-
const commander_1 = require("commander");
|
|
10
|
-
const string_utils_1 = require("../../utils/string-utils");
|
|
11
|
-
const create_preset_1 = require("./create-preset");
|
|
12
|
-
const path_1 = __importDefault(require("path"));
|
|
13
|
-
const presetCommand = new commander_1.Command("preset");
|
|
14
|
-
exports.presetCommand = presetCommand;
|
|
1
|
+
import { getDestinationDir, getRepositoryUrl } from "../../utils/file-utils";
|
|
2
|
+
import prompts from "prompts";
|
|
3
|
+
import { Command } from "commander";
|
|
4
|
+
import { capitalize } from "../../utils/string-utils";
|
|
5
|
+
import { createPresetTemplate } from "./create-preset";
|
|
6
|
+
import path from "path";
|
|
7
|
+
const presetCommand = new Command("preset");
|
|
15
8
|
presetCommand.description("Create a new tsParticles preset");
|
|
16
9
|
presetCommand.argument("<destination>", "Destination folder");
|
|
17
10
|
presetCommand.action(async (destination) => {
|
|
18
|
-
const destPath = await
|
|
11
|
+
const destPath = await getDestinationDir(destination), repoUrl = await getRepositoryUrl(), initialName = destPath.split(path.sep).pop(), questions = [
|
|
19
12
|
{
|
|
20
13
|
type: "text",
|
|
21
14
|
name: "name",
|
|
@@ -28,7 +21,7 @@ presetCommand.action(async (destination) => {
|
|
|
28
21
|
name: "description",
|
|
29
22
|
message: "What is the description of the preset?",
|
|
30
23
|
validate: (value) => (value ? true : "The description can't be empty"),
|
|
31
|
-
initial:
|
|
24
|
+
initial: capitalize(initialName ?? ""),
|
|
32
25
|
},
|
|
33
26
|
{
|
|
34
27
|
type: "text",
|
|
@@ -36,6 +29,7 @@ presetCommand.action(async (destination) => {
|
|
|
36
29
|
message: "What is the repository URL? (optional)",
|
|
37
30
|
initial: repoUrl.trim(),
|
|
38
31
|
},
|
|
39
|
-
], { name, description, repositoryUrl } = (await (
|
|
40
|
-
await
|
|
32
|
+
], { name, description, repositoryUrl } = (await prompts(questions));
|
|
33
|
+
await createPresetTemplate(name.trim(), description.trim(), repositoryUrl.trim(), destPath);
|
|
41
34
|
});
|
|
35
|
+
export { presetCommand };
|