UNPKG

4.1 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"], factory);
7 }
8})(function (require, exports) {
9 "use strict";
10
11 Object.defineProperty(exports, "__esModule", { value: true });
12 const path = require("path");
13 const CoreKit = require("@spicypixel/core-kit-js");
14 class UnityModuleLibraryReference {
15 constructor(module, nodeModule) {
16 this._module = module;
17 this._nodeModule = nodeModule;
18 }
19 get installPath() {
20 return this._module.modulePath;
21 }
22 /** Update module with latest library */
23 async installAsync(assemblyNames, editorAssemblyNames, sourceNames) {
24 await this.uninstallAsync();
25 await this.copyLibraryToAssetsAsync(assemblyNames, editorAssemblyNames, sourceNames);
26 }
27 async uninstallAsync() {
28 // Remove files except *.meta
29 await CoreKit.FileSystem.removePatternsAsync(["Bin/**/*", "Docs/**/*", "MonoDoc/**/*", "Scripts/**/*", "README.md", "LICENSE.md", "!**/*.meta"], { cwd: this.installPath, nodir: true });
30 // Remove folders that no longer exist
31 await CoreKit.FileSystem.Directory.removeUnmatchedAsync(path.join(this._nodeModule.packageDir, "Docs"), path.join(this.installPath, "Docs"), { ignoreMissingSource: true, ignoreMissingDestination: true });
32 await CoreKit.FileSystem.Directory.removeUnmatchedAsync(path.join(this._nodeModule.packageDir, "Source"), path.join(this.installPath, "Scripts"), { ignoreMissingSource: true, ignoreMissingDestination: true });
33 }
34 async copyLibraryToAssetsAsync(assemblyNames, editorAssemblyNames, sourceNames) {
35 const docsSrcDir = path.join(this._nodeModule.packageDir, "Docs");
36 const sourceSrcDir = path.join(this._nodeModule.packageDir, "Source");
37 const docsDestDir = path.join(this.installPath, "Docs");
38 const monoDocDestDir = path.join(this.installPath, "MonoDoc");
39 const binDestDir = path.join(this.installPath, "Bin");
40 const editorDestDir = path.join(binDestDir, "Editor");
41 const sourceDestDir = path.join(this.installPath, "Scripts");
42 let promises = [];
43 assemblyNames.forEach(assembly => {
44 const srcDir = path.join(sourceSrcDir, assembly, "bin", "Release");
45 promises = promises.concat(CoreKit.FileSystem.copyPatternsAsync(path.join(srcDir, assembly + ".dll"), binDestDir, { base: srcDir }));
46 });
47 editorAssemblyNames.forEach(assembly => {
48 const srcDir = path.join(sourceSrcDir, assembly, "bin", "Release");
49 promises = promises.concat(CoreKit.FileSystem.copyPatternsAsync(path.join(srcDir, assembly + ".dll"), editorDestDir, { base: srcDir }));
50 });
51 sourceNames.forEach(assembly => {
52 const srcDir = path.join(sourceSrcDir, assembly);
53 promises = promises.concat(CoreKit.FileSystem.copyPatternsAsync([path.join(srcDir, "**", "*.cs"), "!**/AssemblyInfo.cs"], sourceDestDir, { base: sourceSrcDir }));
54 });
55 promises = promises.concat(CoreKit.FileSystem.copyPatternsAsync(path.join(docsSrcDir, "**/*"), docsDestDir, { base: docsSrcDir }));
56 promises = promises.concat(CoreKit.FileSystem.copyPatternsAsync(["*.source", "assemble/*.tree", "assemble/*.zip"], monoDocDestDir, { cwd: path.join(this._nodeModule.packageDir, "MonoDoc"), flatten: true }));
57 promises = promises.concat(CoreKit.FileSystem.copyPatternsAsync(["README.md", "LICENSE.md"], this.installPath, { cwd: this._nodeModule.packageDir }));
58 await Promise.all(promises);
59 }
60 }
61 exports.default = UnityModuleLibraryReference;
62});
63//# sourceMappingURL=unity-module-library-reference.js.map