mirror of
https://github.com/pcottle/learnGitBranching.git
synced 2025-06-26 16:08:34 +02:00
ok disbaled map is now just instants
This commit is contained in:
parent
4046916432
commit
4aeb56c840
6 changed files with 77 additions and 188 deletions
163
build/bundle.js
163
build/bundle.js
|
@ -4845,6 +4845,8 @@ var Constants = require('../util/constants');
|
||||||
var Views = require('../views');
|
var Views = require('../views');
|
||||||
var util = require('../util');
|
var util = require('../util');
|
||||||
var Command = require('../models/commandModel').Command;
|
var Command = require('../models/commandModel').Command;
|
||||||
|
var ParseWaterfall = require('../level/parseWaterfall').ParseWaterfall;
|
||||||
|
var DisabledMap = require('../level/disabledMap').DisabledMap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Globals
|
* Globals
|
||||||
|
@ -4952,6 +4954,9 @@ function CommandUI() {
|
||||||
collection: this.commandCollection
|
collection: this.commandCollection
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.parseWaterfall = new ParseWaterfall();
|
||||||
|
this.parseWaterfall.addFirst('instantWaterfall', new DisabledMap().getInstantCommands());
|
||||||
|
|
||||||
eventBaton.stealBaton('commandSubmitted', this.commandSubmitted, this);
|
eventBaton.stealBaton('commandSubmitted', this.commandSubmitted, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4959,7 +4964,8 @@ CommandUI.prototype.commandSubmitted = function(value) {
|
||||||
events.trigger('commandSubmittedPassive', value);
|
events.trigger('commandSubmittedPassive', value);
|
||||||
util.splitTextCommand(value, function(command) {
|
util.splitTextCommand(value, function(command) {
|
||||||
this.commandCollection.add(new Command({
|
this.commandCollection.add(new Command({
|
||||||
rawStr: command
|
rawStr: command,
|
||||||
|
parseWaterfall: this.parseWaterfall
|
||||||
}));
|
}));
|
||||||
}, this);
|
}, this);
|
||||||
};
|
};
|
||||||
|
@ -5228,7 +5234,7 @@ var parse = function(str) {
|
||||||
_.each(regexMap, function(regex, thisMethod) {
|
_.each(regexMap, function(regex, thisMethod) {
|
||||||
if (regex.exec(str)) {
|
if (regex.exec(str)) {
|
||||||
options = str.slice(thisMethod.length + 1);
|
options = str.slice(thisMethod.length + 1);
|
||||||
method = thisMethod;
|
method = thisMethod.slice('git '.length);
|
||||||
}
|
}
|
||||||
}, this);
|
}, this);
|
||||||
|
|
||||||
|
@ -5352,6 +5358,7 @@ var SandboxCommands = require('../level/SandboxCommands');
|
||||||
|
|
||||||
// more or less a static class
|
// more or less a static class
|
||||||
function ParseWaterfall(options) {
|
function ParseWaterfall(options) {
|
||||||
|
options = options || {};
|
||||||
this.shortcutWaterfall = options.shortcutWaterfall || [
|
this.shortcutWaterfall = options.shortcutWaterfall || [
|
||||||
GitCommands.shortcutMap
|
GitCommands.shortcutMap
|
||||||
];
|
];
|
||||||
|
@ -5484,6 +5491,48 @@ var instantCommands = [
|
||||||
|
|
||||||
exports.instantCommands = instantCommands;
|
exports.instantCommands = instantCommands;
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
require.define("/src/js/level/disabledMap.js",function(require,module,exports,__dirname,__filename,process,global){var _ = require('underscore');
|
||||||
|
|
||||||
|
var GitCommands = require('../git/commands');
|
||||||
|
|
||||||
|
var Errors = require('../util/errors');
|
||||||
|
var GitError = Errors.GitError;
|
||||||
|
|
||||||
|
function DisabledMap(options) {
|
||||||
|
options = options || {};
|
||||||
|
this.disabledMap = options.disabledMap || {
|
||||||
|
'git cherry-pick': true,
|
||||||
|
'git rebase': true
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
DisabledMap.prototype.getInstantCommands = function() {
|
||||||
|
// this produces an array of regex / function pairs that can be
|
||||||
|
// piped into a parse waterfall to disable certain git commmands
|
||||||
|
// :D
|
||||||
|
var instants = [];
|
||||||
|
var onMatch = function() {
|
||||||
|
throw new GitError({
|
||||||
|
msg: 'That git command is disabled for this level!'
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
_.each(this.disabledMap, function(val, disabledCommand) {
|
||||||
|
var gitRegex = GitCommands.regexMap[disabledCommand];
|
||||||
|
if (!gitRegex) {
|
||||||
|
throw new Error('wuttttt this disbaled command' + disabledCommand +
|
||||||
|
' has no regex matching');
|
||||||
|
}
|
||||||
|
instants.push([gitRegex, onMatch]);
|
||||||
|
});
|
||||||
|
return instants;
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.DisabledMap = DisabledMap;
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
require.define("/src/js/visuals/visualization.js",function(require,module,exports,__dirname,__filename,process,global){var _ = require('underscore');
|
require.define("/src/js/visuals/visualization.js",function(require,module,exports,__dirname,__filename,process,global){var _ = require('underscore');
|
||||||
|
@ -14359,6 +14408,8 @@ var Constants = require('../util/constants');
|
||||||
var Views = require('../views');
|
var Views = require('../views');
|
||||||
var util = require('../util');
|
var util = require('../util');
|
||||||
var Command = require('../models/commandModel').Command;
|
var Command = require('../models/commandModel').Command;
|
||||||
|
var ParseWaterfall = require('../level/parseWaterfall').ParseWaterfall;
|
||||||
|
var DisabledMap = require('../level/disabledMap').DisabledMap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Globals
|
* Globals
|
||||||
|
@ -14466,6 +14517,9 @@ function CommandUI() {
|
||||||
collection: this.commandCollection
|
collection: this.commandCollection
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.parseWaterfall = new ParseWaterfall();
|
||||||
|
this.parseWaterfall.addFirst('instantWaterfall', new DisabledMap().getInstantCommands());
|
||||||
|
|
||||||
eventBaton.stealBaton('commandSubmitted', this.commandSubmitted, this);
|
eventBaton.stealBaton('commandSubmitted', this.commandSubmitted, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14473,7 +14527,8 @@ CommandUI.prototype.commandSubmitted = function(value) {
|
||||||
events.trigger('commandSubmittedPassive', value);
|
events.trigger('commandSubmittedPassive', value);
|
||||||
util.splitTextCommand(value, function(command) {
|
util.splitTextCommand(value, function(command) {
|
||||||
this.commandCollection.add(new Command({
|
this.commandCollection.add(new Command({
|
||||||
rawStr: command
|
rawStr: command,
|
||||||
|
parseWaterfall: this.parseWaterfall
|
||||||
}));
|
}));
|
||||||
}, this);
|
}, this);
|
||||||
};
|
};
|
||||||
|
@ -14573,7 +14628,7 @@ var parse = function(str) {
|
||||||
_.each(regexMap, function(regex, thisMethod) {
|
_.each(regexMap, function(regex, thisMethod) {
|
||||||
if (regex.exec(str)) {
|
if (regex.exec(str)) {
|
||||||
options = str.slice(thisMethod.length + 1);
|
options = str.slice(thisMethod.length + 1);
|
||||||
method = thisMethod;
|
method = thisMethod.slice('git '.length);
|
||||||
}
|
}
|
||||||
}, this);
|
}, this);
|
||||||
|
|
||||||
|
@ -16548,7 +16603,7 @@ exports.TreeCompare = TreeCompare;
|
||||||
});
|
});
|
||||||
require("/src/js/git/treeCompare.js");
|
require("/src/js/git/treeCompare.js");
|
||||||
|
|
||||||
require.define("/src/js/level/disableMap.js",function(require,module,exports,__dirname,__filename,process,global){var _ = require('underscore');
|
require.define("/src/js/level/disabledMap.js",function(require,module,exports,__dirname,__filename,process,global){var _ = require('underscore');
|
||||||
|
|
||||||
var GitCommands = require('../git/commands');
|
var GitCommands = require('../git/commands');
|
||||||
|
|
||||||
|
@ -16556,9 +16611,10 @@ var Errors = require('../util/errors');
|
||||||
var GitError = Errors.GitError;
|
var GitError = Errors.GitError;
|
||||||
|
|
||||||
function DisabledMap(options) {
|
function DisabledMap(options) {
|
||||||
|
options = options || {};
|
||||||
this.disabledMap = options.disabledMap || {
|
this.disabledMap = options.disabledMap || {
|
||||||
'cherry-pick': true,
|
'git cherry-pick': true,
|
||||||
'rebase': true
|
'git rebase': true
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16588,97 +16644,7 @@ exports.DisabledMap = DisabledMap;
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
require("/src/js/level/disableMap.js");
|
require("/src/js/level/disabledMap.js");
|
||||||
|
|
||||||
require.define("/src/js/level/inputWaterfall.js",function(require,module,exports,__dirname,__filename,process,global){var _ = require('underscore');
|
|
||||||
|
|
||||||
var Main = require('../app');
|
|
||||||
var GitCommands = require('../git/commands');
|
|
||||||
|
|
||||||
var Errors = require('../util/errors');
|
|
||||||
var CommandProcessError = Errors.CommandProcessError;
|
|
||||||
var GitError = Errors.GitError;
|
|
||||||
var Warning = Errors.Warning;
|
|
||||||
var CommandResult = Errors.CommandResult;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This class supports a few things we need for levels:
|
|
||||||
~ A disabled map (to prevent certain git commands from firing)
|
|
||||||
~ A post-git command hook (to compare the git tree against the solution)
|
|
||||||
~ Extra level-specific commands (like help, hint, etc) that are async
|
|
||||||
**/
|
|
||||||
|
|
||||||
function InputWaterfall(options) {
|
|
||||||
options = options || {};
|
|
||||||
this.listenEvent = options.listenEvent || 'processCommand';
|
|
||||||
this.disabledMap = options.disabledMap || {
|
|
||||||
'git cherry-pick': true,
|
|
||||||
'git rebase': true
|
|
||||||
};
|
|
||||||
|
|
||||||
this.listen();
|
|
||||||
}
|
|
||||||
|
|
||||||
InputWaterfall.prototype.listen = function() {
|
|
||||||
Main.getEvents().on(this.listenEvent, this.process, this);
|
|
||||||
};
|
|
||||||
|
|
||||||
InputWaterfall.prototype.mute = function() {
|
|
||||||
Main.getEvents().off(this.listenEvent, this.process, this);
|
|
||||||
};
|
|
||||||
|
|
||||||
InputWaterfall.prototype.process = function(command, callback) {
|
|
||||||
|
|
||||||
if (this.checkDisabledMap(command)) {
|
|
||||||
callback();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// for now, just immediately fire it
|
|
||||||
Main.getEvents().trigger('processGitCommand', command, callback);
|
|
||||||
};
|
|
||||||
|
|
||||||
InputWaterfall.prototype.sliceGitOff = function(str) {
|
|
||||||
return str.slice('git '.length);
|
|
||||||
};
|
|
||||||
|
|
||||||
InputWaterfall.prototype.checkDisabledMap = function(command) {
|
|
||||||
try {
|
|
||||||
this.loopDisabledMap(command);
|
|
||||||
} catch(err) {
|
|
||||||
Errors.filterError(err);
|
|
||||||
command.set('error', err);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
// not needed explicitly, but included for clarity
|
|
||||||
return false;
|
|
||||||
};
|
|
||||||
|
|
||||||
InputWaterfall.prototype.loopDisabledMap = function(command) {
|
|
||||||
var toTest = this.sliceGitOff(command.get('rawStr'));
|
|
||||||
var regexMap = GitCommands.regexMap;
|
|
||||||
|
|
||||||
_.each(this.disabledMap, function(val, disabledGitCommand) {
|
|
||||||
disabledGitCommand = this.sliceGitOff(disabledGitCommand);
|
|
||||||
|
|
||||||
var regex = regexMap[disabledGitCommand];
|
|
||||||
if (!regex) {
|
|
||||||
console.warn('wut, no regex for command', disabledGitCommand);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (regex.test(toTest)) {
|
|
||||||
throw new GitError({
|
|
||||||
msg: 'That git command is disabled for this level!'
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}, this);
|
|
||||||
};
|
|
||||||
|
|
||||||
exports.InputWaterfall = InputWaterfall;
|
|
||||||
|
|
||||||
|
|
||||||
});
|
|
||||||
require("/src/js/level/inputWaterfall.js");
|
|
||||||
|
|
||||||
require.define("/src/js/level/parseWaterfall.js",function(require,module,exports,__dirname,__filename,process,global){var _ = require('underscore');
|
require.define("/src/js/level/parseWaterfall.js",function(require,module,exports,__dirname,__filename,process,global){var _ = require('underscore');
|
||||||
|
|
||||||
|
@ -16687,6 +16653,7 @@ var SandboxCommands = require('../level/SandboxCommands');
|
||||||
|
|
||||||
// more or less a static class
|
// more or less a static class
|
||||||
function ParseWaterfall(options) {
|
function ParseWaterfall(options) {
|
||||||
|
options = options || {};
|
||||||
this.shortcutWaterfall = options.shortcutWaterfall || [
|
this.shortcutWaterfall = options.shortcutWaterfall || [
|
||||||
GitCommands.shortcutMap
|
GitCommands.shortcutMap
|
||||||
];
|
];
|
||||||
|
|
|
@ -5,6 +5,8 @@ var Constants = require('../util/constants');
|
||||||
var Views = require('../views');
|
var Views = require('../views');
|
||||||
var util = require('../util');
|
var util = require('../util');
|
||||||
var Command = require('../models/commandModel').Command;
|
var Command = require('../models/commandModel').Command;
|
||||||
|
var ParseWaterfall = require('../level/parseWaterfall').ParseWaterfall;
|
||||||
|
var DisabledMap = require('../level/disabledMap').DisabledMap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Globals
|
* Globals
|
||||||
|
@ -112,6 +114,9 @@ function CommandUI() {
|
||||||
collection: this.commandCollection
|
collection: this.commandCollection
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.parseWaterfall = new ParseWaterfall();
|
||||||
|
this.parseWaterfall.addFirst('instantWaterfall', new DisabledMap().getInstantCommands());
|
||||||
|
|
||||||
eventBaton.stealBaton('commandSubmitted', this.commandSubmitted, this);
|
eventBaton.stealBaton('commandSubmitted', this.commandSubmitted, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -119,7 +124,8 @@ CommandUI.prototype.commandSubmitted = function(value) {
|
||||||
events.trigger('commandSubmittedPassive', value);
|
events.trigger('commandSubmittedPassive', value);
|
||||||
util.splitTextCommand(value, function(command) {
|
util.splitTextCommand(value, function(command) {
|
||||||
this.commandCollection.add(new Command({
|
this.commandCollection.add(new Command({
|
||||||
rawStr: command
|
rawStr: command,
|
||||||
|
parseWaterfall: this.parseWaterfall
|
||||||
}));
|
}));
|
||||||
}, this);
|
}, this);
|
||||||
};
|
};
|
||||||
|
|
|
@ -71,7 +71,7 @@ var parse = function(str) {
|
||||||
_.each(regexMap, function(regex, thisMethod) {
|
_.each(regexMap, function(regex, thisMethod) {
|
||||||
if (regex.exec(str)) {
|
if (regex.exec(str)) {
|
||||||
options = str.slice(thisMethod.length + 1);
|
options = str.slice(thisMethod.length + 1);
|
||||||
method = thisMethod;
|
method = thisMethod.slice('git '.length);
|
||||||
}
|
}
|
||||||
}, this);
|
}, this);
|
||||||
|
|
||||||
|
|
|
@ -6,9 +6,10 @@ var Errors = require('../util/errors');
|
||||||
var GitError = Errors.GitError;
|
var GitError = Errors.GitError;
|
||||||
|
|
||||||
function DisabledMap(options) {
|
function DisabledMap(options) {
|
||||||
|
options = options || {};
|
||||||
this.disabledMap = options.disabledMap || {
|
this.disabledMap = options.disabledMap || {
|
||||||
'cherry-pick': true,
|
'git cherry-pick': true,
|
||||||
'rebase': true
|
'git rebase': true
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,86 +0,0 @@
|
||||||
var _ = require('underscore');
|
|
||||||
|
|
||||||
var Main = require('../app');
|
|
||||||
var GitCommands = require('../git/commands');
|
|
||||||
|
|
||||||
var Errors = require('../util/errors');
|
|
||||||
var CommandProcessError = Errors.CommandProcessError;
|
|
||||||
var GitError = Errors.GitError;
|
|
||||||
var Warning = Errors.Warning;
|
|
||||||
var CommandResult = Errors.CommandResult;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This class supports a few things we need for levels:
|
|
||||||
~ A disabled map (to prevent certain git commands from firing)
|
|
||||||
~ A post-git command hook (to compare the git tree against the solution)
|
|
||||||
~ Extra level-specific commands (like help, hint, etc) that are async
|
|
||||||
**/
|
|
||||||
|
|
||||||
function InputWaterfall(options) {
|
|
||||||
options = options || {};
|
|
||||||
this.listenEvent = options.listenEvent || 'processCommand';
|
|
||||||
this.disabledMap = options.disabledMap || {
|
|
||||||
'git cherry-pick': true,
|
|
||||||
'git rebase': true
|
|
||||||
};
|
|
||||||
|
|
||||||
this.listen();
|
|
||||||
}
|
|
||||||
|
|
||||||
InputWaterfall.prototype.listen = function() {
|
|
||||||
Main.getEvents().on(this.listenEvent, this.process, this);
|
|
||||||
};
|
|
||||||
|
|
||||||
InputWaterfall.prototype.mute = function() {
|
|
||||||
Main.getEvents().off(this.listenEvent, this.process, this);
|
|
||||||
};
|
|
||||||
|
|
||||||
InputWaterfall.prototype.process = function(command, callback) {
|
|
||||||
|
|
||||||
if (this.checkDisabledMap(command)) {
|
|
||||||
callback();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// for now, just immediately fire it
|
|
||||||
Main.getEvents().trigger('processGitCommand', command, callback);
|
|
||||||
};
|
|
||||||
|
|
||||||
InputWaterfall.prototype.sliceGitOff = function(str) {
|
|
||||||
return str.slice('git '.length);
|
|
||||||
};
|
|
||||||
|
|
||||||
InputWaterfall.prototype.checkDisabledMap = function(command) {
|
|
||||||
try {
|
|
||||||
this.loopDisabledMap(command);
|
|
||||||
} catch(err) {
|
|
||||||
Errors.filterError(err);
|
|
||||||
command.set('error', err);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
// not needed explicitly, but included for clarity
|
|
||||||
return false;
|
|
||||||
};
|
|
||||||
|
|
||||||
InputWaterfall.prototype.loopDisabledMap = function(command) {
|
|
||||||
var toTest = this.sliceGitOff(command.get('rawStr'));
|
|
||||||
var regexMap = GitCommands.regexMap;
|
|
||||||
|
|
||||||
_.each(this.disabledMap, function(val, disabledGitCommand) {
|
|
||||||
disabledGitCommand = this.sliceGitOff(disabledGitCommand);
|
|
||||||
|
|
||||||
var regex = regexMap[disabledGitCommand];
|
|
||||||
if (!regex) {
|
|
||||||
console.warn('wut, no regex for command', disabledGitCommand);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (regex.test(toTest)) {
|
|
||||||
throw new GitError({
|
|
||||||
msg: 'That git command is disabled for this level!'
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}, this);
|
|
||||||
};
|
|
||||||
|
|
||||||
exports.InputWaterfall = InputWaterfall;
|
|
||||||
|
|
|
@ -5,6 +5,7 @@ var SandboxCommands = require('../level/SandboxCommands');
|
||||||
|
|
||||||
// more or less a static class
|
// more or less a static class
|
||||||
function ParseWaterfall(options) {
|
function ParseWaterfall(options) {
|
||||||
|
options = options || {};
|
||||||
this.shortcutWaterfall = options.shortcutWaterfall || [
|
this.shortcutWaterfall = options.shortcutWaterfall || [
|
||||||
GitCommands.shortcutMap
|
GitCommands.shortcutMap
|
||||||
];
|
];
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue