Пример #1
0
ConfFuIO.prototype.logUnpopulated = function(varPaths) {
	var logger = console.error.bind (console);

	if (!this.verbose) {
		logger = function () {};
	}

	logger (paint.error ("those config variables is unpopulated:"));
	for (var varPath in varPaths) {
		var value = (varPaths[varPath] && varPaths[varPath].constructor === Array) ? varPaths[varPath][0] : varPaths[varPath];
		logger ("\t", paint.path(varPath), '=', value);
		varPaths[varPath] = value || "<#undefined>";
	}
	var messageChunks = [
		paint.error ((this.fixupFile? "" : "you must define fixup path, then") + " you can execute"),
		"\n"+paint.confFu ("set <variable> <value>"),
		"\nto define individual variables or",
		"\n"+paint.confFu ("edit fixup"),
		"\nto define all those vars at once by editing",
		this.fixupFile ? paint.path (this.fixupFile.shortPath ()) : "fixup file"
	];

	logger.apply (console, messageChunks);

	// console.log (this.logUnpopulated.list);
};
Пример #2
0
ConfFuIO.prototype.onConfigRead = function (err, data, parsed) {

	if (err && !data) {
		var message = "can't access '" + this.configFile.shortPath() + "' file ("+err.code+")";
		if (this.verbose) console.error (paint.confFu(), paint.error (message));
		this.emit ('error', 'core', 'file', err, this.configFile);
		this.checkList.coreLoaded = false;
		this.applyFixup ();
		return;
	}

	if (!parsed || parsed.error) {
		var message = "cannot parse '" + this.configFile.shortPath() + "' file";
		if (this.verbose) console.error (paint.confFu(), paint.error (message));
		this.emit ('error', 'core', 'parse', (parsed ? parsed.error : null), this.configFile);
		this.checkList.coreLoaded = false;
		this.applyFixup ();
		return;
	}

	this.emit ('read', 'config', this.configFile);

	var config = parsed.object;

	this.id = config.id;

	var self = this;
	// TODO: load includes after fixup is loaded
	this.loadIncludes(config, 'projectRoot', this.configFile.path, function (err, config, variables, placeholders) {

		self.variables    = variables;
		self.placeholders = placeholders;

		if (err) {
			// console.error (err);
			console.warn ("Couldn't load includes.");
			// actually, failure when loading includes is a warning, not an error
			// this.emit ('error', 'core', 'file', err, this.configFile);

			this.checkList.coreLoaded = false;
			this.applyFixup ();

			return;

		}

		self.config = config;

		self.emit ('configLoaded');
	}.bind (this));
};
Пример #3
0
ConfFuIO.prototype.logVariables = function() {
	if (this.verbose) console.log (paint.confFu (), 'variables:');
	for (var varPath in this.setupVariables) {
		var prefix = '[setup]';
		// TODO: show overriden values
		var value = (this.setupVariables[varPath] && this.setupVariables[varPath].constructor === Array)
			? this.setupVariables[varPath][0]
			: this.setupVariables[varPath];
		console.log ("\t", prefix, paint.path(varPath), '=', value);
		//		this.variables[varPath] = value || "<#undefined>";
	}
	for (varPath in this.variables) {
		var value = (this.variables[varPath] && this.variables[varPath].constructor === Array)
			? this.variables[varPath][1]
			: this.variables[varPath];
		var enchanted = this.isEnchantedValue (this.variables[varPath][0]);
		var logEnchanted = [];
		if ('placeholder' in enchanted) {
			logEnchanted.push ('placeholder: ' + enchanted.placeholder);
		}
		if ('default' in enchanted) {
			logEnchanted.push ('default: ' + enchanted.placeholder);
		}
		if ('variable' in enchanted) {
			logEnchanted.push ('referencing: ' + [].slice.apply (enchanted).map (function (ref) {return ref.variable}).join (", "));
		}
		console.log ("\t", paint.path(varPath), '=', paint.yellow (value === undefined ? "undefined" : value), '(' + logEnchanted.join ("; ") + ')');
//		this.variables[varPath] = value || "<#undefined>";
	}
};
Пример #4
0
ConfFuIO.prototype.setVariables = function (fixupVars, force) {

	var changed = this.super_.prototype.setVariables.apply (this, arguments);

	this.fixupChanged = changed;

	// TODO: make sure every test case is covered in 06-dirs with fixupChanged
	// console.log ("setVariables changed:", changed);

	if (!changed) return;

	if (this.fixupFile) {
		// TODO: create fixup directory or display message for user

		// wrote config to the fixup file
		var validFixupString;
		if (this.fixupFile.stringify)
			validFixupString = this.fixupFile.stringify (this.fixup);

		if (validFixupString) {
			this.ioWait ++;
			this.fixupFile.writeFile (validFixupString, function (err) {
				if (err) {
					console.error (paint.confFu(), 'write error for ', paint.path (this.fixupFile.path), ':', err);
				}
				this.ioWait --;
			}.bind (this));
		}
	} else {
		if (this.verbose) console.error (paint.confFu(), 'fixup file name is undefined, cannot write to the fixup file');
		if (Object.keys (fixupVars).length) {

//			process.kill ();
		}
	}

};
Пример #5
0
			this.fixupFile.writeFile (validFixupString, function (err) {
				if (err) {
					console.error (paint.confFu(), 'write error for ', paint.path (this.fixupFile.path), ':', err);
				}
				this.ioWait --;
			}.bind (this));
Пример #6
0
	this.on ('fixupApplied', function () {
		if (self.verbose) {
			console.error (paint.confFu (), 'fixup applied');
		}
	});
Пример #7
0
	this.on ('notReady', function () {
		if (self.verbose) {console.error (paint.confFu (), paint.error ('config not ready'));}
		self.ready = false;
	});
Пример #8
0
	this.on ('ready', function () {
		if (self.verbose) {console.log (paint.confFu (), 'config ready');}
		self.ready = true;
	});