Skip to content

Commit fca3256

Browse files
committed
feat(Template): Added UnityTemplates class for editor templates
1 parent 149c389 commit fca3256

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed

src/index.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
1+
// Exporting Classes
12
export { default as UnityHub } from "./unityHub.ts";
23
export { default as UnityEditor } from "./unityEditor.ts";
4+
export { default as UnityTemplates } from "./unityTemplates.ts";
5+
6+
// Exporting Events & Emitters
37
export { UnityHubInstallerEvent } from "./events/hubEventEmitter.ts";
48

9+
// Exporting Configurations
10+
export { UnityConfig } from "./configs/unityConfig.ts";
11+
12+
// Exporting Types
513
export * from "./types/unity.ts";

src/unityTemplates.ts

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import path from "path";
2+
import fs from "fs-extra";
3+
import { UnityConfig, PlatformConfig } from "./configs/unityConfig.ts";
4+
5+
interface ProjectTemplates {
6+
templateName: string;
7+
templatePath: string;
8+
}
9+
10+
/**
11+
* UnityTemplates class provides methods to access Unity templates
12+
*
13+
*/
14+
class UnityTemplates {
15+
/**
16+
* Platform-specific configuration for Unity Hub
17+
* @internal
18+
*/
19+
private static unityConfig: PlatformConfig = UnityConfig.getPlatformConfig();
20+
21+
/**
22+
* Get the path to the Unity project templates
23+
* @returns The path to the Unity project templates
24+
*/
25+
private static getProjectTemplatesPath(): string {
26+
return this.unityConfig.templates.projectTemplates;
27+
}
28+
29+
/**
30+
* Get the path to the Unity project templates for a specific version
31+
* @param version - The Unity version
32+
* @returns The path to the Unity project templates for the specified version
33+
*/
34+
private static getProjectTemplatesPathForVersion(version: string): string {
35+
return path.join(this.unityConfig.editor.base, version, this.getProjectTemplatesPath());
36+
}
37+
38+
/**
39+
* Get the path to the Unity project templates for a specific version and template name
40+
* @param version - The Unity version
41+
* @param templateName - The name of the template
42+
* @returns The path to the Unity project templates for the specified version and template name
43+
*/
44+
public static getProjectTemplates(version: string): ProjectTemplates[] {
45+
const templatePath = this.getProjectTemplatesPathForVersion(version);
46+
47+
if (!fs.existsSync(templatePath)) {
48+
throw new Error(`Template path does not exist: ${templatePath}`);
49+
}
50+
51+
const templates = fs.readdirSync(templatePath).filter((file) => path.extname(file) === ".tgz");
52+
return templates.map((template) => ({
53+
templateName: path.basename(template, ".tgz"),
54+
templatePath: path.join(templatePath, template),
55+
}));
56+
}
57+
}
58+
59+
export default UnityTemplates;

0 commit comments

Comments
 (0)