@tsparticles/cli 1.1.1 → 1.3.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/README.md +61 -1
- package/dist/build/build-bundle.js +1 -1
- package/dist/build/build-clear.js +1 -1
- package/dist/build/build-distfiles.js +1 -1
- package/dist/build/build-diststats.js +43 -0
- package/dist/build/build-eslint.js +1 -1
- package/dist/build/build-prettier.js +4 -4
- package/dist/build/build-tsc.js +3 -3
- package/dist/build/build.js +11 -1
- package/dist/create/create.js +0 -1
- package/dist/create/preset/create-preset.js +30 -30
- package/dist/create/preset/preset.js +0 -1
- package/dist/utils/string-utils.js +13 -20
- package/dist/utils/template-utils.js +25 -25
- package/files/empty-project/package.json +7 -7
- package/package.json +9 -9
- package/src/build/build-bundle.ts +1 -1
- package/src/build/build-clear.ts +1 -1
- package/src/build/build-distfiles.ts +1 -1
- package/src/build/build-diststats.ts +48 -0
- package/src/build/build-eslint.ts +1 -1
- package/src/build/build-prettier.ts +4 -4
- package/src/build/build-tsc.ts +3 -3
- package/src/build/build.ts +23 -1
- package/src/create/create.ts +0 -1
- package/src/create/preset/create-preset.ts +30 -30
- package/src/create/preset/preset.ts +0 -1
- package/src/utils/string-utils.ts +15 -20
- package/src/utils/template-utils.ts +25 -25
package/README.md
CHANGED
|
@@ -1,3 +1,63 @@
|
|
|
1
1
|
[](https://particles.js.org)
|
|
2
2
|
|
|
3
|
-
# tsParticles
|
|
3
|
+
# tsParticles CLI
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
### NPM
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install -g @particlesjs/cli
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
### Yarn
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
yarn global add @particlesjs/cli
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
### PNPM
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
pnpm global add @particlesjs/cli
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Usage
|
|
26
|
+
|
|
27
|
+
### Help
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
npx @particlesjs/cli --help
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
or
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
tsparticles-cli --help
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### Build
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
npx @particlesjs/cli build
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
or
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
tsparticles-cli build
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### Create
|
|
52
|
+
|
|
53
|
+
#### Preset
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
npx @particlesjs/cli create preset <folder>
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
or
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
tsparticles-cli create preset <folder>
|
|
63
|
+
```
|
|
@@ -30,8 +30,8 @@ exports.bundle = void 0;
|
|
|
30
30
|
const path_1 = __importDefault(require("path"));
|
|
31
31
|
const webpack_1 = __importDefault(require("webpack"));
|
|
32
32
|
/**
|
|
33
|
-
*
|
|
34
33
|
* @param basePath -
|
|
34
|
+
* @returns true if the bundle was created
|
|
35
35
|
*/
|
|
36
36
|
async function bundle(basePath) {
|
|
37
37
|
console.log("Bundling started");
|
|
@@ -7,8 +7,8 @@ exports.clearDist = void 0;
|
|
|
7
7
|
const path_1 = __importDefault(require("path"));
|
|
8
8
|
const rimraf_1 = require("rimraf");
|
|
9
9
|
/**
|
|
10
|
-
*
|
|
11
10
|
* @param basePath -
|
|
11
|
+
* @returns true if the dist folder was cleared
|
|
12
12
|
*/
|
|
13
13
|
async function clearDist(basePath) {
|
|
14
14
|
console.log("Clearing dist folder");
|
|
@@ -31,8 +31,8 @@ const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
|
31
31
|
const klaw_1 = __importDefault(require("klaw"));
|
|
32
32
|
const path_1 = __importDefault(require("path"));
|
|
33
33
|
/**
|
|
34
|
-
*
|
|
35
34
|
* @param basePath -
|
|
35
|
+
* @returns true if the dist files process was successful
|
|
36
36
|
*/
|
|
37
37
|
async function buildDistFiles(basePath) {
|
|
38
38
|
console.log("Build - started on dist files");
|
|
@@ -0,0 +1,43 @@
|
|
|
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.getDistStats = void 0;
|
|
7
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
/**
|
|
10
|
+
* @param folderPath - the path to the folder to get the stats for
|
|
11
|
+
* @returns the given folder stats;
|
|
12
|
+
*/
|
|
13
|
+
async function getFolderStats(folderPath) {
|
|
14
|
+
const stats = {
|
|
15
|
+
totalFiles: 0,
|
|
16
|
+
totalFolders: 0,
|
|
17
|
+
totalSize: 0,
|
|
18
|
+
};
|
|
19
|
+
const dir = await fs_extra_1.default.promises.opendir(folderPath);
|
|
20
|
+
for await (const dirent of dir) {
|
|
21
|
+
if (dirent.isDirectory()) {
|
|
22
|
+
const subDirStats = await getDistStats(path_1.default.join(folderPath, dirent.name));
|
|
23
|
+
stats.totalFolders += subDirStats.totalFolders + 1;
|
|
24
|
+
stats.totalFiles += subDirStats.totalFiles;
|
|
25
|
+
stats.totalSize += subDirStats.totalSize;
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
const fileStats = await fs_extra_1.default.stat(path_1.default.join(folderPath, dirent.name));
|
|
29
|
+
stats.totalFiles++;
|
|
30
|
+
stats.totalSize += fileStats.size;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return stats;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Gets the stats for the dist folder
|
|
37
|
+
* @param basePath - the base path to the project
|
|
38
|
+
* @returns the stats for the dist folder
|
|
39
|
+
*/
|
|
40
|
+
async function getDistStats(basePath) {
|
|
41
|
+
return await getFolderStats(path_1.default.join(basePath, "dist"));
|
|
42
|
+
}
|
|
43
|
+
exports.getDistStats = getDistStats;
|
|
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.lint = void 0;
|
|
4
4
|
const eslint_1 = require("eslint");
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
7
6
|
* @param ci -
|
|
7
|
+
* @returns true if the linting was successful
|
|
8
8
|
*/
|
|
9
9
|
async function lint(ci) {
|
|
10
10
|
console.log("ESLint - started on src");
|
|
@@ -9,10 +9,10 @@ const klaw_1 = __importDefault(require("klaw"));
|
|
|
9
9
|
const path_1 = __importDefault(require("path"));
|
|
10
10
|
const prettier_1 = __importDefault(require("prettier"));
|
|
11
11
|
/**
|
|
12
|
-
*
|
|
13
12
|
* @param basePath -
|
|
14
13
|
* @param srcPath -
|
|
15
14
|
* @param ci -
|
|
15
|
+
* @returns true if the prettify src process was successful
|
|
16
16
|
*/
|
|
17
17
|
async function prettifySrc(basePath, srcPath, ci) {
|
|
18
18
|
console.log("Prettier - started on src");
|
|
@@ -48,9 +48,9 @@ async function prettifySrc(basePath, srcPath, ci) {
|
|
|
48
48
|
}
|
|
49
49
|
exports.prettifySrc = prettifySrc;
|
|
50
50
|
/**
|
|
51
|
-
*
|
|
52
51
|
* @param basePath -
|
|
53
52
|
* @param ci -
|
|
53
|
+
* @returns true if the prettify readme process was successful
|
|
54
54
|
*/
|
|
55
55
|
async function prettifyReadme(basePath, ci) {
|
|
56
56
|
console.log("Prettier - started on README.md");
|
|
@@ -80,9 +80,9 @@ async function prettifyReadme(basePath, ci) {
|
|
|
80
80
|
}
|
|
81
81
|
exports.prettifyReadme = prettifyReadme;
|
|
82
82
|
/**
|
|
83
|
-
*
|
|
84
83
|
* @param basePath -
|
|
85
84
|
* @param ci -
|
|
85
|
+
* @returns true if the prettify traductions process was successful
|
|
86
86
|
*/
|
|
87
87
|
async function prettifyTraductions(basePath, ci) {
|
|
88
88
|
console.log("Prettier - started on traductions");
|
|
@@ -122,9 +122,9 @@ async function prettifyTraductions(basePath, ci) {
|
|
|
122
122
|
return res;
|
|
123
123
|
}
|
|
124
124
|
/**
|
|
125
|
-
*
|
|
126
125
|
* @param basePath -
|
|
127
126
|
* @param ci -
|
|
127
|
+
* @returns true if the prettify markdown typedoc files process was successful
|
|
128
128
|
*/
|
|
129
129
|
async function prettifyMarkdownTypeDocFiles(basePath, ci) {
|
|
130
130
|
console.log("Prettier - started on markdown");
|
package/dist/build/build-tsc.js
CHANGED
|
@@ -8,9 +8,9 @@ const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
|
8
8
|
const path_1 = __importDefault(require("path"));
|
|
9
9
|
const typescript_1 = __importDefault(require("typescript"));
|
|
10
10
|
/**
|
|
11
|
-
*
|
|
12
11
|
* @param basePath -
|
|
13
12
|
* @param file -
|
|
13
|
+
* @returns the file content or undefined if the file doesn't exist
|
|
14
14
|
*/
|
|
15
15
|
async function readConfig(basePath, file) {
|
|
16
16
|
const tsconfigPath = path_1.default.join(basePath, file);
|
|
@@ -21,9 +21,9 @@ async function readConfig(basePath, file) {
|
|
|
21
21
|
return;
|
|
22
22
|
}
|
|
23
23
|
/**
|
|
24
|
-
*
|
|
25
24
|
* @param basePath -
|
|
26
25
|
* @param type -
|
|
26
|
+
* @returns the exit code
|
|
27
27
|
*/
|
|
28
28
|
async function compile(basePath, type) {
|
|
29
29
|
let options, data;
|
|
@@ -124,8 +124,8 @@ async function compile(basePath, type) {
|
|
|
124
124
|
return exitCode;
|
|
125
125
|
}
|
|
126
126
|
/**
|
|
127
|
-
*
|
|
128
127
|
* @param basePath -
|
|
128
|
+
* @returns true if the build was successful
|
|
129
129
|
*/
|
|
130
130
|
async function buildTS(basePath) {
|
|
131
131
|
console.log("Building TS files");
|
package/dist/build/build.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
1
|
"use strict";
|
|
3
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
@@ -12,6 +11,7 @@ const build_tsc_1 = require("./build-tsc");
|
|
|
12
11
|
const build_bundle_1 = require("./build-bundle");
|
|
13
12
|
const build_clear_1 = require("./build-clear");
|
|
14
13
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
14
|
+
const build_diststats_1 = require("./build-diststats");
|
|
15
15
|
const build_eslint_1 = require("./build-eslint");
|
|
16
16
|
const path_1 = __importDefault(require("path"));
|
|
17
17
|
const buildCommand = new commander_1.Command("build");
|
|
@@ -29,6 +29,7 @@ buildCommand.argument("[path]", `Path to the project root folder, default is "sr
|
|
|
29
29
|
buildCommand.action(async (argPath) => {
|
|
30
30
|
const opts = buildCommand.opts(), ci = !!opts.ci, all = !!opts.all, doBundle = all || !!opts.bundle, clean = all || !!opts.clean, distfiles = all || !!opts.dist, doLint = all || !!opts.lint, prettier = all || !!opts.prettify, tsc = all || !!opts.tsc;
|
|
31
31
|
const basePath = process.cwd();
|
|
32
|
+
const oldStats = await (0, build_diststats_1.getDistStats)(path_1.default.join(basePath, "dist"));
|
|
32
33
|
if (clean) {
|
|
33
34
|
await (0, build_clear_1.clearDist)(basePath);
|
|
34
35
|
}
|
|
@@ -58,4 +59,13 @@ buildCommand.action(async (argPath) => {
|
|
|
58
59
|
if (!canContinue) {
|
|
59
60
|
throw new Error("Build failed");
|
|
60
61
|
}
|
|
62
|
+
const newStats = await (0, build_diststats_1.getDistStats)(path_1.default.join(basePath, "dist")), diffSize = newStats.totalSize - oldStats.totalSize, texts = [
|
|
63
|
+
`Size changed from ${oldStats.totalSize} to ${newStats.totalSize} (${diffSize}B)`,
|
|
64
|
+
`Files count changed from ${oldStats.totalFiles} to ${newStats.totalFiles} (${newStats.totalFiles - oldStats.totalFiles})`,
|
|
65
|
+
`Folders count changed from ${oldStats.totalFolders} to ${newStats.totalFolders} (${newStats.totalFolders - oldStats.totalFolders})`,
|
|
66
|
+
], sizeIncreased = diffSize > 0, outputFunc = sizeIncreased ? console.warn : console.info;
|
|
67
|
+
console.log("Build finished successfully!");
|
|
68
|
+
for (const text of texts) {
|
|
69
|
+
outputFunc(text);
|
|
70
|
+
}
|
|
61
71
|
});
|
package/dist/create/create.js
CHANGED
|
@@ -9,51 +9,51 @@ 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
11
|
/**
|
|
12
|
-
*
|
|
13
|
-
* @param destPath -
|
|
14
|
-
* @param name -
|
|
12
|
+
* Updates the bundle file with the correct function name
|
|
13
|
+
* @param destPath - The path where the project is located
|
|
14
|
+
* @param name - The name of the project
|
|
15
15
|
*/
|
|
16
16
|
async function updateBundleFile(destPath, name) {
|
|
17
17
|
const bundlePath = path_1.default.resolve(destPath, "src", "bundle.ts"), bundle = await fs_extra_1.default.readFile(bundlePath, "utf-8"), capitalizedName = (0, string_utils_1.capitalize)((0, string_utils_1.capitalize)(name, "-"), " "), bundleRegex = /loadTemplatePreset/g, replacedText = bundle.replace(bundleRegex, `load${capitalizedName}Preset`);
|
|
18
18
|
await fs_extra_1.default.writeFile(bundlePath, replacedText);
|
|
19
19
|
}
|
|
20
20
|
/**
|
|
21
|
-
*
|
|
22
|
-
* @param destPath -
|
|
23
|
-
* @param name -
|
|
21
|
+
* Updates the index file with the correct function name
|
|
22
|
+
* @param destPath - The path where the project is located
|
|
23
|
+
* @param name - The name of the project
|
|
24
24
|
*/
|
|
25
25
|
async function updateIndexFile(destPath, name) {
|
|
26
26
|
const indexPath = path_1.default.resolve(destPath, "src", "index.ts"), index = await fs_extra_1.default.readFile(indexPath, "utf-8"), capitalizedName = (0, string_utils_1.capitalize)((0, string_utils_1.capitalize)(name, "-"), " "), camelizedName = (0, string_utils_1.camelize)(capitalizedName), indexFunctionRegex = /loadTemplatePreset/g, replacedFuncText = index.replace(indexFunctionRegex, `load${capitalizedName}Preset`), indexNameRegex = /"#template#"/g, replacedNameText = replacedFuncText.replace(indexNameRegex, `"${camelizedName}"`);
|
|
27
27
|
await fs_extra_1.default.writeFile(indexPath, replacedNameText);
|
|
28
28
|
}
|
|
29
29
|
/**
|
|
30
|
-
*
|
|
31
|
-
* @param destPath -
|
|
32
|
-
* @param name -
|
|
33
|
-
* @param description -
|
|
34
|
-
* @param repoUrl -
|
|
30
|
+
* Updates the preset package file
|
|
31
|
+
* @param destPath - The path where the project is located
|
|
32
|
+
* @param name - The name of the project
|
|
33
|
+
* @param description - The description of the project
|
|
34
|
+
* @param repoUrl - The repository url
|
|
35
35
|
*/
|
|
36
36
|
async function updatePresetPackageFile(destPath, name, description, repoUrl) {
|
|
37
37
|
const camelizedName = (0, string_utils_1.camelize)((0, string_utils_1.camelize)(name, "-"), " "), dashedName = (0, string_utils_1.dash)(camelizedName);
|
|
38
38
|
(0, template_utils_1.updatePackageFile)(destPath, `"tsparticles-preset-${dashedName}"`, description, `"tsparticles.preset.${camelizedName}.min.js"`, repoUrl);
|
|
39
39
|
}
|
|
40
40
|
/**
|
|
41
|
-
*
|
|
42
|
-
* @param destPath -
|
|
43
|
-
* @param name -
|
|
44
|
-
* @param description -
|
|
45
|
-
* @param repoUrl -
|
|
41
|
+
* Updates the preset package dist file
|
|
42
|
+
* @param destPath - The path where the project is located
|
|
43
|
+
* @param name - The name of the project
|
|
44
|
+
* @param description - The description of the project
|
|
45
|
+
* @param repoUrl - The repository url
|
|
46
46
|
*/
|
|
47
47
|
async function updatePresetPackageDistFile(destPath, name, description, repoUrl) {
|
|
48
48
|
const camelizedName = (0, string_utils_1.camelize)((0, string_utils_1.camelize)(name, "-"), " "), dashedName = (0, string_utils_1.dash)(camelizedName);
|
|
49
49
|
(0, template_utils_1.updatePackageDistFile)(destPath, `"tsparticles-preset-${dashedName}"`, description, `"tsparticles.preset.${camelizedName}.min.js"`, repoUrl);
|
|
50
50
|
}
|
|
51
51
|
/**
|
|
52
|
-
*
|
|
53
|
-
* @param destPath -
|
|
54
|
-
* @param name -
|
|
55
|
-
* @param description -
|
|
56
|
-
* @param repoUrl -
|
|
52
|
+
* Updates the preset readme file
|
|
53
|
+
* @param destPath - The path where the project is located
|
|
54
|
+
* @param name - The name of the project
|
|
55
|
+
* @param description - The description of the project
|
|
56
|
+
* @param repoUrl - The repository url
|
|
57
57
|
*/
|
|
58
58
|
async function updateReadmeFile(destPath, name, description, repoUrl) {
|
|
59
59
|
const readmePath = path_1.default.resolve(destPath, "README.md"), readme = await fs_extra_1.default.readFile(readmePath, "utf-8"), capitalizedName = (0, string_utils_1.capitalize)((0, string_utils_1.capitalize)(name, "-"), " "), camelizedName = (0, string_utils_1.camelize)(capitalizedName), dashedName = (0, string_utils_1.dash)(camelizedName), readmeDescriptionRegex = /tsParticles Template Preset/g, replacedDescriptionText = readme.replace(readmeDescriptionRegex, `tsParticles ${description} Preset`), readmePackageNameRegex = /tsparticles-preset-template/g, replacedPackageNameText = replacedDescriptionText.replace(readmePackageNameRegex, `tsparticles-preset-${dashedName}`), readmeFileNameRegex = /tsparticles\.preset\.template(\.bundle)?\.min\.js/g, replacedFileNameText = replacedPackageNameText.replace(readmeFileNameRegex, `tsparticles.preset.${camelizedName}$1.min.js`), readmeFunctionNameRegex = /loadTemplatePreset/g, replacedFunctionNameText = replacedFileNameText.replace(readmeFunctionNameRegex, `load${capitalizedName}Preset`), readmeMiniDescriptionRegex = /\[tsParticles\]\(https:\/\/github.com\/matteobruni\/tsparticles\) preset template\./g, replacedMiniDescriptionText = replacedFunctionNameText.replace(readmeMiniDescriptionRegex, `[tsParticles](https://github.com/matteobruni/tsparticles) preset ${name}.`), readmeUsageRegex = /preset: "template"/g, replacedUsageText = replacedMiniDescriptionText.replace(readmeUsageRegex, `preset: "${camelizedName}`), sampleImageRegex = /!\[demo\]\(https:\/\/raw.githubusercontent.com\/tsparticles\/preset-template\/main\/images\/sample.png\)/g, repoPath = repoUrl.includes("github.com")
|
|
@@ -62,20 +62,20 @@ async function updateReadmeFile(destPath, name, description, repoUrl) {
|
|
|
62
62
|
await fs_extra_1.default.writeFile(readmePath, replacedText);
|
|
63
63
|
}
|
|
64
64
|
/**
|
|
65
|
-
*
|
|
66
|
-
* @param destPath -
|
|
67
|
-
* @param name -
|
|
68
|
-
* @param description -
|
|
65
|
+
* Updates the preset webpack file
|
|
66
|
+
* @param destPath - The path where the project is located
|
|
67
|
+
* @param name - The name of the project
|
|
68
|
+
* @param description - The description of the project
|
|
69
69
|
*/
|
|
70
70
|
async function updatePresetWebpackFile(destPath, name, description) {
|
|
71
71
|
await (0, template_utils_1.updateWebpackFile)(destPath, (0, string_utils_1.camelize)((0, string_utils_1.capitalize)((0, string_utils_1.capitalize)(name, "-"), " ")), `tsParticles ${description} Preset`, "loadParticlesPreset");
|
|
72
72
|
}
|
|
73
73
|
/**
|
|
74
|
-
*
|
|
75
|
-
* @param name -
|
|
76
|
-
* @param description -
|
|
77
|
-
* @param repoUrl -
|
|
78
|
-
* @param destPath -
|
|
74
|
+
* Creates the preset project
|
|
75
|
+
* @param name - The name of the project
|
|
76
|
+
* @param description - The description of the project
|
|
77
|
+
* @param repoUrl - The repository url
|
|
78
|
+
* @param destPath - The path where the project is located
|
|
79
79
|
*/
|
|
80
80
|
async function createPresetTemplate(name, description, repoUrl, destPath) {
|
|
81
81
|
const sourcePath = path_1.default.resolve(__dirname, "..", "..", "..", "files", "create-preset");
|
|
@@ -2,40 +2,33 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.dash = exports.camelize = exports.capitalize = void 0;
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
6
|
-
* @param str -
|
|
7
|
-
* @param split -
|
|
5
|
+
* This function is used to capitalize a string.
|
|
6
|
+
* @param str - the string to capitalize (e.g. "my-string" -\> "MyString")
|
|
7
|
+
* @param split - the character 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
10
|
function capitalize(str, split) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
.split(split)
|
|
14
|
-
.map(token => capitalize(token))
|
|
15
|
-
.join("");
|
|
16
|
-
}
|
|
17
|
-
else {
|
|
18
|
-
return str.replace(/./, c => c.toUpperCase());
|
|
19
|
-
}
|
|
11
|
+
const words = split ? str.split(split) : [str];
|
|
12
|
+
return words.map(w => w.replace(/./, c => c.toUpperCase())).join("");
|
|
20
13
|
}
|
|
21
14
|
exports.capitalize = capitalize;
|
|
22
15
|
/**
|
|
23
|
-
*
|
|
24
|
-
* @param str -
|
|
25
|
-
* @param split -
|
|
16
|
+
* This function is used to camelcase a string.
|
|
17
|
+
* @param str - the string to camelcase (e.g. "my-string" -\> "myString")
|
|
18
|
+
* @param split - the character used to split the string, if not provided the string will be considered a single word
|
|
26
19
|
* @returns the camelized string
|
|
27
20
|
*/
|
|
28
21
|
function camelize(str, split) {
|
|
29
|
-
|
|
30
|
-
return capitalized.replace(/./, c => c.toLowerCase());
|
|
22
|
+
return capitalize(str, split).replace(/./, c => c.toLowerCase());
|
|
31
23
|
}
|
|
32
24
|
exports.camelize = camelize;
|
|
33
25
|
/**
|
|
34
|
-
*
|
|
35
|
-
* @param str -
|
|
26
|
+
* This function is used to dash a string.
|
|
27
|
+
* @param str - the string to dash (e.g. "myString" -\> "my-string")
|
|
36
28
|
* @returns the dashed string
|
|
37
29
|
*/
|
|
38
30
|
function dash(str) {
|
|
39
|
-
|
|
31
|
+
const dashed = str.replace(/([A-Z])/g, g => `-${g[0].toLowerCase()}`);
|
|
32
|
+
return dashed.startsWith("-") ? dashed.substring(1) : dashed;
|
|
40
33
|
}
|
|
41
34
|
exports.dash = dash;
|
|
@@ -8,12 +8,12 @@ const child_process_1 = require("child_process");
|
|
|
8
8
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
9
9
|
const path_1 = __importDefault(require("path"));
|
|
10
10
|
/**
|
|
11
|
-
*
|
|
12
|
-
* @param destPath -
|
|
13
|
-
* @param packageName -
|
|
14
|
-
* @param description -
|
|
15
|
-
* @param fileName -
|
|
16
|
-
* @param repoUrl -
|
|
11
|
+
* Updates the package.json file
|
|
12
|
+
* @param destPath - The path where the package.json file is located
|
|
13
|
+
* @param packageName - The name of the package
|
|
14
|
+
* @param description - The description of the package
|
|
15
|
+
* @param fileName - The name of the output file
|
|
16
|
+
* @param repoUrl - The repository URL
|
|
17
17
|
*/
|
|
18
18
|
async function updatePackageFile(destPath, packageName, description, fileName, repoUrl) {
|
|
19
19
|
const packagePath = path_1.default.resolve(destPath, "package.json"), packageContents = await fs_extra_1.default.readFile(packagePath, "utf-8"), descriptionRegex = /"tsParticles empty template"/g, replacedDescriptionText = packageContents.replace(descriptionRegex, `"${description}"`), fileRegex = /"tsparticles.empty.template.min.js"/g, replacedFileText = replacedDescriptionText.replace(fileRegex, fileName), privateRegex = /\s{4}"private": true,\r?\n?/g, replacedPrivateText = replacedFileText.replace(privateRegex, ""), nameRegex = /"@tsparticles\/empty-template"/g, nameReplacedText = replacedPrivateText.replace(nameRegex, packageName), repoUrlRegex = /"url": "git\+https:\/\/github\.com\/tsparticles\/empty-template\.git"/g, repoUrlReplacedText = nameReplacedText.replace(repoUrlRegex, `"url": "git+${repoUrl}"`), issuesUrlRegex = /"url": "https:\/\/github\.com\/tsparticles\/empty-template\/issues"/g, replacedText = repoUrlReplacedText.replace(issuesUrlRegex, `"url": "${repoUrl.replace(".git", "/issues")}"`);
|
|
@@ -21,12 +21,12 @@ async function updatePackageFile(destPath, packageName, description, fileName, r
|
|
|
21
21
|
}
|
|
22
22
|
exports.updatePackageFile = updatePackageFile;
|
|
23
23
|
/**
|
|
24
|
-
*
|
|
25
|
-
* @param destPath -
|
|
26
|
-
* @param packageName -
|
|
27
|
-
* @param description -
|
|
28
|
-
* @param fileName -
|
|
29
|
-
* @param repoUrl -
|
|
24
|
+
* Updates the package.dist.json file with the new project name and description
|
|
25
|
+
* @param destPath - The path where the package.dist.json file is located
|
|
26
|
+
* @param packageName - The name of the package
|
|
27
|
+
* @param description - The description of the package
|
|
28
|
+
* @param fileName - The name of the output file
|
|
29
|
+
* @param repoUrl - The url of the repository
|
|
30
30
|
*/
|
|
31
31
|
async function updatePackageDistFile(destPath, packageName, description, fileName, repoUrl) {
|
|
32
32
|
const packagePath = path_1.default.resolve(destPath, "package.dist.json"), packageContents = await fs_extra_1.default.readFile(packagePath, "utf-8"), descriptionRegex = /"tsParticles empty template"/g, replacedDescriptionText = packageContents.replace(descriptionRegex, `"${description}"`), fileRegex = /"tsparticles.empty.template.min.js"/g, replacedFileText = replacedDescriptionText.replace(fileRegex, fileName), privateRegex = /\s{4}"private": true,\r?\n?/g, replacedPrivateText = replacedFileText.replace(privateRegex, ""), nameRegex = /"@tsparticles\/empty-template"/g, nameReplacedText = replacedPrivateText.replace(nameRegex, packageName), repoUrlRegex = /"url": "git\+https:\/\/github\.com\/tsparticles\/empty-template\.git"/g, repoUrlReplacedText = nameReplacedText.replace(repoUrlRegex, `"url": "git+${repoUrl}"`), issuesUrlRegex = /"url": "https:\/\/github\.com\/tsparticles\/empty-template\/issues"/g, replacedText = repoUrlReplacedText.replace(issuesUrlRegex, `"url": "${repoUrl.replace(".git", "/issues")}"`);
|
|
@@ -34,11 +34,11 @@ async function updatePackageDistFile(destPath, packageName, description, fileNam
|
|
|
34
34
|
}
|
|
35
35
|
exports.updatePackageDistFile = updatePackageDistFile;
|
|
36
36
|
/**
|
|
37
|
-
*
|
|
38
|
-
* @param destPath -
|
|
39
|
-
* @param name -
|
|
40
|
-
* @param description -
|
|
41
|
-
* @param fnName -
|
|
37
|
+
* Updates the webpack file with the new project name and description
|
|
38
|
+
* @param destPath - The path where the project will be created
|
|
39
|
+
* @param name - The name of the project
|
|
40
|
+
* @param description - The description of the project
|
|
41
|
+
* @param fnName - The name of the function to load the template
|
|
42
42
|
*/
|
|
43
43
|
async function updateWebpackFile(destPath, name, description, fnName) {
|
|
44
44
|
const webpackPath = path_1.default.resolve(destPath, "webpack.config.js"), webpack = await fs_extra_1.default.readFile(webpackPath, "utf-8"), webpackDescriptionRegex = /tsParticles Empty Template/g, replacedDescriptionText = webpack.replace(webpackDescriptionRegex, description), webpackEntryRegex = /"template(\.bundle)?"/g, replacedNameText = replacedDescriptionText.replace(webpackEntryRegex, `"${name}$1"`), webpackFunctionNameRegex = /loadParticlesTemplate/g, replacedFunctionNameText = replacedNameText.replace(webpackFunctionNameRegex, fnName);
|
|
@@ -46,8 +46,8 @@ async function updateWebpackFile(destPath, name, description, fnName) {
|
|
|
46
46
|
}
|
|
47
47
|
exports.updateWebpackFile = updateWebpackFile;
|
|
48
48
|
/**
|
|
49
|
-
*
|
|
50
|
-
* @param destPath -
|
|
49
|
+
* Copies the empty template files to the destination path
|
|
50
|
+
* @param destPath - The path where the project will be created
|
|
51
51
|
*/
|
|
52
52
|
async function copyEmptyTemplateFiles(destPath) {
|
|
53
53
|
const emptyPath = path_1.default.resolve(__dirname, "..", "..", "files", "empty-project");
|
|
@@ -58,8 +58,8 @@ async function copyEmptyTemplateFiles(destPath) {
|
|
|
58
58
|
}
|
|
59
59
|
exports.copyEmptyTemplateFiles = copyEmptyTemplateFiles;
|
|
60
60
|
/**
|
|
61
|
-
*
|
|
62
|
-
* @param src -
|
|
61
|
+
* Filters the files to copy
|
|
62
|
+
* @param src - The source file path
|
|
63
63
|
* @returns true if the file should be copied
|
|
64
64
|
*/
|
|
65
65
|
function copyFilter(src) {
|
|
@@ -70,8 +70,8 @@ function copyFilter(src) {
|
|
|
70
70
|
}
|
|
71
71
|
exports.copyFilter = copyFilter;
|
|
72
72
|
/**
|
|
73
|
-
*
|
|
74
|
-
* @param destPath -
|
|
73
|
+
* Runs npm install in the given path
|
|
74
|
+
* @param destPath - The path where the project will be created
|
|
75
75
|
*/
|
|
76
76
|
function runInstall(destPath) {
|
|
77
77
|
(0, child_process_1.execSync)("npm install", {
|
|
@@ -80,8 +80,8 @@ function runInstall(destPath) {
|
|
|
80
80
|
}
|
|
81
81
|
exports.runInstall = runInstall;
|
|
82
82
|
/**
|
|
83
|
-
*
|
|
84
|
-
* @param destPath -
|
|
83
|
+
* Runs npm run build in the given path
|
|
84
|
+
* @param destPath - The path where the project will be build
|
|
85
85
|
*/
|
|
86
86
|
function runBuild(destPath) {
|
|
87
87
|
(0, child_process_1.execSync)("npm run build", {
|
|
@@ -83,14 +83,14 @@
|
|
|
83
83
|
"prettier": "@tsparticles/prettier-config",
|
|
84
84
|
"devDependencies": {
|
|
85
85
|
"@babel/core": "^7.21.4",
|
|
86
|
-
"@tsparticles/cli": "^1.
|
|
87
|
-
"@tsparticles/eslint-config": "^1.
|
|
88
|
-
"@tsparticles/prettier-config": "^1.
|
|
89
|
-
"@tsparticles/tsconfig": "^1.
|
|
90
|
-
"@tsparticles/webpack-plugin": "^1.
|
|
86
|
+
"@tsparticles/cli": "^1.2.0",
|
|
87
|
+
"@tsparticles/eslint-config": "^1.11.0",
|
|
88
|
+
"@tsparticles/prettier-config": "^1.9.0",
|
|
89
|
+
"@tsparticles/tsconfig": "^1.12.0",
|
|
90
|
+
"@tsparticles/webpack-plugin": "^1.13.0",
|
|
91
91
|
"@types/webpack-env": "^1.18.0",
|
|
92
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
93
|
-
"@typescript-eslint/parser": "^5.
|
|
92
|
+
"@typescript-eslint/eslint-plugin": "^5.59.0",
|
|
93
|
+
"@typescript-eslint/parser": "^5.59.0",
|
|
94
94
|
"babel-loader": "^9.1.2",
|
|
95
95
|
"browserslist": "^4.21.5",
|
|
96
96
|
"copyfiles": "^2.4.1",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsparticles/cli",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"bin": {
|
|
6
6
|
"tsparticles-cli": "dist/cli.js"
|
|
@@ -10,16 +10,16 @@
|
|
|
10
10
|
},
|
|
11
11
|
"prettier": "@tsparticles/prettier-config",
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@tsparticles/eslint-config": "^1.
|
|
14
|
-
"@tsparticles/prettier-config": "^1.
|
|
15
|
-
"@tsparticles/tsconfig": "^1.
|
|
16
|
-
"@tsparticles/webpack-plugin": "^1.
|
|
17
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
18
|
-
"@typescript-eslint/parser": "^5.
|
|
19
|
-
"commander": "^10.0.
|
|
13
|
+
"@tsparticles/eslint-config": "^1.11.0",
|
|
14
|
+
"@tsparticles/prettier-config": "^1.9.0",
|
|
15
|
+
"@tsparticles/tsconfig": "^1.12.0",
|
|
16
|
+
"@tsparticles/webpack-plugin": "^1.13.0",
|
|
17
|
+
"@typescript-eslint/eslint-plugin": "^5.59.0",
|
|
18
|
+
"@typescript-eslint/parser": "^5.59.0",
|
|
19
|
+
"commander": "^10.0.1",
|
|
20
20
|
"eslint": "^8.38.0",
|
|
21
21
|
"eslint-config-prettier": "^8.8.0",
|
|
22
|
-
"eslint-plugin-jsdoc": "^
|
|
22
|
+
"eslint-plugin-jsdoc": "^44.0.0",
|
|
23
23
|
"eslint-plugin-tsdoc": "^0.2.17",
|
|
24
24
|
"fs-extra": "^11.1.1",
|
|
25
25
|
"klaw": "^4.1.0",
|
package/src/build/build-clear.ts
CHANGED
|
@@ -3,8 +3,8 @@ import klaw from "klaw";
|
|
|
3
3
|
import path from "path";
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
7
6
|
* @param basePath -
|
|
7
|
+
* @returns true if the dist files process was successful
|
|
8
8
|
*/
|
|
9
9
|
export async function buildDistFiles(basePath: string): Promise<boolean> {
|
|
10
10
|
console.log("Build - started on dist files");
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import fs from "fs-extra";
|
|
2
|
+
import path from "path";
|
|
3
|
+
|
|
4
|
+
export interface IDistStats {
|
|
5
|
+
totalFiles: number;
|
|
6
|
+
totalFolders: number;
|
|
7
|
+
totalSize: number;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @param folderPath - the path to the folder to get the stats for
|
|
12
|
+
* @returns the given folder stats;
|
|
13
|
+
*/
|
|
14
|
+
async function getFolderStats(folderPath: string): Promise<IDistStats> {
|
|
15
|
+
const stats: IDistStats = {
|
|
16
|
+
totalFiles: 0,
|
|
17
|
+
totalFolders: 0,
|
|
18
|
+
totalSize: 0,
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const dir = await fs.promises.opendir(folderPath);
|
|
22
|
+
|
|
23
|
+
for await (const dirent of dir) {
|
|
24
|
+
if (dirent.isDirectory()) {
|
|
25
|
+
const subDirStats = await getDistStats(path.join(folderPath, dirent.name));
|
|
26
|
+
|
|
27
|
+
stats.totalFolders += subDirStats.totalFolders + 1;
|
|
28
|
+
stats.totalFiles += subDirStats.totalFiles;
|
|
29
|
+
stats.totalSize += subDirStats.totalSize;
|
|
30
|
+
} else {
|
|
31
|
+
const fileStats = await fs.stat(path.join(folderPath, dirent.name));
|
|
32
|
+
|
|
33
|
+
stats.totalFiles++;
|
|
34
|
+
stats.totalSize += fileStats.size;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return stats;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Gets the stats for the dist folder
|
|
43
|
+
* @param basePath - the base path to the project
|
|
44
|
+
* @returns the stats for the dist folder
|
|
45
|
+
*/
|
|
46
|
+
export async function getDistStats(basePath: string): Promise<IDistStats> {
|
|
47
|
+
return await getFolderStats(path.join(basePath, "dist"));
|
|
48
|
+
}
|
|
@@ -4,10 +4,10 @@ import path from "path";
|
|
|
4
4
|
import prettier from "prettier";
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
-
*
|
|
8
7
|
* @param basePath -
|
|
9
8
|
* @param srcPath -
|
|
10
9
|
* @param ci -
|
|
10
|
+
* @returns true if the prettify src process was successful
|
|
11
11
|
*/
|
|
12
12
|
export async function prettifySrc(basePath: string, srcPath: string, ci: boolean): Promise<boolean> {
|
|
13
13
|
console.log("Prettier - started on src");
|
|
@@ -52,9 +52,9 @@ export async function prettifySrc(basePath: string, srcPath: string, ci: boolean
|
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
/**
|
|
55
|
-
*
|
|
56
55
|
* @param basePath -
|
|
57
56
|
* @param ci -
|
|
57
|
+
* @returns true if the prettify readme process was successful
|
|
58
58
|
*/
|
|
59
59
|
export async function prettifyReadme(basePath: string, ci: boolean): Promise<boolean> {
|
|
60
60
|
console.log("Prettier - started on README.md");
|
|
@@ -92,9 +92,9 @@ export async function prettifyReadme(basePath: string, ci: boolean): Promise<boo
|
|
|
92
92
|
}
|
|
93
93
|
|
|
94
94
|
/**
|
|
95
|
-
*
|
|
96
95
|
* @param basePath -
|
|
97
96
|
* @param ci -
|
|
97
|
+
* @returns true if the prettify traductions process was successful
|
|
98
98
|
*/
|
|
99
99
|
async function prettifyTraductions(basePath: string, ci: boolean): Promise<boolean> {
|
|
100
100
|
console.log("Prettier - started on traductions");
|
|
@@ -147,9 +147,9 @@ async function prettifyTraductions(basePath: string, ci: boolean): Promise<boole
|
|
|
147
147
|
}
|
|
148
148
|
|
|
149
149
|
/**
|
|
150
|
-
*
|
|
151
150
|
* @param basePath -
|
|
152
151
|
* @param ci -
|
|
152
|
+
* @returns true if the prettify markdown typedoc files process was successful
|
|
153
153
|
*/
|
|
154
154
|
async function prettifyMarkdownTypeDocFiles(basePath: string, ci: boolean): Promise<boolean> {
|
|
155
155
|
console.log("Prettier - started on markdown");
|
package/src/build/build-tsc.ts
CHANGED
|
@@ -3,9 +3,9 @@ import path from "path";
|
|
|
3
3
|
import ts from "typescript";
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
7
6
|
* @param basePath -
|
|
8
7
|
* @param file -
|
|
8
|
+
* @returns the file content or undefined if the file doesn't exist
|
|
9
9
|
*/
|
|
10
10
|
async function readConfig(basePath: string, file: string): Promise<string | undefined> {
|
|
11
11
|
const tsconfigPath = path.join(basePath, file);
|
|
@@ -20,9 +20,9 @@ async function readConfig(basePath: string, file: string): Promise<string | unde
|
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
/**
|
|
23
|
-
*
|
|
24
23
|
* @param basePath -
|
|
25
24
|
* @param type -
|
|
25
|
+
* @returns the exit code
|
|
26
26
|
*/
|
|
27
27
|
async function compile(basePath: string, type: "browser" | "cjs" | "esm" | "types" | "umd"): Promise<number> {
|
|
28
28
|
let options: unknown, data: string | undefined;
|
|
@@ -150,8 +150,8 @@ async function compile(basePath: string, type: "browser" | "cjs" | "esm" | "type
|
|
|
150
150
|
}
|
|
151
151
|
|
|
152
152
|
/**
|
|
153
|
-
*
|
|
154
153
|
* @param basePath -
|
|
154
|
+
* @returns true if the build was successful
|
|
155
155
|
*/
|
|
156
156
|
export async function buildTS(basePath: string): Promise<boolean> {
|
|
157
157
|
console.log("Building TS files");
|
package/src/build/build.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
1
|
import { prettifyReadme, prettifySrc } from "./build-prettier";
|
|
3
2
|
import { Command } from "commander";
|
|
4
3
|
import { buildDistFiles } from "./build-distfiles";
|
|
@@ -6,6 +5,7 @@ import { buildTS } from "./build-tsc";
|
|
|
6
5
|
import { bundle } from "./build-bundle";
|
|
7
6
|
import { clearDist } from "./build-clear";
|
|
8
7
|
import fs from "fs-extra";
|
|
8
|
+
import { getDistStats } from "./build-diststats";
|
|
9
9
|
import { lint } from "./build-eslint";
|
|
10
10
|
import path from "path";
|
|
11
11
|
|
|
@@ -43,6 +43,8 @@ buildCommand.action(async (argPath: string) => {
|
|
|
43
43
|
|
|
44
44
|
const basePath = process.cwd();
|
|
45
45
|
|
|
46
|
+
const oldStats = await getDistStats(path.join(basePath, "dist"));
|
|
47
|
+
|
|
46
48
|
if (clean) {
|
|
47
49
|
await clearDist(basePath);
|
|
48
50
|
}
|
|
@@ -82,6 +84,26 @@ buildCommand.action(async (argPath: string) => {
|
|
|
82
84
|
if (!canContinue) {
|
|
83
85
|
throw new Error("Build failed");
|
|
84
86
|
}
|
|
87
|
+
|
|
88
|
+
const newStats = await getDistStats(path.join(basePath, "dist")),
|
|
89
|
+
diffSize = newStats.totalSize - oldStats.totalSize,
|
|
90
|
+
texts = [
|
|
91
|
+
`Size changed from ${oldStats.totalSize} to ${newStats.totalSize} (${diffSize}B)`,
|
|
92
|
+
`Files count changed from ${oldStats.totalFiles} to ${newStats.totalFiles} (${
|
|
93
|
+
newStats.totalFiles - oldStats.totalFiles
|
|
94
|
+
})`,
|
|
95
|
+
`Folders count changed from ${oldStats.totalFolders} to ${newStats.totalFolders} (${
|
|
96
|
+
newStats.totalFolders - oldStats.totalFolders
|
|
97
|
+
})`,
|
|
98
|
+
],
|
|
99
|
+
sizeIncreased = diffSize > 0,
|
|
100
|
+
outputFunc = sizeIncreased ? console.warn : console.info;
|
|
101
|
+
|
|
102
|
+
console.log("Build finished successfully!");
|
|
103
|
+
|
|
104
|
+
for (const text of texts) {
|
|
105
|
+
outputFunc(text);
|
|
106
|
+
}
|
|
85
107
|
});
|
|
86
108
|
|
|
87
109
|
export { buildCommand };
|
package/src/create/create.ts
CHANGED
|
@@ -12,9 +12,9 @@ import fs from "fs-extra";
|
|
|
12
12
|
import path from "path";
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
|
-
*
|
|
16
|
-
* @param destPath -
|
|
17
|
-
* @param name -
|
|
15
|
+
* Updates the bundle file with the correct function name
|
|
16
|
+
* @param destPath - The path where the project is located
|
|
17
|
+
* @param name - The name of the project
|
|
18
18
|
*/
|
|
19
19
|
async function updateBundleFile(destPath: string, name: string): Promise<void> {
|
|
20
20
|
const bundlePath = path.resolve(destPath, "src", "bundle.ts"),
|
|
@@ -27,9 +27,9 @@ async function updateBundleFile(destPath: string, name: string): Promise<void> {
|
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
/**
|
|
30
|
-
*
|
|
31
|
-
* @param destPath -
|
|
32
|
-
* @param name -
|
|
30
|
+
* Updates the index file with the correct function name
|
|
31
|
+
* @param destPath - The path where the project is located
|
|
32
|
+
* @param name - The name of the project
|
|
33
33
|
*/
|
|
34
34
|
async function updateIndexFile(destPath: string, name: string): Promise<void> {
|
|
35
35
|
const indexPath = path.resolve(destPath, "src", "index.ts"),
|
|
@@ -45,11 +45,11 @@ async function updateIndexFile(destPath: string, name: string): Promise<void> {
|
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
/**
|
|
48
|
-
*
|
|
49
|
-
* @param destPath -
|
|
50
|
-
* @param name -
|
|
51
|
-
* @param description -
|
|
52
|
-
* @param repoUrl -
|
|
48
|
+
* Updates the preset package file
|
|
49
|
+
* @param destPath - The path where the project is located
|
|
50
|
+
* @param name - The name of the project
|
|
51
|
+
* @param description - The description of the project
|
|
52
|
+
* @param repoUrl - The repository url
|
|
53
53
|
*/
|
|
54
54
|
async function updatePresetPackageFile(
|
|
55
55
|
destPath: string,
|
|
@@ -70,11 +70,11 @@ async function updatePresetPackageFile(
|
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
/**
|
|
73
|
-
*
|
|
74
|
-
* @param destPath -
|
|
75
|
-
* @param name -
|
|
76
|
-
* @param description -
|
|
77
|
-
* @param repoUrl -
|
|
73
|
+
* Updates the preset package dist file
|
|
74
|
+
* @param destPath - The path where the project is located
|
|
75
|
+
* @param name - The name of the project
|
|
76
|
+
* @param description - The description of the project
|
|
77
|
+
* @param repoUrl - The repository url
|
|
78
78
|
*/
|
|
79
79
|
async function updatePresetPackageDistFile(
|
|
80
80
|
destPath: string,
|
|
@@ -95,11 +95,11 @@ async function updatePresetPackageDistFile(
|
|
|
95
95
|
}
|
|
96
96
|
|
|
97
97
|
/**
|
|
98
|
-
*
|
|
99
|
-
* @param destPath -
|
|
100
|
-
* @param name -
|
|
101
|
-
* @param description -
|
|
102
|
-
* @param repoUrl -
|
|
98
|
+
* Updates the preset readme file
|
|
99
|
+
* @param destPath - The path where the project is located
|
|
100
|
+
* @param name - The name of the project
|
|
101
|
+
* @param description - The description of the project
|
|
102
|
+
* @param repoUrl - The repository url
|
|
103
103
|
*/
|
|
104
104
|
async function updateReadmeFile(destPath: string, name: string, description: string, repoUrl: string): Promise<void> {
|
|
105
105
|
const readmePath = path.resolve(destPath, "README.md"),
|
|
@@ -146,10 +146,10 @@ async function updateReadmeFile(destPath: string, name: string, description: str
|
|
|
146
146
|
}
|
|
147
147
|
|
|
148
148
|
/**
|
|
149
|
-
*
|
|
150
|
-
* @param destPath -
|
|
151
|
-
* @param name -
|
|
152
|
-
* @param description -
|
|
149
|
+
* Updates the preset webpack file
|
|
150
|
+
* @param destPath - The path where the project is located
|
|
151
|
+
* @param name - The name of the project
|
|
152
|
+
* @param description - The description of the project
|
|
153
153
|
*/
|
|
154
154
|
async function updatePresetWebpackFile(destPath: string, name: string, description: string): Promise<void> {
|
|
155
155
|
await updateWebpackFile(
|
|
@@ -161,11 +161,11 @@ async function updatePresetWebpackFile(destPath: string, name: string, descripti
|
|
|
161
161
|
}
|
|
162
162
|
|
|
163
163
|
/**
|
|
164
|
-
*
|
|
165
|
-
* @param name -
|
|
166
|
-
* @param description -
|
|
167
|
-
* @param repoUrl -
|
|
168
|
-
* @param destPath -
|
|
164
|
+
* Creates the preset project
|
|
165
|
+
* @param name - The name of the project
|
|
166
|
+
* @param description - The description of the project
|
|
167
|
+
* @param repoUrl - The repository url
|
|
168
|
+
* @param destPath - The path where the project is located
|
|
169
169
|
*/
|
|
170
170
|
export async function createPresetTemplate(
|
|
171
171
|
name: string,
|
|
@@ -1,37 +1,32 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* @param str -
|
|
4
|
-
* @param split -
|
|
2
|
+
* This function is used to capitalize a string.
|
|
3
|
+
* @param str - the string to capitalize (e.g. "my-string" -\> "MyString")
|
|
4
|
+
* @param split - the character 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
7
|
export function capitalize(str: string, split?: string): string {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
.map(token => capitalize(token))
|
|
12
|
-
.join("");
|
|
13
|
-
} else {
|
|
14
|
-
return str.replace(/./, c => c.toUpperCase());
|
|
15
|
-
}
|
|
8
|
+
const words = split ? str.split(split) : [str];
|
|
9
|
+
|
|
10
|
+
return words.map(w => w.replace(/./, c => c.toUpperCase())).join("");
|
|
16
11
|
}
|
|
17
12
|
|
|
18
13
|
/**
|
|
19
|
-
*
|
|
20
|
-
* @param str -
|
|
21
|
-
* @param split -
|
|
14
|
+
* This function is used to camelcase a string.
|
|
15
|
+
* @param str - the string to camelcase (e.g. "my-string" -\> "myString")
|
|
16
|
+
* @param split - the character used to split the string, if not provided the string will be considered a single word
|
|
22
17
|
* @returns the camelized string
|
|
23
18
|
*/
|
|
24
19
|
export function camelize(str: string, split?: string): string {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
return capitalized.replace(/./, c => c.toLowerCase());
|
|
20
|
+
return capitalize(str, split).replace(/./, c => c.toLowerCase());
|
|
28
21
|
}
|
|
29
22
|
|
|
30
23
|
/**
|
|
31
|
-
*
|
|
32
|
-
* @param str -
|
|
24
|
+
* This function is used to dash a string.
|
|
25
|
+
* @param str - the string to dash (e.g. "myString" -\> "my-string")
|
|
33
26
|
* @returns the dashed string
|
|
34
27
|
*/
|
|
35
28
|
export function dash(str: string): string {
|
|
36
|
-
|
|
29
|
+
const dashed = str.replace(/([A-Z])/g, g => `-${g[0].toLowerCase()}`);
|
|
30
|
+
|
|
31
|
+
return dashed.startsWith("-") ? dashed.substring(1) : dashed;
|
|
37
32
|
}
|
|
@@ -3,12 +3,12 @@ import fs from "fs-extra";
|
|
|
3
3
|
import path from "path";
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
7
|
-
* @param destPath -
|
|
8
|
-
* @param packageName -
|
|
9
|
-
* @param description -
|
|
10
|
-
* @param fileName -
|
|
11
|
-
* @param repoUrl -
|
|
6
|
+
* Updates the package.json file
|
|
7
|
+
* @param destPath - The path where the package.json file is located
|
|
8
|
+
* @param packageName - The name of the package
|
|
9
|
+
* @param description - The description of the package
|
|
10
|
+
* @param fileName - The name of the output file
|
|
11
|
+
* @param repoUrl - The repository URL
|
|
12
12
|
*/
|
|
13
13
|
export async function updatePackageFile(
|
|
14
14
|
destPath: string,
|
|
@@ -36,12 +36,12 @@ export async function updatePackageFile(
|
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
/**
|
|
39
|
-
*
|
|
40
|
-
* @param destPath -
|
|
41
|
-
* @param packageName -
|
|
42
|
-
* @param description -
|
|
43
|
-
* @param fileName -
|
|
44
|
-
* @param repoUrl -
|
|
39
|
+
* Updates the package.dist.json file with the new project name and description
|
|
40
|
+
* @param destPath - The path where the package.dist.json file is located
|
|
41
|
+
* @param packageName - The name of the package
|
|
42
|
+
* @param description - The description of the package
|
|
43
|
+
* @param fileName - The name of the output file
|
|
44
|
+
* @param repoUrl - The url of the repository
|
|
45
45
|
*/
|
|
46
46
|
export async function updatePackageDistFile(
|
|
47
47
|
destPath: string,
|
|
@@ -69,11 +69,11 @@ export async function updatePackageDistFile(
|
|
|
69
69
|
}
|
|
70
70
|
|
|
71
71
|
/**
|
|
72
|
-
*
|
|
73
|
-
* @param destPath -
|
|
74
|
-
* @param name -
|
|
75
|
-
* @param description -
|
|
76
|
-
* @param fnName -
|
|
72
|
+
* Updates the webpack file with the new project name and description
|
|
73
|
+
* @param destPath - The path where the project will be created
|
|
74
|
+
* @param name - The name of the project
|
|
75
|
+
* @param description - The description of the project
|
|
76
|
+
* @param fnName - The name of the function to load the template
|
|
77
77
|
*/
|
|
78
78
|
export async function updateWebpackFile(
|
|
79
79
|
destPath: string,
|
|
@@ -94,8 +94,8 @@ export async function updateWebpackFile(
|
|
|
94
94
|
}
|
|
95
95
|
|
|
96
96
|
/**
|
|
97
|
-
*
|
|
98
|
-
* @param destPath -
|
|
97
|
+
* Copies the empty template files to the destination path
|
|
98
|
+
* @param destPath - The path where the project will be created
|
|
99
99
|
*/
|
|
100
100
|
export async function copyEmptyTemplateFiles(destPath: string): Promise<void> {
|
|
101
101
|
const emptyPath = path.resolve(__dirname, "..", "..", "files", "empty-project");
|
|
@@ -107,8 +107,8 @@ export async function copyEmptyTemplateFiles(destPath: string): Promise<void> {
|
|
|
107
107
|
}
|
|
108
108
|
|
|
109
109
|
/**
|
|
110
|
-
*
|
|
111
|
-
* @param src -
|
|
110
|
+
* Filters the files to copy
|
|
111
|
+
* @param src - The source file path
|
|
112
112
|
* @returns true if the file should be copied
|
|
113
113
|
*/
|
|
114
114
|
export function copyFilter(src: string): boolean {
|
|
@@ -120,8 +120,8 @@ export function copyFilter(src: string): boolean {
|
|
|
120
120
|
}
|
|
121
121
|
|
|
122
122
|
/**
|
|
123
|
-
*
|
|
124
|
-
* @param destPath -
|
|
123
|
+
* Runs npm install in the given path
|
|
124
|
+
* @param destPath - The path where the project will be created
|
|
125
125
|
*/
|
|
126
126
|
export function runInstall(destPath: string): void {
|
|
127
127
|
execSync("npm install", {
|
|
@@ -130,8 +130,8 @@ export function runInstall(destPath: string): void {
|
|
|
130
130
|
}
|
|
131
131
|
|
|
132
132
|
/**
|
|
133
|
-
*
|
|
134
|
-
* @param destPath -
|
|
133
|
+
* Runs npm run build in the given path
|
|
134
|
+
* @param destPath - The path where the project will be build
|
|
135
135
|
*/
|
|
136
136
|
export function runBuild(destPath: string): void {
|
|
137
137
|
execSync("npm run build", {
|