Skip to content

Commit 5d983dc

Browse files
list templates
1 parent cfed4e0 commit 5d983dc

File tree

3 files changed

+62
-29
lines changed

3 files changed

+62
-29
lines changed

dist/index.js

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -61395,24 +61395,37 @@ async function main() {
6139561395
throw new Error('UNITY_EDITOR_PATH environment variable must be set!');
6139661396
}
6139761397
const unityEditor = new unity_cli_1.UnityEditor(process.env.UNITY_EDITOR_PATH);
61398-
core.debug(`Using Unity Editor at path:\n > ${unityEditor.editorPath}`);
61399-
const templatePath = unityEditor.GetTemplatePath(core.getInput('template-name'));
61400-
core.debug(`Using Unity template at path:\n > ${templatePath}`);
61398+
core.info(`Using Unity Editor at path:\n > ${unityEditor.editorPath}`);
61399+
let templatePath = undefined;
61400+
if (this.version.isGreaterThan('2018.0.0')) {
61401+
const availableTemplates = unityEditor.GetAvailableTemplates();
61402+
core.startGroup('Available Unity Project Templates:');
61403+
for (const template of availableTemplates) {
61404+
core.info(` - ${template}`);
61405+
}
61406+
core.endGroup();
61407+
templatePath = unityEditor.GetTemplatePath(core.getInput('template-name'));
61408+
core.info(`Using Unity template at path:\n > ${templatePath}`);
61409+
}
61410+
else {
61411+
core.info('Unity Project Templates are not supported for Unity versions below 2018');
61412+
}
6140161413
const projectNameInput = core.getInput('project-name', { required: true });
6140261414
const projectDirectoryInput = core.getInput('project-directory') || process.cwd();
6140361415
const projectPath = `${projectDirectoryInput}/${projectNameInput}`;
61404-
core.debug(`Creating Unity project at:\n > ${projectPath}`);
61416+
core.info(`Creating Unity project at:\n > ${projectPath}`);
61417+
const args = [
61418+
'-quit',
61419+
'-nographics',
61420+
'-batchmode',
61421+
'-createProject', projectPath,
61422+
];
61423+
if (templatePath) {
61424+
args.push('-projectTemplate', templatePath);
61425+
}
6140561426
const logPath = unityEditor.GenerateLogFilePath(projectPath, 'create-unity-project');
61406-
await unityEditor.Run({
61407-
args: [
61408-
'-quit',
61409-
'-nographics',
61410-
'-batchmode',
61411-
'-createProject', projectPath,
61412-
'-cloneFromTemplate', templatePath,
61413-
'-logFile', logPath
61414-
]
61415-
});
61427+
args.push('-logFile', logPath);
61428+
await unityEditor.Run({ args: [...args] });
6141661429
core.setOutput('project-path', projectPath);
6141761430
}
6141861431
catch (error) {

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/index.ts

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,44 @@ async function main() {
88
}
99

1010
const unityEditor = new UnityEditor(process.env.UNITY_EDITOR_PATH);
11-
core.debug(`Using Unity Editor at path:\n > ${unityEditor.editorPath}`);
12-
const templatePath = unityEditor.GetTemplatePath(core.getInput('template-name'));
13-
core.debug(`Using Unity template at path:\n > ${templatePath}`);
11+
core.info(`Using Unity Editor at path:\n > ${unityEditor.editorPath}`);
12+
13+
let templatePath: string | undefined = undefined;
14+
15+
if (this.version.isGreaterThan('2018.0.0')) {
16+
const availableTemplates = unityEditor.GetAvailableTemplates();
17+
core.startGroup('Available Unity Project Templates:');
18+
19+
for (const template of availableTemplates) {
20+
core.info(` - ${template}`);
21+
}
22+
23+
core.endGroup();
24+
templatePath = unityEditor.GetTemplatePath(core.getInput('template-name'));
25+
core.info(`Using Unity template at path:\n > ${templatePath}`);
26+
} else {
27+
core.info('Unity Project Templates are not supported for Unity versions below 2018');
28+
}
29+
1430
const projectNameInput = core.getInput('project-name', { required: true });
1531
const projectDirectoryInput = core.getInput('project-directory') || process.cwd();
1632
const projectPath = `${projectDirectoryInput}/${projectNameInput}`;
17-
core.debug(`Creating Unity project at:\n > ${projectPath}`);
33+
core.info(`Creating Unity project at:\n > ${projectPath}`);
34+
35+
const args: string[] = [
36+
'-quit',
37+
'-nographics',
38+
'-batchmode',
39+
'-createProject', projectPath,
40+
];
41+
42+
if (templatePath) {
43+
args.push('-projectTemplate', templatePath);
44+
}
45+
1846
const logPath = unityEditor.GenerateLogFilePath(projectPath, 'create-unity-project');
19-
await unityEditor.Run({
20-
args: [
21-
'-quit',
22-
'-nographics',
23-
'-batchmode',
24-
'-createProject', projectPath,
25-
'-cloneFromTemplate', templatePath,
26-
'-logFile', logPath
27-
]
28-
});
47+
args.push('-logFile', logPath);
48+
await unityEditor.Run({ args: [...args] });
2949
core.setOutput('project-path', projectPath);
3050
} catch (error) {
3151
core.setFailed(error);

0 commit comments

Comments
 (0)