<commit_before>// asset/importer - import assets from other asset containers
// Part of Stardazed
// (c) 2015-2017 by <NAME> - @zenmumbler
// https://github.com/stardazed/stardazed

/// <reference path="./identifier.ts" />

namespace sd.asset {

	/**
	 * Extend an AssetPipeline with the capacity to import external asset (group) files.
	 */
	export const importerStage: AssetPipelineStage = (pipeline: AssetPipeline) => {
		const assetImporter: AssetProcessor = (asset: Asset) =>
			new Promise<Asset>((resolve, reject) => {
				if (asset.kind === "import") {
					if (typeof asset.uri !== "string") {
						return reject("Importer: import asset did not specify a uri");
					}
					if (!(asset.blob instanceof Blob)) {
						return reject("Importer: external asset data was not loaded");
					}

					importer.importAssets(asset.blob, asset.uri)
						.then(dependencies => {
							asset.dependencies = dependencies;
							resolve(asset);
						});
				}
				else {
					resolve(asset);
				}
			});

		// place next processor at end of chain
		const process = pipeline.process;
		pipeline.process = (asset: Asset) => process(asset).then(assetImporter);
	};

	/**
	 * Extend an AssetPipeline with the feature to flatten an imported asset's
	 * dependencies into its containing asset's dependencies.
	 */
	export const importFlatteningStage: AssetPipelineStage = (pipeline: AssetPipeline) => {
		const importFlattener: AssetProcessor = (asset: Asset) =>
			new Promise<Asset>(resolve => {
				if (asset.dependencies) {
					let assetsToMerge: AssetDependencies = {};
					for (const depName in asset.dependencies) {
						if (asset.dependencies.hasOwnProperty(depName)) {
							const dependency = asset.dependencies[depName];
							if (dependency && dependency.kind === "import") {
								const importedAssets = dependency.dependencies;
								if (importedAssets) {<commit_msg>wip(mesh): quick name transfer hack for single-item imports<commit_after>// asset/importer - import assets from other asset containers
// Part of Stardazed
// (c) 2015-2017 by <NAME> - @zenmumbler
// https://github.com/stardazed/stardazed

/// <reference path="./identifier.ts" />

namespace sd.asset {

	/**
	 * Extend an AssetPipeline with the capacity to import external asset (group) files.
	 */
	export const importerStage: AssetPipelineStage = (pipeline: AssetPipeline) => {
		const assetImporter: AssetProcessor = (asset: Asset) =>
			new Promise<Asset>((resolve, reject) => {
				if (asset.kind === "import") {
					if (typeof asset.uri !== "string") {
						return reject("Importer: import asset did not specify a uri");
					}
					if (!(asset.blob instanceof Blob)) {
						return reject("Importer: external asset data was not loaded");
					}

					importer.importAssets(asset.blob, asset.uri)
						.then(dependencies => {
							// FIXME: this is just a quick hack, need a formal name/id gen system
							if (asset.name && propertyCount(dependencies) === 1) {
								container.mapObject(dependencies, (subAsset) => {
									if (subAsset) {
										subAsset.name = asset.name;
									}
									return subAsset;
								});
							}
							asset.dependencies = dependencies;
							resolve(asset);
						});
				}
				else {
					resolve(asset);
				}
			});

		// place next processor at end of chain
		const process = pipeline.process;
		pipeline.process = (asset: Asset) => process(asset).then(assetImporter);
	};

	/**
	 * Extend an AssetPipeline with the feature to flatten an imported asset's
	 * dependencies into its containing asset's dependencies.
	 */
	export const importFlatteningStage: AssetPipelineStage = (pipeline: AssetPipeline) => {
		const importFlattener: AssetProcessor = (asset: Asset) =>
			new Promise<Asset>(resolve => {
				if (asset.dependencies) {
					let assetsToMerge: AssetDependencies = {};
					for (const depName in asset.dependencies) {
						if (asset.dependencies.hasOwnProperty(depName)) {
							const dependency = asset.dependencies[depName];
							if (dependency && dependency.kind === "import") {
								const importedAssets = dependency.dependencies;
								if (importedAssets) {
{'fraction_non_alphanumeric': 0.12318489835430785, 'fraction_numerical': 0.004114230396902226, 'mean_word_length': 3.1495983935742973, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 28, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5485766', 'n_tokens_mistral': 1506, 'n_tokens_neox': 1126, 'n_words': 334}