file-prompt
Advanced tools
Comparing version 1.1.3 to 1.2.0
@@ -19,10 +19,4 @@ /** | ||
*/ | ||
Object.assign(config.rules, { | ||
/** | ||
* Since this tool will be used on linting production ready code | ||
* lets make it an error to have console statements in the code. | ||
*/ | ||
'no-console': 2 | ||
}); | ||
Object.assign(config.rules, {}); | ||
export default config; |
@@ -22,5 +22,6 @@ /* eslint no-process-env: 0 */ | ||
paths.src = project.to('test', '*.js'); | ||
paths.dir = project.to('test'); | ||
paths.watch = [ | ||
project.paths.js.src, | ||
paths.src | ||
paths.src, | ||
]; | ||
@@ -30,8 +31,13 @@ | ||
* Reusable test | ||
* | ||
* @param {vinyl} [file] - A vinyl file | ||
* @returns {stream} Resulting transform stream | ||
*/ | ||
function test () { | ||
let args = minimist(process.argv.slice(2)); | ||
function test (file) { | ||
let args = minimist(process.argv.slice(2)), | ||
src = paths.src; | ||
return gulp.src(paths.src, { read: false }) | ||
if (file) src = project.join(paths.dir, file.basename); | ||
return gulp.src(src, { read: false }) | ||
.pipe(plumber()) | ||
@@ -54,3 +60,4 @@ .pipe(mocha(args)); | ||
require.cache = {}; | ||
log.task('Cleared') | ||
log.task('test') | ||
.action('Cleared') | ||
.data(file.relative) | ||
@@ -60,3 +67,3 @@ .text('From cache') | ||
return test(); | ||
return test(file); | ||
}); | ||
@@ -63,0 +70,0 @@ }); |
@@ -1,1 +0,1 @@ | ||
"use strict";function _interopRequireDefault(e){return e&&e.__esModule?e:{"default":e}}function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _possibleConstructorReturn(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function _inherits(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}function readDir(e,t){var r={};return Array.isArray(t)||(t=[t]),_fs2["default"].readdirSync(e).filter(function(e){return(0,_minimatchAll2["default"])(e,t)}).forEach(function(t){var n=_path2["default"].basename(t,"_page.js");r[n]=require(_path2["default"].resolve(__dirname,e,t))["default"]}),r}function selectCurrentPage(e){return e.getState().currentPage}var _createClass=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}();Object.defineProperty(exports,"__esModule",{value:!0});var _component=require("./component"),_component2=_interopRequireDefault(_component),_fs=require("fs"),_fs2=_interopRequireDefault(_fs),_minimatchAll=require("minimatch-all"),_minimatchAll2=_interopRequireDefault(_minimatchAll),_path=require("path"),_path2=_interopRequireDefault(_path),_reducers=require("./reducers"),_reducers2=_interopRequireDefault(_reducers),_redux=require("redux"),_actions=require("./actions"),App=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e));return r.store=(0,_redux.createStore)(_reducers2["default"],{config:{base:r.props.base},files:[],glob:r.props.glob,currentPage:{name:"index",props:{glob:r.props.glob},isNavigating:!1}}),r}return _inherits(t,e),_createClass(t,[{key:"getDefaultProps",value:function(){return{base:process.cwd(),filter:"**/*.js",stdin:process.stdin,stdout:process.stdout}}},{key:"getInitialState",value:function(){return{pageName:null,pageProps:null}}},{key:"componentWillMount",value:function(){var e=this,t=selectCurrentPage(this.store);this.once("complete",function(){e.componentWillUnmount()},this),this.once("error",function(){e.componentWillUnmount()},this),this.setState({pageName:t.name,pageProps:t.props})}},{key:"componentDidMount",value:function(){var e=this;this.unsubscribe=this.store.subscribe(function(){var t=selectCurrentPage(e.store);t.isNavigating&&(e.setState({pageName:t.name,pageProps:t.props}),_component2["default"].display(e),e.store.dispatch((0,_actions.navigateComplete)()))})}},{key:"componentWillUnmount",value:function(){this.off(),this.unsubscribe()}},{key:"renderPage",value:function(){var e={app:this,store:this.store,stdin:this.props.stdin,stdout:this.props.stdout};if(!t.PAGES.hasOwnProperty(this.state.pageName))throw new Error("App: Page does not exist “"+this.state.pageName+"”.");return this.state.pageProps&&Object.assign(e,this.state.pageProps),new t.PAGES[this.state.pageName](e).render()}},{key:"render",value:function(){return this.renderPage()}}]),t}(_component2["default"]);App.PAGES=readDir(_path2["default"].join(__dirname,"pages"),"*_page.js"),exports["default"]=App; | ||
"use strict";function _interopRequireDefault(e){return e&&e.__esModule?e:{"default":e}}function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _possibleConstructorReturn(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function _inherits(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}function readDir(e,t){var r={};return Array.isArray(t)||(t=[t]),_fs2["default"].readdirSync(e).filter(function(e){return(0,_minimatchAll2["default"])(e,t)}).forEach(function(t){var n=_path2["default"].basename(t,"_page.js");r[n]=require(_path2["default"].resolve(__dirname,e,t))["default"]}),r}function selectCurrentPage(e){return e.getState().currentPage}var _createClass=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}();Object.defineProperty(exports,"__esModule",{value:!0});var _component=require("./component"),_component2=_interopRequireDefault(_component),_fs=require("fs"),_fs2=_interopRequireDefault(_fs),_minimatchAll=require("minimatch-all"),_minimatchAll2=_interopRequireDefault(_minimatchAll),_path=require("path"),_path2=_interopRequireDefault(_path),_reducers=require("./reducers"),_reducers2=_interopRequireDefault(_reducers),_redux=require("redux"),_actions=require("./actions"),App=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e));return r.store=(0,_redux.createStore)(_reducers2["default"],{config:{base:r.props.base},files:[],glob:r.props.glob,currentPage:{name:"index",props:{glob:r.props.glob},isNavigating:!1}}),r}return _inherits(t,e),_createClass(t,[{key:"getDefaultProps",value:function(){return{base:process.cwd(),filter:"**/*.js",stdin:process.stdin,stdout:process.stdout}}},{key:"getInitialState",value:function(){return{pageName:null,pageProps:null}}},{key:"componentWillMount",value:function(){var e=this,t=selectCurrentPage(this.store);this.once("complete",function(){e.componentWillUnmount()},this),this.once("error",function(){e.componentWillUnmount()},this),this.setState({pageName:t.name,pageProps:t.props})}},{key:"componentDidMount",value:function(){var e=this;this.unsubscribe=this.store.subscribe(function(){var t=selectCurrentPage(e.store);t.isNavigating&&(e.setState({pageName:t.name,pageProps:t.props}),_component2["default"].display(e),e.store.dispatch((0,_actions.navigateComplete)()))})}},{key:"componentWillUnmount",value:function(){this.off(),this.unsubscribe()}},{key:"renderPage",value:function(){var e={app:this,store:this.store,stdin:this.props.stdin,stdout:this.props.stdout},r=void 0;if(!t.PAGES.hasOwnProperty(this.state.pageName))throw new Error("App: Page does not exist “"+this.state.pageName+"”.");return this.state.pageProps&&Object.assign(e,this.state.pageProps),r=new t.PAGES[this.state.pageName](e),"index"===this.state.pageName&&r.once("complete",this.emit.bind(this,"complete")),r.render()}},{key:"render",value:function(){return this.renderPage()}}]),t}(_component2["default"]);App.PAGES=readDir(_path2["default"].join(__dirname,"pages"),"*_page.js"),exports["default"]=App; |
@@ -1,1 +0,1 @@ | ||
"use strict";function _interopRequireDefault(e){return e&&e.__esModule?e:{"default":e}}function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _possibleConstructorReturn(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function _inherits(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}var _createClass=function(){function e(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}return function(t,n,o){return n&&e(t.prototype,n),o&&e(t,o),t}}();Object.defineProperty(exports,"__esModule",{value:!0});var _chalk=require("chalk"),_chalk2=_interopRequireDefault(_chalk),_column=require("./util/column"),_column2=_interopRequireDefault(_column),_component=require("./component"),_component2=_interopRequireDefault(_component),ITEMS_PER_ROW=4,MAX_COLUMN_LENGTH=20,Menu=function(e){function t(e){return _classCallCheck(this,t),_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e))}return _inherits(t,e),_createClass(t,[{key:"getDefaultProps",value:function(){return{options:[],stdout:process.stdout,stdin:process.stdin}}},{key:"getInitialState",value:function(){return{options:this.props.options||[]}}},{key:"options",value:function(){return this.state.options}},{key:"setOptions",value:function(e){this.setState({options:e})}},{key:"renderLabel",value:function(e){return""+_chalk2["default"].magenta.bold(e.slice(0,1))+e.slice(1)}},{key:"renderOption",value:function(e,t){var n=(t+1)%ITEMS_PER_ROW===0,o=" "+e.id+": "+this.renderLabel(e.label);return o=(0,_column2["default"])(o,MAX_COLUMN_LENGTH),o+" "+(n?"\n":"")}},{key:"render",value:function(){return this.state.options.map(this.renderOption,this).join("")}}]),t}(_component2["default"]);exports["default"]=Menu; | ||
"use strict";function _interopRequireDefault(e){return e&&e.__esModule?e:{"default":e}}function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _possibleConstructorReturn(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function _inherits(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}var _createClass=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}();Object.defineProperty(exports,"__esModule",{value:!0});var _chalk=require("chalk"),_chalk2=_interopRequireDefault(_chalk),_column=require("./util/column"),_column2=_interopRequireDefault(_column),_component=require("./component"),_component2=_interopRequireDefault(_component),ITEMS_PER_ROW=4,MAX_COLUMN_LENGTH=20,Menu=function(e){function t(e){return _classCallCheck(this,t),_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e))}return _inherits(t,e),_createClass(t,[{key:"getDefaultProps",value:function(){return{options:[],stdout:process.stdout,stdin:process.stdin}}},{key:"getInitialState",value:function(){var e=this.props.options;return{options:e||[],ids:e?e.map(function(e){return e.id}):[]}}},{key:"filter",value:function(e){var t=arguments.length<=1||void 0===arguments[1]?this:arguments[1];return this.options().filter(e,t)}},{key:"getChoiceById",value:function(e){if(!this.hasId(e))throw new Error('Menu.getChoiceById: Could not find chocie by id "'+e+'"');return this.options()[this.state.ids.indexOf(e)]}},{key:"getIdByName",value:function(e){var t=this.filter(function(t){return t.name.startsWith(e)});return 1!==t.length?[]:t.map(function(e){return e.id})}},{key:"hasId",value:function(e){return this.state.ids.indexOf(Number(e))>-1}},{key:"ids",value:function(){return this.state.ids}},{key:"map",value:function(e){var t=arguments.length<=1||void 0===arguments[1]?this:arguments[1];return this.options().map(e,t)}},{key:"options",value:function(){return this.state.options}},{key:"setOptions",value:function(e){this.setState({options:e,ids:e.map(function(e){return e.id})})}},{key:"renderLabel",value:function(e){return""+_chalk2["default"].magenta.bold(e.slice(0,1))+e.slice(1)}},{key:"renderOption",value:function(e,t){var n=(t+1)%ITEMS_PER_ROW===0,r=" "+e.id+": "+this.renderLabel(e.label);return r=(0,_column2["default"])(r,MAX_COLUMN_LENGTH),r+" "+(n?"\n":"")}},{key:"render",value:function(){return this.state.options.map(this.renderOption,this).join("")}}]),t}(_component2["default"]);exports["default"]=Menu; |
@@ -1,1 +0,1 @@ | ||
"use strict";function _interopRequireDefault(e){return e&&e.__esModule?e:{"default":e}}function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _possibleConstructorReturn(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function _inherits(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}var _createClass=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}();Object.defineProperty(exports,"__esModule",{value:!0});var _component=require("./component"),_component2=_interopRequireDefault(_component),_bind_methods=require("./util/bind_methods"),_bind_methods2=_interopRequireDefault(_bind_methods),_actions=require("./actions"),Page=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e));return(0,_bind_methods2["default"])(r,"errorHandler","pipeTo","reprompt","route","showPrompt"),r}return _inherits(t,e),_createClass(t,[{key:"getDefaultProps",value:function(){return{stdin:process.stdin,stdout:process.stdout}}},{key:"getInitialState",value:function(){return{selected:[]}}},{key:"dispatch",value:function(e){return this.props.store.dispatch(e)}},{key:"errorHandler",value:function(e){this.props.app.emmit("error",e)}},{key:"getBasedir",value:function(){return this.props.base||this.select("config.base")}},{key:"getGlob",value:function(){return this.props.glob||this.select("glob")}},{key:"navigate",value:function(e){var t=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];this.dispatch((0,_actions.navigate)(e,t))}},{key:"pipeTo",value:function(e){return e.on("restart",this.reprompt)}},{key:"reprompt",value:function(){this.renderComponent(),t.display(this)}},{key:"select",value:function(e){var t=this.props.store.getState();return e.split(".").map(function(e){t=t[e]}),t}},{key:"render",value:function(){var e=[];return this.renderIntro&&e.push(this.renderIntro()),this.renderMenu&&e.push(this.renderMenu()),this.renderPrompt&&e.push(this.renderPrompt()),e}}]),t}(_component2["default"]);exports["default"]=Page; | ||
"use strict";function _interopRequireDefault(e){return e&&e.__esModule?e:{"default":e}}function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _possibleConstructorReturn(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function _inherits(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}var _createClass=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}();Object.defineProperty(exports,"__esModule",{value:!0});var _component=require("./component"),_component2=_interopRequireDefault(_component),_bind_methods=require("./util/bind_methods"),_bind_methods2=_interopRequireDefault(_bind_methods),_labeledStreamSplicer=require("labeled-stream-splicer"),_labeledStreamSplicer2=_interopRequireDefault(_labeledStreamSplicer),_actions=require("./actions"),Page=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e));return(0,_bind_methods2["default"])(r,"errorHandler","reprompt","route","showPrompt"),r}return _inherits(t,e),_createClass(t,[{key:"getDefaultProps",value:function(){return{stdin:process.stdin,stdout:process.stdout}}},{key:"getInitialState",value:function(){return{selected:[]}}},{key:"createPipeline",value:function(){var e=this.workflow(),t=[],r=function(e){return e.on("error",function(e){return console.error(e.stack||e.message||e)})};return Object.keys(e).forEach(function(n){t.push(n,[r(e[n])])}),_labeledStreamSplicer2["default"].obj(t)}},{key:"displayError",value:function(e){this.props.stdout.write(e)}},{key:"dispatch",value:function(e){return this.props.store.dispatch(e)}},{key:"getBasedir",value:function(){return this.props.base||this.select("config.base")}},{key:"getGlob",value:function(){return this.props.glob||this.select("glob")}},{key:"navigate",value:function(e){var t=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];this.dispatch((0,_actions.navigate)(e,t))}},{key:"reprompt",value:function(){this.pipeline=this.createPipeline(),this.renderComponent(),t.display(this),this.emit("reprompt")}},{key:"select",value:function(e){var t=this.props.store.getState();return e.split(".").map(function(e){t=t[e]}),t}},{key:"render",value:function(){var e=[];return this.renderIntro&&e.push(this.renderIntro()),this.renderMenu&&e.push(this.renderMenu()),this.renderPrompt&&e.push(this.renderPrompt()),e}}]),t}(_component2["default"]);exports["default"]=Page; |
@@ -1,1 +0,1 @@ | ||
"use strict";function _interopRequireDefault(e){return e&&e.__esModule?e:{"default":e}}function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _possibleConstructorReturn(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function _inherits(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}var _createClass=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}();Object.defineProperty(exports,"__esModule",{value:!0});var _chalk=require("chalk"),_chalk2=_interopRequireDefault(_chalk),_base_dispatcher=require("../streams/base_dispatcher"),_base_dispatcher2=_interopRequireDefault(_base_dispatcher),_menu_transform=require("../streams/menu_transform"),_menu_transform2=_interopRequireDefault(_menu_transform),_minimatchAll=require("minimatch-all"),_minimatchAll2=_interopRequireDefault(_minimatchAll),_page=require("../page"),_page2=_interopRequireDefault(_page),_path=require("path"),_path2=_interopRequireDefault(_path),_prompt=require("../prompt"),_prompt2=_interopRequireDefault(_prompt),_queries_transform=require("../streams/queries_transform"),_queries_transform2=_interopRequireDefault(_queries_transform),_vertical_menu=require("../vertical_menu"),_vertical_menu2=_interopRequireDefault(_vertical_menu),_child_process=require("child_process"),ChangedPage=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e));return r.question="Add files",r.menu=new _vertical_menu2["default"]({canUnselect:!0,acceptsMany:!0,stdin:r.props.stdin,stdout:r.props.stdout,app:r.props.app}),r.prompt=new _prompt2["default"]({stdin:r.props.stdin,stdout:r.props.stdout}),r}return _inherits(t,e),_createClass(t,[{key:"getInitialState",value:function(){return{files:this.getFiles(this.getGlob())}}},{key:"createOptionsFrom",value:function(e){var t=this.select("files"),r=this.getBasedir();return e.map(function(e,n){return{id:n+1,label:_path2["default"].relative(r,e),name:e,value:e,isSelected:t.indexOf(e)>-1}})||[]}},{key:"getFiles",value:function(e){var t=this.getBasedir(),r=(0,_child_process.execSync)("git diff --name-only"),n=r.toString().split("\n");return Array.isArray(e)||(e=[e]),n.length?n.map(function(e){return _path2["default"].resolve(e)}).filter(function(r){return(0,_minimatchAll2["default"])(r,e)&&r.indexOf(t)>-1}):[]}},{key:"showPrompt",value:function(){return 0===this.menu.options().length?(process.stderr.write(_chalk2["default"].bold.red("No files have been changed since last git commit.\n")),this.navigate("index")):this.prompt.beckon(this.question).pipe(new _queries_transform2["default"]).pipe(new _menu_transform2["default"]({choices:this.menu.options()})).pipe(new _base_dispatcher2["default"]({store:this.props.store})).then(this.reprompt)}},{key:"renderMenu",value:function(){return this.menu.setOptions(this.createOptionsFrom(this.state.files)),this.menu.render()}},{key:"renderPrompt",value:function(){return this.showPrompt}}]),t}(_page2["default"]);exports["default"]=ChangedPage; | ||
"use strict";function _interopRequireDefault(e){return e&&e.__esModule?e:{"default":e}}function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _possibleConstructorReturn(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function _inherits(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}var _createClass=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}();Object.defineProperty(exports,"__esModule",{value:!0});var _chalk=require("chalk"),_chalk2=_interopRequireDefault(_chalk),_dispatcher=require("../streams/dispatcher"),_dispatcher2=_interopRequireDefault(_dispatcher),_dispatch_transform=require("../streams/dispatch_transform"),_dispatch_transform2=_interopRequireDefault(_dispatch_transform),_menu_transform=require("../streams/menu_transform"),_menu_transform2=_interopRequireDefault(_menu_transform),_minimatchAll=require("minimatch-all"),_minimatchAll2=_interopRequireDefault(_minimatchAll),_page=require("../page"),_page2=_interopRequireDefault(_page),_path=require("path"),_path2=_interopRequireDefault(_path),_prompt=require("../prompt"),_prompt2=_interopRequireDefault(_prompt),_queries_transform=require("../streams/queries_transform"),_queries_transform2=_interopRequireDefault(_queries_transform),_vertical_menu=require("../vertical_menu"),_vertical_menu2=_interopRequireDefault(_vertical_menu),_child_process=require("child_process"),ChangedPage=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e));return r.question="Add files",r.menu=new _vertical_menu2["default"]({canUnselect:!0,acceptsMany:!0,stdin:r.props.stdin,stdout:r.props.stdout,app:r.props.app}),r.prompt=new _prompt2["default"]({stdin:r.props.stdin,stdout:r.props.stdout}),r.pipeline=r.createPipeline(),r}return _inherits(t,e),_createClass(t,[{key:"getInitialState",value:function(){return{files:this.getFiles(this.getGlob())}}},{key:"createOptionsFrom",value:function(e){var t=this.select("files"),r=this.getBasedir();return e.map(function(e,n){return{id:n+1,label:_path2["default"].relative(r,e),name:e,value:e,isSelected:t.indexOf(e)>-1}})||[]}},{key:"getFiles",value:function(e){var t=this.getBasedir(),r=(0,_child_process.execSync)("git diff --name-only"),n=r.toString().split("\n");return Array.isArray(e)||(e=[e]),n.length?n.map(function(e){return _path2["default"].resolve(e)}).filter(function(r){return(0,_minimatchAll2["default"])(r,e)&&r.indexOf(t)>-1}):[]}},{key:"route",value:function(e,t){switch(t.type){case"navigate":switch(t.data){case"blank":e.end(),this.navigate("index");break;case"all":this.navigate("index")}break;case"done":this.reprompt();break;case"error":this.displayError(t.data)}}},{key:"showPrompt",value:function(){return 0===this.menu.options().length?(this.props.stdout.write(_chalk2["default"].bold.red("No files have been changed since last git commit.\n")),this.navigate("index")):this.prompt.beckon(this.question).pipe(this.pipeline).pipe(new _dispatcher2["default"](this.route))}},{key:"workflow",value:function(){return{query:new _queries_transform2["default"],menu:new _menu_transform2["default"]({menu:this.menu}),dispatch:new _dispatch_transform2["default"]({store:this.props.store})}}},{key:"renderMenu",value:function(){return this.menu.setOptions(this.createOptionsFrom(this.state.files)),this.menu.render()}},{key:"renderPrompt",value:function(){return this.showPrompt}}]),t}(_page2["default"]);exports["default"]=ChangedPage; |
@@ -1,1 +0,1 @@ | ||
"use strict";function _interopRequireDefault(e){return e&&e.__esModule?e:{"default":e}}function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _possibleConstructorReturn(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function _inherits(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}var _createClass=function(){function e(e,t){for(var r=0;r<t.length;r++){var i=t[r];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}return function(t,r,i){return r&&e(t.prototype,r),i&&e(t,i),t}}();Object.defineProperty(exports,"__esModule",{value:!0});var _chalk=require("chalk"),_chalk2=_interopRequireDefault(_chalk),_fs=require("fs"),_fs2=_interopRequireDefault(_fs),_base_dispatcher=require("../streams/base_dispatcher"),_base_dispatcher2=_interopRequireDefault(_base_dispatcher),_generic_transform=require("../streams/generic_transform"),_generic_transform2=_interopRequireDefault(_generic_transform),_menu_transform=require("../streams/menu_transform"),_menu_transform2=_interopRequireDefault(_menu_transform),_minimatchAll=require("minimatch-all"),_minimatchAll2=_interopRequireDefault(_minimatchAll),_page=require("../page"),_page2=_interopRequireDefault(_page),_path=require("path"),_path2=_interopRequireDefault(_path),_prompt=require("../prompt"),_prompt2=_interopRequireDefault(_prompt),_queries_transform=require("../streams/queries_transform"),_queries_transform2=_interopRequireDefault(_queries_transform),_vertical_menu=require("../vertical_menu"),_vertical_menu2=_interopRequireDefault(_vertical_menu),DirectoriesPage=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e));return r.question="Add files or enter directory",r.menu=new _vertical_menu2["default"]({canUnselect:!0,acceptsMany:!0,stdin:r.props.stdin,stdout:r.props.stdout,app:r.props.app}),r.prompt=new _prompt2["default"]({stdin:r.props.stdin,stdout:r.props.stdout}),r}return _inherits(t,e),_createClass(t,[{key:"getInitialState",value:function(){return{selected:[],targetDir:null}}},{key:"getFiles",value:function(e,t){var r=this.select("config.base"),i=t===r,n=this.select("files"),a=[],s=[];return Array.isArray(e)||(e=[e]),a=_fs2["default"].readdirSync(t),a=a.map(function(e){return _path2["default"].join(t,e)}).filter(function(t){var r=_fs2["default"].statSync(t);return r.isDirectory()?(s.push(t),!0):(0,_minimatchAll2["default"])(t,e)}).map(function(e,r){var a=_path2["default"].relative(t,e),u=s.indexOf(e)>-1;return u&&(a+="/"),{id:i?r+1:r+2,name:a,value:e,isSelected:n.indexOf(e)>-1,label:u?_chalk2["default"].bold(a):a}}),t!==r&&a.unshift({id:1,name:"..",value:_path2["default"].resolve(t,".."),label:_chalk2["default"].bold("..")}),a}},{key:"showPrompt",value:function(){return this.prompt.beckon(this.question).pipe(new _queries_transform2["default"]).pipe(new _menu_transform2["default"]({choices:this.menu.options()})).pipe(new _generic_transform2["default"](this.processFile.bind(this))).pipe(new _base_dispatcher2["default"]({store:this.props.store,route:this.route})).then(this.reprompt)}},{key:"processFile",value:function(e,t){var r=null,i=t.data,n=t.params,a=i.value,s=void 0;return"file"!==t.type?void e.push(t):(s=_fs2["default"].statSync(a),s.isDirectory()&&(r=a,t.type="directory"),r&&1===n.queryCount&&!this.state.targetDir&&"single"===i.type&&(this.state.targetDir=r),void e.push(t))}},{key:"route",value:function(){return this.state.targetDir?(this.navigate("directories",{base:this.state.targetDir}),!0):void 0}},{key:"renderMenu",value:function(){return this.menu.setOptions(this.getFiles(this.getGlob(),this.getBasedir())),this.menu.render()}},{key:"renderPrompt",value:function(){return this.showPrompt}}]),t}(_page2["default"]);exports["default"]=DirectoriesPage; | ||
"use strict";function _interopRequireDefault(e){return e&&e.__esModule?e:{"default":e}}function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _possibleConstructorReturn(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function _inherits(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}var _createClass=function(){function e(e,t){for(var r=0;r<t.length;r++){var i=t[r];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}return function(t,r,i){return r&&e(t.prototype,r),i&&e(t,i),t}}();Object.defineProperty(exports,"__esModule",{value:!0});var _chalk=require("chalk"),_chalk2=_interopRequireDefault(_chalk),_fs=require("fs"),_fs2=_interopRequireDefault(_fs),_dispatcher=require("../streams/dispatcher"),_dispatcher2=_interopRequireDefault(_dispatcher),_dispatch_transform=require("../streams/dispatch_transform"),_dispatch_transform2=_interopRequireDefault(_dispatch_transform),_generic_transform=require("../streams/generic_transform"),_generic_transform2=_interopRequireDefault(_generic_transform),_menu_transform=require("../streams/menu_transform"),_menu_transform2=_interopRequireDefault(_menu_transform),_minimatchAll=require("minimatch-all"),_minimatchAll2=_interopRequireDefault(_minimatchAll),_page=require("../page"),_page2=_interopRequireDefault(_page),_path=require("path"),_path2=_interopRequireDefault(_path),_prompt=require("../prompt"),_prompt2=_interopRequireDefault(_prompt),_queries_transform=require("../streams/queries_transform"),_queries_transform2=_interopRequireDefault(_queries_transform),_vertical_menu=require("../vertical_menu"),_vertical_menu2=_interopRequireDefault(_vertical_menu),DirectoriesPage=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e));return r.question="Add files or enter directory",r.menu=new _vertical_menu2["default"]({canUnselect:!0,acceptsMany:!0,stdin:r.props.stdin,stdout:r.props.stdout,app:r.props.app}),r.prompt=new _prompt2["default"]({stdin:r.props.stdin,stdout:r.props.stdout}),r.pipeline=r.createPipeline(),r}return _inherits(t,e),_createClass(t,[{key:"getInitialState",value:function(){return{selected:[],targetDir:null}}},{key:"getFiles",value:function(e,t){var r=this.select("config.base"),i=t===r,a=this.select("files"),n=[],s=[];return Array.isArray(e)||(e=[e]),n=_fs2["default"].readdirSync(t),n=n.map(function(e){return _path2["default"].join(t,e)}).filter(function(t){var r=_fs2["default"].statSync(t);return r.isDirectory()?(s.push(t),!0):(0,_minimatchAll2["default"])(t,e)}).map(function(e,r){var n=_path2["default"].relative(t,e),u=s.indexOf(e)>-1;return u&&(n+="/"),{id:i?r+1:r+2,name:n,value:e,isSelected:a.indexOf(e)>-1,label:u?_chalk2["default"].bold(n):n}}),t!==r&&n.unshift({id:1,name:"..",value:_path2["default"].resolve(t,".."),label:_chalk2["default"].bold("..")}),n}},{key:"processFile",value:function(e,t){var r=null,i=t.data,a=t.params,n=i.value,s=void 0;if("file"!==t.type)return void e.push(t);if(s=_fs2["default"].statSync(n),s.isDirectory()&&"single"===t.data.type)r=n,t.type="directory";else if(s.isDirectory())return;r&&1===a.queryCount&&!this.state.targetDir&&"single"===i.type&&(this.state.targetDir=r),e.push(t)}},{key:"route",value:function(e,t){switch(t.type){case"navigate":switch(t.data){case"blank":e.end(),this.navigate("index");break;case"all":this.navigate("index");break;default:e.end(),this.navigate("directories",{base:this.state.targetDir})}break;case"done":this.reprompt();break;case"error":this.displayError(t.data)}}},{key:"showPrompt",value:function(){return this.prompt.beckon(this.question).pipe(this.pipeline).pipe(new _dispatcher2["default"](this.route))}},{key:"workflow",value:function(){return{query:new _queries_transform2["default"],menu:new _menu_transform2["default"]({menu:this.menu}),process:new _generic_transform2["default"](this.processFile.bind(this)),dispatch:new _dispatch_transform2["default"]({store:this.props.store})}}},{key:"renderMenu",value:function(){return this.menu.setOptions(this.getFiles(this.getGlob(),this.getBasedir())),this.menu.render()}},{key:"renderPrompt",value:function(){return this.showPrompt}}]),t}(_page2["default"]);exports["default"]=DirectoriesPage; |
@@ -1,1 +0,1 @@ | ||
"use strict";function _interopRequireDefault(e){return e&&e.__esModule?e:{"default":e}}function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _possibleConstructorReturn(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function _inherits(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}var _createClass=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}();Object.defineProperty(exports,"__esModule",{value:!0});var _globAll=require("glob-all"),_globAll2=_interopRequireDefault(_globAll),_base_dispatcher=require("../streams/base_dispatcher"),_base_dispatcher2=_interopRequireDefault(_base_dispatcher),_menu_transform=require("../streams/menu_transform"),_menu_transform2=_interopRequireDefault(_menu_transform),_page=require("../page"),_page2=_interopRequireDefault(_page),_path=require("path"),_path2=_interopRequireDefault(_path),_prompt=require("../prompt"),_prompt2=_interopRequireDefault(_prompt),_queries_transform=require("../streams/queries_transform"),_queries_transform2=_interopRequireDefault(_queries_transform),_vertical_menu=require("../vertical_menu"),_vertical_menu2=_interopRequireDefault(_vertical_menu),FilesPage=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e));return r.question="Add files",r.menu=new _vertical_menu2["default"]({canUnselect:!0,acceptsMany:!0,stdin:r.props.stdin,stdout:r.props.stdout,app:r.props.app}),r.prompt=new _prompt2["default"]({stdin:r.props.stdin,stdout:r.props.stdout}),r}return _inherits(t,e),_createClass(t,[{key:"getFiles",value:function(e){var t=this.getBasedir(),r=this.select("files"),n=e;return Array.isArray(n)||(n=[n]),n=n.map(function(e){return _path2["default"].join(t,e)}),_globAll2["default"].sync(n,{cwd:process.cwd()}).map(function(e,n){var i=_path2["default"].relative(t,e);return{id:n+1,name:i,value:_path2["default"].resolve(process.cwd(),e),isSelected:r.indexOf(e)>-1,label:i}})||[]}},{key:"showPrompt",value:function(){this.prompt.beckon(this.question).pipe(new _queries_transform2["default"]).pipe(new _menu_transform2["default"]({choices:this.menu.options()})).pipe(new _base_dispatcher2["default"]({store:this.props.store})).then(this.reprompt)}},{key:"processInput",value:function(e){return this.menu.find(e)}},{key:"renderMenu",value:function(){return this.menu.setOptions(this.getFiles(this.getGlob())),this.menu.render()}},{key:"renderPrompt",value:function(){return this.showPrompt.bind(this)}}]),t}(_page2["default"]);exports["default"]=FilesPage; | ||
"use strict";function _interopRequireDefault(e){return e&&e.__esModule?e:{"default":e}}function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _possibleConstructorReturn(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function _inherits(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}var _createClass=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}();Object.defineProperty(exports,"__esModule",{value:!0});var _globAll=require("glob-all"),_globAll2=_interopRequireDefault(_globAll),_dispatcher=require("../streams/dispatcher"),_dispatcher2=_interopRequireDefault(_dispatcher),_dispatch_transform=require("../streams/dispatch_transform"),_dispatch_transform2=_interopRequireDefault(_dispatch_transform),_menu_transform=require("../streams/menu_transform"),_menu_transform2=_interopRequireDefault(_menu_transform),_page=require("../page"),_page2=_interopRequireDefault(_page),_path=require("path"),_path2=_interopRequireDefault(_path),_prompt=require("../prompt"),_prompt2=_interopRequireDefault(_prompt),_queries_transform=require("../streams/queries_transform"),_queries_transform2=_interopRequireDefault(_queries_transform),_vertical_menu=require("../vertical_menu"),_vertical_menu2=_interopRequireDefault(_vertical_menu),FilesPage=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e));return r.question="Add files",r.menu=new _vertical_menu2["default"]({canUnselect:!0,acceptsMany:!0,stdin:r.props.stdin,stdout:r.props.stdout,app:r.props.app}),r.prompt=new _prompt2["default"]({stdin:r.props.stdin,stdout:r.props.stdout}),r.pipeline=r.createPipeline(),r}return _inherits(t,e),_createClass(t,[{key:"getFiles",value:function(e){var t=this.getBasedir(),r=this.select("files"),n=e;return Array.isArray(n)||(n=[n]),n=n.map(function(e){return _path2["default"].join(t,e)}),_globAll2["default"].sync(n,{cwd:process.cwd()}).map(function(e,n){var a=_path2["default"].relative(t,e);return{id:n+1,name:a,value:_path2["default"].resolve(process.cwd(),e),isSelected:r.indexOf(e)>-1,label:a}})||[]}},{key:"route",value:function(e,t){switch(t.type){case"navigate":switch(t.data){case"blank":e.end(),this.navigate("index");break;case"all":this.navigate("index")}break;case"done":this.reprompt();break;case"error":this.displayError(t.data)}}},{key:"showPrompt",value:function(){return this.prompt.beckon(this.question).pipe(this.pipeline).pipe(new _dispatcher2["default"](this.route))}},{key:"workflow",value:function(){return{query:new _queries_transform2["default"],menu:new _menu_transform2["default"]({menu:this.menu}),dispatch:new _dispatch_transform2["default"]({store:this.props.store})}}},{key:"renderMenu",value:function(){return this.menu.setOptions(this.getFiles(this.getGlob())),this.menu.render()}},{key:"renderPrompt",value:function(){return this.showPrompt.bind(this)}}]),t}(_page2["default"]);exports["default"]=FilesPage; |
@@ -1,1 +0,1 @@ | ||
"use strict";function _interopRequireDefault(e){return e&&e.__esModule?e:{"default":e}}function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _possibleConstructorReturn(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function _inherits(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}var _createClass=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}();Object.defineProperty(exports,"__esModule",{value:!0});var _globAll=require("glob-all"),_globAll2=_interopRequireDefault(_globAll),_base_dispatcher=require("../streams/base_dispatcher"),_base_dispatcher2=_interopRequireDefault(_base_dispatcher),_generic_transform=require("../streams/generic_transform"),_generic_transform2=_interopRequireDefault(_generic_transform),_menu_transform=require("../streams/menu_transform"),_menu_transform2=_interopRequireDefault(_menu_transform),_page=require("../page"),_page2=_interopRequireDefault(_page),_path=require("path"),_path2=_interopRequireDefault(_path),_prompt=require("../prompt"),_prompt2=_interopRequireDefault(_prompt),_queries_transform=require("../streams/queries_transform"),_queries_transform2=_interopRequireDefault(_queries_transform),_vertical_menu=require("../vertical_menu"),_vertical_menu2=_interopRequireDefault(_vertical_menu),GlobPage=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e));return r.menu=new _vertical_menu2["default"]({canUnselect:!0,acceptsMany:!0,stdin:r.props.stdin,stdout:r.props.stdout,app:r.props.app}),r.prompt=new _prompt2["default"]({stdin:r.props.stdin,stdout:r.props.stdout}),r}return _inherits(t,e),_createClass(t,[{key:"getInitialState",value:function(){return{files:[],filter:null}}},{key:"componentShouldUpdate",value:function(){return!1}},{key:"createOptionsFrom",value:function(e){var t=this.select("files"),r=this.getBasedir();return e.map(function(e,n){return{id:n+1,label:_path2["default"].relative(r,e),name:e,value:e,isSelected:t.indexOf(e)>-1}})||[]}},{key:"getFiles",value:function(e){var t=this.getBasedir();return _globAll2["default"].sync(_path2["default"].join(t,e),{cwd:process.cwd()})}},{key:"processGlob",value:function(e,t){var r=void 0,n=[],i=t.type,s=t.creator;return"string"!==i||"prompt"!==s?e.push(t):(r=t.data,r||(this.navigate("index"),e.push(null)),n=this.getFiles(r),n.length?(this.setState({filter:r,files:n}),void e.push(null)):e.pushError(new Error('No files matched the glob string "'+r+'"')))}},{key:"question",value:function(){var e=this.getBasedir();return this.state.files.length?"Add files":(e=_path2["default"].relative(_path2["default"].resolve(this.select("config.base"),".."),e),"Enter glob from "+e)}},{key:"showPrompt",value:function(){this.state.files.length?this.prompt.beckon(this.question()).pipe(new _queries_transform2["default"]).pipe(new _menu_transform2["default"]({choices:this.menu.options()})).pipe(new _base_dispatcher2["default"]({store:this.props.store})).then(this.reprompt):this.prompt.beckon(this.question()).pipe(new _generic_transform2["default"](this.processGlob.bind(this))).pipe(new _base_dispatcher2["default"]({store:this.props.store})).on("finish",this.reprompt)}},{key:"renderMenu",value:function(){return this.state.files.length?(this.menu.setOptions(this.createOptionsFrom(this.state.files)),this.menu.render()):""}},{key:"renderPrompt",value:function(){return this.showPrompt}}]),t}(_page2["default"]);exports["default"]=GlobPage; | ||
"use strict";function _interopRequireDefault(e){return e&&e.__esModule?e:{"default":e}}function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _possibleConstructorReturn(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function _inherits(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}var _createClass=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}();Object.defineProperty(exports,"__esModule",{value:!0});var _globAll=require("glob-all"),_globAll2=_interopRequireDefault(_globAll),_dispatcher=require("../streams/dispatcher"),_dispatcher2=_interopRequireDefault(_dispatcher),_dispatch_transform=require("../streams/dispatch_transform"),_dispatch_transform2=_interopRequireDefault(_dispatch_transform),_generic_transform=require("../streams/generic_transform"),_generic_transform2=_interopRequireDefault(_generic_transform),_menu_transform=require("../streams/menu_transform"),_menu_transform2=_interopRequireDefault(_menu_transform),_page=require("../page"),_page2=_interopRequireDefault(_page),_path=require("path"),_path2=_interopRequireDefault(_path),_prompt=require("../prompt"),_prompt2=_interopRequireDefault(_prompt),_queries_transform=require("../streams/queries_transform"),_queries_transform2=_interopRequireDefault(_queries_transform),_vertical_menu=require("../vertical_menu"),_vertical_menu2=_interopRequireDefault(_vertical_menu),GlobPage=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e));return r.menu=new _vertical_menu2["default"]({canUnselect:!0,acceptsMany:!0,stdin:r.props.stdin,stdout:r.props.stdout,app:r.props.app}),r.prompt=new _prompt2["default"]({stdin:r.props.stdin,stdout:r.props.stdout}),r.pipeline=r.createPipeline(),r}return _inherits(t,e),_createClass(t,[{key:"getInitialState",value:function(){return{files:[],filter:null}}},{key:"componentShouldUpdate",value:function(){return!1}},{key:"createOptionsFrom",value:function(e){var t=this.select("files"),r=this.getBasedir();return e.map(function(e,n){return{id:n+1,label:_path2["default"].relative(r,e),name:e,value:e,isSelected:t.indexOf(e)>-1}})||[]}},{key:"getFiles",value:function(e){var t=this.getBasedir();return _globAll2["default"].sync(_path2["default"].join(t,e),{cwd:process.cwd()})}},{key:"processGlob",value:function(e,t){var r=void 0,n=[],i=t.type,a=t.creator;return"string"!==i||"prompt"!==a?void e.push(t):(r=t.data)?(n=this.getFiles(r),n.length?void this.setState({filter:r,files:n}):void e.pushError('No files matched the glob string "'+r+'"')):(e.destroy(),t.type="navigate",t.data={value:"blank"},void e.push(t))}},{key:"question",value:function(){var e=this.getBasedir();return this.state.files.length?"Add files":(e=_path2["default"].relative(_path2["default"].resolve(this.select("config.base"),".."),e),"Enter glob from "+e)}},{key:"route",value:function(e,t){switch(t.type){case"navigate":switch(t.data){case"blank":e.end(),this.navigate("index");break;case"all":this.navigate("index")}break;case"done":this.reprompt();break;case"error":this.displayError(t.data)}}},{key:"showPrompt",value:function(){return this.prompt.beckon(this.question()).pipe(this.pipeline).pipe(new _dispatcher2["default"](this.route))}},{key:"workflow",value:function(){return this.state.files.length?{query:new _queries_transform2["default"],menu:new _menu_transform2["default"]({menu:this.menu}),dispatch:new _dispatch_transform2["default"]({store:this.props.store})}:{glob:new _generic_transform2["default"](this.processGlob.bind(this)),dispatch:new _dispatch_transform2["default"]({store:this.props.store})}}},{key:"renderMenu",value:function(){return this.state.files.length?(this.menu.setOptions(this.createOptionsFrom(this.state.files)),this.menu.render()):""}},{key:"renderPrompt",value:function(){return this.showPrompt}}]),t}(_page2["default"]);exports["default"]=GlobPage; |
@@ -1,1 +0,1 @@ | ||
"use strict";function _interopRequireDefault(e){return e&&e.__esModule?e:{"default":e}}function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _possibleConstructorReturn(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function _inherits(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}var _createClass=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}();Object.defineProperty(exports,"__esModule",{value:!0});var _chalk=require("chalk"),_chalk2=_interopRequireDefault(_chalk),_column=require("../util/column"),_column2=_interopRequireDefault(_column),_base_dispatcher=require("../streams/base_dispatcher"),_base_dispatcher2=_interopRequireDefault(_base_dispatcher),_menu=require("../menu"),_menu2=_interopRequireDefault(_menu),_menu_transform=require("../streams/menu_transform"),_menu_transform2=_interopRequireDefault(_menu_transform),_page=require("../page"),_page2=_interopRequireDefault(_page),_path=require("path"),_path2=_interopRequireDefault(_path),_prompt=require("../prompt"),_prompt2=_interopRequireDefault(_prompt),_queries_transform=require("../streams/queries_transform"),_queries_transform2=_interopRequireDefault(_queries_transform),MENU_OPTIONS=[{id:1,label:"directories",name:"directories",value:"directories"},{id:2,label:"files",name:"files",value:"files"},{id:3,label:"glob",name:"glob",value:"glob"},{id:4,label:"changed",name:"changed",value:"changed"},{id:5,label:"help",name:"help",value:"help"},{id:6,label:"quit",name:"quit",value:"quit"}],MAX_LABEL_WIDTH=6,MAX_HELP_WIDTH=11,IndexPage=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e));return r.intro="*** COMMANDS ***",r.question="What do you seek?",r.prompt=new _prompt2["default"]({stdin:r.props.stdin,stdout:r.props.stdout}),r.menu=new _menu2["default"]({options:MENU_OPTIONS,stdin:r.props.stdin,stdout:r.props.stdout,app:r.props.app}),r}return _inherits(t,e),_createClass(t,[{key:"processInput",value:function(e){return this.menu.find(e,function(e){return e.slice(0,1)})}},{key:"quit",value:function(){this.props.app&&this.props.app.emit("complete",this.select("files")),this.props.stdin.pause()}},{key:"route",value:function(e,t,r){var n=r.value;switch(n){case null:return!1;case"quit":return this.quit(),!0;case"help":return this.showHelp(),!1;default:return this.navigate(n),!0}}},{key:"showHelp",value:function(){var e={directories:"Select files & browse directories",files:"Select from a list of all nested files",glob:"Input a glob string then selected from matches",changed:"Select files from git diff --name-only",help:"Uhhh... this thing I guess...",quit:"Forward files along"},t="HELP\n";for(var r in e)if(e.hasOwnProperty(r)){var n=e[r];t+=" "+(0,_column2["default"])(r,MAX_HELP_WIDTH)+" - "+n+"\n"}this.props.stdout.write(_chalk2["default"].bold.red(t))}},{key:"showPrompt",value:function(){var e=this.pipeTo;return this.prompt.beckon(this.question).pipe(e(new _queries_transform2["default"]({maxQueries:1}))).pipe(e(new _menu_transform2["default"]({choices:this.menu.options(),canUnselect:!1}))).pipe(e(new _base_dispatcher2["default"]({store:this.props.store,route:this.route}))).then(this.reprompt)}},{key:"renderIntro",value:function(){var e="",t=this.select("files"),r=this.select("config.base");return t.length&&(e+="\n",t.forEach(function(t,n){var i=_path2["default"].relative(r,t),o=n+1+": ";o=(0,_column2["default"])(o,MAX_LABEL_WIDTH),e+=o+" "+i+"\n"}),e+="\n"),e+=_chalk2["default"].white.bold(this.intro)+"\n"}},{key:"renderPrompt",value:function(){return this.showPrompt}},{key:"renderMenu",value:function(){return this.menu.render()+"\n"}}]),t}(_page2["default"]);exports["default"]=IndexPage; | ||
"use strict";function _interopRequireDefault(e){return e&&e.__esModule?e:{"default":e}}function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _possibleConstructorReturn(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function _inherits(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}var _createClass=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}();Object.defineProperty(exports,"__esModule",{value:!0});var _chalk=require("chalk"),_chalk2=_interopRequireDefault(_chalk),_column=require("../util/column"),_column2=_interopRequireDefault(_column),_dispatcher=require("../streams/dispatcher"),_dispatcher2=_interopRequireDefault(_dispatcher),_dispatch_transform=require("../streams/dispatch_transform"),_dispatch_transform2=_interopRequireDefault(_dispatch_transform),_menu=require("../menu"),_menu2=_interopRequireDefault(_menu),_menu_transform=require("../streams/menu_transform"),_menu_transform2=_interopRequireDefault(_menu_transform),_page=require("../page"),_page2=_interopRequireDefault(_page),_path=require("path"),_path2=_interopRequireDefault(_path),_prompt=require("../prompt"),_prompt2=_interopRequireDefault(_prompt),_queries_transform=require("../streams/queries_transform"),_queries_transform2=_interopRequireDefault(_queries_transform),MENU_OPTIONS=[{id:1,label:"directories",name:"directories",value:"directories"},{id:2,label:"files",name:"files",value:"files"},{id:3,label:"glob",name:"glob",value:"glob"},{id:4,label:"changed",name:"changed",value:"changed"},{id:5,label:"help",name:"help",value:"help"},{id:6,label:"quit",name:"quit",value:"quit"}],MAX_LABEL_WIDTH=6,MAX_HELP_WIDTH=11,IndexPage=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e));return r.intro="*** COMMANDS ***",r.question="What do you seek?",r.prompt=new _prompt2["default"]({stdin:r.props.stdin,stdout:r.props.stdout}),r.menu=new _menu2["default"]({options:MENU_OPTIONS,stdin:r.props.stdin,stdout:r.props.stdout,app:r.props.app}),r.pipeline=r.createPipeline(),r}return _inherits(t,e),_createClass(t,[{key:"quit",value:function(){this.emit("complete",this.select("files"))}},{key:"route",value:function(e,t){var r=t.data;switch(t.type){case"navigate":switch(t.data){case"blank":e.end(),this.reprompt();break;case"quit":e.end(),this.quit();break;case"help":e.end(),this.showHelp(),this.reprompt();break;default:e.end(),this.navigate(r)}break;case"done":this.reprompt();break;case"error":this.displayError(t.data)}}},{key:"showHelp",value:function(){var e={directories:"Select files & browse directories",files:"Select from a list of all nested files",glob:"Input a glob string then selected from matches",changed:"Select files from git diff --name-only",help:"Uhhh... this thing I guess...",quit:"Forward files along"},t="HELP\n";for(var r in e)if(e.hasOwnProperty(r)){var n=e[r];t+=" "+(0,_column2["default"])(r,MAX_HELP_WIDTH)+" - "+n+"\n"}this.props.stdout.write(_chalk2["default"].bold.red(t))}},{key:"showPrompt",value:function(){return this.prompt.beckon(this.question).pipe(this.pipeline).pipe(new _dispatcher2["default"](this.route))}},{key:"workflow",value:function(){return{query:new _queries_transform2["default"]({maxQueries:1}),menu:new _menu_transform2["default"]({menu:this.menu,canUnselect:!1}),dispatch:new _dispatch_transform2["default"]({store:this.props.store})}}},{key:"renderIntro",value:function(){var e="",t=this.select("files"),r=this.select("config.base");return t.length&&(e+="\n",t.forEach(function(t,n){var i=_path2["default"].relative(r,t),a=n+1+": ";a=(0,_column2["default"])(a,MAX_LABEL_WIDTH),e+=a+" "+i+"\n"}),e+="\n"),e+=_chalk2["default"].white.bold(this.intro)+"\n"}},{key:"renderPrompt",value:function(){return this.showPrompt}},{key:"renderMenu",value:function(){return this.menu.render()+"\n"}}]),t}(_page2["default"]);exports["default"]=IndexPage; |
@@ -1,1 +0,1 @@ | ||
"use strict";function _interopRequireDefault(e){return e&&e.__esModule?e:{"default":e}}function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _possibleConstructorReturn(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function _inherits(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}var _createClass=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}();Object.defineProperty(exports,"__esModule",{value:!0});var _bind_methods=require("../util/bind_methods"),_bind_methods2=_interopRequireDefault(_bind_methods),_transform_action=require("../transform_action"),_transform_action2=_interopRequireDefault(_transform_action),_stream=require("stream"),_errors=require("../errors"),BaseTransform=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,{objectMode:!0}));return r.filters={},r.params={},"function"==typeof r.getParams&&Object.assign(r.params,r.getParams(e)),(0,_bind_methods2["default"])(r,"errorHandler"),r.setListeners(),r}return _inherits(t,e),_createClass(t,[{key:"createAction",value:function(e){return e.creator||(e.creator=this.name),new _transform_action2["default"](e)}},{key:"commit",value:function(e){this.pushAction(e),this.finish()}},{key:"errorHandler",value:function(e){process.stderr.write((e.stack||e.message)+"\n"),process.exit(0)}},{key:"filterData",value:function(e,t){return Object.keys(e).every(function(r){return e[r]===t[r]})}},{key:"finish",value:function(){this.push(null)}},{key:"matchError",value:function(e){this.pushError(new _errors.MatchError(e.toString()))}},{key:"pushAction",value:function(e){this.push(this.createAction(e))}},{key:"pushError",value:function(e){this.pushAction({type:"error",data:e}),this.finish()}},{key:"setListeners",value:function(){this.on("error",this.errorHandler)}},{key:"transform",value:function(e){this.push(e),this.finish()}},{key:"_transform",value:function(e,t,r){try{return this.filterData(this.filters,e)?(this.transform(e),r()):r(null,e)}catch(n){this.emit("error",n),r()}}}]),t}(_stream.Transform);exports["default"]=BaseTransform; | ||
"use strict";function _interopRequireDefault(e){return e&&e.__esModule?e:{"default":e}}function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _possibleConstructorReturn(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function _inherits(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}var _createClass=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}();Object.defineProperty(exports,"__esModule",{value:!0});var _bind_methods=require("../util/bind_methods"),_bind_methods2=_interopRequireDefault(_bind_methods),_stripAnsi=require("strip-ansi"),_stripAnsi2=_interopRequireDefault(_stripAnsi),_transform_action=require("../transform_action"),_transform_action2=_interopRequireDefault(_transform_action),_stream=require("stream"),BaseTransform=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,{objectMode:!0}));return r.filters={},r.params={},r.name="BaseTransform",r.isDestroyed=!1,"function"==typeof r.getParams&&Object.assign(r.params,r.getParams(e)),(0,_bind_methods2["default"])(r,"errorHandler"),r.setListeners(),r}return _inherits(t,e),_createClass(t,[{key:"createAction",value:function(e){return e.creator||(e.creator=this.name),new _transform_action2["default"](e)}},{key:"destroy",value:function(e){var t=this;this.isDestroyed||(this.isDestroyed=!0,process.nextTick(function(){e&&t.emit("error",e),t.emit("close")}))}},{key:"errorHandler",value:function(e){process.stderr.write((e.stack||e.message)+"\n"),process.exit(1)}},{key:"filterData",value:function(e,t){return Object.keys(e).every(function(r){return e[r]===t[r]})}},{key:"matchError",value:function(e){var t=(0,_stripAnsi2["default"])(e.toString()).trim();t&&(t=" ("+t+")"),t="Huh"+t+"?",this.pushError(t)}},{key:"pushAction",value:function(e){this.push(this.createAction(e))}},{key:"pushError",value:function(e){this.pushAction({type:"error",data:e})}},{key:"setListeners",value:function(){this.on("error",this.errorHandler)}},{key:"transform",value:function(e){this.push(e)}},{key:"_transform",value:function(e,t,r){try{return this.filterData(this.filters,e)?(this.transform(e),r()):r(null,e)}catch(n){this.emit("error",n),r()}}}]),t}(_stream.Transform);exports["default"]=BaseTransform; |
@@ -1,1 +0,1 @@ | ||
"use strict";function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _possibleConstructorReturn(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function _inherits(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}var _createClass=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}();Object.defineProperty(exports,"__esModule",{value:!0});var _stream=require("stream"),GenericTransform=function(e){function t(e){var r=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];_classCallCheck(this,t);var n=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,Object.assign({},r,{objectMode:!0})));return n._transformCallback=e,n}return _inherits(t,e),_createClass(t,[{key:"pushError",value:function(e){this.push({creator:"generic-transformer",type:"error",data:e}),this.push(null)}},{key:"_transform",value:function(e,t,r){try{this._transformCallback(this,e),r()}catch(n){this.emit("error",n),r()}}}]),t}(_stream.Transform);exports["default"]=GenericTransform; | ||
"use strict";function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _possibleConstructorReturn(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function _inherits(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}var _createClass=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}();Object.defineProperty(exports,"__esModule",{value:!0});var _stream=require("stream"),GenericTransform=function(e){function t(e){var r=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];_classCallCheck(this,t);var n=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,Object.assign({},r,{objectMode:!0})));return n._transformCallback=e,n}return _inherits(t,e),_createClass(t,[{key:"destroy",value:function(e){var t=this;this.isDestroyed||(this.isDestroyed=!0,process.nextTick(function(){e&&t.emit("error",e),t.emit("close")}))}},{key:"pushError",value:function(e){this.push({creator:"generic-transformer",type:"error",data:e}),this.push(null)}},{key:"_transform",value:function(e,t,r){try{this._transformCallback(this,e),r()}catch(n){this.emit("error",n),r()}}}]),t}(_stream.Transform);exports["default"]=GenericTransform; |
@@ -1,1 +0,1 @@ | ||
"use strict";function _interopRequireDefault(e){return e&&e.__esModule?e:{"default":e}}function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _possibleConstructorReturn(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function _inherits(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}function range(e,t,r){return e.slice(t-1,r)}var _createClass=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}();Object.defineProperty(exports,"__esModule",{value:!0});var _base_transform=require("./base_transform"),_base_transform2=_interopRequireDefault(_base_transform),_path=require("path"),_path2=_interopRequireDefault(_path),MenuTransform=function(e){function t(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0];_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e));return r.name="menu",r.filters={creator:"queries",type:"query"},r.choices=[],r.ids=[],e.choices&&(r.choices=e.choices,r.ids=r.choices.map(function(e){return e.id})),r}return _inherits(t,e),_createClass(t,[{key:"getParams",value:function(e){var t=e.canSelect;return{canUnselect:!!t||"undefined"==typeof t}}},{key:"filter",value:function(e){var t=arguments.length<=1||void 0===arguments[1]?this:arguments[1];return this.choices.filter(e,t)}},{key:"getChoiceById",value:function(e){if(!this.hasId(e))throw new Error('MenuTransform.getChoiceById: Could not find chocie by id "'+e+'"');return this.choices[this.ids.indexOf(e)]}},{key:"getChoiceByName",value:function(e){var t=this.filter(function(t){return e.isStartOf(t.name)});return 1!==t.length?[]:t.map(function(e){return e.id})}},{key:"hasId",value:function(e){return this.ids.indexOf(Number(e))>-1}},{key:"isSelectOnly",value:function(e){return"unselect"===e&&!this.params.canUnselect}},{key:"map",value:function(e){var t=arguments.length<=1||void 0===arguments[1]?this:arguments[1];return this.choices.map(e,t)}},{key:"transform",value:function(e){var t=this,r=e.data,n=e.params,i=r.data,a=i.type,s=i.action,o=i.value,u=[];if(this.isSelectOnly(s))return this.matchError(r);switch(Object.assign(n,{canUnselect:this.params.canUnselect}),a){case"all":if(n.maxQueries>0)return this.matchError(r);u=this.ids.slice();break;case"range":if(n.maxQueries>0)return this.matchError(r);if(!this.hasId(o.min)||!this.hasId(o.max))return this.matchError(r);u=range(this.ids,o.min,o.max);break;case"id":if(!this.hasId(o))return this.matchError(r);u=[o],a="single";break;case"string":u=this.getChoiceByName(r),a="single"}return u&&u.length?void u.filter(this.hasId,this).map(this.getChoiceById,this).forEach(function(e){var r=e.value,i=r.slice(0,1)===_path2["default"].sep;t.pushAction({type:i?"file":"action",data:{operation:s,value:r,type:a},params:n})}):this.matchError(r)}}]),t}(_base_transform2["default"]);exports["default"]=MenuTransform; | ||
"use strict";function _interopRequireDefault(e){return e&&e.__esModule?e:{"default":e}}function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _possibleConstructorReturn(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function _inherits(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}function range(e,t){for(var r=t-e,n=Array(r),a=0;r>=a;a+=1,e+=1)n[a]=e;return n}var _createClass=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}();Object.defineProperty(exports,"__esModule",{value:!0});var _base_transform=require("./base_transform"),_base_transform2=_interopRequireDefault(_base_transform),_path=require("path"),_path2=_interopRequireDefault(_path),MenuTransform=function(e){function t(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0];_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e));return r.name="menu",r.filters={creator:"queries",type:"query"},r.menu=null,e.menu&&(r.menu=e.menu),r}return _inherits(t,e),_createClass(t,[{key:"getParams",value:function(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],t=e.canUnselect;return t="undefined"==typeof t?!0:t,{canUnselect:t}}},{key:"getChoiceIds",value:function(){return this.menu.ids().slice()}},{key:"isSelectOnly",value:function(e){return"unselect"===e&&!this.params.canUnselect}},{key:"isValid",value:function(){var e=arguments.length<=0||void 0===arguments[0]?[]:arguments[0],t=Array.isArray(e)&&e.every(this.menu.hasId,this.menu);return t&&e&&e.length>0}},{key:"select",value:function(e,t){var r=[],n=e.data;if(this.isSelectOnly(e.action))return[];switch(Object.assign(t,{canUnselect:this.params.canUnselect}),n.type){case"all":if(t.maxQueries>0)return[];r=this.getChoiceIds();break;case"range":if(t.maxQueries>0)return[];if(!n.value.min||!n.value.max)return[];if(n.value.min>n.value.max)return[];r=range(n.value.min,n.value.max);break;case"id":if(!e.isInteger())return[];r=[n.value],n.type="single";break;case"string":r=this.menu.getIdByName(e.toString()),n.type="single"}return r}},{key:"transform",value:function(e){var t=this,r=e.data,n=e.params,a=this.select(r,n);return this.isValid(a)?void a.map(function(e){return t.menu.getChoiceById(e).value}).map(function(e){var t=e.slice(0,1)===_path2["default"].sep;return{type:t?"file":"page",data:{operation:r.data.action,value:e,type:r.data.type},params:n}}).forEach(this.pushAction,this):void this.matchError(r)}}]),t}(_base_transform2["default"]);exports["default"]=MenuTransform; |
@@ -1,1 +0,1 @@ | ||
"use strict";function _interopRequireDefault(e){return e&&e.__esModule?e:{"default":e}}function _classCallCheck(e,r){if(!(e instanceof r))throw new TypeError("Cannot call a class as a function")}function _possibleConstructorReturn(e,r){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!r||"object"!=typeof r&&"function"!=typeof r?e:r}function _inherits(e,r){if("function"!=typeof r&&null!==r)throw new TypeError("Super expression must either be null or a function, not "+typeof r);e.prototype=Object.create(r&&r.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),r&&(Object.setPrototypeOf?Object.setPrototypeOf(e,r):e.__proto__=r)}var _createClass=function(){function e(e,r){for(var t=0;t<r.length;t++){var n=r[t];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(r,t,n){return t&&e(r.prototype,t),n&&e(r,n),r}}();Object.defineProperty(exports,"__esModule",{value:!0});var _base_transform=require("./base_transform"),_base_transform2=_interopRequireDefault(_base_transform),_query=require("../query"),_query2=_interopRequireDefault(_query),QueriesTransform=function(e){function r(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0];_classCallCheck(this,r);var t=_possibleConstructorReturn(this,Object.getPrototypeOf(r).call(this,e));return t.name="queries",t.filters={creator:"prompt",type:"string"},t}return _inherits(r,e),_createClass(r,[{key:"getParams",value:function(e){return{maxQueries:e.maxQueries||0}}},{key:"isTooManyQueries",value:function(e){var r=e.length;return this.params.maxQueries>0&&r>this.params.maxQueries}},{key:"transform",value:function(e){var r=this,t=[],n=e.data,a={maxQueries:this.params.maxQueries};return""===n?this.commit({creator:"menu",type:"action",data:{operation:"blank",value:null},params:{queryCount:1}}):_query2["default"].isValid(n)?(t=_query2["default"].createFrom(n),this.isTooManyQueries(t)?this.matchError("2:"+n):(a.queryCount=t.length,t.forEach(function(e){r.pushAction({type:"query",data:e,params:a})}),void this.finish())):this.matchError("1:"+n)}}]),r}(_base_transform2["default"]);exports["default"]=QueriesTransform; | ||
"use strict";function _interopRequireDefault(e){return e&&e.__esModule?e:{"default":e}}function _classCallCheck(e,r){if(!(e instanceof r))throw new TypeError("Cannot call a class as a function")}function _possibleConstructorReturn(e,r){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!r||"object"!=typeof r&&"function"!=typeof r?e:r}function _inherits(e,r){if("function"!=typeof r&&null!==r)throw new TypeError("Super expression must either be null or a function, not "+typeof r);e.prototype=Object.create(r&&r.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),r&&(Object.setPrototypeOf?Object.setPrototypeOf(e,r):e.__proto__=r)}var _createClass=function(){function e(e,r){for(var t=0;t<r.length;t++){var n=r[t];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(r,t,n){return t&&e(r.prototype,t),n&&e(r,n),r}}();Object.defineProperty(exports,"__esModule",{value:!0});var _base_transform=require("./base_transform"),_base_transform2=_interopRequireDefault(_base_transform),_query=require("../query"),_query2=_interopRequireDefault(_query),QueriesTransform=function(e){function r(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0];_classCallCheck(this,r);var t=_possibleConstructorReturn(this,Object.getPrototypeOf(r).call(this,e));return t.name="queries",t.filters={creator:"prompt",type:"string"},t}return _inherits(r,e),_createClass(r,[{key:"getParams",value:function(e){return{maxQueries:e.maxQueries||0}}},{key:"isTooManyQueries",value:function(e){var r=this.params.maxQueries;return r>0&&e.length>r}},{key:"transform",value:function(e){var r=this,t=[],n=e.data,a={maxQueries:this.params.maxQueries};return""===n?void this.pushAction({creator:"menu",type:"action",data:{operation:"blank",value:null},params:{queryCount:1}}):_query2["default"].isValid(n)?(t=_query2["default"].createFrom(n),this.isTooManyQueries(t)?void this.matchError(n):(a.queryCount=t.length,void t.forEach(function(e){r.pushAction({type:"query",data:e,params:a})}))):void this.matchError(n)}}]),r}(_base_transform2["default"]);exports["default"]=QueriesTransform; |
@@ -1,1 +0,1 @@ | ||
"use strict";function _interopRequireDefault(t){return t&&t.__esModule?t:{"default":t}}function _classCallCheck(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function _possibleConstructorReturn(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}function _inherits(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}var _createClass=function(){function t(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}return function(e,n,r){return n&&t(e.prototype,n),r&&t(e,r),e}}();Object.defineProperty(exports,"__esModule",{value:!0});var _transform_action=require("../transform_action"),_transform_action2=_interopRequireDefault(_transform_action),_stream=require("stream"),StdinReader=function(t){function e(t){_classCallCheck(this,e);var n=_possibleConstructorReturn(this,Object.getPrototypeOf(e).call(this,{objectMode:!0}));return n.listener=null,n.stdin=process.stdin,n.stdout=process.stdout,n.stdin.setEncoding("utf8"),t.stdin&&(n.stdin=t.stdin),t.stdout&&(n.stdout=t.stdout),n}return _inherits(e,t),_createClass(e,[{key:"addListeners",value:function(){var t=this;this.stdin.on("data",function(e){t.push(new _transform_action2["default"]({creator:"prompt",type:"string",data:String(e).trim()})),t.push(null)}),this.listener=this.stdin.listeners("data").pop(),this.once("end",function(){t.stdin.removeListener("data",t.listener),t.listener=null,t.stdin.pause()})}},{key:"_read",value:function(){this.listener||this.addListeners(),this.stdin.resume()}}]),e}(_stream.Readable);exports["default"]=StdinReader; | ||
"use strict";function _interopRequireDefault(t){return t&&t.__esModule?t:{"default":t}}function _classCallCheck(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function _possibleConstructorReturn(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}function _inherits(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}var _createClass=function(){function t(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}return function(e,r,n){return r&&t(e.prototype,r),n&&t(e,n),e}}();Object.defineProperty(exports,"__esModule",{value:!0});var _transform_action=require("../transform_action"),_transform_action2=_interopRequireDefault(_transform_action),_stream=require("stream"),StdinReader=function(t){function e(){var t=arguments.length<=0||void 0===arguments[0]?{}:arguments[0];_classCallCheck(this,e);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(e).call(this,{objectMode:!0}));return r.listener=null,r.stdin=process.stdin,r.stdout=process.stdout,r.stdin.setEncoding("utf8"),t.stdin&&(r.stdin=t.stdin),t.stdout&&(r.stdout=t.stdout),r}return _inherits(e,t),_createClass(e,[{key:"addListeners",value:function(){var t=this;this.stdin.removeAllListeners("data"),this.stdin.on("data",function(e){t.push(new _transform_action2["default"]({creator:"prompt",type:"string",data:String(e).trim()})),t.stdin.pause(),t.push(null)}),this.listener=!0}},{key:"_read",value:function(){this.listener||this.addListeners(),this.stdin.resume()}}]),e}(_stream.Readable);exports["default"]=StdinReader; |
{ | ||
"name": "file-prompt", | ||
"version": "1.1.3", | ||
"version": "1.2.0", | ||
"description": "An interactive prompt for selecting files from a directory.", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "gulp test", | ||
"preversion": "gulp lint && gulp test && gulp clean build" | ||
"test": "gulp test" | ||
}, | ||
@@ -37,2 +36,3 @@ "repository": { | ||
"glob-all": "^3.0.1", | ||
"labeled-stream-splicer": "^2.0.0", | ||
"minimatch-all": "^1.0.2", | ||
@@ -45,4 +45,5 @@ "redux": "^3.0.4", | ||
"gulp": ">= 3.9.0 < 4", | ||
"minimist": "^1.2.0" | ||
"minimist": "^1.2.0", | ||
"through2": "^2.0.0" | ||
} | ||
} |
@@ -75,3 +75,3 @@ import Component from './component'; | ||
config: { | ||
base: this.props.base | ||
base: this.props.base, | ||
}, | ||
@@ -83,6 +83,6 @@ files: [], | ||
props: { | ||
glob: this.props.glob | ||
glob: this.props.glob, | ||
}, | ||
isNavigating: false | ||
} | ||
isNavigating: false, | ||
}, | ||
}); | ||
@@ -104,3 +104,3 @@ } | ||
stdin: process.stdin, | ||
stdout: process.stdout | ||
stdout: process.stdout, | ||
}; | ||
@@ -112,3 +112,3 @@ } | ||
pageName: null, | ||
pageProps: null | ||
pageProps: null, | ||
}; | ||
@@ -137,3 +137,3 @@ } | ||
pageName: currentPage.name, | ||
pageProps: currentPage.props | ||
pageProps: currentPage.props, | ||
}); | ||
@@ -157,3 +157,3 @@ } | ||
pageName: currentPage.name, | ||
pageProps: currentPage.props | ||
pageProps: currentPage.props, | ||
}); | ||
@@ -188,7 +188,8 @@ Component.display(this); | ||
let props = { | ||
app: this, | ||
store: this.store, | ||
stdin: this.props.stdin, | ||
stdout: this.props.stdout | ||
}; | ||
app: this, | ||
store: this.store, | ||
stdin: this.props.stdin, | ||
stdout: this.props.stdout, | ||
}, | ||
page; | ||
@@ -204,3 +205,13 @@ if (!App.PAGES.hasOwnProperty(this.state.pageName)) { | ||
return new App.PAGES[this.state.pageName](props).render(); | ||
// Create the page instance with the passed props | ||
page = new App.PAGES[this.state.pageName](props); | ||
/** | ||
* Add a listener on the index page to know when selections are complete | ||
*/ | ||
if (this.state.pageName === 'index') { | ||
page.once('complete', this.emit.bind(this, 'complete')); | ||
} | ||
return page.render(); | ||
} | ||
@@ -207,0 +218,0 @@ |
@@ -26,3 +26,3 @@ /* eslint no-unused-vars: 0 */ | ||
callback, | ||
context | ||
context, | ||
}; | ||
@@ -390,7 +390,7 @@ } | ||
props: _.clone(this.props), | ||
state: _.clone(this.state) | ||
state: _.clone(this.state), | ||
}, | ||
next = { | ||
props: _.clone(this.props), | ||
state: _.clone(this.state) | ||
state: _.clone(this.state), | ||
}; | ||
@@ -397,0 +397,0 @@ |
@@ -16,3 +16,3 @@ import Promise from 'bluebird'; | ||
let app = new App(Object.assign({ | ||
base: __dirname | ||
base: __dirname, | ||
}, options)); | ||
@@ -19,0 +19,0 @@ |
101
src/menu.js
@@ -41,3 +41,3 @@ import colors from 'chalk'; | ||
stdout: process.stdout, | ||
stdin: process.stdin | ||
stdin: process.stdin, | ||
}; | ||
@@ -47,4 +47,7 @@ } | ||
getInitialState () { | ||
let options = this.props.options; | ||
return { | ||
options: this.props.options || [] | ||
options: options || [], | ||
ids: options ? options.map((opt) => opt.id) : [], | ||
}; | ||
@@ -56,2 +59,91 @@ } | ||
/** | ||
* Filter | ||
* Iterates through each chocie and returns a new array | ||
* | ||
* @method | ||
* @public | ||
* @param {function} callback - Callback to iterate on each item | ||
* @param {object} [context] - Optional context to send with callback | ||
* @returns {array} Filtered result arrray | ||
*/ | ||
filter (callback, context=this) { | ||
return this.options().filter(callback, context); | ||
} | ||
/** | ||
* Get Choice By Id | ||
* Returns a choice by the given id | ||
* | ||
* @method | ||
* @public | ||
* @param {int} id - Id to search through choices for | ||
* @returns {object} Choice by that given id | ||
*/ | ||
getChoiceById (id) { | ||
/** | ||
* Throw a serious error if this fails, it is only used internally | ||
*/ | ||
if (!this.hasId(id)) { | ||
throw new Error(`Menu.getChoiceById: Could not find chocie by id "${id}"`); | ||
} | ||
return this.options()[this.state.ids.indexOf(id)]; | ||
} | ||
/** | ||
* Get Id By Name | ||
* Searches through all our options looking for | ||
* | ||
* @param {string} name - Name partial to find | ||
* @returns {array} Array of matching ids | ||
*/ | ||
getIdByName (name) { | ||
let results = this.filter((option) => option.name.startsWith(name)); | ||
/** | ||
* If the results are 0 or more than 1 return an empty array because | ||
* name searches need to match only 1 item to be valid. | ||
*/ | ||
if (results.length !== 1) return []; | ||
return results.map((option) => option.id); | ||
} | ||
/** | ||
* Has Id | ||
* Returns boolean if a choice by that id exists. | ||
* | ||
* @method | ||
* @public | ||
* @param {int} id - Id to look for | ||
* @returns {boolean} True if id was found | ||
*/ | ||
hasId (id) { | ||
return this.state.ids.indexOf(Number(id)) > -1; | ||
} | ||
/** | ||
* Ids | ||
* Returns a list of ids from the state | ||
* | ||
* @method | ||
* @public | ||
* @returns {array} Array of option ids | ||
*/ | ||
ids () { | ||
return this.state.ids; | ||
} | ||
/** | ||
* Map | ||
* Iterates through each choice and returns a new array of the same size | ||
* | ||
* @param {function} callback - Callback to iterate on each item | ||
* @param {object} [context] - Optional context to send with callback | ||
* @returns {array} Mapped result arrray | ||
*/ | ||
map (callback, context=this) { | ||
return this.options().map(callback, context); | ||
} | ||
/** | ||
* Options | ||
@@ -77,3 +169,6 @@ * Returns the array of options | ||
setOptions (options) { | ||
this.setState({ options }); | ||
this.setState({ | ||
options, | ||
ids: options.map((opt) => opt.id), | ||
}); | ||
} | ||
@@ -80,0 +175,0 @@ |
import Component from './component'; | ||
import bindMethods from './util/bind_methods'; | ||
import splicer from 'labeled-stream-splicer'; | ||
import { navigate } from './actions'; | ||
@@ -23,3 +25,2 @@ | ||
'errorHandler', | ||
'pipeTo', | ||
'reprompt', | ||
@@ -42,3 +43,3 @@ 'route', | ||
stdin: process.stdin, | ||
stdout: process.stdout | ||
stdout: process.stdout, | ||
}; | ||
@@ -57,3 +58,3 @@ } | ||
return { | ||
selected: [] | ||
selected: [], | ||
}; | ||
@@ -63,27 +64,57 @@ } | ||
/** | ||
* Dispatch | ||
* Dispatches the targeted action | ||
* Create Pipeline | ||
* Creates the labeled stream splicer pipeline | ||
* | ||
* @method | ||
* @public | ||
* @param {object} action - Dispatches the given action object | ||
* @returns {*} The result of the dispatch call | ||
* @returns {splicer} A labeled stream splicer pipeline | ||
*/ | ||
dispatch (action) { | ||
return this.props.store.dispatch(action); | ||
createPipeline () { | ||
let workflow = this.workflow(), | ||
streams = [], | ||
to = (stream) => { | ||
return stream | ||
.on('error', (err) => console.error(err.stack || err.message || err)); | ||
}; | ||
Object.keys(workflow).forEach((name) => { | ||
streams.push( | ||
/** The name from which to get the stream with */ | ||
name, | ||
/** Wrap each stream with an error and restart handler */ | ||
[to(workflow[name])], | ||
); | ||
}); | ||
return splicer.obj(streams); | ||
} | ||
/** | ||
* Error Handler | ||
* Emit an error event on serious errors. | ||
* Display Error | ||
* Shows the error on our stdout prop for the user | ||
* | ||
* @method | ||
* @public | ||
* @param {Error} e - Error instance thrown or caught | ||
* @param {string} err - Erro string to display | ||
*/ | ||
errorHandler (e) { | ||
this.props.app.emmit('error', e); | ||
displayError (err) { | ||
this.props.stdout.write(err); | ||
} | ||
/** | ||
* Dispatch | ||
* Dispatches the targeted action | ||
* | ||
* @method | ||
* @public | ||
* @param {object} action - Dispatches the given action object | ||
* @returns {*} The result of the dispatch call | ||
*/ | ||
dispatch (action) { | ||
return this.props.store.dispatch(action); | ||
} | ||
/** | ||
* Get Basedir | ||
@@ -126,16 +157,2 @@ * Returns the basedir from props or what is in the app state's config | ||
/** | ||
* Pipe To | ||
* Convienence method to restart the prompt as a last step | ||
* | ||
* @method | ||
* @public | ||
* @param {Stream} stream - A stream instance to add listeners to | ||
* @returns {Stream} The stream with listeners added | ||
*/ | ||
pipeTo (stream) { | ||
return stream | ||
.on('restart', this.reprompt); | ||
} | ||
/** | ||
* Reprompt | ||
@@ -148,4 +165,6 @@ * Shows the intro and the menu | ||
reprompt () { | ||
this.pipeline = this.createPipeline(); | ||
this.renderComponent(); | ||
Page.display(this); | ||
this.emit('reprompt'); | ||
} | ||
@@ -152,0 +171,0 @@ |
import colors from 'chalk'; | ||
import Dispatcher from '../streams/base_dispatcher'; | ||
import Dispatcher from '../streams/dispatcher'; | ||
import DispatchTransform from '../streams/dispatch_transform'; | ||
import MenuTransform from '../streams/menu_transform'; | ||
@@ -54,3 +55,3 @@ import minimatch from 'minimatch-all'; | ||
stdout: this.props.stdout, | ||
app: this.props.app | ||
app: this.props.app, | ||
}); | ||
@@ -60,4 +61,6 @@ | ||
stdin: this.props.stdin, | ||
stdout: this.props.stdout | ||
stdout: this.props.stdout, | ||
}); | ||
this.pipeline = this.createPipeline(); | ||
} | ||
@@ -75,3 +78,3 @@ | ||
return { | ||
files: this.getFiles(this.getGlob()) | ||
files: this.getFiles(this.getGlob()), | ||
}; | ||
@@ -99,3 +102,3 @@ } | ||
value: filename, | ||
isSelected: selectedFiles.indexOf(filename) > -1 | ||
isSelected: selectedFiles.indexOf(filename) > -1, | ||
}; | ||
@@ -132,2 +135,34 @@ }) || []; | ||
/** | ||
* Route | ||
* Routes the actions from the pipeline to navigation or error events. | ||
* | ||
* @param {stream} stream - Writable stream at the end of the pipeline | ||
* @param {object} action - Final action passed to router | ||
*/ | ||
route (stream, action) { | ||
switch (action.type) { | ||
case 'navigate': | ||
switch (action.data) { | ||
case 'blank': | ||
stream.end(); | ||
this.navigate('index'); | ||
break; | ||
case 'all': | ||
this.navigate('index'); | ||
break; | ||
} | ||
break; | ||
case 'done': | ||
this.reprompt(); | ||
break; | ||
case 'error': | ||
this.displayError(action.data); | ||
break; | ||
} | ||
} | ||
/** | ||
* Show Prompt | ||
@@ -138,7 +173,7 @@ * Beckons the prompt | ||
* @public | ||
* @returns {Stream|null} A duplex stream for processing the found files | ||
* @returns {stream} The resulting writable dispatcher stream. | ||
*/ | ||
showPrompt () { | ||
if (this.menu.options().length === 0) { | ||
process.stderr.write(colors.bold.red('No files have been changed since last git commit.\n')); | ||
this.props.stdout.write(colors.bold.red('No files have been changed since last git commit.\n')); | ||
return this.navigate('index'); | ||
@@ -148,12 +183,26 @@ } | ||
return this.prompt.beckon(this.question) | ||
.pipe(new QueriesTransform()) | ||
.pipe(new MenuTransform({ | ||
choices: this.menu.options() | ||
})) | ||
.pipe(new Dispatcher({ | ||
store: this.props.store | ||
})) | ||
.then(this.reprompt); | ||
.pipe(this.pipeline) | ||
.pipe(new Dispatcher(this.route)); | ||
} | ||
/** | ||
* Workflow | ||
* Returns the steps in the pipeline to send to labeled stream splicer. | ||
* | ||
* @method | ||
* @public | ||
* @returns {object} named steps in the pipeline | ||
*/ | ||
workflow () { | ||
return { | ||
query: new QueriesTransform(), | ||
menu: new MenuTransform({ | ||
menu: this.menu, | ||
}), | ||
dispatch: new DispatchTransform({ | ||
store: this.props.store, | ||
}), | ||
}; | ||
} | ||
renderMenu () { | ||
@@ -160,0 +209,0 @@ this.menu.setOptions(this.createOptionsFrom(this.state.files)); |
import colors from 'chalk'; | ||
import fs from 'fs'; | ||
import Dispatcher from '../streams/base_dispatcher'; | ||
import Dispatcher from '../streams/dispatcher'; | ||
import DispatchTransform from '../streams/dispatch_transform'; | ||
import GenericTransform from '../streams/generic_transform'; | ||
@@ -56,3 +57,3 @@ import MenuTransform from '../streams/menu_transform'; | ||
stdout: this.props.stdout, | ||
app: this.props.app | ||
app: this.props.app, | ||
}); | ||
@@ -62,4 +63,6 @@ | ||
stdin: this.props.stdin, | ||
stdout: this.props.stdout | ||
stdout: this.props.stdout, | ||
}); | ||
this.pipeline = this.createPipeline(); | ||
} | ||
@@ -78,3 +81,3 @@ | ||
selected: [], | ||
targetDir: null | ||
targetDir: null, | ||
}; | ||
@@ -133,3 +136,3 @@ } | ||
// Make dir labels bold bold | ||
label: isDirectory ? colors.bold(label) : label | ||
label: isDirectory ? colors.bold(label) : label, | ||
}; | ||
@@ -144,3 +147,3 @@ }); | ||
value: path.resolve(dir, '..'), | ||
label: colors.bold('..') | ||
label: colors.bold('..'), | ||
}); | ||
@@ -153,24 +156,2 @@ } | ||
/** | ||
* Show Prompt | ||
* Beckons the prompt | ||
* | ||
* @method | ||
* @public | ||
* @returns {Stream} A transform stream | ||
*/ | ||
showPrompt () { | ||
return this.prompt.beckon(this.question) | ||
.pipe(new QueriesTransform()) | ||
.pipe(new MenuTransform({ | ||
choices: this.menu.options() | ||
})) | ||
.pipe(new GenericTransform(this.processFile.bind(this))) | ||
.pipe(new Dispatcher({ | ||
store: this.props.store, | ||
route: this.route | ||
})) | ||
.then(this.reprompt); | ||
} | ||
/** | ||
* Process File | ||
@@ -202,6 +183,9 @@ * | ||
*/ | ||
if (stats.isDirectory()) { | ||
if (stats.isDirectory() && transformAction.data.type === 'single') { | ||
selectedDir = filepath; | ||
transformAction.type = 'directory'; | ||
} | ||
else if (stats.isDirectory()) { | ||
return; | ||
} | ||
@@ -224,9 +208,76 @@ /** | ||
route () { | ||
if (this.state.targetDir) { | ||
this.navigate('directories', { base: this.state.targetDir }); | ||
return true; | ||
/** | ||
* Route | ||
* Routes the actions from the pipeline to navigation or error events. | ||
* | ||
* @param {stream} stream - Writable stream at the end of the pipeline | ||
* @param {object} action - Final action passed to router | ||
*/ | ||
route (stream, action) { | ||
switch (action.type) { | ||
case 'navigate': | ||
switch (action.data) { | ||
case 'blank': | ||
stream.end(); | ||
this.navigate('index'); | ||
break; | ||
case 'all': | ||
this.navigate('index'); | ||
break; | ||
default: | ||
stream.end(); | ||
this.navigate('directories', { base: this.state.targetDir }); | ||
break; | ||
} | ||
break; | ||
case 'done': | ||
this.reprompt(); | ||
break; | ||
case 'error': | ||
this.displayError(action.data); | ||
break; | ||
} | ||
} | ||
/** | ||
* Show Prompt | ||
* Beckons the prompt | ||
* | ||
* @method | ||
* @public | ||
* @returns {stream} The resulting writable dispatcher stream. | ||
*/ | ||
showPrompt () { | ||
return this.prompt.beckon(this.question) | ||
.pipe(this.pipeline) | ||
.pipe(new Dispatcher(this.route)); | ||
} | ||
/** | ||
* Workflow | ||
* Returns the steps in the pipeline to send to labeled stream splicer. | ||
* | ||
* @method | ||
* @public | ||
* @returns {object} named steps in the pipeline | ||
*/ | ||
workflow () { | ||
return { | ||
query: new QueriesTransform(), | ||
menu: new MenuTransform({ | ||
menu: this.menu, | ||
}), | ||
process: new GenericTransform( | ||
this.processFile.bind(this) | ||
), | ||
dispatch: new DispatchTransform({ | ||
store: this.props.store, | ||
}), | ||
}; | ||
} | ||
renderMenu () { | ||
@@ -233,0 +284,0 @@ this.menu.setOptions(this.getFiles(this.getGlob(), this.getBasedir())); |
import glob from 'glob-all'; | ||
import Dispatcher from '../streams/base_dispatcher'; | ||
import Dispatcher from '../streams/dispatcher'; | ||
import DispatchTransform from '../streams/dispatch_transform'; | ||
import MenuTransform from '../streams/menu_transform'; | ||
@@ -53,3 +54,3 @@ import Page from '../page'; | ||
stdout: this.props.stdout, | ||
app: this.props.app | ||
app: this.props.app, | ||
}); | ||
@@ -59,4 +60,6 @@ | ||
stdin: this.props.stdin, | ||
stdout: this.props.stdout | ||
stdout: this.props.stdout, | ||
}); | ||
this.pipeline = this.createPipeline(); | ||
} | ||
@@ -95,3 +98,3 @@ | ||
isSelected: selectedFiles.indexOf(filename) > -1, | ||
label | ||
label, | ||
}; | ||
@@ -102,2 +105,34 @@ }) || []; | ||
/** | ||
* Route | ||
* Routes the actions from the pipeline to navigation or error events. | ||
* | ||
* @param {stream} stream - Writable stream at the end of the pipeline | ||
* @param {object} action - Final action passed to router | ||
*/ | ||
route (stream, action) { | ||
switch (action.type) { | ||
case 'navigate': | ||
switch (action.data) { | ||
case 'blank': | ||
stream.end(); | ||
this.navigate('index'); | ||
break; | ||
case 'all': | ||
this.navigate('index'); | ||
break; | ||
} | ||
break; | ||
case 'done': | ||
this.reprompt(); | ||
break; | ||
case 'error': | ||
this.displayError(action.data); | ||
break; | ||
} | ||
} | ||
/** | ||
* Prompt | ||
@@ -108,26 +143,28 @@ * Beckons the prompt | ||
* @public | ||
* @returns {stream} The resulting writable dispatcher stream. | ||
*/ | ||
showPrompt () { | ||
this.prompt.beckon(this.question) | ||
.pipe(new QueriesTransform()) | ||
.pipe(new MenuTransform({ | ||
choices: this.menu.options() | ||
})) | ||
.pipe(new Dispatcher({ | ||
store: this.props.store | ||
})) | ||
.then(this.reprompt); | ||
return this.prompt.beckon(this.question) | ||
.pipe(this.pipeline) | ||
.pipe(new Dispatcher(this.route)); | ||
} | ||
/** | ||
* Process Input | ||
* Deal with the answer from our prompt | ||
* Workflow | ||
* Returns the steps in the pipeline to send to labeled stream splicer. | ||
* | ||
* @method | ||
* @public | ||
* @param {string} answer - User input value | ||
* @returns {promise} Returns a promise to return the result | ||
* @returns {object} named steps in the pipeline | ||
*/ | ||
processInput (answer) { | ||
return this.menu.find(answer); | ||
workflow () { | ||
return { | ||
query: new QueriesTransform(), | ||
menu: new MenuTransform({ | ||
menu: this.menu, | ||
}), | ||
dispatch: new DispatchTransform({ | ||
store: this.props.store, | ||
}), | ||
}; | ||
} | ||
@@ -134,0 +171,0 @@ |
import glob from 'glob-all'; | ||
import Dispatcher from '../streams/base_dispatcher'; | ||
import Dispatcher from '../streams/dispatcher'; | ||
import DispatchTransform from '../streams/dispatch_transform'; | ||
import GenericTransform from '../streams/generic_transform'; | ||
import MenuTransform from '../streams/menu_transform'; import Page from '../page'; | ||
import MenuTransform from '../streams/menu_transform'; | ||
import Page from '../page'; | ||
import path from 'path'; | ||
@@ -51,3 +53,3 @@ import Prompt from '../prompt'; | ||
stdout: this.props.stdout, | ||
app: this.props.app | ||
app: this.props.app, | ||
}); | ||
@@ -57,4 +59,6 @@ | ||
stdin: this.props.stdin, | ||
stdout: this.props.stdout | ||
stdout: this.props.stdout, | ||
}); | ||
this.pipeline = this.createPipeline(); | ||
} | ||
@@ -75,3 +79,3 @@ | ||
files: [], | ||
filter: null | ||
filter: null, | ||
}; | ||
@@ -114,3 +118,3 @@ } | ||
value: filename, | ||
isSelected: selectedFiles.indexOf(filename) > -1 | ||
isSelected: selectedFiles.indexOf(filename) > -1, | ||
}; | ||
@@ -141,3 +145,2 @@ }) || []; | ||
* @param {object} transformAction - Stdin input value | ||
* @returns {*} Returns are used for control flow in this function. | ||
*/ | ||
@@ -149,3 +152,4 @@ processGlob (stream, transformAction) { | ||
if (type !== 'string' || creator !== 'prompt') { | ||
return stream.push(transformAction); | ||
stream.push(transformAction); | ||
return; | ||
} | ||
@@ -160,4 +164,8 @@ | ||
if (!input) { | ||
this.navigate('index'); | ||
stream.push(null); | ||
stream.destroy(); | ||
// this.navigate('index'); | ||
transformAction.type = 'navigate'; | ||
transformAction.data = { value: 'blank' }; | ||
stream.push(transformAction); | ||
return; | ||
} | ||
@@ -168,3 +176,4 @@ | ||
if (!files.length) { | ||
return stream.pushError(new Error(`No files matched the glob string "${input}"`)); | ||
stream.pushError(`No files matched the glob string "${input}"`); | ||
return; | ||
} | ||
@@ -174,6 +183,4 @@ | ||
filter: input, | ||
files | ||
files, | ||
}); | ||
stream.push(null); | ||
} | ||
@@ -203,2 +210,34 @@ | ||
/** | ||
* Route | ||
* Routes the actions from the pipeline to navigation or error events. | ||
* | ||
* @param {stream} stream - Writable stream at the end of the pipeline | ||
* @param {object} action - Final action passed to router | ||
*/ | ||
route (stream, action) { | ||
switch (action.type) { | ||
case 'navigate': | ||
switch (action.data) { | ||
case 'blank': | ||
stream.end(); | ||
this.navigate('index'); | ||
break; | ||
case 'all': | ||
this.navigate('index'); | ||
break; | ||
} | ||
break; | ||
case 'done': | ||
this.reprompt(); | ||
break; | ||
case 'error': | ||
this.displayError(action.data); | ||
break; | ||
} | ||
} | ||
/** | ||
* ShowPrompt | ||
@@ -209,26 +248,41 @@ * Beckons the prompt | ||
* @public | ||
* @returns {stream} The resulting writable dispatcher stream. | ||
*/ | ||
showPrompt () { | ||
return this.prompt.beckon(this.question()) | ||
.pipe(this.pipeline) | ||
.pipe(new Dispatcher(this.route)); | ||
} | ||
/** | ||
* Workflow | ||
* Returns the steps in the pipeline to send to labeled stream splicer. | ||
* | ||
* @method | ||
* @public | ||
* @returns {object} named steps in the pipeline | ||
*/ | ||
workflow () { | ||
/** | ||
* If files have been found from the glob, lets | ||
* If files have been found from the glob, then query against those | ||
* matching files. | ||
*/ | ||
if (this.state.files.length) { | ||
this.prompt.beckon(this.question()) | ||
.pipe(new QueriesTransform()) | ||
.pipe(new MenuTransform({ | ||
choices: this.menu.options() | ||
})) | ||
.pipe(new Dispatcher({ | ||
store: this.props.store | ||
})) | ||
.then(this.reprompt); | ||
return { | ||
query: new QueriesTransform(), | ||
menu: new MenuTransform({ | ||
menu: this.menu, | ||
}), | ||
dispatch: new DispatchTransform({ | ||
store: this.props.store, | ||
}), | ||
}; | ||
} | ||
else { | ||
this.prompt.beckon(this.question()) | ||
.pipe(new GenericTransform(this.processGlob.bind(this))) | ||
.pipe(new Dispatcher({ | ||
store: this.props.store | ||
})) | ||
.on('finish', this.reprompt); | ||
} | ||
return { | ||
glob: new GenericTransform(this.processGlob.bind(this)), | ||
dispatch: new DispatchTransform({ | ||
store: this.props.store, | ||
}), | ||
}; | ||
} | ||
@@ -235,0 +289,0 @@ |
import colors from 'chalk'; | ||
import column from '../util/column'; | ||
import Dispatcher from '../streams/base_dispatcher'; | ||
import Dispatcher from '../streams/dispatcher'; | ||
import DispatchTransform from '../streams/dispatch_transform'; | ||
import Menu from '../menu'; | ||
@@ -15,3 +16,3 @@ import MenuTransform from '../streams/menu_transform'; | ||
name: 'directories', | ||
value: 'directories' | ||
value: 'directories', | ||
}, | ||
@@ -22,3 +23,3 @@ { | ||
name: 'files', | ||
value: 'files' | ||
value: 'files', | ||
}, | ||
@@ -29,3 +30,3 @@ { | ||
name: 'glob', | ||
value: 'glob' | ||
value: 'glob', | ||
}, | ||
@@ -36,3 +37,3 @@ { | ||
name: 'changed', | ||
value: 'changed' | ||
value: 'changed', | ||
}, | ||
@@ -43,3 +44,3 @@ { | ||
name: 'help', | ||
value: 'help' | ||
value: 'help', | ||
}, | ||
@@ -50,3 +51,3 @@ { | ||
name: 'quit', | ||
value: 'quit' | ||
value: 'quit', | ||
}], | ||
@@ -82,3 +83,3 @@ MAX_LABEL_WIDTH = 6, | ||
stdin: this.props.stdin, | ||
stdout: this.props.stdout | ||
stdout: this.props.stdout, | ||
}); | ||
@@ -90,48 +91,62 @@ | ||
stdout: this.props.stdout, | ||
app: this.props.app | ||
app: this.props.app, | ||
}); | ||
this.pipeline = this.createPipeline(); | ||
} | ||
/** | ||
* Process Input | ||
* Deal with the answer from our prompt | ||
* Quit | ||
* Closes the app and writes a goodbye message. | ||
* | ||
* @method | ||
* @public | ||
* @param {string} answer - User input value | ||
* @returns {promise} Returns a promise to return the result | ||
*/ | ||
processInput (answer) { | ||
return this.menu.find(answer, (queries) => queries.slice(0, 1)); | ||
quit () { | ||
this.emit('complete', this.select('files')); | ||
} | ||
/** | ||
* Quit | ||
* Closes the app and writes a goodbye message. | ||
* Route | ||
* Routes the actions from the pipeline to navigation or error events. | ||
* | ||
* @param {stream} stream - Writable stream at the end of the pipeline | ||
* @param {object} action - Final action passed to router | ||
*/ | ||
quit () { | ||
if (this.props.app) { | ||
this.props.app.emit('complete', this.select('files')); | ||
} | ||
this.props.stdin.pause(); | ||
} | ||
route (stream, action) { | ||
let value = action.data; | ||
route (creator, type, data) { | ||
let { value } = data; | ||
switch (action.type) { | ||
case 'navigate': | ||
switch (action.data) { | ||
case 'blank': | ||
stream.end(); | ||
this.reprompt(); | ||
break; | ||
switch (value) { | ||
case null: | ||
return false; | ||
case 'quit': | ||
stream.end(); | ||
this.quit(); | ||
break; | ||
case 'quit': | ||
this.quit(); | ||
return true; | ||
case 'help': | ||
stream.end(); | ||
this.showHelp(); | ||
this.reprompt(); | ||
break; | ||
case 'help': | ||
this.showHelp(); | ||
return false; | ||
default: | ||
stream.end(); | ||
this.navigate(value); | ||
break; | ||
} | ||
break; | ||
default: | ||
this.navigate(value); | ||
return true; | ||
case 'done': | ||
this.reprompt(); | ||
break; | ||
case 'error': | ||
this.displayError(action.data); | ||
break; | ||
} | ||
@@ -154,3 +169,3 @@ } | ||
help: 'Uhhh... this thing I guess...', | ||
quit: 'Forward files along' | ||
quit: 'Forward files along', | ||
}, | ||
@@ -179,17 +194,28 @@ text = 'HELP\n'; | ||
showPrompt () { | ||
let to = this.pipeTo; | ||
return this.prompt.beckon(this.question) | ||
.pipe(this.pipeline) | ||
.pipe(new Dispatcher(this.route)); | ||
} | ||
return this.prompt.beckon(this.question) | ||
.pipe(to(new QueriesTransform({ | ||
maxQueries: 1 | ||
}))) | ||
.pipe(to(new MenuTransform({ | ||
choices: this.menu.options(), | ||
canUnselect: false | ||
}))) | ||
.pipe(to(new Dispatcher({ | ||
/** | ||
* Workflow | ||
* Returns the steps in the pipeline to send to labeled stream splicer. | ||
* | ||
* @method | ||
* @public | ||
* @returns {object} named steps in the pipeline | ||
*/ | ||
workflow () { | ||
return { | ||
query: new QueriesTransform({ | ||
maxQueries: 1, | ||
}), | ||
menu: new MenuTransform({ | ||
menu: this.menu, | ||
canUnselect: false, | ||
}), | ||
dispatch: new DispatchTransform({ | ||
store: this.props.store, | ||
route: this.route | ||
}))) | ||
.then(this.reprompt); | ||
}), | ||
}; | ||
} | ||
@@ -203,3 +229,3 @@ | ||
* @public | ||
* @returns {string} Intro text to display | ||
* @returns {stream} The resulting writable dispatcher stream. | ||
*/ | ||
@@ -206,0 +232,0 @@ renderIntro () { |
@@ -20,3 +20,3 @@ /* eslint no-param-reassign: 0 */ | ||
stdin: process.stdin, | ||
stdout: process.stdout | ||
stdout: process.stdout, | ||
}; | ||
@@ -23,0 +23,0 @@ |
@@ -205,3 +205,3 @@ /** | ||
let data = { | ||
action: 'select' | ||
action: 'select', | ||
}, | ||
@@ -208,0 +208,0 @@ query = this.query; |
import bindMethods from '../util/bind_methods'; | ||
import stripAnsi from 'strip-ansi'; | ||
import TransformAction from '../transform_action'; | ||
import { Transform } from 'stream'; | ||
import { MatchError } from '../errors'; | ||
@@ -17,2 +17,4 @@ /** | ||
params = {}; | ||
name = 'BaseTransform'; | ||
isDestroyed = false; | ||
@@ -55,14 +57,16 @@ /** | ||
/** | ||
* Commit | ||
* Creates an action and calls finish to signify no more data will be | ||
* created from this stream. | ||
* Destroys the transform with an optional err param | ||
* | ||
* @method | ||
* @public | ||
* @param {*} data - Dated to be pushed | ||
* @param {string|null} [type=null] Type of data to be pushed | ||
* @param {string} err - Reason for destroying the stream from error | ||
*/ | ||
commit (data) { | ||
this.pushAction(data); | ||
this.finish(); | ||
destroy (err) { | ||
if (this.isDestroyed) return; | ||
this.isDestroyed = true; | ||
process.nextTick(() => { | ||
if (err) this.emit('error', err); | ||
this.emit('close'); | ||
}); | ||
} | ||
@@ -80,3 +84,3 @@ | ||
process.stderr.write(`${err.stack || err.message}\n`); | ||
process.exit(0); | ||
process.exit(1); | ||
} | ||
@@ -102,13 +106,2 @@ | ||
/** | ||
* Finish | ||
* Tells the stream we are done emitting data and to fire the end event. | ||
* | ||
* @method | ||
* @public | ||
*/ | ||
finish () { | ||
this.push(null); | ||
} | ||
/** | ||
* Match Error | ||
@@ -123,3 +116,9 @@ * Pushes a match error down the stream. This is used when the raw input | ||
matchError (searchFor) { | ||
this.pushError(new MatchError(searchFor.toString())); | ||
let err = stripAnsi(searchFor.toString()).trim(); | ||
/** Format the match error */ | ||
if (err) err = ` (${err})`; | ||
err = `Huh${err}?`; | ||
this.pushError(err); | ||
} | ||
@@ -150,5 +149,4 @@ | ||
type: 'error', | ||
data: err | ||
data: err, | ||
}); | ||
this.finish(); | ||
} | ||
@@ -178,3 +176,2 @@ | ||
this.push(input); | ||
this.finish(); | ||
} | ||
@@ -181,0 +178,0 @@ |
@@ -26,2 +26,19 @@ import { Transform } from 'stream'; | ||
/** | ||
* Destroys the transform with an optional err param | ||
* | ||
* @param {string} err - Reason for destroying the stream from error | ||
*/ | ||
destroy (err) { | ||
if (this.isDestroyed) return; | ||
this.isDestroyed = true; | ||
process.nextTick(() => { | ||
if (err) this.emit('error', err); | ||
this.emit('close'); | ||
}); | ||
} | ||
/** | ||
* Push Error | ||
@@ -37,3 +54,3 @@ * | ||
type: 'error', | ||
data: err | ||
data: err, | ||
}); | ||
@@ -40,0 +57,0 @@ this.push(null); |
@@ -6,11 +6,17 @@ import BaseTransform from './base_transform'; | ||
* Range | ||
* Slice out a range of indexes from an array. | ||
* Return a populated array with the values from the min to the max. | ||
* | ||
* @param {array} ids - List of ids | ||
* @param {int} min - Minimum index value 1-index based | ||
* @param {int} max - Up to the maximum | ||
* @returns {array} Sliced array of ids within the given range | ||
* @returns {array} Array of numbers from min to max | ||
*/ | ||
function range (ids, min, max) { | ||
return ids.slice(min - 1, max); | ||
function range (min, max) { | ||
let length = max - min, | ||
rangeArray = Array(length); | ||
for (let idx = 0; idx <= length; idx += 1, min += 1) { | ||
rangeArray[idx] = min; | ||
} | ||
return rangeArray; | ||
} | ||
@@ -22,7 +28,8 @@ | ||
creator: 'queries', | ||
type: 'query' | ||
type: 'query', | ||
}; | ||
choices = []; | ||
ids = []; | ||
menu = null; | ||
/** Lifecycle methods */ | ||
/** | ||
@@ -38,6 +45,3 @@ * Constructor | ||
if (options.choices) { | ||
this.choices = options.choices; | ||
this.ids = this.choices.map((opt) => opt.id); | ||
} | ||
if (options.menu) this.menu = options.menu; | ||
} | ||
@@ -54,74 +58,24 @@ | ||
*/ | ||
getParams (options) { | ||
let canUnselect = options.canSelect; | ||
getParams (options={}) { | ||
let canUnselect = options.canUnselect; | ||
canUnselect = typeof canUnselect === 'undefined' ? true : canUnselect; | ||
return { | ||
canUnselect: !!canUnselect || typeof canUnselect === 'undefined' | ||
canUnselect, | ||
}; | ||
} | ||
/** | ||
* Filter | ||
* Iterates through each chocie and returns a new array | ||
* | ||
* @method | ||
* @public | ||
* @param {function} callback - Callback to iterate on each item | ||
* @param {object} [context] - Optional context to send with callback | ||
* @returns {array} Filtered result arrray | ||
*/ | ||
filter (callback, context=this) { | ||
return this.choices.filter(callback, context); | ||
} | ||
/** Helpers */ | ||
/** | ||
* Get Choice By Id | ||
* Returns a choice by the given id | ||
* Returns a copy of ids from the menu | ||
* | ||
* @method | ||
* @public | ||
* @param {int} id - Id to search through choices for | ||
* @returns {object} Choice by that given id | ||
* @returns {array} Array of menu option choice ids | ||
*/ | ||
getChoiceById (id) { | ||
/** | ||
* Throw a serious error if this fails, it is only used internally | ||
*/ | ||
if (!this.hasId(id)) throw new Error(`MenuTransform.getChoiceById: Could not find chocie by id "${id}"`); | ||
return this.choices[this.ids.indexOf(id)]; | ||
getChoiceIds () { | ||
return this.menu.ids().slice(); | ||
} | ||
/** | ||
* Get Choice By Name | ||
* Searches through all our options looking for | ||
* | ||
* @param {Query} query - Query to search for | ||
* @returns {array} Array of matching ids | ||
*/ | ||
getChoiceByName (query) { | ||
let results = this.filter((option) => query.isStartOf(option.name)); | ||
/** | ||
* If the results are 0 or more than 1 return an empty array because | ||
* name searches need to match only 1 item to be valid. | ||
*/ | ||
if (results.length !== 1) return []; | ||
return results.map((option) => option.id); | ||
} | ||
/** | ||
* Has Id | ||
* Returns boolean if a choice by that id exists. | ||
* | ||
* @method | ||
* @public | ||
* @param {int} id - Id to look for | ||
* @returns {boolean} True if id was found | ||
*/ | ||
hasId (id) { | ||
return this.ids.indexOf(Number(id)) > -1; | ||
} | ||
/** | ||
* Is Select Only | ||
@@ -142,28 +96,25 @@ * Determines if unselections are allowed. For instance on the main menu | ||
/** | ||
* Map | ||
* Iterates through each choice and returns a new array of the same size | ||
* Validates the selected choices | ||
* | ||
* @param {function} callback - Callback to iterate on each item | ||
* @param {object} [context] - Optional context to send with callback | ||
* @returns {array} Mapped result arrray | ||
* @param {array} ids - An array of option ids | ||
* @returns {array} List of menu choices | ||
*/ | ||
map (callback, context=this) { | ||
return this.choices.map(callback, context); | ||
isValid (ids=[]) { | ||
let isLegit = Array.isArray(ids) && ids.every(this.menu.hasId, this.menu); | ||
return isLegit && ids && ids.length > 0; | ||
} | ||
/** | ||
* Transform | ||
* Transforms the incoming search string into a bunch of queries to process | ||
* Selects choices from the menu based on various query types | ||
* | ||
* @method | ||
* @public | ||
* @param {object} transformAction - Transform action from incoming stream | ||
* @returns {*} Return values are ignored | ||
* @param {query} query - A query instance to test values of | ||
* @param {object} params - Extra params that set constraints on queries | ||
* @returns {array} Array of selected option ids | ||
*/ | ||
transform (transformAction) { | ||
let { data: query, params } = transformAction, | ||
{ type, action, value } = query.data, | ||
data = []; | ||
select (query, params) { | ||
let ids = [], | ||
data = query.data; | ||
if (this.isSelectOnly(action)) return this.matchError(query); | ||
if (this.isSelectOnly(query.action)) return []; | ||
@@ -174,13 +125,11 @@ /** | ||
*/ | ||
Object.assign(params, { | ||
canUnselect: this.params.canUnselect | ||
}); | ||
Object.assign(params, { canUnselect: this.params.canUnselect }); | ||
// Determine what to do by the type of action the query is requesting | ||
switch (type) { | ||
switch (data.type) { | ||
// User has input a '*' so select all the things | ||
case 'all': | ||
if (params.maxQueries > 0) return this.matchError(query); | ||
data = this.ids.slice(); | ||
if (params.maxQueries > 0) return []; | ||
ids = this.getChoiceIds(); | ||
break; | ||
@@ -190,11 +139,13 @@ | ||
case 'range': | ||
if (params.maxQueries > 0) return this.matchError(query); | ||
// If maxQueries is set then ranges are not allowed. | ||
if (params.maxQueries > 0) return []; | ||
// Range should be valid choice id numbers | ||
if (!this.hasId(value.min) || !this.hasId(value.max)) { | ||
return this.matchError(query); | ||
} | ||
// Test against invalid values | ||
if (!data.value.min || !data.value.max) return []; | ||
// Slice the range from the list of ids | ||
data = range(this.ids, value.min, value.max); | ||
// Error if query value.min is greater than the max | ||
else if (data.value.min > data.value.max) return []; | ||
// Create a list of ids in the given range | ||
ids = range(data.value.min, data.value.max); | ||
break; | ||
@@ -204,5 +155,5 @@ | ||
case 'id': | ||
if (!this.hasId(value)) return this.matchError(query); | ||
data = [value]; | ||
type = 'single'; | ||
if (!query.isInteger()) return []; | ||
ids = [data.value]; | ||
data.type = 'single'; | ||
break; | ||
@@ -212,30 +163,56 @@ | ||
case 'string': | ||
data = this.getChoiceByName(query); | ||
type = 'single'; | ||
ids = this.menu.getIdByName(query.toString()); | ||
data.type = 'single'; | ||
break; | ||
} | ||
// If no data operations exist then lets bail | ||
if (!data || !data.length) return this.matchError(query); | ||
return ids; | ||
} | ||
data | ||
// Double check to make sure we are only working with ids that exist | ||
.filter(this.hasId, this) | ||
// Convert the array to a list of choices | ||
.map(this.getChoiceById, this) | ||
// for each choice push an action | ||
.forEach(({ value: choice }) => { | ||
/** Transformer */ | ||
/** | ||
* Transform | ||
* Transforms the incoming search string into a bunch of queries to process | ||
* | ||
* @method | ||
* @public | ||
* @param {object} transformAction - Transform action from incoming stream | ||
*/ | ||
transform (transformAction) { | ||
let { data: query, params } = transformAction, | ||
choices = this.select(query, params); | ||
/** | ||
* If the list of choices is not valid, push a match error. | ||
*/ | ||
if (!this.isValid(choices)) { | ||
this.matchError(query); | ||
return; | ||
} | ||
// Start with our choices array | ||
choices | ||
// Convert our array of ids into an array of menu option objects | ||
.map((id) => this.menu.getChoiceById(id).value) | ||
// Build our action objects for each choice | ||
.map((choice) => { | ||
let isPath = choice.slice(0, 1) === path.sep; | ||
this.pushAction({ | ||
type: isPath ? 'file' : 'action', | ||
return { | ||
type: isPath ? 'file' : 'page', | ||
data: { | ||
operation: action, | ||
operation: query.data.action, | ||
value: choice, | ||
type | ||
type: query.data.type, | ||
}, | ||
params | ||
}); | ||
}); | ||
params, | ||
}; | ||
}) | ||
// Push each action down the stream | ||
.forEach(this.pushAction, this); | ||
} | ||
} |
@@ -8,3 +8,3 @@ import BaseTransform from './base_transform'; | ||
creator: 'prompt', | ||
type: 'string' | ||
type: 'string', | ||
}; | ||
@@ -34,3 +34,3 @@ | ||
return { | ||
maxQueries: options.maxQueries || 0 | ||
maxQueries: options.maxQueries || 0, | ||
}; | ||
@@ -51,5 +51,5 @@ } | ||
isTooManyQueries (queries) { | ||
let length = queries.length; | ||
let maxQueries = this.params.maxQueries; | ||
return this.params.maxQueries > 0 && length > this.params.maxQueries; | ||
return maxQueries > 0 && queries.length > maxQueries; | ||
} | ||
@@ -64,3 +64,2 @@ | ||
* @param {object} transformAction - Transform action from incoming stream | ||
* @returns {*} Return values are ignored | ||
*/ | ||
@@ -71,3 +70,3 @@ transform (transformAction) { | ||
params = { | ||
maxQueries: this.params.maxQueries | ||
maxQueries: this.params.maxQueries, | ||
}; | ||
@@ -80,3 +79,3 @@ | ||
if (searchFor === "") { | ||
return this.commit({ | ||
this.pushAction({ | ||
creator: 'menu', // Create an empty menu selection action | ||
@@ -86,11 +85,15 @@ type: 'action', // As it's not a file just an empty action | ||
operation: 'blank', | ||
value: null | ||
value: null, | ||
}, | ||
params: { | ||
queryCount: 1 | ||
} | ||
queryCount: 1, | ||
}, | ||
}); | ||
return; | ||
} | ||
if (!Query.isValid(searchFor)) return this.matchError('1:' + searchFor); | ||
if (!Query.isValid(searchFor)) { | ||
this.matchError(searchFor); | ||
return; | ||
} | ||
@@ -105,3 +108,6 @@ /** Update the queries options */ | ||
*/ | ||
if (this.isTooManyQueries(queries)) return this.matchError('2:' + searchFor); | ||
if (this.isTooManyQueries(queries)) { | ||
this.matchError(searchFor); | ||
return; | ||
} | ||
@@ -116,8 +122,6 @@ // Update the query count so it's available | ||
data: query, | ||
params | ||
params, | ||
}); | ||
}); | ||
this.finish(); | ||
} | ||
} |
@@ -26,3 +26,3 @@ import TransformAction from '../transform_action'; | ||
*/ | ||
constructor (options) { | ||
constructor (options={}) { | ||
super({ objectMode: true }); | ||
@@ -44,2 +44,5 @@ | ||
addListeners () { | ||
/** Remove the last stdin data listener */ | ||
this.stdin.removeAllListeners('data'); | ||
/** | ||
@@ -53,21 +56,9 @@ * Sets a listener for the data event which is fired when user | ||
type: 'string', | ||
data: String(data).trim() | ||
data: String(data).trim(), | ||
})); | ||
this.stdin.pause(); | ||
this.push(null); | ||
}); | ||
/** | ||
* Get the last data listener | ||
*/ | ||
this.listener = this.stdin.listeners('data').pop(); | ||
/** | ||
* Triggered when we've pushed a null from valid input | ||
*/ | ||
this.once('end', () => { | ||
/** Remove the last stdin data listener */ | ||
this.stdin.removeListener('data', this.listener); | ||
this.listener = null; | ||
this.stdin.pause(); | ||
}); | ||
this.listener = true; | ||
} | ||
@@ -74,0 +65,0 @@ |
@@ -13,3 +13,5 @@ /* eslint no-console: 0 */ | ||
.catch((err) => { | ||
console.error(err); | ||
console.log('\n'); | ||
console.error(err.stack || err.message || err); | ||
console.log('\n'); | ||
}); |
171
test/api.js
@@ -6,39 +6,154 @@ import fileprompt from '../src'; | ||
import path from 'path'; | ||
import StdoutInterceptor from './lib/stdout_interceptor'; | ||
/** | ||
* Extract the basenames from a list of absolute paths | ||
* | ||
* @param {array} files - List of absolute path files | ||
* @returns {array} List of base files filename.ext from /path/filename.ext | ||
*/ | ||
function basenames (files) { | ||
return files.map((file) => path.basename(file)); | ||
} | ||
/** | ||
* Runs fileprompt and makes sure files are returned then maps them to just | ||
* their basenames for further testing | ||
* | ||
* @param {array} data - List of input data to enter in | ||
* @returns {Promise} A promise resolved with the basenames of all the files | ||
*/ | ||
function getFiles (data=[]) { | ||
let stdin = new MockStdin(data), | ||
stdout = new MockStdout(); | ||
return fileprompt({ | ||
stdin, | ||
stdout, | ||
}) | ||
.then((files) => { | ||
expect(files).toExist(); | ||
expect(files).toBeA(Array); | ||
return basenames(files); | ||
}); | ||
} | ||
describe('FilePrompt', () => { | ||
it('Should select 2 files from the src directory', (done) => { | ||
let stdin = new MockStdin(['2', '1 2', '', 'q']), | ||
stdout = new MockStdout(); | ||
describe('directories', () => { | ||
it('Should select 2 files from the src directory', () => { | ||
return getFiles(['1', '1 2', '', 'q']) | ||
.then((files) => { | ||
expect(files).toEqual(['actions.js', 'app.js']); | ||
}); | ||
}); | ||
it('Should be able to select all pages', () => { | ||
return getFiles(['1', 'pages', '*', 'q']) | ||
.then((files) => { | ||
expect(files).toEqual([ | ||
'changed_page.js', | ||
'directories_page.js', | ||
'files_page.js', | ||
'glob_page.js', | ||
'index_page.js', | ||
]); | ||
}); | ||
}); | ||
fileprompt({ | ||
stdin, | ||
stdout | ||
}) | ||
.then((files) => { | ||
expect(files).toExist(); | ||
expect(files).toBeA(Array); | ||
expect(files.map((file) => path.basename(file))).toEqual(['actions.js', 'app.js']); | ||
}) | ||
.then(done, done); | ||
it('Should be able to select a single page file and select another file from root', () => { | ||
return getFiles(['1', 'pages', '2', '1', '1', '', 'q']) | ||
.then((files) => { | ||
expect(files).toEqual([ | ||
'changed_page.js', | ||
'actions.js', | ||
]); | ||
}); | ||
}); | ||
it('Select a range of files', () => { | ||
return getFiles(['1', '1-4', '', 'q']) | ||
.then((files) => { | ||
expect(files).toEqual([ | ||
'actions.js', | ||
'app.js', | ||
'component.js', | ||
'index.js', | ||
]); | ||
}); | ||
}); | ||
it('Select a range of files then unselect one of them', () => { | ||
return getFiles(['1', '1-4', '-3', '', 'q']) | ||
.then((files) => { | ||
expect(files).toEqual([ | ||
'actions.js', | ||
'app.js', | ||
'index.js', | ||
]); | ||
}); | ||
}); | ||
}); | ||
it('Should select 2 files from a glob str', (done) => { | ||
let stdin = new MockStdin(['3','**/*.js', '1 2', '', 'q']), | ||
stdout = new MockStdout(); | ||
describe('files', () => { | ||
it('Should select the first two files', () => { | ||
return getFiles(['2', '1', '2', '', 'q']) | ||
.then((files) => { | ||
expect(files).toEqual(['actions.js', 'app.js']); | ||
}); | ||
}); | ||
it('Should all the files and return to the main menu', () => { | ||
return getFiles(['2', '*', 'q']) | ||
.then((files) => { | ||
expect(files).toInclude('actions.js'); | ||
expect(files).toInclude('app.js'); | ||
}); | ||
}); | ||
fileprompt({ | ||
stdin, | ||
stdout | ||
}) | ||
.then((files) => { | ||
expect(files).toExist(); | ||
expect(files).toBeA(Array); | ||
expect(files.map((file) => path.basename(file))).toEqual(['actions.js', 'app.js']); | ||
}) | ||
.then(done, done); | ||
it('Should select all files unselect all files and return to main menu', () => { | ||
return getFiles(['2', '*', '2', '-*', '', 'q']) | ||
.then((files) => { | ||
expect(files).toEqual([]); | ||
}); | ||
}); | ||
it('Should select 5 files', () => { | ||
return getFiles(['2', '1 2-4', '5', '', 'q']) | ||
.then((files) => { | ||
expect(files).toEqual([ | ||
'actions.js', | ||
'app.js', | ||
'component.js', | ||
'index.js', | ||
'menu.js', | ||
]); | ||
}); | ||
}); | ||
}); | ||
describe('glob', () => { | ||
it('Should select 2 files from a glob str', () => { | ||
return getFiles(['3', '**/*.js', '1 2', '', 'q']) | ||
.then((files) => { | ||
expect(files).toEqual(['actions.js', 'app.js']); | ||
}); | ||
}); | ||
it('Should return to the main menu on blank', () => { | ||
return getFiles(['3', '', 'q']) | ||
.then((files) => { | ||
expect(files).toEqual([]); | ||
}); | ||
}); | ||
it('Should allow selection and unselection', () => { | ||
return getFiles(['3', '**/*.js', '*', '3', '**/*.js', '-*', '1-3', '', 'q']) | ||
.then((files) => { | ||
expect(files).toEqual([ | ||
'actions.js', | ||
'app.js', | ||
'component.js', | ||
]); | ||
}); | ||
}); | ||
}); | ||
}); | ||
@@ -14,3 +14,3 @@ import expect from 'expect'; | ||
'renderPage', | ||
'render' | ||
'render', | ||
]; | ||
@@ -63,3 +63,3 @@ | ||
let app = new App({ | ||
initialPage: 'index' | ||
initialPage: 'index', | ||
}), | ||
@@ -66,0 +66,0 @@ ceptor = new StdoutInterceptor(); |
@@ -8,3 +8,3 @@ import path from 'path'; | ||
config: { | ||
basedir: path.resolve(__dirname, '..', '..') | ||
base: path.resolve(__dirname, '..', '..'), | ||
}, | ||
@@ -14,5 +14,5 @@ files: [], | ||
name: 'index', | ||
props: {} | ||
props: {}, | ||
}, | ||
glob: '**/*.js' | ||
glob: '**/*.js', | ||
}; | ||
@@ -19,0 +19,0 @@ |
@@ -5,3 +5,2 @@ import expect from 'expect'; | ||
import MockStdin from './lib/mock_stdin'; | ||
import StdoutInterceptor from './lib/stdout_interceptor'; | ||
import StoreFactory from './factories/store'; | ||
@@ -11,2 +10,16 @@ | ||
/** | ||
* Creates a page instance with a mock stdin, stdout, and store | ||
* | ||
* @param {array} data - Initial data for mockstdin to emit | ||
* @returns {Page} Initialized page instance | ||
*/ | ||
function createPage (data=[]) { | ||
return new IndexPage({ | ||
store: StoreFactory.create(), | ||
stdin: new MockStdin(data), | ||
stdout, | ||
}); | ||
} | ||
describe('Index Page', () => { | ||
@@ -18,8 +31,2 @@ afterEach(() => { | ||
after(() => { | ||
if (process.stdin.end) { | ||
process.stdin.end(); | ||
} | ||
}); | ||
describe('#constructor()', () => { | ||
@@ -31,16 +38,14 @@ it('Should exist', () => { | ||
it('Should produce an IndexPage', () => { | ||
expect(new IndexPage()).toBeA(IndexPage); | ||
let store = StoreFactory.create(); | ||
expect(new IndexPage({ store })).toBeA(IndexPage); | ||
}); | ||
it('Should support input & output props', () => { | ||
let stdin = new MockStdin(['Hello world']), | ||
page = new IndexPage({ | ||
stdin, | ||
stdout | ||
}); | ||
let page = createPage(['Hello World']); | ||
expect(page.state.menu.props.stdin).toBe(stdin); | ||
expect(page.state.menu.props.stdout).toBe(stdout); | ||
expect(page.state.prompt.options.stdin).toBe(stdin); | ||
expect(page.state.prompt.options.stdout).toBe(stdout); | ||
expect(page.menu.props.stdin).toBe(page.props.stdin); | ||
expect(page.menu.props.stdout).toBe(page.props.stdout); | ||
expect(page.prompt.options.stdin).toBe(page.props.stdin); | ||
expect(page.prompt.options.stdout).toBe(page.props.stdout); | ||
}); | ||
@@ -50,168 +55,172 @@ | ||
describe('#render()', () => { | ||
it('Should render the intro, menu, and prompt', () => { | ||
let store = StoreFactory.create(), | ||
page = new IndexPage({ | ||
stdin: new MockStdin(['Test string']), | ||
stdout, | ||
store | ||
}), | ||
output; | ||
describe('#quit()', () => { | ||
it('Should emit a complete event', () => { | ||
let page = createPage(), | ||
spy = expect.createSpy(); | ||
IndexPage.mount(page); | ||
page.on('complete', spy); | ||
page.quit(); | ||
output = stdout.toString(); | ||
expect(output).toBe('\x1b[37m\x1b[1m*** COMMANDS ***\x1b[22m\x1b[39m\n 1: \x1b[35m\x1b[1md\x1b[22m\x1b[39mirectories 2: \x1b[35m\x1b[1mf\x1b[22m\x1b[39miles 3: \x1b[35m\x1b[1mg\x1b[22m\x1b[39mlob 4: \x1b[35m\x1b[1mc\x1b[22m\x1b[39mhanged \n 5: \x1b[35m\x1b[1mh\x1b[22m\x1b[39melp 6: \x1b[35m\x1b[1mq\x1b[22m\x1b[39muit \n\x1b[34m\x1b[1mWhat do you seek?\x1b[22m\x1b[39m\x1b[35m\x1b[1m > \x1b[22m\x1b[39m'); | ||
expect(spy).toHaveBeenCalled(); | ||
}); | ||
}); | ||
describe('#prompt()', () => { | ||
it('Should respond to numbers', (done) => { | ||
let stdin = new MockStdin(['1']), | ||
store = StoreFactory.create(), | ||
page = new IndexPage({ | ||
stdin, | ||
stdout, | ||
store | ||
}); | ||
describe('#route()', () => { | ||
it('Should reprompt on blank responses', () => { | ||
let page = createPage(), | ||
stream = new MockStdout(), | ||
spy = expect.spyOn(page, 'reprompt'); | ||
page.prompt() | ||
.then((results) => { | ||
expect(results).toExist(); | ||
expect(results.selectedItems).toBeA(Array); | ||
expect(results.selectedItems[0].value).toBe('directories'); | ||
}) | ||
.then(done, done); | ||
page.route(stream, { | ||
type: 'navigate', | ||
data: 'blank', | ||
}); | ||
expect(spy).toHaveBeenCalled(); | ||
}); | ||
stdin.emit('readable'); | ||
it('Should call quit on a quit response', () => { | ||
let page = createPage(), | ||
stream = new MockStdout(), | ||
spy = expect.spyOn(page, 'quit'); | ||
page.route(stream, { | ||
type: 'navigate', | ||
data: 'quit', | ||
}); | ||
expect(spy).toHaveBeenCalled(); | ||
}); | ||
it('Should respond to negative numbers with error and reprompt', (done) => { | ||
let stdin = new MockStdin(['-1']), | ||
store = StoreFactory.create(), | ||
page = new IndexPage({ | ||
stdin, | ||
stdout, | ||
store | ||
}); | ||
it('Should call showHelp on a help response', () => { | ||
let page = createPage(), | ||
stream = new MockStdout(), | ||
spy = expect.spyOn(page, 'showHelp'); | ||
page.prompt() | ||
.catch((e) => { | ||
expect(e).toExist(); | ||
expect(stdout.toString()).toBe('\x1b[34m\x1b[1mWhat do you seek?\x1b[22m\x1b[39m\x1b[35m\x1b[1m > \x1b[22m\x1b[39m\x1b[31m\x1b[1mHuh (-1)?\n\x1b[22m\x1b[39m\x1b[37m\x1b[1m*** COMMANDS ***\x1b[22m\x1b[39m\n 1: \x1b[35m\x1b[1md\x1b[22m\x1b[39mirectories 2: \x1b[35m\x1b[1mf\x1b[22m\x1b[39miles 3: \x1b[35m\x1b[1mg\x1b[22m\x1b[39mlob 4: \x1b[35m\x1b[1mc\x1b[22m\x1b[39mhanged \n 5: \x1b[35m\x1b[1mh\x1b[22m\x1b[39melp 6: \x1b[35m\x1b[1mq\x1b[22m\x1b[39muit \n\x1b[34m\x1b[1mWhat do you seek?\x1b[22m\x1b[39m\x1b[35m\x1b[1m > \x1b[22m\x1b[39m'); | ||
stdin.pause(); | ||
}) | ||
.then(done, done); | ||
page.route(stream, { | ||
type: 'navigate', | ||
data: 'help', | ||
}); | ||
stdin.emit('readable'); | ||
expect(spy).toHaveBeenCalled(); | ||
}); | ||
it('Should navigate to the files page with 2', (done) => { | ||
let stdin = new MockStdin(['2']), | ||
store = StoreFactory.create(), | ||
page = new IndexPage({ | ||
stdin, | ||
stdout, | ||
store | ||
}); | ||
it('Should call navigate on a general navigate response', () => { | ||
let page = createPage(), | ||
stream = new MockStdout(), | ||
spy = expect.spyOn(page, 'navigate'); | ||
page.prompt() | ||
.then((results) => { | ||
expect(results).toExist(); | ||
expect(results.selectedItems).toBeA(Array); | ||
expect(results.selectedItems[0].value).toBe('files'); | ||
expect(store.select('currentPage.name')).toBe('files'); | ||
}) | ||
.then(done, done); | ||
page.route(stream, { | ||
type: 'navigate', | ||
data: 'files', | ||
}); | ||
stdin.emit('readable'); | ||
expect(spy).toHaveBeenCalled(); | ||
expect(spy).toHaveBeenCalledWith('files'); | ||
}); | ||
it('Should navigate to the files page with f', (done) => { | ||
let stdin = new MockStdin(['f']), | ||
store = StoreFactory.create(), | ||
page = new IndexPage({ | ||
stdin, | ||
stdout, | ||
store | ||
}); | ||
it('Should reprompt when stream is done', () => { | ||
let page = createPage(), | ||
stream = new MockStdout(), | ||
spy = expect.spyOn(page, 'reprompt'); | ||
page.prompt() | ||
.then((results) => { | ||
expect(results).toExist(); | ||
expect(results.selectedItems).toBeA(Array); | ||
expect(results.selectedItems[0].value).toBe('files'); | ||
expect(store.select('currentPage.name')).toBe('files'); | ||
}) | ||
.then(done, done); | ||
page.route(stream, { | ||
type: 'done', | ||
data: null, | ||
}); | ||
stdin.emit('readable'); | ||
expect(spy).toHaveBeenCalled(); | ||
}); | ||
it('Should show help content', (done) => { | ||
let stdin = new MockStdin(['help']), | ||
store = StoreFactory.create(), | ||
page = new IndexPage({ | ||
stdin, | ||
stdout, | ||
store | ||
}); | ||
it('Should show an error message on error response', () => { | ||
let page = createPage(), | ||
stream = new MockStdout(), | ||
spy = expect.spyOn(page, 'displayError'); | ||
page.prompt() | ||
.then((results) => { | ||
expect(results).toExist(); | ||
expect(results.selectedItems).toBeA(Array); | ||
expect(results.selectedItems[0].value).toBe('help'); | ||
expect(stdout.toString()).toInclude('HELP'); | ||
}) | ||
.then(done, done); | ||
page.route(stream, { | ||
type: 'error', | ||
data: 'Error message', | ||
}); | ||
stdin.emit('readable'); | ||
expect(spy).toHaveBeenCalled(); | ||
expect(spy).toHaveBeenCalledWith('Error message'); | ||
}); | ||
}); | ||
it('Should exit on quit', (done) => { | ||
let stdin = new MockStdin(['q']), | ||
store = StoreFactory.create(), | ||
page = new IndexPage({ | ||
stdin, | ||
stdout, | ||
store | ||
}), | ||
spy = expect.spyOn(page, 'quit').andCallThrough(); | ||
describe('#showHelp()', () => { | ||
it('Should write out a help message to stdout', () => { | ||
let page = createPage(); | ||
page.prompt() | ||
.then((results) => { | ||
expect(results).toExist(); | ||
expect(results.selectedItems).toBeA(Array); | ||
expect(results.selectedItems[0].value).toBe('quit'); | ||
expect(spy).toHaveBeenCalled(); | ||
}) | ||
.then(done, done); | ||
page.showHelp(); | ||
stdin.emit('readable'); | ||
expect(page.props.stdout.toString()).toBe('\x1b[1m\x1b[31mHELP\n directories - Select files & browse directories\n files - Select from a list of all nested files\n glob - Input a glob string then selected from matches\n changed - Select files from git diff --name-only\n help - Uhhh... this thing I guess...\n quit - Forward files along\n\x1b[39m\x1b[22m'); | ||
}); | ||
}); | ||
it('Should catch an error on *', (done) => { | ||
let stdin = new MockStdin(['*']), | ||
store = StoreFactory.create(), | ||
page = new IndexPage({ | ||
stdin, | ||
stdout, | ||
store | ||
}); | ||
describe('#showPrompt()', () => { | ||
it('Should display the prompt', () => { | ||
let page = createPage('quit'); | ||
page.prompt() | ||
.catch((e) => { | ||
expect(e).toExist(); | ||
expect(stdout.toString()).toInclude('Huh (*)?'); | ||
}) | ||
.then(done, done); | ||
page.showPrompt() | ||
.on('finish', () => { | ||
expect(page.props.stdout.toString()).toBe('\x1b[34m\x1b[1mWhat do you seek?\x1b[22m\x1b[39m\x1b[35m\x1b[1m > \x1b[22m\x1b[39m'); | ||
}); | ||
}); | ||
}); | ||
stdin.emit('readable'); | ||
describe('#workflow()', () => { | ||
it('Should return a workflow object', () => { | ||
let page = createPage(), | ||
workflow = page.workflow(); | ||
expect(workflow.query).toExist(); | ||
expect(workflow.menu).toExist(); | ||
expect(workflow.dispatch).toExist(); | ||
}); | ||
}); | ||
describe('#renderIntro()', () => { | ||
it('Should display intro text', () => { | ||
let page = createPage(); | ||
expect(page.renderIntro()).toBe('\x1b[37m\x1b[1m*** COMMANDS ***\x1b[22m\x1b[39m\n'); | ||
}); | ||
it('Should dispaly files if present', () => { | ||
let page = createPage(); | ||
page.props.store.dispatch({ type: 'ADD_FILE', file: __filename }); | ||
expect(page.renderIntro()).toBe('\n1: test/index_page.js\n\n\x1b[37m\x1b[1m*** COMMANDS ***\x1b[22m\x1b[39m\n'); | ||
}); | ||
}); | ||
describe('#renderPrompt()', () => { | ||
it('Should return showPrompt method', () => { | ||
let page = createPage(); | ||
expect(page.renderPrompt()).toBe(page.showPrompt); | ||
}); | ||
}); | ||
describe('#renderMenu()', () => { | ||
it('Should render the menu', () => { | ||
let page = createPage(); | ||
expect(page.renderMenu()).toBe(' 1: \x1b[35m\x1b[1md\x1b[22m\x1b[39mirectories 2: \x1b[35m\x1b[1mf\x1b[22m\x1b[39miles 3: \x1b[35m\x1b[1mg\x1b[22m\x1b[39mlob 4: \x1b[35m\x1b[1mc\x1b[22m\x1b[39mhanged \n 5: \x1b[35m\x1b[1mh\x1b[22m\x1b[39melp 6: \x1b[35m\x1b[1mq\x1b[22m\x1b[39muit \n'); | ||
}); | ||
}); | ||
describe('#render()', () => { | ||
it('Should render the intro, menu, and prompt', () => { | ||
let page = createPage(), | ||
output; | ||
IndexPage.mount(page); | ||
output = page.props.stdout.toString(); | ||
expect(output).toBe('\x1b[37m\x1b[1m*** COMMANDS ***\x1b[22m\x1b[39m\n 1: \x1b[35m\x1b[1md\x1b[22m\x1b[39mirectories 2: \x1b[35m\x1b[1mf\x1b[22m\x1b[39miles 3: \x1b[35m\x1b[1mg\x1b[22m\x1b[39mlob 4: \x1b[35m\x1b[1mc\x1b[22m\x1b[39mhanged \n 5: \x1b[35m\x1b[1mh\x1b[22m\x1b[39melp 6: \x1b[35m\x1b[1mq\x1b[22m\x1b[39muit \n\x1b[34m\x1b[1mWhat do you seek?\x1b[22m\x1b[39m\x1b[35m\x1b[1m > \x1b[22m\x1b[39m'); | ||
}); | ||
}); | ||
}); | ||
@@ -46,2 +46,9 @@ // import { Readable } from 'stream'; | ||
reset () { | ||
let state = this._readableState; | ||
state.ended = false; | ||
state.endEmitted = false; | ||
} | ||
_read () { | ||
@@ -55,2 +62,6 @@ if (this.cursor >= this.contents.length) { | ||
this.push(null); | ||
process.nextTick(() => { | ||
this.reset(); | ||
}); | ||
} | ||
@@ -57,0 +68,0 @@ } |
176
test/menu.js
@@ -24,5 +24,18 @@ import Promise from 'bluebird'; | ||
value: 'glob' | ||
}, | ||
{ | ||
id: 4, | ||
label: 'glib', | ||
name: 'glib', | ||
value: 'glib' | ||
} | ||
]; | ||
/** | ||
* @returns {Menu} Returns a new menu instance with test options | ||
*/ | ||
function createMenu () { | ||
return new Menu({ options: MENU_OPTIONS }); | ||
} | ||
describe('Menu', () => { | ||
@@ -39,3 +52,3 @@ describe('#constructor()', () => { | ||
it('Should have the given props', () => { | ||
let menu = new Menu({ options: MENU_OPTIONS }); | ||
let menu = createMenu(); | ||
@@ -49,95 +62,116 @@ expect(menu).toExist(); | ||
describe('#find()', () => { | ||
it('Should return a promise', () => { | ||
let menu = new Menu({ | ||
options: MENU_OPTIONS | ||
}), | ||
result; | ||
describe('#filter()', () => { | ||
it('Should filter menu options', () => { | ||
let menu = createMenu(), | ||
results = menu.filter((item) => item.id === 1, this); | ||
result = menu.find('1'); | ||
expect(results.length).toBe(1); | ||
expect(results[0].value).toBe('directories'); | ||
}); | ||
}); | ||
expect(result).toBeA(Promise); | ||
describe('#getChoiceById()', () => { | ||
it('Should return an option with valid id', () => { | ||
let menu = createMenu(), | ||
result = menu.getChoiceById(1); | ||
expect(result).toBe(MENU_OPTIONS[0]); | ||
}); | ||
it('Should find the menu options', (done) => { | ||
let menu = new Menu({ | ||
options: MENU_OPTIONS | ||
}); | ||
it('Should throw an error with invalid id', () => { | ||
let menu = createMenu(); | ||
menu.find('1') | ||
.then((result) => { | ||
expect(result).toBeA(Object); | ||
expect(result.selectedItems).toBeA(Array); | ||
expect(result.selectedItems.length).toBe(1); | ||
expect(result.selectedItems[0].id).toBe(1); | ||
expect(result.selectedItems[0].action).toBe('select'); | ||
expect(result.selectedItems[0].value).toBe('directories'); | ||
}) | ||
.then(done, done); | ||
expect(() => { | ||
menu.getChoiceById(5); | ||
}).toThrow(Error); | ||
}); | ||
}); | ||
it('Should find no menu items ', (done) => { | ||
let menu = new Menu({ | ||
options: MENU_OPTIONS, | ||
stdout: new MockStdout() | ||
}); | ||
describe('#getIdByName()', () => { | ||
it('Should return an array with matching value', () => { | ||
let menu = createMenu(); | ||
menu.find('=1') | ||
.catch(() => { | ||
done(); | ||
}); | ||
expect(menu.getIdByName('files')).toEqual([2]); | ||
}); | ||
it('Should allow * to find all items if acceptMany is on', () => { | ||
let menu = new Menu({ | ||
options: MENU_OPTIONS, | ||
acceptsMany: true | ||
}); | ||
it('Should return an empty array if name matches more than 1 option', () => { | ||
let menu = createMenu(); | ||
menu.find('*') | ||
.then((result) => { | ||
let selectedItems = result.selectedItems; | ||
expect(menu.getIdByName('gl')).toEqual([]); | ||
}); | ||
}); | ||
expect(selectedItems).toBeA(Array); | ||
expect(selectedItems.length).toBe(3); | ||
expect(selectedItems.every((item) => item.action === 'add')); | ||
}); | ||
describe('#hasId()', () => { | ||
it('Should return true when id is present', () => { | ||
let menu = createMenu(); | ||
expect(menu.hasId('3')).toBe(true); | ||
}); | ||
it('Should allow * to find all items if acceptMany is on to subtract', () => { | ||
let menu = new Menu({ | ||
options: MENU_OPTIONS, | ||
acceptsMany: true, | ||
stdout: new MockStdout() | ||
}); | ||
it('Should return false when id is not present', () => { | ||
let menu = createMenu(); | ||
menu.find('-*') | ||
.then((result) => { | ||
let selectedItems = result.selectedItems; | ||
expect(menu.hasId('5')).toBe(false); | ||
}); | ||
}); | ||
expect(selectedItems).toBeA(Array); | ||
expect(selectedItems.length).toBe(3); | ||
expect(selectedItems.every((item) => item.action === 'remove')); | ||
}); | ||
describe('#ids()', () => { | ||
it('Should be a list of menu option ids', () => { | ||
let menu = createMenu(); | ||
expect(menu.ids()).toEqual([1, 2, 3, 4]); | ||
}); | ||
}); | ||
it('Should allow a range', () => { | ||
let menu = new Menu({ | ||
options: MENU_OPTIONS, | ||
acceptsMany: true, | ||
stdout: new MockStdout() | ||
}); | ||
describe('#map()', () => { | ||
it('Should map all options', () => { | ||
let menu = createMenu(); | ||
menu.find('1-3') | ||
.then((result) => { | ||
let selectedItems = result.selectedItems; | ||
expect(menu.map((item) => item.id)).toEqual([1, 2, 3, 4]); | ||
}); | ||
}); | ||
expect(selectedItems).toBeA(Array); | ||
expect(selectedItems.length).toBe(3); | ||
}); | ||
describe('#options()', () => { | ||
it('Should return the list of options', () => { | ||
let menu = createMenu(); | ||
expect(menu.options()).toBe(MENU_OPTIONS); | ||
}); | ||
}); | ||
describe('#setOptions()', () => { | ||
it('Should update options', () => { | ||
let menu = new Menu(); | ||
expect(menu.options()).toEqual([]); | ||
menu.setOptions(MENU_OPTIONS); | ||
expect(menu.options()).toEqual(MENU_OPTIONS); | ||
}); | ||
}); | ||
describe('#renderLabel', () => { | ||
it('Should format a label with the first letter highlighted', () => { | ||
let menu = new Menu(); | ||
expect(menu.renderLabel('test')).toBe('\x1b[35m\x1b[1mt\x1b[22m\x1b[39mest'); | ||
}); | ||
}); | ||
describe('#renderOption()', () => { | ||
it('Should format a label with a number', () => { | ||
let menu = createMenu(); | ||
expect(menu.renderOption(MENU_OPTIONS[0])).toBe(' 1: \x1b[35m\x1b[1md\x1b[22m\x1b[39mirectories '); | ||
}); | ||
}); | ||
describe('#render()', () => { | ||
it('Should render all the options', () => { | ||
let menu = createMenu(); | ||
expect(menu.render()).toBe(' 1: \x1b[35m\x1b[1md\x1b[22m\x1b[39mirectories 2: \x1b[35m\x1b[1mf\x1b[22m\x1b[39miles 3: \x1b[35m\x1b[1mg\x1b[22m\x1b[39mlob 4: \x1b[35m\x1b[1mg\x1b[22m\x1b[39mlib \n'); | ||
}); | ||
}); | ||
}); |
import expect from 'expect'; | ||
import { colors } from 'gulp-util'; | ||
import { Readable } from 'stream'; | ||
@@ -13,3 +14,3 @@ import Prompt from '../src/prompt'; | ||
'formatPrompt', | ||
'formatText' | ||
'formatText', | ||
], | ||
@@ -66,3 +67,3 @@ PROMPT_TEXT = 'Is this working'; | ||
describe('#beckon()', () => { | ||
it('Should prompt the user for input', (done) => { | ||
it('Should prompt the user for input', () => { | ||
let stdin = new MockStdin(['Test string']), | ||
@@ -72,61 +73,8 @@ stdout = new MockStdout(), | ||
stdout, | ||
stdin | ||
stdin, | ||
}); | ||
prompt.beckon() | ||
.then((answer) => { | ||
expect(answer).toBe('Test string'); | ||
stdout.write(answer); | ||
expect(stdout.output).toBe('\x1b[34m\x1b[1mIs this working\x1b[22m\x1b[39m\x1b[35m\x1b[1m > \x1b[22m\x1b[39mTest string'); | ||
}, (e) => { | ||
throw e; | ||
}) | ||
.then(done, done); | ||
stdin.emit('readable'); | ||
expect(prompt.beckon()).toBeA(Readable); | ||
}); | ||
it('Should accept an empty response', (done) => { | ||
let stdin = new MockStdin(['']), | ||
stdout = new MockStdout(), | ||
prompt = new Prompt(PROMPT_TEXT, { | ||
stdout, | ||
stdin | ||
}); | ||
prompt.beckon() | ||
.then((answer) => { | ||
expect(answer).toNotExist(); | ||
stdout.write(answer); | ||
expect(stdout.output).toBe('\x1b[34m\x1b[1mIs this working\x1b[22m\x1b[39m\x1b[35m\x1b[1m > \x1b[22m\x1b[39m'); | ||
}, (e) => { | ||
throw e; | ||
}) | ||
.then(done, done); | ||
stdin.emit('readable'); | ||
}); | ||
it('Should fail when input stream is closed', (done) => { | ||
let stdin = new MockStdin(['']), | ||
stdout = new MockStdout(), | ||
prompt = new Prompt(PROMPT_TEXT, { | ||
stdout, | ||
stdin | ||
}); | ||
prompt.beckon() | ||
.catch((err) => { | ||
expect(err).toBe('Input stream closed.'); | ||
}) | ||
.then(done, done); | ||
stdin.emit('readable'); | ||
stdin.end(); | ||
}); | ||
}); | ||
}); | ||
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
408107
104
7144
14
3
21
11
+ Addedcore-util-is@1.0.3(transitive)
+ Addedisarray@1.0.0(transitive)
+ Addedlabeled-stream-splicer@2.0.2(transitive)
+ Addedprocess-nextick-args@2.0.1(transitive)
+ Addedreadable-stream@2.3.8(transitive)
+ Addedsafe-buffer@5.1.2(transitive)
+ Addedstream-splicer@2.0.1(transitive)
+ Addedstring_decoder@1.1.1(transitive)
+ Addedutil-deprecate@1.0.2(transitive)