@tsparticles/cli 3.3.0 → 3.3.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/dependabot.yml +7 -0
- package/.planning/codebase/ARCHITECTURE.md +132 -3
- package/.planning/codebase/CONCERNS.md +105 -3
- package/.planning/codebase/CONVENTIONS.md +91 -3
- package/.planning/codebase/INTEGRATIONS.md +82 -3
- package/.planning/codebase/STACK.md +88 -8
- package/.planning/codebase/STRUCTURE.md +138 -3
- package/.planning/codebase/TESTING.md +156 -3
- package/dist/build/build-distfiles.js +14 -13
- package/dist/build/build-diststats.js +8 -7
- package/dist/build/build-prettier.d.ts +2 -2
- package/dist/build/build-prettier.js +26 -25
- package/dist/build/build-tsc.js +4 -3
- package/dist/build/build.js +10 -8
- package/dist/cli.js +3 -3
- package/dist/create/plugin/create-plugin.js +4 -3
- package/dist/create/preset/create-preset.js +4 -3
- package/dist/create/shape/create-shape.js +4 -3
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utils/file-utils.js +7 -6
- package/dist/utils/template-utils.js +4 -3
- package/files/empty-project/package.json +7 -7
- package/files/empty-project/webpack.config.js +11 -11
- package/package.json +9 -11
- package/renovate.json +3 -0
- package/src/build/build-distfiles.ts +15 -14
- package/src/build/build-diststats.ts +8 -8
- package/src/build/build-prettier.ts +25 -26
- package/src/build/build-tsc.ts +4 -3
- package/src/build/build.ts +10 -10
- package/src/cli.ts +3 -3
- package/src/create/plugin/create-plugin.ts +4 -3
- package/src/create/preset/create-preset.ts +4 -3
- package/src/create/shape/create-shape.ts +4 -3
- package/src/utils/file-utils.ts +7 -6
- package/src/utils/template-utils.ts +4 -3
- package/tests/create-plugin.test.ts +25 -25
- package/tests/create-preset.test.ts +25 -25
- package/tests/create-shape.test.ts +25 -25
- package/tests/file-utils.test.ts +87 -78
- package/tests/tsconfig.json +12 -11
- package/tsconfig.json +52 -53
|
@@ -1,3 +1,132 @@
|
|
|
1
|
-
Architecture
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
# Architecture
|
|
2
|
+
|
|
3
|
+
**Analysis Date:** 2026-03-10
|
|
4
|
+
|
|
5
|
+
## Pattern Overview
|
|
6
|
+
|
|
7
|
+
Overall: Small modular CLI application organized as command modules with utility libraries and build tooling.
|
|
8
|
+
|
|
9
|
+
Key Characteristics:
|
|
10
|
+
|
|
11
|
+
- Single-process Node.js CLI built in TypeScript (compiled to ESM JavaScript).
|
|
12
|
+
- Commands are organized as independent modules and registered with a central `commander`-based entrypoint.
|
|
13
|
+
- Clear separation between "command" code (user-facing CLI actions) and utilities (I/O, template manipulation, subprocess execution).
|
|
14
|
+
- Build scripts live under `src/build` and are implemented as programmatic build tasks callable from `build` command.
|
|
15
|
+
|
|
16
|
+
## Layers
|
|
17
|
+
|
|
18
|
+
Command Layer:
|
|
19
|
+
|
|
20
|
+
- Purpose: Exposes CLI commands and their behaviors to end users.
|
|
21
|
+
- Location: `src/cli.ts`, `src/create/*`, `src/build/*`
|
|
22
|
+
- Contains: `commander` Command instances, argument parsing, user prompts.
|
|
23
|
+
- Depends on: `src/utils/*` for filesystem and template operations, `prompts` for interactive input.
|
|
24
|
+
- Used by: CLI entrypoint `src/cli.ts` registers commands for runtime.
|
|
25
|
+
|
|
26
|
+
Core/Template Layer:
|
|
27
|
+
|
|
28
|
+
- Purpose: Implement the core operations that create projects and manipulate templates.
|
|
29
|
+
- Location: `src/create/preset/create-preset.ts`, `src/create/shape/create-shape.ts`, `src/create/plugin/create-plugin.ts`, `src/utils/template-utils.ts`, `src/utils/file-utils.ts`
|
|
30
|
+
- Contains: file copy, token replacement, package.json updates, npm execution, webpack/package dist adjustments.
|
|
31
|
+
- Depends on: `fs-extra`, `lookpath`, child_process `exec`.
|
|
32
|
+
- Used by: Command actions in `src/create/*`.
|
|
33
|
+
|
|
34
|
+
Build Tooling Layer:
|
|
35
|
+
|
|
36
|
+
- Purpose: Project build and CI helpers exposed as `build` command.
|
|
37
|
+
- Location: `src/build/*.ts` (`src/build/build.ts`, `src/build/build-tsc.ts`, `src/build/build-bundle.ts`, etc.)
|
|
38
|
+
- Contains: tasks to run prettier, eslint, tsc, bundling and other project checks.
|
|
39
|
+
- Depends on: dev tooling in `package.json` and runtime tools (SWC, Webpack, etc.).
|
|
40
|
+
|
|
41
|
+
Utilities Layer:
|
|
42
|
+
|
|
43
|
+
- Purpose: Shared helpers for string manipulation, file operations and token replacement.
|
|
44
|
+
- Location: `src/utils/string-utils.ts`, `src/utils/file-utils.ts`, `src/utils/template-utils.ts`
|
|
45
|
+
- Contains: helper functions with small focused responsibilities (e.g., `replaceTokensInFile`, `getDestinationDir`, `getRepositoryUrl`).
|
|
46
|
+
|
|
47
|
+
Test Layer:
|
|
48
|
+
|
|
49
|
+
- Purpose: Unit tests for templates and generator functions.
|
|
50
|
+
- Location: `tests/*.test.ts`, `vitest.config.ts`
|
|
51
|
+
|
|
52
|
+
## Data Flow
|
|
53
|
+
|
|
54
|
+
Create command flow (example `preset`):
|
|
55
|
+
|
|
56
|
+
1. User invokes CLI: `tsparticles-cli create preset <destination>` -> `src/cli.ts` boots and routes to `src/create/create.ts` -> `src/create/preset/preset.ts`.
|
|
57
|
+
2. `preset.ts` gathers interactive input via `prompts` and computes `destPath` using `src/utils/file-utils.ts:getDestinationDir`.
|
|
58
|
+
3. `createPresetTemplate` in `src/create/preset/create-preset.ts` runs sequence:
|
|
59
|
+
- copy empty template files (`src/utils/template-utils.ts:copyEmptyTemplateFiles`) -> uses `files` templates under repo
|
|
60
|
+
- copy project-specific files via `fs.copy`
|
|
61
|
+
- run a series of `replaceTokensInFile` operations (`src/utils/file-utils.ts`) to customize bundle/index/readme/package files
|
|
62
|
+
- run `runInstall` and `runBuild` (`src/utils/template-utils.ts`) which spawn subprocesses (`npm install`, `npm run build`) if `npm` found
|
|
63
|
+
|
|
64
|
+
State Management:
|
|
65
|
+
|
|
66
|
+
- Stateless CLI operations. Functions operate on input parameters and filesystem state. There is no in-memory application-wide state beyond individual command execution.
|
|
67
|
+
|
|
68
|
+
## Key Abstractions
|
|
69
|
+
|
|
70
|
+
Command Module:
|
|
71
|
+
|
|
72
|
+
- Purpose: Encapsulate a single CLI command and its action handler.
|
|
73
|
+
- Examples: `src/create/preset/preset.ts`, `src/create/shape/shape.ts`, `src/create/plugin/plugin.ts`, `src/create/create.ts`.
|
|
74
|
+
- Pattern: Each command is a `commander.Command` with `argument` declarations and an `action` async function.
|
|
75
|
+
|
|
76
|
+
Template Manipulation Utility:
|
|
77
|
+
|
|
78
|
+
- Purpose: Replace tokens and patch files in a project template.
|
|
79
|
+
- Examples: `src/utils/file-utils.ts` (`replaceTokensInFile`, `replaceTokensInFiles`), `src/utils/template-utils.ts` (`updatePackageFile`, `updateWebpackFile`).
|
|
80
|
+
|
|
81
|
+
Build Task Modules:
|
|
82
|
+
|
|
83
|
+
- Purpose: Implement discrete build subtasks called from `src/build/build.ts`.
|
|
84
|
+
- Examples: `src/build/build-tsc.ts`, `src/build/build-bundle.ts`, `src/build/build-eslint.ts`.
|
|
85
|
+
|
|
86
|
+
## Entry Points
|
|
87
|
+
|
|
88
|
+
CLI Entrypoint:
|
|
89
|
+
|
|
90
|
+
- Location: `src/cli.ts`
|
|
91
|
+
- Triggers: Executed when package binary `dist/cli.js` is run (shebang present); `npm run build` ensures `dist/cli.js` is executable.
|
|
92
|
+
- Responsibilities: Read package version (`package.json`), register `build` and `create` commands and parse `process.argv`.
|
|
93
|
+
|
|
94
|
+
Create Command Aggregator:
|
|
95
|
+
|
|
96
|
+
- Location: `src/create/create.ts`
|
|
97
|
+
- Triggers: Registered by `src/cli.ts` as `create` command
|
|
98
|
+
- Responsibilities: Add subcommands `plugin`, `preset`, `shape` from their respective modules.
|
|
99
|
+
|
|
100
|
+
Build Aggregator:
|
|
101
|
+
|
|
102
|
+
- Location: `src/build/build.ts`
|
|
103
|
+
- Triggers: Registered by `src/cli.ts` as `build` command
|
|
104
|
+
- Responsibilities: Compose and run smaller build tasks (prettier, lint, tsc, circular deps, dist packaging).
|
|
105
|
+
|
|
106
|
+
## Error Handling
|
|
107
|
+
|
|
108
|
+
Strategy: Throw and bubble errors from async functions; top-level command handlers are async and do not wrap all exceptions. Some tests and callers catch errors for logging.
|
|
109
|
+
|
|
110
|
+
Patterns:
|
|
111
|
+
|
|
112
|
+
- Synchronous validation: `getDestinationDir` checks destination existence and throws an Error if folder not empty (`src/utils/file-utils.ts:getDestinationDir`).
|
|
113
|
+
- Subprocess execution: `exec` wrappers (`runInstall`, `runBuild`) return Promises and reject on `exec` error; calling code awaits and therefore receives the rejection (`src/utils/template-utils.ts`).
|
|
114
|
+
- Tests catch and log errors selectively (`tests/*.test.ts`), but many command entrypoints do not add global try/catch.
|
|
115
|
+
|
|
116
|
+
## Cross-Cutting Concerns
|
|
117
|
+
|
|
118
|
+
Logging:
|
|
119
|
+
|
|
120
|
+
- Approach: Minimal; code uses `console.error` in tests. No centralized logger present. Files: `tests/*`, most modules do not log.
|
|
121
|
+
|
|
122
|
+
Validation:
|
|
123
|
+
|
|
124
|
+
- Approach: Input validation is enforced by `prompts` validators and `getDestinationDir` pre-checks. See `src/create/*` for validators on required fields.
|
|
125
|
+
|
|
126
|
+
Authentication:
|
|
127
|
+
|
|
128
|
+
- Approach: Not applicable to this CLI: no remote APIs or credential storage.
|
|
129
|
+
|
|
130
|
+
---
|
|
131
|
+
|
|
132
|
+
_Architecture analysis: 2026-03-10_
|
|
@@ -1,3 +1,105 @@
|
|
|
1
|
-
Concerns
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
# Codebase Concerns
|
|
2
|
+
|
|
3
|
+
**Analysis Date:** 2026-03-10
|
|
4
|
+
|
|
5
|
+
## Tech Debt
|
|
6
|
+
|
|
7
|
+
**Regex-based token replacement (critical):**
|
|
8
|
+
|
|
9
|
+
- Issue: `src/utils/file-utils.ts` implements `replaceTokensInFiles` and constructs a RegExp with `new RegExp(token.from, "g")` regardless of whether `token.from` is a `string` or a `RegExp`.
|
|
10
|
+
- Files: `src/utils/file-utils.ts`, callers in `src/utils/template-utils.ts`, `src/create/preset/create-preset.ts` (many tokens are passed as `RegExp` literals).
|
|
11
|
+
- Impact: When `token.from` is already a `RegExp` and flags are passed as the second argument to `RegExp` constructor, Node throws a TypeError. This makes token replacement fragile and causes runtime exceptions in template updates. Tests and callers may swallow the error (see `tests/create-preset.test.ts`) so the issue can be silent in CI but still indicate a bug.
|
|
12
|
+
- Fix approach: Update `replaceTokensInFiles` to detect `RegExp` values and use them directly, or construct a `RegExp` only when `token.from` is a string. Example change in `src/utils/file-utils.ts`:
|
|
13
|
+
|
|
14
|
+
```ts
|
|
15
|
+
const regex = token.from instanceof RegExp ? token.from : new RegExp(String(token.from), "g");
|
|
16
|
+
data = data.replace(regex, token.to);
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Applying this fix ensures RegExp arguments are respected and avoids TypeErrors.
|
|
20
|
+
|
|
21
|
+
**Template JSON changes performed with regex (moderate):**
|
|
22
|
+
|
|
23
|
+
- Issue: `src/utils/template-utils.ts` updates `package.json` and `package.dist.json` using regex replacements (`replaceTokensInFile`) instead of reading and writing JSON.
|
|
24
|
+
- Files: `src/utils/template-utils.ts`, `src/create/preset/create-preset.ts`.
|
|
25
|
+
- Impact: Regex-based edits are brittle: formatting differences, comments, CRLF vs LF, or unexpected matches can break JSON structure or fail to update fields correctly.
|
|
26
|
+
- Fix approach: Parse the JSON files with `fs.readJSON` / `fs.writeJSON` and modify the relevant fields (name, description, repository, files). This is more robust and easier to test. Example target: update `updatePackageFile` to `const pkg = await fs.readJSON(pkgPath); pkg.name = packageName; await fs.writeJSON(pkgPath, pkg, { spaces: 2 });`
|
|
27
|
+
|
|
28
|
+
## Known Bugs
|
|
29
|
+
|
|
30
|
+
**RegExp constructor TypeError during replacements:**
|
|
31
|
+
|
|
32
|
+
- Symptoms: Token replacement throws TypeError when token pattern is a `RegExp` and code calls `new RegExp(token.from, "g")`.
|
|
33
|
+
- Files: `src/utils/file-utils.ts` (replacement implementation).
|
|
34
|
+
- Trigger: Calling any create/template flow that passes `RegExp` literals into tokens (e.g., `src/create/preset/create-preset.ts`).
|
|
35
|
+
- Workaround: Tests and callers often wrap calls in try/catch (see `tests/create-preset.test.ts`) so tests still assert package.json existence, masking the problem. Do not rely on that; fix the replacement implementation.
|
|
36
|
+
|
|
37
|
+
## Security Considerations
|
|
38
|
+
|
|
39
|
+
**Arbitrary script execution via `npm install` / `npm run build`:**
|
|
40
|
+
|
|
41
|
+
- Area: `src/utils/template-utils.ts` functions `runInstall` and `runBuild` execute `npm install` and `npm run build` in generated projects.
|
|
42
|
+
- Files: `src/utils/template-utils.ts`, `src/create/*` where `runInstall` and `runBuild` are invoked (e.g., `src/create/preset/create-preset.ts`).
|
|
43
|
+
- Risk: Running `npm install` in a directory containing an attacker-controlled `package.json` can execute lifecycle scripts (postinstall, preinstall). The CLI currently runs installs automatically during template creation, which can execute arbitrary code on the user's machine.
|
|
44
|
+
- Current mitigation: `lookpath("npm")` is used to avoid running when `npm` is not available, but this does not mitigate script execution risks.
|
|
45
|
+
- Recommendation: Do not run `npm install` / `npm run build` automatically. Instead:
|
|
46
|
+
- Require an explicit flag (e.g., `--install`) to run automatic installs, or
|
|
47
|
+
- Use `npm ci --ignore-scripts` or `npm install --ignore-scripts` as a safer default, and clearly warn users before running scripts, or
|
|
48
|
+
- Prompt for confirmation before running `npm` and print the exact command being run.
|
|
49
|
+
|
|
50
|
+
## Performance Bottlenecks
|
|
51
|
+
|
|
52
|
+
**Use of `child_process.exec` for long-running, high-output commands (moderate):**
|
|
53
|
+
|
|
54
|
+
- Area: `src/utils/template-utils.ts` and `src/utils/file-utils.ts` (the latter uses `exec` in `getRepositoryUrl`).
|
|
55
|
+
- Files: `src/utils/template-utils.ts` (`runInstall`, `runBuild`), `src/utils/file-utils.ts` (`getRepositoryUrl`).
|
|
56
|
+
- Problem: `exec` buffers the full stdout/stderr and has a default buffer size; heavy outputs (e.g., `npm install`) can overflow the buffer and cause the subprocess to fail. Also, using `exec` hides streaming logs from the user.
|
|
57
|
+
- Improvement path: Use `child_process.spawn` with streaming of stdout/stderr and proper error/exit-code handling. Stream logs to the console or into a logger so users see progress.
|
|
58
|
+
|
|
59
|
+
## Fragile Areas
|
|
60
|
+
|
|
61
|
+
**Broad regex replacements over multiple file types (fragile):**
|
|
62
|
+
|
|
63
|
+
- Files: `src/utils/file-utils.ts`, call sites in `src/utils/template-utils.ts` and `src/create/*`.
|
|
64
|
+
- Why fragile: Replacing text with global regexes across files risks accidental substitution (e.g., replacing occurrences in unrelated files). It also makes reasoning about what changed difficult.
|
|
65
|
+
- Safe modification: Limit replacements to specific files and, where possible, use structured transforms (JSON AST edits for `package.json`, templating tools for code files) rather than blind regex.
|
|
66
|
+
|
|
67
|
+
**No centralized logging or structured errors (minor):**
|
|
68
|
+
|
|
69
|
+
- Files: `src/cli.ts`, `src/build/*.ts`, `src/create/*` — modules log via `console` or propagate exceptions.
|
|
70
|
+
- Why fragile: Lack of a central logger and consistent error formatting makes debugging and user-facing error messages inconsistent. Adding a simple logging utility (e.g., `src/utils/logger.ts`) and top-level error handling in `src/cli.ts` would improve UX.
|
|
71
|
+
|
|
72
|
+
## Dependencies at Risk
|
|
73
|
+
|
|
74
|
+
**Self-referential devDependency:**
|
|
75
|
+
|
|
76
|
+
- Files: `package.json` lists `"@tsparticles/cli": "latest"` in `devDependencies`.
|
|
77
|
+
- Risk: This can lead to confusing local development semantics. It is common for monorepo setups but should be intentional.
|
|
78
|
+
- Migration plan: If not required, remove the self-reference. If needed for local testing, ensure a documented developer workflow.
|
|
79
|
+
|
|
80
|
+
## Missing Critical Features
|
|
81
|
+
|
|
82
|
+
**Safe-by-default template creation (missing):**
|
|
83
|
+
|
|
84
|
+
- Problem: Template creation runs `npm install`/`npm run build` by default. There is no opt-in flag to skip these actions for safer, faster creation in CI or sandboxed environments.
|
|
85
|
+
- Blocks: CI runs, offline usage, and security-conscious users.
|
|
86
|
+
- Recommendation: Add a `--no-install` / `--skip-install` option to `create` commands or a top-level config, and ensure `runInstall`/`runBuild` respect that option.
|
|
87
|
+
|
|
88
|
+
## Test Coverage Gaps
|
|
89
|
+
|
|
90
|
+
**Replacement function tests (high priority):**
|
|
91
|
+
|
|
92
|
+
- What's not tested: `replaceTokensInFiles` behavior when `token.from` is a `RegExp` object vs a `string` (no explicit unit tests for this edge case).
|
|
93
|
+
- Files: `src/utils/file-utils.ts`, tests should be added under `tests/file-utils.test.ts` or similar.
|
|
94
|
+
- Risk: Future regressions and silent failures in template flows.
|
|
95
|
+
- Priority: High — add targeted unit tests that exercise both `string` and `RegExp` token inputs and verify no exceptions are thrown and replacements occur as expected.
|
|
96
|
+
|
|
97
|
+
**Integration tests should avoid running real npm:**
|
|
98
|
+
|
|
99
|
+
- What's not tested safely: `createPresetTemplate` currently calls `runInstall` and `runBuild` which invoke `npm` and may perform network operations in CI.
|
|
100
|
+
- Files: `tests/create-preset.test.ts`, `src/utils/template-utils.ts`.
|
|
101
|
+
- Recommendation: Mock `lookpath` and `child_process.exec` in tests, or refactor `runInstall`/`runBuild` to accept an injectable runner (dependency injection) so tests can inject a no-op runner.
|
|
102
|
+
|
|
103
|
+
---
|
|
104
|
+
|
|
105
|
+
_Concerns audit: 2026-03-10_
|
|
@@ -1,3 +1,91 @@
|
|
|
1
|
-
Conventions
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
# Coding Conventions
|
|
2
|
+
|
|
3
|
+
**Analysis Date:** 2026-03-10
|
|
4
|
+
|
|
5
|
+
## Naming Patterns
|
|
6
|
+
|
|
7
|
+
Files:
|
|
8
|
+
|
|
9
|
+
- Pattern: kebab-case for source filenames and CLI commands
|
|
10
|
+
- Examples: `src/create/create.ts`, `src/create/preset/create-preset.ts`, `src/build/build-tsc.ts`
|
|
11
|
+
|
|
12
|
+
Functions:
|
|
13
|
+
|
|
14
|
+
- Pattern: camelCase for free functions and helpers
|
|
15
|
+
- Examples: `replaceTokensInFile` in `src/utils/file-utils.ts`, `createPresetTemplate` in `src/create/preset/create-preset.ts`
|
|
16
|
+
|
|
17
|
+
Variables:
|
|
18
|
+
|
|
19
|
+
- Pattern: camelCase for local variables and constants; use `const` when value is not reassigned
|
|
20
|
+
- Examples: `destPath`, `camelizedName` in `src/create/shape/create-shape.ts`
|
|
21
|
+
|
|
22
|
+
Types / Interfaces:
|
|
23
|
+
|
|
24
|
+
- Pattern: PascalCase for interfaces and type names
|
|
25
|
+
- Examples: `ReplaceTokensOptions`, `ReplaceTokensData` in `src/utils/file-utils.ts`
|
|
26
|
+
|
|
27
|
+
Exports:
|
|
28
|
+
|
|
29
|
+
- Pattern: named exports from modules (no default exports observed)
|
|
30
|
+
- Examples: `export async function replaceTokensInFiles` in `src/utils/file-utils.ts`
|
|
31
|
+
|
|
32
|
+
## Code Style
|
|
33
|
+
|
|
34
|
+
Formatting:
|
|
35
|
+
|
|
36
|
+
- Prettier is used via the package `prettier` and project config referenced in `package.json` (`prettier": "@tsparticles/prettier-config"`).
|
|
37
|
+
- Scripts: `prettify:src`, `prettify:readme`, `prettify:ci:src` in `package.json`
|
|
38
|
+
|
|
39
|
+
Linting:
|
|
40
|
+
|
|
41
|
+
- ESLint is configured in `eslint.config.js` and reuses `@tsparticles/eslint-config` (see `eslint.config.js`).
|
|
42
|
+
- Scripts: `lint` (auto-fix) and `lint:ci` in `package.json`
|
|
43
|
+
- Rule note: `no-console` is disabled in `eslint.config.js` to allow `console` usage in CLI code and tests.
|
|
44
|
+
|
|
45
|
+
TypeScript:
|
|
46
|
+
|
|
47
|
+
- Strict TypeScript settings are enabled in `tsconfig.json` (many `strict` flags set: `strict`, `noImplicitAny`, `noUnusedLocals`, etc.).
|
|
48
|
+
|
|
49
|
+
Doc comments:
|
|
50
|
+
|
|
51
|
+
- Use JSDoc/TSDoc style comments on exported functions and complex helpers.
|
|
52
|
+
- Examples: function headers in `src/utils/string-utils.ts`, `src/utils/template-utils.ts`.
|
|
53
|
+
|
|
54
|
+
## Import Organization
|
|
55
|
+
|
|
56
|
+
- Pattern observed: third-party packages first, then Node built-ins, then local relative imports.
|
|
57
|
+
- Example from `src/create/preset/create-preset.ts`:
|
|
58
|
+
- `import { camelize, capitalize, dash } from "../../utils/string-utils.js";`
|
|
59
|
+
- `import fs from "fs-extra"`; `import path from "node:path"`;
|
|
60
|
+
|
|
61
|
+
Path aliases:
|
|
62
|
+
|
|
63
|
+
- Not detected. Imports use relative paths (e.g., `../../utils/*`) and explicit `.js` extension when imported from tests or other ESM contexts.
|
|
64
|
+
|
|
65
|
+
## Error Handling
|
|
66
|
+
|
|
67
|
+
- Pattern: functions either throw synchronous errors (`throw new Error(...)`) for validation or reject Promises when asynchronous operations fail.
|
|
68
|
+
- Example: `getDestinationDir` throws `new Error("Destination folder already exists and is not empty")` in `src/utils/file-utils.ts`.
|
|
69
|
+
- Example: `runInstall`/`runBuild` use the `exec` callback to `reject(error)` in `src/utils/template-utils.ts`.
|
|
70
|
+
|
|
71
|
+
## Logging
|
|
72
|
+
|
|
73
|
+
- Pattern: CLI code and tests use `console` for informational output and debugging. ESLint `no-console` is turned off to permit this.
|
|
74
|
+
- Files: `src/cli.ts`, tests in `tests/*.test.ts` (see `tests/file-utils.test.ts` where `console.log`/`console.error` is used).
|
|
75
|
+
|
|
76
|
+
## Comments and Documentation
|
|
77
|
+
|
|
78
|
+
- Public helpers include JSDoc comments (examples in `src/utils/*`). Maintain comments for exported functions to describe parameters and return values.
|
|
79
|
+
|
|
80
|
+
## Function & Module Design
|
|
81
|
+
|
|
82
|
+
- Small single-responsibility functions are the norm (examples: `replaceTokensInFiles`, `updatePackageFile`, `copyEmptyTemplateFiles`).
|
|
83
|
+
- Modules export multiple named helpers rather than a default export (see `src/utils/template-utils.ts`).
|
|
84
|
+
|
|
85
|
+
## Barrel files
|
|
86
|
+
|
|
87
|
+
- Not used. Individual modules are imported with relative paths.
|
|
88
|
+
|
|
89
|
+
---
|
|
90
|
+
|
|
91
|
+
_Convention analysis: 2026-03-10_
|
|
@@ -1,3 +1,82 @@
|
|
|
1
|
-
External Integrations
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
# External Integrations
|
|
2
|
+
|
|
3
|
+
**Analysis Date:** 2026-03-10
|
|
4
|
+
|
|
5
|
+
## APIs & External Services
|
|
6
|
+
|
|
7
|
+
This project is a local CLI tool focused on scaffolding and building tsParticles-related packages. There are minimal external service integrations.
|
|
8
|
+
|
|
9
|
+
**Repository / Git:**
|
|
10
|
+
|
|
11
|
+
- Git: CLI uses the `git` binary when available to obtain repository URL (`src/utils/file-utils.ts` uses `lookpath("git")` and executes `git config --get remote.origin.url`). No other GitHub API integration detected.
|
|
12
|
+
|
|
13
|
+
**NPM Registry:**
|
|
14
|
+
|
|
15
|
+
- Publishing: GitHub Actions workflow publishes packages to npm registry (`.github/workflows/npm-publish.yml`) using `pnpm publish` against `https://registry.npmjs.org`.
|
|
16
|
+
- Auth: CI uses OIDC/GitHub Actions environment for authentication as configured in `.github/workflows/npm-publish.yml` (permissions include `id-token: write`).
|
|
17
|
+
|
|
18
|
+
## Data Storage
|
|
19
|
+
|
|
20
|
+
**Databases:**
|
|
21
|
+
|
|
22
|
+
- Not detected. The CLI operates on the local filesystem; no database clients (e.g. PostgreSQL, MongoDB) are referenced in `src/`.
|
|
23
|
+
|
|
24
|
+
**File Storage:**
|
|
25
|
+
|
|
26
|
+
- Local filesystem via `fs-extra` (`src/utils/file-utils.ts` and many create/template helpers). Templates are copied from `files/*` into target directories (`src/create/*`, e.g. `src/create/plugin/create-plugin.ts` uses `files/create-plugin`).
|
|
27
|
+
|
|
28
|
+
**Caching:**
|
|
29
|
+
|
|
30
|
+
- Not detected. No Redis or in-process caching libraries observed.
|
|
31
|
+
|
|
32
|
+
## Authentication & Identity
|
|
33
|
+
|
|
34
|
+
**Auth Provider:**
|
|
35
|
+
|
|
36
|
+
- None for runtime. CI publishes to npm using GitHub Actions OIDC flow (see `.github/workflows/npm-publish.yml`). There are no runtime OAuth or Identity providers integrated into the CLI.
|
|
37
|
+
|
|
38
|
+
## Monitoring & Observability
|
|
39
|
+
|
|
40
|
+
**Error Tracking:**
|
|
41
|
+
|
|
42
|
+
- Not detected. No Sentry, Datadog, or similar SDKs in dependencies.
|
|
43
|
+
|
|
44
|
+
**Logs:**
|
|
45
|
+
|
|
46
|
+
- Console logging used throughout the CLI (`console.log`, `console.warn`, `console.error`). See `src/build/*` and `src/create/*` for examples (e.g. `src/build/build.ts`, `src/build/build-prettier.ts`).
|
|
47
|
+
|
|
48
|
+
## CI/CD & Deployment
|
|
49
|
+
|
|
50
|
+
**Hosting:**
|
|
51
|
+
|
|
52
|
+
- NPM registry for package distribution. Source is maintained in GitHub and CI runs on GitHub Actions (`.github/workflows/*`).
|
|
53
|
+
|
|
54
|
+
**CI Pipeline:**
|
|
55
|
+
|
|
56
|
+
- GitHub Actions pipelines:
|
|
57
|
+
- `Node.js CI` (`.github/workflows/node.js-ci.yml`) runs on push and PRs to `main`: installs via `pnpm install`, runs `pnpm run build:ci` and `pnpm test`.
|
|
58
|
+
- `Publish Packages` (`.github/workflows/npm-publish.yml`) publishes tags `v*` to npm, using OIDC-based auth and `pnpm publish`.
|
|
59
|
+
|
|
60
|
+
## Environment Configuration
|
|
61
|
+
|
|
62
|
+
**Required env vars:**
|
|
63
|
+
|
|
64
|
+
- Not enforced in repo code. CI publishing relies on GitHub Actions OIDC configured in workflow; no runtime environment variables are required by the CLI itself.
|
|
65
|
+
|
|
66
|
+
**Secrets location:**
|
|
67
|
+
|
|
68
|
+
- Not present in repo. CI uses OIDC in the publish workflow. No local secrets files detected (no `.env`).
|
|
69
|
+
|
|
70
|
+
## Webhooks & Callbacks
|
|
71
|
+
|
|
72
|
+
**Incoming:**
|
|
73
|
+
|
|
74
|
+
- Not detected. This is a CLI tool; it does not expose HTTP endpoints.
|
|
75
|
+
|
|
76
|
+
**Outgoing:**
|
|
77
|
+
|
|
78
|
+
- Not detected. The CLI does not make outbound HTTP API calls; templates and README files reference public CDNs (jsDelivr) and GitHub URLs but no HTTP client libraries are used.
|
|
79
|
+
|
|
80
|
+
---
|
|
81
|
+
|
|
82
|
+
_Integration audit: 2026-03-10_
|
|
@@ -1,11 +1,91 @@
|
|
|
1
|
-
|
|
1
|
+
# Technology Stack
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
- TypeScript (src/)
|
|
5
|
-
- Node.js for CLI
|
|
3
|
+
**Analysis Date:** 2026-03-10
|
|
6
4
|
|
|
7
|
-
|
|
8
|
-
- Vitest, tsc, pnpm
|
|
5
|
+
## Languages
|
|
9
6
|
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
**Primary:**
|
|
8
|
+
|
|
9
|
+
- TypeScript 5.x (project uses `typescript` ^5.9.3) - used across CLI source under `src/` (`src/**/*.ts`). See `package.json` and `tsconfig.json` (`package.json`: `dependencies`/`devDependencies`, `tsconfig.json`: `compilerOptions`).
|
|
10
|
+
|
|
11
|
+
**Secondary:**
|
|
12
|
+
|
|
13
|
+
- JavaScript (Node ESM runtime output in `dist/` / CLI entry `dist/cli.js`) - `package.json` `type: "module"` and `bin` field (`package.json`).
|
|
14
|
+
|
|
15
|
+
## Runtime
|
|
16
|
+
|
|
17
|
+
**Environment:**
|
|
18
|
+
|
|
19
|
+
- Node.js (ES module, NodeNext resolution). CI workflows use Node 24 (`.github/workflows/node.js-ci.yml`). `tsconfig.json` `module: "NodeNext"`, `target: "ESNext"`.
|
|
20
|
+
|
|
21
|
+
**Package Manager:**
|
|
22
|
+
|
|
23
|
+
- pnpm (project declares `packageManager: "pnpm@10.32.0"` in `package.json`, lock file `pnpm-lock.yaml` present).
|
|
24
|
+
- Lockfile: `pnpm-lock.yaml` (present).
|
|
25
|
+
|
|
26
|
+
## Frameworks
|
|
27
|
+
|
|
28
|
+
**Core:**
|
|
29
|
+
|
|
30
|
+
- None web-framework-specific. This is a CLI application built with Node and TypeScript. CLI command framework: `commander` (`package.json` -> `dependencies`), commands live in `src/cli.ts`, `src/build/*`, `src/create/*`.
|
|
31
|
+
|
|
32
|
+
**Testing:**
|
|
33
|
+
|
|
34
|
+
- Vitest (`vitest` ^4.x) - config file: `vitest.config.ts`, tests located in `tests/*.test.ts`.
|
|
35
|
+
|
|
36
|
+
**Build/Dev:**
|
|
37
|
+
|
|
38
|
+
- TypeScript compiler (`tsc`) is used for building (`scripts.build:ts*` in `package.json`, `tsconfig.json` and `src/tsconfig.json`).
|
|
39
|
+
- Prettier for formatting (configured via dependency `@tsparticles/prettier-config` referenced in `package.json`). Prettier is run by `src/build/build-prettier.ts` and scripts in `package.json`.
|
|
40
|
+
- ESLint (`eslint`) with `@tsparticles/eslint-config` - linting run in `src/build/build-eslint.ts` and via `package.json` scripts.
|
|
41
|
+
- Webpack used for bundling (dependency `webpack`, `swc-loader`, `@swc/core`) - bundling logic in `src/build/build-bundle.ts`.
|
|
42
|
+
- dependency-cruiser used for circular dependency checks - config `.dependency-cruiser.cjs` and script `circular-deps` in `package.json`.
|
|
43
|
+
|
|
44
|
+
## Key Dependencies
|
|
45
|
+
|
|
46
|
+
**Critical:**
|
|
47
|
+
|
|
48
|
+
- `typescript` ^5.9.3 - primary language toolchain (`package.json`).
|
|
49
|
+
- `commander` ^14.x - CLI command framework (`src/cli.ts`, `package.json`).
|
|
50
|
+
- `fs-extra` ^11.x - filesystem utilities used widely (`src/utils/file-utils.ts`, `package.json`).
|
|
51
|
+
- `prettier` ^3.8.x - formatting; project references `@tsparticles/prettier-config` (`package.json`).
|
|
52
|
+
- `eslint` ^10.x and TypeScript ESLint tooling (`package.json`, `src/build/build-eslint.ts`).
|
|
53
|
+
|
|
54
|
+
**Infrastructure / Build:**
|
|
55
|
+
|
|
56
|
+
- `webpack` ^5.x, `swc-loader`, `@swc/core` - bundling and fast transpilation (`package.json`, `src/build/build-bundle.ts`).
|
|
57
|
+
- `vitest` ^4.x - test runner (`vitest.config.ts`, `package.json`).
|
|
58
|
+
- `klaw` - used by prettier tooling to walk folders (`src/build/build-prettier.ts`).
|
|
59
|
+
|
|
60
|
+
**Utilities:**
|
|
61
|
+
|
|
62
|
+
- `prompts` - interactive prompts used in templates/generator code (`package.json`, `src/create/*`).
|
|
63
|
+
- `lookpath` - used to detect `git` presence in `src/utils/file-utils.ts`.
|
|
64
|
+
|
|
65
|
+
## Configuration
|
|
66
|
+
|
|
67
|
+
**Environment:**
|
|
68
|
+
|
|
69
|
+
- No project-level `.env` files detected. The CLI uses the local environment (executes `git` where available). See `src/utils/file-utils.ts` (calls `lookpath("git")` and runs `git config --get remote.origin.url`).
|
|
70
|
+
|
|
71
|
+
**Build:**
|
|
72
|
+
|
|
73
|
+
- TypeScript config: `tsconfig.json` (root) and `src/tsconfig.json` (per-source) - `module: NodeNext`, `target: ESNext`, strict compiler options.
|
|
74
|
+
- Linting config is provided by `@tsparticles/eslint-config` (referenced in `package.json`). A dependency-cruiser configuration is present at `.dependency-cruiser.cjs`.
|
|
75
|
+
- Prettier config is supplied via `@tsparticles/prettier-config` and `package.json` scripts rely on `src/build/build-prettier.ts`.
|
|
76
|
+
|
|
77
|
+
## Platform Requirements
|
|
78
|
+
|
|
79
|
+
**Development:**
|
|
80
|
+
|
|
81
|
+
- Node.js >= 24 recommended (CI uses Node 24 in `.github/workflows/node.js-ci.yml`).
|
|
82
|
+
- pnpm >= 10.x (project `packageManager` sets `pnpm@10.32.0`).
|
|
83
|
+
- Git CLI for repository URL resolution used by templates (`src/utils/file-utils.ts`).
|
|
84
|
+
|
|
85
|
+
**Production / Publishing:**
|
|
86
|
+
|
|
87
|
+
- Packages are published to npm registry (see `.github/workflows/npm-publish.yml`). The CI uses GitHub Actions and OIDC for auth when publishing (`.github/workflows/npm-publish.yml`).
|
|
88
|
+
|
|
89
|
+
---
|
|
90
|
+
|
|
91
|
+
_Stack analysis: 2026-03-10_
|
|
@@ -1,3 +1,138 @@
|
|
|
1
|
-
Structure
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
# Codebase Structure
|
|
2
|
+
|
|
3
|
+
**Analysis Date:** 2026-03-10
|
|
4
|
+
|
|
5
|
+
## Directory Layout
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
[project-root]/
|
|
9
|
+
├── src/ # TypeScript source for CLI and build tasks
|
|
10
|
+
│ ├── cli.ts # CLI entrypoint (registers commands)
|
|
11
|
+
│ ├── create/ # "create" command and subcommands
|
|
12
|
+
│ │ ├── create.ts
|
|
13
|
+
│ │ ├── plugin/
|
|
14
|
+
│ │ │ ├── plugin.ts
|
|
15
|
+
│ │ │ └── create-plugin.ts
|
|
16
|
+
│ │ ├── preset/
|
|
17
|
+
│ │ │ ├── preset.ts
|
|
18
|
+
│ │ │ └── create-preset.ts
|
|
19
|
+
│ │ └── shape/
|
|
20
|
+
│ │ ├── shape.ts
|
|
21
|
+
│ │ └── create-shape.ts
|
|
22
|
+
│ ├── build/ # Build helper commands/tasks
|
|
23
|
+
│ │ ├── build.ts
|
|
24
|
+
│ │ ├── build-tsc.ts
|
|
25
|
+
│ │ ├── build-bundle.ts
|
|
26
|
+
│ │ └── ...
|
|
27
|
+
│ └── utils/ # Shared utilities
|
|
28
|
+
│ ├── file-utils.ts
|
|
29
|
+
│ ├── template-utils.ts
|
|
30
|
+
│ └── string-utils.ts
|
|
31
|
+
├── files/ # Template files used by generators (not under src/ but referenced)
|
|
32
|
+
├── tests/ # Vitest unit tests
|
|
33
|
+
├── dist/ # Compiled ESM output (generated)
|
|
34
|
+
├── package.json
|
|
35
|
+
├── pnpm-lock.yaml
|
|
36
|
+
├── tsconfig.json
|
|
37
|
+
└── .planning/ # Mapping and planning docs
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Directory Purposes
|
|
41
|
+
|
|
42
|
+
**src/**:
|
|
43
|
+
|
|
44
|
+
- Purpose: Source code for the CLI tool and internal build tasks.
|
|
45
|
+
- Contains: Command modules (`src/create/*`), build tasks (`src/build/*`), utilities (`src/utils/*`).
|
|
46
|
+
- Key files: `src/cli.ts`, `src/create/create.ts`, `src/create/preset/create-preset.ts`.
|
|
47
|
+
|
|
48
|
+
**src/create/**:
|
|
49
|
+
|
|
50
|
+
- Purpose: Implements the `create` command and its subcommands.
|
|
51
|
+
- Contains: `plugin`, `preset`, `shape` subfolders each exposing a `Command` instance and a template-creation implementation (`create-*.ts`).
|
|
52
|
+
- Key files: `src/create/preset/preset.ts`, `src/create/preset/create-preset.ts`.
|
|
53
|
+
|
|
54
|
+
**src/build/**:
|
|
55
|
+
|
|
56
|
+
- Purpose: Build and CI helper tasks used by `pnpm run build` and `build` CLI command.
|
|
57
|
+
- Contains: modular build steps: `build-prettier.ts`, `build-eslint.ts`, `build-tsc.ts`, bundling helpers.
|
|
58
|
+
- Key files: `src/build/build.ts` (aggregator), `src/build/build-tsc.ts`.
|
|
59
|
+
|
|
60
|
+
**src/utils/**:
|
|
61
|
+
|
|
62
|
+
- Purpose: Shared helpers for filesystem operations, string handling, and template updates.
|
|
63
|
+
- Contains: `file-utils.ts` (`replaceTokensInFile`, `getDestinationDir`), `template-utils.ts` (`runInstall`, `runBuild`, `updatePackageFile`).
|
|
64
|
+
|
|
65
|
+
**files/**:
|
|
66
|
+
|
|
67
|
+
- Purpose: Template projects that are copied into new destinations by `create` commands.
|
|
68
|
+
- Note: Referenced by `src/create/*` code via relative paths (e.g., `path.join(__dirname, "..", "..", "files", "create-preset")` in `src/create/preset/create-preset.ts`).
|
|
69
|
+
|
|
70
|
+
**tests/**:
|
|
71
|
+
|
|
72
|
+
- Purpose: Unit tests using Vitest for template creation behavior.
|
|
73
|
+
- Contains: `tests/create-shape.test.ts`, `tests/create-preset.test.ts`.
|
|
74
|
+
|
|
75
|
+
## Key File Locations
|
|
76
|
+
|
|
77
|
+
Entry Points:
|
|
78
|
+
|
|
79
|
+
- `src/cli.ts`: boots the program, reads package version from `package.json`, registers `build` and `create` commands.
|
|
80
|
+
|
|
81
|
+
Create commands:
|
|
82
|
+
|
|
83
|
+
- `src/create/create.ts`: aggregates subcommands.
|
|
84
|
+
- `src/create/preset/preset.ts`: CLI surface for `preset` command.
|
|
85
|
+
- `src/create/preset/create-preset.ts`: implementation that writes files and runs install/build.
|
|
86
|
+
|
|
87
|
+
Utilities:
|
|
88
|
+
|
|
89
|
+
- `src/utils/file-utils.ts`: token replacement helpers and repository detection.
|
|
90
|
+
- `src/utils/template-utils.ts`: file copying, package updates and running `npm` commands.
|
|
91
|
+
|
|
92
|
+
Build tasks:
|
|
93
|
+
|
|
94
|
+
- `src/build/build.ts`: orchestration of build steps called both in CI and local `pnpm run build`.
|
|
95
|
+
|
|
96
|
+
## Naming Conventions
|
|
97
|
+
|
|
98
|
+
Files:
|
|
99
|
+
|
|
100
|
+
- Pattern: kebab-case for file names that represent commands or grouped concerns (e.g., `create-preset.ts`, `build-tsc.ts`).
|
|
101
|
+
- Source modules are TypeScript (`.ts`) compiled to ESM JS in `dist/`.
|
|
102
|
+
|
|
103
|
+
Directories:
|
|
104
|
+
|
|
105
|
+
- Pattern: singular, descriptive names (`create`, `build`, `utils`, `files`).
|
|
106
|
+
|
|
107
|
+
## Where to Add New Code
|
|
108
|
+
|
|
109
|
+
New Feature (CLI command):
|
|
110
|
+
|
|
111
|
+
- Primary code: add a new command module under `src/<feature>/` or create a subcommand under `src/create/`.
|
|
112
|
+
- Registration: register the new `Command` in `src/cli.ts` or in `src/create/create.ts` for `create`-subcommands.
|
|
113
|
+
- Tests: add unit tests under `tests/` following existing patterns (`tests/<feature>.test.ts`).
|
|
114
|
+
|
|
115
|
+
New Utility:
|
|
116
|
+
|
|
117
|
+
- Implementation: add new helper in `src/utils/` and export named functions; reuse in command modules.
|
|
118
|
+
- Examples: `src/utils/new-util.ts` and update `src/utils/index.ts` (if created) to re-export it.
|
|
119
|
+
|
|
120
|
+
Templates and Files:
|
|
121
|
+
|
|
122
|
+
- Add new templates under `files/` and reference them from create implementations using `path.join(__dirname, "..", "..", "files", "<template>")`.
|
|
123
|
+
|
|
124
|
+
## Special Directories
|
|
125
|
+
|
|
126
|
+
dist/:
|
|
127
|
+
|
|
128
|
+
- Purpose: Compiled ESM output for packaging and the `bin` entry (`dist/cli.js`).
|
|
129
|
+
- Generated: Yes
|
|
130
|
+
- Committed: No (should be generated during build)
|
|
131
|
+
|
|
132
|
+
tests/tmp-files/:
|
|
133
|
+
|
|
134
|
+
- Purpose: Tests write temporary projects into `tests/tmp-files/*` during execution and remove them afterwards (see `tests/*.test.ts`).
|
|
135
|
+
|
|
136
|
+
---
|
|
137
|
+
|
|
138
|
+
_Structure analysis: 2026-03-10_
|