From 474274c71f4b8b27da38dc84a06a16f70def2909 Mon Sep 17 00:00:00 2001 From: Camel Aissani Date: Thu, 8 Sep 2016 23:19:07 +0200 Subject: [PATCH] exposed frontexpress in the browser global context #2 --- .babelrc | 3 ++- .npmignore | 1 + frontexpress.min.js | 2 +- index.js | 1 + package.json | 3 +++ webpack.config.js => webpack.config.babel.js | 14 ++++++-------- 6 files changed, 14 insertions(+), 10 deletions(-) create mode 100644 index.js rename webpack.config.js => webpack.config.babel.js (60%) diff --git a/.babelrc b/.babelrc index c730c21..48ec9bb 100755 --- a/.babelrc +++ b/.babelrc @@ -1,3 +1,4 @@ { - "presets": ["es2015"] + "presets": ["es2015"], + "plugins": ["add-module-exports"] } diff --git a/.npmignore b/.npmignore index 75320ea..5150ae1 100644 --- a/.npmignore +++ b/.npmignore @@ -1,3 +1,4 @@ +index.js frontexpress.min.js test coverage \ No newline at end of file diff --git a/frontexpress.min.js b/frontexpress.min.js index bf19b6a..2f9ea80 100644 --- a/frontexpress.min.js +++ b/frontexpress.min.js @@ -1 +1 @@ -!function(modules){function __webpack_require__(moduleId){if(installedModules[moduleId])return installedModules[moduleId].exports;var module=installedModules[moduleId]={exports:{},id:moduleId,loaded:!1};return modules[moduleId].call(module.exports,module,module.exports,__webpack_require__),module.loaded=!0,module.exports}var installedModules={};return __webpack_require__.m=modules,__webpack_require__.c=installedModules,__webpack_require__.p="",__webpack_require__(0)}([function(module,exports,__webpack_require__){"use strict";function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{"default":obj}}Object.defineProperty(exports,"__esModule",{value:!0});var _application=__webpack_require__(4),_application2=_interopRequireDefault(_application),_router=__webpack_require__(3),_router2=_interopRequireDefault(_router),_middleware=__webpack_require__(1),_middleware2=_interopRequireDefault(_middleware),frontexpress=function(){return new _application2["default"]};frontexpress.Router=function(baseUri){return new _router2["default"](baseUri)},frontexpress.Middleware=function(name){return new _middleware2["default"](name)},exports["default"]=frontexpress},function(module,exports){"use strict";function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(exports,"__esModule",{value:!0});var _createClass=function(){function defineProperties(target,props){for(var i=0;i=0&&(uriToCheck=uriToCheck.slice(0,questionMarkIndex));var hashIndex=uriToCheck.indexOf("#");return hashIndex>=0&&(uriToCheck=uriToCheck.slice(0,hashIndex)),route.uri instanceof RegExp?uriToCheck.match(route.uri):route.uri===uriToCheck})}},{key:"visited",value:function(){return this._routes.filter(function(route){return route.visited})}},{key:"use",value:function(middleware){if(!(middleware instanceof _middleware2["default"])&&"function"!=typeof middleware)throw new TypeError("use method takes at least a middleware");return this._add(new Route(this,(void 0),(void 0),middleware)),this}},{key:"all",value:function(){for(var _len=arguments.length,args=Array(_len),_key=0;_key<_len;_key++)args[_key]=arguments[_key];if(0===args.length)throw new TypeError("use all method takes at least a middleware");var middleware=void 0;if(middleware=1===args.length?args[0]:args[1],!(middleware instanceof _middleware2["default"])&&"function"!=typeof middleware)throw new TypeError("use all method takes at least a middleware");var _iteratorNormalCompletion=!0,_didIteratorError=!1,_iteratorError=void 0;try{for(var _step,_iterator=_methods2["default"][Symbol.iterator]();!(_iteratorNormalCompletion=(_step=_iterator.next()).done);_iteratorNormalCompletion=!0){var method=_step.value;this[method.toLowerCase()].apply(this,args)}}catch(err){_didIteratorError=!0,_iteratorError=err}finally{try{!_iteratorNormalCompletion&&_iterator["return"]&&_iterator["return"]()}finally{if(_didIteratorError)throw _iteratorError}}return this}},{key:"baseUri",set:function(uri){if(uri){if(!this._baseUri)return void(this._baseUri=uri);if(this._baseUri instanceof RegExp)throw new TypeError("the router already contains a regexp uri "+this._baseUri.toString()+" It cannot be mixed with "+uri.toString());if(uri instanceof RegExp)throw new TypeError("the router already contains an uri "+this._baseUri.toString()+" It cannot be mixed with regexp "+uri.toString())}},get:function(){return this._baseUri}}]),Router}();exports["default"]=Router;var _iteratorNormalCompletion2=!0,_didIteratorError2=!1,_iteratorError2=void 0;try{for(var _step2,_loop=function(){var method=_step2.value,methodName=method.toLowerCase();Router.prototype[methodName]=function(){for(var _len2=arguments.length,args=Array(_len2),_key2=0;_key2<_len2;_key2++)args[_key2]=arguments[_key2];if(0===args.length)throw new TypeError("use "+methodName+" method takes at least a middleware");var uri=void 0,middleware=void 0;if(1===args.length?middleware=args[0]:(uri=args[0],middleware=args[1]),!(middleware instanceof _middleware2["default"])&&"function"!=typeof middleware)throw new TypeError("use "+methodName+" method takes at least a middleware");if(uri&&this._baseUri&&this._baseUri instanceof RegExp)throw new TypeError("router contains a regexp cannot mix with route uri/regexp");return this._add(new Route(this,uri,method,middleware)),this}},_iterator2=_methods2["default"][Symbol.iterator]();!(_iteratorNormalCompletion2=(_step2=_iterator2.next()).done);_iteratorNormalCompletion2=!0)_loop()}catch(err){_didIteratorError2=!0,_iteratorError2=err}finally{try{!_iteratorNormalCompletion2&&_iterator2["return"]&&_iterator2["return"]()}finally{if(_didIteratorError2)throw _iteratorError2}}},function(module,exports,__webpack_require__){"use strict";function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{"default":obj}}function _toConsumableArray(arr){if(Array.isArray(arr)){for(var i=0,arr2=Array(arr.length);i=1&&(uriWithoutAnchor=_uri.slice(0,hashIndex),anchor=_uri.slice(hashIndex,_uri.length)),uriWithoutAnchor=Object.keys(data).reduce(function(gUri,d,index){return gUri+=0===index&&gUri.indexOf("?")===-1?"?":"&",gUri+=d+"="+data[d]},uriWithoutAnchor),uriWithoutAnchor+anchor},data:function(_ref2){_ref2.uri,_ref2.headers,_ref2.data}}},this.rules={"http requester":function(requester){if("function"!=typeof requester.fetch)throw new TypeError("setting http requester has no fetch method")}}}return _createClass(Settings,[{key:"set",value:function(name,value){var checkRules=this.rules[name];checkRules&&checkRules(value),this.settings[name]=value}},{key:"get",value:function(name){return this.settings[name]}}]),Settings}();exports["default"]=Settings}]); \ No newline at end of file +!function(modules){function __webpack_require__(moduleId){if(installedModules[moduleId])return installedModules[moduleId].exports;var module=installedModules[moduleId]={exports:{},id:moduleId,loaded:!1};return modules[moduleId].call(module.exports,module,module.exports,__webpack_require__),module.loaded=!0,module.exports}var installedModules={};return __webpack_require__.m=modules,__webpack_require__.c=installedModules,__webpack_require__.p="",__webpack_require__(0)}([function(module,exports,__webpack_require__){"use strict";function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{"default":obj}}var _frontexpress=__webpack_require__(8);_interopRequireDefault(_frontexpress)},function(module,exports){"use strict";function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(exports,"__esModule",{value:!0});var _createClass=function(){function defineProperties(target,props){for(var i=0;i=0&&(uriToCheck=uriToCheck.slice(0,questionMarkIndex));var hashIndex=uriToCheck.indexOf("#");return hashIndex>=0&&(uriToCheck=uriToCheck.slice(0,hashIndex)),route.uri instanceof RegExp?uriToCheck.match(route.uri):route.uri===uriToCheck})}},{key:"visited",value:function(){return this._routes.filter(function(route){return route.visited})}},{key:"use",value:function(middleware){if(!(middleware instanceof _middleware2["default"])&&"function"!=typeof middleware)throw new TypeError("use method takes at least a middleware");return this._add(new Route(this,(void 0),(void 0),middleware)),this}},{key:"all",value:function(){for(var _len=arguments.length,args=Array(_len),_key=0;_key<_len;_key++)args[_key]=arguments[_key];if(0===args.length)throw new TypeError("use all method takes at least a middleware");var middleware=void 0;if(middleware=1===args.length?args[0]:args[1],!(middleware instanceof _middleware2["default"])&&"function"!=typeof middleware)throw new TypeError("use all method takes at least a middleware");var _iteratorNormalCompletion=!0,_didIteratorError=!1,_iteratorError=void 0;try{for(var _step,_iterator=_methods2["default"][Symbol.iterator]();!(_iteratorNormalCompletion=(_step=_iterator.next()).done);_iteratorNormalCompletion=!0){var method=_step.value;this[method.toLowerCase()].apply(this,args)}}catch(err){_didIteratorError=!0,_iteratorError=err}finally{try{!_iteratorNormalCompletion&&_iterator["return"]&&_iterator["return"]()}finally{if(_didIteratorError)throw _iteratorError}}return this}},{key:"baseUri",set:function(uri){if(uri){if(!this._baseUri)return void(this._baseUri=uri);if(this._baseUri instanceof RegExp)throw new TypeError("the router already contains a regexp uri "+this._baseUri.toString()+" It cannot be mixed with "+uri.toString());if(uri instanceof RegExp)throw new TypeError("the router already contains an uri "+this._baseUri.toString()+" It cannot be mixed with regexp "+uri.toString())}},get:function(){return this._baseUri}}]),Router}();exports["default"]=Router;var _iteratorNormalCompletion2=!0,_didIteratorError2=!1,_iteratorError2=void 0;try{for(var _step2,_loop=function(){var method=_step2.value,methodName=method.toLowerCase();Router.prototype[methodName]=function(){for(var _len2=arguments.length,args=Array(_len2),_key2=0;_key2<_len2;_key2++)args[_key2]=arguments[_key2];if(0===args.length)throw new TypeError("use "+methodName+" method takes at least a middleware");var uri=void 0,middleware=void 0;if(1===args.length?middleware=args[0]:(uri=args[0],middleware=args[1]),!(middleware instanceof _middleware2["default"])&&"function"!=typeof middleware)throw new TypeError("use "+methodName+" method takes at least a middleware");if(uri&&this._baseUri&&this._baseUri instanceof RegExp)throw new TypeError("router contains a regexp cannot mix with route uri/regexp");return this._add(new Route(this,uri,method,middleware)),this}},_iterator2=_methods2["default"][Symbol.iterator]();!(_iteratorNormalCompletion2=(_step2=_iterator2.next()).done);_iteratorNormalCompletion2=!0)_loop()}catch(err){_didIteratorError2=!0,_iteratorError2=err}finally{try{!_iteratorNormalCompletion2&&_iterator2["return"]&&_iterator2["return"]()}finally{if(_didIteratorError2)throw _iteratorError2}}module.exports=exports["default"]},function(module,exports,__webpack_require__){"use strict";function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{"default":obj}}function _toConsumableArray(arr){if(Array.isArray(arr)){for(var i=0,arr2=Array(arr.length);i=1&&(uriWithoutAnchor=_uri.slice(0,hashIndex),anchor=_uri.slice(hashIndex,_uri.length)),uriWithoutAnchor=Object.keys(data).reduce(function(gUri,d,index){return gUri+=0===index&&gUri.indexOf("?")===-1?"?":"&",gUri+=d+"="+data[d]},uriWithoutAnchor),uriWithoutAnchor+anchor},data:function(_ref2){_ref2.uri,_ref2.headers,_ref2.data}}},this.rules={"http requester":function(requester){if("function"!=typeof requester.fetch)throw new TypeError("setting http requester has no fetch method")}}}return _createClass(Settings,[{key:"set",value:function(name,value){var checkRules=this.rules[name];checkRules&&checkRules(value),this.settings[name]=value}},{key:"get",value:function(name){return this.settings[name]}}]),Settings}();exports["default"]=Settings,module.exports=exports["default"]},function(module,exports,__webpack_require__){(function(global){module.exports=global.frontexpress=__webpack_require__(5)}).call(exports,function(){return this}())}]); \ No newline at end of file diff --git a/index.js b/index.js new file mode 100644 index 0000000..f88a75f --- /dev/null +++ b/index.js @@ -0,0 +1 @@ +import frontexpress from 'expose?frontexpress!./lib/frontexpress.js'; \ No newline at end of file diff --git a/package.json b/package.json index 6b92e31..e8076c4 100644 --- a/package.json +++ b/package.json @@ -32,10 +32,13 @@ "babel-eslint": "^6.1.2", "babel-istanbul": "^0.11.0", "babel-loader": "^6.2.4", + "babel-plugin-add-module-exports": "^0.2.1", "babel-preset-es2015": "^6.9.0", + "babel-register": "^6.14.0", "chai": "^3.5.0", "eslint": "^3.1.0", "eslint-loader": "^1.4.1", + "expose-loader": "^0.7.1", "istanbul": "^0.4.4", "mocha": "^2.5.3", "rimraf": "^2.5.3", diff --git a/webpack.config.js b/webpack.config.babel.js similarity index 60% rename from webpack.config.js rename to webpack.config.babel.js index eef7746..2fb3e5e 100644 --- a/webpack.config.js +++ b/webpack.config.babel.js @@ -1,15 +1,15 @@ -var webpack = require('webpack'); -var path = require('path'); +import webpack from 'webpack'; +import path from 'path'; -var frontend = { - entry: path.join(__dirname, 'lib','frontexpress.js'), +export default { + entry: path.join(__dirname, 'index.js'), output: { path: __dirname, filename: 'frontexpress.min.js' }, module: { loaders: [ - { test: /\.js/, loader: 'babel-loader' }, + { test: /\.js/, loader: 'babel-loader' } ] }, plugins: [ @@ -17,6 +17,4 @@ var frontend = { new webpack.optimize.OccurenceOrderPlugin(), new webpack.optimize.UglifyJsPlugin({ mangle: false, sourcemap: false }), ], -}; - -module.exports = [frontend]; \ No newline at end of file +}; \ No newline at end of file