@mitm/assetbundlecompiler
Advanced tools
Comparing version 1.3.0 to 1.4.0
@@ -35,3 +35,2 @@ import { logger } from '@mitm/unityinvoker'; | ||
private buildTarget; | ||
private finalDest; | ||
private state; | ||
@@ -38,0 +37,0 @@ includingAssets(...assets: streamMaker.ReadableFileInput[]): this; |
@@ -12,2 +12,3 @@ "use strict"; | ||
const unityinvoker_1 = require("@mitm/unityinvoker"); | ||
const path = require("path"); | ||
const build_context_1 = require("./build_context"); | ||
@@ -74,4 +75,8 @@ const streamMaker = require("./stream_maker"); | ||
this.state = BundlerState.Bundling; | ||
this.finalDest = file; | ||
const buildContext = new build_context_1.BuildContext(); | ||
//=> Normalize dest to a writable strem | ||
const fileStream = streamMaker.normalizeWriteStream(file); | ||
const fileName = path.basename(fileStream.path.toString()); | ||
//=> Create the build context (contains infos about the paths used by the current build) | ||
const buildContext = new build_context_1.BuildContext(fileName); | ||
//=> Handle abrupt process terminations | ||
const signalCleanup = this.signalCleanup.bind(this, buildContext); | ||
@@ -99,3 +104,3 @@ process.on('SIGINT', signalCleanup); | ||
this.logger(`Moving asset bundle to target destination`); | ||
yield unityproj.moveGeneratedAssetBundle(buildContext, this.finalDest, overwrite); | ||
yield unityproj.moveGeneratedAssetBundle(buildContext, fileStream, overwrite); | ||
} | ||
@@ -102,0 +107,0 @@ finally { |
export declare class BuildContext { | ||
readonly assetBundleName: string; | ||
readonly projectRootDir: string; | ||
@@ -6,3 +7,4 @@ readonly assetsDir: string; | ||
readonly assetBundleDir: string; | ||
constructor(); | ||
readonly assetBundlePath: string; | ||
constructor(assetBundleName: string); | ||
} |
@@ -6,3 +6,4 @@ "use strict"; | ||
class BuildContext { | ||
constructor() { | ||
constructor(assetBundleName) { | ||
this.assetBundleName = assetBundleName; | ||
this.projectRootDir = unity_project_1.ProjectDirectory; | ||
@@ -12,4 +13,5 @@ this.assetsDir = path.resolve(`${unity_project_1.ProjectDirectory}/Assets/CopiedAssets`); | ||
this.assetBundleDir = path.resolve(`${unity_project_1.ProjectDirectory}/GeneratedAssetBundles`); | ||
this.assetBundlePath = path.resolve(`${this.assetBundleDir}/${assetBundleName}`); | ||
} | ||
} | ||
exports.BuildContext = BuildContext; |
@@ -14,3 +14,3 @@ /// <reference types="node" /> | ||
export declare function generateAssetBundle(context: BuildContext, fileStreams: fs.ReadStream[], buildOptions: Set<string>, buildTarget: BuildTarget, unityLogger?: logger.SimpleLogger, signalAssetProcessed?: logger.SimpleLogger): Promise<void>; | ||
export declare function moveGeneratedAssetBundle(context: BuildContext, finalDest: string | fs.WriteStream, overwrite: boolean): Promise<void>; | ||
export declare function moveGeneratedAssetBundle(context: BuildContext, finalDest: fs.WriteStream, overwrite: boolean): Promise<void>; | ||
export declare function cleanupProject(context: BuildContext): Promise<void>; |
@@ -14,3 +14,2 @@ "use strict"; | ||
const path = require("path"); | ||
const streamMaker = require("./stream_maker"); | ||
const unity = require("./unity_invoker"); | ||
@@ -81,3 +80,3 @@ exports.ProjectDirectory = path.join(os.tmpdir(), 'AssetBundleCompiler'); | ||
const assetNames = fileStreams.map(fileStream => path.basename(fileStream.path)); | ||
yield unity.generateAssetBundle(exports.ProjectDirectory, assetNames, context.assetBundleDir, 'assetbundle', buildOptions, buildTarget, unityLogger, signalAssetProcessed); | ||
yield unity.generateAssetBundle(exports.ProjectDirectory, assetNames, context.assetBundleDir, context.assetBundleName, buildOptions, buildTarget, unityLogger, signalAssetProcessed); | ||
}); | ||
@@ -88,21 +87,15 @@ } | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const assetBundlePath = path.resolve(`${context.assetBundleDir}/assetbundle`); | ||
if (typeof finalDest === 'string') { | ||
yield fsx.move(assetBundlePath, finalDest, { overwrite }); | ||
} | ||
else if (streamMaker.isWriteStream(finalDest)) { | ||
if (!overwrite) { | ||
try { | ||
yield fsx.access(finalDest.path); | ||
throw new Error(`File ${finalDest.path} already exists, overwrite option is false, aborting.`); | ||
} | ||
finally { } | ||
if (!overwrite) { | ||
try { | ||
yield fsx.access(finalDest.path); | ||
throw new Error(`File ${finalDest.path} already exists, overwrite option is false, aborting.`); | ||
} | ||
const assetBundleStream = fsx.createReadStream(assetBundlePath); | ||
return new Promise((resolve, reject) => { | ||
assetBundleStream.pipe(finalDest) | ||
.on('finish', () => resolve()) | ||
.on('error', (err) => reject(err)); | ||
}); | ||
finally { } | ||
} | ||
const assetBundleStream = fsx.createReadStream(context.assetBundlePath); | ||
return new Promise((resolve, reject) => { | ||
assetBundleStream.pipe(finalDest) | ||
.on('finish', () => resolve()) | ||
.on('error', (err) => reject(err)); | ||
}); | ||
}); | ||
@@ -109,0 +102,0 @@ } |
{ | ||
"name": "@mitm/assetbundlecompiler", | ||
"version": "1.3.0", | ||
"version": "1.4.0", | ||
"description": "Node.js wrapper around Unity3D's BuildPipeline to create AssetBundles from any files", | ||
@@ -14,4 +14,4 @@ "repository": "git@github.com:toverux/AssetBundleCompiler.git", | ||
"semantic-release": "semantic-release pre && npm publish --access public && semantic-release post", | ||
"test": "mocha dist/test/**/*.js", | ||
"lint": "tslint src/**/*.ts test/**/*.ts" | ||
"test": "mocha \"dist/test/**/*.js\"", | ||
"lint": "tslint \"src/**/*.ts\" \"test/**/*.ts\"" | ||
}, | ||
@@ -18,0 +18,0 @@ "devDependencies": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
103869
718