@tsparticles/cli 2.0.0-beta.8 → 2.0.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 +4 -4
- package/dist/create/plugin/create-plugin.js +2 -2
- package/dist/create/plugin/plugin.js +1 -1
- package/dist/create/preset/create-preset.js +2 -2
- package/dist/create/preset/preset.js +1 -1
- package/dist/create/shape/create-shape.js +2 -2
- package/dist/create/shape/shape.js +1 -1
- package/dist/utils/file-utils.js +12 -5
- package/dist/utils/template-utils.js +29 -6
- package/files/create-plugin/README.md +2 -2
- package/files/create-plugin/src/PluginInstance.ts +1 -1
- package/files/create-plugin/src/index.ts +1 -1
- package/files/create-preset/README.md +2 -2
- package/files/create-preset/src/bundle.ts +1 -1
- package/files/create-preset/src/index.ts +1 -1
- package/files/create-preset/src/options.ts +1 -1
- package/files/create-shape/README.md +2 -2
- package/files/create-shape/src/ShapeDrawer.ts +3 -8
- package/files/create-shape/src/index.ts +1 -1
- package/files/empty-project/package.dist.json +1 -1
- package/files/empty-project/package.json +17 -17
- package/package.json +23 -21
- package/src/create/plugin/create-plugin.ts +2 -2
- package/src/create/plugin/plugin.ts +1 -1
- package/src/create/preset/create-preset.ts +2 -2
- package/src/create/preset/preset.ts +1 -1
- package/src/create/shape/create-shape.ts +2 -2
- package/src/create/shape/shape.ts +1 -1
- package/src/utils/file-utils.ts +16 -5
- package/src/utils/template-utils.ts +44 -7
- package/tests/file-utils.test.ts +2 -2
|
@@ -43,8 +43,8 @@ jobs:
|
|
|
43
43
|
restore-keys: |
|
|
44
44
|
${{ runner.os }}-pnpm-store-
|
|
45
45
|
- run: pnpm install --no-frozen-lockfile
|
|
46
|
-
- run:
|
|
47
|
-
- run:
|
|
46
|
+
- run: pnpm run build:ci
|
|
47
|
+
- run: pnpm test
|
|
48
48
|
pr:
|
|
49
49
|
runs-on: ubuntu-latest
|
|
50
50
|
if: ${{ github.event_name == 'pull_request' }}
|
|
@@ -81,5 +81,5 @@ jobs:
|
|
|
81
81
|
restore-keys: |
|
|
82
82
|
${{ runner.os }}-pnpm-store-
|
|
83
83
|
- run: pnpm install --no-frozen-lockfile
|
|
84
|
-
- run:
|
|
85
|
-
- run:
|
|
84
|
+
- run: pnpm run build:ci
|
|
85
|
+
- run: pnpm test
|
|
@@ -125,7 +125,7 @@ async function createPluginTemplate(name, description, repoUrl, destPath) {
|
|
|
125
125
|
await updatePluginPackageDistFile(destPath, name, description, repoUrl);
|
|
126
126
|
await updateReadmeFile(destPath, name, description, repoUrl);
|
|
127
127
|
await updatePluginWebpackFile(destPath, name, description);
|
|
128
|
-
(0, template_utils_1.runInstall)(destPath);
|
|
129
|
-
(0, template_utils_1.runBuild)(destPath);
|
|
128
|
+
await (0, template_utils_1.runInstall)(destPath);
|
|
129
|
+
await (0, template_utils_1.runBuild)(destPath);
|
|
130
130
|
}
|
|
131
131
|
exports.createPluginTemplate = createPluginTemplate;
|
|
@@ -15,7 +15,7 @@ exports.pluginCommand = pluginCommand;
|
|
|
15
15
|
pluginCommand.description("Create a new tsParticles plugin");
|
|
16
16
|
pluginCommand.argument("<destination>", "Destination folder");
|
|
17
17
|
pluginCommand.action(async (destination) => {
|
|
18
|
-
const destPath = await (0, file_utils_1.getDestinationDir)(destination), repoUrl = (0, file_utils_1.getRepositoryUrl)();
|
|
18
|
+
const destPath = await (0, file_utils_1.getDestinationDir)(destination), repoUrl = await (0, file_utils_1.getRepositoryUrl)();
|
|
19
19
|
const initialName = destPath.split(path_1.default.sep).pop(), questions = [
|
|
20
20
|
{
|
|
21
21
|
type: "text",
|
|
@@ -143,7 +143,7 @@ async function createPresetTemplate(name, description, repoUrl, destPath) {
|
|
|
143
143
|
await updatePresetPackageDistFile(destPath, name, description, repoUrl);
|
|
144
144
|
await updateReadmeFile(destPath, name, description, repoUrl);
|
|
145
145
|
await updatePresetWebpackFile(destPath, name, description);
|
|
146
|
-
(0, template_utils_1.runInstall)(destPath);
|
|
147
|
-
(0, template_utils_1.runBuild)(destPath);
|
|
146
|
+
await (0, template_utils_1.runInstall)(destPath);
|
|
147
|
+
await (0, template_utils_1.runBuild)(destPath);
|
|
148
148
|
}
|
|
149
149
|
exports.createPresetTemplate = createPresetTemplate;
|
|
@@ -15,7 +15,7 @@ exports.presetCommand = presetCommand;
|
|
|
15
15
|
presetCommand.description("Create a new tsParticles preset");
|
|
16
16
|
presetCommand.argument("<destination>", "Destination folder");
|
|
17
17
|
presetCommand.action(async (destination) => {
|
|
18
|
-
const destPath = await (0, file_utils_1.getDestinationDir)(destination), repoUrl = (0, file_utils_1.getRepositoryUrl)();
|
|
18
|
+
const destPath = await (0, file_utils_1.getDestinationDir)(destination), repoUrl = await (0, file_utils_1.getRepositoryUrl)();
|
|
19
19
|
const initialName = destPath.split(path_1.default.sep).pop(), questions = [
|
|
20
20
|
{
|
|
21
21
|
type: "text",
|
|
@@ -125,7 +125,7 @@ async function createShapeTemplate(name, description, repoUrl, destPath) {
|
|
|
125
125
|
await updateShapePackageDistFile(destPath, name, description, repoUrl);
|
|
126
126
|
await updateReadmeFile(destPath, name, description, repoUrl);
|
|
127
127
|
await updateShapeWebpackFile(destPath, name, description);
|
|
128
|
-
(0, template_utils_1.runInstall)(destPath);
|
|
129
|
-
(0, template_utils_1.runBuild)(destPath);
|
|
128
|
+
await (0, template_utils_1.runInstall)(destPath);
|
|
129
|
+
await (0, template_utils_1.runBuild)(destPath);
|
|
130
130
|
}
|
|
131
131
|
exports.createShapeTemplate = createShapeTemplate;
|
|
@@ -15,7 +15,7 @@ exports.shapeCommand = shapeCommand;
|
|
|
15
15
|
shapeCommand.description("Create a new tsParticles shape");
|
|
16
16
|
shapeCommand.argument("<destination>", "Destination folder");
|
|
17
17
|
shapeCommand.action(async (destination) => {
|
|
18
|
-
const destPath = await (0, file_utils_1.getDestinationDir)(destination), repoUrl = (0, file_utils_1.getRepositoryUrl)();
|
|
18
|
+
const destPath = await (0, file_utils_1.getDestinationDir)(destination), repoUrl = await (0, file_utils_1.getRepositoryUrl)();
|
|
19
19
|
const initialName = destPath.split(path_1.default.sep).pop(), questions = [
|
|
20
20
|
{
|
|
21
21
|
type: "text",
|
package/dist/utils/file-utils.js
CHANGED
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.getRepositoryUrl = exports.getDestinationDir = exports.replaceTokensInFile = exports.replaceTokensInFiles = void 0;
|
|
7
7
|
const child_process_1 = require("child_process");
|
|
8
8
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
9
|
+
const lookpath_1 = require("lookpath");
|
|
9
10
|
const path_1 = __importDefault(require("path"));
|
|
10
11
|
/**
|
|
11
12
|
*
|
|
@@ -51,12 +52,18 @@ exports.getDestinationDir = getDestinationDir;
|
|
|
51
52
|
/**
|
|
52
53
|
* @returns the repository URL
|
|
53
54
|
*/
|
|
54
|
-
function getRepositoryUrl() {
|
|
55
|
-
|
|
56
|
-
return (0, child_process_1.execSync)("git config --get remote.origin.url").toString();
|
|
57
|
-
}
|
|
58
|
-
catch {
|
|
55
|
+
async function getRepositoryUrl() {
|
|
56
|
+
if (!(await (0, lookpath_1.lookpath)("git"))) {
|
|
59
57
|
return "";
|
|
60
58
|
}
|
|
59
|
+
return new Promise((resolve, reject) => {
|
|
60
|
+
(0, child_process_1.exec)("git config --get remote.origin.url", (error, stdout) => {
|
|
61
|
+
if (error) {
|
|
62
|
+
reject(error);
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
resolve(stdout.toString());
|
|
66
|
+
});
|
|
67
|
+
});
|
|
61
68
|
}
|
|
62
69
|
exports.getRepositoryUrl = getRepositoryUrl;
|
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.runBuild = exports.runInstall = exports.copyFilter = exports.copyEmptyTemplateFiles = exports.updateWebpackFile = exports.updatePackageDistFile = exports.updatePackageFile = void 0;
|
|
7
7
|
const child_process_1 = require("child_process");
|
|
8
8
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
9
|
+
const lookpath_1 = require("lookpath");
|
|
9
10
|
const path_1 = __importDefault(require("path"));
|
|
10
11
|
const file_utils_1 = require("./file-utils");
|
|
11
12
|
/**
|
|
@@ -139,9 +140,20 @@ exports.copyFilter = copyFilter;
|
|
|
139
140
|
* Runs npm install in the given path
|
|
140
141
|
* @param destPath - The path where the project will be created
|
|
141
142
|
*/
|
|
142
|
-
function runInstall(destPath) {
|
|
143
|
-
(0,
|
|
144
|
-
|
|
143
|
+
async function runInstall(destPath) {
|
|
144
|
+
if (!(await (0, lookpath_1.lookpath)("npm"))) {
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
return new Promise((resolve, reject) => {
|
|
148
|
+
(0, child_process_1.exec)("npm install", {
|
|
149
|
+
cwd: destPath,
|
|
150
|
+
}, error => {
|
|
151
|
+
if (error) {
|
|
152
|
+
reject(error);
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
resolve();
|
|
156
|
+
});
|
|
145
157
|
});
|
|
146
158
|
}
|
|
147
159
|
exports.runInstall = runInstall;
|
|
@@ -149,9 +161,20 @@ exports.runInstall = runInstall;
|
|
|
149
161
|
* Runs npm run build in the given path
|
|
150
162
|
* @param destPath - The path where the project will be build
|
|
151
163
|
*/
|
|
152
|
-
function runBuild(destPath) {
|
|
153
|
-
(0,
|
|
154
|
-
|
|
164
|
+
async function runBuild(destPath) {
|
|
165
|
+
if (!(await (0, lookpath_1.lookpath)("npm"))) {
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
return new Promise((resolve, reject) => {
|
|
169
|
+
(0, child_process_1.exec)("npm run build", {
|
|
170
|
+
cwd: destPath,
|
|
171
|
+
}, error => {
|
|
172
|
+
if (error) {
|
|
173
|
+
reject(error);
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
resolve();
|
|
177
|
+
});
|
|
155
178
|
});
|
|
156
179
|
}
|
|
157
180
|
exports.runBuild = runBuild;
|
|
@@ -54,7 +54,7 @@ $ yarn add tsparticles-plugin-template
|
|
|
54
54
|
Then you need to import it in the app, like this:
|
|
55
55
|
|
|
56
56
|
```javascript
|
|
57
|
-
const { tsParticles } = require("tsparticles
|
|
57
|
+
const { tsParticles } = require("@tsparticles/engine");
|
|
58
58
|
const { loadTemplatePlugin } = require("tsparticles-plugin-template");
|
|
59
59
|
|
|
60
60
|
(async () => {
|
|
@@ -65,7 +65,7 @@ const { loadTemplatePlugin } = require("tsparticles-plugin-template");
|
|
|
65
65
|
or
|
|
66
66
|
|
|
67
67
|
```javascript
|
|
68
|
-
import { tsParticles } from "tsparticles
|
|
68
|
+
import { tsParticles } from "@tsparticles/engine";
|
|
69
69
|
import { loadTemplatePlugin } from "tsparticles-plugin-template";
|
|
70
70
|
|
|
71
71
|
(async () => {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type Container, type Engine, type IContainerPlugin } from "tsparticles
|
|
1
|
+
import { type Container, type Engine, type IContainerPlugin } from "@tsparticles/engine";
|
|
2
2
|
|
|
3
3
|
export class PluginInstance implements IContainerPlugin {
|
|
4
4
|
private readonly _container;
|
|
@@ -21,7 +21,7 @@ Once installed you need one more script to be included in your page (or you can
|
|
|
21
21
|
from [jsDelivr](https://www.jsdelivr.com/package/npm/tsparticles-preset-template):
|
|
22
22
|
|
|
23
23
|
```html
|
|
24
|
-
<script src="https://cdn.jsdelivr.net/npm/
|
|
24
|
+
<script src="https://cdn.jsdelivr.net/npm/@tsparticles/engine@2/tsparticles.engine.min.js"></script>
|
|
25
25
|
<script src="https://cdn.jsdelivr.net/npm/tsparticles-preset-template/tsparticles.preset.template.min.js"></script>
|
|
26
26
|
```
|
|
27
27
|
|
|
@@ -75,7 +75,7 @@ This sample uses the class component syntax, but you can use hooks as well (if t
|
|
|
75
75
|
|
|
76
76
|
```javascript
|
|
77
77
|
import Particles from "react-particles";
|
|
78
|
-
import { Engine } from "tsparticles
|
|
78
|
+
import { Engine } from "@tsparticles/engine";
|
|
79
79
|
import { loadTemplatePreset } from "tsparticles-preset-template";
|
|
80
80
|
|
|
81
81
|
export class ParticlesContainer extends React.PureComponent<IProps> {
|
|
@@ -55,7 +55,7 @@ $ yarn add tsparticles-shape-template
|
|
|
55
55
|
Then you need to import it in the app, like this:
|
|
56
56
|
|
|
57
57
|
```javascript
|
|
58
|
-
const { tsParticles } = require("tsparticles
|
|
58
|
+
const { tsParticles } = require("@tsparticles/engine");
|
|
59
59
|
const { loadTemplateShape } = require("tsparticles-shape-template");
|
|
60
60
|
|
|
61
61
|
(async () => {
|
|
@@ -66,7 +66,7 @@ const { loadTemplateShape } = require("tsparticles-shape-template");
|
|
|
66
66
|
or
|
|
67
67
|
|
|
68
68
|
```javascript
|
|
69
|
-
import { tsParticles } from "tsparticles
|
|
69
|
+
import { tsParticles } from "@tsparticles/engine";
|
|
70
70
|
import { loadTemplateShape } from "tsparticles-shape-template";
|
|
71
71
|
|
|
72
72
|
(async () => {
|
|
@@ -1,15 +1,10 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { IShapeDrawData, IShapeDrawer } from "@tsparticles/engine";
|
|
2
2
|
|
|
3
3
|
export class ShapeDrawer implements IShapeDrawer {
|
|
4
|
-
draw(
|
|
5
|
-
_particle: Particle,
|
|
6
|
-
_radius: number,
|
|
7
|
-
_opacity: number,
|
|
8
|
-
_delta: IDelta,
|
|
9
|
-
_pixelRatio: number): void {
|
|
4
|
+
draw(_data: IShapeDrawData): void {
|
|
10
5
|
// draw the particle using the context
|
|
11
6
|
// which is already centered in the particle position
|
|
12
|
-
// colors are already
|
|
7
|
+
// colors are already handled, just draw the shape
|
|
13
8
|
// the bounds are -radius to radius
|
|
14
9
|
// delta is the frame time difference between the last frame and this one, in ms, use it for animated shapes
|
|
15
10
|
// pixelRatio is the canvas ratio used by the tsParticles instance, you may need it for density-independent shapes
|
|
@@ -82,29 +82,29 @@
|
|
|
82
82
|
"types": "dist/types/index.d.ts",
|
|
83
83
|
"prettier": "@tsparticles/prettier-config",
|
|
84
84
|
"devDependencies": {
|
|
85
|
-
"@babel/core": "^7.
|
|
86
|
-
"@tsparticles/cli": "^2.0.0
|
|
87
|
-
"@tsparticles/eslint-config": "^
|
|
88
|
-
"@tsparticles/prettier-config": "^
|
|
89
|
-
"@tsparticles/tsconfig": "^
|
|
90
|
-
"@tsparticles/webpack-plugin": "^
|
|
91
|
-
"@types/webpack-env": "^1.18.
|
|
92
|
-
"@typescript-eslint/eslint-plugin": "^6.
|
|
93
|
-
"@typescript-eslint/parser": "^6.
|
|
85
|
+
"@babel/core": "^7.23.3",
|
|
86
|
+
"@tsparticles/cli": "^2.0.0",
|
|
87
|
+
"@tsparticles/eslint-config": "^2.0.0-beta.7",
|
|
88
|
+
"@tsparticles/prettier-config": "^2.0.0-beta.4",
|
|
89
|
+
"@tsparticles/tsconfig": "^2.0.0-beta.1",
|
|
90
|
+
"@tsparticles/webpack-plugin": "^2.0.0-beta.11",
|
|
91
|
+
"@types/webpack-env": "^1.18.4",
|
|
92
|
+
"@typescript-eslint/eslint-plugin": "^6.11.0",
|
|
93
|
+
"@typescript-eslint/parser": "^6.11.0",
|
|
94
94
|
"babel-loader": "^9.1.3",
|
|
95
|
-
"browserslist": "^4.
|
|
95
|
+
"browserslist": "^4.22.1",
|
|
96
96
|
"copyfiles": "^2.4.1",
|
|
97
|
-
"eslint": "^8.
|
|
97
|
+
"eslint": "^8.53.0",
|
|
98
98
|
"eslint-config-prettier": "^9.0.0",
|
|
99
|
-
"prettier": "^3.0
|
|
100
|
-
"rimraf": "^5.0.
|
|
99
|
+
"prettier": "^3.1.0",
|
|
100
|
+
"rimraf": "^5.0.5",
|
|
101
101
|
"terser-webpack-plugin": "^5.3.9",
|
|
102
|
-
"typescript": "^5.
|
|
103
|
-
"webpack": "^5.
|
|
104
|
-
"webpack-bundle-analyzer": "^4.
|
|
102
|
+
"typescript": "^5.2.2",
|
|
103
|
+
"webpack": "^5.89.0",
|
|
104
|
+
"webpack-bundle-analyzer": "^4.10.0",
|
|
105
105
|
"webpack-cli": "^5.1.4"
|
|
106
106
|
},
|
|
107
107
|
"dependencies": {
|
|
108
|
-
"tsparticles
|
|
108
|
+
"@tsparticles/engine": "^3.0.0-beta.3"
|
|
109
109
|
}
|
|
110
110
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsparticles/cli",
|
|
3
|
-
"version": "2.0.0
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"bin": {
|
|
6
6
|
"tsparticles-cli": "dist/cli.js"
|
|
@@ -10,34 +10,36 @@
|
|
|
10
10
|
},
|
|
11
11
|
"prettier": "@tsparticles/prettier-config",
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@tsparticles/eslint-config": "^2.0.0
|
|
14
|
-
"@tsparticles/prettier-config": "^2.0.0
|
|
15
|
-
"@tsparticles/tsconfig": "^2.0.0
|
|
16
|
-
"@tsparticles/webpack-plugin": "^2.0.0
|
|
17
|
-
"@typescript-eslint/eslint-plugin": "^6.
|
|
18
|
-
"@typescript-eslint/parser": "^6.
|
|
19
|
-
"commander": "^11.
|
|
20
|
-
"eslint": "^8.
|
|
13
|
+
"@tsparticles/eslint-config": "^2.0.0",
|
|
14
|
+
"@tsparticles/prettier-config": "^2.0.0",
|
|
15
|
+
"@tsparticles/tsconfig": "^2.0.0",
|
|
16
|
+
"@tsparticles/webpack-plugin": "^2.0.0",
|
|
17
|
+
"@typescript-eslint/eslint-plugin": "^6.12.0",
|
|
18
|
+
"@typescript-eslint/parser": "^6.12.0",
|
|
19
|
+
"commander": "^11.1.0",
|
|
20
|
+
"eslint": "^8.54.0",
|
|
21
21
|
"eslint-config-prettier": "^9.0.0",
|
|
22
|
-
"eslint-plugin-jsdoc": "^46.
|
|
22
|
+
"eslint-plugin-jsdoc": "^46.9.0",
|
|
23
23
|
"eslint-plugin-tsdoc": "^0.2.17",
|
|
24
24
|
"fs-extra": "^11.1.1",
|
|
25
25
|
"klaw": "^4.1.0",
|
|
26
|
+
"lookpath": "^1.2.2",
|
|
26
27
|
"path-scurry": "^1.10.1",
|
|
27
|
-
"prettier": "^3.0
|
|
28
|
+
"prettier": "^3.1.0",
|
|
29
|
+
"prettier-plugin-multiline-arrays": "^3.0.1",
|
|
28
30
|
"prompts": "^2.4.2",
|
|
29
|
-
"rimraf": "^5.0.
|
|
30
|
-
"typescript": "^5.
|
|
31
|
-
"webpack": "^5.
|
|
31
|
+
"rimraf": "^5.0.5",
|
|
32
|
+
"typescript": "^5.3.2",
|
|
33
|
+
"webpack": "^5.89.0"
|
|
32
34
|
},
|
|
33
35
|
"devDependencies": {
|
|
34
|
-
"@types/chai": "^4.3.
|
|
35
|
-
"@types/fs-extra": "^11.0.
|
|
36
|
-
"@types/klaw": "^3.0.
|
|
37
|
-
"@types/mocha": "^10.0.
|
|
38
|
-
"@types/node": "^20.
|
|
39
|
-
"@types/prompts": "^2.4.
|
|
40
|
-
"chai": "^4.3.
|
|
36
|
+
"@types/chai": "^4.3.11",
|
|
37
|
+
"@types/fs-extra": "^11.0.4",
|
|
38
|
+
"@types/klaw": "^3.0.6",
|
|
39
|
+
"@types/mocha": "^10.0.5",
|
|
40
|
+
"@types/node": "^20.9.3",
|
|
41
|
+
"@types/prompts": "^2.4.9",
|
|
42
|
+
"chai": "^4.3.10",
|
|
41
43
|
"cross-env": "^7.0.3",
|
|
42
44
|
"mocha": "^10.2.0",
|
|
43
45
|
"nyc": "^15.1.0",
|
|
@@ -175,6 +175,6 @@ export async function createPluginTemplate(
|
|
|
175
175
|
await updateReadmeFile(destPath, name, description, repoUrl);
|
|
176
176
|
await updatePluginWebpackFile(destPath, name, description);
|
|
177
177
|
|
|
178
|
-
runInstall(destPath);
|
|
179
|
-
runBuild(destPath);
|
|
178
|
+
await runInstall(destPath);
|
|
179
|
+
await runBuild(destPath);
|
|
180
180
|
}
|
|
@@ -11,7 +11,7 @@ pluginCommand.description("Create a new tsParticles plugin");
|
|
|
11
11
|
pluginCommand.argument("<destination>", "Destination folder");
|
|
12
12
|
pluginCommand.action(async (destination: string) => {
|
|
13
13
|
const destPath = await getDestinationDir(destination),
|
|
14
|
-
repoUrl = getRepositoryUrl();
|
|
14
|
+
repoUrl = await getRepositoryUrl();
|
|
15
15
|
|
|
16
16
|
const initialName = destPath.split(path.sep).pop(),
|
|
17
17
|
questions: PromptObject[] = [
|
|
@@ -194,6 +194,6 @@ export async function createPresetTemplate(
|
|
|
194
194
|
await updateReadmeFile(destPath, name, description, repoUrl);
|
|
195
195
|
await updatePresetWebpackFile(destPath, name, description);
|
|
196
196
|
|
|
197
|
-
runInstall(destPath);
|
|
198
|
-
runBuild(destPath);
|
|
197
|
+
await runInstall(destPath);
|
|
198
|
+
await runBuild(destPath);
|
|
199
199
|
}
|
|
@@ -11,7 +11,7 @@ presetCommand.description("Create a new tsParticles preset");
|
|
|
11
11
|
presetCommand.argument("<destination>", "Destination folder");
|
|
12
12
|
presetCommand.action(async (destination: string) => {
|
|
13
13
|
const destPath = await getDestinationDir(destination),
|
|
14
|
-
repoUrl = getRepositoryUrl();
|
|
14
|
+
repoUrl = await getRepositoryUrl();
|
|
15
15
|
|
|
16
16
|
const initialName = destPath.split(path.sep).pop(),
|
|
17
17
|
questions: PromptObject[] = [
|
|
@@ -174,6 +174,6 @@ export async function createShapeTemplate(
|
|
|
174
174
|
await updateReadmeFile(destPath, name, description, repoUrl);
|
|
175
175
|
await updateShapeWebpackFile(destPath, name, description);
|
|
176
176
|
|
|
177
|
-
runInstall(destPath);
|
|
178
|
-
runBuild(destPath);
|
|
177
|
+
await runInstall(destPath);
|
|
178
|
+
await runBuild(destPath);
|
|
179
179
|
}
|
|
@@ -11,7 +11,7 @@ shapeCommand.description("Create a new tsParticles shape");
|
|
|
11
11
|
shapeCommand.argument("<destination>", "Destination folder");
|
|
12
12
|
shapeCommand.action(async (destination: string) => {
|
|
13
13
|
const destPath = await getDestinationDir(destination),
|
|
14
|
-
repoUrl = getRepositoryUrl();
|
|
14
|
+
repoUrl = await getRepositoryUrl();
|
|
15
15
|
|
|
16
16
|
const initialName = destPath.split(path.sep).pop(),
|
|
17
17
|
questions: PromptObject[] = [
|
package/src/utils/file-utils.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { exec } from "child_process";
|
|
2
2
|
import fs from "fs-extra";
|
|
3
|
+
import { lookpath } from "lookpath";
|
|
3
4
|
import path from "path";
|
|
4
5
|
|
|
5
6
|
export type ReplaceTokensOptions = {
|
|
@@ -66,10 +67,20 @@ export async function getDestinationDir(destination: string): Promise<string> {
|
|
|
66
67
|
/**
|
|
67
68
|
* @returns the repository URL
|
|
68
69
|
*/
|
|
69
|
-
export function getRepositoryUrl(): string {
|
|
70
|
-
|
|
71
|
-
return execSync("git config --get remote.origin.url").toString();
|
|
72
|
-
} catch {
|
|
70
|
+
export async function getRepositoryUrl(): Promise<string> {
|
|
71
|
+
if (!(await lookpath("git"))) {
|
|
73
72
|
return "";
|
|
74
73
|
}
|
|
74
|
+
|
|
75
|
+
return new Promise<string>((resolve, reject) => {
|
|
76
|
+
exec("git config --get remote.origin.url", (error, stdout) => {
|
|
77
|
+
if (error) {
|
|
78
|
+
reject(error);
|
|
79
|
+
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
resolve(stdout.toString());
|
|
84
|
+
});
|
|
85
|
+
});
|
|
75
86
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { exec } from "child_process";
|
|
2
2
|
import fs from "fs-extra";
|
|
3
|
+
import { lookpath } from "lookpath";
|
|
3
4
|
import path from "path";
|
|
4
5
|
import { replaceTokensInFile } from "./file-utils";
|
|
5
6
|
|
|
@@ -151,9 +152,27 @@ export function copyFilter(src: string): boolean {
|
|
|
151
152
|
* Runs npm install in the given path
|
|
152
153
|
* @param destPath - The path where the project will be created
|
|
153
154
|
*/
|
|
154
|
-
export function runInstall(destPath: string): void {
|
|
155
|
-
|
|
156
|
-
|
|
155
|
+
export async function runInstall(destPath: string): Promise<void> {
|
|
156
|
+
if (!(await lookpath("npm"))) {
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
return new Promise((resolve, reject) => {
|
|
161
|
+
exec(
|
|
162
|
+
"npm install",
|
|
163
|
+
{
|
|
164
|
+
cwd: destPath,
|
|
165
|
+
},
|
|
166
|
+
error => {
|
|
167
|
+
if (error) {
|
|
168
|
+
reject(error);
|
|
169
|
+
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
resolve();
|
|
174
|
+
},
|
|
175
|
+
);
|
|
157
176
|
});
|
|
158
177
|
}
|
|
159
178
|
|
|
@@ -161,8 +180,26 @@ export function runInstall(destPath: string): void {
|
|
|
161
180
|
* Runs npm run build in the given path
|
|
162
181
|
* @param destPath - The path where the project will be build
|
|
163
182
|
*/
|
|
164
|
-
export function runBuild(destPath: string): void {
|
|
165
|
-
|
|
166
|
-
|
|
183
|
+
export async function runBuild(destPath: string): Promise<void> {
|
|
184
|
+
if (!(await lookpath("npm"))) {
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
return new Promise((resolve, reject) => {
|
|
189
|
+
exec(
|
|
190
|
+
"npm run build",
|
|
191
|
+
{
|
|
192
|
+
cwd: destPath,
|
|
193
|
+
},
|
|
194
|
+
error => {
|
|
195
|
+
if (error) {
|
|
196
|
+
reject(error);
|
|
197
|
+
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
resolve();
|
|
202
|
+
},
|
|
203
|
+
);
|
|
167
204
|
});
|
|
168
205
|
}
|
package/tests/file-utils.test.ts
CHANGED
|
@@ -90,8 +90,8 @@ describe("file-utils", async () => {
|
|
|
90
90
|
});
|
|
91
91
|
|
|
92
92
|
describe("get repository url", () => {
|
|
93
|
-
it("should return the repository url", () => {
|
|
94
|
-
expect(getRepositoryUrl()).to.be.not.equal("");
|
|
93
|
+
it("should return the repository url", async () => {
|
|
94
|
+
expect(await getRepositoryUrl()).to.be.not.equal("");
|
|
95
95
|
});
|
|
96
96
|
});
|
|
97
97
|
|