New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@mitm/assetbundlecompiler

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@mitm/assetbundlecompiler - npm Package Compare versions

Comparing version 1.4.0 to 1.5.0

18

dist/src/assets_bundler.d.ts

@@ -27,3 +27,11 @@ import { logger } from '@mitm/unityinvoker';

dryRunBuild?: boolean;
/** Disables Asset Bundle LoadAsset by file name. */
disableLoadAssetByFileName?: boolean;
/** Disables Asset Bundle LoadAsset by file name with extension. */
disableLoadAssetByFileNameWithExtension?: boolean;
}
export interface IExportOptions {
overwrite?: boolean;
manifestFile?: streamMaker.WritableFileInput;
}
export declare class AssetsBundler {

@@ -39,13 +47,11 @@ private logger;

targeting(buildTarget: unityproj.BuildTarget): this;
withLogger(logger: logger.SimpleLogger): this;
withLogger(loggerFn: logger.SimpleLogger): this;
withUnityLogger(unityLogger: logger.SimpleLogger): this;
withBuildOptions(buildOptions: IBuildOptionsMap): this;
includingEditorScripts(...scripts: streamMaker.ReadableFileInput[]): this;
to(file: streamMaker.WritableFileInput, {overwrite}?: {
overwrite: boolean;
}): Promise<void>;
to(file: streamMaker.WritableFileInput, options?: IExportOptions): Promise<unityproj.IAssetBundleManifest>;
private cleanup(context);
private signalCleanup(context);
private checkLoggerType(logger);
private checkBundlerIsntConfigured();
private checkLoggerType(loggerFn);
private checkBundlerIsntAlreadyConfigured();
}

@@ -32,3 +32,3 @@ "use strict";

