From 12b43a4c6900f88465873cf82bad98f14746aba0 Mon Sep 17 00:00:00 2001 From: Peter Cottle Date: Fri, 14 Dec 2012 01:16:34 -0800 Subject: [PATCH] big file movearound --- build/bundle.js | 491 +++----------------------------------------- grunt.js | 1 + src/collections.js | 8 +- src/commandModel.js | 372 --------------------------------- src/commandViews.js | 6 +- src/debug.js | 4 +- src/git.js | 2 +- src/main.js | 53 ----- src/tree.js | 2 +- src/visuals.js | 2 +- 10 files changed, 42 insertions(+), 899 deletions(-) delete mode 100644 src/commandModel.js delete mode 100644 src/main.js diff --git a/build/bundle.js b/build/bundle.js index 809fcaa3..e0c866c2 100644 --- a/build/bundle.js +++ b/build/bundle.js @@ -531,7 +531,7 @@ exports.GRAPHICS = GRAPHICS; require.define("/git.js",function(require,module,exports,__dirname,__filename,process,global){var AnimationFactoryModule = require('./animationFactory'); var animationFactory = new AnimationFactoryModule.AnimationFactory(); -var Main = require('./main'); +var Main = require('./app/main'); var AnimationQueue = require('./async').AnimationQueue; var InteractiveRebaseView = require('./miscViews').InteractiveRebaseView; @@ -2438,7 +2438,7 @@ exports.AnimationFactory = AnimationFactory; }); -require.define("/main.js",function(require,module,exports,__dirname,__filename,process,global){/** +require.define("/app/main.js",function(require,module,exports,__dirname,__filename,process,global){/** * Globals */ var events = _.clone(Backbone.Events); @@ -2448,7 +2448,7 @@ var mainVis = null; /////////////////////////////////////////////////////////////////////// $(document).ready(function(){ - var Visuals = require('./visuals'); + var Visuals = require('../visuals'); ui = new UI(); mainVis = new Visuals.Visualization({ @@ -2463,8 +2463,8 @@ $(document).ready(function(){ }); function UI() { - var Collections = require('./collections'); - var CommandViews = require('./commandViews'); + var Collections = require('../collections'); + var CommandViews = require('../commandViews'); this.commandCollection = new Collections.CommandCollection(); @@ -2494,7 +2494,7 @@ exports.getUI = function() { }); -require.define("/visuals.js",function(require,module,exports,__dirname,__filename,process,global){var Main = require('./main'); +require.define("/visuals.js",function(require,module,exports,__dirname,__filename,process,global){var Main = require('./app/main'); var GRAPHICS = require('./constants').GRAPHICS; var GLOBAL = require('./constants').GLOBAL; @@ -3179,9 +3179,9 @@ exports.Visualization = Visualization; require.define("/collections.js",function(require,module,exports,__dirname,__filename,process,global){var Commit = require('./git').Commit; var Branch = require('./git').Branch; -var Main = require('./main'); -var Command = require('./commandModel').Command; -var CommandEntry = require('./commandModel').CommandEntry; +var Main = require('./app/main'); +var Command = require('./models/commandModel').Command; +var CommandEntry = require('./models/commandModel').CommandEntry; var TIME = require('./constants').TIME; var CommitCollection = Backbone.Collection.extend({ @@ -3207,7 +3207,7 @@ var CommandBuffer = Backbone.Model.extend({ }, initialize: function(options) { - require('./main').getEvents().on('gitCommandReady', _.bind( + require('./app/main').getEvents().on('gitCommandReady', _.bind( this.addCommand, this )); @@ -3282,7 +3282,7 @@ exports.CommandBuffer = CommandBuffer; }); -require.define("/commandModel.js",function(require,module,exports,__dirname,__filename,process,global){var Errors = require('./errors'); +require.define("/models/commandModel.js",function(require,module,exports,__dirname,__filename,process,global){var Errors = require('../errors'); var CommandProcessError = Errors.CommandProcessError; var GitError = Errors.GitError; @@ -3466,7 +3466,7 @@ var Command = Backbone.Model.extend({ }); }], [/^refresh$/, function() { - var events = require('./main').getEvents(); + var events = require('../app/main').getEvents(); events.trigger('refreshTree'); throw new CommandResult({ @@ -3474,7 +3474,7 @@ var Command = Backbone.Model.extend({ }); }], [/^rollup (\d+)$/, function(bits) { - var events = require('./main').getEvents(); + var events = require('../app/main').getEvents(); // go roll up these commands by joining them with semicolons events.trigger('rollupCommands', bits[1]); @@ -3705,7 +3705,7 @@ var GitError = exports.GitError = MyError.extend({ }); -require.define("/tree.js",function(require,module,exports,__dirname,__filename,process,global){var Main = require('./main'); +require.define("/tree.js",function(require,module,exports,__dirname,__filename,process,global){var Main = require('./app/main'); var GRAPHICS = require('./constants').GRAPHICS; var randomHueString = function() { @@ -4669,9 +4669,9 @@ exports.VisBranch = VisBranch; }); require.define("/commandViews.js",function(require,module,exports,__dirname,__filename,process,global){var CommandEntryCollection = require('./collections').CommandEntryCollection; -var Main = require('./main'); -var Command = require('./commandModel').Command; -var CommandEntry = require('./commandModel').CommandEntry; +var Main = require('./app/main'); +var Command = require('./models/commandModel').Command; +var CommandEntry = require('./models/commandModel').CommandEntry; var Errors = require('./errors'); var Warning = Errors.Warning; @@ -5658,9 +5658,9 @@ require("/async.js"); require.define("/collections.js",function(require,module,exports,__dirname,__filename,process,global){var Commit = require('./git').Commit; var Branch = require('./git').Branch; -var Main = require('./main'); -var Command = require('./commandModel').Command; -var CommandEntry = require('./commandModel').CommandEntry; +var Main = require('./app/main'); +var Command = require('./models/commandModel').Command; +var CommandEntry = require('./models/commandModel').CommandEntry; var TIME = require('./constants').TIME; var CommitCollection = Backbone.Collection.extend({ @@ -5686,7 +5686,7 @@ var CommandBuffer = Backbone.Model.extend({ }, initialize: function(options) { - require('./main').getEvents().on('gitCommandReady', _.bind( + require('./app/main').getEvents().on('gitCommandReady', _.bind( this.addCommand, this )); @@ -5762,386 +5762,10 @@ exports.CommandBuffer = CommandBuffer; }); require("/collections.js"); -require.define("/commandModel.js",function(require,module,exports,__dirname,__filename,process,global){var Errors = require('./errors'); - -var CommandProcessError = Errors.CommandProcessError; -var GitError = Errors.GitError; -var Warning = Errors.Warning; -var CommandResult = Errors.CommandResult; - -var Command = Backbone.Model.extend({ - defaults: { - status: 'inqueue', - rawStr: null, - result: '', - - error: null, - warnings: null, - - generalArgs: null, - supportedMap: null, - options: null, - method: null, - - createTime: null - }, - - validateAtInit: function() { - // weird things happen with defaults if you dont - // make new objects - this.set('generalArgs', []); - this.set('supportedMap', {}); - this.set('warnings', []); - - if (this.get('rawStr') === null) { - throw new Error('Give me a string!'); - } - if (!this.get('createTime')) { - this.set('createTime', new Date().toString()); - } - - - this.on('change:error', this.errorChanged, this); - // catch errors on init - if (this.get('error')) { - this.errorChanged(); - } - }, - - setResult: function(msg) { - this.set('result', msg); - }, - - addWarning: function(msg) { - this.get('warnings').push(msg); - // change numWarnings so the change event fires. This is bizarre -- Backbone can't - // detect if an array changes, so adding an element does nothing - this.set('numWarnings', this.get('numWarnings') ? this.get('numWarnings') + 1 : 1); - }, - - getFormattedWarnings: function() { - if (!this.get('warnings').length) { - return ''; - } - var i = ''; - return '

' + i + this.get('warnings').join('

' + i) + '

'; - }, - - initialize: function() { - this.validateAtInit(); - this.parseOrCatch(); - }, - - parseOrCatch: function() { - try { - this.parse(); - } catch (err) { - if (err instanceof CommandProcessError || - err instanceof GitError || - err instanceof CommandResult || - err instanceof Warning) { - // errorChanged() will handle status and all of that - this.set('error', err); - } else { - throw err; - } - } - }, - - errorChanged: function() { - var err = this.get('error'); - if (err instanceof CommandProcessError || - err instanceof GitError) { - this.set('status', 'error'); - } else if (err instanceof CommandResult) { - this.set('status', 'finished'); - } else if (err instanceof Warning) { - this.set('status', 'warning'); - } - this.formatError(); - }, - - formatError: function() { - this.set('result', this.get('error').toResult()); - }, - - getShortcutMap: function() { - return { - 'git commit': /^gc($|\s)/, - 'git add': /^ga($|\s)/, - 'git checkout': /^gchk($|\s)/, - 'git rebase': /^gr($|\s)/, - 'git branch': /^gb($|\s)/ - }; - }, - - getRegexMap: function() { - return { - // ($|\s) means that we either have to end the string - // after the command or there needs to be a space for options - commit: /^commit($|\s)/, - add: /^add($|\s)/, - checkout: /^checkout($|\s)/, - rebase: /^rebase($|\s)/, - reset: /^reset($|\s)/, - branch: /^branch($|\s)/, - revert: /^revert($|\s)/, - log: /^log($|\s)/, - merge: /^merge($|\s)/, - show: /^show($|\s)/, - status: /^status($|\s)/, - 'cherry-pick': /^cherry-pick($|\s)/ - }; - }, - - getSandboxCommands: function() { - return [ - [/^ls/, function() { - throw new CommandResult({ - msg: "DontWorryAboutFilesInThisDemo.txt" - }); - }], - [/^cd/, function() { - throw new CommandResult({ - msg: "Directory Changed to '/directories/dont/matter/in/this/demo'" - }); - }], - [/^git help($|\s)/, function() { - // sym link this to the blank git command - var allCommands = Command.prototype.getSandboxCommands(); - // wow this is hacky :( - var equivalent = 'git'; - _.each(allCommands, function(bits) { - var regex = bits[0]; - if (regex.test(equivalent)) { - bits[1](); - } - }); - }], - [/^git$/, function() { - var lines = [ - 'Git Version PCOTTLE.1.0', - '
', - 'Usage:', - _.escape('\t git []'), - '
', - 'Supported commands:', - '
' - ]; - var commands = OptionParser.prototype.getMasterOptionMap(); - - // build up a nice display of what we support - _.each(commands, function(commandOptions, command) { - lines.push('git ' + command); - _.each(commandOptions, function(vals, optionName) { - lines.push('\t ' + optionName); - }, this); - }, this); - - // format and throw - var msg = lines.join('\n'); - msg = msg.replace(/\t/g, '   '); - throw new CommandResult({ - msg: msg - }); - }], - [/^refresh$/, function() { - var events = require('./main').getEvents(); - - events.trigger('refreshTree'); - throw new CommandResult({ - msg: "Refreshing tree..." - }); - }], - [/^rollup (\d+)$/, function(bits) { - var events = require('./main').getEvents(); - - // go roll up these commands by joining them with semicolons - events.trigger('rollupCommands', bits[1]); - throw new CommandResult({ - msg: 'Commands combined!' - }); - }] - ]; - }, - - parse: function() { - var str = this.get('rawStr'); - // first if the string is empty, they just want a blank line - if (!str.length) { - throw new CommandResult({msg: ""}); - } - - // then check if it's one of our sandbox commands - _.each(this.getSandboxCommands(), function(tuple) { - var regex = tuple[0]; - var results = regex.exec(str); - if (results) { - tuple[1](results); - } - }); - - // then check if shortcut exists, and replace, but - // preserve options if so - _.each(this.getShortcutMap(), function(regex, method) { - var results = regex.exec(str); - if (results) { - str = method + ' ' + str.slice(results[0].length); - } - }); - - // see if begins with git - if (str.slice(0,3) !== 'git') { - throw new CommandProcessError({ - msg: 'That command is not supported, sorry!' - }); - } - - // ok, we have a (probably) valid command. actually parse it - this.gitParse(str); - }, - - gitParse: function(str) { - // now slice off command part - var fullCommand = str.slice('git '.length); - - // see if we support this particular command - _.each(this.getRegexMap(), function(regex, method) { - if (regex.exec(fullCommand)) { - this.set('options', fullCommand.slice(method.length + 1)); - this.set('method', method); - // we should stop iterating, but the regex will only match - // one command in practice. we could stop iterating if we used - // jqeurys for each but im using underscore (for no real reason other - // than style) - } - }, this); - - if (!this.get('method')) { - throw new CommandProcessError({ - msg: "Sorry, this demo does not support that git command: " + fullCommand - }); - } - - // parse off the options and assemble the map / general args - var optionParser = new OptionParser(this.get('method'), this.get('options')); - - // steal these away so we can be completely JSON - this.set('generalArgs', optionParser.generalArgs); - this.set('supportedMap', optionParser.supportedMap); - } -}); - -/** - * OptionParser - */ -function OptionParser(method, options) { - this.method = method; - this.rawOptions = options; - - this.supportedMap = this.getMasterOptionMap()[method]; - if (this.supportedMap === undefined) { - throw new Error('No option map for ' + method); - } - - this.generalArgs = []; - this.explodeAndSet(); -} - -OptionParser.prototype.getMasterOptionMap = function() { - // here a value of false means that we support it, even if its just a - // pass-through option. If the value is not here (aka will be undefined - // when accessed), we do not support it. - return { - commit: { - '--amend': false, - '-a': false, // warning - '-am': false, // warning - '-m': false - }, - status: {}, - log: {}, - add: {}, - 'cherry-pick': {}, - branch: { - '-d': false, - '-D': false, - '-f': false, - '--contains': false - }, - checkout: { - '-b': false, - '-B': false, - '-': false - }, - reset: { - '--hard': false, - '--soft': false // this will raise an error but we catch it in gitEngine - }, - merge: {}, - rebase: { - '-i': false // the mother of all options - }, - revert: {}, - show: {} - }; -}; - -OptionParser.prototype.explodeAndSet = function() { - // split on spaces, except when inside quotes - - var exploded = this.rawOptions.match(/('.*?'|".*?"|\S+)/g) || []; - - for (var i = 0; i < exploded.length; i++) { - var part = exploded[i]; - if (part.slice(0,1) == '-') { - // it's an option, check supportedMap - if (this.supportedMap[part] === undefined) { - throw new CommandProcessError({ - msg: 'The option "' + part + '" is not supported' - }); - } - - // go through and include all the next args until we hit another option or the end - var optionArgs = []; - var next = i + 1; - while (next < exploded.length && exploded[next].slice(0,1) != '-') { - optionArgs.push(exploded[next]); - next += 1; - } - i = next - 1; - - // **phew** we are done grabbing those. theseArgs is truthy even with an empty array - this.supportedMap[part] = optionArgs; - } else { - // must be a general arg - this.generalArgs.push(part); - } - } - - // done! -}; - -// command entry is for the commandview -var CommandEntry = Backbone.Model.extend({ - defaults: { - text: '' - }, - localStorage: new Backbone.LocalStorage('CommandEntries') -}); - - -exports.CommandEntry = CommandEntry; -exports.Command = Command; - - -}); -require("/commandModel.js"); - require.define("/commandViews.js",function(require,module,exports,__dirname,__filename,process,global){var CommandEntryCollection = require('./collections').CommandEntryCollection; -var Main = require('./main'); -var Command = require('./commandModel').Command; -var CommandEntry = require('./commandModel').CommandEntry; +var Main = require('./app/main'); +var Command = require('./models/commandModel').Command; +var CommandEntry = require('./models/commandModel').CommandEntry; var Errors = require('./errors'); var Warning = Errors.Warning; @@ -6589,13 +6213,13 @@ require.define("/debug.js",function(require,module,exports,__dirname,__filename, Tree: require('./tree'), Visuals: require('./visuals'), Git: require('./git'), - CommandModel: require('./commandModel'), + CommandModel: require('./models/commandModel'), Levels: require('./levels'), Constants: require('./constants'), Collections: require('./collections'), Async: require('./async'), AnimationFactory: require('./animationFactory'), - Main: require('./main') + Main: require('./app/main') }; _.each(toGlobalize, function(module) { @@ -6659,7 +6283,7 @@ require("/errors.js"); require.define("/git.js",function(require,module,exports,__dirname,__filename,process,global){var AnimationFactoryModule = require('./animationFactory'); var animationFactory = new AnimationFactoryModule.AnimationFactory(); -var Main = require('./main'); +var Main = require('./app/main'); var AnimationQueue = require('./async').AnimationQueue; var InteractiveRebaseView = require('./miscViews').InteractiveRebaseView; @@ -8401,63 +8025,6 @@ exports.LevelEngine = LevelEngine; }); require("/levels.js"); -require.define("/main.js",function(require,module,exports,__dirname,__filename,process,global){/** - * Globals - */ -var events = _.clone(Backbone.Events); -var ui = null; -var mainVis = null; - -/////////////////////////////////////////////////////////////////////// - -$(document).ready(function(){ - var Visuals = require('./visuals'); - - ui = new UI(); - mainVis = new Visuals.Visualization({ - el: $('#canvasWrapper')[0] - }); - - if (/\?demo/.test(window.location.href)) { - setTimeout(function() { - events.trigger('submitCommandValueFromEvent', "gc; git checkout HEAD~1; git commit; git checkout -b bugFix; gc; gc; git rebase master; git checkout master; gc; gc; git merge bugFix"); - }, 500); - } -}); - -function UI() { - var Collections = require('./collections'); - var CommandViews = require('./commandViews'); - - this.commandCollection = new Collections.CommandCollection(); - - this.commandBuffer = new Collections.CommandBuffer({ - collection: this.commandCollection - }); - - this.commandPromptView = new CommandViews.CommandPromptView({ - el: $('#commandLineBar'), - collection: this.commandCollection - }); - this.commandLineHistoryView = new CommandViews.CommandLineHistoryView({ - el: $('#commandLineHistory'), - collection: this.commandCollection - }); - - $('#commandTextField').focus(); -} - -exports.getEvents = function() { - return events; -}; -exports.getUI = function() { - return ui; -}; - - -}); -require("/main.js"); - require.define("/miscViews.js",function(require,module,exports,__dirname,__filename,process,global){var InteractiveRebaseView = Backbone.View.extend({ tagName: 'div', template: _.template($('#interactive-rebase-template').html()), @@ -8609,7 +8176,7 @@ exports.InteractiveRebaseView = InteractiveRebaseView; }); require("/miscViews.js"); -require.define("/tree.js",function(require,module,exports,__dirname,__filename,process,global){var Main = require('./main'); +require.define("/tree.js",function(require,module,exports,__dirname,__filename,process,global){var Main = require('./app/main'); var GRAPHICS = require('./constants').GRAPHICS; var randomHueString = function() { @@ -9573,7 +9140,7 @@ exports.VisBranch = VisBranch; }); require("/tree.js"); -require.define("/visuals.js",function(require,module,exports,__dirname,__filename,process,global){var Main = require('./main'); +require.define("/visuals.js",function(require,module,exports,__dirname,__filename,process,global){var Main = require('./app/main'); var GRAPHICS = require('./constants').GRAPHICS; var GLOBAL = require('./constants').GLOBAL; diff --git a/grunt.js b/grunt.js index e58ec1ca..87ec3c14 100644 --- a/grunt.js +++ b/grunt.js @@ -105,6 +105,7 @@ module.exports = function(grunt) { grunt.registerTask('default', 'lint jasmine_node browserify rm min hash compliment'); grunt.registerTask('watching', 'browserify'); + grunt.registerTask('brow', 'browserify'); grunt.registerTask('export', 'browserify min'); grunt.registerTask('test', 'jasmine_node'); }; diff --git a/src/collections.js b/src/collections.js index dc557b2c..165a1dbd 100644 --- a/src/collections.js +++ b/src/collections.js @@ -1,9 +1,9 @@ var Commit = require('./git').Commit; var Branch = require('./git').Branch; -var Main = require('./main'); -var Command = require('./commandModel').Command; -var CommandEntry = require('./commandModel').CommandEntry; +var Main = require('./app/main'); +var Command = require('./models/commandModel').Command; +var CommandEntry = require('./models/commandModel').CommandEntry; var TIME = require('./constants').TIME; var CommitCollection = Backbone.Collection.extend({ @@ -29,7 +29,7 @@ var CommandBuffer = Backbone.Model.extend({ }, initialize: function(options) { - require('./main').getEvents().on('gitCommandReady', _.bind( + require('./app/main').getEvents().on('gitCommandReady', _.bind( this.addCommand, this )); diff --git a/src/commandModel.js b/src/commandModel.js deleted file mode 100644 index 04ff8716..00000000 --- a/src/commandModel.js +++ /dev/null @@ -1,372 +0,0 @@ -var Errors = require('./errors'); - -var CommandProcessError = Errors.CommandProcessError; -var GitError = Errors.GitError; -var Warning = Errors.Warning; -var CommandResult = Errors.CommandResult; - -var Command = Backbone.Model.extend({ - defaults: { - status: 'inqueue', - rawStr: null, - result: '', - - error: null, - warnings: null, - - generalArgs: null, - supportedMap: null, - options: null, - method: null, - - createTime: null - }, - - validateAtInit: function() { - // weird things happen with defaults if you dont - // make new objects - this.set('generalArgs', []); - this.set('supportedMap', {}); - this.set('warnings', []); - - if (this.get('rawStr') === null) { - throw new Error('Give me a string!'); - } - if (!this.get('createTime')) { - this.set('createTime', new Date().toString()); - } - - - this.on('change:error', this.errorChanged, this); - // catch errors on init - if (this.get('error')) { - this.errorChanged(); - } - }, - - setResult: function(msg) { - this.set('result', msg); - }, - - addWarning: function(msg) { - this.get('warnings').push(msg); - // change numWarnings so the change event fires. This is bizarre -- Backbone can't - // detect if an array changes, so adding an element does nothing - this.set('numWarnings', this.get('numWarnings') ? this.get('numWarnings') + 1 : 1); - }, - - getFormattedWarnings: function() { - if (!this.get('warnings').length) { - return ''; - } - var i = ''; - return '

' + i + this.get('warnings').join('

' + i) + '

'; - }, - - initialize: function() { - this.validateAtInit(); - this.parseOrCatch(); - }, - - parseOrCatch: function() { - try { - this.parse(); - } catch (err) { - if (err instanceof CommandProcessError || - err instanceof GitError || - err instanceof CommandResult || - err instanceof Warning) { - // errorChanged() will handle status and all of that - this.set('error', err); - } else { - throw err; - } - } - }, - - errorChanged: function() { - var err = this.get('error'); - if (err instanceof CommandProcessError || - err instanceof GitError) { - this.set('status', 'error'); - } else if (err instanceof CommandResult) { - this.set('status', 'finished'); - } else if (err instanceof Warning) { - this.set('status', 'warning'); - } - this.formatError(); - }, - - formatError: function() { - this.set('result', this.get('error').toResult()); - }, - - getShortcutMap: function() { - return { - 'git commit': /^gc($|\s)/, - 'git add': /^ga($|\s)/, - 'git checkout': /^gchk($|\s)/, - 'git rebase': /^gr($|\s)/, - 'git branch': /^gb($|\s)/ - }; - }, - - getRegexMap: function() { - return { - // ($|\s) means that we either have to end the string - // after the command or there needs to be a space for options - commit: /^commit($|\s)/, - add: /^add($|\s)/, - checkout: /^checkout($|\s)/, - rebase: /^rebase($|\s)/, - reset: /^reset($|\s)/, - branch: /^branch($|\s)/, - revert: /^revert($|\s)/, - log: /^log($|\s)/, - merge: /^merge($|\s)/, - show: /^show($|\s)/, - status: /^status($|\s)/, - 'cherry-pick': /^cherry-pick($|\s)/ - }; - }, - - getSandboxCommands: function() { - return [ - [/^ls/, function() { - throw new CommandResult({ - msg: "DontWorryAboutFilesInThisDemo.txt" - }); - }], - [/^cd/, function() { - throw new CommandResult({ - msg: "Directory Changed to '/directories/dont/matter/in/this/demo'" - }); - }], - [/^git help($|\s)/, function() { - // sym link this to the blank git command - var allCommands = Command.prototype.getSandboxCommands(); - // wow this is hacky :( - var equivalent = 'git'; - _.each(allCommands, function(bits) { - var regex = bits[0]; - if (regex.test(equivalent)) { - bits[1](); - } - }); - }], - [/^git$/, function() { - var lines = [ - 'Git Version PCOTTLE.1.0', - '
', - 'Usage:', - _.escape('\t git []'), - '
', - 'Supported commands:', - '
' - ]; - var commands = OptionParser.prototype.getMasterOptionMap(); - - // build up a nice display of what we support - _.each(commands, function(commandOptions, command) { - lines.push('git ' + command); - _.each(commandOptions, function(vals, optionName) { - lines.push('\t ' + optionName); - }, this); - }, this); - - // format and throw - var msg = lines.join('\n'); - msg = msg.replace(/\t/g, '   '); - throw new CommandResult({ - msg: msg - }); - }], - [/^refresh$/, function() { - var events = require('./main').getEvents(); - - events.trigger('refreshTree'); - throw new CommandResult({ - msg: "Refreshing tree..." - }); - }], - [/^rollup (\d+)$/, function(bits) { - var events = require('./main').getEvents(); - - // go roll up these commands by joining them with semicolons - events.trigger('rollupCommands', bits[1]); - throw new CommandResult({ - msg: 'Commands combined!' - }); - }] - ]; - }, - - parse: function() { - var str = this.get('rawStr'); - // first if the string is empty, they just want a blank line - if (!str.length) { - throw new CommandResult({msg: ""}); - } - - // then check if it's one of our sandbox commands - _.each(this.getSandboxCommands(), function(tuple) { - var regex = tuple[0]; - var results = regex.exec(str); - if (results) { - tuple[1](results); - } - }); - - // then check if shortcut exists, and replace, but - // preserve options if so - _.each(this.getShortcutMap(), function(regex, method) { - var results = regex.exec(str); - if (results) { - str = method + ' ' + str.slice(results[0].length); - } - }); - - // see if begins with git - if (str.slice(0,3) !== 'git') { - throw new CommandProcessError({ - msg: 'That command is not supported, sorry!' - }); - } - - // ok, we have a (probably) valid command. actually parse it - this.gitParse(str); - }, - - gitParse: function(str) { - // now slice off command part - var fullCommand = str.slice('git '.length); - - // see if we support this particular command - _.each(this.getRegexMap(), function(regex, method) { - if (regex.exec(fullCommand)) { - this.set('options', fullCommand.slice(method.length + 1)); - this.set('method', method); - // we should stop iterating, but the regex will only match - // one command in practice. we could stop iterating if we used - // jqeurys for each but im using underscore (for no real reason other - // than style) - } - }, this); - - if (!this.get('method')) { - throw new CommandProcessError({ - msg: "Sorry, this demo does not support that git command: " + fullCommand - }); - } - - // parse off the options and assemble the map / general args - var optionParser = new OptionParser(this.get('method'), this.get('options')); - - // steal these away so we can be completely JSON - this.set('generalArgs', optionParser.generalArgs); - this.set('supportedMap', optionParser.supportedMap); - } -}); - -/** - * OptionParser - */ -function OptionParser(method, options) { - this.method = method; - this.rawOptions = options; - - this.supportedMap = this.getMasterOptionMap()[method]; - if (this.supportedMap === undefined) { - throw new Error('No option map for ' + method); - } - - this.generalArgs = []; - this.explodeAndSet(); -} - -OptionParser.prototype.getMasterOptionMap = function() { - // here a value of false means that we support it, even if its just a - // pass-through option. If the value is not here (aka will be undefined - // when accessed), we do not support it. - return { - commit: { - '--amend': false, - '-a': false, // warning - '-am': false, // warning - '-m': false - }, - status: {}, - log: {}, - add: {}, - 'cherry-pick': {}, - branch: { - '-d': false, - '-D': false, - '-f': false, - '--contains': false - }, - checkout: { - '-b': false, - '-B': false, - '-': false - }, - reset: { - '--hard': false, - '--soft': false // this will raise an error but we catch it in gitEngine - }, - merge: {}, - rebase: { - '-i': false // the mother of all options - }, - revert: {}, - show: {} - }; -}; - -OptionParser.prototype.explodeAndSet = function() { - // split on spaces, except when inside quotes - - var exploded = this.rawOptions.match(/('.*?'|".*?"|\S+)/g) || []; - - for (var i = 0; i < exploded.length; i++) { - var part = exploded[i]; - if (part.slice(0,1) == '-') { - // it's an option, check supportedMap - if (this.supportedMap[part] === undefined) { - throw new CommandProcessError({ - msg: 'The option "' + part + '" is not supported' - }); - } - - // go through and include all the next args until we hit another option or the end - var optionArgs = []; - var next = i + 1; - while (next < exploded.length && exploded[next].slice(0,1) != '-') { - optionArgs.push(exploded[next]); - next += 1; - } - i = next - 1; - - // **phew** we are done grabbing those. theseArgs is truthy even with an empty array - this.supportedMap[part] = optionArgs; - } else { - // must be a general arg - this.generalArgs.push(part); - } - } - - // done! -}; - -// command entry is for the commandview -var CommandEntry = Backbone.Model.extend({ - defaults: { - text: '' - }, - localStorage: new Backbone.LocalStorage('CommandEntries') -}); - - -exports.CommandEntry = CommandEntry; -exports.Command = Command; - diff --git a/src/commandViews.js b/src/commandViews.js index f21c9d50..2b7c725a 100644 --- a/src/commandViews.js +++ b/src/commandViews.js @@ -1,7 +1,7 @@ var CommandEntryCollection = require('./collections').CommandEntryCollection; -var Main = require('./main'); -var Command = require('./commandModel').Command; -var CommandEntry = require('./commandModel').CommandEntry; +var Main = require('./app/main'); +var Command = require('./models/commandModel').Command; +var CommandEntry = require('./models/commandModel').CommandEntry; var Errors = require('./errors'); var Warning = Errors.Warning; diff --git a/src/debug.js b/src/debug.js index 34d548eb..b8c5baf3 100644 --- a/src/debug.js +++ b/src/debug.js @@ -2,13 +2,13 @@ var toGlobalize = { Tree: require('./tree'), Visuals: require('./visuals'), Git: require('./git'), - CommandModel: require('./commandModel'), + CommandModel: require('./models/commandModel'), Levels: require('./levels'), Constants: require('./constants'), Collections: require('./collections'), Async: require('./async'), AnimationFactory: require('./animationFactory'), - Main: require('./main') + Main: require('./app/main') }; _.each(toGlobalize, function(module) { diff --git a/src/git.js b/src/git.js index e1769e6b..36f8463e 100644 --- a/src/git.js +++ b/src/git.js @@ -1,6 +1,6 @@ var AnimationFactoryModule = require('./animationFactory'); var animationFactory = new AnimationFactoryModule.AnimationFactory(); -var Main = require('./main'); +var Main = require('./app/main'); var AnimationQueue = require('./async').AnimationQueue; var InteractiveRebaseView = require('./miscViews').InteractiveRebaseView; diff --git a/src/main.js b/src/main.js deleted file mode 100644 index 3c4f10b1..00000000 --- a/src/main.js +++ /dev/null @@ -1,53 +0,0 @@ -/** - * Globals - */ -var events = _.clone(Backbone.Events); -var ui = null; -var mainVis = null; - -/////////////////////////////////////////////////////////////////////// - -$(document).ready(function(){ - var Visuals = require('./visuals'); - - ui = new UI(); - mainVis = new Visuals.Visualization({ - el: $('#canvasWrapper')[0] - }); - - if (/\?demo/.test(window.location.href)) { - setTimeout(function() { - events.trigger('submitCommandValueFromEvent', "gc; git checkout HEAD~1; git commit; git checkout -b bugFix; gc; gc; git rebase master; git checkout master; gc; gc; git merge bugFix"); - }, 500); - } -}); - -function UI() { - var Collections = require('./collections'); - var CommandViews = require('./commandViews'); - - this.commandCollection = new Collections.CommandCollection(); - - this.commandBuffer = new Collections.CommandBuffer({ - collection: this.commandCollection - }); - - this.commandPromptView = new CommandViews.CommandPromptView({ - el: $('#commandLineBar'), - collection: this.commandCollection - }); - this.commandLineHistoryView = new CommandViews.CommandLineHistoryView({ - el: $('#commandLineHistory'), - collection: this.commandCollection - }); - - $('#commandTextField').focus(); -} - -exports.getEvents = function() { - return events; -}; -exports.getUI = function() { - return ui; -}; - diff --git a/src/tree.js b/src/tree.js index 04a8f293..9ad926a1 100644 --- a/src/tree.js +++ b/src/tree.js @@ -1,4 +1,4 @@ -var Main = require('./main'); +var Main = require('./app/main'); var GRAPHICS = require('./constants').GRAPHICS; var randomHueString = function() { diff --git a/src/visuals.js b/src/visuals.js index 43610c72..1b287092 100644 --- a/src/visuals.js +++ b/src/visuals.js @@ -1,4 +1,4 @@ -var Main = require('./main'); +var Main = require('./app/main'); var GRAPHICS = require('./constants').GRAPHICS; var GLOBAL = require('./constants').GLOBAL;