Skip to content

Commit df7a2cd

Browse files
Merge pull request #6 from homy-game-studio/fix-unity-version
Fix unity version
2 parents b3568db + 828889a commit df7a2cd

File tree

4 files changed

+18
-127
lines changed

4 files changed

+18
-127
lines changed

package-lock.json

Lines changed: 0 additions & 123 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
"ora": "^6.1.2",
3131
"simple-git": "^3.15.1",
3232
"template-directory": "^2.0.0",
33-
"template-file": "^6.0.1",
3433
"typescript": "^4.9.3"
3534
},
3635
"devDependencies": {

src/index.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { createDirectory } from "./modules/directory";
55
import { createRepo as createGitRepo } from "./modules/git";
66
import input from "./modules/input";
77
import { render as renderTemplate } from "./modules/render";
8-
import { createUnityProject, getUnityInstallations, openUnityProject } from "./modules/unity";
8+
import { createUnityProject, getUnityInstallations, openUnityProject, parseUnityVersion } from "./modules/unity";
99

1010
const run = <T>(promise: Promise<T>, text: string) => {
1111
return oraPromise(
@@ -23,7 +23,11 @@ const main = async () => {
2323
const projectPath = await run(createDirectory(inputData.packageName), "Create directory");
2424
await run(createUnityProject(unityPath, projectPath), "Create unity project");
2525
await run(createGitRepo(projectPath), "Create git repo");
26-
await run(renderTemplate(inputData, projectPath), "Render template");
26+
const renderData = {
27+
...inputData,
28+
unityVersion: parseUnityVersion(inputData.unityVersion)
29+
}
30+
await run(renderTemplate(renderData, projectPath), "Render template");
2731
await run(openUnityProject(unityPath, projectPath), "Open unity project");
2832
} catch (e) {
2933
console.error(e);

src/modules/unity.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,21 @@ export const getUnityInstallations = async (): Promise<UnityInstallations> => {
4545
return installations;
4646
}
4747

48+
export const parseUnityVersion = (raw: string) => {
49+
const result = /^[0-9]+\.[0-9]+/gm.exec(raw);
50+
if (!result || result.length === 0) throw `Failed to parse unity version ${raw}`;
51+
52+
return result[0];
53+
}
54+
4855
export const createUnityProject = async (unityPath: string, projectPath: string) => {
4956
await execa(unityPath, ["-quit", "-batchmode", "-createProject", projectPath]);
5057
}
5158

5259
export const openUnityProject = async (unityPath: string, projectPath: string) => {
53-
await execa(unityPath, ["-projectPath", projectPath], { stdio: "ignore" });
60+
await execa(unityPath, ["-projectPath", projectPath], {
61+
stdio: "ignore",
62+
detached: true,
63+
cleanup: false,
64+
});
5465
}

0 commit comments

Comments
 (0)