@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.
- package/.browserslistrc +2 -0
- package/.dependency-cruiser.cjs +230 -0
- package/LICENSE +21 -0
- package/README.md +11 -0
- package/dist/app.d.ts +3 -0
- package/dist/app.js +28 -0
- package/dist/prompts.d.ts +21 -0
- package/dist/prompts.js +75 -0
- package/dist/scaffold.d.ts +10 -0
- package/dist/scaffold.js +128 -0
- package/dist/template-resolver.d.ts +19 -0
- package/dist/template-resolver.js +88 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/types.d.ts +18 -0
- package/dist/types.js +1 -0
- package/eslint.config.js +22 -0
- package/package.json +65 -0
- package/src/app.ts +45 -0
- package/src/prompts.ts +108 -0
- package/src/scaffold.ts +181 -0
- package/src/template-resolver.ts +120 -0
- package/src/tsconfig.json +9 -0
- package/src/types.ts +20 -0
- package/tsconfig.json +21 -0
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { existsSync, readFileSync, readdirSync } from "node:fs";
|
|
2
|
+
import type { TemplateInfo } from "./types.js";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
|
|
6
|
+
const __filename = fileURLToPath(import.meta.url),
|
|
7
|
+
__dirname = path.dirname(__filename),
|
|
8
|
+
repoRoot = path.resolve(__dirname, "..", "..", "..", ".."),
|
|
9
|
+
workspaceTemplateRoot = path.join(repoRoot, "templates"),
|
|
10
|
+
isWorkspaceMode = existsSync(path.join(workspaceTemplateRoot, "scaffold", "package.json"));
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
*
|
|
14
|
+
* @param name
|
|
15
|
+
*/
|
|
16
|
+
export function resolveTemplateRoot(name: string): string {
|
|
17
|
+
if (isWorkspaceMode) {
|
|
18
|
+
const workspacePath = path.join(workspaceTemplateRoot, name);
|
|
19
|
+
|
|
20
|
+
if (existsSync(path.join(workspacePath, "package.json"))) {
|
|
21
|
+
return workspacePath;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const nodeModulesPath = path.join(repoRoot, "node_modules", `@tsparticles/template-${name}`),
|
|
26
|
+
hoistedPath = path.join(repoRoot, "..", "node_modules", `@tsparticles/template-${name}`);
|
|
27
|
+
|
|
28
|
+
for (const candidate of [nodeModulesPath, hoistedPath]) {
|
|
29
|
+
if (existsSync(path.join(candidate, "package.json"))) {
|
|
30
|
+
return candidate;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
throw new Error(
|
|
35
|
+
`Template "${name}" not found. Looked in workspace (${path.join(workspaceTemplateRoot, name)}) and installed packages.`,
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
*
|
|
41
|
+
* @param templateName
|
|
42
|
+
*/
|
|
43
|
+
export function listAvailableFrameworks(templateName: string): string[] {
|
|
44
|
+
const templateRoot = resolveTemplateRoot(templateName),
|
|
45
|
+
frameworksDir = path.join(templateRoot, "template");
|
|
46
|
+
|
|
47
|
+
if (!existsSync(frameworksDir)) {
|
|
48
|
+
return [];
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const entries = readdirSync(frameworksDir),
|
|
52
|
+
result: string[] = [];
|
|
53
|
+
|
|
54
|
+
for (const entry of entries) {
|
|
55
|
+
if (existsSync(path.join(frameworksDir, entry, "package.json"))) {
|
|
56
|
+
result.push(entry);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return result.sort();
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
*
|
|
65
|
+
*/
|
|
66
|
+
export function listAvailableTemplates(): TemplateInfo[] {
|
|
67
|
+
const templateMap: Record<string, { displayName: string; type: "scaffold" | "example" }> = {
|
|
68
|
+
scaffold: { displayName: "Scaffold", type: "scaffold" },
|
|
69
|
+
login: { displayName: "Login Page", type: "example" },
|
|
70
|
+
portfolio: { displayName: "Portfolio", type: "example" },
|
|
71
|
+
landing: { displayName: "Landing Page", type: "example" },
|
|
72
|
+
tictactoe: { displayName: "Tic Tac Toe", type: "example" },
|
|
73
|
+
confetti: { displayName: "Confetti", type: "example" },
|
|
74
|
+
ribbons: { displayName: "Ribbons", type: "example" },
|
|
75
|
+
particles: { displayName: "Particles", type: "example" },
|
|
76
|
+
},
|
|
77
|
+
results: TemplateInfo[] = [];
|
|
78
|
+
|
|
79
|
+
for (const [name, info] of Object.entries(templateMap)) {
|
|
80
|
+
try {
|
|
81
|
+
const frameworks = listAvailableFrameworks(name);
|
|
82
|
+
|
|
83
|
+
results.push({
|
|
84
|
+
displayName: info.displayName,
|
|
85
|
+
frameworks,
|
|
86
|
+
name,
|
|
87
|
+
type: info.type,
|
|
88
|
+
});
|
|
89
|
+
} catch {
|
|
90
|
+
// template not available, skip
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return results;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
*
|
|
99
|
+
*/
|
|
100
|
+
export function resolveEngineVersion(): string {
|
|
101
|
+
if (isWorkspaceMode) {
|
|
102
|
+
const enginePkgPath = path.join(repoRoot, "engine", "package.json");
|
|
103
|
+
|
|
104
|
+
if (existsSync(enginePkgPath)) {
|
|
105
|
+
const pkg = JSON.parse(readFileSync(enginePkgPath, "utf-8")) as { version?: string };
|
|
106
|
+
|
|
107
|
+
return pkg.version ?? "4.1.3";
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const enginePkgPath = path.join(repoRoot, "node_modules", "@tsparticles", "engine", "package.json");
|
|
112
|
+
|
|
113
|
+
if (existsSync(enginePkgPath)) {
|
|
114
|
+
const pkg = JSON.parse(readFileSync(enginePkgPath, "utf-8")) as { version?: string };
|
|
115
|
+
|
|
116
|
+
return pkg.version ?? "4.1.3";
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
return "4.1.3";
|
|
120
|
+
}
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export interface TemplateInfo {
|
|
2
|
+
displayName: string;
|
|
3
|
+
frameworks: string[];
|
|
4
|
+
name: string;
|
|
5
|
+
type: "scaffold" | "example";
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface UserOptions {
|
|
9
|
+
destination: string;
|
|
10
|
+
framework: string;
|
|
11
|
+
projectName: string;
|
|
12
|
+
skipInstall: boolean;
|
|
13
|
+
template?: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface ScaffoldResult {
|
|
17
|
+
frameworkUsed: string;
|
|
18
|
+
targetDir: string;
|
|
19
|
+
templateUsed: string;
|
|
20
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"rootDir": ".",
|
|
4
|
+
"outDir": ".",
|
|
5
|
+
"resolveJsonModule": true,
|
|
6
|
+
"composite": true,
|
|
7
|
+
"target": "ESNext",
|
|
8
|
+
"module": "NodeNext",
|
|
9
|
+
"moduleResolution": "NodeNext",
|
|
10
|
+
"types": [
|
|
11
|
+
"node"
|
|
12
|
+
],
|
|
13
|
+
"strict": true,
|
|
14
|
+
"esModuleInterop": true,
|
|
15
|
+
"forceConsistentCasingInFileNames": true,
|
|
16
|
+
"allowSyntheticDefaultImports": true
|
|
17
|
+
},
|
|
18
|
+
"include": [
|
|
19
|
+
"src/**/*"
|
|
20
|
+
]
|
|
21
|
+
}
|