Skip to content

Commit

Permalink
misc: update structure & template render info
Browse files Browse the repository at this point in the history
  • Loading branch information
elcarim5efil committed Mar 9, 2017
1 parent e8c5148 commit 53af0d8
Show file tree
Hide file tree
Showing 54 changed files with 1,749 additions and 664 deletions.
34 changes: 12 additions & 22 deletions lib/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ var _koaOnerror = require('koa-onerror');

var _koaOnerror2 = _interopRequireDefault(_koaOnerror);

var _koaBodyparser = require('koa-bodyparser');

var _koaBodyparser2 = _interopRequireDefault(_koaBodyparser);

var _koaLogger = require('koa-logger');

var _koaLogger2 = _interopRequireDefault(_koaLogger);
Expand All @@ -29,27 +33,19 @@ var _path = require('path');

var _path2 = _interopRequireDefault(_path);

var _mock = require('./mock');

var _mock2 = _interopRequireDefault(_mock);
var _router = require('./router');

var _index_page = require('./router/index_page');

var _index_page2 = _interopRequireDefault(_index_page);
var _router2 = _interopRequireDefault(_router);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; }

var bodyparser = (0, _koaBodyparser2.default)();
var app = new _koa2.default();
var router = require('koa-router')();

var bodyparser = require('koa-bodyparser')();

var __root = fozy.__root;
var config = require(_path2.default.join(__root, 'fozy.config'));
var config = fozy.__config;

// middlewares
if (!config.mock.proxy) {
app.use((0, _koaConvert2.default)(bodyparser));
}
Expand All @@ -65,7 +61,9 @@ if (global.fozy.__dev.watch) {

// static files
config.resource.forEach(function (item) {
app.use((0, _koaConvert2.default)(require('koa-static')(_path2.default.join(__root, item))));
var staticFilePath = _path2.default.join(__root, item);
var staticRoute = (0, _koaConvert2.default)(require('koa-static')(staticFilePath));
app.use(staticRoute);
});

// logger
Expand Down Expand Up @@ -98,15 +96,7 @@ app.use(function () {
};
}());

// pages index
router.get('/fozy/index', _index_page2.default);

// route to mock server
router.use('/', _mock2.default.routes(), _mock2.default.allowedMethods());

// router.get('*', indexPage);

app.use(router.routes(), router.allowedMethods());
app.use(_router2.default.routes(), _router2.default.allowedMethods());

app.on('error', function (err, ctx) {
console.log(err);
Expand Down
5 changes: 4 additions & 1 deletion lib/engine/freemarker.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ module.exports = function (option) {
if (err) {
reject(err);
} else {
resolve(html);
resolve({
html: html,
output: output
});
}
});
}));
Expand Down
20 changes: 20 additions & 0 deletions lib/mock/async_mock/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

'use strict';

Object.defineProperty(exports, "__esModule", {
value: true
});
exports.Local = exports.Proxy = undefined;

var _proxy = require('./proxy');

var _proxy2 = _interopRequireDefault(_proxy);

var _local = require('./local');

var _local2 = _interopRequireDefault(_local);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

exports.Proxy = _proxy2.default;
exports.Local = _local2.default;
63 changes: 63 additions & 0 deletions lib/mock/async_mock/local/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@

'use strict';

Object.defineProperty(exports, "__esModule", {
value: true
});

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

var _data = require('../../data');

function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var LocalMock = function () {
function LocalMock() {
_classCallCheck(this, LocalMock);
}

_createClass(LocalMock, [{
key: 'getMocker',
value: function getMocker() {
var _this = this;

var mock = function () {
var _ref = _asyncToGenerator(regeneratorRuntime.mark(function _callee(ctx, next) {
return regeneratorRuntime.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
_context.prev = 0;

ctx.body = new _data.AsyncData(ctx).getData();
ctx.type = 'json';
_context.next = 8;
break;

case 5:
_context.prev = 5;
_context.t0 = _context['catch'](0);
return _context.abrupt('return', next());

case 8:
case 'end':
return _context.stop();
}
}
}, _callee, _this, [[0, 5]]);
}));

return function mock(_x, _x2) {
return _ref.apply(this, arguments);
};
}();
return mock;
}
}]);

return LocalMock;
}();