includingAssets(...assets) {
this.checkBundlerIsntConfigured();
this.checkBundlerIsntAlreadyConfigured();
assets.map(streamMaker.normalizeReadStream).forEach(stream => this.assetsStreams.push(stream));

@@ -38,3 +38,3 @@ return this;

targeting(buildTarget) {
this.checkBundlerIsntConfigured();
this.checkBundlerIsntAlreadyConfigured();
if (typeof buildTarget !== 'string') {

@@ -46,10 +46,10 @@ throw new Error('buildTarget must be a string (member name of an UnityEngine.BuildTarget enum).');

}
withLogger(logger) {
this.checkBundlerIsntConfigured();
this.checkLoggerType(logger);
this.logger = logger;
withLogger(loggerFn) {
this.checkBundlerIsntAlreadyConfigured();
this.checkLoggerType(loggerFn);
this.logger = loggerFn;
return this;
}
withUnityLogger(unityLogger) {
this.checkBundlerIsntConfigured();
this.checkBundlerIsntAlreadyConfigured();
this.checkLoggerType(unityLogger);

@@ -60,3 +60,3 @@ this.unityLogger = unityLogger;

withBuildOptions(buildOptions) {
this.checkBundlerIsntConfigured();
this.checkBundlerIsntAlreadyConfigured();
Object.keys(buildOptions)

@@ -68,7 +68,7 @@ .filter(key => buildOptions[key])

includingEditorScripts(...scripts) {
this.checkBundlerIsntConfigured();
this.checkBundlerIsntAlreadyConfigured();
scripts.map(streamMaker.normalizeReadStream).forEach(stream => this.editorScriptsStreams.push(stream));
return this;
}
to(file, { overwrite } = { overwrite: true }) {
to(file, options = {}) {
return __awaiter(this, void 0, void 0, function* () {

@@ -78,6 +78,9 @@ if (!this.buildTarget) {

}
const defaultedOptions = Object.assign({ overwrite: true }, options);
this.state = BundlerState.Bundling;
//=> Normalize dest to a writable strem
//=> Normalize destinations to writable streams
const fileStream = streamMaker.normalizeWriteStream(file);
const fileName = path.basename(fileStream.path.toString());
const hasManifest = !!defaultedOptions.manifestFile;
const manifestStream = hasManifest ? streamMaker.normalizeWriteStream(defaultedOptions.manifestFile) : null;
//=> Create the build context (contains infos about the paths used by the current build)

@@ -89,2 +92,3 @@ const buildContext = new build_context_1.BuildContext(fileName);

process.on('SIGTERM', signalCleanup);
let manifest;
try {

@@ -105,7 +109,7 @@ //=> Create project and temporary "sub project"

this.logger(`Generating asset bundle in ${buildContext.assetBundleDir}`);
yield unityproj.generateAssetBundle(buildContext, this.assetsStreams, this.buildOptions, this.buildTarget, this.unityLogger, assetPath => this.logger(`Updating resource: ${assetPath}`));
manifest = yield unityproj.generateAssetBundle(buildContext, this.assetsStreams, this.buildOptions, this.buildTarget, this.unityLogger, assetPath => this.logger(`Updating resource: ${assetPath}`));
//=> Move the generated asset bundle to the final dest
//----------------------------------------------------
this.logger(`Moving asset bundle to target destination`);
yield unityproj.moveGeneratedAssetBundle(buildContext, fileStream, overwrite);
yield unityproj.moveGeneratedAssetBundle(buildContext, fileStream, manifestStream, defaultedOptions.overwrite);
}

@@ -123,2 +127,3 @@ finally {

this.logger('Done.');
return manifest;
});

@@ -139,10 +144,10 @@ }

}
checkLoggerType(logger) {
if (typeof logger !== 'function') {
checkLoggerType(loggerFn) {
if (typeof loggerFn !== 'function') {
throw new Error('Logger must be a function of type (message?: string) => void.');
}
}
checkBundlerIsntConfigured() {
checkBundlerIsntAlreadyConfigured() {
if (this.state !== BundlerState.Configuring) {
throw new Error('Cannot configure the bundler after conversion!');
throw new Error('Cannot configure the bundler after the AssetBundle build has started!');
}

@@ -149,0 +154,0 @@ }

@@ -8,3 +8,4 @@ export declare class BuildContext {

readonly assetBundlePath: string;
readonly assetBundleManifestPath: string;
constructor(assetBundleName: string);
}

@@ -13,4 +13,5 @@ "use strict";

this.assetBundlePath = path.resolve(`${this.assetBundleDir}/${assetBundleName}`);
this.assetBundleManifestPath = path.resolve(`${this.assetBundlePath}.manifest`);
}
}
exports.BuildContext = BuildContext;

@@ -0,1 +1,2 @@

export declare const StandaloneOSX = "StandaloneOSXUniversal";
export declare const StandaloneOSXUniversal = "StandaloneOSXUniversal";

@@ -5,2 +6,3 @@ export declare const StandaloneOSXIntel = "StandaloneOSXIntel";

export declare const iOS = "iOS";
export declare const Android = "Android";
export declare const StandaloneLinux = "StandaloneLinux";

@@ -7,0 +9,0 @@ export declare const StandaloneWindows64 = "StandaloneWindows64";

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.StandaloneOSXUniversal = 'StandaloneOSXUniversal';
exports.StandaloneOSXIntel = 'StandaloneOSXIntel';
exports.StandaloneOSX = 'StandaloneOSXUniversal';
exports.StandaloneOSXUniversal = 'StandaloneOSXUniversal'; // @UnityVersion remove when 5.x support is dropped
exports.StandaloneOSXIntel = 'StandaloneOSXIntel'; // @UnityVersion remove when 5.x support is dropped
exports.StandaloneWindows = 'StandaloneWindows';
exports.iOS = 'iOS';
exports.Android = 'Android';
exports.StandaloneLinux = 'StandaloneLinux';

@@ -13,3 +15,3 @@ exports.StandaloneWindows64 = 'StandaloneWindows64';

exports.StandaloneLinuxUniversal = 'StandaloneLinuxUniversal';
exports.StandaloneOSXIntel64 = 'StandaloneOSXIntel64';
exports.StandaloneOSXIntel64 = 'StandaloneOSXIntel64'; // @UnityVersion remove when 5.x support is dropped
exports.Tizen = 'Tizen';

@@ -19,3 +21,3 @@ exports.PSP2 = 'PSP2';

exports.XboxOne = 'XboxOne';
exports.SamsungTV = 'SamsungTV';
exports.SamsungTV = 'SamsungTV'; // @UnityVersion remove when 5.x support is dropped
exports.N3DS = 'N3DS';

@@ -22,0 +24,0 @@ exports.WiiU = 'WiiU';

@@ -7,2 +7,19 @@ /// <reference types="node" />

export declare type BuildTarget = (keyof typeof buildTargets) | string;
export interface IAssetBundleManifest {
ManifestFileVersion: number;
CRC: number;
Hashes: {
[HashType: string]: {
serializedVersion: number;
Hash: string;
};
};
HashAppended: number;
ClassTypes: Array<{
Class: number;
Script: any;
}>;
Assets: string[];
Dependencies: any[];
}
export declare const ProjectDirectory: string;

@@ -14,4 +31,4 @@ export declare function shouldCreateProject(): Promise<boolean>;

export declare function copyAssetsInProject(context: BuildContext, assetStreams: fs.ReadStream[]): Promise<void>;
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: fs.WriteStream, overwrite: boolean): Promise<void>;
export declare function generateAssetBundle(context: BuildContext, fileStreams: fs.ReadStream[], buildOptions: Set<string>, buildTarget: BuildTarget, unityLogger?: logger.SimpleLogger, signalAssetProcessed?: logger.SimpleLogger): Promise<IAssetBundleManifest>;
export declare function moveGeneratedAssetBundle(context: BuildContext, finalDest: fs.WriteStream, finalManifestDest: fs.WriteStream | null, overwrite: boolean): Promise<void>;
export declare function cleanupProject(context: BuildContext): Promise<void>;

@@ -12,2 +12,3 @@ "use strict";

const fsx = require("fs-extra");
const jsyaml = require("js-yaml");
const os = require("os");

@@ -19,17 +20,2 @@ const path = require("path");

const CompilerScriptDest = path.resolve(`${exports.ProjectDirectory}/Assets/Editor/AssetBundleCompiler.cs`);
function copyStreamInDirectory(fileStream, directory) {
return new Promise((resolve, reject) => {
const fileName = path.basename(fileStream.path);
const fileDestStream = fsx.createWriteStream(path.join(directory, fileName));
fileStream.pipe(fileDestStream);
fileDestStream.on('finish', resolve);
fileDestStream.on('error', reject);
});
}
function copyStreamsInDirectory(fileStreams, directory) {
return __awaiter(this, void 0, void 0, function* () {
const copyTasks = fileStreams.map(stream => copyStreamInDirectory(stream, directory));
yield Promise.all(copyTasks);
});
}
function shouldCreateProject() {

@@ -82,6 +68,8 @@ return __awaiter(this, void 0, void 0, function* () {

yield unity.generateAssetBundle(exports.ProjectDirectory, assetNames, context.assetBundleDir, context.assetBundleName, buildOptions, buildTarget, unityLogger, signalAssetProcessed);
const manifestBuf = yield fsx.readFile(context.assetBundleManifestPath);
return jsyaml.safeLoad(manifestBuf.toString());
});
}
exports.generateAssetBundle = generateAssetBundle;
function moveGeneratedAssetBundle(context, finalDest, overwrite) {
function moveGeneratedAssetBundle(context, finalDest, finalManifestDest, overwrite) {
return __awaiter(this, void 0, void 0, function* () {

@@ -95,8 +83,10 @@ if (!overwrite) {

}
const tasks = [];
const assetBundleStream = fsx.createReadStream(context.assetBundlePath);
return new Promise((resolve, reject) => {
assetBundleStream.pipe(finalDest)
.on('finish', () => resolve())
.on('error', (err) => reject(err));
});
tasks.push(copyReadableToWritableStream(assetBundleStream, finalDest));
if (finalManifestDest) {
const manifestStream = fsx.createReadStream(context.assetBundleManifestPath);
tasks.push(copyReadableToWritableStream(manifestStream, finalManifestDest));
}
yield Promise.all(tasks);
});

@@ -115,1 +105,23 @@ }

exports.cleanupProject = cleanupProject;
function copyStreamInDirectory(fileStream, directory) {
return new Promise((resolve, reject) => {
const fileName = path.basename(fileStream.path);
const fileDestStream = fsx.createWriteStream(path.join(directory, fileName));
fileStream.pipe(fileDestStream);
fileDestStream.on('finish', resolve);
fileDestStream.on('error', reject);
});
}
function copyStreamsInDirectory(fileStreams, directory) {
return __awaiter(this, void 0, void 0, function* () {
const copyTasks = fileStreams.map(stream => copyStreamInDirectory(stream, directory));
yield Promise.all(copyTasks);
});
}
function copyReadableToWritableStream(readable, writable) {
return new Promise((resolve, reject) => {
readable.pipe(writable)
.on('finish', () => resolve())
.on('error', (err) => reject(err));
});
}
{
"name": "@mitm/assetbundlecompiler",
"version": "1.4.0",
"version": "1.5.0",
"description": "Node.js wrapper around Unity3D's BuildPipeline to create AssetBundles from any files",
"repository": "git@github.com:toverux/AssetBundleCompiler.git",
"repository": "git@github.com:mitmadness/AssetBundleCompiler.git",
"author": "Morgan Touverey Quilling <mtouverey@methodinthemadness.eu>",

@@ -13,21 +13,25 @@ "license": "MIT",

"watch": "tsc -w",
"semantic-release": "semantic-release pre && npm publish --access public && semantic-release post",
"semantic-release": "semantic-release",
"test": "mocha \"dist/test/**/*.js\"",
"lint": "tslint \"src/**/*.ts\" \"test/**/*.ts\""
"lint": "tslint -t verbose \"src/**/*.ts\" \"test/**/*.ts\"",
"travis-deploy-once": "travis-deploy-once"
},
"devDependencies": {
"@types/chai": "^3.4.35",
"@types/fs-extra": "^3.0.1",
"@types/chai": "^4.1.0",
"@types/fs-extra": "^5.0.0",
"@types/js-yaml": "^3.10.1",
"@types/mocha": "^2.2.40",
"@types/node": "^7.0.11",
"chai": "^3.5.0",
"mocha": "^3.2.0",
"semantic-release": "^6.3.2",
"@types/node": "^9.3.0",
"chai": "^4.1.2",
"mocha": "^4.1.0",
"semantic-release": "^11.0.2",
"tslint": "^5.2.0",
"typescript": "^2.3.2"
"typescript": "~2.6.2",
"travis-deploy-once": "^4.3.1"
},
"dependencies": {
"@mitm/unityinvoker": "^1.0.0",
"fs-extra": "^3.0.1"
"fs-extra": "^5.0.0",
"js-yaml": "^3.10.0"
}
}
}

@@ -84,16 +84,26 @@ <img src="https://github.com/mitmadness/AssetBundleCompiler/raw/master/abcompiler-logo.png" alt="AssetBundleCompiler logo" align="right">

// Give it a path to the asset bundle name or a fs.WriteStream.
.to('/abs/path/to/assetbundle.bin');
.to('/abs/path/to/resources.assetbundle');
```
(Not recommended) `bundle()` is the normal entry function but you can also use directly the underlying `AssetsBundler` class:
You can also retrieve the manifest Unity generates during the build - the manifest contains informations about the asset bundle:
```typescript
const bundler = new AssetsBundler();
// The promise gets resolved with the manifest as a plain JS object
const manifest = await bundle('...').to('...');
await bundler
.includingAssets('/abs/path/to/fbx', '/abs/path/to/texture')
.targeting(WebGL)
.to('/abs/path/to/assetbundle.bin');
/* manifest = {
CRC: 2924050344,
Assets: ['Assets/CopiedAssets/MyAsset.jpg'],
...etc...
} */
```
You can also dump the original manifest file (a YAML file) alongside the assetbundle:
```typescript
const manifest = await bundle('...')
// manifestFile can take a path or a fs.WriteStream too
.to('/path/to/resources.assetbundle', { manifestFile: '/path/to/resources.assetbundle.manifest' });
```
## :bulb: Notes

@@ -100,0 +110,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc