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", "gulp-util", "path", "@spicypixel/core-kit-js", "./unity-project"], factory);
|
7 | }
|
8 | })(function (require, exports) {
|
9 | "use strict";
|
10 |
|
11 | Object.defineProperty(exports, "__esModule", { value: true });
|
12 | const gutil = require("gulp-util");
|
13 | const path = require("path");
|
14 | const CoreKit = require("@spicypixel/core-kit-js");
|
15 | const unity_project_1 = require("./unity-project");
|
16 | class UnityModule {
|
17 | constructor(project, vendor, name) {
|
18 | this._project = project;
|
19 | this._vendor = vendor;
|
20 | this._name = name;
|
21 | }
|
22 | static createFromPath(path, vendor, name) {
|
23 | return new UnityModule(new unity_project_1.default(path), vendor, name);
|
24 | }
|
25 | static createFromProject(unityProject, vendor, name) {
|
26 | return new UnityModule(unityProject, vendor, name);
|
27 | }
|
28 | get project() {
|
29 | return this._project;
|
30 | }
|
31 | get vendor() {
|
32 | return this._vendor;
|
33 | }
|
34 | get name() {
|
35 | return this._name;
|
36 | }
|
37 | get modulePath() {
|
38 | return path.join(this._project.assetsPath, this._vendor, "Modules", this._name);
|
39 | }
|
40 | get artifactsPath() {
|
41 | return path.join(this._project.projectPath, "Artifacts");
|
42 | }
|
43 | async getPackageFileName() {
|
44 | const pkg = await CoreKit.FileSystem.File.readFileAsync(path.join(this._project.projectPath, "package.json"), "utf8");
|
45 | const tag = "v" + JSON.parse(pkg).version;
|
46 | return this._vendor + "." + this._name + "-" + tag + ".unitypackage";
|
47 | }
|
48 | async exportPackageAsync() {
|
49 | try {
|
50 | await CoreKit.FileSystem.Directory.accessAsync(this.modulePath, CoreKit.FileSystem.FileSystemPermission.Visible);
|
51 | } catch (err) {
|
52 | gutil.log("Skipping export Unity package because module folder does not exist: ", this.modulePath);
|
53 | return;
|
54 | }
|
55 | await CoreKit.FileSystem.Directory.createRecursiveAsync(this.artifactsPath);
|
56 | await this.cleanArtifactsAsync();
|
57 | const packageFileName = await this.getPackageFileName();
|
58 | await this._project.exportPackageAsync([path.relative(this._project.projectPath, this.modulePath)], path.join(this.artifactsPath, packageFileName));
|
59 | }
|
60 | async cleanArtifactsAsync() {
|
61 | await CoreKit.FileSystem.removePatternsAsync(path.join(this.artifactsPath, "*"));
|
62 | }
|
63 | }
|
64 | exports.default = UnityModule;
|
65 | });
|
66 |
|