UNPKG

3.4 kBJavaScriptView Raw
1(function (factory) {
2 if (typeof module === "object" && typeof module.exports === "object") {
3 var v = factory(require, exports);
4 if (v !== undefined) module.exports = v;
5 } else if (typeof define === "function" && define.amd) {
6 define(["require", "exports", "path", "@spicypixel/core-kit-js/lib/file-system", "@spicypixel/core-kit-js/lib/child-process", "./unity-editor"], factory);
7 }
8})(function (require, exports) {
9 "use strict";
10
11 Object.defineProperty(exports, "__esModule", { value: true });
12 const path = require("path");
13 const fs = require("@spicypixel/core-kit-js/lib/file-system");
14 const child_process_1 = require("@spicypixel/core-kit-js/lib/child-process");
15 const unity_editor_1 = require("./unity-editor");
16 class UnityProject {
17 constructor(projectPath) {
18 this._projectPath = projectPath;
19 }
20 get projectPath() {
21 return this._projectPath;
22 }
23 get assetsPath() {
24 return path.join(this._projectPath, "Assets");
25 }
26 get projectPathArgs() {
27 return ["-projectPath", this._projectPath];
28 }
29 async createAsync() {
30 await fs.Directory.createRecursiveAsync(path.dirname(this._projectPath));
31 let args = unity_editor_1.default.batchModeArgs;
32 args = args.concat("-createProject");
33 args = args.concat(this._projectPath);
34 await child_process_1.default.spawnAsync(unity_editor_1.default.editorPath, args, { stdio: ["pipe", "ignore", process.stderr] });
35 }
36 async exportPackageAsync(sourcePaths, outputPath) {
37 await this.verifyProjectExistsAsync();
38 await fs.Directory.createRecursiveAsync(path.dirname(outputPath));
39 let args = unity_editor_1.default.batchModeArgs;
40 args = args.concat(this.projectPathArgs);
41 args = args.concat("-exportPackage");
42 args = args.concat(sourcePaths);
43 args = args.concat(outputPath);
44 await child_process_1.default.spawnAsync(unity_editor_1.default.editorPath, args, { stdio: ["pipe", "ignore", process.stderr] });
45 }
46 async importPackageAsync(packagePath) {
47 await this.verifyProjectExistsAsync();
48 if (!path.isAbsolute(packagePath)) packagePath = path.resolve(path.join(this._projectPath, packagePath));
49 try {
50 await fs.FileSystemRecord.accessAsync(packagePath, fs.FileSystemPermission.Visible);
51 } catch (err) {
52 throw new Error("Package path does not exist: " + err.message);
53 }
54 let args = unity_editor_1.default.batchModeArgs;
55 args = args.concat(this.projectPathArgs);
56 args = args.concat("-importPackage");
57 args = args.concat(packagePath);
58 await child_process_1.default.spawnAsync(unity_editor_1.default.editorPath, args, { stdio: ["pipe", "ignore", process.stderr] });
59 }
60 async verifyProjectExistsAsync() {
61 try {
62 await fs.FileSystemRecord.accessAsync(this._projectPath, fs.FileSystemPermission.Visible);
63 } catch (err) {
64 throw new Error("Project path does not exist: " + err.message);
65 }
66 }
67 }
68 exports.default = UnityProject;
69});
70//# sourceMappingURL=unity-project.js.map