<commit_before>/* eslint consistent-this: 0 */
'use strict';

var _ = require('lodash');
var log = require('gulplog');

var Configuration = require('../configuration');
var metadata = require('./metadata');

function ConfigurableTaskFactory(recipes, registry, expose) {
	this.recipes = recipes;
	this.registry = registry;
	this.expose = expose;
}

function isVisible(task) {
	return task.visibility === Configuration.CONSTANT.VISIBILITY.NORMAL || !('visibility' in task);
}

function isDisabled(task) {
	return task.visibility === Configuration.CONSTANT.VISIBILITY.DISABLED;
}

ConfigurableTaskFactory.prototype.one = function (prefix, rawConfig, parentConfig) {
	var self, recipes, taskInfo;

	self = this;
	recipes = this.recipes;

	taskInfo = Configuration.getTaskRuntimeInfo(rawConfig);
	if (isDisabled(taskInfo)) {
		return null;
	}

	return simple() || auxiliary() || composite() || noop();

	// simple task should show up in task tree and cli.
	function simple() {
		var recipe, configs;

		recipe = recipes.inline(taskInfo) || recipes.plugin(taskInfo) || recipes.task(taskInfo);
		if (recipe) {
			configs = Configuration.sort(taskInfo, rawConfig, parentConfig, recipe.schema);
			return self.create(prefix, taskInfo, configs.taskConfig, recipe);
		}
	}

	// auxiliary task should show up in task tree, but not in cli by default for simplicity.
	function auxiliary() {
		var recipe, configs, tasks;

		recipe = reference() || synthetic();
		if (recipe) {
			configs = Configuration.sort(taskInfo, rawConfig, parentConfig, recipe.schema);
			if (!('visibility' in taskInfo)) {
				taskInfo.visibility = '.';
			}
			// TODO: add running time profile.
			// TODO: add metadata.
			if (recipe.type === 'stream' || recipe.type === 'flow') {
				tasks = createTasks(configs);
			}
			return self.create(prefix, taskInfo, configs.taskConfig, recipe, tasks);
		}

		function reference() {
			return recipes.reference(taskInfo);
		}

		function synthetic() {
			return recipes.stream(taskInfo) || recipes.flow(taskInfo);
		}
	}

	// composite task should show up in task treem, and show up in cli if holding task is a named task.
	function composite() {
		var configs, type, recipe, tasks, wrapper;

		configs = Configuration.sort(taskInfo, rawConfig, parentConfig);
		tasks = taskInfo.parallel || taskInfo.series || taskInfo.task || configs.subTaskConfigs;
		type = _type();
		if (type) {
			tasks = createTasks(configs);
			// NOTE: must call gulp's series or parallel to profile task's running time.
			recipe = function (done) {
				var fn;

				// TODO: use async.map, async.series rather then gulp.parallel, gulp.series.
				fn = this.gulp[type].apply(null, tasks);
				return fn.call(this, done);
			};
			recipe.displayName = '<' + type + '>';
			if (taskInfo.name) {
				wrapper = self.create(prefix, {
					visibility: '.'
				}, configs.taskConfig, recipe, tasks);
				return self.create(prefix, taskInfo, configs.taskConfig, wrapper, [wrapper]);
			}
			if (!('visibility' in taskInfo)) {
				taskInfo.visibility = '.';
			}
			return self.create(prefix, taskInfo, configs.taskConfig, recipe, tasks);
		}

		function _type() {
			if (taskInfo.series) {
				return 'series';
			} else if (taskInfo.parallel) {
				return 'parallel';
			} else if (_.size(tasks)) {
				if (Array.isArray(tasks)) {
					return 'series';
				} else if (_.isPlainObject(tasks)) {
					return 'parallel';
				}
			}
		}
	}

	function noop() {
		log.warn('configure:', 'the task "' + taskInfo.name + "\" won't do anything, misspelled a recipe name?");
		return self.create(prefix, taskInfo, {}, self.recipes.noop());
	}

	function createTasks(configs) {
		var tasksPrefix, tasks;

		tasks = configs.taskInfo.parallel || configs.taskInfo.series || configs.taskInfo.task || configs.subTaskConfigs;
		if (tasks && _.size(tasks)) {<commit_msg>task/factory: fix named reference task not exposed<commit_after>/* eslint consistent-this: 0 */
'use strict';

var _ = require('lodash');
var log = require('gulplog');

var Configuration = require('../configuration');
var metadata = require('./metadata');

function ConfigurableTaskFactory(recipes, registry, expose) {
	this.recipes = recipes;
	this.registry = registry;
	this.expose = expose;
}

function isVisible(task) {
	return task.visibility === Configuration.CONSTANT.VISIBILITY.NORMAL || !('visibility' in task);
}

function isDisabled(task) {
	return task.visibility === Configuration.CONSTANT.VISIBILITY.DISABLED;
}

ConfigurableTaskFactory.prototype.one = function (prefix, rawConfig, parentConfig) {
	var self, recipes, taskInfo;

	self = this;
	recipes = this.recipes;

	taskInfo = Configuration.getTaskRuntimeInfo(rawConfig);
	if (isDisabled(taskInfo)) {
		return null;
	}

	return simple() || auxiliary() || composite() || noop();

	// simple task should show up in task tree and cli.
	function simple() {
		var recipe, configs;

		recipe = recipes.inline(taskInfo) || recipes.plugin(taskInfo) || recipes.task(taskInfo);
		if (recipe) {
			configs = Configuration.sort(taskInfo, rawConfig, parentConfig, recipe.schema);
			return self.create(prefix, taskInfo, configs.taskConfig, recipe);
		}
	}

	// auxiliary task should show up in task tree, but not in cli by default for simplicity.
	function auxiliary() {
		var recipe, configs, tasks;

		recipe = reference() || synthetic();
		if (recipe) {
			configs = Configuration.sort(taskInfo, rawConfig, parentConfig, recipe.schema);
			if (!taskInfo.name && !('visibility' in taskInfo)) {
				taskInfo.visibility = '.';
			}
			// TODO: add running time profile.
			// TODO: add metadata.
			if (recipe.type === 'stream' || recipe.type === 'flow') {
				tasks = createTasks(configs);
			}
			return self.create(prefix, taskInfo, configs.taskConfig, recipe, tasks);
		}

		function reference() {
			return recipes.reference(taskInfo);
		}

		function synthetic() {
			return recipes.stream(taskInfo) || recipes.flow(taskInfo);
		}
	}

	// composite task should show up in task treem, and show up in cli if holding task is a named task.
	function composite() {
		var configs, type, recipe, tasks, wrapper;

		configs = Configuration.sort(taskInfo, rawConfig, parentConfig);
		tasks = taskInfo.parallel || taskInfo.series || taskInfo.task || configs.subTaskConfigs;
		type = _type();
		if (type) {
			tasks = createTasks(configs);
			// NOTE: must call gulp's series or parallel to profile task's running time.
			recipe = function (done) {
				var fn;

				// TODO: use async.map, async.series rather then gulp.parallel, gulp.series.
				fn = this.gulp[type].apply(null, tasks);
				return fn.call(this, done);
			};
			recipe.displayName = '<' + type + '>';
			if (taskInfo.name) {
				wrapper = self.create(prefix, {
					visibility: '.'
				}, configs.taskConfig, recipe, tasks);
				return self.create(prefix, taskInfo, configs.taskConfig, wrapper, [wrapper]);
			}
			taskInfo.visibility = '.';
			return self.create(prefix, taskInfo, configs.taskConfig, recipe, tasks);
		}

		function _type() {
			if (taskInfo.series) {
				return 'series';
			} else if (taskInfo.parallel) {
				return 'parallel';
			} else if (_.size(tasks)) {
				if (Array.isArray(tasks)) {
					return 'series';
				} else if (_.isPlainObject(tasks)) {
					return 'parallel';
				}
			}
		}
	}

	function noop() {
		log.warn('configure:', 'the task "' + taskInfo.name + "\" won't do anything, misspelled a recipe name?");
		return self.create(prefix, taskInfo, {}, self.recipes.noop());
	}

	function createTasks(configs) {
		var tasksPrefix, tasks;

		tasks = configs.taskInfo.parallel || configs.taskInfo.series || configs.taskInfo.task || configs.subTaskConfigs;
		if (tasks && _.size(tasks)) {
{'fraction_non_alphanumeric': 0.14129158512720155, 'fraction_numerical': 0.0002609262883235486, 'mean_word_length': 3.8518987341772153, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, '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': '1505438', 'n_tokens_mistral': 2689, 'n_tokens_neox': 2364, 'n_words': 635}