exports.default = LocalMock;
48 changes: 48 additions & 0 deletions lib/mock/async_mock/proxy/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@

'use strict';

Object.defineProperty(exports, "__esModule", {
value: true
});

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

var _proxy = require('./proxy');

var _proxy2 = _interopRequireDefault(_proxy);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var _class = function () {
function _class() {
_classCallCheck(this, _class);

this.config = fozy.__config.mock.proxy;
this.headers = {
'accept-encoding': 'gzip;q=0,deflate,sdch,br'
};
}

_createClass(_class, [{
key: 'getMocker',
value: function getMocker() {
var config = this.config;

var option = {
target: config.target,
headers: this.headers
};

if (config.host) {
option.host = config.host;
}
return (0, _proxy2.default)(option);
}
}]);

return _class;
}();

exports.default = _class;
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@ var _path = require('path');

var _path2 = _interopRequireDefault(_path);

var _extend = require('../../../util/extend');
var _extend = require('../../util/extend');

var _extend2 = _interopRequireDefault(_extend);

var _querystring = require('querystring');

var _querystring2 = _interopRequireDefault(_querystring);

var _jsonProcessor = require('../../../util/json.processor.js');
var _jsonProcessor = require('../../util/json.processor.js');

var _jsonProcessor2 = _interopRequireDefault(_jsonProcessor);

var _local_data = require('../local_data');
var _local_data = require('./local_data');

var _local_data2 = _interopRequireDefault(_local_data);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ var _path = require('path');

var _path2 = _interopRequireDefault(_path);

var _local_data = require('../local_data');
var _local_data = require('./local_data');

var _local_data2 = _interopRequireDefault(_local_data);

Expand Down
30 changes: 30 additions & 0 deletions lib/mock/data/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@

'use strict';

Object.defineProperty(exports, "__esModule", {
value: true
});
exports.GlobalSyncData = exports.SyncData = exports.AsyncData = exports.LocalData = undefined;

var _local_data = require('./local_data');

var _local_data2 = _interopRequireDefault(_local_data);

var _async_data = require('./async_data');

var _async_data2 = _interopRequireDefault(_async_data);

var _sync_data = require('./sync_data');

var _sync_data2 = _interopRequireDefault(_sync_data);

var _global_sync_data = require('./global_sync_data');

var _global_sync_data2 = _interopRequireDefault(_global_sync_data);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

exports.LocalData = _local_data2.default;
exports.AsyncData = _async_data2.default;
exports.SyncData = _sync_data2.default;
exports.GlobalSyncData = _global_sync_data2.default;
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ var _path = require('path');

var _path2 = _interopRequireDefault(_path);

var _extend = require('../../../util/extend');
var _extend = require('../../util/extend');

var _extend2 = _interopRequireDefault(_extend);

var _require_from_new = require('../../../util/require_from_new');
var _require_from_new = require('../../util/require_from_new');

var _require_from_new2 = _interopRequireDefault(_require_from_new);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,26 @@ var _path2 = require('path');

var _path3 = _interopRequireDefault(_path2);

var _extend = require('../../../util/extend');
var _extend = require('../../util/extend');

var _extend2 = _interopRequireDefault(_extend);

var _jsonProcessor = require('../../util/json.processor.js');

var _jsonProcessor2 = _interopRequireDefault(_jsonProcessor);

var _querystring = require('querystring');

var _querystring2 = _interopRequireDefault(_querystring);

var _local_data = require('../local_data');
var _local_data = require('./local_data');

var _local_data2 = _interopRequireDefault(_local_data);

var _global_sync_data = require('./global_sync_data.js');
var _global_sync_data = require('./global_sync_data');

var _global_sync_data2 = _interopRequireDefault(_global_sync_data);

var _jsonProcessor = require('../../../util/json.processor.js');

var _jsonProcessor2 = _interopRequireDefault(_jsonProcessor);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
Expand All @@ -46,7 +46,6 @@ var MockData = function () {
this.fileType = option.fileType || '.json';
this.path = option.path || '';
this.pageDataPath = _path3.default.join(__root, config.template.mock || '', this.path || this.ctx.url);

this.data;
}

Expand Down
Loading

0 comments on commit 53af0d8

Please sign in to comment.