@tsparticles/cli-command-create-app 4.1.3

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.
@@ -0,0 +1,2 @@
1
+ since 2021
2
+ not dead
@@ -0,0 +1,230 @@
1
+ /** @type {import('dependency-cruiser').IConfiguration} */
2
+ module.exports = {
3
+ forbidden: [
4
+ {
5
+ name: 'no-circular',
6
+ severity: 'warn',
7
+ comment:
8
+ "This dependency is part of a circular relationship. You might want to revise " +
9
+ "your solution (i.e. use dependency inversion, make sure the modules have a single responsibility) ",
10
+ from: {},
11
+ to: {
12
+ circular: true
13
+ }
14
+ },
15
+ {
16
+ name: 'no-orphans',
17
+ comment:
18
+ "This is an orphan module - it's likely not used (anymore?). Either use it or " +
19
+ "remove it. If it's logical this module is an orphan (i.e. it's a config file), " +
20
+ "add an exception for it in your dependency-cruiser configuration. By default " +
21
+ "this rule does not scrutinize dot-files (e.g. .eslintrc.js), TypeScript declaration " +
22
+ "files (.d.ts), tsconfig.json and some of the babel and webpack configs.",
23
+ severity: 'warn',
24
+ from: {
25
+ orphan: true,
26
+ pathNot: [
27
+ '(^|/)[.][^/]+[.](?:js|cjs|mjs|ts|cts|mts|json)$',
28
+ '[.]d[.]ts$',
29
+ '(^|/)tsconfig[.]json$',
30
+ '(^|/)(?:babel|webpack)[.]config[.](?:js|cjs|mjs|ts|cts|mts|json)$'
31
+ ]
32
+ },
33
+ to: {},
34
+ },
35
+ {
36
+ name: 'no-deprecated-core',
37
+ comment:
38
+ 'A module depends on a node core module that has been deprecated. Find an alternative - these are ' +
39
+ "bound to exist - node doesn't deprecate lightly.",
40
+ severity: 'warn',
41
+ from: {},
42
+ to: {
43
+ dependencyTypes: [
44
+ 'core'
45
+ ],
46
+ path: [
47
+ '^v8/tools/codemap$',
48
+ '^v8/tools/consarray$',
49
+ '^v8/tools/csvparser$',
50
+ '^v8/tools/logreader$',
51
+ '^v8/tools/profile_view$',
52
+ '^v8/tools/profile$',
53
+ '^v8/tools/SourceMap$',
54
+ '^v8/tools/splaytree$',
55
+ '^v8/tools/tickprocessor-driver$',
56
+ '^v8/tools/tickprocessor$',
57
+ '^node-inspect/lib/_inspect$',
58
+ '^node-inspect/lib/internal/inspect_client$',
59
+ '^node-inspect/lib/internal/inspect_repl$',
60
+ '^async_hooks$',
61
+ '^punycode$',
62
+ '^domain$',
63
+ '^constants$',
64
+ '^sys$',
65
+ '^_linklist$',
66
+ '^_stream_wrap$'
67
+ ],
68
+ }
69
+ },
70
+ {
71
+ name: 'not-to-deprecated',
72
+ comment:
73
+ 'This module uses a (version of an) npm module that has been deprecated. Either upgrade to a later ' +
74
+ 'version of that module, or find an alternative. Deprecated modules are a security risk.',
75
+ severity: 'warn',
76
+ from: {},
77
+ to: {
78
+ dependencyTypes: [
79
+ 'deprecated'
80
+ ]
81
+ }
82
+ },
83
+ {
84
+ name: 'no-non-package-json',
85
+ severity: 'error',
86
+ comment:
87
+ "This module depends on an npm package that isn't in the 'dependencies' section of your package.json. " +
88
+ "That's problematic as the package either (1) won't be available on live (2 - worse) will be " +
89
+ "available on live with an non-guaranteed version. Fix it by adding the package to the dependencies " +
90
+ "in your package.json.",
91
+ from: {},
92
+ to: {
93
+ dependencyTypes: [
94
+ 'npm-no-pkg',
95
+ 'npm-unknown'
96
+ ]
97
+ }
98
+ },
99
+ {
100
+ name: 'not-to-unresolvable',
101
+ comment:
102
+ "This module depends on a module that cannot be found ('resolved to disk'). If it's an npm " +
103
+ 'module: add it to your package.json. In all other cases you likely already know what to do.',
104
+ severity: 'error',
105
+ from: {},
106
+ to: {
107
+ couldNotResolve: true
108
+ }
109
+ },
110
+ {
111
+ name: 'no-duplicate-dep-types',
112
+ comment:
113
+ "Likely this module depends on an external ('npm') package that occurs more than once " +
114
+ "in your package.json i.e. bot as a devDependencies and in dependencies. This will cause " +
115
+ "maintenance problems later on.",
116
+ severity: 'warn',
117
+ from: {},
118
+ to: {
119
+ moreThanOneDependencyType: true,
120
+ dependencyTypesNot: ["type-only"]
121
+ }
122
+ },
123
+ {
124
+ name: 'not-to-test',
125
+ comment:
126
+ "This module depends on code within a folder that should only contain tests. As tests don't " +
127
+ "implement functionality this is odd. Either you're writing a test outside the test folder " +
128
+ "or there's something in the test folder that isn't a test.",
129
+ severity: 'error',
130
+ from: {
131
+ pathNot: '^(tests)'
132
+ },
133
+ to: {
134
+ path: '^(tests)'
135
+ }
136
+ },
137
+ {
138
+ name: 'not-to-spec',
139
+ comment:
140
+ 'This module depends on a spec (test) file. The responsibility of a spec file is to test code. ' +
141
+ "If there's something in a spec that's of use to other modules, it doesn't have that single " +
142
+ 'responsibility anymore. Factor it out into (e.g.) a separate utility/ helper or a mock.',
143
+ severity: 'error',
144
+ from: {},
145
+ to: {
146
+ path: '[.](?:spec|test)[.](?:js|mjs|cjs|jsx|ts|mts|cts|tsx)$'
147
+ }
148
+ },
149
+ {
150
+ name: 'not-to-dev-dep',
151
+ severity: 'error',
152
+ comment:
153
+ "This module depends on an npm package from the 'devDependencies' section of your " +
154
+ 'package.json. It looks like something that ships to production, though. To prevent problems ' +
155
+ "with npm packages that aren't there on production declare it (only!) in the 'dependencies'" +
156
+ 'section of your package.json. If this module is development only - add it to the ' +
157
+ 'from.pathNot re of the not-to-dev-dep rule in the dependency-cruiser configuration',
158
+ from: {
159
+ path: '^(src)',
160
+ pathNot: '[.](?:spec|test)[.](?:js|mjs|cjs|jsx|ts|mts|cts|tsx)$'
161
+ },
162
+ to: {
163
+ dependencyTypes: [
164
+ 'npm-dev',
165
+ ],
166
+ dependencyTypesNot: [
167
+ 'type-only'
168
+ ],
169
+ pathNot: [
170
+ 'node_modules/@types/'
171
+ ]
172
+ }
173
+ },
174
+ {
175
+ name: 'optional-deps-used',
176
+ severity: 'info',
177
+ comment:
178
+ "This module depends on an npm package that is declared as an optional dependency " +
179
+ "in your package.json. As this makes sense in limited situations only, it's flagged here. " +
180
+ "If you use an optional dependency here by design - add an exception to your" +
181
+ "dependency-cruiser configuration.",
182
+ from: {},
183
+ to: {
184
+ dependencyTypes: [
185
+ 'npm-optional'
186
+ ]
187
+ }
188
+ },
189
+ {
190
+ name: 'peer-deps-used',
191
+ comment:
192
+ "This module depends on an npm package that is declared as a peer dependency " +
193
+ "in your package.json. This makes sense if your package is e.g. a plugin, but in " +
194
+ "other cases - maybe not so much. If the use of a peer dependency is intentional " +
195
+ "add an exception to your dependency-cruiser configuration.",
196
+ severity: 'warn',
197
+ from: {},
198
+ to: {
199
+ dependencyTypes: [
200
+ 'npm-peer'
201
+ ]
202
+ }
203
+ }
204
+ ],
205
+ options: {
206
+ doNotFollow: {
207
+ path: ['node_modules']
208
+ },
209
+ tsConfig: {
210
+ fileName: 'src/tsconfig.json'
211
+ },
212
+ enhancedResolveOptions: {
213
+ exportsFields: ['exports'],
214
+ conditionNames: ['import', 'require', 'node', 'default', 'types'],
215
+ mainFields: ["module", "main", "types", "typings"],
216
+ },
217
+ skipAnalysisNotInRules: true,
218
+ reporterOptions: {
219
+ dot: {
220
+ collapsePattern: 'node_modules/(?:@[^/]+/[^/]+|[^/]+)',
221
+ },
222
+ archi: {
223
+ collapsePattern: '^(?:packages|src|lib(s?)|app(s?)|bin|test(s?)|spec(s?))/[^/]+|node_modules/(?:@[^/]+/[^/]+|[^/]+)',
224
+ },
225
+ text: {
226
+ highlightFocused: true
227
+ },
228
+ }
229
+ }
230
+ };
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020 Matteo Bruni
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,11 @@
1
+ # @tsparticles/cli-command-create-app
2
+
3
+ ## Build
4
+
5
+ ```bash
6
+ pnpm run build
7
+ ```
8
+
9
+ ## License
10
+
11
+ MIT
package/dist/app.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ import { Command } from "commander";
2
+ declare const appCreateCommand: Command;
3
+ export { appCreateCommand };
package/dist/app.js ADDED
@@ -0,0 +1,28 @@
1
+ import { promptAppData } from "./prompts.js";
2
+ import { Command } from "commander";
3
+ import { createAppProject } from "./scaffold.js";
4
+ const appCreateCommand = new Command("app");
5
+ appCreateCommand.description("Create a new tsParticles app from a template");
6
+ appCreateCommand.argument("[destination]", "Destination folder (defaults to project name)");
7
+ appCreateCommand.option("--framework <name>", "Framework (vanilla|react|vue3|angular|svelte|solid)");
8
+ appCreateCommand.option("--skip-install", "Skip npm install after scaffolding");
9
+ appCreateCommand.option("--template <name>", "Template to use (scaffold|login|portfolio|landing|tictactoe|confetti|ribbons|particles)");
10
+ appCreateCommand.action(async (destination, options) => {
11
+ const destArg = destination ?? "tsparticles-app", template = options.template, framework = options.framework, skipInstall = options.skipInstall ?? false, data = await promptAppData(destArg, {
12
+ framework,
13
+ projectName: undefined,
14
+ useCase: template,
15
+ }), result = await createAppProject({
16
+ destination: data.destinationPath,
17
+ framework: data.framework,
18
+ projectName: data.projectName,
19
+ skipInstall,
20
+ useCase: data.useCase,
21
+ });
22
+ console.log(`\nProject created successfully at ${result.targetDir}`);
23
+ console.log("Run the following commands to get started:\n");
24
+ console.log(` cd ${result.targetDir}`);
25
+ console.log(skipInstall ? " npm install" : "");
26
+ console.log(" npm run dev\n");
27
+ });
28
+ export { appCreateCommand };
@@ -0,0 +1,21 @@
1
+ export type Framework = "vanilla" | "react" | "vue3" | "angular" | "svelte" | "solid";
2
+ export type UseCase = "none" | "login" | "portfolio" | "landing" | "tictactoe" | "confetti" | "ribbons" | "particles";
3
+ export interface IAppPromptResult {
4
+ destinationPath: string;
5
+ framework: Framework;
6
+ projectName: string;
7
+ useCase: UseCase;
8
+ }
9
+ /**
10
+ *
11
+ * @param destination
12
+ * @param prefill
13
+ * @param prefill.framework
14
+ * @param prefill.projectName
15
+ * @param prefill.useCase
16
+ */
17
+ export declare function promptAppData(destination: string, prefill?: {
18
+ framework?: Framework;
19
+ projectName?: string;
20
+ useCase?: UseCase;
21
+ }): Promise<IAppPromptResult>;
@@ -0,0 +1,75 @@
1
+ import { getDestinationDir, getRepositoryUrl } from "@tsparticles/cli-create-utils";
2
+ import path from "node:path";
3
+ import prompts from "prompts";
4
+ const initialFrameworkIndex = 0, initialUseCaseIndex = 0, frameworkChoices = [
5
+ { title: "Vanilla (Vite + TypeScript)", value: "vanilla" },
6
+ { title: "React", value: "react" },
7
+ { title: "Vue 3", value: "vue3" },
8
+ { title: "Angular", value: "angular" },
9
+ { title: "Svelte", value: "svelte" },
10
+ { title: "Solid", value: "solid" },
11
+ ], useCaseChoices = [
12
+ { title: "None (just the scaffold)", value: "none" },
13
+ { title: "Login / Register", value: "login" },
14
+ { title: "Portfolio", value: "portfolio" },
15
+ { title: "Landing Page", value: "landing" },
16
+ { title: "Tic Tac Toe", value: "tictactoe" },
17
+ { title: "Confetti", value: "confetti" },
18
+ { title: "Ribbons", value: "ribbons" },
19
+ { title: "Particles", value: "particles" },
20
+ ];
21
+ /**
22
+ *
23
+ * @param destination
24
+ * @param prefill
25
+ * @param prefill.framework
26
+ * @param prefill.projectName
27
+ * @param prefill.useCase
28
+ */
29
+ export async function promptAppData(destination, prefill) {
30
+ const destinationPath = await getDestinationDir(destination), repositoryUrl = await getRepositoryUrl(), initialName = destinationPath.split(path.sep).pop() ?? "tsparticles-app";
31
+ void repositoryUrl;
32
+ const questions = [];
33
+ if (!prefill?.projectName) {
34
+ questions.push({
35
+ type: "text",
36
+ name: "projectName",
37
+ message: "What is the project name?",
38
+ validate: (value) => (value ? true : "The project name can't be empty"),
39
+ initial: initialName,
40
+ });
41
+ }
42
+ if (!prefill?.framework) {
43
+ questions.push({
44
+ type: "select",
45
+ name: "framework",
46
+ message: "Which framework would you like to use?",
47
+ choices: frameworkChoices,
48
+ initial: initialFrameworkIndex,
49
+ });
50
+ }
51
+ if (!prefill?.useCase) {
52
+ questions.push({
53
+ type: "select",
54
+ name: "useCase",
55
+ message: "Which use-case template would you like to include?",
56
+ choices: useCaseChoices,
57
+ initial: initialUseCaseIndex,
58
+ });
59
+ }
60
+ if (!questions.length) {
61
+ return {
62
+ destinationPath,
63
+ framework: prefill?.framework ?? "vanilla",
64
+ projectName: prefill?.projectName ?? initialName,
65
+ useCase: prefill?.useCase ?? "none",
66
+ };
67
+ }
68
+ const answers = (await prompts(questions));
69
+ return {
70
+ destinationPath,
71
+ framework: prefill?.framework ?? answers.framework ?? "vanilla",
72
+ projectName: (prefill?.projectName ?? answers.projectName ?? initialName).trim(),
73
+ useCase: prefill?.useCase ?? answers.useCase ?? "none",
74
+ };
75
+ }
@@ -0,0 +1,10 @@
1
+ import type { ScaffoldResult, UserOptions } from "./types.js";
2
+ import type { Framework, UseCase } from "./prompts.js";
3
+ /**
4
+ *
5
+ * @param options
6
+ */
7
+ export declare function createAppProject(options: UserOptions & {
8
+ framework: Framework;
9
+ useCase: UseCase;
10
+ }): Promise<ScaffoldResult>;
@@ -0,0 +1,128 @@
1
+ /* eslint-disable sort-imports */
2
+ import { runInstall, dash } from "@tsparticles/cli-create-utils";
3
+ import { mkdir, readFile, readdir, writeFile } from "node:fs/promises";
4
+ import { existsSync } from "node:fs";
5
+ import path from "node:path";
6
+ import { resolveEngineVersion, resolveTemplateRoot } from "./template-resolver.js";
7
+ const jsonIndentation = 2, useCaseTemplateNames = {
8
+ none: undefined,
9
+ login: "login",
10
+ portfolio: "portfolio",
11
+ landing: "landing",
12
+ tictactoe: "tictactoe",
13
+ confetti: "confetti",
14
+ ribbons: "ribbons",
15
+ particles: "particles",
16
+ };
17
+ /**
18
+ *
19
+ * @param options
20
+ */
21
+ export async function createAppProject(options) {
22
+ const { projectName, framework, skipInstall, useCase } = options, targetDir = options.destination, packageName = dash(projectName), version = resolveEngineVersion(), replacements = {
23
+ "{{projectName}}": projectName,
24
+ "{{packageName}}": packageName,
25
+ "{{version}}": version,
26
+ };
27
+ let mergedDeps = {};
28
+ const scaffoldRoot = resolveTemplateRoot("scaffold"), scaffoldDeps = await readTemplateJson(scaffoldRoot);
29
+ if (scaffoldDeps) {
30
+ mergedDeps = deepMergeDeps(mergedDeps, scaffoldDeps);
31
+ }
32
+ const scaffoldSource = path.join(scaffoldRoot, "template", framework);
33
+ if (!existsSync(path.join(scaffoldSource, "package.json"))) {
34
+ throw new Error(`Scaffold template not found for framework "${framework}". Looked at: ${scaffoldSource}. Available frameworks: check template directories.`);
35
+ }
36
+ await mkdir(targetDir, { recursive: true });
37
+ await copyAndReplace(scaffoldSource, targetDir, replacements);
38
+ if (useCase !== "none") {
39
+ const ucTemplateName = useCaseTemplateNames[useCase];
40
+ if (ucTemplateName) {
41
+ const ucRoot = resolveTemplateRoot(ucTemplateName), ucDeps = await readTemplateJson(ucRoot);
42
+ if (ucDeps) {
43
+ mergedDeps = deepMergeDeps(mergedDeps, ucDeps);
44
+ }
45
+ const ucSource = path.join(ucRoot, "template", framework);
46
+ if (existsSync(path.join(ucSource, "package.json"))) {
47
+ await copyAndReplace(ucSource, targetDir, replacements);
48
+ }
49
+ }
50
+ }
51
+ if (mergedDeps.dependencies || mergedDeps.devDependencies) {
52
+ const pkgJsonPath = path.join(targetDir, "package.json"), pkg = JSON.parse(await readFile(pkgJsonPath, "utf-8"));
53
+ if (mergedDeps.dependencies) {
54
+ const existingDeps = (pkg.dependencies ?? {});
55
+ pkg.dependencies = { ...mergedDeps.dependencies, ...existingDeps };
56
+ }
57
+ if (mergedDeps.devDependencies) {
58
+ const existingDevDeps = (pkg.devDependencies ?? {});
59
+ pkg.devDependencies = { ...mergedDeps.devDependencies, ...existingDevDeps };
60
+ }
61
+ await writeFile(pkgJsonPath, `${JSON.stringify(pkg, undefined, jsonIndentation)}\n`);
62
+ }
63
+ if (!skipInstall) {
64
+ await runInstall(targetDir);
65
+ }
66
+ return {
67
+ frameworkUsed: framework,
68
+ targetDir,
69
+ templateUsed: useCase === "none" ? "scaffold" : useCase,
70
+ };
71
+ }
72
+ /**
73
+ *
74
+ * @param templateRoot
75
+ */
76
+ async function readTemplateJson(templateRoot) {
77
+ const templateJsonPath = path.join(templateRoot, "template.json");
78
+ if (!existsSync(templateJsonPath)) {
79
+ return null;
80
+ }
81
+ const content = JSON.parse(await readFile(templateJsonPath, "utf-8"));
82
+ return content.package ?? null;
83
+ }
84
+ /**
85
+ *
86
+ * @param src
87
+ * @param dest
88
+ * @param replacements
89
+ */
90
+ async function copyAndReplace(src, dest, replacements) {
91
+ const entries = await readdir(src, { withFileTypes: true });
92
+ for (const entry of entries) {
93
+ const srcPath = path.join(src, entry.name);
94
+ let destName = entry.name;
95
+ if (destName === "gitignore") {
96
+ destName = ".gitignore";
97
+ }
98
+ const destPath = path.join(dest, destName);
99
+ if (entry.isDirectory()) {
100
+ await mkdir(destPath, { recursive: true });
101
+ await copyAndReplace(srcPath, destPath, replacements);
102
+ }
103
+ else {
104
+ let content = await readFile(srcPath, "utf-8");
105
+ for (const [key, value] of Object.entries(replacements)) {
106
+ content = content.replaceAll(key, value);
107
+ }
108
+ await writeFile(destPath, content);
109
+ }
110
+ }
111
+ }
112
+ /**
113
+ *
114
+ * @param target
115
+ * @param source
116
+ */
117
+ function deepMergeDeps(target, source) {
118
+ return {
119
+ dependencies: {
120
+ ...(target.dependencies ?? {}),
121
+ ...(source.dependencies ?? {}),
122
+ },
123
+ devDependencies: {
124
+ ...(target.devDependencies ?? {}),
125
+ ...(source.devDependencies ?? {}),
126
+ },
127
+ };
128
+ }
@@ -0,0 +1,19 @@
1
+ import type { TemplateInfo } from "./types.js";
2
+ /**
3
+ *
4
+ * @param name
5
+ */
6
+ export declare function resolveTemplateRoot(name: string): string;
7
+ /**
8
+ *
9
+ * @param templateName
10
+ */
11
+ export declare function listAvailableFrameworks(templateName: string): string[];
12
+ /**
13
+ *
14
+ */
15
+ export declare function listAvailableTemplates(): TemplateInfo[];
16
+ /**
17
+ *
18
+ */
19
+ export declare function resolveEngineVersion(): string;
@@ -0,0 +1,88 @@
1
+ import { existsSync, readFileSync, readdirSync } from "node:fs";
2
+ import { fileURLToPath } from "node:url";
3
+ import path from "node:path";
4
+ const __filename = fileURLToPath(import.meta.url), __dirname = path.dirname(__filename), repoRoot = path.resolve(__dirname, "..", "..", "..", ".."), workspaceTemplateRoot = path.join(repoRoot, "templates"), isWorkspaceMode = existsSync(path.join(workspaceTemplateRoot, "scaffold", "package.json"));
5
+ /**
6
+ *
7
+ * @param name
8
+ */
9
+ export function resolveTemplateRoot(name) {
10
+ if (isWorkspaceMode) {
11
+ const workspacePath = path.join(workspaceTemplateRoot, name);
12
+ if (existsSync(path.join(workspacePath, "package.json"))) {
13
+ return workspacePath;
14
+ }
15
+ }
16
+ const nodeModulesPath = path.join(repoRoot, "node_modules", `@tsparticles/template-${name}`), hoistedPath = path.join(repoRoot, "..", "node_modules", `@tsparticles/template-${name}`);
17
+ for (const candidate of [nodeModulesPath, hoistedPath]) {
18
+ if (existsSync(path.join(candidate, "package.json"))) {
19
+ return candidate;
20
+ }
21
+ }
22
+ throw new Error(`Template "${name}" not found. Looked in workspace (${path.join(workspaceTemplateRoot, name)}) and installed packages.`);
23
+ }
24
+ /**
25
+ *
26
+ * @param templateName
27
+ */
28
+ export function listAvailableFrameworks(templateName) {
29
+ const templateRoot = resolveTemplateRoot(templateName), frameworksDir = path.join(templateRoot, "template");
30
+ if (!existsSync(frameworksDir)) {
31
+ return [];
32
+ }
33
+ const entries = readdirSync(frameworksDir), result = [];
34
+ for (const entry of entries) {
35
+ if (existsSync(path.join(frameworksDir, entry, "package.json"))) {
36
+ result.push(entry);
37
+ }
38
+ }
39
+ return result.sort();
40
+ }
41
+ /**
42
+ *
43
+ */
44
+ export function listAvailableTemplates() {
45
+ const templateMap = {
46
+ scaffold: { displayName: "Scaffold", type: "scaffold" },
47
+ login: { displayName: "Login Page", type: "example" },
48
+ portfolio: { displayName: "Portfolio", type: "example" },
49
+ landing: { displayName: "Landing Page", type: "example" },
50
+ tictactoe: { displayName: "Tic Tac Toe", type: "example" },
51
+ confetti: { displayName: "Confetti", type: "example" },
52
+ ribbons: { displayName: "Ribbons", type: "example" },
53
+ particles: { displayName: "Particles", type: "example" },
54
+ }, results = [];
55
+ for (const [name, info] of Object.entries(templateMap)) {
56
+ try {
57
+ const frameworks = listAvailableFrameworks(name);
58
+ results.push({
59
+ displayName: info.displayName,
60
+ frameworks,
61
+ name,
62
+ type: info.type,
63
+ });
64
+ }
65
+ catch {
66
+ // template not available, skip
67
+ }
68
+ }
69
+ return results;
70
+ }
71
+ /**
72
+ *
73
+ */
74
+ export function resolveEngineVersion() {
75
+ if (isWorkspaceMode) {
76
+ const enginePkgPath = path.join(repoRoot, "engine", "package.json");
77
+ if (existsSync(enginePkgPath)) {
78
+ const pkg = JSON.parse(readFileSync(enginePkgPath, "utf-8"));
79
+ return pkg.version ?? "4.1.3";
80
+ }
81
+ }
82
+ const enginePkgPath = path.join(repoRoot, "node_modules", "@tsparticles", "engine", "package.json");
83
+ if (existsSync(enginePkgPath)) {
84
+ const pkg = JSON.parse(readFileSync(enginePkgPath, "utf-8"));
85
+ return pkg.version ?? "4.1.3";
86
+ }
87
+ return "4.1.3";
88
+ }